Commit 41608b8e authored by Tim Steenvoorden's avatar Tim Steenvoorden
Browse files

experiment with internal array modules

parent 122a3494
system module Data.File
//TODO change `prim_` prefix to just `_` and move to internal module.
/// # Files
// :: File
// BUILTIN
/// # Operations
/// ## Opening and Closing
prim_openFile :: !String !Int -> (!Bool,!*File)
prim_closeFile :: !*File -> Bool
prim_reopenFile :: !*File !Int -> (!Bool,!*File)
/// ## Standard IO
prim_stdio :: *File
prim_stderr :: *File
/// ## Seeking
prim_positionFile :: !*File -> (!Int,!*File)
prim_seekFile :: !*File !Int !Int -> (!Bool,!*File)
/// ## Tests
prim_isEndOfFile :: !*File -> (!Bool,!*File)
prim_isErrorFile :: !*File -> (!Bool,!*File)
/// ## Reading
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)
/// ## Writing
prim_writeCharFile :: !Char !*File -> *File
prim_writeIntFile :: !Int !*File -> *File
prim_writeRealFile :: !Real !*File -> *File
prim_writeStringFile :: !String !*File -> *File
system module _DataArrayInternal
from Data.Nat import :: Nat
/// # Overloading
class Array .a e where
// creation
array :: !Nat e -> *(a e)
_array :: !Nat -> *(a .e)
// a.size and a!size TODO add syntax
size :: !.(a .e) -> Nat
usize :: !u:(a .e) -> *(!Nat, !u:(a .e))
// a.[i] and a![i]
select :: !.(a .e) !Nat -> .e
uselect :: !u:(a e) !Nat -> *(e, !u:(a e))
// a.[i..<j] and a![i..<j] TODO add syntax
slice :: !.(a .e) !Nat !Nat -> .(a .e)
uslice :: !u:(a .e) !Nat !Nat -> *(.(a .e), !u:(a .e))
// a.[i] = e
update :: !*(a .e) !Nat .e -> *(a .e)
replace :: !*(a .e) !Nat .e -> *(.e, !*(a .e))
// efficient array operations
concat :: !.(a .e) !.(a .e) -> .(a .e)
compare :: !.(a .e) !.(a .e) -> Bool
//FIXME change name in compiler?
createArray x y :== array x y
_createArray x :== _array x
instance Array {} a
implementation module _DataArrayInternal
/// # Overloading
instance Array {} a where
array size el = code inline {
create_array _ 1 0
}
_array size = code inline {
create_array_ _ 1 0
}
size arr = code inline {
push_arraysize _ 1 0
}
usize arr = code inline {
push_a 0
push_arraysize _ 1 0
}
select arr index = code inline {
select _ 1 0
jsr_eval 0
}
uselect arr index = code inline {
push_a 0
select _ 1 0
}
// slice arr lower upper = undefined
// uslice arr lower upper = undefined
update arr index el = code inline {
update _ 1 0
}
replace arr index el = code inline {
replace _ 1 0
}
system module _DataArrayStrictInternal
import _DataArrayInternal
/// # Overloading
instance Array {!} a
implementation module _DataArrayStrictInternal
import _DataArrayInternal
/// # Overloading
instance Array {!} a where
array size el = code inline {
create_array _ 1 0
}
_array size = code inline {
create_array_ _ 1 0
}
select arr index = code inline {
select _ 1 0
}
uselect arr index = code inline {
push_a 0
select _ 1 0
}
size arr = code inline {
push_arraysize _ 1 0
}
usize arr = code inline {
push_a 0
push_arraysize _ 1 0
}
update arr index el = code inline {
update _ 1 0
}
replace arr index el = code inline {
replace _ 1 0
}
system module _DataArrayUnboxedInternal
import _DataArrayInternal
/// # Overloading
instance Array {#} Bool
instance Array {#} Char
// instance Array {#} Nat
instance Array {#} Int
instance Array {#} Real
instance Array {#} {#.a}
instance Array {#} {!.a}
instance Array {#} {.a}
instance Array {#} a
implementation module _DataArrayUnboxedInternal
import _DataArrayInternal
/// # Overloading
instance Array {#} Bool where
array size el = code inline {
create_array BOOL 0 1
}
_array size = code inline {
create_array_ BOOL 0 1
}
select arr index = code inline {
select BOOL 0 1
}
uselect arr index = code inline {
push_a 0
select BOOL 0 1
}
size arr = code inline {
push_arraysize BOOL 0 1
}
usize arr = code inline {
push_a 0
push_arraysize BOOL 0 1
}
update arr index el = code inline {
update BOOL 0 1
}
replace arr index el = code inline {
replace BOOL 0 1
}
instance Array {#} Char where
array size el = code inline {
create_array CHAR 0 1
}
_array size = code inline {
create_array_ CHAR 0 1
}
select arr index = code inline {
select CHAR 0 1
}
uselect arr index = code inline {
push_a 0
select CHAR 0 1
}
slice arr lower upper = code inline {
.d 1 2 i i
jsr sliceAC
.o 1 0
}
size arr = code inline {
push_arraysize CHAR 0 1
}
usize arr = code inline {
push_a 0
push_arraysize CHAR 0 1
}
update arr index el = code inline {
update CHAR 0 1
}
replace arr index el = code inline {
replace CHAR 0 1
}
concat arr1 arr2 = code inline {
.d 2 0
jsr catAC
.o 1 0
}
compare arr1 arr2 = code inline {
.d 2 0
jsr cmpAC
.o 0 1 i
}
instance Array {#} Int where
array size el = code inline {
create_array INT 0 1
}
_array size = code inline {
create_array_ INT 0 1
}
select arr index = code inline {
select INT 0 1
}
uselect arr index = code inline {
push_a 0
select INT 0 1
}
size arr = code inline {
push_arraysize INT 0 1
}
usize arr = code inline {
push_a 0
push_arraysize INT 0 1
}
update arr index el = code inline {
update INT 0 1
}
replace arr index el = code inline {
replace INT 0 1
}
instance Array {#} Real where
array size el = code inline {
create_array REAL 0 1
}
_array size = code inline {
create_array_ REAL 0 1
}
select arr index = code inline {
select REAL 0 1
}
uselect arr index = code inline {
push_a 0
select REAL 0 1
}
size arr = code inline {
push_arraysize REAL 0 1
}
usize arr = code inline {
push_a 0
push_arraysize REAL 0 1
}
update arr index el = code inline {
update REAL 0 1
}
replace arr index el = code inline {
replace REAL 0 1
}
instance Array {#} {#.a} where
array size el = code inline {
create_array _ 1 0
}
_array size = code inline {
create_array_ _ 1 0
}
select arr index = code inline {
select _ 1 0
}
uselect arr index = code inline {
push_a 0
select _ 1 0
}
size arr = code inline {
push_arraysize _ 1 0
}
usize arr = code inline {
push_a 0
push_arraysize _ 1 0
}
update arr index el = code inline {
update _ 1 0
}
replace arr index el = code inline {
replace _ 1 0
}
instance Array {#} {!.a} where
array size el = code inline {
create_array _ 1 0
}
_array size = code inline {
create_array_ _ 1 0
}
select arr index = code inline {
select _ 1 0
}
uselect arr index = code inline {
push_a 0
select _ 1 0
}
size arr = code inline {
push_arraysize _ 1 0
}
usize arr = code inline {
push_a 0
push_arraysize _ 1 0
}
update arr index el = code inline {
update _ 1 0
}
replace arr index el = code inline {
replace _ 1 0
}
instance Array {#} {.a} where
array size el = code inline {
create_array _ 1 0
}
_array size = code inline {
create_array_ _ 1 0
}
select arr index = code inline {
select _ 1 0
}
uselect arr index = code inline {
push_a 0
select _ 1 0
}
size arr = code inline {
push_arraysize _ 1 0
}
usize arr = code inline {
push_a 0
push_arraysize _ 1 0
}
update arr index el = code inline {
update _ 1 0
}
replace arr index el = code inline {
replace _ 1 0
}
instance Array {#} a where
array size el = code inline {
buildAC "Data.Array.Unboxed.array: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
_array size = code inline {
buildAC "Data.Array.Unboxed._array: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
select arr index = code inline {
buildAC "Data.Array.Unboxed.select: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
uselect arr index = code inline {
buildAC "Data.Array.Unboxed.uselect: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
size arr = code inline {
buildAC "Data.Array.Unboxed.size: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
usize arr = code inline {
buildAC "Data.Array.Unboxed.usize: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
update arr index el = code inline {
buildAC "Data.Array.Unboxed.update: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
replace arr index el = code inline {
buildAC "Data.Array.Unboxed.replace: should not be called for unknown basic type"
.d 1 0
jsr print_string_
.o 0 0
halt
}
definition module Clean._Enum
from Data.Enum import class Enum(enumFrom, enumFromTo, enumFromThen, enumFromThenTo)
/*
This module must be imported if dotdot expressions are used
[from .. ] -> _from from
[from .. to] -> _from_to from to
[from, then .. ] -> _from_then from then
[from, then .. to] -> _from_then_to from then to
*/
//FIXME doesn't print right...
_from x :== enumFrom x
_from_to x y :== enumFromTo x y
_from_then x y :== enumFromThen x y
_from_then_to x y z :== enumFromThenTo x y z
implementation module Clean._Enum
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