From f03f445652185d142313a00797373288130e6af2 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 17 Mar 2020 11:01:37 +0200 Subject: [PATCH] passing values to macros conceptually still a bit open, leaving the hack in for now passing values to the macro instead of sol instances --- lib/sol/macro_expression.rb | 17 ++++++++++++++++- test/sol/test_macro_expression.rb | 8 ++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/sol/macro_expression.rb b/lib/sol/macro_expression.rb index 63968319..ace18a26 100644 --- a/lib/sol/macro_expression.rb +++ b/lib/sol/macro_expression.rb @@ -9,7 +9,22 @@ module Sol def to_slot(compiler) parts = name.to_s.split("_") class_name = "SlotMachine::#{parts.collect{|s| s.capitalize}.join}" - eval(class_name).new( self , *arguments) + # Hmm, slightly open issue how to pass args from sol to macro + # WIP, hack for comparison + args = arguments.collect {|arg| + case arg + when Sol::SymbolConstant + arg.value + when Sol::IntegerConstant + arg.value + when Sol::LocalVariable + arg.name + else + puts "unhandled #{arg}:#{arg.class}" + arg + end + } + eval(class_name).new( self , *args) end # When used as right hand side, this tells what data to move to get the result into diff --git a/test/sol/test_macro_expression.rb b/test/sol/test_macro_expression.rb index 69855f9d..09399b84 100644 --- a/test/sol/test_macro_expression.rb +++ b/test/sol/test_macro_expression.rb @@ -26,12 +26,12 @@ module Sol assert_equal SlotMachine::PlusEquals , @ins.class , @ins end def test_arg1 - assert_equal Sol::LocalVariable , @ins.a.class - assert_equal :arg , @ins.a.name + assert_equal Symbol , @ins.a.class + assert_equal :arg , @ins.a end def test_arg2 - assert_equal Sol::IntegerConstant , @ins.b.class - assert_equal 1 , @ins.b.value + assert_equal Integer , @ins.b.class + assert_equal 1 , @ins.b end def test_to_risc comp = @compiler.to_risc