Commit 13171859 authored by Camil Staps's avatar Camil Staps 🍃

Move generic wasm-supporting JS from here to abc-interpreter

parent e463865a
Pipeline #26083 passed with stage
in 5 minutes and 13 seconds
......@@ -9,8 +9,8 @@
<link rel="stylesheet" href="/Incidone.css" type="text/css" >
<!-- ABC interpreter -->
<script type="text/javascript" src="/js/abc-instructions.js"></script>
<script type="text/javascript" src="/js/abc-interpreter.js"></script>
<script type="text/javascript" src="/js/itasks-abc-interpreter.js"></script>
<!-- iTasks framework -->
<script type="text/javascript" src="/js/itasks-core.js"></script>
......
......@@ -12,7 +12,7 @@ definition module iTasks.UI.JavaScript
* with JavaScript (where indicated in documentation below).
*
* The JavaScript interfacing with this module can be found in itasks-core.js
* and abc-interpreter.js.
* and itasks-abc-interpreter.js.
*/
import StdGeneric
......@@ -51,7 +51,7 @@ jsGetCleanReference :: !JSVal !*JSWorld -> *(!Maybe b, !*JSWorld)
/**
* Remove a Clean value from the JavaScript heap. The value must have been
* shared using `jsMakeCleanReference` or `jsWrapFun`. For example:
* shared using `jsMakeCleanReference` or `jsWrapFun`.
*/
jsFreeCleanReference :: !JSVal !*JSWorld -> *JSWorld
......
......@@ -8,8 +8,8 @@
<link rel="stylesheet" href="/css/itasks-modules.css" type="text/css" >
<!-- ABC interpreter -->
<script type="text/javascript" src="/js/abc-instructions.js"></script>
<script type="text/javascript" src="/js/abc-interpreter.js"></script>
<script type="text/javascript" src="/js/itasks-abc-interpreter.js"></script>
<!-- iTasks framework -->
<script type="text/javascript" src="/js/itasks-core.js"></script>
......
This diff is collapsed.
"use strict";
var ABC=null;
const ABC_loading_promise=ABCInterpreter.instantiate({
bytecode_path: '/js/app.pbc',
heap_size: 8<<20,
stack_size: 512<<10,
util_imports: {
has_host_reference: function (index) {
if (index>=ABC.shared_clean_values.length)
return 0;
if (ABC.shared_clean_values[index]==null)
return -1;
return ABC.shared_clean_values[index].ref;
},
update_host_reference: function (index, new_location) {
ABC.shared_clean_values[index].ref=new_location;
},
},
interpreter_imports: {
handle_illegal_instr: function (pc, instr, asp, bsp, csp, hp, hp_free) {
if (ABCInterpreter.instructions[instr]=='instruction') {
const arg=ABC.memory_array[(pc+8)/4];
switch (arg) {
case 0: /* evaluation finished */
return 0;
case 1: /* iTasks.UI.JS.Interface: set_js */
var v=ABC.get_clean_string(ABC.memory_array[asp/4], true);
var x=ABC.get_clean_string(ABC.memory_array[asp/4-2], true);
if (ABC_DEBUG)
console.log(v,'.=',x);
try {
var ref=eval(v+'.shared_clean_value_index');
if (typeof ref != 'undefined') {
if (ABC_DEBUG)
console.log('removing old reference to Clean',ref);
ABC.clear_shared_clean_value(ref);
}
} catch (e) {}
Function(v+'='+x)();
break;
case 2: /* iTasks.UI.JS.Interface: eval_js */
var string=ABC.get_clean_string(ABC.memory_array[asp/4], true);
if (ABC_DEBUG)
console.log('eval',string);
Function(string)();
break;
case 3: /* iTasks.UI.JS.Interface: eval_js_with_return_value */
var string=ABC.get_clean_string(ABC.memory_array[asp/4], true);
if (ABC_DEBUG)
console.log('eval',string);
var result=eval('('+string+')'); // the parentheses are needed for {}, for instance
var copied=ABC.copy_js_to_clean(result, asp);
ABC.interpreter.instance.exports.set_hp(copied.hp);
ABC.interpreter.instance.exports.set_hp_free(copied.hp_free);
break;
case 4: /* iTasks.UI.JS.Interface: share */
var attach_to=ABC.memory_array[bsp/4];
var index=ABC.share_clean_value(ABC.memory_array[asp/4],ABC.js[attach_to]);
ABC.memory_array[bsp/4]=index;
break;
case 5: /* iTasks.UI.JS.Interface: fetch */
var index=ABC.memory_array[bsp/4];
ABC.memory_array[asp/4]=ABC.shared_clean_values[index].ref;
break;
case 6: /* iTasks.UI.JS.Interface: deserialize */
var hp_ptr=ABC.memory_array[asp/4];
ABC.memory_array[asp/4]=ABC.deserialize_from_unique_string(hp_ptr);
break;
case 7: /* iTasks.UI.JS.Interface: initialize_client in wrapInitUIFunction */
var array=ABC.memory_array[asp/4]+24;
ABC.addresses.JSInt= ABC.memory_array[ABC.memory_array[array/4]/4];
ABC.addresses.JSBool= ABC.memory_array[ABC.memory_array[array/4+2]/4];
ABC.addresses.JSString= ABC.memory_array[ABC.memory_array[array/4+4]/4];
ABC.addresses.JSReal= ABC.memory_array[ABC.memory_array[array/4+6]/4];
ABC.addresses.JSNull= ABC.memory_array[ABC.memory_array[array/4+8]/4];
ABC.addresses.JSUndefined=ABC.memory_array[ABC.memory_array[array/4+10]/4];
ABC.addresses.JSArray= ABC.memory_array[ABC.memory_array[array/4+12]/4];
ABC.addresses.JSRef= ABC.memory_array[ABC.memory_array[array/4+14]/4];
ABC.addresses.JSCleanRef= ABC.memory_array[ABC.memory_array[array/4+16]/4];
ABC.util.instance.exports.set_js_ref_constructor(ABC.addresses.JSRef);
ABC.initialized=true;
break;
case 10: /* iTasks.UI.JS.Interface: add CSS */
var url=ABC.get_clean_string(ABC.memory_array[asp/4], false);
var css=document.createElement('link');
css.rel='stylesheet';
css.type='text/css';
css.async=true;
css.href=url;
document.head.appendChild(css);
break;
case 11: /* iTasks.UI.JS.Interface: add JS */
var url=ABC.get_clean_string(ABC.memory_array[asp/4], false);
var callback=ABC.get_clean_string(ABC.memory_array[asp/4-2], true);
var js=document.createElement('script');
js.type='text/javascript';
js.async=false;
if (callback.length>0)
js.onload=Function(callback+'();');
document.head.appendChild(js);
js.src=url;
break;
default:
throw new ABCError('unknown instruction',arg);
}
return pc+16;
}
return 0;
},
illegal_instr: function (addr, instr) {
ABC.empty_log_buffer();
if (ABCInterpreter.instructions[instr]=='instruction')
/* `instruction 0` ends the interpretation, so this is no error */
return;
throw new ABCError('illegal instruction',instr);
},
},
}).then(function(instance){
ABC=instance;
ABC.initialized=false;
});
......@@ -43,10 +43,10 @@ itasks.Component = {
initUI: function() {
var me=this;
if (me.attributes.initUI!=null && me.attributes.initUI!='') {
return ABC.loading_promise.then(function(){
return ABC_loading_promise.then(function(){
var initUI=ABC.deserialize(me.attributes.initUI);
var ref=ABC.share_clean_value(initUI,me);
ABC.interpret(SharedCleanValue(ref), [me, ABC.initialized ? 0 : 1]);
ABC.interpret(new SharedCleanValue(ref), [me, ABC.initialized ? 0 : 1]);
ABC.clear_shared_clean_value(ref);
});
}
......
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