<commit_before>package net.sandius.rembulan.compiler.gen;

import net.sandius.rembulan.compiler.gen.block.ClassEmitter;
import net.sandius.rembulan.compiler.gen.block.CodeEmitter;
import net.sandius.rembulan.compiler.types.Type;
import net.sandius.rembulan.core.Upvalue;
import net.sandius.rembulan.lbc.Prototype;
import net.sandius.rembulan.util.Check;
import net.sandius.rembulan.util.ReadOnlyArray;

public class JavaBytecodeCodeVisitor extends CodeVisitor {

	private final CodeEmitter e;

	public JavaBytecodeCodeVisitor(CodeEmitter e) {
		this.e = Check.notNull(e);
	}

	@Override
	public void visitMove(Object id, SlotState st, int r_src, int r_dest) {
		e._load_reg(r_src, st);
		e._store(r_dest, st);
	}

	@Override
	public void visitLoadK(Object id, SlotState st, int r_dest, int constIndex) {
		e._load_k(constIndex);
		e._store(r_dest, st);
	}

	@Override
	public void visitLoadBool(Object id, SlotState st, int r_dest, boolean value) {
		e._load_constant(value);
		e._store(r_dest, st);
	}

	@Override
	public void visitLoadNil(Object id, SlotState st, int r_dest, int count) {
		for (int i = 0; i < count; i++) {
			e._push_null();
			e._store(r_dest + i, st);
		}
	}

	@Override
	public void visitGetUpVal(Object id, SlotState st, int r_dest, int upvalueIndex) {
		e._get_upvalue_ref(upvalueIndex);
		e._get_upvalue_value();
		e._store(r_dest, st);
	}

	@Override
	public void visitGetTabUp(Object id, SlotState st, int r_dest, int upvalueIndex, int rk_key) {
		e._save_pc(this);

		e._loadState();
		e._loadObjectSink();
		e._get_upvalue_ref(upvalueIndex);
		e._get_upvalue_value();
		e._load_reg_or_const(rk_key, st);
		e._dispatch_index();

		e._resumptionPoint(this);
		e._retrieve_0();
		e._store(r_dest, st);
	}

	@Override
	public void visitGetTable(Object id, SlotState st, int r_dest, int r_tab, int rk_key) {
		throw new UnsupportedOperationException();  // TODO
	}

	@Override
	public void visitSetTabUp(Object id, SlotState st, int upvalueIndex, int rk_key, int rk_value) {
		e._save_pc(this);

		e._loadState();
		e._loadObjectSink();
		e._get_upvalue_ref(upvalueIndex);
		e._get_upvalue_value();
		e._load_reg_or_const(rk_key, st);
		e._load_reg_or_const(rk_value, st);
		e._dispatch_newindex();

		e._resumptionPoint(this);
	}

	@Override
	public void visitSetUpVal(Object id, SlotState st, int r_src, int upvalueIndex) {
		e._get_upvalue_ref(upvalueIndex);
		e._load_reg(r_src, st);
		e._set_upvalue_value();
	}

	@Override
	public void visitSetTable(Object id, SlotState st, int r_tab, int rk_key, int rk_value) {
		throw new UnsupportedOperationException();  // TODO<commit_msg>Emitting bytecode for GETTABLE and SETTABLE.<commit_after>package net.sandius.rembulan.compiler.gen;

import net.sandius.rembulan.compiler.gen.block.ClassEmitter;
import net.sandius.rembulan.compiler.gen.block.CodeEmitter;
import net.sandius.rembulan.compiler.types.Type;
import net.sandius.rembulan.core.Upvalue;
import net.sandius.rembulan.lbc.Prototype;
import net.sandius.rembulan.util.Check;
import net.sandius.rembulan.util.ReadOnlyArray;

public class JavaBytecodeCodeVisitor extends CodeVisitor {

	private final CodeEmitter e;

	public JavaBytecodeCodeVisitor(CodeEmitter e) {
		this.e = Check.notNull(e);
	}

	@Override
	public void visitMove(Object id, SlotState st, int r_src, int r_dest) {
		e._load_reg(r_src, st);
		e._store(r_dest, st);
	}

	@Override
	public void visitLoadK(Object id, SlotState st, int r_dest, int constIndex) {
		e._load_k(constIndex);
		e._store(r_dest, st);
	}

	@Override
	public void visitLoadBool(Object id, SlotState st, int r_dest, boolean value) {
		e._load_constant(value);
		e._store(r_dest, st);
	}

	@Override
	public void visitLoadNil(Object id, SlotState st, int r_dest, int count) {
		for (int i = 0; i < count; i++) {
			e._push_null();
			e._store(r_dest + i, st);
		}
	}

	@Override
	public void visitGetUpVal(Object id, SlotState st, int r_dest, int upvalueIndex) {
		e._get_upvalue_ref(upvalueIndex);
		e._get_upvalue_value();
		e._store(r_dest, st);
	}

	@Override
	public void visitGetTabUp(Object id, SlotState st, int r_dest, int upvalueIndex, int rk_key) {
		e._save_pc(this);

		e._loadState();
		e._loadObjectSink();
		e._get_upvalue_ref(upvalueIndex);
		e._get_upvalue_value();
		e._load_reg_or_const(rk_key, st);
		e._dispatch_index();

		e._resumptionPoint(this);
		e._retrieve_0();
		e._store(r_dest, st);
	}

	@Override
	public void visitGetTable(Object id, SlotState st, int r_dest, int r_tab, int rk_key) {
		e._save_pc(this);

		e._loadState();
		e._loadObjectSink();
		e._load_reg(r_tab, st);
		e._load_reg_or_const(rk_key, st);
		e._dispatch_index();

		e._resumptionPoint(this);
		e._retrieve_0();
		e._store(r_dest, st);
	}

	@Override
	public void visitSetTabUp(Object id, SlotState st, int upvalueIndex, int rk_key, int rk_value) {
		e._save_pc(this);

		e._loadState();
		e._loadObjectSink();
		e._get_upvalue_ref(upvalueIndex);
		e._get_upvalue_value();
		e._load_reg_or_const(rk_key, st);
		e._load_reg_or_const(rk_value, st);
		e._dispatch_newindex();

		e._resumptionPoint(this);
	}

	@Override
	public void visitSetUpVal(Object id, SlotState st, int r_src, int upvalueIndex) {
		e._get_upvalue_ref(upvalueIndex);
		e._load_reg(r_src, st);
		e._set_upvalue_value();
	}

	@Override
	public void visitSetTable(Object id, SlotState st, int r_tab, int rk_key, int rk_value) {
		e._save_pc(this);

		e._loadState();
		e._loadObjectSink();
		e._load_reg(r_tab, st);
		e._load_reg_or_const(rk_key, st);
		e._load_reg_or_const(rk_value, st);
		e._dispatch_newindex();

		e._resumptionPoint(this);
{'fraction_non_alphanumeric': 0.12166278444723168, 'fraction_numerical': 0.0008958967926894822, 'mean_word_length': 4.869610935856993, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6207705', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2175, 'n_words': 435}