Commit f24107fb authored by Michael Hanus 's avatar Michael Hanus
Browse files

Prelude externals adapted to PAKCS 2.2.1

parent 747d99bc
{ {
"name": "base", "name": "base",
"version": "1.0.0", "version": "1.1.0",
"author": "Michael Hanus <mh@informatik.uni-kiel.de>", "author": "Michael Hanus <mh@informatik.uni-kiel.de>",
"synopsis": "Base libraries for Curry systems", "synopsis": "Base libraries for Curry systems",
"description": "This package contains the base libraries which are directly distributed with specific versions of the Curry systems PAKCS and KiCS2.", "description": "This package contains the base libraries which are directly distributed with specific versions of the Curry systems PAKCS and KiCS2.",
"category": [ "Programming" ], "category": [ "Programming" ],
"compilerCompatibility": { "compilerCompatibility": {
"kics2": ">= 2.0.0, < 3.0.0", "kics2": "> 2.2.0, < 3.0.0",
"pakcs": ">= 2.0.0, < 3.0.0" "pakcs": ">= 2.2.1, < 3.0.0"
}, },
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"licenseFile": "LICENSE", "licenseFile": "LICENSE",
......
...@@ -598,10 +598,10 @@ prim_chr external ...@@ -598,10 +598,10 @@ prim_chr external
--- Adds two integers. --- Adds two integers.
(+$) :: Int -> Int -> Int (+$) :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x +$ y = (prim_Int_plus $# y) $# x x +$ y = (prim_plusInt $# y) $# x
prim_Int_plus :: Int -> Int -> Int prim_plusInt :: Int -> Int -> Int
prim_Int_plus external prim_plusInt external
#else #else
(+$) external (+$) external
#endif #endif
...@@ -609,10 +609,10 @@ prim_Int_plus external ...@@ -609,10 +609,10 @@ prim_Int_plus external
--- Subtracts two integers. --- Subtracts two integers.
(-$) :: Int -> Int -> Int (-$) :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x -$ y = (prim_Int_minus $# y) $# x x -$ y = (prim_minusInt $# y) $# x
prim_Int_minus :: Int -> Int -> Int prim_minusInt :: Int -> Int -> Int
prim_Int_minus external prim_minusInt external
#else #else
(-$) external (-$) external
#endif #endif
...@@ -620,10 +620,10 @@ prim_Int_minus external ...@@ -620,10 +620,10 @@ prim_Int_minus external
--- Multiplies two integers. --- Multiplies two integers.
(*$) :: Int -> Int -> Int (*$) :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x *$ y = (prim_Int_times $# y) $# x x *$ y = (prim_timesInt $# y) $# x
prim_Int_times :: Int -> Int -> Int prim_timesInt :: Int -> Int -> Int
prim_Int_times external prim_timesInt external
#else #else
(*$) external (*$) external
#endif #endif
...@@ -634,10 +634,10 @@ prim_Int_times external ...@@ -634,10 +634,10 @@ prim_Int_times external
--- and the value of <code>-15 `div` 4</code> is <code>-3</code>. --- and the value of <code>-15 `div` 4</code> is <code>-3</code>.
div_ :: Int -> Int -> Int div_ :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x `div_` y = (prim_Int_div $# y) $# x x `div_` y = (prim_divInt $# y) $# x
prim_Int_div :: Int -> Int -> Int prim_divInt :: Int -> Int -> Int
prim_Int_div external prim_divInt external
#else #else
div_ external div_ external
#endif #endif
...@@ -648,10 +648,10 @@ div_ external ...@@ -648,10 +648,10 @@ div_ external
--- and the value of <code>-15 `mod` 4</code> is <code>-3</code>. --- and the value of <code>-15 `mod` 4</code> is <code>-3</code>.
mod_ :: Int -> Int -> Int mod_ :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x `mod_` y = (prim_Int_mod $# y) $# x x `mod_` y = (prim_modInt $# y) $# x
prim_Int_mod :: Int -> Int -> Int prim_modInt :: Int -> Int -> Int
prim_Int_mod external prim_modInt external
#else #else
mod_ external mod_ external
#endif #endif
...@@ -672,10 +672,10 @@ divMod_ external ...@@ -672,10 +672,10 @@ divMod_ external
--- and the value of <code>-15 `quot` 4</code> is <code>-3</code>. --- and the value of <code>-15 `quot` 4</code> is <code>-3</code>.
quot_ :: Int -> Int -> Int quot_ :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x `quot_` y = (prim_Int_quot $# y) $# x x `quot_` y = (prim_quotInt $# y) $# x
prim_Int_quot :: Int -> Int -> Int prim_quotInt :: Int -> Int -> Int
prim_Int_quot external prim_quotInt external
#else #else
quot_ external quot_ external
#endif #endif
...@@ -686,10 +686,10 @@ quot_ external ...@@ -686,10 +686,10 @@ quot_ external
--- and the value of <code>-15 `rem` 4</code> is <code>-3</code>. --- and the value of <code>-15 `rem` 4</code> is <code>-3</code>.
rem_ :: Int -> Int -> Int rem_ :: Int -> Int -> Int
#ifdef __PAKCS__ #ifdef __PAKCS__
x `rem_` y = (prim_Int_rem $# y) $# x x `rem_` y = (prim_remInt $# y) $# x
prim_Int_rem :: Int -> Int -> Int prim_remInt :: Int -> Int -> Int
prim_Int_rem external prim_remInt external
#else #else
rem_ external rem_ external
#endif #endif
...@@ -890,13 +890,6 @@ catch external ...@@ -890,13 +890,6 @@ catch external
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
--- Converts an arbitrary term into an external string representation.
show_ :: _ -> String
show_ x = prim_show $## x
prim_show :: _ -> String
prim_show external
--- Converts a term into a string and prints it. --- Converts a term into a string and prints it.
print :: Show a => a -> IO () print :: Show a => a -> IO ()
print t = putStrLn (show t) print t = putStrLn (show t)
...@@ -1244,16 +1237,16 @@ instance Show a => Show [a] where ...@@ -1244,16 +1237,16 @@ instance Show a => Show [a] where
instance Show Char where instance Show Char where
-- TODO: own implementation instead of passing to original Prelude functions? -- TODO: own implementation instead of passing to original Prelude functions?
showsPrec _ c = showString (show_ c) showsPrec _ c = showString (showCharLiteral c)
showList cs | null cs = showString "\"\"" showList cs | null cs = showString "\"\""
| otherwise = showString (show_ cs) | otherwise = showString (showStringLiteral cs)
instance Show Int where instance Show Int where
showsPrec = showSigned (showString . show_) showsPrec = showSigned (showString . showIntLiteral)
instance Show Float where instance Show Float where
showsPrec = showSigned (showString . show_) showsPrec = showSigned (showString . showFloatLiteral)
showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS
showSigned showPos p x showSigned showPos p x
...@@ -1265,11 +1258,33 @@ showTuple ss = showChar '(' ...@@ -1265,11 +1258,33 @@ showTuple ss = showChar '('
. foldr1 (\s r -> s . showChar ',' . r) ss . foldr1 (\s r -> s . showChar ',' . r) ss
. showChar ')' . showChar ')'
appPrec :: Int -- Returns the string representation of a character.
appPrec = 10 showCharLiteral :: Char -> String
showCharLiteral x = prim_showCharLiteral $## x
prim_showCharLiteral :: Char -> String
prim_showCharLiteral external
-- Returns the string representation of a string.
showStringLiteral :: String -> String
showStringLiteral x = prim_showStringLiteral $## x
prim_showStringLiteral :: String -> String
prim_showStringLiteral external
-- Returns the string representation of an integer.
showIntLiteral :: Int -> String
showIntLiteral x = prim_showIntLiteral $## x
prim_showIntLiteral :: Int -> String
prim_showIntLiteral external
-- Returns the string representation of a floating point number.
showFloatLiteral :: Float -> String
showFloatLiteral x = prim_showFloatLiteral $## x
appPrec1 :: Int prim_showFloatLiteral :: Float -> String
appPrec1 = 11 prim_showFloatLiteral external
-- ------------------------------------------------------------------------- -- -------------------------------------------------------------------------
-- Read class and related instances and functions -- Read class and related instances and functions
...@@ -1796,38 +1811,38 @@ asTypeOf = const ...@@ -1796,38 +1811,38 @@ asTypeOf = const
--- Addition on floats. --- Addition on floats.
(+.) :: Float -> Float -> Float (+.) :: Float -> Float -> Float
x +. y = (prim_Float_plus $# y) $# x x +. y = (prim_plusFloat $# y) $# x
prim_Float_plus :: Float -> Float -> Float prim_plusFloat :: Float -> Float -> Float
prim_Float_plus external prim_plusFloat external
--- Subtraction on floats. --- Subtraction on floats.
(-.) :: Float -> Float -> Float (-.) :: Float -> Float -> Float
x -. y = (prim_Float_minus $# y) $# x x -. y = (prim_minusFloat $# y) $# x
prim_Float_minus :: Float -> Float -> Float prim_minusFloat :: Float -> Float -> Float
prim_Float_minus external prim_minusFloat external
--- Multiplication on floats. --- Multiplication on floats.
(*.) :: Float -> Float -> Float (*.) :: Float -> Float -> Float
x *. y = (prim_Float_times $# y) $# x x *. y = (prim_timesFloat $# y) $# x
prim_Float_times :: Float -> Float -> Float prim_timesFloat :: Float -> Float -> Float
prim_Float_times external prim_timesFloat external
--- Division on floats. --- Division on floats.
(/.) :: Float -> Float -> Float (/.) :: Float -> Float -> Float
x /. y = (prim_Float_div $# y) $# x x /. y = (prim_divFloat $# y) $# x
prim_Float_div :: Float -> Float -> Float prim_divFloat :: Float -> Float -> Float
prim_Float_div external prim_divFloat external
--- Conversion function from integers to floats. --- Conversion function from integers to floats.
i2f :: Int -> Float i2f :: Int -> Float
i2f x = prim_i2f $# x i2f x = prim_intToFloat $# x
prim_i2f :: Int -> Float prim_intToFloat :: Int -> Float
prim_i2f external prim_intToFloat external
-- the end of the standard prelude -- the end of the standard prelude
......
...@@ -17,38 +17,6 @@ ...@@ -17,38 +17,6 @@
<library>prim_standard</library> <library>prim_standard</library>
<entry>prim_applyGroundNormalForm[raw]</entry> <entry>prim_applyGroundNormalForm[raw]</entry>
</primitive> </primitive>
<primitive name="prim_Int_plus" arity="2">
<library>prim_standard</library>
<entry>prim_Int_plus</entry>
</primitive>
<primitive name="prim_Int_minus" arity="2">
<library>prim_standard</library>
<entry>prim_Int_minus</entry>
</primitive>
<primitive name="prim_Int_times" arity="2">
<library>prim_standard</library>
<entry>prim_Int_times</entry>
</primitive>
<primitive name="prim_Int_div" arity="2">
<library>prim_standard</library>
<entry>prim_Int_div</entry>
</primitive>
<primitive name="prim_Int_mod" arity="2">
<library>prim_standard</library>
<entry>prim_Int_mod</entry>
</primitive>
<primitive name="prim_Int_quot" arity="2">
<library>prim_standard</library>
<entry>prim_Int_quot</entry>
</primitive>
<primitive name="prim_Int_rem" arity="2">
<library>prim_standard</library>
<entry>prim_Int_rem</entry>
</primitive>
<primitive name="prim_negateFloat" arity="1">
<library>prim_standard</library>
<entry>prim_negateFloat</entry>
</primitive>
<primitive name="seq" arity="2"> <primitive name="seq" arity="2">
<library>prim_standard</library> <library>prim_standard</library>
<entry>prim_seq[raw]</entry> <entry>prim_seq[raw]</entry>
...@@ -57,34 +25,6 @@ ...@@ -57,34 +25,6 @@
<library>prim_standard</library> <library>prim_standard</library>
<entry>prim_ensureNotFree[raw]</entry> <entry>prim_ensureNotFree[raw]</entry>
</primitive> </primitive>
<primitive name="prim_ord" arity="1">
<library>prim_standard</library>
<entry>prim_ord</entry>
</primitive>
<primitive name="prim_chr" arity="1">
<library>prim_standard</library>
<entry>prim_chr</entry>
</primitive>
<primitive name="prim_show" arity="1">
<library>prim_readshowterm</library>
<entry>prim_showTerm</entry>
</primitive>
<primitive name="prim_readNatLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_readNatLiteral</entry>
</primitive>
<primitive name="prim_readFloatLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_readFloatLiteral</entry>
</primitive>
<primitive name="prim_readCharLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_readCharLiteral</entry>
</primitive>
<primitive name="prim_readStringLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_readStringLiteral</entry>
</primitive>
<primitive name="prim_error" arity="1"> <primitive name="prim_error" arity="1">
<library>prim_standard</library> <library>prim_standard</library>
<entry>prim_error</entry> <entry>prim_error</entry>
...@@ -141,14 +81,6 @@ ...@@ -141,14 +81,6 @@
<library>prim_standard</library> <library>prim_standard</library>
<entry>prim_return[raw]</entry> <entry>prim_return[raw]</entry>
</primitive> </primitive>
<primitive name="prim_putChar" arity="1">
<library>prim_standard</library>
<entry>prim_putChar</entry>
</primitive>
<primitive name="getChar" arity="0">
<library>prim_standard</library>
<entry>prim_getChar</entry>
</primitive>
<primitive name="prim_readFile" arity="1"> <primitive name="prim_readFile" arity="1">
<library>prim_standard</library> <library>prim_standard</library>
<entry>prim_readFile</entry> <entry>prim_readFile</entry>
...@@ -170,49 +102,4 @@ ...@@ -170,49 +102,4 @@
<entry>prim_catch[raw]</entry> <entry>prim_catch[raw]</entry>
</primitive> </primitive>
<primitive name="prim_eqChar" arity="2">
<library>prim_standard</library>
<entry>prim_eqBasic</entry>
</primitive>
<primitive name="prim_eqInt" arity="2">
<library>prim_standard</library>
<entry>prim_eqBasic</entry>
</primitive>
<primitive name="prim_eqFloat" arity="2">
<library>prim_standard</library>
<entry>prim_eqBasic</entry>
</primitive>
<primitive name="prim_ltEqChar" arity="2">
<library>prim_standard</library>
<entry>prim_leqChar</entry>
</primitive>
<primitive name="prim_ltEqInt" arity="2">
<library>prim_standard</library>
<entry>prim_leqNumber</entry>
</primitive>
<primitive name="prim_ltEqFloat" arity="2">
<library>prim_standard</library>
<entry>prim_leqNumber</entry>
</primitive>
<primitive name="prim_Float_plus" arity="2">
<library>prim_float</library>
<entry>prim_Float_plus</entry>
</primitive>
<primitive name="prim_Float_minus" arity="2">
<library>prim_float</library>
<entry>prim_Float_minus</entry>
</primitive>
<primitive name="prim_Float_times" arity="2">
<library>prim_float</library>
<entry>prim_Float_times</entry>
</primitive>
<primitive name="prim_Float_div" arity="2">
<library>prim_float</library>
<entry>prim_Float_div</entry>
</primitive>
<primitive name="prim_i2f" arity="1">
<library>prim_float</library>
<entry>prim_i2f</entry>
</primitive>
</primitives> </primitives>
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Definition of standard external functions:
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of arithmetic functions:
%
'Prelude.prim_plusInt'(Y,X,R) :- R is X+Y.
'Prelude.prim_minusInt'(Y,X,R) :- R is X-Y.
'Prelude.prim_timesInt'(Y,X,R) :- R is X*Y.
'Prelude.prim_divInt'(Y,X,R) :- R is div(X,Y).
'Prelude.prim_modInt'(Y,X,R) :- isMod(R,X,Y).
'Prelude.prim_quotInt'(Y,X,R) :- R is X // Y.
'Prelude.prim_remInt'(Y,X,R) :- isRem(R,X,Y).
'Prelude.prim_plusFloat'(Y,X,R) :- R is X+Y.
'Prelude.prim_minusFloat'(Y,X,R) :- R is X-Y.
'Prelude.prim_timesFloat'(Y,X,R) :- R is X*Y.
'Prelude.prim_divFloat'(Y,X,R) :- R is X/Y.
'Prelude.prim_negateFloat'(X,R) :- R is -X.
% transform an integer into a float:
'Prelude.prim_intToFloat'(X,R) :- R is X*1.0.
% transform a float to an integer:
'Prelude.prim_truncateFloat'(X,R) :- R is integer(X).
% round a float to an integer:
'Prelude.prim_roundFloat'(X,R) :- R is integer(round(X)).
'Prelude.prim_sqrtFloat'(X,R) :- R is sqrt(X).
'Prelude.prim_logFloat'(X,R) :- R is log(X).
'Prelude.prim_expFloat'(X,R) :- R is exp(X).
'Prelude.prim_sinFloat'(X,R) :- R is sin(X).
'Prelude.prim_cosFloat'(X,R) :- R is cos(X).
'Prelude.prim_tanFloat'(X,R) :- R is tan(X).
'Prelude.prim_asinFloat'(X,R) :- R is asin(X).
'Prelude.prim_acosFloat'(X,R) :- R is acos(X).
'Prelude.prim_atanFloat'(X,R) :- R is atan(X).
'Prelude.prim_sinhFloat'(X,R) :- R is sinh(X).
'Prelude.prim_coshFloat'(X,R) :- R is cosh(X).
'Prelude.prim_tanhFloat'(X,R) :- R is tanh(X).
'Prelude.prim_asinhFloat'(X,R) :- R is asinh(X).
'Prelude.prim_acoshFloat'(X,R) :- R is acosh(X).
'Prelude.prim_atanhFloat'(X,R) :- R is atanh(X).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of comparsion of primitive data:
%
'Prelude.prim_eqInt'(Y,X,R) :- X==Y -> R='Prelude.True' ; R='Prelude.False'.
'Prelude.prim_eqFloat'(Y,X,R) :- X==Y -> R='Prelude.True' ; R='Prelude.False'.
'Prelude.prim_eqChar'(Y,X,R) :- X==Y -> R='Prelude.True' ; R='Prelude.False'.
'Prelude.prim_ltEqInt'(Y,X,R) :- X=<Y -> R='Prelude.True' ; R='Prelude.False'.
'Prelude.prim_ltEqFloat'(Y,X,R) :- X=<Y -> R='Prelude.True' ; R='Prelude.False'.
'Prelude.prim_ltEqChar'(Y,X,R) :-
char_int(X,VX), char_int(Y,VY),
VX=<VY -> R='Prelude.True' ; R='Prelude.False'.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of conversion functions for characters:
%
'Prelude.prim_ord'(C,N) :- char_int(C,N).
'Prelude.prim_chr'(N,C) :- N>=0, N<1114112, !, char_int(C,N).
'Prelude.prim_chr'(_,_) :- raise_exception('chr: argument out of range').
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Show and read functions for primitive types:
%
'Prelude.prim_showIntLiteral'(N,S) :- prim_showNumber(N,S).
'Prelude.prim_showFloatLiteral'(N,S) :- prim_showNumber(N,S).
prim_showNumber(N,S) :-
number_codes(N,SN), map2M(basics:char_int,String,SN),
(N>=0 -> S = String
; % enclose negative number in parentheses:
char_int(Op,40), char_int(Cl,41),
append([Op|String],[Cl],S)).
% conversion of string representations of nat literals into Curry terms:
'Prelude.prim_readNatLiteral'([CC|String],['Prelude.(,)'(Num,TailString)]) :-
char_int(CC,C), C>47, C<58,
natConst(NumStr,String,TailString),
number_codes(Num,[C|NumStr]), !.
'Prelude.prim_readNatLiteral'(_,[]). % parse error
% conversion of string representations of float literals into Curry terms:
'Prelude.prim_readFloatLiteral'([CC|String],['Prelude.(,)'(Num,TailString)]) :-
char_int(CC,C), C>47, C<58,
floatConst(NumStr,String,TailString),
number_codes(Num,[C|NumStr]), !.
'Prelude.prim_readFloatLiteral'(_,[]). % parse error
natConst([C|Cs]) --> [CC],
{ char_int(CC,C), C>47, C<58 }, !,
natConst(Cs).
natConst([]) --> skipblanks.
floatConst([C|Cs]) --> [CC],
{ char_int(CC,C), C>47, C<58 }, !,
floatConst(Cs).
floatConst([46,C|Cs]) --> [PC], { char_int(PC,46) }, [CC],
{ char_int(CC,C), C>47, C<58 }, !,
floatConstRest(Cs).
floatConstRest([C|Cs]) --> [CC],
{ char_int(CC,C), C>47, C<58 }, !,
floatConstRest(Cs).
floatConstRest([C|Cs]) --> [CC], {char_int(CC,C), C=69 ; C=101}, !, % exponent
intConst(Cs).
floatConstRest([]) --> skipblanks.
intConst(Cs) --> ( [CC], {char_int(CC,45)}, natConst(NCs), {Cs=[45|NCs]}
; natConst(Cs)
).
% conversion of string representations of char literals into Curry terms:
% TODO: avoid char_int conversion
'Prelude.prim_readCharLiteral'(String,['Prelude.(,)'(Char,TailString)]) :-
map2M(basics:char_int,String,[C|PrologString]),
C=39, readChar(PrologString,Tail,Char),
map2M(basics:char_int,TailString,Tail), !.
'Prelude.prim_readCharLiteral'(_,[]). % parse error
% conversion of string representations of string literals into Curry terms:
% TODO: avoid char_int conversion
'Prelude.prim_readStringLiteral'(String,['Prelude.(,)'(Result,TailString)]) :-
map2M(basics:char_int,String,[C|PrologString]),
C=34, readString(PrologString,Tail,Result),
map2M(basics:char_int,TailString,Tail), !.
'Prelude.prim_readStringLiteral'(_,[]). % parse error
'Prelude.prim_showCharLiteral'(C,[Apo|S]) :-
char_int(Apo,39), % 39='''