ISourceLocation src = (ISourceLocation) declaration.get("src");
CodeBlock codeblock = new CodeBlock(vf);
// Loading instructions
try {
for (int i = 0; i < code.length(); i++) {
IConstructor instruction = (IConstructor) code.get(i);
String opcode = instruction.getName();
switch (opcode) {
case "LOADCON":
codeblock.LOADCON(instruction.get("val"));
break;
case "LOADVAR":
codeblock.LOADVAR(getStrField(instruction, "fuid"),
getIntField(instruction, "pos"));
break;
case "LOADLOC":
codeblock.LOADLOC(getIntField(instruction, "pos"));
break;
case "LOADCONT":
codeblock.LOADCONT(getStrField(instruction, "fuid"));
break;
case "STOREVAR":
codeblock.STOREVAR(getStrField(instruction, "fuid"),
getIntField(instruction, "pos"));
break;
case "STORELOC":
codeblock.STORELOC(getIntField(instruction, "pos"));
break;
case "LABEL":
codeblock = codeblock.LABEL(getStrField(instruction, "label"));
break;
case "CALLPRIM":
codeblock.CALLPRIM(RascalPrimitive.valueOf(getStrField(instruction, "name")),
getIntField(instruction, "arity"),
getLocField(instruction, "src"));
break;
case "CALLMUPRIM":
codeblock.CALLMUPRIM(MuPrimitive.valueOf(getStrField(instruction, "name")),
getIntField(instruction, "arity"));
break;
case "CALL":
codeblock.CALL(getStrField(instruction, "fuid"), getIntField(instruction, "arity"));
break;
case "CALLDYN":
codeblock.CALLDYN( getIntField(instruction, "arity"));
break;
case "APPLY":
codeblock.APPLY(getStrField(instruction, "fuid"),
getIntField(instruction, "arity"));
break;
case "APPLYDYN":
codeblock.APPLYDYN(getIntField(instruction, "arity"));
break;
case "LOADFUN":
codeblock.LOADFUN(getStrField(instruction, "fuid"));
break;
case "RETURN0":
codeblock.RETURN0();
break;
case "RETURN1":
codeblock.RETURN1(getIntField(instruction, "arity"));
break;
case "JMP":
codeblock.JMP(getStrField(instruction, "label"));
break;
case "JMPTRUE":
codeblock.JMPTRUE(getStrField(instruction, "label"));
break;
case "JMPFALSE":
codeblock.JMPFALSE(getStrField(instruction, "label"));
break;
case "HALT":
codeblock.HALT();
break;
case "CREATE":
codeblock.CREATE(getStrField(instruction, "fuid"),
getIntField(instruction, "arity"));
break;
case "CREATEDYN":
codeblock.CREATEDYN(getIntField(instruction, "arity"));
break;
case "RESET":
codeblock.RESET();
break;
case "NEXT0":
codeblock.NEXT0();
break;
case "NEXT1":
codeblock.NEXT1();
break;
case "YIELD0":
codeblock.YIELD0();
break;
case "YIELD1":
codeblock.YIELD1(getIntField(instruction, "arity"));
break;
case "SHIFT":
codeblock.SHIFT();
break;
case "PRINTLN":
codeblock.PRINTLN(getIntField(instruction, "arity"));
break;
case "POP":
codeblock.POP();
break;
case "LOADLOCREF":
codeblock.LOADLOCREF(getIntField(instruction, "pos"));
break;
case "LOADVARREF":
codeblock.LOADVARREF(getStrField(instruction, "fuid"),
getIntField(instruction, "pos"));
break;
case "LOADLOCDEREF":
codeblock.LOADLOCDEREF(getIntField(instruction, "pos"));
break;
case "LOADVARDEREF":
codeblock.LOADVARDEREF(getStrField(instruction, "fuid"),
getIntField(instruction, "pos"));
break;
case "STORELOCDEREF":
codeblock.STORELOCDEREF(getIntField(instruction, "pos"));
break;
case "STOREVARDEREF":
codeblock.STOREVARDEREF(getStrField(instruction, "fuid"),
getIntField(instruction, "pos"));
break;
case "LOAD_NESTED_FUN":
codeblock.LOADNESTEDFUN(getStrField(instruction, "fuid"),
getStrField(instruction, "scopeIn"));
break;
case "LOADCONSTR":
codeblock.LOADCONSTR(getStrField(instruction, "fuid"));
break;
case "CALLCONSTR":
codeblock.CALLCONSTR(getStrField(instruction, "fuid"),
getIntField(instruction, "arity")/*, getLocField(instruction, "src")*/);
break;
case "LOADTYPE":
codeblock.LOADTYPE(rvm.symbolToType((IConstructor) instruction.get("type")));
break;
case "LOADBOOL":
codeblock.LOADBOOL(getBooleanField(instruction, "bval"));
break;
case "LOADINT":
codeblock.LOADINT(getIntField(instruction, "nval"));
break;
case "FAILRETURN":
codeblock.FAILRETURN();
break;
case "LOADOFUN" :
codeblock.LOADOFUN(getStrField(instruction, "fuid"));
break;
case "OCALL" :
codeblock.OCALL(getStrField(instruction, "fuid"),
getIntField(instruction, "arity"),
getLocField(instruction, "src"));
break;
case "OCALLDYN" :
codeblock.OCALLDYN(rvm.symbolToType((IConstructor) instruction.get("types")),
getIntField(instruction, "arity"),
getLocField(instruction, "src"));
break;
case "CALLJAVA":
codeblock.CALLJAVA(getStrField(instruction, "name"),
getStrField(instruction, "class"),
rvm.symbolToType((IConstructor) instruction.get("parameterTypes")),
rvm.symbolToType((IConstructor) instruction.get("keywordTypes")),
getIntField(instruction, "reflect"));
break;
case "THROW":
codeblock.THROW(getLocField(instruction, "src"));
break;
case "TYPESWITCH":
codeblock.TYPESWITCH((IList)instruction.get("labels"));
break;
case "UNWRAPTHROWNLOC":
codeblock.UNWRAPTHROWNLOC(getIntField(instruction, "pos"));
break;
case "FILTERRETURN":
codeblock.FILTERRETURN();
break;
case "EXHAUST":
codeblock.EXHAUST();
break;
case "GUARD":
codeblock.GUARD();
break;
case "SUBSCRIPTARRAY":
codeblock.SUBSCRIPTARRAY();
break;
case "SUBSCRIPTLIST":
codeblock.SUBSCRIPTLIST();
break;
case "LESSINT":
codeblock.LESSINT();
break;
case "GREATEREQUALINT":
codeblock.GREATEREQUALINT();
break;
case "ADDINT":
codeblock.ADDINT();
break;
case "SUBTRACTINT":
codeblock.SUBTRACTINT();
break;
case "ANDBOOL":
codeblock.ANDBOOL();
break;
case "TYPEOF":
codeblock.TYPEOF();
break;
case "SUBTYPE":
codeblock.SUBTYPE();
break;
case "CHECKARGTYPE":
codeblock.CHECKARGTYPE();
break;
case "JMPINDEXED":
codeblock.JMPINDEXED((IList)instruction.get("labels"));
break;
case "LOADLOCKWP":
codeblock.LOADLOCKWP(getStrField(instruction, "name"));
break;