4 include term-colours.4th
6 include catch-throw.4th
30 make-type boolean-type
31 make-type character-type
37 make-type primitive-proc-type
38 make-type compound-proc-type
39 make-type fileport-type
40 : istype? ( obj type -- obj bool )
45 \ ---- Exceptions ---- {{{
47 variable nextexception
50 create nextexception @ ,
54 make-exception recoverable-exception
55 make-exception unrecoverable-exception
57 : display-exception-msg ( addr count -- )
70 ['] display-exception-msg ,
78 \ ---- List-structured memory ---- {{{
80 10000 constant scheme-memsize
82 create car-cells scheme-memsize allot
83 create car-type-cells scheme-memsize allot
84 create cdr-cells scheme-memsize allot
85 create cdr-type-cells scheme-memsize allot
87 create nextfrees scheme-memsize allot
98 nextfrees nextfree @ + @
101 nextfree @ scheme-memsize >= if
105 nextfree @ scheme-memsize >= if
106 unrecoverable-exception throw s" Out of memory!"
110 : cons ( car-obj cdr-obj -- pair-obj )
111 cdr-type-cells nextfree @ + !
112 cdr-cells nextfree @ + !
113 car-type-cells nextfree @ + !
114 car-cells nextfree @ + !
120 : car ( pair-obj -- car-obj )
122 dup car-cells + @ swap
126 : cdr ( pair-obj -- car-obj )
128 dup cdr-cells + @ swap
132 : set-car! ( obj pair-obj -- )
134 rot swap car-type-cells + !
138 : set-cdr! ( obj pair-obj -- )
140 rot swap cdr-type-cells + !
145 : nil? nil-type istype? ;
148 : none? none-type istype? ;
150 : objvar create nil swap , , ;
152 : value@ ( objvar -- val ) @ ;
153 : type@ ( objvar -- type ) 1+ @ ;
154 : value! ( newval objvar -- ) ! ;
155 : type! ( newtype objvar -- ) 1+ ! ;
156 : obj! ( newobj objvar -- ) dup rot swap 1+ ! ! ;
157 : obj@ ( objvar -- obj ) dup @ swap 1+ @ ;
159 : objeq? ( obj obj -- bool )
162 : 2rot ( a1 a2 b1 b2 c1 c2 -- b1 b2 c1 c2 a1 a2 )
163 >R >R ( a1 a2 b1 b2 )
164 2swap ( b1 b2 a1 a2 )
165 R> R> ( b1 b2 a1 a2 c1 c2 )
169 : -2rot ( a1 a2 b1 b2 c1 c2 -- c1 c2 a1 a2 b1 b2 )
170 2swap ( a1 a2 c1 c2 b1 b2 )
171 >R >R ( a1 a2 c1 c2 )
172 2swap ( c1 c2 a1 a2 )
178 \ ---- Port I/O ---- {{{
180 : fileport>fid ( fileport -- fid )
183 : fid>fileport ( fid -- fileport )
186 : open-input-file ( addr n -- fileport )
187 r/o open-file drop fid>fileport
190 : close-port ( fileport -- )
191 fileport>fid close-file drop
194 objvar console-i/o-port
195 0 fileport-type console-i/o-port obj!
197 objvar current-input-port
198 console-i/o-port obj@ current-input-port obj!
200 : read-port ( fileport -- obj )
201 current-input-port obj!
204 : read-console ( -- obj )
205 console-i/o-port obj@ read-port ;
209 \ ---- Pre-defined symbols ---- {{{
213 : duplicate-charlist ( charlist -- copy )
215 2dup car 2swap cdr recurse cons
218 : charlist-equiv ( charlist charlist -- bool )
227 2drop 2drop true exit
229 2drop 2drop false exit
234 2drop 2drop false exit
241 car drop -rot car drop = if
242 cdr 2swap cdr recurse
248 : charlist>symbol ( charlist -- symbol-obj )
267 drop symbol-type 2dup
268 symbol-table obj@ cons
273 : cstr>charlist ( addr n -- charlist )
277 2dup drop @ character-type 2swap
285 : create-symbol ( -- )
293 does> dup @ swap 1+ @
296 create-symbol quote quote-symbol
297 create-symbol quasiquote quasiquote-symbol
298 create-symbol unquote unquote-symbol
299 create-symbol unquote-splicing unquote-splicing-symbol
300 create-symbol define define-symbol
301 create-symbol define-macro define-macro-symbol
302 create-symbol set! set!-symbol
303 create-symbol ok ok-symbol
304 create-symbol if if-symbol
305 create-symbol lambda lambda-symbol
306 create-symbol λ λ-symbol
307 create-symbol begin begin-symbol
309 \ Symbol to be bound to welcome message procedure by library
310 create-symbol welcome welcome-symbol
314 \ ---- Environments ---- {{{
316 : enclosing-env ( env -- env )
319 : first-frame ( env -- frame )
322 : make-frame ( vars vals -- frame )
325 : frame-vars ( frame -- vars )
328 : frame-vals ( frame -- vals )
331 : add-binding ( var val frame -- )
332 2swap 2over frame-vals cons
334 2swap 2over frame-vars cons
338 : extend-env ( vars vals env -- env )
348 : get-vars-vals-frame ( var frame -- bool )
349 2dup frame-vars vars obj!
353 vars obj@ nil objeq? false =
355 2dup vars obj@ car objeq? if
360 vars obj@ cdr vars obj!
361 vals obj@ cdr vals obj!
367 : get-vars-vals ( var env -- vars? vals? bool )
372 2over 2over first-frame
373 get-vars-vals-frame if
375 vars obj@ vals obj@ true
389 : lookup-var ( var env -- val )
393 recoverable-exception throw" Tried to read unbound variable."
397 : set-var ( var val env -- )
398 >R >R 2swap R> R> ( val var env )
400 2swap 2drop ( val vals )
403 recoverable-exception throw" Tried to set unbound variable."
409 : define-var ( var val env -- )
412 2over env obj@ ( var val var env )
414 2swap 2drop ( var val vals )
419 first-frame ( var val frame )
426 : make-procedure ( params body env -- proc )
429 drop compound-proc-type
433 nil nil nil extend-env
438 \ ---- Primitives ---- {{{
440 : make-primitive ( cfa -- )
447 rot primitive-proc-type ( var prim )
448 global-env obj@ define-var
451 : ensure-arg-count ( args n -- )
453 drop nil objeq? false = if
454 recoverable-exception throw" Too many arguments for primitive procedure."
458 recoverable-exception throw" Too few arguments for primitive procedure."
465 : ensure-arg-type-and-count ( tn tn-1 ... t2 t1 args n -- )
467 drop nil objeq? false = if
468 recoverable-exception throw" Too many arguments for primitive procedure."
472 recoverable-exception throw" Too few arguments for primitive procedure."
475 2dup cdr 2swap car ( ... t1 n args' arg1 )
476 2rot 1- swap 2swap rot ( ... args' n-1 arg1 t1 )
478 recoverable-exception throw" Incorrect type for primitive procedure."
486 : push-args-to-stack ( args -- arg1 arg2 ... argn )
496 : add-fa-checks ( cfa n -- cfa' )
497 here current @ 1+ dup @ , !
501 ['] 2dup , ['] lit , , ['] ensure-arg-count ,
502 ['] push-args-to-stack ,
503 ['] lit , , ['] execute ,
507 : add-fa-type-checks ( cfa t1 t2 ... tn n -- cfa' )
508 here current @ 1+ dup @ , !
515 dup ( cfa t1 t2 ... tn n m )
520 rot ['] lit , , ( cfa t1 t2 ... tn-1 n m )
526 ['] lit , , ['] ensure-arg-type-and-count ,
528 ['] push-args-to-stack ,
529 ['] lit , , ['] execute ,
535 : make-fa-primitive ( cfa n -- )
536 add-fa-checks make-primitive ;
538 : make-fa-type-primitive ( cfa t1 t2 ... tn n -- )
539 add-fa-type-checks make-primitive ;
542 bold fg red ." Incorrect argument type." reset-term cr
546 : ensure-arg-type ( arg type -- arg )
548 recoverable-exception throw" Incorrect argument type for primitive procedure."
555 \ ---- Macros ---- {{{
559 ( Look up macro in macro table. Returns nil if
561 : lookup-macro ( name_symbol -- proc )
580 : make-macro ( name_symbol params body env -- )
583 2swap ( proc name_symbol )
590 2over 2over ( proc name table name table )
592 2swap 2drop ( proc table )
604 macro-table obj@ cons
613 variable stored-parse-idx
614 create parse-str 161 allot
615 variable parse-str-span
617 create parse-idx-stack 10 allot
618 variable parse-idx-sp
619 parse-idx-stack parse-idx-sp !
622 parse-idx @ parse-idx-sp @ !
627 parse-idx-sp @ parse-idx-stack <= abort" Parse index stack underflow."
631 parse-idx-sp @ @ parse-idx ! ;
635 '\n' parse-str parse-str-span @ + !
636 1 parse-str-span +! ;
639 4 parse-str parse-str-span @ + !
640 1 parse-str-span +! ;
647 current-input-port obj@ console-i/o-port obj@ objeq? if
648 parse-str 160 expect cr
649 span @ parse-str-span !
651 parse-str 160 current-input-port obj@ fileport>fid read-line
652 drop swap parse-str-span !
654 parse-str-span @ 0= and if append-eof then
665 : charavailable? ( -- bool )
666 parse-str-span @ parse-idx @ > ;
668 : nextchar ( -- char )
669 charavailable? false = if getline then
670 parse-str parse-idx @ + @ ;
673 : whitespace? ( -- bool )
685 nextchar [char] ( = or
686 nextchar [char] ) = or
689 : commentstart? ( -- bool )
690 nextchar [char] ; = ;
694 false \ Indicates whether or not we're eating a comment
697 dup whitespace? or commentstart? or
699 dup nextchar '\n' = and if
700 invert \ Stop eating comment
702 dup false = commentstart? and if
703 invert \ Begin eating comment
718 nextchar [char] - = ;
721 nextchar [char] + = ;
723 : fixnum? ( -- bool )
749 : flonum? ( -- bool )
756 \ Record starting parse idx:
757 \ Want to detect whether any characters (following +/-) were eaten.
764 [char] . nextchar = if
771 [char] e nextchar = [char] E nextchar = or if
779 drop pop-parse-idx false exit
787 \ This is a real number if characters were
788 \ eaten and the next characer is a delimiter.
789 parse-idx @ < delim? and
794 : ratnum? ( -- bool )
802 pop-parse-idx false exit
811 [char] / nextchar <> if
812 pop-parse-idx false exit
818 pop-parse-idx false exit
830 : boolean? ( -- bool )
831 nextchar [char] # <> if false exit then
838 and if pop-parse-idx false exit then
850 : str-equiv? ( str -- bool )
867 delim? false = if drop false then
872 : character? ( -- bool )
873 nextchar [char] # <> if false exit then
878 nextchar [char] \ <> if pop-parse-idx false exit then
882 S" newline" str-equiv? if pop-parse-idx true exit then
883 S" space" str-equiv? if pop-parse-idx true exit then
884 S" tab" str-equiv? if pop-parse-idx true exit then
886 charavailable? false = if pop-parse-idx false exit then
892 nextchar [char] ( = ;
894 : string? ( -- bool )
895 nextchar [char] " = ;
897 : readfixnum ( -- fixnum )
908 10 * nextchar [char] 0 - +
917 : readflonum ( -- flonum )
921 [char] . nextchar = if
927 nextchar [char] 0 - i->f ( f exp d )
928 over f/ rot f+ ( exp f' )
929 swap 10.0 f* ( f' exp' )
936 [char] e nextchar = [char] E nextchar = or if
950 : make-rational ( fixnum fixnum -- ratnum|fixnum )
957 fixnum-type swap fixnum-type
958 cons drop ratnum-type
962 : readratnum ( -- ratnum )
963 readfixnum inc-parse-idx readfixnum
967 : readbool ( -- bool-obj )
970 nextchar [char] f = if
981 : readchar ( -- char-obj )
985 S" newline" str-equiv? if 7 parse-idx +! '\n' character-type exit then
986 S" space" str-equiv? if 5 parse-idx +! bl character-type exit then
987 S" tab" str-equiv? if 3 parse-idx +! 9 character-type exit then
989 nextchar character-type
994 : readstring ( -- charlist )
1001 nextchar [char] \ = if
1004 [char] n of '\n' endof
1005 [char] " of [char] " endof
1011 inc-parse-idx character-type
1014 ( firstchar prevchar thischar )
1017 2drop 2swap 2drop 2dup ( thischar thischar )
1019 ( firstchar thischar prevchar )
1020 2over 2swap set-cdr! ( firstchar thischar )
1024 \ Discard previous character
1030 ." No delimiter following right double quote. Aborting." cr
1042 : readsymbol ( -- charlist )
1043 delim? if nil exit then
1045 nextchar inc-parse-idx character-type
1052 : readpair ( -- pairobj )
1056 nextchar [char] ) = if
1061 ." No delimiter following right paren. Aborting." cr
1070 \ Read first pair element
1075 nextchar [char] . = if
1080 ." No delimiter following '.'. Aborting." cr
1094 \ Parse a scheme expression
1129 nextchar [char] " <> if
1130 bold red ." Missing closing double-quote." reset-term cr
1148 nextchar [char] ) <> if
1149 bold red ." Missing closing paren." reset-term cr
1158 nextchar [char] ' = if
1160 quote-symbol recurse nil cons cons exit
1163 nextchar [char] ` = if
1165 quasiquote-symbol recurse nil cons cons exit
1168 nextchar [char] , = if
1170 nextchar [char] @ = if
1172 unquote-splicing-symbol recurse nil cons cons exit
1174 unquote-symbol recurse nil cons cons exit
1184 \ Anything else is parsed as a symbol
1185 readsymbol charlist>symbol
1187 \ Replace λ with lambda
1188 2dup λ-symbol objeq? if
1197 \ ---- Eval ---- {{{
1199 : self-evaluating? ( obj -- obj bool )
1200 boolean-type istype? if true exit then
1201 fixnum-type istype? if true exit then
1202 flonum-type istype? if true exit then
1203 ratnum-type istype? if true exit then
1204 character-type istype? if true exit then
1205 string-type istype? if true exit then
1206 nil-type istype? if true exit then
1207 none-type istype? if true exit then
1212 : tagged-list? ( obj tag-obj -- obj bool )
1214 pair-type istype? false = if
1220 : quote? ( obj -- obj bool )
1221 quote-symbol tagged-list? ;
1223 : quote-body ( quote-obj -- quote-body-obj )
1226 : quasiquote? ( obj -- obj bool )
1227 quasiquote-symbol tagged-list? ;
1229 : unquote? ( obj -- obj bool )
1230 unquote-symbol tagged-list? ;
1232 : unquote-splicing? ( obj -- obj bool )
1233 unquote-splicing-symbol tagged-list? ;
1235 : eval-unquote ( env obj -- res )
1239 recoverable-exception throw" no arguments to unquote."
1244 recoverable-exception throw" too many arguments to unquote."
1247 2drop car 2swap eval
1250 ( Create a new list from elements of l1 consed on to l2 )
1251 : join-lists ( l2 l1 -- l3 )
1252 nil? if 2drop exit then
1259 defer eval-quasiquote-item
1260 : eval-quasiquote-pair ( env obj -- res )
1261 2over 2over ( env obj env obj )
1263 cdr eval-quasiquote-item
1265 -2rot car ( cdritem env objcar )
1267 unquote-splicing? if
1268 eval-unquote ( cdritems caritem )
1276 eval-quasiquote-item ( cdritems caritem )
1291 pair-type istype? if
1292 eval-quasiquote-pair exit
1296 ; is eval-quasiquote-item
1298 : eval-quasiquote ( obj env -- res )
1299 2swap cdr ( env args )
1302 recoverable-exception throw" no arguments to quasiquote."
1305 2dup cdr ( env args args-cdr )
1307 recoverable-exception throw" too many arguments to quasiquote."
1310 2drop car ( env arg )
1312 eval-quasiquote-item
1315 : variable? ( obj -- obj bool )
1316 symbol-type istype? ;
1318 : definition? ( obj -- obj bool )
1319 define-symbol tagged-list? ;
1321 : make-lambda ( params body -- lambda-exp )
1322 lambda-symbol -2rot cons cons ;
1324 ( Handles iterative expansion of defines in
1325 terms of nested lambdas. Most Schemes only
1326 handle one iteration of expansion! )
1327 : definition-var-val ( obj -- var val )
1329 cdr 2dup cdr 2swap car ( val var )
1332 symbol-type istype? false =
1334 2dup cdr 2swap car ( val formals var' )
1335 -2rot 2swap ( var' formals val )
1336 make-lambda nil cons ( var' val' )
1343 : eval-definition ( obj env -- res )
1344 2dup 2rot ( env env obj )
1345 definition-var-val ( env env var val )
1346 2rot eval ( env var val )
1348 2rot ( var val env )
1354 : assignment? ( obj -- obj bool )
1355 set!-symbol tagged-list? ;
1357 : assignment-var ( obj -- var )
1360 : assignment-val ( obj -- val )
1363 : eval-assignment ( obj env -- res )
1365 2over 2over ( env obj env obj )
1366 assignment-val 2swap ( env obj valexp env )
1367 eval ( env obj val )
1369 2swap assignment-var 2swap ( env var val )
1371 2rot ( var val env )
1377 : macro-definition? ( obj -- obj bool )
1378 define-macro-symbol tagged-list? ;
1380 : macro-definition-name ( exp -- mname )
1383 : macro-definition-params ( exp -- params )
1386 : macro-definition-body ( exp -- body )
1390 : eval-define-macro ( obj env -- res )
1393 2dup macro-definition-name 2swap ( name obj )
1394 2dup macro-definition-params 2swap ( name params obj )
1395 macro-definition-body ( name params body )
1397 env obj@ ( name params body env )
1405 : if? ( obj -- obj bool )
1406 if-symbol tagged-list? ;
1408 : if-predicate ( ifobj -- pred )
1411 : if-consequent ( ifobj -- conseq )
1414 : if-alternative ( ifobj -- alt|none )
1422 : false? ( boolobj -- boolean )
1423 boolean-type istype? if
1424 false boolean-type objeq?
1430 : true? ( boolobj -- bool )
1433 : lambda? ( obj -- obj bool )
1434 lambda-symbol tagged-list? ;
1436 : lambda-parameters ( obj -- params )
1439 : lambda-body ( obj -- body )
1442 : begin? ( obj -- obj bool )
1443 begin-symbol tagged-list? ;
1445 : begin-actions ( obj -- actions )
1448 : eval-sequence ( explist env -- finalexp env )
1449 ( Evaluates all bar the final expressions in
1450 an an expression list. The final expression
1451 is returned to allow for tail optimization. )
1453 2swap ( env explist )
1455 \ Abort on empty list
1462 2dup cdr ( env explist nextexplist )
1465 -2rot car 2over ( nextexplist env exp env )
1467 2drop \ discard result
1468 2swap ( env nextexplist )
1471 2drop car 2swap ( finalexp env )
1474 : application? ( obj -- obj bool )
1477 : operator ( obj -- operator )
1480 : operands ( obj -- operands )
1483 : nooperands? ( operands -- bool )
1486 : first-operand ( operands -- operand )
1489 : rest-operands ( operands -- other-operands )
1492 : list-of-vals ( args env -- vals )
1498 2over 2over first-operand 2swap eval
1499 -2rot rest-operands 2swap recurse
1504 : procedure-params ( proc -- params )
1505 drop pair-type car ;
1507 : procedure-body ( proc -- body )
1508 drop pair-type cdr car ;
1510 : procedure-env ( proc -- body )
1511 drop pair-type cdr cdr car ;
1513 ( Ensure terminating symbol arg name is handled
1514 specially to allow for variadic procedures. )
1515 : flatten-proc-args ( argvals argnames -- argvals' argnames' )
1517 2over nil? false = if
1518 recoverable-exception throw" Too many arguments for compound procedure."
1525 symbol-type istype? if
1535 recoverable-exception throw" Too few arguments for compound procedure."
1542 recurse ( argvals argnames argvals'' argnames'' )
1543 2rot car 2swap cons ( argvals argvals'' argnames' )
1544 2rot car 2rot cons ( argnames' argvals' )
1548 : apply ( proc argvals -- result )
1550 primitive-proc-type of
1554 compound-proc-type of
1555 2dup procedure-body ( argvals proc body )
1556 -2rot 2dup procedure-params ( body argvals proc argnames )
1557 -2rot procedure-env ( body argnames argvals procenv )
1563 extend-env ( body env )
1567 R> drop ['] eval goto-deferred \ Tail call optimization
1570 recoverable-exception throw" Object not applicable."
1574 ( Simply evaluates the given procedure with expbody as its argument. )
1575 : macro-expand ( proc expbody -- result )
1577 2dup procedure-body ( expbody proc procbody )
1578 -2rot 2dup procedure-params ( procbody expbody proc argnames )
1579 -2rot procedure-env ( procbody argnames expbody procenv )
1585 extend-env eval-sequence eval
1588 :noname ( obj env -- result )
1603 2swap eval-quasiquote
1613 2swap eval-definition
1618 2swap eval-assignment
1622 macro-definition? if
1623 2swap eval-define-macro
1639 ['] eval goto-deferred
1643 2dup lambda-parameters
1652 ['] eval goto-deferred
1657 2over 2over ( env exp env exp )
1658 operator ( env exp env opname )
1660 2dup lookup-macro nil? false = if
1661 \ Macro function evaluation
1663 ( env exp env opname mproc )
1664 2swap 2drop -2rot 2drop cdr ( env mproc body )
1669 ['] eval goto-deferred
1671 \ Regular function application
1673 2drop ( env exp env opname )
1675 2swap eval ( env exp proc )
1677 -2rot ( proc env exp )
1678 operands 2swap ( proc operands env )
1679 list-of-vals ( proc argvals )
1686 recoverable-exception throw" Tried to evaluate object with unknown type."
1691 \ ---- Print ---- {{{
1693 : printfixnum ( fixnum -- ) drop 0 .R ;
1695 : printflonum ( flonum -- ) drop f. ;
1697 : printratnum ( ratnum -- )
1699 car print ." /" cdr print
1702 : printbool ( bool -- )
1710 : printchar ( charobj -- )
1713 9 of ." #\tab" endof
1714 bl of ." #\space" endof
1715 '\n' of ." #\newline" endof
1721 : (printstring) ( stringobj -- )
1722 nil? if 2drop exit then
1726 '\n' of ." \n" drop endof
1727 [char] \ of ." \\" drop endof
1728 [char] " of [char] \ emit [char] " emit drop endof
1734 : printstring ( stringobj -- )
1739 : printsymbol ( symbolobj -- )
1740 nil-type istype? if 2drop exit then
1746 : printnil ( nilobj -- )
1749 : printpair ( pairobj -- )
1753 nil-type istype? if 2drop exit then
1754 pair-type istype? if space recurse exit then
1758 : printprim ( primobj -- )
1759 2drop ." <primitive procedure>" ;
1761 : printcomp ( primobj -- )
1762 2drop ." <compound procedure>" ;
1764 : printnone ( noneobj -- )
1765 2drop ." Unspecified return value" ;
1767 : printport ( port -- )
1771 fixnum-type istype? if printfixnum exit then
1772 flonum-type istype? if printflonum exit then
1773 ratnum-type istype? if printratnum exit then
1774 boolean-type istype? if printbool exit then
1775 character-type istype? if printchar exit then
1776 string-type istype? if printstring exit then
1777 symbol-type istype? if printsymbol exit then
1778 nil-type istype? if printnil exit then
1779 pair-type istype? if ." (" printpair ." )" exit then
1780 primitive-proc-type istype? if printprim exit then
1781 compound-proc-type istype? if printcomp exit then
1782 none-type istype? if printnone exit then
1784 recoverable-exception throw" Tried to print object with unknown type."
1789 \ ---- Garbage Collection ---- {{{
1794 variable gc-stack-depth
1797 depth gc-stack-depth !
1801 false gc-enabled ! ;
1806 : pairlike? ( obj -- obj bool )
1807 pair-type istype? if true exit then
1808 string-type istype? if true exit then
1809 symbol-type istype? if true exit then
1810 compound-proc-type istype? if true exit then
1815 : pairlike-marked? ( obj -- obj bool )
1816 over nextfrees + @ 0=
1819 : mark-pairlike ( obj -- obj )
1820 over nextfrees + 0 swap !
1829 : gc-mark-obj ( obj -- )
1831 pairlike? invert if 2drop exit then
1832 pairlike-marked? if 2drop exit then
1843 scheme-memsize nextfree !
1844 0 scheme-memsize 1- do
1845 nextfrees i + @ 0<> if
1846 nextfree @ nextfrees i + !
1852 \ Following a GC, this gives the amount of free memory
1856 nextfrees i + @ 0= if 1+ then
1860 \ Debugging word - helps spot memory that is retained
1863 nextfrees i + @ 0<> if
1875 symbol-table obj@ gc-mark-obj
1876 macro-table obj@ gc-mark-obj
1877 global-env obj@ gc-mark-obj
1879 depth gc-stack-depth @ do
1888 \ ." (" gc-count-marked . ." pairs marked as used.)" cr
1889 ; is collect-garbage
1893 \ ---- Loading files ---- {{{
1895 : charlist>cstr ( charlist addr -- n )
1897 dup 2swap ( origaddr addr charlist )
1903 drop ( origaddr addr charlist char )
1904 -rot 2swap ( origaddr charlist addr char )
1906 1+ -rot ( origaddr nextaddr charlist )
1909 2drop ( origaddr finaladdr )
1913 : load ( addr n -- finalResult )
1918 ok-symbol ( port res )
1921 2over read-port ( port res obj )
1923 2dup EOF character-type objeq? if
1924 2drop 2swap close-port
1928 2swap 2drop ( port obj )
1930 global-env obj@ eval ( port res )
1936 \ ---- Standard Library ---- {{{
1938 include scheme-primitives.4th
1940 s" scheme-library.scm" load 2drop
1946 ( REPL calls REPL-BODY in a loop until repl-body returns true. )
1947 : repl-body ( -- bool )
1948 cr bold fg green ." > " reset-term
1952 2dup EOF character-type objeq? if
1954 bold fg blue ." Moriturus te saluto." reset-term cr
1958 global-env obj@ eval
1960 fg cyan ." ; " print reset-term
1971 \ Display welcome message
1972 welcome-symbol nil cons global-env obj@ eval 2drop
1977 recoverable-exception of false endof
1978 unrecoverable-exception of true endof