Merge branch 'ruby1.9' of https://github.com/elektronaut/mal into elektronaut-ruby1.9
[jackhill/mal.git] / forth / step1_read_print.fs
CommitLineData
59038a10
C
1require reader.fs
2require printer.fs
3
4: read read-str ;
5: eval ;
45c1894b
C
6: print
7 \ ." Type: " dup mal-type @ type-name safe-type cr
8 pr-str ;
59038a10 9
45c1894b 10: rep ( str-addr str-len -- str-addr str-len )
59038a10
C
11 read
12 eval
13 print ;
14
15create buff 128 allot
45c1894b 1677777777777 constant stack-leak-detect
59038a10
C
17
18: read-lines
19 begin
20 ." user> "
45c1894b 21 stack-leak-detect
59038a10 22 buff 128 stdin read-line throw
45c1894b
C
23 while ( num-bytes-read )
24 buff swap ( str-addr str-len )
168fb5dc
C
25 ['] rep
26 \ execute safe-type
45c1894b 27 catch ?dup 0= if safe-type else ." Caught error " . endif
168fb5dc 28 cr
45c1894b 29 stack-leak-detect <> if ." --stack leak--" cr endif
59038a10
C
30 repeat ;
31
59038a10
C
32read-lines
33cr
34bye