diff --git a/lib/melon/compiler.rb b/lib/melon/compiler.rb new file mode 100644 index 00000000..8873ea97 --- /dev/null +++ b/lib/melon/compiler.rb @@ -0,0 +1,18 @@ + + +module Melon + class Compiler < AST::Processor + + def self.compile input + ast = Parser::Ruby22.parse input + compiler = self.new + compiler.process ast + end + + def on_class statement + name , _ , _ = *statement + clazz_name = name.children[1] + Parfait::Space.object_space.create_class(clazz_name , nil ) + end + end +end diff --git a/lib/salama.rb b/lib/salama.rb index 7d377f93..279c6563 100644 --- a/lib/salama.rb +++ b/lib/salama.rb @@ -13,3 +13,6 @@ require "register" require "register/builtin/space" require "arm/arm_machine" require "arm/translator" + +require "parser/ruby22" +require "melon/compiler" diff --git a/lib/typed/parfait/space.rb b/lib/typed/parfait/space.rb index 89a490f1..da476663 100644 --- a/lib/typed/parfait/space.rb +++ b/lib/typed/parfait/space.rb @@ -83,7 +83,8 @@ module Parfait # so we get and keep exactly one per name def create_class name , superclass raise "create_class #{name.class}" unless name.is_a? Symbol - c = Class.new(name , superclass) + superclass = :Object unless superclass + c = Class.new(name , superclass ) self.classes[name] = c end diff --git a/test/melon/compiler/helper.rb b/test/melon/compiler/helper.rb new file mode 100644 index 00000000..3f91a123 --- /dev/null +++ b/test/melon/compiler/helper.rb @@ -0,0 +1 @@ +require_relative '../helper' diff --git a/test/melon/compiler/test_all.rb b/test/melon/compiler/test_all.rb new file mode 100644 index 00000000..9e6f195a --- /dev/null +++ b/test/melon/compiler/test_all.rb @@ -0,0 +1 @@ +require_relative "test_class" diff --git a/test/melon/compiler/test_class.rb b/test/melon/compiler/test_class.rb new file mode 100644 index 00000000..63468091 --- /dev/null +++ b/test/melon/compiler/test_class.rb @@ -0,0 +1,17 @@ +require_relative "helper" + +module Melon + class TestClass < MiniTest::Test + + def test_creates_class + Register.machine.boot + before = Parfait::Space.object_space.classes.length + @string_input = <