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

Rename JavaScript variable names to make JS ffi somewhat more lightweight

parent 1194a86b
......@@ -26,7 +26,7 @@ import Text
| JSSel !JSVal !JSVal // x[y]
| JSSelPath !JSVal !String // x.path1.path2...pathn
| JSRef !Int // a reference to shared_js_values
| JSRef !Int // a reference to js
| JSCleanRef !Int // a reference to shared_clean_values
| JSTempPair !JSVal !JSVal
......@@ -57,8 +57,8 @@ where
JSSel obj attr -> toString obj+++"["+++toString attr+++"]"
JSSelPath obj path -> toString obj+++"."+++path
JSRef i -> "abc_interpreter.shared_js_values["+++toString i+++"]"
JSCleanRef i -> "abc_interpreter.apply_to_clean_value("+++toString i+++")"
JSRef i -> "ABC.js["+++toString i+++"]"
JSCleanRef i -> "ABC.ap("+++toString i+++")"
jsMakeCleanReference :: a -> JSVal
jsMakeCleanReference x = share x
......
......@@ -25,7 +25,7 @@
<!-- load iTasks viewport -->
<script type="text/javascript">
window.onload = function() {
abc_interpreter.loading_promise.then(function(){
ABC.loading_promise.then(function(){
itasks.viewport({syncTitle: true}, document.body);
});
};
......
......@@ -8,7 +8,7 @@ function SharedCleanValue(index) {
};
}
const abc_interpreter={
const ABC={
prog: undefined,
memory: undefined,
memory_array: undefined,
......@@ -25,17 +25,17 @@ const abc_interpreter={
log_buffer: '',
log: function (s) {
s=String(s);
abc_interpreter.log_buffer+=s;
ABC.log_buffer+=s;
if (s.indexOf('\n')>=0) {
var lines=abc_interpreter.log_buffer.split('\n');
var lines=ABC.log_buffer.split('\n');
for (var i=0; i<lines.length-1; i++)
console.log(lines[i]);
abc_interpreter.log_buffer=lines[lines.length-1];
ABC.log_buffer=lines[lines.length-1];
}
},
empty_log_buffer: function(){
if (abc_interpreter.log_buffer.length>0)
console.log(abc_interpreter.log_buffer);
if (ABC.log_buffer.length>0)
console.log(ABC.log_buffer);
},
deserialize: function(string) {
......@@ -43,40 +43,40 @@ const abc_interpreter={
for (var i in string)
array[i]=string.charCodeAt(i);
var graph=new Uint32Array(array.buffer);
var unused_semispace=abc_interpreter.util.instance.exports.get_unused_semispace();
var unused_semispace=ABC.util.instance.exports.get_unused_semispace();
for (var i=0; i<graph.length; i++)
abc_interpreter.memory_array[unused_semispace/4+i] = graph[i];
ABC.memory_array[unused_semispace/4+i]=graph[i];
// TODO: maybe garbage collection is needed
var old_hp=abc_interpreter.interpreter.instance.exports.get_hp();
var new_hp=abc_interpreter.util.instance.exports.copy_from_string(
var old_hp=ABC.interpreter.instance.exports.get_hp();
var new_hp=ABC.util.instance.exports.copy_from_string(
unused_semispace,
graph.length/2,
abc_interpreter.interpreter.instance.exports.get_asp()+8,
abc_interpreter.interpreter.instance.exports.get_bsp()-8,
ABC.interpreter.instance.exports.get_asp()+8,
ABC.interpreter.instance.exports.get_bsp()-8,
old_hp,
abc_interpreter.code_offset*8);
abc_interpreter.interpreter.instance.exports.set_hp(new_hp);
abc_interpreter.interpreter.instance.exports.set_hp_free(
abc_interpreter.interpreter.instance.exports.get_hp_free()-(new_hp-old_hp)/8);
ABC.code_offset*8);
ABC.interpreter.instance.exports.set_hp(new_hp);
ABC.interpreter.instance.exports.set_hp_free(
ABC.interpreter.instance.exports.get_hp_free()-(new_hp-old_hp)/8);
var index=abc_interpreter.shared_clean_values.length;
abc_interpreter.shared_clean_values.push(abc_interpreter.memory_array[unused_semispace/4]);
var index=ABC.shared_clean_values.length;
ABC.shared_clean_values.push(ABC.memory_array[unused_semispace/4]);
return SharedCleanValue(index);
},
interpret: null,
shared_js_values: [], // javascript objects accessible from Clean
js: [], // javascript objects accessible from Clean
shared_clean_values: [], // pointers to the Clean heap
apply_to_clean_value: function (index) {
ap: function (index) { // create a JavaScript closure to call the interpreter
var f=function () {
var args=[];
for (var i=0; i<arguments.length; i++)
args[i]=arguments[i];
abc_interpreter.interpret(SharedCleanValue(index), args);
ABC.interpret(SharedCleanValue(index), args);
};
f.shared_clean_value_index=index;
return f;
......@@ -85,98 +85,98 @@ const abc_interpreter={
copy_js_to_clean: function (values, store_ptrs, hp, hp_free, wrap_array) {
for (var i=0; i<values.length; i++) {
if (values[i]===null) {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=26*8+2; // INT
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=0;
abc_interpreter.memory_array[hp/4+3]=1<<30;
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=26*8+2; // INT
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=0;
ABC.memory_array[hp/4+3]=1<<30;
hp+=16;
hp_free-=2;
} else if (typeof values[i]=='undefined') {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=26*8+2; // INT
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=1;
abc_interpreter.memory_array[hp/4+3]=1<<30;
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=26*8+2; // INT
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=1;
ABC.memory_array[hp/4+3]=1<<30;
hp+=16;
hp_free-=2;
} else if (typeof values[i]=='number') {
// TODO use small integers
// TODO check garbage collection
if (Number.isInteger(values[i])) {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=26*8+2; // INT
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=values[i]; // TODO also support >32-bit
abc_interpreter.memory_array[hp/4+3]=0;
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=26*8+2; // INT
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=values[i]; // TODO also support >32-bit
ABC.memory_array[hp/4+3]=0;
hp+=16;
hp_free-=2;
} else {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=21*8+2; // REAL
abc_interpreter.memory_array[hp/4+1]=0;
const float_array=new Float64Array(abc_interpreter.memory_array.buffer, hp+8);
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=21*8+2; // REAL
ABC.memory_array[hp/4+1]=0;
const float_array=new Float64Array(ABC.memory_array.buffer, hp+8);
float_array[0]=values[i];
hp+=16;
hp_free-=2;
}
} else if (typeof values[i]=='boolean') {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=11*8+2; // BOOL
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=values[i] ? 1 : 0;
abc_interpreter.memory_array[hp/4+3]=0;
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=11*8+2; // BOOL
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=values[i] ? 1 : 0;
ABC.memory_array[hp/4+3]=0;
hp+=16;
hp_free-=2;
} else if (typeof values[i]=='string') {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=6*8+2; // _STRING_
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=values[i].length;
abc_interpreter.memory_array[hp/4+3]=0;
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=6*8+2; // _STRING_
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=values[i].length;
ABC.memory_array[hp/4+3]=0;
var array=new Int8Array(((values[i].length+3)>>2)<<2);
for (var j in values[i])
array[j]=values[i].charCodeAt(j);
array=new Uint32Array(array.buffer);
for (var j=0; j<((values[i].length+3)>>2); j++)
abc_interpreter.memory_array[hp/4+4+j]=array[j];
ABC.memory_array[hp/4+4+j]=array[j];
hp+=16+(((values[i].length+7)>>3)<<3);
hp_free-=2+((values[i].length+7)>>3);
} else if (Array.isArray(values[i])) {
abc_interpreter.memory_array[store_ptrs/4]=hp;
ABC.memory_array[store_ptrs/4]=hp;
if (wrap_array) {
abc_interpreter.memory_array[hp/4]=2;
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=hp+16;
abc_interpreter.memory_array[hp/4+3]=0;
ABC.memory_array[hp/4]=2;
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=hp+16;
ABC.memory_array[hp/4+3]=0;
hp+=16;
hp_free-=2;
}
abc_interpreter.memory_array[hp/4]=1*8+2; // _ARRAY_
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=values[i].length;
abc_interpreter.memory_array[hp/4+3]=0;
abc_interpreter.memory_array[hp/4+4]=0;
abc_interpreter.memory_array[hp/4+5]=0;
ABC.memory_array[hp/4]=1*8+2; // _ARRAY_
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=values[i].length;
ABC.memory_array[hp/4+3]=0;
ABC.memory_array[hp/4+4]=0;
ABC.memory_array[hp/4+5]=0;
hp+=24;
hp_free-=3;
var copied=abc_interpreter.copy_js_to_clean(values[i], hp, hp+8*values[i].length, hp_free, false);
var copied=ABC.copy_js_to_clean(values[i], hp, hp+8*values[i].length, hp_free, false);
hp=copied.hp;
hp_free=copied.hp_free-values[i].length;
} else if ('shared_clean_value_index' in values[i]) {
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=661*8+2; // DOMNode type
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=(values[i].shared_clean_value_index<<1)+1;
abc_interpreter.memory_array[hp/4+3]=0;
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=661*8+2; // DOMNode type
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=(values[i].shared_clean_value_index<<1)+1;
ABC.memory_array[hp/4+3]=0;
} else if (typeof values[i]=='object') {
// TODO: check if garbage collection is needed
abc_interpreter.memory_array[store_ptrs/4]=hp;
abc_interpreter.memory_array[hp/4]=661*8+2; // DOMNode type
abc_interpreter.memory_array[hp/4+1]=0;
abc_interpreter.memory_array[hp/4+2]=abc_interpreter.shared_js_values.length<<1;
abc_interpreter.memory_array[hp/4+3]=0;
abc_interpreter.shared_js_values.push(values[i]);
ABC.memory_array[store_ptrs/4]=hp;
ABC.memory_array[hp/4]=661*8+2; // DOMNode type
ABC.memory_array[hp/4+1]=0;
ABC.memory_array[hp/4+2]=ABC.js.length<<1;
ABC.memory_array[hp/4+3]=0;
ABC.js.push(values[i]);
hp+=16;
hp_free-=2;
} else {
......@@ -195,8 +195,8 @@ const abc_interpreter={
},
get_clean_string: function (hp_ptr) {
var size=abc_interpreter.memory_array[hp_ptr/4+2];
var string_buffer=new Uint8Array(abc_interpreter.memory.buffer, hp_ptr+16);
var size=ABC.memory_array[hp_ptr/4+2];
var string_buffer=new Uint8Array(ABC.memory.buffer, hp_ptr+16);
var string='';
for (var i=0; i<size; i++)
string+=String.fromCharCode(string_buffer[i]);
......@@ -204,42 +204,42 @@ const abc_interpreter={
},
};
abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
ABC.loading_promise=fetch('js/app.pbc').then(function(resp){
if (!resp.ok)
throw 'failed to fetch bytecode';
return resp.arrayBuffer();
}).then(function(bytecode){
abc_interpreter.prog=new Uint32Array(bytecode);
ABC.prog=new Uint32Array(bytecode);
const blocks_needed=Math.floor((abc_interpreter.prog.length*4 + abc_interpreter.stack_size + abc_interpreter.hp_size*2 + 65535) / 65536);
const blocks_needed=Math.floor((ABC.prog.length*4 + ABC.stack_size + ABC.hp_size*2 + 65535) / 65536);
abc_interpreter.memory=new WebAssembly.Memory({initial: blocks_needed});
abc_interpreter.memory_array=new Uint32Array(abc_interpreter.memory.buffer);
ABC.memory=new WebAssembly.Memory({initial: blocks_needed});
ABC.memory_array=new Uint32Array(ABC.memory.buffer);
for (var i in abc_interpreter.prog)
abc_interpreter.memory_array[i]=abc_interpreter.prog[i];
for (var i in ABC.prog)
ABC.memory_array[i]=ABC.prog[i];
(function(prog){
var i=0;
while (prog.length > 0) {
if (prog[0]==1) /* ST_Code section; see ABCInterpreter's bcprelink.c */
abc_interpreter.code_offset=i+1;
ABC.code_offset=i+1;
i+=1+prog[1];
prog=prog.slice(2+2*prog[1]);
}
})(abc_interpreter.prog);
})(ABC.prog);
return WebAssembly.instantiateStreaming(
fetch('js/abc-interpreter-util.wasm'),
{ clean: {
memory: abc_interpreter.memory,
memory: ABC.memory,
has_host_reference: function (index) {
if (abc_interpreter.shared_clean_values.length>index && abc_interpreter.shared_clean_values[index]!=null)
return abc_interpreter.shared_clean_values[index];
if (ABC.shared_clean_values.length>index && ABC.shared_clean_values[index]!=null)
return ABC.shared_clean_values[index];
return 0;
},
update_host_reference: function (index, new_location) {
abc_interpreter.shared_clean_values[index]=new_location;
ABC.shared_clean_values[index]=new_location;
},
debug: function(what,a,b,c) {
if (!ABC_DEBUG)
......@@ -254,54 +254,54 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
}}
);
}).then(function(util){
abc_interpreter.util=util;
ABC.util=util;
const interpreter_imports={
clean: {
memory: abc_interpreter.memory,
memory: ABC.memory,
debug_instr: function (addr, instr) {
if (MAX_INSTRUCTIONS-- == 0)
throw 'MAX_INSTRUCTIONS ran out';
if (ABC_DEBUG)
console.log(addr/8-abc_interpreter.code_offset,abc_instructions[instr]);
console.log(addr/8-ABC.code_offset,abc_instructions[instr]);
},
handle_illegal_instr: function (pc, instr, asp, bsp, csp, hp, hp_free) {
if (abc_instructions[instr]=='instruction') {
const arg=abc_interpreter.memory_array[(pc+8)/4];
const arg=ABC.memory_array[(pc+8)/4];
switch (arg) {
case 0: /* evaluation finished */
return 0;
case 1: /* iTasks.UI.JS.Interface: eval_js */
var string=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var string=ABC.get_clean_string(ABC.memory_array[asp/4]);
if (ABC_DEBUG)
console.log('eval',string);
Function(string)();
break;
case 2:
var string=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var string=ABC.get_clean_string(ABC.memory_array[asp/4]);
if (ABC_DEBUG)
console.log('eval',string);
var result=eval('('+string+')'); // the parentheses are needed for {}, for instance
var copied=abc_interpreter.copy_js_to_clean([result], asp, hp, hp_free, false);
abc_interpreter.interpreter.instance.exports.set_hp(copied.hp);
abc_interpreter.interpreter.instance.exports.set_hp_free(copied.hp_free);
var copied=ABC.copy_js_to_clean([result], asp, hp, hp_free, false);
ABC.interpreter.instance.exports.set_hp(copied.hp);
ABC.interpreter.instance.exports.set_hp_free(copied.hp_free);
break;
case 3: /* iTasks.UI.JS.Interface: share */
abc_interpreter.memory_array[bsp/4]=abc_interpreter.shared_clean_values.length;
abc_interpreter.shared_clean_values.push(abc_interpreter.memory_array[asp/4]);
ABC.memory_array[bsp/4]=ABC.shared_clean_values.length;
ABC.shared_clean_values.push(ABC.memory_array[asp/4]);
break;
case 4: /* iTasks.UI.JS.Interface: fetch */
var index=abc_interpreter.memory_array[bsp/4];
abc_interpreter.memory_array[asp/4]=abc_interpreter.shared_clean_values[index];
var index=ABC.memory_array[bsp/4];
ABC.memory_array[asp/4]=ABC.shared_clean_values[index];
break;
case 5: /* iTasks.UI.JS.Interface: deserialize */
var string=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var shared_clean_value=abc_interpreter.deserialize(string);
abc_interpreter.memory_array[asp/4]=abc_interpreter.shared_clean_values[shared_clean_value.shared_clean_value_index];
var string=ABC.get_clean_string(ABC.memory_array[asp/4]);
var shared_clean_value=ABC.deserialize(string);
ABC.memory_array[asp/4]=ABC.shared_clean_values[shared_clean_value.shared_clean_value_index];
break;
case 10: /* iTasks.UI.JS.Interface: add CSS */
var url=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var url=ABC.get_clean_string(ABC.memory_array[asp/4]);
var css=document.createElement('link');
css.rel='stylesheet';
css.type='text/css';
......@@ -310,8 +310,8 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
document.head.appendChild(css);
break;
case 11: /* iTasks.UI.JS.Interface: add JS */
var url=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4]);
var callback=abc_interpreter.get_clean_string(abc_interpreter.memory_array[asp/4-2]);
var url=ABC.get_clean_string(ABC.memory_array[asp/4]);
var callback=ABC.get_clean_string(ABC.memory_array[asp/4-2]);
var js=document.createElement('script');
js.type='text/javascript';
js.async=false;
......@@ -328,31 +328,31 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
return 0;
},
illegal_instr: function (addr, instr) {
abc_interpreter.empty_log_buffer();
ABC.empty_log_buffer();
if (abc_instructions[instr]=='instruction')
/* `instruction 0` ends the interpretation, so this is no error */
return;
throw ('illegal instruction '+instr+' ('+abc_instructions[instr]+') at address '+(addr/8-1));
},
out_of_memory: function () {
abc_interpreter.empty_log_buffer();
ABC.empty_log_buffer();
throw 'out of memory';
},
gc: util.instance.exports.gc,
halt: function (pc, hp_free, hp_size) {
abc_interpreter.empty_log_buffer();
throw ('halt at '+((pc/8)-abc_interpreter.code_offset));
ABC.empty_log_buffer();
throw ('halt at '+((pc/8)-ABC.code_offset));
},
memcpy: util.instance.exports.memcpy,
strncmp: util.instance.exports.strncmp,
putchar: function (v) {
abc_interpreter.log(String.fromCharCode(v));
ABC.log(String.fromCharCode(v));
},
print_int: function (high,low) {
if (high==0 && low>=0) {
abc_interpreter.log(low);
ABC.log(low);
} else {
var n=BigInt(high)*BigInt(2)**BigInt(32);
if (low<0) {
......@@ -360,17 +360,17 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
low+=2**31;
}
n+=BigInt(low);
abc_interpreter.log(n);
ABC.log(n);
}
},
print_bool: function (v) {
abc_interpreter.log(v==0 ? 'False' : 'True');
ABC.log(v==0 ? 'False' : 'True');
},
print_char: function (v) {
abc_interpreter.log("'"+String.fromCharCode(v)+"'");
ABC.log("'"+String.fromCharCode(v)+"'");
},
print_real: function (v) {
abc_interpreter.log(Number(0+v).toLocaleString(
ABC.log(Number(0+v).toLocaleString(
['en-US'],
{
useGrouping: false,
......@@ -397,11 +397,11 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
maximumSignificantDigits: 15,
}
);
abc_interpreter.memory_array[dest/4]=6*8+2; // __STRING__
abc_interpreter.memory_array[dest/4+1]=0;
abc_interpreter.memory_array[dest/4+2]=v.length;
abc_interpreter.memory_array[dest/4+3]=0;
var arr=new Uint8Array(abc_interpreter.memory_array.buffer, dest+16);
ABC.memory_array[dest/4]=6*8+2; // __STRING__
ABC.memory_array[dest/4+1]=0;
ABC.memory_array[dest/4+2]=v.length;
ABC.memory_array[dest/4+3]=0;
var arr=new Uint8Array(ABC.memory_array.buffer, dest+16);
for (var i=0; i<v.length; i++)
arr[i]=v.charCodeAt(i);
return dest+16+(((v.length+7)>>3)<<3);
......@@ -413,51 +413,51 @@ abc_interpreter.loading_promise=fetch('js/app.pbc').then(function(resp){
fetch('js/abc-interpreter.wasm'),
interpreter_imports);
}).then(function(intp){
abc_interpreter.interpreter=intp;
ABC.interpreter=intp;
const asp=4*abc_interpreter.prog.length;
const bsp=asp+abc_interpreter.stack_size;
const csp=asp+abc_interpreter.stack_size/2;
const asp=4*ABC.prog.length;
const bsp=asp+ABC.stack_size;
const csp=asp+ABC.stack_size/2;
const hp=bsp+8;
abc_interpreter.util.instance.exports.setup_gc(hp, abc_interpreter.hp_size, asp, 98*8);
ABC.util.instance.exports.setup_gc(hp, ABC.hp_size, asp, 98*8);
abc_interpreter.interpreter.instance.exports.set_asp(asp);
abc_interpreter.interpreter.instance.exports.set_bsp(bsp);
abc_interpreter.interpreter.instance.exports.set_csp(csp);
abc_interpreter.interpreter.instance.exports.set_hp(hp);
abc_interpreter.interpreter.instance.exports.set_hp_free(abc_interpreter.hp_size/8);
abc_interpreter.interpreter.instance.exports.set_hp_size(abc_interpreter.hp_size);
ABC.interpreter.instance.exports.set_asp(asp);
ABC.interpreter.instance.exports.set_bsp(bsp);
ABC.interpreter.instance.exports.set_csp(csp);
ABC.interpreter.instance.exports.set_hp(hp);
ABC.interpreter.instance.exports.set_hp_free(ABC.hp_size/8);
ABC.interpreter.instance.exports.set_hp_size(ABC.hp_size);
abc_interpreter.interpret=function (f, args) {
var asp=abc_interpreter.interpreter.instance.exports.get_asp();
ABC.interpret=function (f, args) {
var asp=ABC.interpreter.instance.exports.get_asp();
const old_asp=asp;
var hp=abc_interpreter.interpreter.instance.exports.get_hp();
var hp_free=abc_interpreter.interpreter.instance.exports.get_hp_free();
var hp=ABC.interpreter.instance.exports.get_hp();
var hp_free=ABC.interpreter.instance.exports.get_hp_free();
abc_interpreter.memory_array[asp/4]=(31+17*2)*8; // JSWorld: INT 17
abc_interpreter.memory_array[asp/4+2]=hp;
abc_interpreter.memory_array[asp/4+4]=abc_interpreter.shared_clean_values[f.shared_clean_value_index];
ABC.memory_array[asp/4]=(31+17*2)*8; // JSWorld: INT 17
ABC.memory_array[asp/4+2]=hp;
ABC.memory_array[asp/4+4]=ABC.shared_clean_values[f.shared_clean_value_index];
const copied=abc_interpreter.copy_js_to_clean([args], asp+8, hp, hp_free, true);
const copied=ABC.copy_js_to_clean([args], asp+8, hp, hp_free, true);
asp+=16;
hp=copied.hp;
hp_free=copied.hp_free;
var csp=abc_interpreter.interpreter.instance.exports.get_csp();
abc_interpreter.memory_array[csp/4]=659*8; // instruction 0; to return
var csp=ABC.interpreter.instance.exports.get_csp();
ABC.memory_array[csp/4]=659*8; // instruction 0; to return
csp+=8;
const old_pc=abc_interpreter.interpreter.instance.exports.get_pc();
abc_interpreter.interpreter.instance.exports.set_pc(100*8); // jmp_ap2
abc_interpreter.interpreter.instance.exports.set_asp(asp);
abc_interpreter.interpreter.instance.exports.set_csp(csp);
abc_interpreter.interpreter.instance.exports.set_hp(hp);
abc_interpreter.interpreter.instance.exports.set_hp_free(hp_free);
const old_pc=ABC.interpreter.instance.exports.get_pc();
ABC.interpreter.instance.exports.set_pc(100*8); // jmp_ap2
ABC.interpreter.instance.exports.set_asp(asp);
ABC.interpreter.instance.exports.set_csp(csp);
ABC.interpreter.instance.exports.set_hp(hp);
ABC.interpreter.instance.exports.set_hp_free(hp_free);
abc_interpreter.interpreter.