Array fixes done, UG updated.

This commit is contained in:
Peter Camilleri 2015-08-10 12:16:49 -04:00
parent d50b0643f6
commit 9adf897a98
3 changed files with 25 additions and 4 deletions

Binary file not shown.

View file

@ -109,11 +109,16 @@ class ArrayLibraryTester < Minitest::Test
foorth_equal('$tte @ ', [10])
foorth_equal(' 0 $tte .[]@ ', [10])
foorth_equal(' -1 $tte .[]@ ', [16])
foorth_equal('1 0 $tte .[]! ', [])
foorth_equal('$tte @ ', [1])
foorth_equal(' 10 $tte .[]@ ', [nil])
foorth_equal('-10 $tte .[]@ ', [nil])
foorth_equal(' "0" $tte .[]@ ', [1])
foorth_equal('try "apple" $tte .[]@ catch end ', [])
end
def test_the_left_group
@ -210,6 +215,11 @@ class ArrayLibraryTester < Minitest::Test
foorth_equal('[ 9 3 5 ] 0 + ', [[9,3,5,0]])
foorth_equal('[ 9 3 5 ] [ 0 ] + ', [[9,3,5,0]])
foorth_equal('[ 9 3 5 ] { } + ', [[9,3,5,{}]])
foorth_equal('[ "9" 3 5 ] .sort ', [[3,5,"9"]])
foorth_equal('[ 9 "3" 5 ] .sort ', [["3",5,9]])
foorth_equal('try [ 9 "apple" 5 ] .sort catch end', [])
end
def test_formatting_and_related
@ -228,6 +238,9 @@ class ArrayLibraryTester < Minitest::Test
foorth_raises('[ 9 0 1 "pear" ] .min')
foorth_raises('[ 9 0 1 "apple" ] .max')
foorth_equal('try [ 9 0 1 "pear" ] .min catch end', [])
foorth_equal('try [ 9 0 1 "pear" ] .max catch end', [])
end
def test_array_empty

View file

@ -80,8 +80,14 @@ module XfOOrth
})
# [i a] .[]@ [a[i]]
Array.create_shared_method('.[]@', TosSpec, [],
&lambda {|vm| vm.poke(self[Integer.foorth_coerce(vm.peek)]); })
Array.create_shared_method('.[]@', TosSpec, [], &lambda {|vm|
begin
vm.poke(self[Integer.foorth_coerce(vm.peek)])
rescue
vm.data_stack.pop
raise
end
})
# [v i a] .[]! []; a[i]=v
Array.create_shared_method('.[]!', TosSpec, [], &lambda {|vm|
@ -121,6 +127,7 @@ module XfOOrth
Array.create_shared_method('.left', TosSpec, [], &lambda {|vm|
begin
width = Integer.foorth_coerce(vm.peek)
error "F41: Invalid width: #{width} in .left" if width < 0
vm.poke(self.first(width));
rescue
vm.data_stack.pop
@ -157,6 +164,7 @@ module XfOOrth
Array.create_shared_method('.right', TosSpec, [], &lambda {|vm|
begin
width = Integer.foorth_coerce(vm.peek)
error "F41: Invalid width: #{width} in .right" if width < 0
vm.poke(self.last(width))
rescue
vm.data_stack.pop
@ -208,8 +216,8 @@ module XfOOrth
begin
width = Integer.foorth_coerce(vm.pop)
posn = Integer.foorth_coerce(vm.peek)
error "F41: Invalid index: #{posn} in .mid" if posn < 0
error "F41: Invalid width: #{width} in .mid" if width < 0
error "F41: Invalid index: #{posn} in .-mid" if posn < 0
error "F41: Invalid width: #{width} in .-mid" if width < 0
vm.poke(self[0...posn] + self[(posn+width)..-1])
rescue
vm.data_stack.pop