Verified Commit 87929ea7 authored by Camil Staps's avatar Camil Staps 🚀

Add string_to_graph for wasm

parent b6b0e540
......@@ -144,10 +144,10 @@ where
# d = d+symbol_offset
# s=store_int_in_string s (i+IF_INT_64_OR_32 16 8) (d-array_desc)
#! l = get_word_from_string s (i+IF_INT_64_OR_32 8 4)
| d==array_desc-6*8+2 // INT
| d==array_desc-5*8+2 // REAL
# l = l << IF_INT_64_OR_32 3 2
= replace_desc_numbers_by_descs (i+(IF_INT_64_OR_32 24 12)+l) s symbol_a symbol_offset array_desc
| d==array_desc-5*8+2 // REAL
| d==array_desc-6*8+2 // INT
# l = l << 3
= replace_desc_numbers_by_descs (i+(IF_INT_64_OR_32 24 12)+l) s symbol_a symbol_offset array_desc
| d==array_desc-3*8+2 // BOOL
......@@ -194,7 +194,7 @@ where
| d==array_desc-2*8+2 = (0,False) // _STRING_
| d==array_desc-3*8+2 = (1,True) // BOOL
| d==array_desc-4*8+2 = (1,True) // CHAR
| d==array_desc-5*8+2 = (IF_INT_64_OR_32 2 1,True) // REAL
| d==array_desc-5*8+2 = (IF_INT_64_OR_32 1 2,True) // REAL
| d==array_desc-6*8+2 = (1,True) // INT/dINT
| otherwise = abort "internal error in serialize_for_unrelocated_interpretation\n"
# arity = get_D_node_arity d
......
......@@ -95,6 +95,29 @@ intp = new Uint8Array(intp);
{
clean: {
memory: memory,
debug: function(what,a,b,c) {
switch (what) {
case 0:
console.log('loop',a,'/',b,'; hp at',c);
break;
case 1:
console.log('desc',a);
break;
case 2:
console.log('arity',a);
break;
case 3:
console.log('unimplemented:',['large hnf','thunk'][a]);
break;
case 4:
console.log('redirect',a,c,'(from',b,')');
break;
case 5:
console.log('a arity',a);
break;
}
}
}
}
);
......@@ -192,6 +215,20 @@ intp = new Uint8Array(intp);
});
}
var i=scriptArgs.indexOf('--graph');
if (i >= 0) {
var graph = os.file.readFile(scriptArgs[i+1], 'binary');
graph = new Uint32Array(graph.buffer);
var unused_semispace = util.instance.exports.get_unused_semispace();
for (var i=0; i<graph.length; i++)
membuffer[unused_semispace/4+i] = graph[i];
var node = hp;
hp = util.instance.exports.copy_from_string(unused_semispace,graph.length/2,asp,bsp,hp,code_offset*8);
asp+=8;
membuffer[asp/4] = node;
start+=32; /* skip bootstrap to build start node; jump to _print_graph */
}
var time_start=new Date().getTime();
var r=intp.instance.exports.interpret(start, asp, bsp, csp, hp, heap_size/8);
......
This diff is collapsed.
......@@ -210,22 +210,23 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
}
/* not a basic type */
a_arity=arity;
if (arity>256) {
a_arity=((int16_t*)desc)[0];
arity-=256;
}
ie->hp[0]=desc;
if (arity==0) {
desc-=10;
**ptr_stack--=desc;
s[i]=desc;
*--a_size_stack=0;
continue;
} else if (arity==1) {
**ptr_stack--=(BC_WORD)ie->hp;
}
**ptr_stack--=(BC_WORD)ie->hp;
ie->hp[0]=desc;
if (arity==1) {
if (a_arity==1)
*++ptr_stack=&ie->hp[1];
else
......@@ -234,7 +235,6 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
*--a_size_stack=1;
continue;
} else if (arity==2) {
**ptr_stack--=(BC_WORD)ie->hp;
if (a_arity==2) {
ptr_stack[2]=&ie->hp[1];
ptr_stack[1]=&ie->hp[2];
......@@ -253,7 +253,6 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
}
/* large hnf */
**ptr_stack--=(BC_WORD)ie->hp;
ie->hp[2]=(BC_WORD)&ie->hp[3];
if (a_arity==0) {
......@@ -273,9 +272,6 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
ie->hp+=arity+2;
*--a_size_stack = a_arity;
} else { /* thunk */
**ptr_stack--=(BC_WORD)ie->hp;
ie->hp[0]=desc;
int32_t arity=((int32_t*)desc)[-1];
int16_t a_arity=arity;
......@@ -286,8 +282,12 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
arity&=0xff;
}
**ptr_stack--=(BC_WORD)ie->hp;
ie->hp[0]=desc;
ie->hp++;
*--a_size_stack = a_arity;
for (int a=0; a<a_arity; a++)
ptr_stack[a_arity-a]=&ie->hp[a];
ptr_stack+=a_arity;
......@@ -296,8 +296,6 @@ BC_WORD *string_to_interpreter(uint64_t *clean_string, struct interpretation_env
ie->hp[b]=s[++i];
ie->hp+=arity<3 ? 2 : arity;
*--a_size_stack = a_arity;
}
}
......
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