2019-08-12 11:36:32 +02:00
|
|
|
module Mom
|
2019-08-11 13:31:00 +02:00
|
|
|
module Builtin
|
|
|
|
module CompileHelper
|
|
|
|
|
|
|
|
def compiler_for( clazz_name , method_name , arguments , locals = {})
|
|
|
|
frame = Parfait::NamedList.type_for( locals )
|
|
|
|
args = Parfait::NamedList.type_for( arguments )
|
|
|
|
Mom::MethodCompiler.compiler_for_class(clazz_name , method_name , args, frame )
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-29 10:23:26 +02:00
|
|
|
require_relative "builtin/space"
|
|
|
|
require_relative "builtin/integer"
|
|
|
|
require_relative "builtin/object"
|
|
|
|
require_relative "builtin/word"
|
|
|
|
|
2019-08-12 11:36:32 +02:00
|
|
|
module Mom
|
2018-06-29 10:23:26 +02:00
|
|
|
module Builtin
|
|
|
|
# classes have booted, now create a minimal set of functions
|
|
|
|
# minimal means only that which can not be coded in ruby
|
|
|
|
# Methods are grabbed from respective modules by sending the method name.
|
2019-08-12 15:12:17 +02:00
|
|
|
# This should return the implementation of the method (ie a method compiler),
|
2018-06-29 10:23:26 +02:00
|
|
|
# not actually try to implement it(as that's impossible in ruby)
|
|
|
|
#
|
2019-08-12 15:12:17 +02:00
|
|
|
# We create an empty main for init to jump to, if no code is compiled, that just returns
|
|
|
|
# See Builtin directory readme and module
|
2019-09-07 16:56:06 +02:00
|
|
|
def self.boot_functions( options = nil)
|
2018-07-04 08:17:30 +02:00
|
|
|
space = Parfait.object_space
|
2018-06-30 22:16:17 +02:00
|
|
|
space_type = space.get_class.instance_type
|
2019-09-07 16:56:06 +02:00
|
|
|
|
|
|
|
if @compilers and options == nil
|
|
|
|
if(space_type.methods.nil?)
|
|
|
|
@compilers << compiler_for( space_type , Space , :main)
|
|
|
|
end
|
2019-09-09 19:26:54 +02:00
|
|
|
return @compilers
|
2018-07-04 08:17:30 +02:00
|
|
|
end
|
2019-09-07 16:56:06 +02:00
|
|
|
# TODO go through the virtual parfait layer and adjust function names
|
|
|
|
# to what they really are
|
|
|
|
@compilers = []
|
2018-06-29 10:23:26 +02:00
|
|
|
|
2018-07-13 20:50:40 +02:00
|
|
|
obj_type = space.get_type_by_class_name(:Object)
|
2019-08-12 15:12:17 +02:00
|
|
|
[ :__init__ , :exit , :_method_missing, :get_internal_word ,
|
|
|
|
:set_internal_word ].each do |f|
|
2019-09-07 16:56:06 +02:00
|
|
|
@compilers << compiler_for( obj_type , Object , f)
|
2018-06-29 10:23:26 +02:00
|
|
|
end
|
|
|
|
|
2018-07-13 20:50:40 +02:00
|
|
|
word_type = space.get_type_by_class_name(:Word)
|
2018-06-29 10:23:26 +02:00
|
|
|
[:putstring , :get_internal_byte , :set_internal_byte ].each do |f|
|
2019-09-07 16:56:06 +02:00
|
|
|
@compilers << compiler_for( word_type , Word , f)
|
2018-06-29 10:23:26 +02:00
|
|
|
end
|
|
|
|
|
2018-07-13 20:50:40 +02:00
|
|
|
int_type = space.get_type_by_class_name(:Integer)
|
2018-06-29 10:23:26 +02:00
|
|
|
Risc.operators.each do |op|
|
2019-09-07 16:56:06 +02:00
|
|
|
@compilers << operator_compiler( int_type , op)
|
2018-06-29 10:23:26 +02:00
|
|
|
end
|
2019-08-12 10:08:09 +02:00
|
|
|
[ :div4, :<,:<= , :>=, :> , :div10 ].each do |f| #div4 is just a forward declaration
|
2019-09-07 16:56:06 +02:00
|
|
|
@compilers << compiler_for( int_type , Integer , f)
|
2018-06-29 10:23:26 +02:00
|
|
|
end
|
2019-09-07 16:56:06 +02:00
|
|
|
return @compilers
|
2018-06-29 10:23:26 +02:00
|
|
|
end
|
|
|
|
|
2018-06-30 22:16:17 +02:00
|
|
|
def self.compiler_for( type , mod , name)
|
|
|
|
compiler = mod.send(name , nil)
|
2018-07-09 18:32:17 +02:00
|
|
|
compiler.add_method_to(type)
|
2018-06-30 22:16:17 +02:00
|
|
|
compiler
|
|
|
|
end
|
|
|
|
def self.operator_compiler(int_type , op)
|
|
|
|
compiler = Integer.operator_method(op)
|
2018-07-09 18:32:17 +02:00
|
|
|
compiler.add_method_to(int_type)
|
2018-06-30 22:16:17 +02:00
|
|
|
compiler
|
|
|
|
end
|
2018-06-29 10:23:26 +02:00
|
|
|
end
|
|
|
|
end
|