Commit 90bc10d2 authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

move primitives into system modules

parent 9a4da8e6
......@@ -113,20 +113,6 @@ OtherModules
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Clean.Prim
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Array
Dir: {Project}/src
......@@ -267,20 +253,6 @@ OtherModules
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.String
Dir: {Project}/src
Compiler
NeverMemoryProfile: False
NeverTimeProfile: False
StrictnessAnalysis: True
ListTypes: StrictExportTypes
ListAttributes: True
Warnings: True
Verbose: True
ReadableABC: False
ReuseUniqueNodes: True
Fusion: False
Module
Name: Data.Tuple
Dir: {Project}/src
......
......@@ -4,166 +4,3 @@ system module Clean.Prim
// - add primitives for gt, le, ge, ne
// - add primitives for arrays
// - add primitives for files
/// # Miscellaneous
prim_abort :: !String -> .a
prim_noop :: .a
/// # Booleans
prim_eqBool :: !Bool !Bool -> Bool
prim_trueBool :: Bool
prim_falseBool :: Bool
prim_andBool :: !Bool Bool -> Bool
prim_orBool :: !Bool Bool -> Bool
prim_notBool :: !Bool -> Bool
/// # Characters
prim_eqChar :: !Char !Char -> Bool
prim_ltChar :: !Char !Char -> Bool
// prim_gtChar :: !Char !Char -> Bool
// prim_minChar :: !Char !Char -> Char
// prim_maxChar :: !Char !Char-> Char
prim_setLowercaseBitChar :: !Char -> Char
prim_unsetLowercaseBitChar :: !Char -> Char
/// # Integers
prim_zeroInt :: Int
prim_oneInt :: Int
prim_upperInt :: Int
prim_lowerInt :: Int
prim_eqInt :: !Int !Int -> Bool
prim_ltInt :: !Int !Int -> Bool
// prim_gtInt :: !Int !Int -> Bool
prim_incInt :: !Int -> Int
prim_decInt :: !Int -> Int
prim_minInt :: !Int !Int -> Int
prim_maxInt :: !Int !Int-> Int
prim_negInt :: !Int -> Int
prim_addInt :: !Int !Int -> Int
prim_subInt :: !Int !Int -> Int
prim_mulInt :: !Int !Int -> Int
prim_quotInt :: !Int !Int -> Int
prim_remInt :: !Int !Int -> Int
prim_divInt :: !Int !Int -> Int
prim_modInt :: !Int !Int -> Int
prim_quotRemInt :: !Int !Int -> (!Int,!Int)
prim_divModInt :: !Int !Int -> (!Int,!Int)
prim_isEvenInt :: !Int -> Bool
prim_isOddInt :: !Int -> Bool
prim_andInt :: !Int !Int -> Int
prim_orInt :: !Int !Int -> Int
prim_xorInt :: !Int !Int -> Int
prim_notInt :: !Int -> Int
prim_shlInt :: !Int !Int -> Int
prim_shrInt :: !Int !Int -> Int
/// # Reals
prim_eqReal :: !Real !Real -> Bool
prim_ltReal :: !Real !Real -> Bool
// prim_gtReal :: !Real !Real -> Bool
// prim_minReal :: !Real !Real -> Real
// prim_maxReal :: !Real !Real -> Real
prim_zeroReal :: Real
prim_oneReal :: Real
prim_piReal :: Real
prim_eReal :: Real
prim_negReal :: !Real -> Real
prim_addReal :: !Real !Real -> Real
prim_subReal :: !Real !Real -> Real
prim_mulReal :: !Real !Real -> Real
prim_divReal :: !Real !Real -> Real
prim_powReal :: !Real !Real -> Real
prim_absReal :: !Real -> Real
prim_floorReal :: !Real -> Int
// prim_ceilReal :: !Real -> Int
// prim_truncateReal :: !Real -> Int
prim_logReal :: !Real -> Real
prim_log10Real :: !Real -> Real
prim_expReal :: !Real -> Real
prim_sqrtReal :: !Real -> Real
prim_sinReal :: !Real -> Real
prim_cosReal :: !Real -> Real
prim_tanReal :: !Real -> Real
prim_asinReal :: !Real -> Real
prim_acosReal :: !Real -> Real
prim_atanReal :: !Real -> Real
/// # Strings
prim_eqString :: !String !String -> Bool
prim_ltString :: !String !String -> Bool
prim_emptyString :: String
prim_sliceString :: !String !Int !Int -> String
prim_concatString :: !String !String -> String
/// # Files
prim_readTextFileMode :== 0 /// Read from a text file
prim_writeTextFileMode :== 1 /// Write to a text file
prim_appendTextFileMode :== 2 /// Append to an existing text file
prim_readDataFileMode :== 3 /// Read from a data file
prim_writeDataFileMode :== 4 /// Write to a data file
prim_appendDataFileMode :== 5 /// Append to an existing data file
prim_absoluteSeekMode :== 0 /// New position is the seek offset
prim_relativeSeekMode :== 1 /// New position is the current position plus the seek offset
prim_fromEndSeekMode :== 2 /// New position is the size of the file plus the seek offset
prim_openFile :: !String !Int -> (!Bool,!*File)
prim_closeFile :: !*File -> Bool
prim_reopenFile :: !*File !Int -> (!Bool,!*File)
prim_stdio :: *File
prim_stderr :: *File
prim_positionFile :: !*File -> (!Int,!*File)
prim_seekFile :: !*File !Int !Int -> (!Bool,!*File)
prim_isEndFile :: !*File -> (!Bool,!*File)
prim_isErrorFile :: !*File -> (!Bool,!*File)
prim_readCharFile :: !*File -> (!Bool,!Char,!*File)
prim_readIntFile :: !*File -> (!Bool,!Int,!*File)
// prim_readRealFile :: !*File -> (!Bool,!Real,!*File)
prim_readStringFile :: !*File !Int -> (!*String,!*File)
prim_readLineFile :: !*File -> (!*String,!*File)
prim_writeCharFile :: !Char !*File -> *File
prim_writeIntFile :: !Int !*File -> *File
// prim_writeRealFile :: !Real !*File -> *File
prim_writeStringFile :: !String !*File -> *File
/// # Conversions
prim_boolToString :: !Bool -> String
prim_charToInt :: !Char -> Int
prim_charToString :: !Char -> String
prim_intToChar :: !Int -> Char
prim_intToReal :: !Int -> Real
prim_intToString :: !Int -> String
prim_realToInt :: !Real -> Int
// prim_realToString :: !Real -> String
implementation module Clean.Prim
undefined :== prim_abort "Clean.Prim: Not yet implementd"
/// # Miscellaneous
prim_abort :: !String -> .a
prim_abort s = code inline {
.d 1 0
jsr print_string_
.o 0 0
halt
}
prim_noop :: .a
prim_noop = code inline {
no_op
}
/// # Booleans
/// ## Ordering
prim_eqBool :: !Bool !Bool -> Bool
prim_eqBool a b = code inline {
eqB
}
/// ## Literals
prim_trueBool :: Bool
prim_trueBool = code inline {
pushB TRUE
}
prim_falseBool :: Bool
prim_falseBool = code inline {
pushB FALSE
}
/// ## Logic
prim_andBool :: !Bool Bool -> Bool
prim_andBool a b = code {
push_b 0
jmp_false l1
pop_b 1
jsr_eval 0
pushB_a 0
pop_a 1
.d 0 1 b
rtn
:l1
pop_a 1
.d 0 1 b
rtn
}
prim_orBool :: !Bool Bool -> Bool
prim_orBool a b = code {
push_b 0
jmp_true l2
pop_b 1
jsr_eval 0
pushB_a 0
pop_a 1
.d 0 1 b
rtn
:l2
pop_a 1
.d 0 1 b
rtn
}
prim_notBool :: !Bool -> Bool
prim_notBool b = code inline {
notB
}
/// # Characters
/// ## Ordering
prim_eqChar :: !Char !Char -> Bool
prim_eqChar a b = code inline {
eqC
}
prim_ltChar :: !Char !Char -> Bool
prim_ltChar a b = code inline {
ltC
}
/// ## Casing
prim_setLowercaseBitChar :: !Char -> Char
prim_setLowercaseBitChar c = code inline {
pushI 32
or%
}
prim_unsetLowercaseBitChar :: !Char -> Char
prim_unsetLowercaseBitChar c = code inline {
pushI 223
and%
}
/// # Integers
/// ## Values
prim_zeroInt :: Int
prim_zeroInt = code inline {
pushI 0
}
prim_oneInt :: Int
prim_oneInt = code inline {
pushI 1
}
prim_upperInt :: Int
prim_upperInt = undefined
prim_lowerInt :: Int
prim_lowerInt = undefined
/// ## Ordering
prim_eqInt :: !Int !Int -> Bool
prim_eqInt a b = code inline {
eqI
}
prim_ltInt :: !Int !Int -> Bool
prim_ltInt a b = code inline {
ltI
}
/// ## Operations
prim_incInt :: !Int -> Int
prim_incInt a = code inline {
incI
}
prim_decInt :: !Int -> Int
prim_decInt a = code inline {
decI
}
prim_minInt :: !Int !Int -> Int
prim_minInt a b = undefined // code inline {
// minI
// }
prim_maxInt :: !Int !Int -> Int
prim_maxInt a b = undefined // code inline {
// maxI
// }
/// ## Arithmetic
prim_negInt :: !Int -> Int
prim_negInt a = code inline {
negI
}
prim_addInt :: !Int !Int -> Int
prim_addInt a b = code inline {
addI
}
prim_subInt :: !Int !Int -> Int
prim_subInt a b = code inline {
subI
}
prim_mulInt :: !Int !Int -> Int
prim_mulInt a b = code inline {
mulI
}
/// ## Integer Arithmetic
prim_quotInt :: !Int !Int -> Int
prim_quotInt a b = code inline {
divI
}
prim_remInt :: !Int !Int -> Int
prim_remInt a b = code inline {
remI
}
prim_divInt :: !Int !Int -> Int
prim_divInt a b = undefined
// prim_divInt a b = code inline {
// floordivI
// }
prim_modInt :: !Int !Int -> Int
prim_modInt a b = undefined
// prim_modInt a b = code inline {
// modI
// }
prim_quotRemInt :: !Int !Int -> (!Int,!Int)
prim_quotRemInt a b = code inline {
push_b 1
push_b 1
divI
push_b 2
push_b 1
mulI
push_b 2
subI
update_b 0 3
update_b 1 2
pop_b 2
}
prim_divModInt :: !Int !Int -> (!Int,!Int)
prim_divModInt a b = undefined
// prim_divModInt a b = code inline {
// push_b 1
// push_b 1
// floordivI
// push_b 2
// push_b 1
// mulI
// push_b 2
// subI
// update_b 0 3
// update_b 1 2
// pop_b 2
// }
/// ## Tests
prim_isEvenInt :: !Int -> Bool
......@@ -289,78 +55,19 @@ prim_shrInt a b = code inline {
/// # Reals
/// ## Ordering
prim_eqReal :: !Real !Real -> Bool
prim_eqReal a b = code inline {
eqR
}
prim_ltReal :: !Real !Real -> Bool
prim_ltReal a b = code inline {
ltR
}
/// ## Basic Values
prim_zeroReal :: Real
prim_zeroReal = code inline {
pushR 0.0
}
prim_oneReal :: Real
prim_oneReal = code inline {
pushR 1.0
}
prim_piReal :: Real
prim_piReal = code inline {
pushR 3.141592653589793238
}
prim_eReal :: Real
prim_eReal = code inline {
pushR 2.718281828459045235
}
/// ## Arithmetic
prim_negReal :: !Real -> Real
prim_negReal a = code inline {
negR
}
prim_addReal :: !Real !Real -> Real
prim_addReal a b = code inline {
addR
}
prim_subReal :: !Real !Real -> Real
prim_subReal a b = code inline {
subR
}
prim_mulReal :: !Real !Real -> Real
prim_mulReal a b = code inline {
mulR
}
prim_divReal :: !Real !Real -> Real
prim_divReal a b = code inline {
divR
}
prim_powReal :: !Real !Real -> Real
prim_powReal a b = code inline {
powR
}
prim_absReal :: !Real -> Real
prim_absReal a = code inline {
absR
}
/// ## Rounded
prim_logReal :: !Real -> Real
prim_logReal a = code inline {
log10R
}
/// ## Rounding
prim_roundReal :: !Real -> Int
prim_roundReal r = code inline {
......@@ -384,86 +91,8 @@ prim_floorReal r = code inline {
// truncateR
//}
/// ## Algebraic
prim_logReal :: !Real -> Real
prim_logReal x = code inline {
lnR
}
prim_log10Real :: !Real -> Real
prim_log10Real x = code inline {
log10R
}
prim_expReal :: !Real -> Real
prim_expReal x = code inline {
expR
}
prim_sqrtReal :: !Real -> Real
prim_sqrtReal x = code inline {
sqrtR
}
/// ## Trigoniometric
prim_sinReal :: !Real -> Real
prim_sinReal x = code inline {
sinR
}
prim_cosReal :: !Real -> Real
prim_cosReal x = code inline {
cosR
}
prim_tanReal :: !Real -> Real
prim_tanReal x = code inline {
tanR
}
prim_asinReal :: !Real -> Real
prim_asinReal x = code inline {
asinR
}
prim_acosReal :: !Real -> Real
prim_acosReal x = code inline {
acosR
}
prim_atanReal :: !Real -> Real
prim_atanReal x = code inline {
atanR
}
/// # Strings
/// ## Comparing
prim_eqString :: !String !String -> Bool
prim_eqString a b = code inline {
.d 2 0
jsr eqAC
.o 0 1 b
}
prim_ltString :: !String !String -> Bool
prim_ltString a b = code inline {
.d 2 0
jsr cmpAC
.o 0 1 i
pushI 0
gtI
}
/// ## Basic Values
//TODO use create_array (?)
prim_emptyString :: String
prim_emptyString = ""
/// ## Slicing
//FIXME change from tuple to two args, does this work?
......@@ -474,15 +103,6 @@ prim_sliceString s a b = code inline {
.o 1 0
}