Commit 59ee5c1c authored by johnvg@science.ru.nl's avatar johnvg@science.ru.nl Committed by Camil Staps

add inline abc code to definition modules

parent daff4dc8
......@@ -5,18 +5,18 @@ system module StdBool
*/
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version 2.0
// Copyright 1998 University of Nijmegen
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
import StdOverloaded
instance == Bool
instance == Bool :: !Bool !Bool -> Bool :== code { eqB }
instance toBool Bool
instance toBool Bool :: !Bool -> Bool :== code { no_op }
instance fromBool Bool
instance fromBool {#Char}
instance fromBool Bool :: !Bool -> Bool :== code { no_op }
instance fromBool {#Char} :: !Bool -> {#Char} :== code { .d 0 1 b ; jsr BtoAC ; .o 1 0 }
// Additional Logical Operators:
......@@ -26,7 +26,7 @@ instance fromBool {#Char}
* @param The boolean to negate
* @result True if the parameter was False; False if True
*/
not :: !Bool -> Bool
not :: !Bool -> Bool :== code { notB }
/**
* Logical disjunction. The second parameter is not strict and will not be
......
......@@ -5,26 +5,26 @@ system module StdChar
*/
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version 2.0
// Copyright 1998 University of Nijmegen
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
import StdOverloaded
instance + Char
instance - Char
instance zero Char
instance one Char
instance + Char :: !Char !Char -> Char :== code { addI ; ItoC }
instance - Char :: !Char !Char -> Char :== code { subI; ItoC }
instance zero Char :: Char :== code { pushI 0; ItoC }
instance one Char :: Char :== code { pushI 1; ItoC }
instance == Char
instance < Char
instance == Char :: !Char !Char -> Bool :== code { eqC }
instance < Char :: !Char !Char -> Bool :== code { ltC }
instance toChar Char
instance toChar Int
instance toChar Char :: !Char -> Char :== code { no_op }
instance toChar Int :: !Int -> Char :== code { ItoC }
instance fromChar Int
instance fromChar Char
instance fromChar {#Char}
instance fromChar Int :: !Char -> Int :== code { CtoI }
instance fromChar Char :: !Char -> Char :== code { no_op }
instance fromChar {#Char} :: !Char -> {#Char} :== code { CtoAC }
// Additional conversions:
......
implementation module StdChar
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version .0
// Copyright 1998 University of Nijmegen
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
import StdOverloaded, StdBool, StdInt, StdClass
......
system module StdFile
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
// File modes synonyms
FReadText :== 0 // Read from a text file
FWriteText :== 1 // Write to a text file
FAppendText :== 2 // Append to an existing text file
FReadData :== 3 // Read from a data file
FWriteData :== 4 // Write to a data file
FAppendData :== 5 // Append to an existing data file
// Seek modes synonyms
FSeekSet :== 0 // New position is the seek offset
FSeekCur :== 1 // New position is the current position plus the seek offset
FSeekEnd :== 2 // New position is the size of the file plus the seek offset
:: *Files
// Acces to the FileSystem (Files)
class FileSystem f where
fopen :: !{#Char} !Int !*f -> (!Bool,!*File,!*f)
/* Opens a file for the first time in a certain mode (read, write or append, text or data).
The boolean output parameter reports success or failure. */
fclose :: !*File !*f -> (!Bool,!*f)
/* Closes a file */
stdio :: !*f -> (!*File,!*f)
/* Open the 'Console' for reading and writing. */
sfopen :: !{#Char} !Int !*f -> (!Bool,!File,!*f)
/* With sfopen a file can be opened for reading more than once.
On a file opened by sfopen only the operations beginning with sf can be used.
The sf... operations work just like the corresponding f... operations.
They can't be used for files opened with fopen or freopen. */
instance FileSystem Files
instance FileSystem World
class FileEnv env where
accFiles :: !.(*Files -> (.x,*Files)) !*env -> (!.x,!*env)
appFiles :: !.(*Files -> *Files) !*env -> *env
instance FileEnv World
// openfiles :: !*World -> (!*Files,!*World) // no longer supported
// closefiles :: !*Files !*World -> *World // no longer supported
freopen :: !*File !Int -> (!Bool,!*File) :== code { .d 0 3 f i ; jsr reopenF ; .o 0 3 b f }
/* Re-opens an open file in a possibly different mode.
The boolean indicates whether the file was successfully closed before reopening. */
// Reading from a File:
freadc :: !*File -> (!Bool,!Char,!*File) :== code { .d 0 2 f ; jsr readFC ; .o 0 4 b c f }
/* Reads a character from a text file or a byte from a datafile.
The boolean indicates succes or failure */
freadi :: !*File -> (!Bool,!Int,!*File) :== code { .d 0 2 f ; jsr readFI ; .o 0 4 b i f }
/* Reads an Integer from a textfile by skipping spaces, tabs and newlines and
then reading digits, which may be preceeded by a plus or minus sign.
From a datafile freadi will just read four bytes (a Clean Int). */
freadr :: !*File -> (!Bool,!Real,!*File) :== code { .d 0 2 f ; jsr readFR ; .o 0 4 b r f }
/* Reads a Real from a textfile by skipping spaces, tabs and newlines and then
reading a character representation of a Real number.
From a datafile freadr will just read eight bytes (a Clean Real). */
freads :: ! *File !Int -> (!*{#Char},!*File) :== code { .d 0 3 f i ; jsr readFS ; .o 1 2 f }
/* Reads n characters from a text or data file, which are returned as a String.
If the file doesn't contain n characters the file will be read to the end
of the file. An empty String is returned if no characters can be read. */
freadsubstring :: !Int !Int !*{#Char} !*File -> (!Int,!*{#Char},!*File) :== code { .d 1 4 i i f ; jsr readFString ; .o 1 3 i f }
/*
Reads n characters from a text or data file, which are returned in the string
arg3 at positions arg1..arg1+arg2-1. If the file doesn't contain arg2 characters
the file will be read to the end of the file, and the part of the string arg3 that
could not be read will not be changed. The number of characters read, the modified
string and the file are returned.
*/
freadline :: !*File -> (!*{#Char},!*File) :== code { .d 0 2 f ; jsr readLineF ; .o 1 2 f }
/* Reads a line from a textfile. (including a newline character, except for the last
line) freadline cannot be used on data files. */
// Writing to a File:
fwritec :: !Char !*File -> *File :== code { .d 0 3 c f ; jsr writeFC ; .o 0 2 f }
/* Writes a character to a textfile.
To a datafile fwritec writes one byte (a Clean Char). */
fwritei :: !Int !*File -> *File :== code { .d 0 3 i f ; jsr writeFI ; .o 0 2 f }
/* Writes an Integer (its textual representation) to a text file.
To a datafile fwritei writes four bytes (a Clean Int). */
fwriter :: !Real !*File -> *File :== code { .d 0 3 r f ; jsr writeFR ; .o 0 2 f }
/* Writes a Real (its textual representation) to a text file.
To a datafile fwriter writes eight bytes (a Clean Real). */
fwrites :: !{#Char} !*File -> *File :== code { .d 1 2 f ; jsr writeFS ; .o 0 2 f }
/* Writes a String to a text or data file. */
fwritesubstring :: !Int !Int !{#Char} !*File -> *File :== code { .d 1 4 i i f ; jsr writeFString ; .o 0 2 f }
/* Writes the characters at positions arg1..arg1+arg2-1 of string arg3 to
a text or data file. */
class (<<<) infixl a :: !*File !a -> *File
/* Overloaded write to file */
instance <<< Int :: !*File !Int -> *File :== code { push_b 2 ; update_b 2 3 ; update_b 1 2 ; updatepop_b 0 1 ; .d 0 3 i f ; jsr writeFI ; .o 0 2 f }
instance <<< Char :: !*File !Char -> *File :== code { push_b 2 ; update_b 2 3 ; update_b 1 2 ; updatepop_b 0 1 ; .d 0 3 c f ; jsr writeFC ; .o 0 2 f }
instance <<< {#Char} :: !*File !{#Char} -> *File :== code { .d 1 2 f ; jsr writeFS ; .o 0 2 f }
instance <<< Real :: !*File !Real -> *File :== code { push_b 2 ; update_b 2 3 ; update_b 1 2 ; updatepop_b 0 1 ; .d 0 3 r f ; jsr writeFR ; .o 0 2 f }
// Testing:
fend :: !*File -> (!Bool,!*File) :== code { .d 0 2 f ; jsr endF ; .o 0 3 b f }
/* Tests for end-of-file. */
ferror :: !*File -> (!Bool,!*File) :== code { .d 0 2 f ; jsr errorF ; .o 0 3 b f }
/* Has an error occurred during previous file I/O operations? */
fposition :: !*File -> (!Int,!*File) :== code { .d 0 2 f ; jsr positionF ; .o 0 3 i f }
/* returns the current position of the file poInter as an Integer.
This position can be used later on for the fseek function. */
fseek :: !*File !Int !Int -> (!Bool,!*File) :== code { .d 0 4 f i i ; jsr seekF ; .o 0 3 b f }
/* Move to a different position in the file, the first Integer argument is the offset,
the second argument is a seek mode. (see above). True is returned if successful. */
// Predefined files.
stderr :: *File :== code { .d 0 0 ; jsr stderrF ; .o 0 2 f }
/* Open the 'Errors' file for writing only. May be opened more than once. */
// Opening and reading Shared Files:
sfreadc :: !File -> (!Bool,!Char,!File) :== code { .d 0 2 f ; jsr readSFC ; .o 0 4 b c f }
sfreadi :: !File -> (!Bool,!Int,!File) :== code { .d 0 2 f ; jsr readSFI ; .o 0 4 b i f }
sfreadr :: !File -> (!Bool,!Real,!File) :== code { .d 0 2 f ; jsr readSFR ; .o 0 4 b r f }
sfreads :: !File !Int -> (!*{#Char},!File) :== code { .d 0 3 f i ; jsr readSFS ; .o 1 2 f }
sfreadline :: !File -> (!*{#Char},!File) :== code { .d 0 2 f ; jsr readLineSF ; .o 1 2 f }
sfseek :: !File !Int !Int -> (!Bool,!File) :== code { .d 0 4 f i i ; jsr seekSF ; .o 0 3 b f }
sfend :: !File -> Bool :== code { .d 0 2 f ; jsr endSF ; .o 0 1 b }
sfposition :: !File -> Int :== code { .d 0 2 f ; jsr positionSF ; .o 0 1 i }
/* The functions sfend and sfposition work like fend and fposition, but don't return a
new file on which other operations can continue. They can be used for files opened
with sfopen or after fshare, and in guards for files opened with fopen or freopen. */
// Convert a *File into:
fshare :: !*File -> File :== code { .d 0 2 f ; jsr shareF ; .o 0 2 f }
/* Change a file so that from now it can only be used with sf... operations. */
fflush :: !*File -> (!Bool,!*File) :== code { .d 0 2 f ; jsr flushF ; .o 0 3 bf }
......@@ -112,46 +112,6 @@ sfopen_ s i
.o 0 3 b f
}
/*
openfiles::!*World -> (!*Files,!*World)
openfiles world
| (1 bitand w) == 0
= OpenFiles2 (StoreWorld (w bitor 1) world)
= abort "openfiles: This world doesn't contain files"
where w = LoadWorld world
OpenFiles2::!*World -> (!*Files,!*World)
OpenFiles2 w
= code inline {
pushI 0
}
LoadWorld :: !World -> Int;
LoadWorld w = code inline {
pushI_a 0
pop_a 1
};
StoreWorld :: !Int !World -> *World;
StoreWorld i w = code inline {
fillI_b 0 1
pop_b 1
pop_a 1
};
closefiles::!*Files !*World -> *World
closefiles f world
= CloseFiles2 f (StoreWorld ((LoadWorld world) bitand (-2)) world)
CloseFiles2::!*Files !*World -> *World
CloseFiles2 f w
= code inline {
pop_b 1
fill_a 0 1
pop_a 1
}
*/
freopen::!*File !Int -> (!Bool,!*File)
/* Re-opens an open file in a possibly different mode.
The boolean indicates whether the file was successfully closed before reopening. */
......@@ -215,12 +175,10 @@ freadsubstring :: !Int !Int !*{#Char} !*File -> (!Int,!*{#Char},!*File)
and the file are returned.
*/
freadsubstring i n s f
= code {
.inline freadsubstring
= code inline {
.d 1 4 i i f
jsr readFString
.o 1 3 i f
.end
}
freadline::!*File -> (!*{#Char},!*File)
......@@ -417,6 +375,7 @@ class (<<<) infixl a :: !*File !a -> *File
instance <<< Int where
// (<<<) file i = fwritei i file
(<<<) :: !*File !Int -> *File
(<<<) file i = code inline {
push_b 2
update_b 2 3
......@@ -430,6 +389,7 @@ instance <<< Int where
instance <<< Char where
// (<<<) file c = fwritec c file
(<<<) :: !*File !Char -> *File
(<<<) file c = code inline {
push_b 2
update_b 2 3
......@@ -443,6 +403,7 @@ instance <<< Char where
instance <<< {#Char} where
// (<<<) file s = fwrites s file
(<<<) :: !*File !{#Char} -> *File
(<<<) file s = code inline {
.d 1 2 f
jsr writeFS
......@@ -451,6 +412,7 @@ instance <<< {#Char} where
instance <<< Real where
// (<<<) file r = fwriter r file
(<<<) :: !*File !Real -> *File
(<<<) file r = code inline {
push_b 2
update_b 2 3
......@@ -481,10 +443,8 @@ instance FileEnv World where
appFiles :: !.(*Files -> *Files) !*World -> *World
appFiles appfun world
#! files1=create_files
// RWS ... #! files=appfun files
files=appfun files1
// .. RWS
#! files=create_files
files=appfun files
= do_files files world
where
do_files :: !*Files !*World -> *World
......
......@@ -7,52 +7,59 @@ system module StdInt
import StdOverloaded
instance + Int :: !Int !Int -> Int :== code { addI }
instance + Int
instance - Int :: !Int !Int -> Int :== code { subI }
instance - Int
instance zero Int :: Int :== code { pushI 0 }
instance zero Int
instance * Int
instance / Int
instance one Int
instance * Int :: !Int !Int -> Int :== code { mulI }
instance / Int :: !Int !Int -> Int :== code { divI }
instance one Int :: Int :== code { pushI 1 }
instance ^ Int
instance abs Int
instance sign Int
instance ~ Int
instance == Int
instance < Int
instance isEven Int // True if arg1 is an even number
instance isOdd Int // True if arg1 is an odd number
instance toInt Char
instance toInt Int
instance toInt Real
instance ~ Int :: !Int -> Int :== code { negI }
instance == Int :: !Int !Int -> Bool :== code { eqI }
instance < Int :: !Int !Int -> Bool :== code { ltI }
instance isEven Int :: !Int -> Bool :== code { pushI 1 ; and% ; pushI 0 ; eqI }
// True if arg1 is an even number
instance isOdd Int :: !Int -> Bool :== code { pushI 1 ; and% ; pushI 0 ; eqI ; notB }
// True if arg1 is an odd number
instance toInt Char :: !Char -> Int :== code { CtoI }
instance toInt Int :: !Int -> Int :== code { no_op }
instance toInt Real :: !Real -> Int :== code { RtoI }
instance toInt {#Char}
instance fromInt Int
instance fromInt Char
instance fromInt Real
instance fromInt {#Char}
instance fromInt Int :: !Int -> Int :== code { no_op }
instance fromInt Char :: !Int -> Char :== code { ItoC }
instance fromInt Real :: !Int -> Real :== code { ItoR }
instance fromInt {#Char} :: !Int -> {#Char} :== code { .d 0 1 i ; jsr ItoAC ; .o 1 0 }
// Additional functions for integer arithmetic:
instance rem Int // remainder after integer division
instance rem Int :: !Int !Int -> Int :== code { remI }
// remainder after integer division
instance gcd Int // Greatest common divider
instance lcm Int // Least common multiple
// Operators on Bits:
(bitor) infixl 6 :: !Int !Int -> Int // Bitwise Or of arg1 and arg2
(bitand) infixl 6 :: !Int !Int -> Int // Bitwise And of arg1 and arg2
(bitxor) infixl 6 :: !Int !Int -> Int // Exclusive-Or arg1 with mask arg2
(<<) infix 7 :: !Int !Int -> Int // Shift arg1 to the left arg2 bit places
(>>) infix 7 :: !Int !Int -> Int // Shift arg1 to the right arg2 bit places
bitnot :: !Int -> Int // One's complement of arg1
(bitor) infixl 6 :: !Int !Int -> Int :== code { or% }
// Bitwise Or of arg1 and arg2
(bitand) infixl 6 :: !Int !Int -> Int :== code { and% }
// Bitwise And of arg1 and arg2
(bitxor) infixl 6 :: !Int !Int -> Int :== code { xor% }
// Exclusive-Or arg1 with mask arg2
(<<) infix 7 :: !Int !Int -> Int :== code { shiftl% }
// Shift arg1 to the left arg2 bit places
(>>) infix 7 :: !Int !Int -> Int :== code { shiftr% }
// Shift arg1 to the right arg2 bit places
bitnot :: !Int -> Int :== code { not% }
// One's complement of arg1
IF_INT_64_OR_32 int64 int32 :== int64;
system module StdReal
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
import StdOverloaded
instance + Real :: !Real !Real -> Real :== code { addR }
instance - Real :: !Real !Real -> Real :== code { subR }
instance zero Real :: Real :== code { pushR 0.0 }
instance * Real :: !Real !Real -> Real :== code { mulR }
instance / Real :: !Real !Real -> Real :== code { divR }
instance one Real :: Real :== code { pushR 1.0 }
instance ^ Real :: !Real !Real -> Real :== code { powR }
instance abs Real :: !Real -> Real :== code { absR }
instance sign Real
instance ~ Real :: !Real -> Real :== code { negR}
instance == Real :: !Real !Real -> Bool :== code { eqR }
instance < Real :: !Real !Real -> Bool :== code { ltR }
instance toReal Int :: !Int -> Real :== code { ItoR }
instance toReal Real :: !Real -> Real :== code { no_op }
instance toReal {#Char}
instance fromReal Int :: !Real -> Int :== code { RtoI }
instance fromReal Real :: !Real -> Real :== code { no_op }
instance fromReal {#Char} :: !Real -> {#Char} :== code { .d 0 1 r ; jsr RtoAC ; .o 1 0 }
// Logarithmical Functions:
instance ln Real :: !Real -> Real :== code { lnR }
// Logarithm base e
instance log10 Real :: !Real -> Real :== code { log10R }
// Logarithm base 10
instance exp Real :: !Real -> Real :== code { expR }
// e to the power
instance sqrt Real :: !Real -> Real :== code { sqrtR }
// Square root
// Trigonometrical Functions:
instance sin Real :: !Real -> Real :== code { sinR }
// Sinus
instance cos Real :: !Real -> Real :== code { cosR }
// Cosinus
instance tan Real :: !Real -> Real :== code { tanR }
// Tangens
instance asin Real :: !Real -> Real :== code { asinR }
// Arc Sinus
instance acos Real :: !Real -> Real :== code { acosR }
// Arc Cosinus
instance atan Real :: !Real -> Real :== code { atanR }
// Arc Tangent
instance sinh Real // Hyperbolic Sine
instance cosh Real // Hyperbolic Cosine
instance tanh Real // Hyperbolic Tangent
instance asinh Real // Arc Hyperbolic Sine
instance acosh Real // Arc Hyperbolic Cosine, partial function, only defined if arg > 1.0
instance atanh Real // Arc Hyperbolic Tangent, partial function, only defined if -1.0 < arg < 1.0
// Additional conversion:
entier :: !Real -> Int :== code { entierR }
// Convert Real into Int by taking entier
Infinity :== 1E9999
NaN :== 1E9999+(-1E9999)
isNaN x :== if (x==x) False True
isInfinity x :== if (abs x==1E9999) True False
isFinite x :== if (x-x==0.0) True False
implementation module StdReal
// ********************************************************
// Concurrent Clean Standard Library Module Version 2.0
// Copyright 1998 University of Nijmegen
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ********************************************************
import StdClass
import StdOverloaded,StdInt,StdArray
......@@ -106,6 +106,7 @@ where
instance ln Real
where
ln :: !Real -> Real
ln a
= code inline {
lnR
......@@ -113,25 +114,31 @@ where
instance log10 Real
where
log10 :: !Real -> Real
log10 a
= code inline {
log10R
}
instance exp Real
where exp a
where
exp :: !Real -> Real
exp a
= code inline {
expR
}
instance sqrt Real
where sqrt a
where
sqrt :: !Real -> Real
sqrt a
= code inline {
sqrtR
}
instance sin Real
where
sin :: !Real -> Real
sin a
= code inline {
sinR
......@@ -139,13 +146,15 @@ where
instance cos Real
where
cos :: !Real -> Real
cos a
= code inline {
cosR
}
instance tan Real
where
where
tan :: !Real -> Real
tan a
= code inline {
tanR
......@@ -153,6 +162,7 @@ where
instance asin Real
where
asin :: !Real -> Real
asin a
= code inline {
asinR
......@@ -160,6 +170,7 @@ where
instance acos Real
where
acos :: !Real -> Real
acos a
= code inline {
acosR
......@@ -167,6 +178,7 @@ where
instance atan Real
where
atan :: !Real -> Real
atan a
= code inline {
atanR
......
system module StdString
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
import StdOverloaded
instance == {#Char} :: !{#Char} !{#Char} -> Bool :== code { .d 2 0 ; jsr eqAC ; .o 0 1 b }
instance < {#Char} :: !{#Char} !{#Char} -> Bool :== code { .d 2 0 ; jsr cmpAC ; .o 0 1 i ; pushI 0 ; gtI }
instance fromString {#Char} :: !{#Char} -> {#Char} :== code { no_op }
instance toString Int :: !Int -> {#Char} :== code { .d 0 1 i ; jsr ItoAC ; .o 1 0 }
instance toString Char :: !Char -> {#Char} :== code { CtoAC }
instance toString Real :: !Real -> {#Char} :== code { .d 0 1 r ; jsr RtoAC ; .o 1 0 }
instance toString Bool :: !Bool -> {#Char} :== code { .d 0 1 b ; jsr BtoAC ; .o 1 0 }
instance toString {#Char} :: !{#Char} -> {#Char} :== code { no_op }
instance % {#Char} :: !{#Char} !(!Int,!Int) -> {#Char} :== code { .d 1 2 ii ; jsr sliceAC ; .o 1 0 }
instance +++ {#Char} :: !{#Char} !{#Char} -> {#Char} :== code { .d 2 0 ; jsr catAC ; .o 1 0 }
// string concatenation
(+++.) infixr 5 :: !{#Char} !{#Char} -> .{#Char} :== code { .d 2 0 ; jsr catAC ; .o 1 0 }
// string concatenation with unique result
(:=) infixl 9 :: !{#Char} !(!Int,!Char) -> {#Char} :== code { .d 1 2 ic ; jsr updateAC ; .o 1 0 }
// update i-th element with char
implementation module StdString
// ****************************************************************************************
// Concurrent Clean Standard Library Module Version 2.0
// Copyright 1998 University of Nijmegen
// Concurrent Clean Standard Library Module Version 3.0
// Copyright 2019 University of Nijmegen
// ****************************************************************************************
import StdOverloaded
......@@ -31,6 +31,7 @@ where
instance toString Int
where
toString :: !Int -> {#Char}
toString a
= code inline {
.d 0 1 i
......@@ -40,6 +41,7 @@ where
instance toString Char
where
toString :: !Char -> {#Char}
toString a