sardonyx 0.1.84 → 0.1.85

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: f381674f5e870ec9ac7fe8f9ce699b1e851c7314ad9480201710bcd32e665185
4
- data.tar.gz: c42b1e66d327aa8bc0e39075c3778bd3b40beb7c82d47edce91a601418a82408
3
+ metadata.gz: 8c24e6115400ff31393984b7220c4226ea6f6a4fc8f9ba146f8d9f3ce51f749b
4
+ data.tar.gz: e1b92b4d17872047f11fe869d988370898dbebc74f5fe2ba4cb5e8d0ede648ec
5
5
  SHA512:
6
- metadata.gz: 43c77a34a4edf0b6a87af9183004a57d8cb285f115159240b5798c8ce37723e2f9018c5f5a630d2f7c102cbf50a42f181eee30685f74cf2ede839f1e5a224a72
7
- data.tar.gz: 83d259340d9dec63f6696de3a3d76832bc7c98880634df1139f5cd89042d7c7eb5c8cad1d27062fa027174344583a593d37698c96aac19328c7965b047d4ea34
6
+ metadata.gz: c87037ad33284bec4da7576040d214a45978ab5e018c5ef62152a2ae31858484df6f5f2e7899d6b29f9618a875d145f45960aa8c1efa22b97e60ff661b579eea
7
+ data.tar.gz: 2ed22a60d030ac9236075a3f97d992956753dc9c3cda125783f3e05f5c74c9d20ce3fe84a848b96b7933b2063efc9d1dd9a899f95d26957050dd7979de75d957
@@ -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,11 +10,13 @@ module Parser
10
10
  /\Aobject/ => :object,
11
11
  /\Anew/ => :new,
12
12
  /\Arequire/ => :require,
13
- /\A(<|>|<=|>=|==|!=)/ => :op,
14
- /\A(\+|-|\*|\/|%)?=/ => :eq,
15
- /\A(\+|-|\*|\/|%)/ => :op,
16
- /\A-?[0-9]+/ => :number,
13
+ /\A(true|false)/ => :bool,
17
14
  /\A-?[0-9]+\.[0-9]+/ => :float,
15
+ /\A-?[0-9]+/ => :number,
16
+ /\A(\+|-)/ => :l1op,
17
+ /\A(\/|\*|%)/ => :l2op,
18
+ /\A(<|>|<=|>=|==|!=)/ => :l1op,
19
+ /\A(\+|-|\*|\/|%)?=/ => :eq,
18
20
  /\A"([^"]|\\")*"/ => :string,
19
21
  /\Anil/ => :nil,
20
22
  /\A\(/ => :lpar,
@@ -97,6 +99,14 @@ module Parser
97
99
  end
98
100
  end
99
101
 
102
+ def self.parse_bool(tokens)
103
+ if self.expect tokens, :bool
104
+ [ (Node.new :bool, tokens[0][0], []), 1 ]
105
+ else
106
+ nil
107
+ end
108
+ end
109
+
100
110
  def self.parse_float(tokens)
101
111
  if self.expect tokens, :float
102
112
  [ (Node.new :float, tokens[0][0], []), 1 ]
@@ -189,7 +199,7 @@ module Parser
189
199
  end
190
200
 
191
201
  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)
