Fix bug and comment more on the pains of recursion

This commit is contained in:
Brendan Hansknecht 2021-09-29 21:05:36 -07:00
parent 414f3a0438
commit 157a04d1ac
3 changed files with 32 additions and 6 deletions

View File

@ -160,8 +160,9 @@ interpretContext = \ctx ->
Ok a -> interpretContext a
# Being explicit with error type is required to stop the need to propogate the error parameters to Context.popStack
Err EmptyStack -> Task.fail EmptyStack
0xC3 -> # `ø` pick
0xC3 -> # `ø` pick or `ß` flush
# this is actually 2 bytes, 0xC3 0xB8
# or it is 0xC3 0x9F
result2 <- Task.attempt (Context.getChar (Context.consumeChar newCtx))
when result2 is
Ok (T 0xB8 newCtx2) ->
@ -178,6 +179,9 @@ interpretContext = \ctx ->
when result3 is
Ok a -> interpretContext a
Err e -> Task.fail e
Ok (T 0x9F newCtx2) ->
# This is supposed to flush io buffers. We don't buffer, so it does nothing
interpretContext (Context.consumeChar newCtx2)
Ok (T x _) ->
data = Str.fromInt (Num.intCast x)
Task.fail (InvalidChar data)
@ -197,6 +201,9 @@ interpretContext = \ctx ->
when result2 is
Ok a -> interpretContext a
Err e -> Task.fail e
0x42 -> # `B` also treat this as flush for easier script writing
# This is supposed to flush io buffers. We don't buffer, so it does nothing
interpretContext (Context.consumeChar newCtx)
0x27 -> # `'` load next char
result2 <- Task.attempt (Context.getChar (Context.consumeChar newCtx))
when result2 is
@ -299,9 +306,6 @@ interpretContext = \ctx ->
0x7B -> # `{` comment start
afterCommentCtx <- Task.await (consumeComment (Context.consumeChar newCtx))
interpretContext afterCommentCtx
0xE1 -> # `ß` flush
# This is supposed to flush io buffers. We don't buffer, so it does nothing
interpretContext (Context.consumeChar newCtx)
x if isDigit x -> # number start
afterNumberCtx <- Task.await (pushNumber newCtx)
interpretContext afterNumberCtx

View File

@ -1,4 +1,9 @@
{ This currently doesn't run cause the interpreter will stack overflow, even in optimized build}
{
This currently doesn't run cause the interpreter will stack overflow, even in optimized build
I tried to run this with unlimited stack size, but I gave up after it used 24+ GB of my memory on stack space.
This is just to do the CRC32 of the letter a, which runs essentially instantly in one of the JS interpreters.
Maybe a really need to model things differently to help Roc figure out how to optimize or otherwise avoid essentially infinite recursion
}
{ unix cksum, CRC32. -- Jonathan Neuschäfer <j.neuschaefer@gmx.net> }
[[$0>][\2*\1-]#%]l:[0\128[$0>][$2O&0>[$@\64/x;!@@$g;*@x;!@@]?2/]#%%]h:
@ -6,4 +11,4 @@
[q1_0[\1+\^$1_>]s;#%@%\$@[1O0>][1O255&s;!\8r;!\]#~n;!32,%.10,]m:[$2O&@@|~|~]x:
[$0\>\1O[$u;!]?\~[$.]?%]n:[h;y:[3+O]h:255[$0>][$y;!\1-]#m;!256[$0>][\%1-]#%]o:
[1000$$**0@[$$0\>\4O\>~|][2O-\1+\]#\.\[10/$0>][\$2O/$.2O*-\]#%%]u: {width: 78}
{ usage: run m for "main" or o for "optimized" (builds a lookup table) } o;!
{ usage: run m for "main" or o for "optimized" (builds a lookup table) } m;!

View File

@ -0,0 +1,17 @@
{ queens }
{ solves the problem of placing n queens on a }
{ n*n chessboard without attacking eachother }
{ written in false }
{ by Marcel van Kervinck }
{ e-mail <marcelk@stack.urc.tue.nl> }
{ June 1994 }
[$0=$[1\]?~[0 2O[$0=~][$$_&$7O7O|_1-&[@1O7O|$+2
O7O|2/3O_1-7O&6O1-q;!+@@]?_1-&]#%]?\%\%\%\%]q:
"enter number of queens [0..9] "B^B'0-
0$@$1[1O0>][$+\1-\]#1-\%\q;!." solutions
"
{ that's all }