on master help sign in
Bug fix for infinite loop while executing a callback in the Javascript runtime.

The NULL BC operation, which is supposed to clear a register (according to the docs) was translated as delete in the Javascript backend. This worked fine for clearing registers from the stack, but did not work well while trying to clear i$RT. This cause an infinite loop in i$ffiWrap which was checking the return value should have been cleared but continued to hold its old value (essentially ignoring the delete operation). Callbacks work fine now in my tests.

commit3bbaf1e5e35a09b73f8623aaa13c25aa8bc74d3a authorAaron Craelius <aaroncraelius@gmail.com> dateTue 1 Dec 2015, 22:23 (11 years ago) parent10a22eb
2 files changed+5−3
src/IRTS/CodegenJavaScript.hs+1−2 src/IRTS/JavaScript/AST.hs+4−1
src/IRTS/CodegenJavaScript.hs+1−2
@@ -604,7 +604,7 @@ jsBASETOP _ 0 = JSAssign jsSTACKBASE jsSTACKTOP
604604jsBASETOP _ n = JSAssign jsSTACKBASE (JSBinOp "+" jsSTACKTOP (JSNum (JSInt n)))
605605
606606jsNULL :: CompileInfo -> Reg -> JS
607−jsNULL _ r = JSDelete (translateReg r)
607+jsNULL _ r = JSClear (translateReg r)
608608
609609jsERROR :: CompileInfo -> String -> JS
610610jsERROR _ = JSError
@@ -1277,4 +1277,3 @@ toFType (FApp c [_,ity])
12771277toFType (FApp c [_,fty])
12781278 | c == sUN "JS_FnT" = toFnType fty
12791279toFType t = error (show t ++ " not yet defined in toFType")
1280−
src/IRTS/JavaScript/AST.hs+4−1
@@ -77,6 +77,7 @@ data JS = JSRaw String
7777 | JSFFI String [JS]
7878 | JSAnnotation JSAnnotation JS
7979 | JSDelete JS
80+ | JSClear JS
8081 | JSNoop
8182 deriving Eq
8283
@@ -133,6 +134,9 @@ compileJS' indent (JSAnnotation annotation js) =
133134compileJS' indent (JSDelete js) =
134135 "delete " `T.append` compileJS' 0 js
135136
137+compileJS' indent (JSClear js) =
138+ compileJS' 0 js `T.append` " = undefined"
139+
136140compileJS' indent (JSFFI raw args) =
137141 ffi raw (map (T.unpack . compileJS' indent) args)
138142
@@ -398,4 +402,3 @@ jsPackSBits16 js = JSNew "Int16Array" [JSArray [js]]
398402
399403jsPackSBits32 :: JS -> JS
400404jsPackSBits32 js = JSNew "Int32Array" [JSArray [js]]
401−