Dernière activité 1748629027

capitalex's Avatar capitalex a révisé ce gist 1748629027. Aller à la révision

1 file changed, 153 insertions

hello-world.nils.jets.nv(fichier créé)

@@ -0,0 +1,153 @@
1 + |:: documentation for NILS Form|
2 + :@doc string:
3 + "Nova In-Language Static Form is a possible structure for lowering
4 + Nova code into a bytecode language describable in Nova. This is not
5 + intended to be written by hand."
6 +
7 + |:: match $stack $arity :failed:?|
8 + |:: match $stack $symbol|
9 + :@jet:
10 + "
11 + local s = stacks[$stack]
12 + local s_top = s.n
13 + local tuple = s[s_top]
14 + if not tuple or tuple[1] ~= $symbol then
15 + push("failed", { })
16 + else
17 + pop($stack)
18 + push($stack .. " (r)", { $symbol })
19 + end
20 + "
21 +
22 + |:: bind $stack $symbol :failed:?|
23 + |:: bind $stack $register|
24 + :@jet:
25 + "
26 + local s = stacks[$stack]
27 + local s_top = s.n
28 + local r = stacks[$register]
29 + local r_top = r.n
30 + local s_tuple = s[s_top]
31 + local r_tuple = r[r_top]
32 + if not s_tuple or r_tuple and s_tuple[1] ~= r_tuple[1] then
33 + push("failed", { })
34 + else
35 + pop($stack)
36 + push($stack .. " (r)", s_tuple)
37 + if not r_tuple then push($register, s_tuple) end
38 + end
39 + "
40 +
41 + |:: consume $stack :failed:?|
42 + :@jet:
43 + "
44 + local r = pop($stack .. " (r)")
45 + if r then push($stack, r) end
46 + "
47 + |:: consume $stack |
48 + :@jet:
49 + "
50 + pop($stack .. " (r)")
51 + "
52 +
53 + |:: push $stack $symbol :failed:?|
54 + |:: push $stack $symbol|
55 + :@jet:
56 + "
57 + push($stack, { $symbol })
58 + "
59 +
60 + |:: pushvar $stack $reg :failed:?|
61 + |:: pushvar $stack $reg|
62 + :@jet:
63 + "
64 + local r_tuple = pop($reg)
65 + push($stack, r_tuple)
66 + push($reg, r_tuple)
67 + "
68 +
69 + |:: unbind $n|
70 + :@jet:
71 + "
72 + if stacks[$n].n > 0 then
73 + pop($n)
74 + end
75 + "
76 +
77 + |:: jet @stdio write/1 :failed:?|
78 + |:: jet @stdio write/1|
79 + :@jet: "io.write(string.char(tonumber(stacks["1"][1][1])))"
80 +
81 + |:stacks:|
82 + :@stdio.arity: :@stdio.1: :@stdio.2:
83 + :@stdio.arity (r): :@stdio.1 (r): :@stdio.2 (r):
84 +
85 + :.arity: :.1: :.2:
86 + :.arity (r): :.1 (r): :.2 (r):
87 +
88 + :message.arity: :message.1:
89 + :message.arity (r): :message.1 (r):
90 +
91 + |:registers:|
92 + :1:
93 +
94 + |:: rule 1 succeeded :failed:| :: rule 2
95 + |:: rule 2 succeeded :failed:| :: rule 3
96 + |:: rule 3 succeeded :failed:| :: rule 4
97 + |:: rule $x succeeded :failed:?|
98 + |:: rule $x succeeded| :: rule 1
99 +
100 +
101 + |:/:| :: print message :message: "Hello, World!"
102 + |:: rule 0|
103 + :: push .arity 2 :: push .1 print :: push .2 message
104 + :: push message.arity 1 :: push message.1 33
105 + :: push message.arity 1 :: push message.1 100
106 + :: push message.arity 1 :: push message.1 108
107 + :: push message.arity 1 :: push message.1 114
108 + :: push message.arity 1 :: push message.1 111
109 + :: push message.arity 1 :: push message.1 87
110 + :: push message.arity 1 :: push message.1 32
111 + :: push message.arity 1 :: push message.1 44
112 + :: push message.arity 1 :: push message.1 111
113 + :: push message.arity 1 :: push message.1 108
114 + :: push message.arity 1 :: push message.1 108
115 + :: push message.arity 1 :: push message.1 101
116 + :: push message.arity 1 :: push message.1 72
117 + :: rule 0 succeeded
118 +
119 + |:@stdio: write $char|
120 + :@jet: "io.write(string.char(tonumber($char)))"
121 + |:: rule 1|
122 + :: match @stdio.arity 2 :: match @stdio.1 write :: bind @stdio.2 1
123 + :: consume @stdio.arity
124 + :: consume @stdio.1
125 + :: consume @stdio.2
126 + :: jet @stdio write/1
127 + :: unbind 1
128 + :: rule 1 succeeded
129 +
130 + |:: print message? :message: $char|
131 + :@stdio: write $char
132 + |:: rule 2|
133 + :: match .arity 2 :: match .1 print :: match .2 message
134 + :: match message.arity 1 :: bind message.1 1
135 + :: consume .arity :: consume .1 :: consume .2
136 + :: consume message.arity :: consume message.1
137 + :: push @stdio.arity 2 :: push @stdio.1 write :: pushvar @stdio.2 1
138 + :: push .arity 2 :: push .1 print :: push .2 message
139 + :: unbind 1
140 + :: rule 2 succeeded
141 +
142 +
143 + |:: print message|
144 + :@stdio: write 10
145 + |:: rule 3|
146 + :: match .arity 2 :: match .1 print :: match .2 message
147 + :: consume .arity :: consume .1 :: consume .2
148 + :: push @stdio.arity 2 :: push @stdio.1 write :: push @stdio.2 10
149 + :: unbind 1
150 + :: rule 3 succeeded
151 +
152 +
153 + || :: rule 0
Plus récent Plus ancien