mirror of
https://github.com/PeterCamilleri/fOOrth
synced 2024-11-16 07:47:56 +01:00
Duration fixes.
This commit is contained in:
parent
6be6771bf1
commit
a5b095009d
3 changed files with 40 additions and 8 deletions
|
@ -119,6 +119,17 @@ class StandardLibraryTester < Minitest::Test
|
||||||
foorth_equal('try now false - catch end', [])
|
foorth_equal('try now false - catch end', [])
|
||||||
foorth_equal('try now false format catch end', [])
|
foorth_equal('try now false format catch end', [])
|
||||||
|
|
||||||
|
foorth_equal('try 10 .to_duration false > catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false < catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false >= catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false <= catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false <=> catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false + catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false - catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false * catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration false / catch end', [])
|
||||||
|
foorth_equal('try 10 .to_duration f"%Z" catch end', [])
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_some_logical_and
|
def test_some_logical_and
|
||||||
|
|
|
@ -33,26 +33,46 @@ module XfOOrth
|
||||||
|
|
||||||
#[a_duration numeric/duration] + [a_duration]
|
#[a_duration numeric/duration] + [a_duration]
|
||||||
Duration.create_shared_method('+', NosSpec, [], &lambda {|vm|
|
Duration.create_shared_method('+', NosSpec, [], &lambda {|vm|
|
||||||
result = @period + @period.foorth_coerce(vm.peek)
|
begin
|
||||||
vm.poke(Duration.new(result))
|
result = @period + @period.foorth_coerce(vm.peek)
|
||||||
|
vm.poke(Duration.new(result))
|
||||||
|
rescue
|
||||||
|
vm.data_stack.pop
|
||||||
|
raise
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
#[a_duration numeric/duration] - [a_duration]
|
#[a_duration numeric/duration] - [a_duration]
|
||||||
Duration.create_shared_method('-', NosSpec, [], &lambda {|vm|
|
Duration.create_shared_method('-', NosSpec, [], &lambda {|vm|
|
||||||
result = @period - @period.foorth_coerce(vm.peek)
|
begin
|
||||||
vm.poke(Duration.new(result))
|
result = @period - @period.foorth_coerce(vm.peek)
|
||||||
|
vm.poke(Duration.new(result))
|
||||||
|
rescue
|
||||||
|
vm.data_stack.pop
|
||||||
|
raise
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
#[a_duration numeric/duration] * [a_duration]
|
#[a_duration numeric/duration] * [a_duration]
|
||||||
Duration.create_shared_method('*', NosSpec, [], &lambda {|vm|
|
Duration.create_shared_method('*', NosSpec, [], &lambda {|vm|
|
||||||
result = @period * @period.foorth_coerce(vm.peek)
|
begin
|
||||||
vm.poke(Duration.new(result))
|
result = @period * @period.foorth_coerce(vm.peek)
|
||||||
|
vm.poke(Duration.new(result))
|
||||||
|
rescue
|
||||||
|
vm.data_stack.pop
|
||||||
|
raise
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
#[a_duration numeric/duration] / [a_duration]
|
#[a_duration numeric/duration] / [a_duration]
|
||||||
Duration.create_shared_method('/', NosSpec, [], &lambda {|vm|
|
Duration.create_shared_method('/', NosSpec, [], &lambda {|vm|
|
||||||
result = @period / @period.foorth_coerce(vm.peek)
|
begin
|
||||||
vm.poke(Duration.new(result))
|
result = @period / @period.foorth_coerce(vm.peek)
|
||||||
|
vm.poke(Duration.new(result))
|
||||||
|
rescue
|
||||||
|
vm.data_stack.pop
|
||||||
|
raise
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
# [a_duration] 1+ [a_duration+1]
|
# [a_duration] 1+ [a_duration+1]
|
||||||
|
|
|
@ -138,6 +138,7 @@ module XfOOrth
|
||||||
begin
|
begin
|
||||||
vm.poke(self.strfmt(vm.peek))
|
vm.poke(self.strfmt(vm.peek))
|
||||||
rescue => err
|
rescue => err
|
||||||
|
vm.data_stack.pop
|
||||||
error "F40: Formating error: #{err.message}."
|
error "F40: Formating error: #{err.message}."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue