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

Change wasm garbage collector interface so that it does not require an i64 any...

Change wasm garbage collector interface so that it does not require an i64 any more (so that it can be run from JavaScript later)
parent b5f44ea2
Pipeline #22025 passed with stages
in 13 minutes and 13 seconds
......@@ -9,6 +9,10 @@
(func $has-host-reference (import "clean" "has_host_reference") (param i32) (result i32))
(func $update-host-reference (import "clean" "update_host_reference") (param i32 i32))
(func $get-asp (import "clean" "get_asp") (result i32))
(func $set-hp (import "clean" "set_hp") (param i32))
(func $set-hp-free (import "clean" "set_hp_free") (param i32))
(global $start-heap (mut i32) (i32.const 0))
(global $half-heap (mut i32) (i32.const 0))
(global $end-heap (mut i32) (i32.const 0))
......@@ -137,9 +141,8 @@
)
)
;; upper half of result is new hp pointer;
;; lower half is hp-free
(func (export "gc") (param $asp i32) (result i64)
(func (export "gc")
(local $asp i32)
(local $old i32)
(local $new i32)
(local $n i32)
......@@ -148,6 +151,8 @@
(local $arity i32)
(local $size i32)
(local.set $asp (call $get-asp))
(if
(global.get $in-first-semispace)
(then
......@@ -416,18 +421,15 @@
;; return
(global.set $in-first-semispace (i32.sub (i32.const 1) (global.get $in-first-semispace)))
(i64.or
(i64.shl (i64.extend_i32_u (local.get $new)) (i64.const 32))
(i64.extend_i32_u
(i32.shr_u
(i32.sub
(select (global.get $half-heap) (global.get $end-heap) (global.get $in-first-semispace))
(local.get $new)
)
(i32.const 3)
(call $set-hp (local.get $new))
(call $set-hp-free
(i32.shr_u
(i32.sub
(select (global.get $half-heap) (global.get $end-heap) (global.get $in-first-semispace))
(local.get $new)
)
)
)
(i32.const 3)
))
)
(func $update-ref (param $ref i32) (param $hp i32) (result i32)
......
......@@ -102,6 +102,10 @@ intp = new Uint8Array(intp);
update_host_reference: function(index,new_location) {
},
get_asp: () => intp.instance.exports.get_asp(),
set_hp: hp => intp.instance.exports.set_hp(hp),
set_hp_free: free => intp.instance.exports.set_hp_free(free),
debug: function(what,a,b,c) {
switch (what) {
case 0:
......
......@@ -324,7 +324,7 @@ where
, "(func $clean_handle_illegal_instr (import \"clean\" \"handle_illegal_instr\") (param i32 i32 i32 i32 i32 i32 i32) (result i32))"
, "(func $clean_illegal_instr (import \"clean\" \"illegal_instr\") (param i32 i32))"
, "(func $clean_out_of_memory (import \"clean\" \"out_of_memory\"))"
, "(func $clean_gc (import \"clean\" \"gc\") (param i32) (result i64))"
, "(func $clean_gc (import \"clean\" \"gc\"))"
, "(func $clean_halt (import \"clean\" \"halt\") (param i32 i32 i32))"
] ++
[ "(global $"+++g+++" (mut i64) (i64.const 0))" \\ g <- global_vars ] ++
......@@ -343,11 +343,10 @@ where
global_vars = ["pc","asp","bsp","csp","hp","hp_size","hp_free"]
end =
[ ")" // block abc-gc
, "(global.set $vi0 (call $clean_gc (i32.wrap_i64 (global.get $asp))))"
, "(global.set $hp (i64.shr_u (global.get $vi0) (i64.const 32)))"
, "(if (i64.le_s (i64.and (global.get $vi0) (i64.const 0xffffffff)) (global.get $hp_free))"
, "(global.set $vi0 (global.get $hp_free))"
, "(call $clean_gc)"
, "(if (i64.le_s (global.get $hp_free) (global.get $vi0))"
, "\t(then (call $clean_out_of_memory) (unreachable)))"
, "(global.set $hp_free (i64.and (global.get $vi0) (i64.const 0xffffffff)))"
, "(br $abc-loop)"
, ")" // loop abc-loop
, "(unreachable)"
......
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