first oo program to compile. But no worries, there is still work left to be done
This commit is contained in:
@ -38,7 +38,6 @@ module Vm
|
||||
end
|
||||
unless fun
|
||||
fun = Core::Kernel.send(name , @context)
|
||||
return nil if fun == nil
|
||||
@functions << fun
|
||||
end
|
||||
fun
|
||||
@ -47,6 +46,9 @@ module Vm
|
||||
def inspect
|
||||
"BootClass #{@name} , super #{@super_class} #{@functions.length} functions"
|
||||
end
|
||||
def to_s
|
||||
inspect
|
||||
end
|
||||
# Code interface follows. Note position is inheitted as is from Code
|
||||
|
||||
# length of the class is the length of it's functions
|
||||
|
@ -4,6 +4,7 @@ require_relative "call_site"
|
||||
require "arm/arm_machine"
|
||||
require "core/kernel"
|
||||
require "boot/object"
|
||||
require "boot/string"
|
||||
|
||||
module Vm
|
||||
# The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo
|
||||
@ -48,6 +49,11 @@ module Vm
|
||||
puts "adding #{f}"
|
||||
obj.add_function Boot::Object.send(f , @context)
|
||||
end
|
||||
obj = get_or_create_class :String
|
||||
[:get , :set].each do |f|
|
||||
puts "adding #{f}"
|
||||
obj.add_function Boot::String.send(f , @context)
|
||||
end
|
||||
end
|
||||
def add_object o
|
||||
return if @objects.include? o
|
||||
|
@ -4,13 +4,14 @@ module Vm
|
||||
|
||||
class CallSite < Value
|
||||
|
||||
def initialize(name , args , function )
|
||||
def initialize(name , value , args , function )
|
||||
@name = name
|
||||
@value = value
|
||||
@args = args
|
||||
@function = function
|
||||
end
|
||||
attr_reader :function , :args , :name
|
||||
|
||||
attr_reader :function , :args , :name , :value
|
||||
|
||||
def load_args into
|
||||
args.each_with_index do |arg , index|
|
||||
if arg.is_a?(IntegerConstant) or arg.is_a?(StringConstant)
|
||||
|
@ -15,6 +15,9 @@ module Vm
|
||||
@integer = int
|
||||
end
|
||||
attr_reader :integer
|
||||
def value
|
||||
@integer
|
||||
end
|
||||
end
|
||||
|
||||
# The name really says it all.
|
||||
|
@ -65,7 +65,8 @@ module Vm
|
||||
def new_local type = Vm::Integer
|
||||
register = args.length + @locals.length
|
||||
l = type.new(register + 1) # one for the type register 0, TODO add type as arg0 implicitly
|
||||
raise "the red flag #{inspect}" if l.register > 6
|
||||
puts "new local #{l.register}"
|
||||
# raise "Register overflow in function #{name}" if l.register > 6
|
||||
@locals << l
|
||||
l
|
||||
end
|
||||
|
@ -30,8 +30,22 @@ module Vm
|
||||
puts "no function for #{name} in Meta #{@me_self.inspect}" unless f
|
||||
f
|
||||
end
|
||||
# way of creating new functions that have not been parsed.
|
||||
def get_or_create_function name
|
||||
fun = get_function name
|
||||
unless fun or name == :Object
|
||||
supr = @context.object_space.get_or_create_class(@super_class)
|
||||
fun = supr.get_function name
|
||||
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
||||
end
|
||||
fun
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#{@me_self}, #{@functions.length} functions"
|
||||
"MetaClass on #{@me_self}, #{@functions.length} functions"
|
||||
end
|
||||
def to_s
|
||||
inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user