MCPcopy Create free account
hub / github.com/dynjs/dynjs / execute

Method execute

src/main/java/org/dynjs/ir/Interpreter.java:36–203  ·  view source on GitHub ↗
(ExecutionContext context, Scope scope, Instruction[] instructions)

Source from the content-addressed store, hash-verified

34public class Interpreter {
35
36 public static Object execute(ExecutionContext context, Scope scope, Instruction[] instructions) {
37 //System.out.println("Executing: " + context.getFileName() + ":" + context.getLineNumber());
38 Object result = Types.UNDEFINED;
39 Object[] temps = new Object[scope.getTemporaryVariableSize()];
40 int size = instructions.length;
41 Object value = Types.UNDEFINED;
42
43 int ipc = 0;
44 while (ipc < size) {
45 Instruction instr = instructions[ipc];
46 ipc++;
47 //System.out.println("EX: " + instr);
48
49 switch(instr.getOperation()) {
50 case ADD:
51 value = add(context,
52 ((Add) instr).getLHS().retrieve(context, temps),
53 ((Add) instr).getRHS().retrieve(context, temps));
54 break;
55 case SUB:
56 value = sub(context,
57 ((Sub) instr).getLHS().retrieve(context, temps),
58 ((Sub) instr).getRHS().retrieve(context, temps));
59 break;
60 case RECEIVE_FUNCTION_PARAM:
61 value = context.getFunctionParameters()[((ReceiveFunctionParameter) instr).getIndex()];
62 break;
63 case COPY:
64 value = ((Copy) instr).getValue().retrieve(context, temps);
65 break;
66 case JUMP:
67 ipc = ((Jump) instr).getTarget().getTargetIPC();
68 break;
69 case CALL: {
70 Call call = (Call) instr;
71 Object ref = call.getIdentifier().retrieve(context, temps);
72 Object function = Types.getValue(context, ref);
73 Operand[] opers = call.getArgs();
74 Object[] args = new Object[opers.length];
75
76 if (!(function instanceof JSFunction)) {
77 throw new ThrowException(context, context.createTypeError(ref + " is not callable"));
78 }
79
80 for (int i = 0; i < args.length; i++) {
81 args[i] = opers[i].retrieve(context, temps);
82 }
83
84 Object thisValue = getThis(ref);
85
86 value = context.call(ref, (JSFunction) function, thisValue, args);
87 }
88 break;
89 case CONSTRUCTOR: {
90 Constructor constructor = (Constructor) instr;
91 Object ref = constructor.getIdentifier().retrieve(context, temps);
92 Object function = Types.getValue(context, ref);
93 Operand[] opers = constructor.getArgs();

Callers 2

executeMethod · 0.95
callMethod · 0.95

Calls 15

getOperationMethod · 0.95
addMethod · 0.95
subMethod · 0.95
getIdentifierMethod · 0.95
getValueMethod · 0.95
getArgsMethod · 0.95
getThisMethod · 0.95
getIdentifierMethod · 0.95
getArgsMethod · 0.95
compareRelationalMethod · 0.95
getArg1Method · 0.95
getArg2Method · 0.95

Tested by

no test coverage detected