bring class methods down to mom
not functionally correct, still compiling into class, not metaclass part of #24
This commit is contained in:
parent
40581494de
commit
2fbea82039
@ -20,15 +20,9 @@ module Vool
|
||||
@body.each(&block)
|
||||
end
|
||||
|
||||
def has_yield?
|
||||
each{|statement| return true if statement.is_a?(YieldStatement)}
|
||||
return false
|
||||
end
|
||||
|
||||
def make_arg_type( )
|
||||
type_hash = {}
|
||||
@args.each {|arg| type_hash[arg] = :Object }
|
||||
type_hash[:implicit_block] = :Block if has_yield?
|
||||
Parfait::NamedList.type_for( type_hash )
|
||||
end
|
||||
|
||||
@ -42,10 +36,6 @@ module Vool
|
||||
def make_frame
|
||||
nodes = []
|
||||
@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 = {}
|
||||
nodes.each do |node|
|
||||
next unless node.is_a?(LocalVariable) or node.is_a?(LocalAssignment)
|
||||
|
@ -20,7 +20,9 @@ module Vool
|
||||
def to_mom( _ )
|
||||
create_class_object
|
||||
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)
|
||||
end
|
||||
Mom::MomCompiler.new(method_compilers)
|
||||
|
@ -39,5 +39,14 @@ module Vool
|
||||
|
||||
class ModuleName < Expression
|
||||
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
|
||||
|
23
test/vool/blocks/test_class_blocks.rb
Normal file
23
test/vool/blocks/test_class_blocks.rb
Normal 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
|
30
test/vool/send/test_send_class.rb
Normal file
30
test/vool/send/test_send_class.rb
Normal 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
|
Loading…
Reference in New Issue
Block a user