--- gforth/quotations.fs 2011/12/16 21:18:01 1.1 +++ gforth/quotations.fs 2011/12/18 21:38:56 1.2 @@ -2,16 +2,24 @@ :noname false :noname ; :noname locals-wordlist last @ lastcfa @ - postpone SCOPE postpone AHEAD true :noname ; -interpret/compile: [: + postpone AHEAD + locals-list @ locals-list off + locals-dp @ dup >r postpone SCOPE + true :noname r> locals-dp ! ; +interpret/compile: [: ( -- quotation-sys ) +\G Starts a quotation -: ;] ( compile-time: orig colon-sys -- ; run-time: -- xt ) +: ;] ( compile-time: quotation-sys -- ; run-time: -- xt ) + \g ends a quotation POSTPONE ; >r IF - ] postpone THEN r> postpone ALiteral postpone ENDSCOPE + ] postpone ENDSCOPE + locals-dp ! locals-list ! + postpone THEN lastcfa ! last ! to locals-wordlist + r> postpone ALiteral ELSE r> THEN ( xt ) ; immediate -\\\ +0 [IF] \ tests : if-else ( ... f xt1 xt2 -- ... ) \ Postscript-style if-else rot IF @@ -28,3 +36,10 @@ interpret/compile: [: 1 test cr \ writes "true" 0 test cr \ writes "false" + +\ locals within quotations + +: foo { a b } a b + [: { x y } x y + ;] execute . a . b . ; +2 3 foo +[THEN] \ No newline at end of file