<commit_before>/* TODO */
/* kObject_getObjectNULL(O, KEY) have been converted to O[KEY]. */
/* expr.isUnbox */
/* _ctx.konoha_setModule */
/* distinguish beteween bool and number */
/* KW_Block */

konoha.MODCODE_init = function (_ctx)
{
	_ctx.modcode = this;
	this.name = 'minivm';
	this.output = ''; // source code to evaluated
	this.indent = 0; // depth of indent
	this.tab = '\t';

	this.setup = function(_ctx)
	{
		/* kmodcode_setup */
		var base = {};
		base.insts = [];
		base.constPools = [];
		_ctx.ctxcode = base;
		//_ctx.modlocal[konoha.MOD_code] = base;
	}

	this.reftrace = function()
	{
		/* do nothing */
	}

	this.free = function()
	{
		/* do nothing */
	}
	
	//_ctx.Konoha_setModule(konoha.MOD_code, this);

	this.setup(_ctx);
	_ctx.lib2.KMethod_genCode = function(_ctx, mtd, bk)
	{
		/* mtd: kMethod, bk: kBlock */

		/* prepare code generate */
		console.log('START CODE GENERATION..');
		if (_ctx.ctxcode == null) {
			_ctx.modcode.setup(_ctx);
		}
		//if (_ctx.modlocal[konoha.MOD_code] == null) {
		//	_ctx.modshare[konoha.MOD_code].setup(_ctx);
		//}
		
		/* start code generation */

		konoha.BLOCK_asm(_ctx, bk, 0);
	}
}

konoha.MODCODE_init.prototype.ASM = function(str)
{
	this.output += str;
}

konoha.MODCODE_init.prototype.ASM_NEWLINE = function() {
	this.output += '\n';
	for (var i = 0; i < this.indent; i++) {
		this.output += this.tab;
	}
}

konoha.MODCODE_init.prototype.ASM_NMOV = function(a, b, ty)
{
	konoha.MODCODE_init.prototype.ASM('var sfp' + a + ' = sfp' + b + ';');
	konoha.MODCODE_init.prototype.ASM_NEWLINE();
}

konoha.MODCODE_init.prototype.NMOV_asm = function(_ctx, a, ty, b)
{
	konoha.MODCODE_init.prototype.ASM_NMOV(a, b, ty);
}

konoha.MODCODE_init.prototype.ASM_NSET = function(a, data)
{
	konoha.MODCODE_init.prototype.ASM('var sfp' + a + ' = ' + data + ';');
	konoha.MODCODE_init.prototype.ASM_NEWLINE();
}

konoha.MODCODE_init.prototype.ASM_OSET = function(a, data)
{
	console.log('TODO asm_oset');
}

konoha.MODCODE_init.prototype.ASM_CALL = function(_ctx, thisidx, espidx, argc, mtd) {
//	var rtype = konoha.kMethod_rtype(mtd); // TODO
//	if (rtype != konoha.CLASS_Tvoid) {
//		konoha.MODCODE_init.prototype.ASM('var sfp' + (thisidx+konoha.K_RTNIDX) + ' = ');
//	}
	var mtdName = mtd.mtdname;
	konoha.MODCODE_init.prototype.ASM(mtdName + '(');
	for (var i = 0; i < argc; i++) {
		konoha.MODCODE_init.prototype.ASM('sfp' + (thisidx+1+i));
		if (i != argc-1) {
			konoha.MODCODE_init.prototype.ASM(', ');
		}
	}
	konoha.MODCODE_init.prototype.ASM(');');
}

konoha.MODCODE_init.prototype.CALL_asm = function(_ctx, a, expr, shift, espidx)
{
	var mtd = expr.cons.data[0]; // TODO unuse methods field, is it OK?
//	console.log(expr.cons.data[0]);
	var s = 1;//konoha.kMethod_isStatic(mtd) ? 2 : 1,
	var thisidx = espidx + konoha.K_CALLDELTA;
	console.log("-----expr.cons.data.length----------");
	console.log(expr.cons.data.length);
	console.log("-----expr.cons.data.length----------");
	for (var i = s; i < expr.cons.data.length; i++) {
		var exprN = expr.cons.data[i];
		konoha.MODCODE_init.prototype.EXPR_asm(_ctx, thisidx + i - 1, exprN, shift, thisidx + i - 1);
	}
	var argc = expr.cons.data.length - 1;
	/* don't care wheather method is static or not */
	konoha.MODCODE_init.prototype.ASM_CALL(_ctx, thisidx, espidx, argc, mtd);
}

