sardonyx 0.1.841 → 0.1.842
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/compiler.rb +3 -1
- data/lib/sdx/compiler/parser.rb +10 -1
- data/lib/sdx/vm/datatypes.rb +3 -2
- data/lib/sdx/vm/vm.rb +14 -3
- 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: 03ea6caa67024a4b7f5ca9f35759e595e0895825656d561738669ffd410f7a24
|
|
4
|
+
data.tar.gz: 9c4c0459b243c717982b5426b6c88935d37af88a4acc067937a60b916b9baf66
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b2ddef36002cf5a9804ca836d284fb17af8942257c76219425bf41fa1eded5a3ea124fe6db4977f7adc5ef5c18404b8125ed76b2158ec67f72ff839aaf0be8ab
|
|
7
|
+
data.tar.gz: 4b97a87b5241e4caa9828347962bb6eb6647cf495046470d68e8b92eb2aa9e9b57ee9438e1702fd6076271d390d6bb1748b995d5244699903666293386e654e2
|
|
@@ -103,10 +103,12 @@ module Compiler
|
|
|
103
103
|
end
|
|
104
104
|
i += "\x2a#{e.size}\x18"
|
|
105
105
|
end
|
|
106
|
-
bc += "\
|
|
106
|
+
bc += "\x2b#{i.size}\x18" + i
|
|
107
107
|
if e
|
|
108
108
|
bc += e
|
|
109
109
|
end
|
|
110
|
+
when :bool
|
|
111
|
+
bc += "\x21\x12#{node.value}\x18"
|
|
110
112
|
when :name
|
|
111
113
|
bc += "\x20#{node.value}\x18"
|
|
112
114
|
when :nil
|
data/lib/sdx/compiler/parser.rb
CHANGED
|
@@ -10,6 +10,7 @@ module Parser
|
|
|
10
10
|
/\Aobject/ => :object,
|
|
11
11
|
/\Anew/ => :new,
|
|
12
12
|
/\Arequire/ => :require,
|
|
13
|
+
/\A(true|false)/ => :bool,
|
|
13
14
|
/\A(<|>|<=|>=|==|!=)/ => :op,
|
|
14
15
|
/\A(\+|-|\*|\/|%)?=/ => :eq,
|
|
15
16
|
/\A(\+|-|\*|\/|%)/ => :op,
|
|
@@ -97,6 +98,14 @@ module Parser
|
|
|
97
98
|
end
|
|
98
99
|
end
|
|
99
100
|
|
|
101
|
+
def self.parse_bool(tokens)
|
|
102
|
+
if self.expect tokens, :bool
|
|
103
|
+
[ (Node.new :bool, tokens[0][0], []), 1 ]
|
|
104
|
+
else
|
|
105
|
+
nil
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
100
109
|
def self.parse_float(tokens)
|
|
101
110
|
if self.expect tokens, :float
|
|
102
111
|
[ (Node.new :float, tokens[0][0], []), 1 ]
|
|
@@ -189,7 +198,7 @@ module Parser
|
|
|
189
198
|
end
|
|
190
199
|
|
|
191
200
|
def self.parse_literal(tokens)
|
|
192
|
-
(self.parse_block tokens) ||
|
|
201
|
+
(self.parse_block tokens) || (self.parse_bool 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)
|
|
193
202
|
end
|
|
194
203
|
|
|
195
204
|
def self.parse_call(tokens)
|
data/lib/sdx/vm/datatypes.rb
CHANGED
|
@@ -341,8 +341,9 @@ class Nil < DataType
|
|
|
341
341
|
end
|
|
342
342
|
|
|
343
343
|
class List < DataType
|
|
344
|
-
def initialize(val)
|
|
344
|
+
def initialize(val, scope=nil)
|
|
345
345
|
@internal = val
|
|
346
|
+
@scope = scope
|
|
346
347
|
@pos = 0
|
|
347
348
|
@fields = {
|
|
348
349
|
"__as_string" => (NativeFnInternal.new (Proc.new do
|
|
@@ -411,7 +412,7 @@ class List < DataType
|
|
|
411
412
|
end
|
|
412
413
|
|
|
413
414
|
def add(other)
|
|
414
|
-
return List.new [*@internal, (Variable.new other, (get_type other), @internal[0].scope)]
|
|
415
|
+
return List.new [*@internal, (Variable.new other, (get_type other), @scope || @internal[0].scope)]
|
|
415
416
|
end
|
|
416
417
|
|
|
417
418
|
def mul(other)
|
data/lib/sdx/vm/vm.rb
CHANGED
|
@@ -18,10 +18,14 @@ class VM
|
|
|
18
18
|
attr_accessor :bc_io
|
|
19
19
|
|
|
20
20
|
def truthy(val)
|
|
21
|
+
case val.value
|
|
22
|
+
when Bool
|
|
23
|
+
return val.value.internal
|
|
24
|
+
end
|
|
21
25
|
if val.value.fields["__as_bool"]
|
|
22
|
-
(val.value.fields["__as_bool"].call).internal
|
|
26
|
+
return (val.value.fields["__as_bool"].call).internal
|
|
23
27
|
else
|
|
24
|
-
true
|
|
28
|
+
return true
|
|
25
29
|
end
|
|
26
30
|
end
|
|
27
31
|
|
|
@@ -275,12 +279,19 @@ class VM
|
|
|
275
279
|
vals << pop_from_stack
|
|
276
280
|
end
|
|
277
281
|
vals.reverse!
|
|
278
|
-
push_to_stack Variable.new (List.new vals), :list, @global
|
|
282
|
+
push_to_stack Variable.new (List.new vals, @global), :list, @global
|
|
279
283
|
when :block
|
|
280
284
|
size = get_string.to_i
|
|
281
285
|
body =
|
|
282
286
|
((load_bytes size, false).map { |e| e.chr }).join ""
|
|
283
287
|
push_to_stack Variable.new (Block.new body), :block, @global
|
|
288
|
+
when :bool
|
|
289
|
+
val = get_string
|
|
290
|
+
t = {
|
|
291
|
+
"true" => true,
|
|
292
|
+
"false" => false,
|
|
293
|
+
}
|
|
294
|
+
push_to_stack Variable.new (Bool.new t[val]), :bool, @global
|
|
284
295
|
when :nil
|
|
285
296
|
push_to_stack Variable.new (Nil.new), :nil, @global
|
|
286
297
|
end
|