move boot* classes to boot directory
This commit is contained in:
parent
a7551ea8b6
commit
12a92e4db0
@ -1,9 +1,9 @@
|
|||||||
require_relative "meta_class"
|
require_relative "meta_class"
|
||||||
|
|
||||||
module Vm
|
module Boot
|
||||||
# class is mainly a list of functions with a name (for now)
|
# class is mainly a list of functions with a name (for now)
|
||||||
# layout of object is seperated into Layout
|
# layout of object is seperated into Layout
|
||||||
class BootClass < ObjectConstant
|
class BootClass < Vm::ObjectConstant
|
||||||
def initialize name , context , super_class = :Object
|
def initialize name , context , super_class = :Object
|
||||||
super()
|
super()
|
||||||
@context = context
|
@context = context
|
||||||
@ -16,7 +16,7 @@ module Vm
|
|||||||
attr_reader :name , :functions , :meta_class , :context
|
attr_reader :name , :functions , :meta_class , :context
|
||||||
|
|
||||||
def add_function function
|
def add_function function
|
||||||
raise "not a function #{function}" unless function.is_a? Function
|
raise "not a function #{function}" unless function.is_a? Vm::Function
|
||||||
raise "syserr " unless function.name.is_a? Symbol
|
raise "syserr " unless function.name.is_a? Symbol
|
||||||
@functions << function
|
@functions << function
|
||||||
end
|
end
|
@ -1,12 +1,12 @@
|
|||||||
require_relative "context"
|
require "vm/context"
|
||||||
require_relative "boot_class"
|
require "boot/boot_class"
|
||||||
require_relative "call_site"
|
require "vm/call_site"
|
||||||
require "arm/arm_machine"
|
require "arm/arm_machine"
|
||||||
require "core/kernel"
|
require "core/kernel"
|
||||||
require "boot/object"
|
require "boot/object"
|
||||||
require "boot/string"
|
require "boot/string"
|
||||||
|
|
||||||
module Vm
|
module Boot
|
||||||
# The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo
|
# The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo
|
||||||
# it is a collection of objects, some of which are data, some classes, some functions
|
# it is a collection of objects, some of which are data, some classes, some functions
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ module Vm
|
|||||||
|
|
||||||
# throwing in a context for unspecified use (well one is to pass the programm/globals around)
|
# throwing in a context for unspecified use (well one is to pass the programm/globals around)
|
||||||
|
|
||||||
class BootSpace < Code
|
class BootSpace < Vm::Code
|
||||||
|
|
||||||
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
|
# 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 Vm::RegisterMachine
|
||||||
@ -27,19 +27,19 @@ module Vm
|
|||||||
machine = RbConfig::CONFIG["host_cpu"] unless machine
|
machine = RbConfig::CONFIG["host_cpu"] unless machine
|
||||||
machine = "intel" if machine == "x86_64"
|
machine = "intel" if machine == "x86_64"
|
||||||
machine = machine.capitalize
|
machine = machine.capitalize
|
||||||
RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
|
Vm::RegisterMachine.instance = eval("#{machine}::#{machine}Machine").new
|
||||||
@classes = {}
|
@classes = {}
|
||||||
@context = Context.new(self)
|
@context = Vm::Context.new(self)
|
||||||
@context.current_class = get_or_create_class :Object
|
@context.current_class = get_or_create_class :Object
|
||||||
@main = Function.new("main")
|
@main = Vm::Function.new("main")
|
||||||
@context.function = @main
|
@context.function = @main
|
||||||
#global objects (data)
|
#global objects (data)
|
||||||
@objects = []
|
@objects = []
|
||||||
@entry = RegisterMachine.instance.main_start @context
|
@entry = Vm::RegisterMachine.instance.main_start @context
|
||||||
#main gets executed between entry and exit
|
#main gets executed between entry and exit
|
||||||
@exit = RegisterMachine.instance.main_exit @context
|
@exit = Vm::RegisterMachine.instance.main_exit @context
|
||||||
boot_classes
|
boot_classes
|
||||||
@passes = [ MoveMoveReduction.new , LogicMoveReduction.new, NoopReduction.new, SaveLocals.new ]
|
@passes = [ Vm::MoveMoveReduction.new , Vm::LogicMoveReduction.new, Vm::NoopReduction.new, Vm::SaveLocals.new ]
|
||||||
end
|
end
|
||||||
attr_reader :context , :main , :classes , :entry , :exit
|
attr_reader :context , :main , :classes , :entry , :exit
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ module Vm
|
|||||||
# Objects are data and get assembled after functions
|
# Objects are data and get assembled after functions
|
||||||
def add_object o
|
def add_object o
|
||||||
return if @objects.include? o
|
return if @objects.include? o
|
||||||
raise "must be derived from Code #{o.inspect}" unless o.is_a? Code
|
raise "must be derived from Code #{o.inspect}" unless o.is_a? Vm::Code
|
||||||
@objects << o # TODO check type , no basic values allowed (must be wrapped)
|
@objects << o # TODO check type , no basic values allowed (must be wrapped)
|
||||||
end
|
end
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
module Vm
|
module Boot
|
||||||
# class that acts like a class, but is really the object
|
# class that acts like a class, but is really the object
|
||||||
|
|
||||||
# described in the ruby language book as the eigenclass, what you get with
|
# described in the ruby language book as the eigenclass, what you get with
|
||||||
@ -8,7 +8,7 @@ module Vm
|
|||||||
# PS: can't say i fancy the << self syntax and am considerernig adding a keyword for it, like meta
|
# 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(...)
|
# 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
|
# So one could write def meta.function(...) and thus define on the meta-class
|
||||||
class MetaClass < ObjectConstant
|
class MetaClass < Vm::ObjectConstant
|
||||||
# no name, nor nothing. as this is just the object really
|
# no name, nor nothing. as this is just the object really
|
||||||
|
|
||||||
def initialize(object)
|
def initialize(object)
|
@ -9,7 +9,7 @@ require "vm/code"
|
|||||||
require "vm/values"
|
require "vm/values"
|
||||||
require "vm/block"
|
require "vm/block"
|
||||||
require "vm/function"
|
require "vm/function"
|
||||||
require "vm/boot_class"
|
require "boot/boot_class"
|
||||||
require "vm/boot_space"
|
require "boot/boot_space"
|
||||||
require "stream_reader"
|
require "stream_reader"
|
||||||
require "core/kernel"
|
require "core/kernel"
|
||||||
|
@ -17,7 +17,7 @@ module Vm
|
|||||||
if value.is_a?(IntegerConstant) or value.is_a?(ObjectConstant)
|
if value.is_a?(IntegerConstant) or value.is_a?(ObjectConstant)
|
||||||
function.receiver.load into , value
|
function.receiver.load into , value
|
||||||
else
|
else
|
||||||
raise "meta #{name} " if value.is_a? MetaClass
|
raise "meta #{name} " if value.is_a? Boot::MetaClass
|
||||||
function.receiver.move( into, value ) if value.register_symbol != function.receiver.register_symbol
|
function.receiver.move( into, value ) if value.register_symbol != function.receiver.register_symbol
|
||||||
end
|
end
|
||||||
raise "function call '#{name}' has #{args.length} arguments, but function has #{function.args.length}" if args.length != function.args.length
|
raise "function call '#{name}' has #{args.length} arguments, but function has #{function.args.length}" if args.length != function.args.length
|
||||||
|
@ -161,7 +161,7 @@ module Vm
|
|||||||
elsif right.is_a? StringConstant
|
elsif right.is_a? StringConstant
|
||||||
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
||||||
block.mov( Integer.new(self.used_register.next_reg_use) , right.length ) #and the length HACK TODO
|
block.mov( Integer.new(self.used_register.next_reg_use) , right.length ) #and the length HACK TODO
|
||||||
elsif right.is_a?(BootClass) or right.is_a?(MetaClass)
|
elsif right.is_a?(Boot::BootClass) or right.is_a?(Boot::MetaClass)
|
||||||
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
block.add( self , right , nil) #move the address, by "adding" to pc, ie pc relative
|
||||||
else
|
else
|
||||||
raise "unknown #{right.inspect}"
|
raise "unknown #{right.inspect}"
|
||||||
|
@ -13,7 +13,7 @@ require 'parslet/convenience'
|
|||||||
module Fragments
|
module Fragments
|
||||||
# need a code generator, for arm
|
# need a code generator, for arm
|
||||||
def setup
|
def setup
|
||||||
@object_space = Vm::BootSpace.new "Arm"
|
@object_space = Boot::BootSpace.new "Arm"
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse
|
def parse
|
||||||
|
@ -85,7 +85,7 @@ HERE
|
|||||||
expr = part.compile( @object_space.context )
|
expr = part.compile( @object_space.context )
|
||||||
else
|
else
|
||||||
expr = part.compile( @object_space.context )
|
expr = part.compile( @object_space.context )
|
||||||
raise "should be function definition for now, not #{part.inspect}#{expr.inspect}" unless expr.is_a? Vm::BootClass
|
raise "should be function definition for now, not #{part.inspect}#{expr.inspect}" unless expr.is_a? Boot::BootClass
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user