mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Converted from VM .with{ ... } to Object .with{{ ... }}.
This commit is contained in:
parent
f5d84f974f
commit
64c440c9dd
4 changed files with 13 additions and 21 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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, [],
|
||||
|
|
Loading…
Reference in a new issue