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:
5
test/risc/interpreter/builtin/README.md
Normal file
5
test/risc/interpreter/builtin/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Builtin Testing
|
||||
|
||||
Basically test builtin methods by their output.
|
||||
|
||||
Currently through Interpreter only
|
62
test/risc/interpreter/builtin/test_int_cmp.rb
Normal file
62
test/risc/interpreter/builtin/test_int_cmp.rb
Normal file
@ -0,0 +1,62 @@
|
||||
require_relative "helper"
|
||||
|
||||
# TODO move these to interpreter dir
|
||||
module Mom
|
||||
module Builtin
|
||||
class IntCmp < BuiltinTest
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_smaller_true
|
||||
run_main_return "4 < 5"
|
||||
assert_equal Parfait::TrueClass , get_message_return.class
|
||||
end
|
||||
def test_smaller_false
|
||||
run_main_return "6 < 5"
|
||||
assert_equal Parfait::FalseClass , get_message_return.class
|
||||
end
|
||||
def test_smaller_false_same
|
||||
run_main_return "5 < 5"
|
||||
assert_equal Parfait::FalseClass , get_message_return.class
|
||||
end
|
||||
def test_larger_true
|
||||
run_main_return "5 > 4"
|
||||
assert_equal Parfait::TrueClass , get_message_return.class
|
||||
end
|
||||
def test_larger_false
|
||||
run_main_return "5 > 6"
|
||||
assert_equal Parfait::FalseClass , get_message_return.class
|
||||
end
|
||||
def test_larger_false_same
|
||||
run_main_return "5 > 5"
|
||||
assert_equal Parfait::FalseClass , get_message_return.class
|
||||
end
|
||||
|
||||
def test_smaller_or_true
|
||||
run_main_return "4 <= 5"
|
||||
assert_equal Parfait::TrueClass , get_message_return.class
|
||||
end
|
||||
def test_smaller_or_false
|
||||
run_main_return "6 <= 5"
|
||||
assert_equal Parfait::FalseClass , get_message_return.class
|
||||
end
|
||||
def test_smaller_or_same
|
||||
run_main_return "5 <= 5"
|
||||
assert_equal Parfait::TrueClass , get_message_return.class
|
||||
end
|
||||
def test_larger_or_true
|
||||
run_main_return "5 >= 4"
|
||||
assert_equal Parfait::TrueClass , get_message_return.class
|
||||
end
|
||||
def test_larger_or_false
|
||||
run_main_return "5 >= 6"
|
||||
assert_equal Parfait::FalseClass , get_message_return.class
|
||||
end
|
||||
def test_larger_or_same
|
||||
run_main_return "5 >= 5"
|
||||
assert_equal Parfait::TrueClass , get_message_return.class
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
44
test/risc/interpreter/builtin/test_int_math.rb
Normal file
44
test/risc/interpreter/builtin/test_int_math.rb
Normal file
@ -0,0 +1,44 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Mom
|
||||
module Builtin
|
||||
class IntMath < BuiltinTest
|
||||
include Ticker
|
||||
def setup
|
||||
end
|
||||
|
||||
def test_add
|
||||
run_main_return "5 + 5"
|
||||
assert_equal 10 , get_return
|
||||
end
|
||||
def test_minus
|
||||
run_main_return "5 - 5"
|
||||
assert_equal 0 , get_return
|
||||
end
|
||||
def test_minus_neg
|
||||
run_main_return "5 - 15"
|
||||
assert_equal( -10 , get_return)
|
||||
end
|
||||
def test_rshift
|
||||
run_main_return "#{2**8} >> 3"
|
||||
assert_equal 2**5 , get_return
|
||||
end
|
||||
def test_lshift
|
||||
run_main_return "#{2**8} << 3"
|
||||
assert_equal 2**11 , get_return
|
||||
end
|
||||
def test_div10
|
||||
run_main_return "45.div10"
|
||||
assert_equal 4 , get_return
|
||||
end
|
||||
def test_div4
|
||||
run_main_return "45.div4"
|
||||
assert_equal 11 , get_return
|
||||
end
|
||||
def test_mult
|
||||
run_main_return "4 * 4"
|
||||
assert_equal 16 , get_return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user