mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Integer, Object, and String fixes.
This commit is contained in:
parent
a5b095009d
commit
4b99b8f03c
4 changed files with 76 additions and 17 deletions
|
@ -130,6 +130,19 @@ class StandardLibraryTester < Minitest::Test
|
|||
foorth_equal('try 10 .to_duration false / catch end', [])
|
||||
foorth_equal('try 10 .to_duration f"%Z" catch end', [])
|
||||
|
||||
foorth_equal('try 11 false and catch end', [])
|
||||
foorth_equal('try 11 false or catch end', [])
|
||||
foorth_equal('try 11 false xor catch end', [])
|
||||
foorth_equal('try 11 false << catch end', [])
|
||||
foorth_equal('try 11 false >> catch end', [])
|
||||
|
||||
foorth_equal('try 11 false max catch end', [])
|
||||
foorth_equal('try 11 false min catch end', [])
|
||||
|
||||
|
||||
foorth_equal('try 11 false format catch end', [])
|
||||
foorth_equal('try "a" false * catch end', [])
|
||||
|
||||
end
|
||||
|
||||
def test_some_logical_and
|
||||
|
|
|
@ -47,28 +47,58 @@ module XfOOrth
|
|||
|
||||
# Some bitwise operation words.
|
||||
# [b,a] and [b&a]
|
||||
Integer.create_shared_method('and', NosSpec, [],
|
||||
&lambda {|vm| vm.poke(self & Integer.foorth_coerce(vm.peek)); })
|
||||
Integer.create_shared_method('and', NosSpec, [], &lambda {|vm|
|
||||
begin
|
||||
vm.poke(self & Integer.foorth_coerce(vm.peek))
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
# [b,a] or [b|a]
|
||||
Integer.create_shared_method('or', NosSpec, [],
|
||||
&lambda {|vm| vm.poke(self | Integer.foorth_coerce(vm.peek)); })
|
||||
Integer.create_shared_method('or', NosSpec, [], &lambda {|vm|
|
||||
begin
|
||||
vm.poke(self | Integer.foorth_coerce(vm.peek))
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
# [b,a] xor [b^a]
|
||||
Integer.create_shared_method('xor', NosSpec, [],
|
||||
&lambda {|vm| vm.poke(self ^ Integer.foorth_coerce(vm.peek)); })
|
||||
Integer.create_shared_method('xor', NosSpec, [], &lambda {|vm|
|
||||
begin
|
||||
vm.poke(self ^ Integer.foorth_coerce(vm.peek))
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
# [a] com [~a]
|
||||
Integer.create_shared_method('com', TosSpec, [],
|
||||
&lambda {|vm| vm.push(~(self)); })
|
||||
|
||||
# [b,a] << [b<<a]
|
||||
Integer.create_shared_method('<<', NosSpec, [],
|
||||
&lambda {|vm| vm.poke(self << Integer.foorth_coerce(vm.peek)); })
|
||||
Integer.create_shared_method('<<', NosSpec, [], &lambda {|vm|
|
||||
begin
|
||||
vm.poke(self << Integer.foorth_coerce(vm.peek))
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
# [b,a] >> [b>>a]
|
||||
Integer.create_shared_method('>>', NosSpec, [],
|
||||
&lambda {|vm| vm.poke(self >> Integer.foorth_coerce(vm.peek)); })
|
||||
Integer.create_shared_method('>>', NosSpec, [], &lambda {|vm|
|
||||
begin
|
||||
vm.poke(self >> Integer.foorth_coerce(vm.peek))
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -57,15 +57,24 @@ module XfOOrth
|
|||
|
||||
# [b,a] max [max(b,a)]
|
||||
Object.create_shared_method('max', NosSpec, [], &lambda {|vm|
|
||||
other = vm.peek
|
||||
vm.poke((self > self.foorth_coerce(other)) ? self : other)
|
||||
begin
|
||||
other = vm.peek
|
||||
vm.poke((self > self.foorth_coerce(other)) ? self : other)
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
# [b,a] min [min(b,a)]
|
||||
Object.create_shared_method('min', NosSpec, [], &lambda {|vm|
|
||||
other = vm.peek
|
||||
vm.poke((self < self.foorth_coerce(other)) ? self : other)
|
||||
begin
|
||||
other = vm.peek
|
||||
vm.poke((self < self.foorth_coerce(other)) ? self : other)
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ module XfOOrth
|
|||
begin
|
||||
vm.poke(vm.peek % self.in_array)
|
||||
rescue => err
|
||||
vm.data_stack.pop
|
||||
error "F40: Formating error: #{err.message}."
|
||||
end
|
||||
end
|
||||
|
@ -198,8 +199,14 @@ module XfOOrth
|
|||
&lambda {|vm| vm.poke(self << vm.peek.to_s); })
|
||||
|
||||
# ["b", n] * ["bbb..."]
|
||||
String.create_shared_method('*', NosSpec, [],
|
||||
&lambda {|vm| vm.poke(self * Integer.foorth_coerce(vm.peek)); })
|
||||
String.create_shared_method('*', NosSpec, [], &lambda {|vm|
|
||||
begin
|
||||
vm.poke(self * Integer.foorth_coerce(vm.peek))
|
||||
rescue
|
||||
vm.data_stack.pop
|
||||
raise
|
||||
end
|
||||
})
|
||||
|
||||
# ["abCD"] .to_upper ["ABCD"]
|
||||
String.create_shared_method('.to_upper', TosSpec, [],
|
||||
|
|
Loading…
Reference in a new issue