start with melon and tests
First step, create a basic class
This commit is contained in:
parent
b8cf72e729
commit
170d453a36
18
lib/melon/compiler.rb
Normal file
18
lib/melon/compiler.rb
Normal file
@ -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
|
@ -13,3 +13,6 @@ require "register"
|
||||
require "register/builtin/space"
|
||||
require "arm/arm_machine"
|
||||
require "arm/translator"
|
||||
|
||||
require "parser/ruby22"
|
||||
require "melon/compiler"
|
||||
|
@ -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
|
||||
|
||||
|
1
test/melon/compiler/helper.rb
Normal file
1
test/melon/compiler/helper.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative '../helper'
|
1
test/melon/compiler/test_all.rb
Normal file
1
test/melon/compiler/test_all.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative "test_class"
|
17
test/melon/compiler/test_class.rb
Normal file
17
test/melon/compiler/test_class.rb
Normal file
@ -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 = <<HERE
|
||||
class Testing
|
||||
end
|
||||
HERE
|
||||
Compiler.compile @string_input
|
||||
assert_equal 1 , Parfait::Space.object_space.classes.length - before , "No classes created"
|
||||
end
|
||||
end
|
||||
end
|
1
test/melon/helper.rb
Normal file
1
test/melon/helper.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative '../helper'
|
1
test/melon/test_all.rb
Normal file
1
test/melon/test_all.rb
Normal file
@ -0,0 +1 @@
|
||||
require_relative "compiler/test_all"
|
Loading…
x
Reference in New Issue
Block a user