From 7045a4b25680221f92fdb1138712f2fe5bcce4de Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Tue, 1 Jul 2014 15:57:13 +0300 Subject: [PATCH] update reader and implement singletons --- Gemfile.lock | 2 +- lib/ast/basic_expressions.rb | 16 ++++++++++++++++ lib/virtual/constants.rb | 1 - lib/virtual/mystery.rb | 9 ++++++++- lib/virtual/value.rb | 6 ++++++ test/test_all.rb | 1 - test/virtual/test_basic.rb | 18 +++++++++++++++++- 7 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9d0f6893..fdf42c4c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,7 @@ GIT GIT remote: https://github.com/ruby-in-ruby/crystal-reader.git - revision: 3a56ae1a8d96845bbb80f760626c8203d57cb1c3 + revision: bc8697c733113b19863df632b546c7eab2b429c0 specs: crystal-reader (0.1.0) diff --git a/lib/ast/basic_expressions.rb b/lib/ast/basic_expressions.rb index a31b75f8..969ddf42 100644 --- a/lib/ast/basic_expressions.rb +++ b/lib/ast/basic_expressions.rb @@ -9,6 +9,22 @@ module Ast end end + class TrueExpression + def compile frame + Virtual::TrueValue.new + end + end + class FalseExpression + def compile frame + Virtual::FalseValue.new + end + end + class NilExpression + def compile frame + Virtual::NilValue.new + end + end + class NameExpression < Expression # attr_reader :name diff --git a/lib/virtual/constants.rb b/lib/virtual/constants.rb index a6e408f9..62d46a14 100644 --- a/lib/virtual/constants.rb +++ b/lib/virtual/constants.rb @@ -1,7 +1,6 @@ module Virtual class Constant < ::Virtual::Object - end # another abstract "marker" class (so we can check for it) diff --git a/lib/virtual/mystery.rb b/lib/virtual/mystery.rb index dbc0a466..a1ffb650 100644 --- a/lib/virtual/mystery.rb +++ b/lib/virtual/mystery.rb @@ -1,6 +1,6 @@ module Virtual class Mystery < Value - def initilize + def initialize end def as type @@ -8,4 +8,11 @@ module Virtual end end + + class TrueValue < Value + end + class FalseValue < Value + end + class NilValue < Value + end end diff --git a/lib/virtual/value.rb b/lib/virtual/value.rb index 7e37a0d5..1696d820 100644 --- a/lib/virtual/value.rb +++ b/lib/virtual/value.rb @@ -6,6 +6,12 @@ module Virtual # Integer and (Object) References are the main derived classes, but float will come and ... # The Mystery Value has unknown type and has only casting methods. So it must be cast to be useful. class Value + def == other + other.class == self.class + end + def inspect + self.class.name + ".new()" + end def type self.class end diff --git a/test/test_all.rb b/test/test_all.rb index 6c116a94..7b16790d 100644 --- a/test/test_all.rb +++ b/test/test_all.rb @@ -1,2 +1 @@ require_relative "fragments/test_all" -require_relative "test_intel" diff --git a/test/virtual/test_basic.rb b/test/virtual/test_basic.rb index 7f544fa7..5a54eec9 100644 --- a/test/virtual/test_basic.rb +++ b/test/virtual/test_basic.rb @@ -3,13 +3,29 @@ require_relative "virtual_helper" class TestBasic < MiniTest::Test # include the magic (setup and parse -> test method translation), see there include VirtualHelper - + def test_number @string_input = '42 ' @output = [Virtual::IntegerConstant.new(42)] check end + def test_true + @string_input = 'true ' + @output = [Virtual::TrueValue.new()] + check + end + def test_false + @string_input = 'false ' + @output = [Virtual::FalseValue.new()] + check + end + def test_nil + @string_input = 'nil ' + @output = [Virtual::NilValue.new()] + check + end + def test_name @string_input = 'foo ' @output = [nil]