fix and test compiling classes

This commit is contained in:
Torsten Ruger 2015-07-19 10:36:06 +03:00
parent ae7350bd57
commit 0a09477dc6
3 changed files with 25 additions and 3 deletions

View File

@ -60,8 +60,8 @@ module Parfait
kernel.get_instance_method :__init__ kernel.get_instance_method :__init__
end end
# this is the way to instantiate classes (not Parfait::Class.new) # get a class by name (symbol)
# so we get and keep exactly one per name # return nili if no such class. Use bang version if create should be implicit
def get_class_by_name name def get_class_by_name name
raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol) raise "uups #{name}.#{name.class}" unless name.is_a?(Symbol)
c = @classes[name] c = @classes[name]
@ -69,6 +69,16 @@ module Parfait
c c
end 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 def create_class name , superclass
raise "uups #{name.class}" unless name.is_a? Symbol raise "uups #{name.class}" unless name.is_a? Symbol
c = Class.new_object(name , superclass) c = Class.new_object(name , superclass)

View File

@ -6,7 +6,7 @@ module Virtual
end end
def self.compile_class expression , method 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}" puts "Created class #{clazz.name.inspect}"
expression.expressions.each do |expr| expression.expressions.each do |expr|
# check if it's a function definition and add # check if it's a function definition and add

View File

@ -17,6 +17,18 @@ module Virtual
end end
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 def test_simplest_function
@string_input = <<HERE @string_input = <<HERE
def foo(x) def foo(x)