From e1d5592c555020952a48899b2178b588b3ead994 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 27 Jul 2018 10:48:45 +0300 Subject: [PATCH] fix boot to include blocks correctly --- lib/risc/parfait_boot.rb | 8 ++++---- test/parfait/test_callable_method.rb | 7 +++++++ test/support/risc_interpreter.rb | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lib/risc/parfait_boot.rb b/lib/risc/parfait_boot.rb index be73de25..f8c654af 100644 --- a/lib/risc/parfait_boot.rb +++ b/lib/risc/parfait_boot.rb @@ -133,15 +133,15 @@ module Parfait # and all instance variable names. Really have to find a better way def self.type_names {BinaryCode: {next: :BinaryCode} , - Block: {binary: :BinaryCode, next: :CallableMethod, - arguments_type: :Type , self_type: :Type, frame_type: :Type } , + Block: {binary: :BinaryCode, next: :Block, + arguments_type: :Type , self_type: :Type, frame_type: :Type } , CacheEntry: {cached_type: :Type , cached_method: :CallableMethod } , Callable: {binary: :BinaryCode,next: :Callable , arguments_type: :Type , self_type: :Type, frame_type: :Type } , - CallableMethod: {name: :Word, binary: :BinaryCode, + CallableMethod: {binary: :BinaryCode, next: :CallableMethod , arguments_type: :Type , self_type: :Type, frame_type: :Type , - next: :CallableMethod} , + name: :Word , blocks: :Block} , Class: {instance_methods: :List, instance_type: :Type, name: :Word, super_class_name: :Word }, DataObject: {}, diff --git a/test/parfait/test_callable_method.rb b/test/parfait/test_callable_method.rb index efc1bcbf..4ce265eb 100644 --- a/test/parfait/test_callable_method.rb +++ b/test/parfait/test_callable_method.rb @@ -99,5 +99,12 @@ module Parfait method = Parfait::CallableMethod.new( @obj , :other , @args , @frame) assert @method != method end + def test_create_block + @block = @method.create_block(@args , @frame) + assert_equal Block , @block.class + end + def test_has_block + assert_equal 7 , @method.get_type.variable_index( :blocks ) + end end end diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index 3ac49071..b53ea986 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -13,6 +13,14 @@ module Risc end alias :do_setup :setup + def yielder + "def yielder; yield ; end" + end + + def block_main( main , extra = yielder) + in_Space("#{extra} ; def main(arg) ; #{main} ; end") + end + # check the given array of instructions is what the interpreter actually does # possible second argument ignores the given amount, usually up until main def check_chain( should , start_at = 0 )