Converted Array .select{ ... } to .select{{ ... }}.

This commit is contained in:
Peter Camilleri 2015-06-10 18:50:41 -04:00
parent 4402cc4b67
commit 7caa12285c
5 changed files with 13 additions and 40 deletions

View file

@ -84,7 +84,7 @@ class ArrayLibraryTester < Minitest::Test
end
def test_the_select
foorth_equal('[ 0 10 do i loop ] .select{ v 1 and 0= }', [[0,2,4,6,8]])
foorth_equal('[ 0 10 do i loop ] .select{{ v 1 and 0= }}', [[0,2,4,6,8]])
end
def test_simple_array_indexing

View file

@ -74,7 +74,7 @@ class CtrlStructLibraryTester < Minitest::Test
foorth_raises('4 .new{{ }}')
foorth_raises('4 .each{{ }}')
foorth_raises('4 .map{{ }}')
foorth_raises('4 .select{ }')
foorth_raises('4 .select{{ }}')
end
end

View file

@ -37,6 +37,12 @@ module XfOOrth
vm.push(self.map { |val| block.call(vm, val, idx); idx += 1; vm.pop})
})
# [array] .select{{ ... }} [selected_array]
Array.create_shared_method('.select{{', NosSpec, [], &lambda { |vm|
idx, block = 0, vm.pop
vm.push(self.select { |val| block.call(vm, val, idx); idx += 1; vm.pop})
})
# [] [ v1 v2 ... vn ] [[v1,v2,...vn]]; an array literal value
VirtualMachine.create_shared_method('[', VmSpec, [:immediate], &lambda { |vm|
vm.nest_mode('vm.squash; ', :array_literal)
@ -264,19 +270,3 @@ module XfOOrth
})
end
#* Runtime library support for fOOrth constructs.
class Array
# Runtime support for the .select{ } construct.
def do_foorth_select(&block)
index = 0
self.select do |value|
value = block.call(value, index)
index += 1
value
end
end
end

View file

@ -113,20 +113,6 @@ module XfOOrth
})
})
#The object oriented .select{ } construct.
VirtualMachine.create_shared_method('.select{', VmSpec, [:immediate], &lambda {|vm|
suspend_execute_mode('vm.push(vm.pop.do_foorth_select{|vloop, xloop| ', :select_block)
context.create_local_method('v', LocalSpec, [:immediate],
&lambda {|vm| vm << "vm.push(vloop); "} )
context.create_local_method('x', LocalSpec, [:immediate],
&lambda {|vm| vm << "vm.push(xloop); "} )
context.create_local_method('}', LocalSpec, [:immediate],
&lambda {|vm| vm.resume_execute_mode('vm.pop}); ', [:select_block]) })
})
#The object oriented .with{ } construct.
VirtualMachine.create_shared_method('.with{', VmSpec, [:immediate], &lambda {|vm|
old_mode = context[:mode]

View file

@ -48,9 +48,11 @@ module XfOOrth
Object.create_shared_method('@', TosSpec, [:stub])
Object.create_shared_method('!', TosSpec, [:stub])
Object.create_shared_method('.each{{', NosSpec, [:stub])
Object.create_shared_method('.new{{', NosSpec, [:stub])
Object.create_shared_method('.map{{', NosSpec, [:stub])
#Procedure literal stubs.
Object.create_shared_method('.each{{', NosSpec, [:stub])
Object.create_shared_method('.new{{', NosSpec, [:stub])
Object.create_shared_method('.map{{', NosSpec, [:stub])
Object.create_shared_method('.select{{', NosSpec, [:stub])
#Define some "crossover" symbols.
#SymbolMap.add_entry('.init', :foorth_new) -- aliased in core.rb
@ -66,11 +68,6 @@ end
#* Runtime library support stubs.
class Object
# Runtime stub for the .select{ } construct.
def do_foorth_select(&block)
error "F12: A #{self.foorth_name} does not support .select{ ... }."
end
# Runtime stub for the .open{ } construct.
def do_foorth_open_block(_vm, &block)
error "F12: A #{self.foorth_name} does not support .open{ ... }."