Permalink
Browse files

Make keyword a full blown object

  • Loading branch information...
1 parent 904619b commit d081769673ce68fe809380ff56247b88c9574a91 @txus committed May 12, 2012
Showing with 34 additions and 5 deletions.
  1. +3 −0 lib/lambra/bytecode_compiler.rb
  2. +31 −5 spec/syntax/ast_spec.rb
@@ -66,7 +66,10 @@ def visit_Nil(o)
def visit_Keyword(o)
set_line(o)
+ g.push_cpath_top
+ g.find_const :Keyword
g.push_literal o.name
+ g.send :new, 1
end
def visit_Sequence(o)
View
@@ -20,6 +20,13 @@
describe "The Keyword node" do
relates ":hello-world" do
parse { [:keyword, :"hello-world"] }
+ compile do |g|
+ g.push_cpath_top
+ g.find_const :Keyword
+ g.push_literal :"hello-world"
+ g.send :new, 1
+ g.ret
+ end
end
end
@@ -214,13 +221,19 @@
g.send :new_from_literal, 1
g.dup_top
- g.push_literal :a
+ g.push_cpath_top
+ g.find_const :Keyword
+ g.push_literal :a
+ g.send :new, 1
g.push_literal 1
g.send :[]=, 2
g.pop
g.dup_top
- g.push_literal :b
+ g.push_cpath_top
+ g.find_const :Keyword
+ g.push_literal :b
+ g.send :new, 1
g.push_literal 2
g.send :[]=, 2
g.pop
@@ -249,9 +262,22 @@
compile do |g|
g.push_cpath_top
g.find_const :Set
- g.push_literal :a
- g.push_literal :b
- g.push_literal :c
+
+ g.push_cpath_top
+ g.find_const :Keyword
+ g.push_literal :a
+ g.send :new, 1
+
+ g.push_cpath_top
+ g.find_const :Keyword
+ g.push_literal :b
+ g.send :new, 1
+
+ g.push_cpath_top
+ g.find_const :Keyword
+ g.push_literal :c
+ g.send :new, 1
+
g.make_array 3
g.send :new, 1
g.ret

0 comments on commit d081769

Please sign in to comment.