Permalink
Browse files

Compile sets

  • Loading branch information...
1 parent 87c93b6 commit 904619b23c950de7b0376246d538c1b24d449c0a @txus committed May 12, 2012
Showing with 34 additions and 0 deletions.
  1. +15 −0 lib/lambra/bytecode_compiler.rb
  2. +19 −0 spec/syntax/ast_spec.rb
@@ -88,6 +88,21 @@ def visit_Vector(o)
g.make_array count
end
+ def visit_Set(o)
+ set_line(o)
+
+ g.push_cpath_top
+ g.find_const :Set
+
+ count = o.elements.count
+ o.elements.each do |elem|
+ elem.accept(self)
+ end
+ g.make_array count
+
+ g.send :new, 1
+ end
+
def visit_Map(o)
set_line(o)
View
@@ -233,10 +233,29 @@
describe "The Set node" do
relates '#{}' do
parse { [:set] }
+
+ compile do |g|
+ g.push_cpath_top
+ g.find_const :Set
+ g.make_array 0
+ g.send :new, 1
+ g.ret
+ end
end
relates '#{:a :b :c}' do
parse { [:set, [:keyword, :a], [:keyword, :b], [:keyword, :c]] }
+
+ compile do |g|
+ g.push_cpath_top
+ g.find_const :Set
+ g.push_literal :a
+ g.push_literal :b
+ g.push_literal :c
+ g.make_array 3
+ g.send :new, 1
+ g.ret
+ end
end
end

0 comments on commit 904619b

Please sign in to comment.