Commit 63c4e000 authored by Michael Hanus 's avatar Michael Hanus

Simple primitives directly added to prelude

parent 6f795a69
......@@ -148,7 +148,7 @@ splitPath -> System.FilePath.splitPath
lookupFileInPath -> System.Directory.findFileWithSuffix
getFileInPath -> System.Directory.getFileWithSuffix
Nat -> Removed
Nat -> removed
System-> split into System.CPUTime, System.Environment, System.Process
Renames:
......@@ -179,3 +179,5 @@ Float -> removed, important functions integrated in prelude
i2f -> Prelude.fromInt
Read -> use read instance
ReadShowTerm -> in package read-legacy
......@@ -3,8 +3,6 @@
--- All exported functions, data types, type classes
--- and methods defined in this module are always
--- available in any Curry program.
---
--- @category general
--------------------------------------------------------------------------------
{-# LANGUAGE CPP #-}
{-# OPTIONS_FRONTEND -Wno-incomplete-patterns -Wno-overlapping #-}
......
......@@ -17,38 +17,6 @@
<library>prim_standard</library>
<entry>prim_applyGroundNormalForm[raw]</entry>
</primitive>
<primitive name="prim_plusInt" arity="2">
<library>prim_standard</library>
<entry>prim_Int_plus</entry>
</primitive>
<primitive name="prim_minusInt" arity="2">
<library>prim_standard</library>
<entry>prim_Int_minus</entry>
</primitive>
<primitive name="prim_timesInt" arity="2">
<library>prim_standard</library>
<entry>prim_Int_times</entry>
</primitive>
<primitive name="prim_divInt" arity="2">
<library>prim_standard</library>
<entry>prim_Int_div</entry>
</primitive>
<primitive name="prim_modInt" arity="2">
<library>prim_standard</library>
<entry>prim_Int_mod</entry>
</primitive>
<primitive name="prim_quotInt" arity="2">
<library>prim_standard</library>
<entry>prim_Int_quot</entry>
</primitive>
<primitive name="prim_remInt" 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">
<library>prim_standard</library>
<entry>prim_seq[raw]</entry>
......@@ -57,48 +25,6 @@
<library>prim_standard</library>
<entry>prim_ensureNotFree[raw]</entry>
</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_showIntLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_showTerm</entry>
</primitive>
<primitive name="prim_showFloatLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_showTerm</entry>
</primitive>
<primitive name="prim_showCharLiteral" arity="1">
<library>prim_readshowterm</library>
<entry>prim_showTerm</entry>
</primitive>
<primitive name="prim_showStringLiteral" 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">
<library>prim_standard</library>
<entry>prim_error</entry>
......@@ -155,14 +81,6 @@
<library>prim_standard</library>
<entry>prim_return[raw]</entry>
</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">
<library>prim_standard</library>
<entry>prim_readFile</entry>
......@@ -184,117 +102,4 @@
<entry>prim_catch[raw]</entry>
</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_plusFloat" arity="2">
<library>prim_float</library>
<entry>prim_Float_plus</entry>
</primitive>
<primitive name="prim_minusFloat" arity="2">
<library>prim_float</library>
<entry>prim_Float_minus</entry>
</primitive>
<primitive name="prim_timesFloat" arity="2">
<library>prim_float</library>
<entry>prim_Float_times</entry>
</primitive>
<primitive name="prim_divFloat" arity="2">
<library>prim_float</library>
<entry>prim_Float_div</entry>
</primitive>
<primitive name="prim_intToFloat" arity="1">
<library>prim_float</library>
<entry>prim_i2f</entry>
</primitive>
<primitive name="prim_logFloat" arity="1">
<library>prim_float</library>
<entry>prim_log</entry>
</primitive>
<primitive name="prim_expFloat" arity="1">
<library>prim_float</library>
<entry>prim_exp</entry>
</primitive>
<primitive name="prim_sqrtFloat" arity="1">
<library>prim_float</library>
<entry>prim_sqrt</entry>
</primitive>
<primitive name="prim_sinFloat" arity="1">
<library>prim_float</library>
<entry>prim_sin</entry>
</primitive>
<primitive name="prim_cosFloat" arity="1">
<library>prim_float</library>
<entry>prim_cos</entry>
</primitive>
<primitive name="prim_tanFloat" arity="1">
<library>prim_float</library>
<entry>prim_tan</entry>
</primitive>
<primitive name="prim_asinFloat" arity="1">
<library>prim_float</library>
<entry>prim_asin</entry>
</primitive>
<primitive name="prim_acosFloat" arity="1">
<library>prim_float</library>
<entry>prim_acos</entry>
</primitive>
<primitive name="prim_atanFloat" arity="1">
<library>prim_float</library>
<entry>prim_atan</entry>
</primitive>
<primitive name="prim_sinhFloat" arity="1">
<library>prim_float</library>
<entry>prim_sinh</entry>
</primitive>
<primitive name="prim_coshFloat" arity="1">
<library>prim_float</library>
<entry>prim_cosh</entry>
</primitive>
<primitive name="prim_tanhFloat" arity="1">
<library>prim_float</library>
<entry>prim_tanh</entry>
</primitive>
<primitive name="prim_asinhFloat" arity="1">
<library>prim_float</library>
<entry>prim_asinh</entry>
</primitive>
<primitive name="prim_acoshFloat" arity="1">
<library>prim_float</library>
<entry>prim_acosh</entry>
</primitive>
<primitive name="prim_atanhFloat" arity="1">
<library>prim_float</library>
<entry>prim_atanh</entry>
</primitive>
<primitive name="prim_truncateFloat" arity="1">
<library>prim_float</library>
<entry>prim_truncate</entry>
</primitive>
<primitive name="prim_roundFloat" arity="1">
<library>prim_float</library>
<entry>prim_round</entry>
</primitive>
</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='''
char_int(C,N),
(N=39 -> char_int(BS,92), S=[BS,C|SE] % '
; (N=34 -> S=[C|SE] % "
; showTermChar(N,S,SE))),
SE = [Apo].
'Prelude.prim_showStringLiteral'(Str,[Quot|S]) :-
char_int(Quot,34), % 34 = '"'
showTermString(Str,S,[]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Definition of I/O actions:
%
'Prelude.prim_putChar'(C,'Prelude.()') :-
char_int(C,N), put_code(N),
%flush_output. % this is problematic for Sicstus4 (substantial delay)
(N=10 -> flush_output ; true).
'Prelude.getChar'(C) :- get_code(N), char_int(C,N).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
......@@ -3,8 +3,6 @@
% Definitions of builtins of module System.CPUTime
%
:- (current_module(prologbasics) -> true ; use_module('../prologbasics')).
'System.CPUTime.getCPUTime'(MS) :- getRunTime(MS).
'System.CPUTime.getElapsedTime'(MS) :- getElapsedTime(MS).
......
......@@ -3,9 +3,6 @@
% Definitions of builtins of module System.Environment
%
:- (current_module(prologbasics) -> true ; use_module('../prologbasics')).
:- (current_module(basics) -> true ; use_module('../basics')).
'System.Environment.getArgs'(StringArgs) :-
(rtArgs(Args) -> true ; getProgramArgs(Args)),
map2M(basics:atom2String,Args,StringArgs).
......
......@@ -3,12 +3,6 @@
% Definitions of builtins of module System.IO
%
:- (current_module(prologbasics) -> true ; use_module('../prologbasics')).
:- (current_module(basics) -> true ; use_module('../basics')).
% to implement IO.prim_hWaitForInputsOrMsg:
:- (current_module(prim_ports) -> true ; ensure_loaded(prim_ports)).
% equality of two handles:
'System.IO.handle_eq'(H1,H2,B) :-
(H1=H2 -> B='Prelude.True' ; B='Prelude.False').
......
Markdown is supported
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