sardonyx 0.1.83 → 0.1.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sdx/compiler/parser.rb +30 -10
- data/lib/sdx/vm/vm.rb +9 -8
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f381674f5e870ec9ac7fe8f9ce699b1e851c7314ad9480201710bcd32e665185
|
|
4
|
+
data.tar.gz: c42b1e66d327aa8bc0e39075c3778bd3b40beb7c82d47edce91a601418a82408
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43c77a34a4edf0b6a87af9183004a57d8cb285f115159240b5798c8ce37723e2f9018c5f5a630d2f7c102cbf50a42f181eee30685f74cf2ede839f1e5a224a72
|
|
7
|
+
data.tar.gz: 83d259340d9dec63f6696de3a3d76832bc7c98880634df1139f5cd89042d7c7eb5c8cad1d27062fa027174344583a593d37698c96aac19328c7965b047d4ea34
|
data/lib/sdx/compiler/parser.rb
CHANGED
|
@@ -113,6 +113,23 @@ module Parser
|
|
|
113
113
|
end
|
|
114
114
|
end
|
|
115
115
|
|
|
116
|
+
def self.parse_parens(tokens)
|
|
117
|
+
if self.expect tokens, :lpar
|
|
118
|
+
tokens = tokens[1..tokens.size]
|
|
119
|
+
unless self.parse_expr tokens
|
|
120
|
+
return nil
|
|
121
|
+
end
|
|
122
|
+
e, part = self.parse_expr tokens
|
|
123
|
+
tokens = tokens[part..tokens.size]
|
|
124
|
+
unless self.expect tokens, :rpar
|
|
125
|
+
return nil
|
|
126
|
+
end
|
|
127
|
+
return [e, part + 2]
|
|
128
|
+
else
|
|
129
|
+
return nil
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
116
133
|
def self.parse_list(tokens)
|
|
117
134
|
unless (self.expect tokens, :lbrack)
|
|
118
135
|
return nil
|
|
@@ -155,7 +172,7 @@ module Parser
|
|
|
155
172
|
while true
|
|
156
173
|
if self.expect tokens, :rbrace
|
|
157
174
|
total += 1
|
|
158
|
-
|
|
175
|
+
return [ (Node.new :block, "", children), total ]
|
|
159
176
|
end
|
|
160
177
|
e = self.parse_expr tokens
|
|
161
178
|
if e
|
|
@@ -167,23 +184,26 @@ module Parser
|
|
|
167
184
|
Kernel.exit 1
|
|
168
185
|
end
|
|
169
186
|
end
|
|
187
|
+
total += 1
|
|
170
188
|
[ (Node.new :block, "", children), total ]
|
|
171
189
|
end
|
|
172
190
|
|
|
173
191
|
def self.parse_literal(tokens)
|
|
174
|
-
(self.parse_block tokens) || self.parse_float
|
|
192
|
+
(self.parse_block tokens) || (self.parse_float tokens) || (self.parse_name tokens) || (self.parse_number tokens) || (self.parse_list tokens) || (self.parse_string tokens) || (self.parse_nil tokens) || (self.parse_parens tokens)
|
|
175
193
|
end
|
|
176
194
|
|
|
177
195
|
def self.parse_call(tokens)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
196
|
+
unless (self.parse_literal tokens)
|
|
197
|
+
return nil
|
|
198
|
+
end
|
|
199
|
+
callee = (self.parse_literal tokens)
|
|
200
|
+
total = callee[1]
|
|
201
|
+
tokens = tokens[total..tokens.size]
|
|
202
|
+
callee = callee[0]
|
|
203
|
+
if self.expect tokens, :lpar
|
|
184
204
|
args = []
|
|
185
|
-
tokens = tokens[
|
|
186
|
-
total
|
|
205
|
+
tokens = tokens[1..tokens.size]
|
|
206
|
+
total += 1
|
|
187
207
|
if self.expect tokens, :rpar
|
|
188
208
|
return [ (Node.new :call, callee, args), total + 1 ]
|
|
189
209
|
end
|
data/lib/sdx/vm/vm.rb
CHANGED
|
@@ -2,6 +2,14 @@ require 'sdx/vm/variables'
|
|
|
2
2
|
require 'sdx/vm/datatypes'
|
|
3
3
|
require 'sdx/vm/scope'
|
|
4
4
|
|
|
5
|
+
def codify(val)
|
|
6
|
+
if val.value.fields["__as_code_string"]
|
|
7
|
+
(val.value.fields["__as_code_string"].call).internal
|
|
8
|
+
else
|
|
9
|
+
val.value.pretty_inspect
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
5
13
|
class VM
|
|
6
14
|
attr_accessor :bc_io
|
|
7
15
|
|
|
@@ -21,14 +29,6 @@ class VM
|
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
|
|
24
|
-
def codify(val)
|
|
25
|
-
if val.value.fields["__as_code_string"]
|
|
26
|
-
(call val.value.fields["__as_code_string"], [], val.scope).internal
|
|
27
|
-
else
|
|
28
|
-
val.value.pretty_inspect
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
32
|
def call(val, *args)
|
|
33
33
|
if val.respond_to? :value and val.value.respond_to? :fields
|
|
34
34
|
case val.value
|
|
@@ -135,6 +135,7 @@ class VM
|
|
|
135
135
|
0x24 => :sub,
|
|
136
136
|
0x25 => :mul,
|
|
137
137
|
0x26 => :div,
|
|
138
|
+
0x27 => :mod,
|
|
138
139
|
0x12 => :bool,
|
|
139
140
|
0x13 => :int,
|
|
140
141
|
0x14 => :str,
|