最終更新 1748624212

修正履歴 3f9207b0905bba32974be4692d66ece875bde94a

hello-world.nils.nv Raw Playground
1|:: documentation for NILS Form|
2 :@doc string:
3"Nova In-Language Static Form is a possible structure for lowering
4Nova code into a bytecode language describable in Nova. This is not
5intended to be written by hand."
6
7|:: match $stack $arity :failed:?|
8|:: match @stdio.arity $arity :@stdio.arity: $arity| :@stdio.arity (r): $arity
9|:: match @stdio.1 $1 :@stdio.1: $1| :@stdio.1 (r): $1
10|:: match @stdio.2 $2 :@stdio.2: $2| :@stdio.2 (r): $2
11|:: match .arity $arity :.arity: $arity| :.arity (r): $arity
12|:: match .1 $1 :.1: $1| :.1 (r): $1
13|:: match .2 $2 :.2: $2| :.2 (r): $2
14|:: match message.arity $arity :message.arity: $arity| :message.arity (r): $arity
15|:: match message.1 $1 :message.1: $1| :message.1 (r): $1
16|:: match $stack $arity| :failed:
17
18|:: bind $stack $symbol :failed:?|
19|:: bind @stdio.2 1 :@stdio.2: $2| :@stdio.2 (r): $2 :1: $2
20|:: bind message.1 1 :message.1: $1| :message.1 (r): $1 :1: $1
21|:: bind $stack $symbol| :failed:
22
23|:: consume @stdio.arity :@stdio.arity (r): $symbol :failed:?| :@stdio.arity: $symbol
24|:: consume @stdio.1 :@stdio.1 (r): $symbol :failed:?| :@stdio.1: $symbol
25|:: consume @stdio.2 :@stdio.2 (r): $symbol :failed:?| :@stdio.2: $symbol
26|:: consume .arity :.arity (r): $symbol :failed:?| :.arity: $symbol
27|:: consume .1 :.1 (r): $symbol :failed:?| :.1: $symbol
28|:: consume .2 :.2 (r): $symbol :failed:?| :.2: $symbol
29|:: consume message.arity :message.arity (r): $symbol :failed:?| :message.arity: $symbol
30|:: consume message.1 :message.1 (r): $symbol :failed:?| :message.1: $symbol
31|:: consume $stack :failed:?|
32
33|:: consume @stdio.arity :@stdio.arity (r): $symbol|
34|:: consume @stdio.1 :@stdio.1 (r): $symbol|
35|:: consume @stdio.2 :@stdio.2 (r): $symbol|
36|:: consume .arity :.arity (r): $symbol|
37|:: consume .1 :.1 (r): $symbol|
38|:: consume .2 :.2 (r): $symbol|
39|:: consume message.arity :message.arity (r): $symbol|
40|:: consume message.1 :message.1 (r): $symbol|
41
42
43|:: jet @stdio write/1 :failed:?|
44|:: jet @stdio write/1|
45 :@jet: "io.write(string.char(tonumber(stacks["1"][1][1])))"
46
47|:: push $stack $symbol :failed:?|
48|:: push @stdio.arity $arity| :@stdio.arity: $arity
49|:: push @stdio.1 $symbol| :@stdio.1: $symbol
50|:: push @stdio.2 $symbol| :@stdio.2: $symbol
51|:: push .arity $arity| :.arity: $arity
52|:: push .1 $symbol| :.1: $symbol
53|:: push .2 $symbol| :.2: $symbol
54|:: push message.arity $arity| :message.arity: $arity
55|:: push message.1 $symbol| :message.1: $symbol
56
57|:: pushvar $stack $reg :failed:?|
58|:: pushvar @stdio.2 1 :1: $1?| :@stdio.2: $1
59
60
61|:: unbind 1 :1: $1|
62|:: unbind $reg|
63
64
65|:: rule 1 succeeded :failed:| :: rule 2
66|:: rule 2 succeeded :failed:| :: rule 3
67|:: rule 3 succeeded :failed:| :: rule 4
68|:: rule $x succeeded :failed:?|
69|:: rule $x succeeded| :: rule 1
70
71
72|:/:| :: print message :message: "Hello, World!"
73|:: rule 0|
74 :: push .arity 2 :: push .1 print :: push .2 message
75 :: push message.arity 1 :: push message.1 33
76 :: push message.arity 1 :: push message.1 100
77 :: push message.arity 1 :: push message.1 108
78 :: push message.arity 1 :: push message.1 114
79 :: push message.arity 1 :: push message.1 111
80 :: push message.arity 1 :: push message.1 87
81 :: push message.arity 1 :: push message.1 32
82 :: push message.arity 1 :: push message.1 44
83 :: push message.arity 1 :: push message.1 111
84 :: push message.arity 1 :: push message.1 108
85 :: push message.arity 1 :: push message.1 108
86 :: push message.arity 1 :: push message.1 101
87 :: push message.arity 1 :: push message.1 72
88 :: rule 0 succeeded
89
90|:@stdio: write $char|
91 :@jet: "io.write(string.char(tonumber($char)))"
92|:: rule 1|
93 :: match @stdio.arity 2 :: match @stdio.1 write :: bind @stdio.2 1
94 :: consume @stdio.arity
95 :: consume @stdio.1
96 :: consume @stdio.2
97 :: jet @stdio write/1
98 :: unbind 1
99 :: rule 1 succeeded
100
101|:: print message? :message: $char|
102 :@stdio: write $char
103|:: rule 2|
104 :: match .arity 2 :: match .1 print :: match .2 message
105 :: match message.arity 1 :: bind message.1 1
106 :: consume .arity :: consume .1 :: consume .2
107 :: consume message.arity :: consume message.1
108 :: push @stdio.arity 2 :: push @stdio.1 write :: pushvar @stdio.2 1
109 :: push .arity 2 :: push .1 print :: push .2 message
110 :: unbind 1
111 :: rule 2 succeeded
112
113
114|:: print message|
115 :@stdio: write 10
116|:: rule 3|
117 :: match .arity 2 :: match .1 print :: match .2 message
118 :: consume .arity :: consume .1 :: consume .2
119 :: push @stdio.arity 2 :: push @stdio.1 write :: push @stdio.2 10
120 :: unbind 1
121 :: rule 3 succeeded
122
123
124|| :: rule 0