Move builtin wholesale to Mom
Since Builtin generates risc, just like mom instructions, it was a design mistake to put builtin into risc in the first place. Now that borders are coming more into focus, it make much more sense to have the builtin in mom. In fact the instructions should be moved out and a seperate invocation mechanism used , so functions can be parsed, not generated (wip)
This commit is contained in:
parent
a4b6f29834
commit
fa0aa30386
@ -1,4 +1,4 @@
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
module CompileHelper
|
||||
|
||||
@ -16,7 +16,7 @@ require_relative "builtin/integer"
|
||||
require_relative "builtin/object"
|
||||
require_relative "builtin/word"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
# classes have booted, now create a minimal set of functions
|
||||
# minimal means only that which can not be coded in ruby
|
@ -1,4 +1,4 @@
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
# integer related kernel functions
|
||||
# all these functions (return the function they implement) assume interger input
|
@ -1,4 +1,4 @@
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class Object
|
||||
module ClassMethods
|
||||
@ -133,7 +133,7 @@ module Risc
|
||||
# there is a Syscall instruction, but the message has to be saved and restored
|
||||
def self.emit_syscall( builder , name )
|
||||
save_message( builder )
|
||||
builder.add_code Syscall.new("emit_syscall(#{name})", name )
|
||||
builder.add_code Risc::Syscall.new("emit_syscall(#{name})", name )
|
||||
restore_message(builder)
|
||||
return unless (@clazz and @method)
|
||||
builder.add_code Risc.label( "#{@clazz.name}.#{@message.name}" , "return_syscall" )
|
||||
@ -147,7 +147,7 @@ module Risc
|
||||
builder.build do
|
||||
message << message[:return_value]
|
||||
message.reduce_int
|
||||
add_code Syscall.new("emit_syscall(exit)", :exit )
|
||||
add_code Risc::Syscall.new("emit_syscall(exit)", :exit )
|
||||
end
|
||||
end
|
||||
|
||||
@ -156,7 +156,7 @@ module Risc
|
||||
# This relies on linux to save and restore all registers
|
||||
#
|
||||
def self.save_message(builder)
|
||||
r8 = RegisterValue.new( :r8 , :Message).set_builder(builder)
|
||||
r8 = Risc::RegisterValue.new( :r8 , :Message).set_builder(builder)
|
||||
builder.build {r8 << message}
|
||||
end
|
||||
|
||||
@ -166,7 +166,7 @@ module Risc
|
||||
# so that the return value already has an integer instance
|
||||
# This instance is filled with os return value
|
||||
def self.restore_message(builder)
|
||||
r8 = RegisterValue.new( :r8 , :Message)
|
||||
r8 = Risc::RegisterValue.new( :r8 , :Message)
|
||||
builder.build do
|
||||
integer_reg! << message
|
||||
message << r8
|
@ -1,4 +1,4 @@
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class Space
|
||||
module ClassMethods
|
@ -1,4 +1,4 @@
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
module Word
|
||||
module ClassMethods
|
||||
@ -23,7 +23,7 @@ module Risc
|
||||
word! << message[:receiver]
|
||||
integer! << word[Parfait::Word.get_length_index]
|
||||
end
|
||||
Risc::Builtin.emit_syscall( builder , :putstring )
|
||||
Mom::Builtin.emit_syscall( builder , :putstring )
|
||||
compiler
|
||||
end
|
||||
end
|
@ -12,6 +12,10 @@
|
||||
# Machine capabilities (instructions) for basic operations. Use of macros for higher level.
|
||||
|
||||
module Mom
|
||||
# boot bubiltin function (subject to change)
|
||||
def self.boot!
|
||||
Builtin.boot_functions
|
||||
end
|
||||
end
|
||||
|
||||
require_relative "instruction.rb"
|
||||
@ -19,3 +23,4 @@ require_relative "mom_collection"
|
||||
require_relative "callable_compiler"
|
||||
require_relative "method_compiler"
|
||||
require_relative "block_compiler"
|
||||
require_relative "builtin"
|
||||
|
@ -12,15 +12,11 @@ class Class
|
||||
end
|
||||
end
|
||||
|
||||
# The Risc Machine, is an abstract machine with registers. Think of it as an arm machine with
|
||||
# normal instruction names. It is not however an abstraction of existing hardware, but only
|
||||
# of that subset that we need.
|
||||
# See risc/Readme
|
||||
module Risc
|
||||
# module method to reset, and init
|
||||
def self.boot!
|
||||
Position.clear_positions
|
||||
Builtin.boot_functions
|
||||
end
|
||||
end
|
||||
|
||||
@ -47,5 +43,4 @@ end
|
||||
require_relative "risc/instruction"
|
||||
require_relative "risc/register_value"
|
||||
require_relative "risc/text_writer"
|
||||
require_relative "risc/builtin"
|
||||
require_relative "risc/builder"
|
||||
|
@ -3,8 +3,8 @@ require "rx-file"
|
||||
require "util/logging"
|
||||
require "util/list"
|
||||
require_relative "elf/object_writer"
|
||||
require_relative "mom/mom"
|
||||
require_relative "risc"
|
||||
require_relative "mom/mom"
|
||||
require_relative "arm/arm_machine"
|
||||
require_relative "arm/arm_platform"
|
||||
require_relative "vool/statement"
|
||||
|
@ -21,6 +21,7 @@ module RubyX
|
||||
# initialize boots Parfait and Risc (ie load Builin)
|
||||
def initialize(options)
|
||||
Parfait.boot!(options[:parfait] || {})
|
||||
Mom.boot!
|
||||
Risc.boot!
|
||||
end
|
||||
|
||||
|
8
test/mom/builtin/README.md
Normal file
8
test/mom/builtin/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Builtin Testing
|
||||
|
||||
Mostly testing that
|
||||
- functions exist
|
||||
- they compile
|
||||
- basic length tests (no "contents")
|
||||
|
||||
Functionality is tested by interpreter over in interpreter dir
|
@ -1,12 +1,7 @@
|
||||
require_relative "../helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class BuiltinTest < MiniTest::Test
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
end
|
||||
class BootTest < MiniTest::Test
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestIntDiv4 < BootTest
|
||||
def setup
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestObjectFunctionGet < BootTest
|
||||
def setup
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class TestWordPut < BootTest
|
||||
def setup
|
@ -1,6 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
class TestBuiltinFunction < MiniTest::Test
|
||||
|
||||
def setup
|
@ -1,9 +1,12 @@
|
||||
require_relative "helper"
|
||||
|
||||
# TODO move these to interpreter dir
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class IntCmp < BuiltinTest
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_smaller_true
|
||||
run_main_return "4 < 5"
|
@ -1,8 +1,11 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Mom
|
||||
module Builtin
|
||||
class IntMath < BuiltinTest
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_add
|
||||
run_main_return "5 + 5"
|
@ -8,7 +8,7 @@ module Vool
|
||||
|
||||
def setup
|
||||
Parfait.boot!(Parfait.default_test_options)
|
||||
Risc::Builtin.boot_functions
|
||||
Mom.boot!
|
||||
@compiler = compile_first_method( send_method )
|
||||
@ins = @compiler.mom_instructions.next
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user