Make prim_js2idris_array iterative (#2267)

I was getting a stack overflow on the tailrec002 test, caused by this
primitive being recursive. I've made it iterative. I'm no JS expert but
I've tested its behaviour against the old version.
This commit is contained in:
Edwin Brady 2022-01-16 19:15:26 +00:00 committed by GitHub
parent 3ef46f639e
commit 26a47ddafe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -1,11 +1,12 @@
class IdrisError extends Error { }
function __prim_js2idris_array(x){
if(x.length === 0){
return {h:0}
} else {
return {a1:x[0],a2: __prim_js2idris_array(x.slice(1))}
let acc = { h:0 };
for (i = x.length-1; i>=0; i--) {
acc = { a1:x[i], a2:acc };
}
return acc;
}
function __prim_idris2js_array(x){

View File

@ -1,4 +1,4 @@
rm -rf build
$1 --no-color --console-width 0 --no-banner --cg node EvenOdd.idr -o app.js
$1 --no-color --console-width 0 --no-banner Main.idr -x main
rm -rf build