-
Notifications
You must be signed in to change notification settings - Fork 4
/
forth.pir
71 lines (55 loc) · 1.01 KB
/
forth.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
.sub 'main' :main
.param pmc args
$S0 = shift args
load_language 'forth'
.local int argc
argc = elements args
if argc == 0 goto prompt
$S0 = shift args
compile_file($S0)
end
prompt:
prompt()
end
.end
.sub 'compile_file'
.param string filename
.local string source
$P0 = new 'FileHandle'
$P0.'open'(filename)
source = $P0.'readall'()
$P0.'close'()
.local pmc forth
forth = compreg 'forth'
$P0 = forth(source)
$P0()
.end
.sub 'prompt'
.local pmc stdin, forth
stdin = getstdin
forth = compreg 'forth'
print "Parrot Forth\n"
loop:
print "> "
$S0 = stdin.'readline'()
unless stdin goto end
push_eh exception
$P0 = forth($S0)
$P0()
pop_eh
print " ok\n"
goto loop
end:
.return()
exception:
.get_results ($P0)
$S0 = $P0
print $S0
print "\n"
goto loop
.end
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: