bring class methods down to mom

not functionally correct, still compiling into class, not metaclass
part of #24
This commit is contained in:
Torsten Ruger 2019-02-16 17:54:45 +02:00
parent 40581494de
commit 2fbea82039
5 changed files with 65 additions and 11 deletions

View File

@ -20,15 +20,9 @@ module Vool
@body.each(&block) @body.each(&block)
end end
def has_yield?
each{|statement| return true if statement.is_a?(YieldStatement)}
return false
end
def make_arg_type( ) def make_arg_type( )
type_hash = {} type_hash = {}
@args.each {|arg| type_hash[arg] = :Object } @args.each {|arg| type_hash[arg] = :Object }
type_hash[:implicit_block] = :Block if has_yield?
Parfait::NamedList.type_for( type_hash ) Parfait::NamedList.type_for( type_hash )
end end
@ -42,10 +36,6 @@ module Vool
def make_frame def make_frame
nodes = [] nodes = []
@body.each { |node| nodes << node } @body.each { |node| nodes << node }
nodes.dup.each do |node|
next unless node.is_a?(BlockStatement)
node.each {|block_scope| nodes.delete(block_scope)}
end
type_hash = {} type_hash = {}
nodes.each do |node| nodes.each do |node|
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment) next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)

View File

@ -20,7 +20,9 @@ module Vool
def to_mom( _ ) def to_mom( _ )
create_class_object create_class_object
method_compilers = body.statements.collect do |node| method_compilers = body.statements.collect do |node|
raise "Only methods for now #{node}" unless node.is_a?(MethodStatement) unless node.is_a?(MethodStatement) or node.is_a?(ClassMethodStatement)
raise "Only methods for now #{node.class}:#{node}"
end
node.to_mom(@clazz) node.to_mom(@clazz)
end end
Mom::MomCompiler.new(method_compilers) Mom::MomCompiler.new(method_compilers)

View File

@ -39,5 +39,14 @@ module Vool
class ModuleName < Expression class ModuleName < Expression
include Named include Named
def ct_type
get_named_class.instance_type
end
def slot_definition(_)
return Mom::SlotDefinition.new( get_named_class, [])
end
def get_named_class
Parfait.object_space.get_class_by_name(self.name)
end
end end
end end

View File

@ -0,0 +1,23 @@
require_relative "../helper"
module VoolBlocks
class TestClassAssignMom < MiniTest::Test
include MomCompile
def setup
Parfait.boot!(Parfait.default_test_options)
end
def as_class_method(source)
"class Space;def self.main();#{source};end;end"
end
def test_block_not_compiles
source = "main{|val| val = 0}"
vool = Ruby::RubyCompiler.compile( as_class_method(source) ).to_vool
begin
vool.to_mom(nil)
rescue => err
assert err.message.include?("Blocks")
end
end
end
end

View File

@ -0,0 +1,30 @@
require_relative "helper"
module Vool
class TestSendClassMom < MiniTest::Test
include SimpleSendHarness
include Mom
def send_method
"Object.get_internal_word(0)"
end
def test_receiver
assert_equal SlotDefinition, @ins.next.receiver.class
end
def test_arg_one
assert_equal SlotLoad, @ins.next(1).arguments[0].class
end
def test_call_two
assert_equal SimpleCall, @ins.next(2).class
end
def test_call_has_method
assert_equal Parfait::CallableMethod, @ins.next(2).method.class
end
def test_call_has_right_method
assert_equal :get_internal_word, @ins.next(2).method.name
end
def test_call_has_right_receiver
assert_equal "Object_Type", @ins.next(2).method.self_type.name
end
end
end