fix and test compiling classes
This commit is contained in:
parent
ae7350bd57
commit
0a09477dc6
@ -60,8 +60,8 @@ module Parfait
|
||||
kernel.get_instance_method :__init__
|
||||
end
|
||||
|
||||
# this is the way to instantiate classes (not Parfait::Class.new)
|
||||
# so we get and keep exactly one per name
|
||||
# get a class by name (symbol)
|
||||
# return nili if no such class. Use bang version if create should be implicit
|
||||
def get_class_by_name name
|
||||
raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol)
|
||||
c = @classes[name]
|
||||
@ -69,6 +69,16 @@ module Parfait
|
||||
c
|
||||
end
|
||||
|
||||
# get or create the class by the (symbol) name
|
||||
# notice that this method of creating classes implies Object superclass
|
||||
def get_class_by_name! name
|
||||
c = get_class_by_name(name)
|
||||
return c if c
|
||||
create_class name , get_class_by_name(:Object)
|
||||
end
|
||||
|
||||
# this is the way to instantiate classes (not Parfait::Class.new)
|
||||
# so we get and keep exactly one per name
|
||||
def create_class name , superclass
|
||||
raise "uups #{name.class}" unless name.is_a? Symbol
|
||||
c = Class.new_object(name , superclass)
|
||||
|
@ -6,7 +6,7 @@ module Virtual
|
||||
end
|
||||
|
||||
def self.compile_class expression , method
|
||||
clazz = ::Space.space.get_class_by_name expression.name
|
||||
clazz = Parfait::Space.object_space.get_class_by_name! expression.name
|
||||
puts "Created class #{clazz.name.inspect}"
|
||||
expression.expressions.each do |expr|
|
||||
# check if it's a function definition and add
|
||||
|
@ -17,6 +17,18 @@ module Virtual
|
||||
end
|
||||
end
|
||||
|
||||
def test_module
|
||||
@string_input = <<HERE
|
||||
class Some
|
||||
def foo()
|
||||
5
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@output = [[MethodEnter] ,[MethodReturn]]
|
||||
check
|
||||
end
|
||||
|
||||
def test_simplest_function
|
||||
@string_input = <<HERE
|
||||
def foo(x)
|
||||
|
Loading…
Reference in New Issue
Block a user