diff --git a/examples/hello.tal b/examples/hello.tal index b3f97ae..9114a22 100644 --- a/examples/hello.tal +++ b/examples/hello.tal @@ -2,13 +2,17 @@ |0100 @program + { "hello $1 } print-str + { 01 02 03 04 05 } { LIT "0 ADD #18 DEO } foreach + ;hello-word print-str + + #010e DEO #800f DEO BRK @print-str ( str* -- ) - &while ( send ) LDAk #18 DEO ( loop ) INC2 LDAk ?&while @@ -16,6 +20,17 @@ BRK JMP2r +@foreach ( arr* fn* -- ) + STH2 + DUP2 + DUP2 #0002 SUB2 LDA2 ADD2 #0001 SUB2 + SWP2 + &l + LDAk STH2kr JSR2 + INC2 NEQ2k ?&l + POP2 POP2 POP2r +JMP2r + $100 @label2 ~examples/include.tal diff --git a/src/drifblim.tal b/src/drifblim.tal index 01b1273..f051bb4 100644 --- a/src/drifblim.tal +++ b/src/drifblim.tal @@ -69,12 +69,12 @@ [ LIT2 01 -File2/delete ] DEO #0001 .File2/length DEO2 ( | clear memory ) - ;create-symbol/ptr LDA2 ;memory + ;/ptr LDA2 ;memory ( | cleanup cache ) [ LIT2 00 -qerror ] STZ #0000 ;/len STA2 - ;memory/symbols ;create-symbol/ptr STA2 - #0000 ;create-symbol/count STA2 + ;memory/symbols ;/ptr STA2 + #0000 ;/count STA2 ( scan pass ) #01 handle-top ?&when-error ( write pass ) #00 handle-top ?&when-error save-symbols ! @@ -85,6 +85,7 @@ @handle-top ( scan -- err ) .scan STZ #0100 + #00 ;lambda-push/count STA ;dict/reset ;src/buf handle-file .qerror LDZ JMP2r @@ -146,7 +147,7 @@ &toplab ( t* -- ) INC2 ! &sublab ( t* -- ) - INC2 make-sublabel !create-symbol + INC2 make-sublabel ! &litrel ( t* -- ) #80 &rawrel ( t* -- ) @@ -170,6 +171,10 @@ ! &rawstr ( t* -- ) INC2 !/ + &lampus ( t* -- ) + POP2 !lambda-push + &lampop ( t* -- ) + POP2 !lambda-pop &inc ( t* -- ) INC2k ;memory/include STH2k @@ -177,6 +182,31 @@ &ignore ( t* -- ) POP2 JMP2r +@lambda-push ( -- ) + [ LIT &count $1 ] + ( ) INCk ,&count STR + ( ) DUP stack/push + ( ) LIT "0 ADD ,&id STR + ;&sym #60 ! + &sym "la &id "0 $1 + +@lambda-pop ( -- ) + stack/pop LIT "0 ADD ;&id STA + #6c + ;&sym + #6f + JMP2r + &sym "la &id "0 $1 + +@stack &ptr =memory/lambda + &push ( id -- ) + ,&ptr LDR2 INC2k ,&ptr STR2 + STA + JMP2r + &pop ( -- id ) + ,&ptr LDR2 #0001 SUB2 DUP2 ,&ptr STR2 + LDA JMP2r + ( @|primitives ) @@ -259,7 +289,7 @@ #00 STHr INC ,make-sublabel/ptr STR2 ( >> ) -@create-symbol ( name* -- ) +@ ( name* -- ) .scan LDZ ?&>continue POP2 JMP2r &>continue ( not hex ) is-hex ?&invalid @@ -289,7 +319,7 @@ @find-symbol ( name* -- * ) ,&t STR2 - ;create-symbol/ptr LDA2 ;memory/symbols + ;/ptr LDA2 ;memory/symbols &l ( -- ) #0003 ADD2 DUP2 [ LIT2 &t $2 ] scmp ?&found scap/ INC2 GTH2k ?&l @@ -366,7 +396,7 @@ .File1/success DEI2 #0000 EQU2 JMP2r @ ( -- ) - ;create-symbol/ptr LDA2 ;memory/symbols + ;/ptr LDA2 ;memory/symbols &l ( -- ) INC2k INC2 LDA ?&>skip #0003 ADD2 LDAk [ LIT "A ] SUB #1a LTH ?&>skip @@ -384,7 +414,7 @@ ;dict/in / ;/len LDA2 #00ff SUB2 ;dict/bytes / - ;create-symbol/count LDA2 + ;/count LDA2 ;dict/labels / ;dict/end !/ @@ -544,6 +574,7 @@ "; =lib/litabs "= =lib/rawabs "? =lib/litjci "! =lib/litjmi 5b =lib/ignore 5d =lib/ignore + "{ =lib/lampus "} =lib/lampop "# =lib/lithex "" =lib/rawstr "~ =lib/inc ] &end @@ -553,6 +584,7 @@ @memory ( buffers ) &include $30 + &lambda $100 &symbols ( addr*, refs, name[], 00 )