Skip to content
Browse files

compile booleans, nil and string literals

  • Loading branch information...
1 parent 64bceb1 commit 7724386ab28e3adb217d7a3134ae09e2d49b58fc @txus committed
Showing with 36 additions and 0 deletions.
  1. +16 −0 lib/lambra/bytecode_compiler.rb
  2. +20 −0 spec/syntax/ast_spec.rb
View
16 lib/lambra/bytecode_compiler.rb
@@ -37,6 +37,22 @@ def visit_Number(o)
g.push_literal o.value
end
+ def visit_String(o)
+ g.push_literal o.value
+ end
+
+ def visit_True(o)
+ g.push_true
+ end
+
+ def visit_False(o)
+ g.push_false
+ end
+
+ def visit_Nil(o)
+ g.push_nil
+ end
+
def visit_Sequence(o)
o.elements.compact.each do |element|
element.accept(self)
View
20 spec/syntax/ast_spec.rb
@@ -55,24 +55,44 @@
describe "The True node" do
relates "true" do
parse { [:true] }
+
+ compile do |g|
+ g.push_true
+ g.ret
+ end
end
end
describe "The False node" do
relates "false" do
parse { [:false] }
+
+ compile do |g|
+ g.push_false
+ g.ret
+ end
end
end
describe "The Nil node" do
relates "nil" do
parse { [:nil] }
+
+ compile do |g|
+ g.push_nil
+ g.ret
+ end
end
end
describe "The String node" do
relates '"hello, world"' do
parse { [:string, "hello, world"] }
+
+ compile do |g|
+ g.push_literal "hello, world"
+ g.ret
+ end
end
end

0 comments on commit 7724386

Please sign in to comment.
Something went wrong with that request. Please try again.