more speration
Separating vm and parfait especially in method this is hairy, lots of ripples bug is back in sod (i hope thats a good thing)
This commit is contained in:
parent
d6d0f4f43a
commit
6eba363fb8
@ -2,6 +2,7 @@ require "parfait/value"
|
|||||||
require "parfait/object"
|
require "parfait/object"
|
||||||
require "parfait/module"
|
require "parfait/module"
|
||||||
require "parfait/class"
|
require "parfait/class"
|
||||||
|
require "parfait/method"
|
||||||
require "parfait/dictionary"
|
require "parfait/dictionary"
|
||||||
require "parfait/list"
|
require "parfait/list"
|
||||||
require "parfait/layout"
|
require "parfait/layout"
|
||||||
|
@ -34,7 +34,7 @@ module Parfait
|
|||||||
# used to determine if a send must be issued
|
# used to determine if a send must be issued
|
||||||
# return index of the name into the message if so
|
# return index of the name into the message if so
|
||||||
def has_var name
|
def has_var name
|
||||||
name = name.to_sym
|
raise "uups #{name}.#{name.class}" unless name.is_a? Word
|
||||||
index = has_arg(name)
|
index = has_arg(name)
|
||||||
return index if index
|
return index if index
|
||||||
has_local(name)
|
has_local(name)
|
||||||
|
@ -14,15 +14,20 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
class Module < Object
|
class Module < Object
|
||||||
def initialize name , superclass
|
def initialize name , superclass
|
||||||
|
@name = name
|
||||||
@instance_methods = []
|
@instance_methods = []
|
||||||
@name = name
|
@name = name
|
||||||
@super_class = superclass
|
@super_class = superclass
|
||||||
@meta_class = Virtual::MetaClass.new(self)
|
@meta_class = Virtual::MetaClass.new(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def name
|
||||||
|
@name
|
||||||
|
end
|
||||||
|
|
||||||
def add_instance_method method
|
def add_instance_method method
|
||||||
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
raise "not a method #{method.class} #{method.inspect}" unless method.is_a? Method
|
||||||
raise "syserr " unless method.name.is_a? Symbol
|
raise "syserr #{method.name.class}" unless method.name.is_a? Word
|
||||||
method.for_class = self
|
method.for_class = self
|
||||||
@instance_methods << method
|
@instance_methods << method
|
||||||
method
|
method
|
||||||
|
@ -64,13 +64,16 @@ module Parfait
|
|||||||
# this is the way to instantiate classes (not Parfait::Class.new)
|
# this is the way to instantiate classes (not Parfait::Class.new)
|
||||||
# so we get and keep exactly one per name
|
# so we get and keep exactly one per name
|
||||||
def get_class_by_name name
|
def get_class_by_name name
|
||||||
raise "uups #{name}.#{name.class}" unless name.is_a? String or name.is_a? Word
|
raise "uups #{name}.#{name.class}" unless name.is_a? Word
|
||||||
c = @classes[name]
|
c = @classes[name]
|
||||||
|
raise "uups " if name.is_a? String
|
||||||
|
puts "MISS, no class #{name} #{name.class}" # " #{@classes}"
|
||||||
c
|
c
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_class name
|
def create_class name
|
||||||
c = Class.new_object(name)
|
c = Class.new_object(name)
|
||||||
|
raise "uups " if name.is_a? String
|
||||||
@classes[name] = c
|
@classes[name] = c
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ module Virtual
|
|||||||
# (not use the normal initialize way)
|
# (not use the normal initialize way)
|
||||||
def boot_parfait!
|
def boot_parfait!
|
||||||
@space = Parfait::Space.new_object
|
@space = Parfait::Space.new_object
|
||||||
object_class = Parfait::Class.new_object "Parfait::Object"
|
boot_classes!
|
||||||
space_class = Parfait::Class.new_object "Parfait::Space" , object_class
|
#space_layout =
|
||||||
space_layout = Parfait::Layout.new_object space_class
|
# Parfait::Layout.new_object space_class
|
||||||
|
|
||||||
puts "Space #{space.get_layout}"
|
puts "Space #{space.get_layout}"
|
||||||
end
|
end
|
||||||
@ -27,13 +27,13 @@ module Virtual
|
|||||||
puts "BOOT"
|
puts "BOOT"
|
||||||
values = [ "Integer" , "Object" , "Value" , "Kernel"]
|
values = [ "Integer" , "Object" , "Value" , "Kernel"]
|
||||||
rest = ["Word" , "Class" , "Dictionary" , "Space" , "List", "Layout"]
|
rest = ["Word" , "Class" , "Dictionary" , "Space" , "List", "Layout"]
|
||||||
(values + rest).each { |cl| @space.create_class(cl) }
|
(values + rest).each { |cl| @space.create_class(Virtual.new_word(cl)) }
|
||||||
value_class = @space.get_class_by_name "Value"
|
value_class = @space.get_class_by_name Virtual.new_word("Value")
|
||||||
@space.get_class_by_name("Integer").set_super_class( value_class )
|
@space.get_class_by_name(Virtual.new_word("Integer")).set_super_class( value_class )
|
||||||
object_class = @space.get_class_by_name("Object")
|
object_class = @space.get_class_by_name(Virtual.new_word("Object"))
|
||||||
object_class.set_super_class( value_class )
|
object_class.set_super_class( value_class )
|
||||||
rest.each do |name|
|
rest.each do |name|
|
||||||
cl = @space.get_class_by_name( name )
|
cl = @space.get_class_by_name( Virtual.new_word( name ))
|
||||||
cl.set_super_class(object_class)
|
cl.set_super_class(object_class)
|
||||||
end
|
end
|
||||||
boot_layouts!
|
boot_layouts!
|
||||||
@ -73,7 +73,7 @@ module Virtual
|
|||||||
[:putint,:fibo].each do |f|
|
[:putint,:fibo].each do |f|
|
||||||
obj.add_instance_method Builtin::Integer.send(f , nil)
|
obj.add_instance_method Builtin::Integer.send(f , nil)
|
||||||
end
|
end
|
||||||
obj = @space.get_class_by_name "Word"
|
obj = @space.get_class_by_name Virtual.new_word "Word"
|
||||||
[:get , :set , :puts].each do |f|
|
[:get , :set , :puts].each do |f|
|
||||||
obj.add_instance_method Builtin::Word.send(f , nil)
|
obj.add_instance_method Builtin::Word.send(f , nil)
|
||||||
end
|
end
|
||||||
|
@ -31,7 +31,7 @@ module Virtual
|
|||||||
# return the main function (the top level) into which code is compiled
|
# return the main function (the top level) into which code is compiled
|
||||||
# this just create a "main" with create_method , see there
|
# this just create a "main" with create_method , see there
|
||||||
def self.main
|
def self.main
|
||||||
self.create_method( "Object" , :main , [] )
|
self.create_method( "Object" , "main" , [] )
|
||||||
end
|
end
|
||||||
|
|
||||||
# create method does two things
|
# create method does two things
|
||||||
@ -40,6 +40,8 @@ module Virtual
|
|||||||
#
|
#
|
||||||
# compile code then works with the method, but adds code tot the info
|
# compile code then works with the method, but adds code tot the info
|
||||||
def self.create_method( class_name , method_name , args)
|
def self.create_method( class_name , method_name , args)
|
||||||
|
raise "uups #{class_name}.#{class_name.class}" if class_name.is_a? Symbol
|
||||||
|
raise "uups #{method_name}.#{method_name.class}" if class_name.is_a? Symbol
|
||||||
class_name = Virtual.new_word(class_name) if class_name.is_a? String
|
class_name = Virtual.new_word(class_name) if class_name.is_a? String
|
||||||
method_name = Virtual.new_word(method_name) if method_name.is_a? String
|
method_name = Virtual.new_word(method_name) if method_name.is_a? String
|
||||||
clazz = Machine.instance.space.get_class_by_name class_name
|
clazz = Machine.instance.space.get_class_by_name class_name
|
||||||
@ -48,15 +50,16 @@ module Virtual
|
|||||||
method.info = CompiledMethodInfo.new
|
method.info = CompiledMethodInfo.new
|
||||||
method
|
method
|
||||||
end
|
end
|
||||||
def initialize receiver = Virtual::Self.new , return_type = Virtual::Mystery
|
def initialize return_type = Virtual::Mystery
|
||||||
# first block we have to create with .new , as new_block assumes a current
|
# first block we have to create with .new , as new_block assumes a current
|
||||||
enter = Block.new( "enter" , self ).add_code(MethodEnter.new())
|
enter = Block.new( "enter" , self ).add_code(MethodEnter.new())
|
||||||
|
@return_type = return_type
|
||||||
@blocks = [enter]
|
@blocks = [enter]
|
||||||
@current = enter
|
@current = enter
|
||||||
new_block("return").add_code(MethodReturn.new)
|
new_block("return").add_code(MethodReturn.new)
|
||||||
end
|
end
|
||||||
attr_reader :receiver , :blocks
|
attr_reader :blocks
|
||||||
attr_accessor :return_type , :current
|
attr_accessor :return_type , :current , :receiver
|
||||||
|
|
||||||
# add an instruction after the current (insertion point)
|
# add an instruction after the current (insertion point)
|
||||||
# the added instruction will become the new insertion point
|
# the added instruction will become the new insertion point
|
||||||
|
@ -6,11 +6,20 @@ module Virtual
|
|||||||
raise "error, argument must be a identifier, not #{p}" unless p.is_a? Ast::NameExpression
|
raise "error, argument must be a identifier, not #{p}" unless p.is_a? Ast::NameExpression
|
||||||
p.name
|
p.name
|
||||||
end
|
end
|
||||||
r = expression.receiver ? Compiler.compile(expression.receiver, method ) : Self.new()
|
if expression.receiver
|
||||||
new_method = CompiledMethodInfo.create_method(expression.name , args , r )
|
#Do something clever instead of
|
||||||
new_method.class_name = r.is_a?(Parfait::Class) ? r.name : method.class_name
|
r = Compiler.compile(expression.receiver, method )
|
||||||
clazz = Machine.instance.space.get_class_by_name(new_method.class_name)
|
if( r.is_a? Parfait::Class )
|
||||||
clazz.add_instance_method new_method
|
class_name = r.name
|
||||||
|
else
|
||||||
|
raise "unimplemented #{r}"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
r = Self.new()
|
||||||
|
class_name = method.for_class.name
|
||||||
|
end
|
||||||
|
new_method = CompiledMethodInfo.create_method(class_name, expression.name.to_s , args )
|
||||||
|
new_method.info.receiver = r
|
||||||
|
|
||||||
#frame = frame.new_frame
|
#frame = frame.new_frame
|
||||||
return_type = nil
|
return_type = nil
|
||||||
@ -18,7 +27,7 @@ module Virtual
|
|||||||
return_type = Compiler.compile(ex,new_method )
|
return_type = Compiler.compile(ex,new_method )
|
||||||
raise return_type.inspect if return_type.is_a? Instruction
|
raise return_type.inspect if return_type.is_a? Instruction
|
||||||
end
|
end
|
||||||
new_method.return_type = return_type
|
new_method.info.return_type = return_type
|
||||||
new_method
|
new_method
|
||||||
end
|
end
|
||||||
def scratch
|
def scratch
|
||||||
|
@ -93,7 +93,7 @@ module Virtual
|
|||||||
def compile_main bytes
|
def compile_main bytes
|
||||||
syntax = @parser.parse_with_debug(bytes)
|
syntax = @parser.parse_with_debug(bytes)
|
||||||
parts = Parser::Transform.new.apply(syntax)
|
parts = Parser::Transform.new.apply(syntax)
|
||||||
main = Virtual::CompiledMethod.main
|
main = Virtual::CompiledMethodInfo.main
|
||||||
Compiler.compile( parts , main )
|
Compiler.compile( parts , main )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user