renamed program to boot_space, as in object_space at boot time. thats the way its going
This commit is contained in:
@ -58,7 +58,7 @@ module Ast
|
||||
|
||||
def compile context , into
|
||||
value = Vm::StringConstant.new(string)
|
||||
context.program.add_object value
|
||||
context.object_space.add_object value
|
||||
value
|
||||
end
|
||||
def attributes
|
||||
|
@ -8,7 +8,7 @@ module Ast
|
||||
end
|
||||
def compile context , into
|
||||
params = args.collect{ |a| a.compile(context, into) }
|
||||
function = context.program.get_or_create_function(name)
|
||||
function = context.object_space.get_or_create_function(name)
|
||||
raise "Forward declaration not implemented (#{name}) #{inspect}" if function == nil
|
||||
call = Vm::CallSite.new( name , params , function)
|
||||
current_function = context.function
|
||||
|
@ -27,7 +27,7 @@ module Ast
|
||||
args << arg_value
|
||||
end
|
||||
function = Vm::Function.new(name , args )
|
||||
context.program.add_function function
|
||||
context.object_space.add_function function
|
||||
|
||||
parent_locals = context.locals
|
||||
parent_function = context.function
|
||||
|
@ -15,6 +15,13 @@ module Ast
|
||||
[:name , :expressions]
|
||||
end
|
||||
def compile context , into
|
||||
# create the class or module
|
||||
# check if it'sa function definition and add
|
||||
# if not, execute it, but that does means we should be in crystal (executable), not ruby. ie throw an error for now
|
||||
clazz = context.object_space.get_or_create_class name
|
||||
|
||||
|
||||
|
||||
expression_value = expression.compile(context , into)
|
||||
puts "compiled return expression #{expression_value.inspect}, now return in 7"
|
||||
# copied from function expression: TODO make function
|
||||
|
36
lib/core/array.rb
Normal file
36
lib/core/array.rb
Normal file
@ -0,0 +1,36 @@
|
||||
# this is not a "normal" ruby file, ie it is not required by crystal
|
||||
# instead it is parsed by crystal to define part of the crystal that runs
|
||||
|
||||
class BaseObject
|
||||
|
||||
def _set_instance_variable(name , value)
|
||||
|
||||
end
|
||||
|
||||
def _get_instance_variable( name )
|
||||
|
||||
end
|
||||
|
||||
def _get_singleton_method(name )
|
||||
|
||||
end
|
||||
def _add_singleton_method(method)
|
||||
|
||||
end
|
||||
def initialize
|
||||
end
|
||||
end
|
||||
|
||||
class Array < BaseObject
|
||||
def initialize size
|
||||
|
||||
end
|
||||
|
||||
def at(index)
|
||||
|
||||
end
|
||||
|
||||
def set(index , value)
|
||||
|
||||
end
|
||||
end
|
@ -35,10 +35,10 @@ module Core
|
||||
def putint context , arg = Vm::Integer
|
||||
putint_function = Vm::Function.new(:putint , [arg] , arg )
|
||||
buffer = Vm::StringConstant.new(" ") # create a buffer
|
||||
context.program.add_object buffer # and save it (function local variable: a no no)
|
||||
context.object_space.add_object buffer # and save it (function local variable: a no no)
|
||||
int = putint_function.args.first
|
||||
moved_int = putint_function.new_local
|
||||
utoa = context.program.get_or_create_function(:utoa)
|
||||
utoa = context.object_space.get_or_create_function(:utoa)
|
||||
b = putint_function.body
|
||||
b.mov( moved_int , int ) #move arg up
|
||||
#b.a buffer => int # string to write to
|
||||
|
@ -4,6 +4,6 @@ require "elf/object_writer"
|
||||
require 'parser/crystal'
|
||||
require 'parser/transform'
|
||||
require "vm/register_machine"
|
||||
require "vm/program"
|
||||
require "vm/boot_space"
|
||||
require "stream_reader"
|
||||
require "core/kernel"
|
||||
|
@ -8,7 +8,7 @@ module Elf
|
||||
class ObjectWriter
|
||||
def initialize(program , target)
|
||||
@object = Elf::ObjectFile.new(target)
|
||||
@program = program
|
||||
@object_space = program
|
||||
sym_strtab = Elf::StringTableSection.new(".strtab")
|
||||
@object.add_section sym_strtab
|
||||
@symbol_table = Elf::SymbolTableSection.new(".symtab", sym_strtab)
|
||||
|
5
lib/vm/boot_class.rb
Normal file
5
lib/vm/boot_class.rb
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
module Vm
|
||||
class BootClass
|
||||
end
|
||||
end
|
0
lib/vm/boot_memory.rb
Normal file
0
lib/vm/boot_memory.rb
Normal file
@ -5,8 +5,8 @@ require "arm/arm_machine"
|
||||
require "core/kernel"
|
||||
|
||||
module Vm
|
||||
# A Program represents an executable that we want to build
|
||||
# it has a list of functions and (global) objects
|
||||
# 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
|
||||
|
||||
# The main entry is a function called (of all things) "main", This _must be supplied by the compling
|
||||
# There is a start and exit block that call main, which receives an array of strings
|
||||
@ -18,7 +18,7 @@ module Vm
|
||||
|
||||
# throwing in a context for unspecified use (well one is to pass the programm/globals around)
|
||||
|
||||
class Program < Code
|
||||
class BootSpace < 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
|
||||
@ -44,6 +44,7 @@ module Vm
|
||||
|
||||
def add_object o
|
||||
return if @objects.include? o
|
||||
raise "must be derived from Code #{o.inspect}" unless o.is_a? Code
|
||||
@objects << o # TODO check type , no basic values allowed (must be wrapped)
|
||||
end
|
||||
|
@ -1,14 +1,14 @@
|
||||
require "support/hash_attributes"
|
||||
module Vm
|
||||
|
||||
#currently just holding the program in here so we can have global access
|
||||
#currently just holding the object_space in here so we can have global access
|
||||
class Context
|
||||
# Make hash attributes to object attributes
|
||||
include Support::HashAttributes
|
||||
|
||||
def initialize program
|
||||
def initialize object_space
|
||||
@attributes = {}
|
||||
@attributes[:program] = program
|
||||
@attributes[:object_space] = object_space
|
||||
end
|
||||
attr_reader :attributes
|
||||
end
|
||||
|
Reference in New Issue
Block a user