202
+ (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
203
  end
194
204
 
195
205
  def self.parse_call(tokens)
@@ -350,7 +360,7 @@ module Parser
350
360
  return [ (Node.new :for, e, [name, block]), total ]
351
361
  end
352
362
 
353
- def self.parse_op(tokens)
363
+ def self.parse_term(tokens)
354
364
  total = 0
355
365
  unless self.parse_literal tokens
356
366
  return nil
@@ -358,16 +368,38 @@ module Parser
358
368
  lhs, part = self.parse_literal tokens
359
369
  total += part
360
370
  tokens = tokens[part..tokens.size]
361
- unless self.expect tokens, :op
371
+ unless self.expect tokens, :l2op
372
+ return [lhs, part]
373
+ end
374
+ op = tokens[0][0]
375
+ total += 1
376
+ tokens = tokens[1..tokens.size]
377
+ unless self.parse_literal tokens
378
+ return nil
379
+ end
380
+ rhs, part = self.parse_literal tokens
381
+ total += part
382
+ return [ (Node.new :op, op, [lhs, rhs]), total]
383
+ end
384
+
385
+ def self.parse_op(tokens)
386
+ total = 0
387
+ unless self.parse_term tokens
362
388
  return nil
363
389
  end
390
+ lhs, part = self.parse_term tokens
391
+ total += part
392
+ tokens = tokens[part..tokens.size]
393
+ unless self.expect tokens, :l1op
394
+ return [lhs, part]
395
+ end
364
396
  op = tokens[0][0]
365
397
  total += 1
366
398
  tokens = tokens[1..tokens.size]
367
- unless self.parse_expr tokens
399
+ unless self.parse_term tokens
368
400
  return nil
369
401
  end
370
- rhs, part = self.parse_expr tokens
402
+ rhs, part = self.parse_term tokens
371
403
  total += part
372
404
  return [ (Node.new :op, op, [lhs, rhs]), total]
373
405
  end
@@ -503,7 +535,7 @@ module Parser
503
535
  end
504
536
 
505
537
  def self.parse_expr(tokens)
506
- (self.parse_require tokens) || (self.parse_new tokens) || (self.parse_object tokens) || (self.parse_fn tokens) || (self.parse_assign tokens) || (self.parse_op tokens) || (self.parse_call tokens) || (self.parse_literal tokens) || (self.parse_if tokens) || (self.parse_while tokens) || (self.parse_for tokens)
538
+ (self.parse_require tokens) || (self.parse_new tokens) || (self.parse_object tokens) || (self.parse_fn tokens) || (self.parse_assign tokens) || (self.parse_op tokens) || (self.parse_term tokens) || (self.parse_call tokens) || (self.parse_literal tokens) || (self.parse_if tokens) || (self.parse_while tokens) || (self.parse_for tokens)
507
539
  end
508
540
 
509
541
  def self.parse(tokens, path)
@@ -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)
@@ -4,7 +4,11 @@ require 'sdx/vm/scope'
4
4
 
5
5
  def codify(val)
6
6
  if val.value.fields["__as_code_string"]
7
- (val.value.fields["__as_code_string"].call).internal
7
+ if val.value.fields["__as_code_string"].respond_to? :call
8
+ (val.value.fields["__as_code_string"].call).internal
9
+ else
10
+ (val.value.fields["__as_code_string"].fields["__call"].call [], val.scope).internal
11
+ end
8
12
  else
9
13
  val.value.pretty_inspect
10
14
  end
@@ -14,10 +18,14 @@ class VM
14
18
  attr_accessor :bc_io
15
19
 
16
20
  def truthy(val)
21
+ case val.value
22
+ when Bool
23
+ return val.value.internal
24
+ end
17
25
  if val.value.fields["__as_bool"]
18
- (val.value.fields["__as_bool"].call).internal
26
+ return (val.value.fields["__as_bool"].call).internal
19
27
  else
20
- true
28
+ return true
21
29
  end
22
30
  end
23
31
 
@@ -51,7 +59,7 @@ class VM
51
59
  when String
52
60
  to_var (Str.new val)
53
61
  when Float
54
- to_var (Float.new val)
62
+ to_var (Num.new val)
55
63
  when Array
56
64
  to_var (List.new val.map { |v| from_rb v })
57
65
  when Nil
@@ -271,12 +279,19 @@ class VM
271
279
  vals << pop_from_stack
272
280
  end
273
281
  vals.reverse!
274
- push_to_stack Variable.new (List.new vals), :list, @global
282
+ push_to_stack Variable.new (List.new vals, @global), :list, @global
275
283
  when :block
276
284
  size = get_string.to_i
277
285
  body =
278
286
  ((load_bytes size, false).map { |e| e.chr }).join ""
279
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
280
295
  when :nil
281
296
  push_to_stack Variable.new (Nil.new), :nil, @global
282
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.84
4
+ version: 0.1.85
5
5
  platform: ruby
6
6
  authors:
7
7
  - sugarfi