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 Builtin
|
||||||
module CompileHelper
|
module CompileHelper
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ require_relative "builtin/integer"
|
|||||||
require_relative "builtin/object"
|
require_relative "builtin/object"
|
||||||
require_relative "builtin/word"
|
require_relative "builtin/word"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
# classes have booted, now create a minimal set of functions
|
# classes have booted, now create a minimal set of functions
|
||||||
# minimal means only that which can not be coded in ruby
|
# minimal means only that which can not be coded in ruby
|
@ -1,4 +1,4 @@
|
|||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
# integer related kernel functions
|
# integer related kernel functions
|
||||||
# all these functions (return the function they implement) assume interger input
|
# all these functions (return the function they implement) assume interger input
|
@ -1,4 +1,4 @@
|
|||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class Object
|
class Object
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
@ -133,7 +133,7 @@ module Risc
|
|||||||
# there is a Syscall instruction, but the message has to be saved and restored
|
# there is a Syscall instruction, but the message has to be saved and restored
|
||||||
def self.emit_syscall( builder , name )
|
def self.emit_syscall( builder , name )
|
||||||
save_message( builder )
|
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)
|
restore_message(builder)
|
||||||
return unless (@clazz and @method)
|
return unless (@clazz and @method)
|
||||||
builder.add_code Risc.label( "#{@clazz.name}.#{@message.name}" , "return_syscall" )
|
builder.add_code Risc.label( "#{@clazz.name}.#{@message.name}" , "return_syscall" )
|
||||||
@ -147,7 +147,7 @@ module Risc
|
|||||||
builder.build do
|
builder.build do
|
||||||
message << message[:return_value]
|
message << message[:return_value]
|
||||||
message.reduce_int
|
message.reduce_int
|
||||||
add_code Syscall.new("emit_syscall(exit)", :exit )
|
add_code Risc::Syscall.new("emit_syscall(exit)", :exit )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -156,7 +156,7 @@ module Risc
|
|||||||
# This relies on linux to save and restore all registers
|
# This relies on linux to save and restore all registers
|
||||||
#
|
#
|
||||||
def self.save_message(builder)
|
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}
|
builder.build {r8 << message}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -166,7 +166,7 @@ module Risc
|
|||||||
# so that the return value already has an integer instance
|
# so that the return value already has an integer instance
|
||||||
# This instance is filled with os return value
|
# This instance is filled with os return value
|
||||||
def self.restore_message(builder)
|
def self.restore_message(builder)
|
||||||
r8 = RegisterValue.new( :r8 , :Message)
|
r8 = Risc::RegisterValue.new( :r8 , :Message)
|
||||||
builder.build do
|
builder.build do
|
||||||
integer_reg! << message
|
integer_reg! << message
|
||||||
message << r8
|
message << r8
|
@ -1,4 +1,4 @@
|
|||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class Space
|
class Space
|
||||||
module ClassMethods
|
module ClassMethods
|
@ -1,4 +1,4 @@
|
|||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
module Word
|
module Word
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
@ -23,7 +23,7 @@ module Risc
|
|||||||
word! << message[:receiver]
|
word! << message[:receiver]
|
||||||
integer! << word[Parfait::Word.get_length_index]
|
integer! << word[Parfait::Word.get_length_index]
|
||||||
end
|
end
|
||||||
Risc::Builtin.emit_syscall( builder , :putstring )
|
Mom::Builtin.emit_syscall( builder , :putstring )
|
||||||
compiler
|
compiler
|
||||||
end
|
end
|
||||||
end
|
end
|
@ -12,6 +12,10 @@
|
|||||||
# Machine capabilities (instructions) for basic operations. Use of macros for higher level.
|
# Machine capabilities (instructions) for basic operations. Use of macros for higher level.
|
||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
|
# boot bubiltin function (subject to change)
|
||||||
|
def self.boot!
|
||||||
|
Builtin.boot_functions
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_relative "instruction.rb"
|
require_relative "instruction.rb"
|
||||||
@ -19,3 +23,4 @@ require_relative "mom_collection"
|
|||||||
require_relative "callable_compiler"
|
require_relative "callable_compiler"
|
||||||
require_relative "method_compiler"
|
require_relative "method_compiler"
|
||||||
require_relative "block_compiler"
|
require_relative "block_compiler"
|
||||||
|
require_relative "builtin"
|
||||||
|
@ -12,15 +12,11 @@ class Class
|
|||||||
end
|
end
|
||||||
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
|
# See risc/Readme
|
||||||
module Risc
|
module Risc
|
||||||
# module method to reset, and init
|
# module method to reset, and init
|
||||||
def self.boot!
|
def self.boot!
|
||||||
Position.clear_positions
|
Position.clear_positions
|
||||||
Builtin.boot_functions
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -47,5 +43,4 @@ end
|
|||||||
require_relative "risc/instruction"
|
require_relative "risc/instruction"
|
||||||
require_relative "risc/register_value"
|
require_relative "risc/register_value"
|
||||||
require_relative "risc/text_writer"
|
require_relative "risc/text_writer"
|
||||||
require_relative "risc/builtin"
|
|
||||||
require_relative "risc/builder"
|
require_relative "risc/builder"
|
||||||
|
@ -3,8 +3,8 @@ require "rx-file"
|
|||||||
require "util/logging"
|
require "util/logging"
|
||||||
require "util/list"
|
require "util/list"
|
||||||
require_relative "elf/object_writer"
|
require_relative "elf/object_writer"
|
||||||
require_relative "mom/mom"
|
|
||||||
require_relative "risc"
|
require_relative "risc"
|
||||||
|
require_relative "mom/mom"
|
||||||
require_relative "arm/arm_machine"
|
require_relative "arm/arm_machine"
|
||||||
require_relative "arm/arm_platform"
|
require_relative "arm/arm_platform"
|
||||||
require_relative "vool/statement"
|
require_relative "vool/statement"
|
||||||
|
@ -21,6 +21,7 @@ module RubyX
|
|||||||
# initialize boots Parfait and Risc (ie load Builin)
|
# initialize boots Parfait and Risc (ie load Builin)
|
||||||
def initialize(options)
|
def initialize(options)
|
||||||
Parfait.boot!(options[:parfait] || {})
|
Parfait.boot!(options[:parfait] || {})
|
||||||
|
Mom.boot!
|
||||||
Risc.boot!
|
Risc.boot!
|
||||||
end
|
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"
|
require_relative "../helper"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class BuiltinTest < MiniTest::Test
|
|
||||||
include Ticker
|
|
||||||
def setup
|
|
||||||
end
|
|
||||||
end
|
|
||||||
class BootTest < MiniTest::Test
|
class BootTest < MiniTest::Test
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class TestIntDiv4 < BootTest
|
class TestIntDiv4 < BootTest
|
||||||
def setup
|
def setup
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class TestObjectFunctionGet < BootTest
|
class TestObjectFunctionGet < BootTest
|
||||||
def setup
|
def setup
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class TestWordPut < BootTest
|
class TestWordPut < BootTest
|
||||||
def setup
|
def setup
|
@ -1,6 +1,6 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
class TestBuiltinFunction < MiniTest::Test
|
class TestBuiltinFunction < MiniTest::Test
|
||||||
|
|
||||||
def setup
|
def setup
|
@ -1,9 +1,12 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
# TODO move these to interpreter dir
|
# TODO move these to interpreter dir
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class IntCmp < BuiltinTest
|
class IntCmp < BuiltinTest
|
||||||
|
include Ticker
|
||||||
|
def setup
|
||||||
|
end
|
||||||
|
|
||||||
def test_smaller_true
|
def test_smaller_true
|
||||||
run_main_return "4 < 5"
|
run_main_return "4 < 5"
|
@ -1,8 +1,11 @@
|
|||||||
require_relative "helper"
|
require_relative "helper"
|
||||||
|
|
||||||
module Risc
|
module Mom
|
||||||
module Builtin
|
module Builtin
|
||||||
class IntMath < BuiltinTest
|
class IntMath < BuiltinTest
|
||||||
|
include Ticker
|
||||||
|
def setup
|
||||||
|
end
|
||||||
|
|
||||||
def test_add
|
def test_add
|
||||||
run_main_return "5 + 5"
|
run_main_return "5 + 5"
|
@ -8,7 +8,7 @@ module Vool
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!(Parfait.default_test_options)
|
Parfait.boot!(Parfait.default_test_options)
|
||||||
Risc::Builtin.boot_functions
|
Mom.boot!
|
||||||
@compiler = compile_first_method( send_method )
|
@compiler = compile_first_method( send_method )
|
||||||
@ins = @compiler.mom_instructions.next
|
@ins = @compiler.mom_instructions.next
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user