Verified Commit eb7805ea authored by Camil Staps's avatar Camil Staps 🚀

JS frontend: allow implementer to catch and handle unimplemented instructions

parent 257228f0
Pipeline #43529 passed with stages
in 22 minutes and 39 seconds
......@@ -508,7 +508,7 @@ class ABCInterpreter {
if ('with_js_ffi' in args && args.with_js_ffi){
Object.assign(opts.util_imports,ABCInterpreter.util_imports.js_references(me));
Object.assign(opts.interpreter_imports,ABCInterpreter.interpreter_imports.js_ffi(me));
Object.assign(opts.interpreter_imports,ABCInterpreter.interpreter_imports.js_ffi(me, args.js_ffi_options));
}
me.stack_size=opts.stack_size*2;
......@@ -779,9 +779,11 @@ ABCInterpreter.util_imports={
}),
};
ABCInterpreter.interpreter_imports={
js_ffi: me => ({
js_ffi: (me, options) => ({
handle_illegal_instr: function (pc, instr, asp, bsp, csp, hp, hp_free) {
if (ABCInterpreter.instructions[instr]=='instruction') {
const instr_name=ABCInterpreter.instructions[instr];
if (instr_name=='instruction'){
const arg=me.memory_array[(pc+8)/4];
switch (arg) {
case 0: /* evaluation finished */
......@@ -800,13 +802,13 @@ ABCInterpreter.interpreter_imports={
}
} catch (e) {}
eval(v+'='+x);
break;
return pc+16;
case 2: /* ABC.Interpreter.JavaScript: eval_js */
var string=me.get_clean_string(me.memory_array[asp/4], true);
if (ABC_DEBUG)
console.log('eval',string);
eval(string);
break;
return pc+16;
case 3: /* ABC.Interpreter.JavaScript: eval_js_with_return_value */
var string=me.get_clean_string(me.memory_array[asp/4], true);
if (ABC_DEBUG)
......@@ -815,26 +817,26 @@ ABCInterpreter.interpreter_imports={
var copied=me.copy_js_to_clean(result, asp);
me.interpreter.instance.exports.set_hp(copied.hp);
me.interpreter.instance.exports.set_hp_free(copied.hp_free);
break;
return pc+16;
case 4: /* ABC.Interpreter.JavaScript: share */
var attach_to=me.memory_array[bsp/4];
var index=me.share_clean_value(me.memory_array[asp/4],me.js[attach_to]);
me.memory_array[bsp/4]=index;
break;
return pc+16;
case 5: /* ABC.Interpreter.JavaScript: fetch */
var index=me.memory_array[bsp/4];
me.memory_array[asp/4]=me.shared_clean_values[index].ref;
break;
return pc+16;
case 6: /* ABC.Interpreter.JavaScript: deserialize */
var hp_ptr=me.memory_array[asp/4];
me.memory_array[asp/4]=me.deserialize_from_unique_string(hp_ptr);
break;
return pc+16;
case 7: /* ABC.Interpreter.JavaScript: deserializeJSVal */
var string=me.get_clean_string (me.memory_array[asp/4],true);
if (ABC_DEBUG)
console.log ('deserialize',string);
me.memory_array[asp/4]=me.deserialize (eval (string));
break;
return pc+16;
case 8: /* ABC.Interpreter.JavaScript: jsSerializeOnClient */
me.require_hp(2);
var string=me.copy_to_string(me.memory_array[asp/4]);
......@@ -847,7 +849,7 @@ ABCInterpreter.interpreter_imports={
me.interpreter.instance.exports.set_asp(asp);
me.interpreter.instance.exports.set_hp(hp+16);
me.interpreter.instance.exports.set_hp_free(hp_free-2);
break;
return pc+16;
case 9: /* ABC.Interpreter.JavaScript: initialize_client in wrapInitUIFunction */
var array=me.memory_array[asp/4]+24;
me.addresses.JSInt= me.memory_array[me.memory_array[array/4]/4];
......@@ -861,7 +863,7 @@ ABCInterpreter.interpreter_imports={
me.addresses.JSCleanRef= me.memory_array[me.memory_array[array/4+16]/4];
me.util.instance.exports.set_js_ref_constructor(me.addresses.JSRef);
me.initialized=true;
break;
return pc+16;
case 11: /* ABC.Interpreter.JavaScript: add CSS */
var url=me.get_clean_string(me.memory_array[asp/4], false);
var css=document.createElement('link');
......@@ -870,7 +872,7 @@ ABCInterpreter.interpreter_imports={
css.async=true;
css.href=url;
document.head.appendChild(css);
break;
return pc+16;
case 12: /* ABC.Interpreter.JavaScript: add JS */
var url=me.get_clean_string(me.memory_array[asp/4], false);
var callback=me.get_clean_string(me.memory_array[asp/4-2], true);
......@@ -888,12 +890,13 @@ ABCInterpreter.interpreter_imports={
}
document.head.appendChild(js);
js.src=url;
break;
default:
throw new ABCError('unknown instruction',arg);
return pc+16;
}
return pc+16;
}
if ('illegal_instruction_handlers' in options && instr_name in options.illegal_instruction_handlers)
return options.illegal_instruction_handlers[instr_name] (me,pc,asp,bsp,csp,hp,hp_free);
return 0;
},
illegal_instr: function (addr, instr) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment