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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54495fa9b457fb450d812a6a09b57a3284b948e8e93e44ab97521a241bef0a3b
4
- data.tar.gz: '06619369fdff53a992b948401115f98ba11319ff0d06bd0a29d73030e39e892e'
3
+ metadata.gz: 03ea6caa67024a4b7f5ca9f35759e595e0895825656d561738669ffd410f7a24
4
+ data.tar.gz: 9c4c0459b243c717982b5426b6c88935d37af88a4acc067937a60b916b9baf66
5
5
  SHA512:
6
- metadata.gz: ceb7a82b5e59a72b23063caa984e26ce4f3d9d44d41e826d1702613bdad7634f06606dd622c6751aa6f477d042a58c2191cda025bebea6aeb84c356ca9fec984
7
- data.tar.gz: 71514ddd0dfe83eb7542b5686b194c396878f8d9a6da7652b7ca1f2f38cb4f6c114b31e84293df9d37d73777df4fa248a69c37170524d9c009c1d7c8de76ceb6
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 += "\x29#{i.size}\x18" + i
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
@@ -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) || (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)
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)
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sardonyx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.841
4
+ version: 0.1.842
5
5
  platform: ruby
6
6
  authors:
7
7
  - sugarfi