Commit 8d2f44f5 authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

replace nat and .- for Nat with ABC code

parent 92096b76
...@@ -14,11 +14,24 @@ import Algebra.Lattice ...@@ -14,11 +14,24 @@ import Algebra.Lattice
:: Nat :== Int :: Nat :== Int
//TODO rewrite in inlineable ABC (?)
nat :: !Int -> Nat nat :: !Int -> Nat
nat n nat n = code {
| n < 0 = abort "Data.Nat.nat: negative integer" pushI 0
| otherwise = n push_b 1
ltI
jmp_true abort_n
.d 0 1 i
rtn
:abort_n
buildAC "Data.Nat.nat: negative integer"
.d 1 0
jsr print_string_
.o 0 0
halt
}
// nat n
// | n < 0 = abort "Data.Nat.nat: negative integer"
// | otherwise = n
int :: !Nat -> Int int :: !Nat -> Int
int n = code inline { int n = code inline {
...@@ -141,8 +154,23 @@ instance LowerBounded Nat where ...@@ -141,8 +154,23 @@ instance LowerBounded Nat where
/// # Special Algebra /// # Special Algebra
//TODO rewrite in inlineable ABC (?)
(.-) infixl 6 :: !Nat !Nat -> Nat (.-) infixl 6 :: !Nat !Nat -> Nat
(.-) n m (.-) n m = code {
| m < n = nat (int n - int m) push_b 0
| otherwise = neutral push_b 2
ltI
jmp_false zero_n
subI
.d 0 1 i
rtn
:zero_n
pop_b 2
pushI 0
.d 0 1 i
rtn
}
// (.-) n m
// | m < n = nat (int n - int m)
// | otherwise = neutral
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment