diff --git a/integration/ctrl_struct_lib_tests.rb b/integration/ctrl_struct_lib_tests.rb index 515b1bb..2c61981 100644 --- a/integration/ctrl_struct_lib_tests.rb +++ b/integration/ctrl_struct_lib_tests.rb @@ -64,9 +64,9 @@ class CtrlStructLibraryTester < Minitest::Test end def test_with_constructs - foorth_equal('4 .with{ self 2* }', [8]) + foorth_equal('4 .with{{ self 2* }}', [8]) - foorth_run(': twc01 4 .with{ self 2* } ;') + foorth_run(': twc01 4 .with{{ self 2* }} ;') foorth_equal('twc01', [8]) end diff --git a/integration/out_stream_lib_tests.rb b/integration/out_stream_lib_tests.rb index 6c6ee42..dd1b485 100644 --- a/integration/out_stream_lib_tests.rb +++ b/integration/out_stream_lib_tests.rb @@ -53,7 +53,7 @@ class OutStreamLibraryTester < Minitest::Test def test_that_we_can_write_stuff_too - foorth_run($osfn + 'OutStream .create dup .with{ ~"Hello World" } .close') + foorth_run($osfn + 'OutStream .create dup .with{{ ~"Hello World" }} .close') assert_equal(["Hello World"], IO.readlines($osfn[1...-2])) do_cleanup end @@ -79,7 +79,7 @@ class OutStreamLibraryTester < Minitest::Test def test_that_we_can_write_out_lines - foorth_run($osfn + 'OutStream .create .with{ ~"Hello" ~cr ~"World" self .close } ') + foorth_run($osfn + 'OutStream .create .with{{ ~"Hello" ~cr ~"World" self .close }}') assert_equal(["Hello\n", "World"], IO.readlines($osfn[1...-2])) do_cleanup end @@ -92,7 +92,7 @@ class OutStreamLibraryTester < Minitest::Test def test_that_we_can_write_out_a_space - foorth_run($osfn + 'OutStream .create .with{ ~"Hello" self .space ~"World" self .close }') + foorth_run($osfn + 'OutStream .create .with{{ ~"Hello" self .space ~"World" self .close }}') assert_equal(["Hello World"], IO.readlines($osfn[1...-2])) do_cleanup end @@ -105,7 +105,7 @@ class OutStreamLibraryTester < Minitest::Test def test_that_we_can_write_out_spaces - foorth_run($osfn + 'OutStream .create .with{ ~"Hello" 3 self .spaces ~"World" self .close }') + foorth_run($osfn + 'OutStream .create .with{{ ~"Hello" 3 self .spaces ~"World" self .close }}') assert_equal(["Hello World"], IO.readlines($osfn[1...-2])) do_cleanup end diff --git a/lib/fOOrth/library/ctrl_struct_library.rb b/lib/fOOrth/library/ctrl_struct_library.rb index ef871d8..f26d9cb 100644 --- a/lib/fOOrth/library/ctrl_struct_library.rb +++ b/lib/fOOrth/library/ctrl_struct_library.rb @@ -113,19 +113,4 @@ module XfOOrth }) }) - #The object oriented .with{ } construct. - VirtualMachine.create_shared_method('.with{', VmSpec, [:immediate], &lambda {|vm| - old_mode = context[:mode] - suspend_execute_mode('vm.pop.instance_exec(&lambda {', :with_block) - - if old_mode == :execute - context[:obj] = vm.peek - else - context[:cls] = Object - end - - context.create_local_method('}', LocalSpec, [:immediate], - &lambda {|vm| vm.resume_execute_mode('}); ', [:with_block]) }) - }) - end diff --git a/lib/fOOrth/library/object_library.rb b/lib/fOOrth/library/object_library.rb index 3671823..d9c77df 100644 --- a/lib/fOOrth/library/object_library.rb +++ b/lib/fOOrth/library/object_library.rb @@ -13,6 +13,13 @@ module XfOOrth # [] self [self] VirtualMachine.create_shared_method('self', MacroSpec, [:macro, "vm.push(self); "]) + #Get the name of an object or class. + # [obj] .with{{ ... }} [] Execute the block with self set to obj + Object.create_shared_method('.with{{', NosSpec, [], &lambda {|vm| + block = vm.pop + self.instance_exec(vm, nil, nil, &block) + }) + #Get the name of an object or class. # [obj] .name ["name of obj"] Object.create_shared_method('.name', TosSpec, [],