Duration fixes.

This commit is contained in:
Peter Camilleri 2015-08-10 18:31:46 -04:00
parent 6be6771bf1
commit a5b095009d
3 changed files with 40 additions and 8 deletions

View file

@ -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

View file

@ -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]

View file

@ -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