This commit is contained in:
Torsten Ruger
2014-06-26 17:52:15 +03:00
parent 33c62a7db1
commit 525f9d45c5
16 changed files with 134 additions and 54 deletions

View File

@ -3,7 +3,7 @@ require_relative "meta_class"
module Boot
# class is mainly a list of functions with a name (for now)
# layout of object is seperated into Layout
class BootClass < Vm::ObjectConstant
class BootClass < Virtual::ObjectConstant
def initialize name , context , super_class = :Object
super()
@context = context
@ -16,7 +16,7 @@ module Boot
attr_reader :name , :functions , :meta_class , :context , :super_class
def add_function function
raise "not a function #{function}" unless function.is_a? Vm::Function
raise "not a function #{function}" unless function.is_a? Virtual::Function
raise "syserr " unless function.name.is_a? Symbol
@functions << function
end

View File

@ -18,28 +18,28 @@ module Boot
# throwing in a context for unspecified use (well one is to pass the programm/globals around)
class BootSpace < Vm::Code
class BootSpace < Virtual::Code
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
# with a XXXMachine in it that derives from Vm::RegisterMachine
# with a XXXMachine in it that derives from Virtual::RegisterMachine
def initialize machine = nil
super()
machine = RbConfig::CONFIG["host_cpu"] unless machine
machine = "intel" if machine == "x86_64"
machine = machine.capitalize
Vm::RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
Virtual::RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
@classes = {}
@context = Vm::Context.new(self)
@context = Virtual::Context.new(self)
@context.current_class = get_or_create_class :Object
@main = Vm::Function.new("main")
@main = Virtual::Function.new("main")
@context.function = @main
#global objects (data)
@objects = []
@entry = Vm::RegisterMachine.instance.main_start @context
@entry = Virtual::RegisterMachine.instance.main_start @context
#main gets executed between entry and exit
@exit = Vm::RegisterMachine.instance.main_exit @context
@exit = Virtual::RegisterMachine.instance.main_exit @context
boot_classes
@passes = [ Vm::MoveMoveReduction.new , Vm::LogicMoveReduction.new, Vm::NoopReduction.new, Vm::SaveLocals.new ]
@passes = [ Virtual::MoveMoveReduction.new , Virtual::LogicMoveReduction.new, Virtual::NoopReduction.new, Virtual::SaveLocals.new ]
end
attr_reader :context , :main , :classes , :entry , :exit
@ -81,7 +81,7 @@ module Boot
# Objects are data and get assembled after functions
def add_object o
return if @objects.include? o
raise "must be derived from Code #{o.inspect}" unless o.is_a? Vm::Code
raise "must be derived from Code #{o.inspect}" unless o.is_a? Virtual::Code
@objects << o # TODO check type , no basic values allowed (must be wrapped)
end

View File

@ -8,7 +8,7 @@ module Boot
# PS: can't say i fancy the << self syntax and am considerernig adding a keyword for it, like meta
# In effect it is a very similar construct to def self.function(...)
# So one could write def meta.function(...) and thus define on the meta-class
class MetaClass < Vm::ObjectConstant
class MetaClass < Virtual::ObjectConstant
# no name, nor nothing. as this is just the object really
def initialize(object)
@ -19,7 +19,7 @@ module Boot
# in a non-booting version this should map to _add_singleton_method
def add_function function
raise "not a function #{function}" unless function.is_a? Vm::Function
raise "not a function #{function}" unless function.is_a? Virtual::Function
raise "syserr " unless function.name.is_a? Symbol
@functions << function
end

View File

@ -5,13 +5,13 @@ module Boot
# return the index of the variable. Now "normal" code can't really do anything with that, but
# set/get instance variable use it.
# This is just a placeholder, as we code this in ruby, but the instance methods need the definition before.
def index_of context , name = Vm::Integer
index_function = Vm::Function.new(:index_of , Vm::Reference , [Vm::Reference] , Vm::Integer )
def index_of context , name = Virtual::Integer
index_function = Virtual::Function.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
return index_function
end
def self.layout
layout_function = Vm::Function.new(:layout , Vm::Reference , [ ] , Vm::Reference )
layout_function = Virtual::Function.new(:layout , Virtual::Reference , [ ] , Virtual::Reference )
layout_function.at_index 2
layout_function
end
@ -22,8 +22,8 @@ module Boot
# return at_index(i)
# end
# The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby
def _get_instance_variable context , name = Vm::Integer
get_function = Vm::Function.new(:_get_instance_variable , Vm::Reference , [ Vm::Reference ] , Vm::Mystery )
def _get_instance_variable context , name = Virtual::Integer
get_function = Virtual::Function.new(:_get_instance_variable , Virtual::Reference , [ Virtual::Reference ] , Virtual::Mystery )
me = get_function.receiver
var_name = get_function.args.first
return_to = get_function.return_type
@ -42,8 +42,8 @@ module Boot
return get_function
end
def _set_instance_variable(context , name = Vm::Integer , value = Vm::Integer )
set_function = Vm::Function.new(:_set_instance_variable , Vm::Reference ,[Vm::Reference ,Vm::Reference], Vm::Mystery )
def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer )
set_function = Virtual::Function.new(:_set_instance_variable , Virtual::Reference ,[Virtual::Reference ,Virtual::Reference], Virtual::Mystery )
me = set_function.receiver
var_name = set_function.args.first
return_to = set_function.return_type

View File

@ -1,12 +1,12 @@
module Boot
class String
module ClassMethods
def get context , index = Vm::Integer
get_function = Vm::Function.new(:get , Vm::Integer , [ Vm::Integer] , Vm::Integer )
def get context , index = Virtual::Integer
get_function = Virtual::Function.new(:get , Virtual::Integer , [ Virtual::Integer] , Virtual::Integer )
return get_function
end
def set context , index = Vm::Integer , char = Vm::Integer
set_function = Vm::Function.new(:set , Vm::Integer ,[Vm::Integer, Vm::Integer] , Vm::Integer )
def set context , index = Virtual::Integer , char = Virtual::Integer
set_function = Virtual::Function.new(:set , Virtual::Integer ,[Virtual::Integer, Virtual::Integer] , Virtual::Integer )
return set_function
end
end