konoha.MODCODE_init.prototype.EXPR_asm = function(_ctx, a, expr, shift, espidx)
{
	/* a: number, expr: kExpr, shift: number, espidx: number */
	console.log("EXPR_asm start");<commit_msg>asm bug fixed<commit_after>/* TODO */
/* kObject_getObjectNULL(O, KEY) have been converted to O[KEY]. */
/* expr.isUnbox */
/* _ctx.konoha_setModule */
/* distinguish beteween bool and number */
/* KW_Block */

konoha.MODCODE_init = function (_ctx)
{
	_ctx.modcode = this;
	this.name = 'minivm';
	this.output = ''; // source code to evaluated
	this.indent = 0; // depth of indent
	this.tab = '\t';

	this.setup = function(_ctx)
	{
		/* kmodcode_setup */
		var base = {};
		base.insts = [];
		base.constPools = [];
		_ctx.ctxcode = base;
		//_ctx.modlocal[konoha.MOD_code] = base;
	}

	this.reftrace = function()
	{
		/* do nothing */
	}

	this.free = function()
	{
		/* do nothing */
	}
	
	//_ctx.Konoha_setModule(konoha.MOD_code, this);

	this.setup(_ctx);
	_ctx.lib2.KMethod_genCode = function(_ctx, mtd, bk)
	{
		/* mtd: kMethod, bk: kBlock */

		/* prepare code generate */
		console.log('START CODE GENERATION..');
		if (_ctx.ctxcode == null) {
			_ctx.modcode.setup(_ctx);
		}
		//if (_ctx.modlocal[konoha.MOD_code] == null) {
		//	_ctx.modshare[konoha.MOD_code].setup(_ctx);
		//}
		
		/* start code generation */

		konoha.BLOCK_asm(_ctx, bk, 0);
	}
}

konoha.MODCODE_init.prototype.ASM = function(str)
{
	this.output += str;
}

konoha.MODCODE_init.prototype.ASM_NEWLINE = function() {
	this.output += '\n';
	for (var i = 0; i < this.indent; i++) {
		this.output += this.tab;
	}
}

konoha.MODCODE_init.prototype.ASM_NMOV = function(a, b, ty)
{
	konoha.MODCODE_init.prototype.ASM('var sfp' + a + ' = sfp' + b + ';');
	konoha.MODCODE_init.prototype.ASM_NEWLINE();
}

konoha.MODCODE_init.prototype.NMOV_asm = function(_ctx, a, ty, b)
{
	konoha.MODCODE_init.prototype.ASM_NMOV(a, b, ty);
}

konoha.MODCODE_init.prototype.ASM_NSET = function(a, data)
{
	konoha.MODCODE_init.prototype.ASM('var sfp' + a + ' = ' + data + ';');
	konoha.MODCODE_init.prototype.ASM_NEWLINE();
}

konoha.MODCODE_init.prototype.ASM_OSET = function(a, data)
{
	console.log('TODO asm_oset');
}

konoha.MODCODE_init.prototype.ASM_CALL = function(_ctx, thisidx, espidx, argc, mtd) {
//	var rtype = konoha.kMethod_rtype(mtd); // TODO
//	if (rtype != konoha.CLASS_Tvoid) {
//		konoha.MODCODE_init.prototype.ASM('var sfp' + (thisidx+konoha.K_RTNIDX) + ' = ');
//	}
	var mtdName = mtd.mtdname;
	konoha.MODCODE_init.prototype.ASM(mtdName + '(');
	for (var i = 0; i < argc; i++) {
		konoha.MODCODE_init.prototype.ASM('sfp' + (thisidx+i));
		if (i != argc-1) {
			konoha.MODCODE_init.prototype.ASM(', ');
		}
	}
	konoha.MODCODE_init.prototype.ASM(');');
}

konoha.MODCODE_init.prototype.CALL_asm = function(_ctx, a, expr, shift, espidx)
{
	var mtd = expr.cons.data[0]; // TODO unuse methods field, is it OK?
//	console.log(expr.cons.data[0]);
	var s = 1;//konoha.kMethod_isStatic(mtd) ? 2 : 1,
	var thisidx = espidx + konoha.K_CALLDELTA;
	console.log("-----expr.cons.data.length----------");
	console.log(expr.cons.data.length);
	console.log("-----expr.cons.data.length----------");
	for (var i = s; i < expr.cons.data.length; i++) {
		var exprN = expr.cons.data[i];
		konoha.MODCODE_init.prototype.EXPR_asm(_ctx, thisidx + i - 1, exprN, shift, thisidx + i - 1);
	}
	var argc = expr.cons.data.length - 1;
	/* don't care wheather method is static or not */
	konoha.MODCODE_init.prototype.ASM_CALL(_ctx, thisidx, espidx, argc, mtd);
}

konoha.MODCODE_init.prototype.EXPR_asm = function(_ctx, a, expr, shift, espidx)
{
	/* a: number, expr: kExpr, shift: number, espidx: number */
	console.log("EXPR_asm start");
{'fraction_non_alphanumeric': 0.18622375611159045, 'fraction_numerical': 0.004170261719873454, 'mean_word_length': 3.578670177748519, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2586486', 'n_tokens_mistral': 3001, 'n_tokens_neox': 2800, 'n_words': 499}