Added directfs

Added a very rudimentary file I/O system suitable for experimenting
with the language further. A better one will be designed when we have
sensible error management.
This commit is contained in:
2023-09-17 16:37:39 +01:00
parent 1078835e8b
commit 7396078304
84 changed files with 563 additions and 721 deletions

View File

@@ -125,7 +125,7 @@ expr=x in
)?
}
let (asl, bsl) = bin.0.split_at(i as usize);
Ok(tuple(vec![
Ok(tuple([
Binary(Arc::new(asl.to_vec())).atom_cls().into(),
Binary(Arc::new(bsl.to_vec())).atom_cls().into(),
]))

View File

@@ -1,13 +1,17 @@
import super::(option, fn::*, proc::*, loop::*, bool::*, known::*, num::*)
import super::(option, fn::*, proc::*, loop::*, bool::*, known::*, num::*, tuple::*)
const pair := \a.\b. \f. f a b
-- Constructors
export const cons := \hd.\tl. option::some (pair hd tl)
export const cons := \hd.\tl. option::some t[hd, tl]
export const end := option::none
export const pop := \list.\default.\f.list default \cons.cons f
export const pop := \list.\default.\f. do{
cps tuple = list default;
cps head, tail = tuple;
f head tail
}
-- Operators
@@ -100,6 +104,25 @@ export const get := \list.\n. (
}
)
--[
Map every element to a pair of the index and the original element
]--
export const enumerate := \list. (
recursive r (list, n = 0)
pop list end \head.\tail.
cons t[n, head] $ r tail $ n + 1
)
--[
Turn a list of CPS commands into a sequence. This is achieved by calling every
element on the return value of the next element with the tail passed to it.
The continuation is passed to the very last argument.
]--
export const chain := \list.\cont. loop_over (list) {
cps head, list = pop list cont;
cps head;
}
macro new[...$item, ...$rest:1] =0x2p84=> (cons (...$item) new[...$rest])
macro new[...$end] =0x1p84=> (cons (...$end) end)
macro new[] =0x1p84=> end

View File

@@ -1,7 +1,7 @@
export operators[ + - * % / ]
macro ...$a + ...$b =0x2p36=> (add (...$a) (...$b))
macro ...$a - ...$b:1 =0x2p36=> (subtract (...$a) (...$b))
macro ...$a:1 - ...$b =0x2p36=> (subtract (...$a) (...$b))
macro ...$a * ...$b =0x1p36=> (multiply (...$a) (...$b))
macro ...$a % ...$b:1 =0x1p36=> (remainder (...$a) (...$b))
macro ...$a / ...$b:1 =0x1p36=> (divide (...$a) (...$b))
macro ...$a:1 % ...$b =0x1p36=> (remainder (...$a) (...$b))
macro ...$a:1 / ...$b =0x1p36=> (divide (...$a) (...$b))

View File

@@ -6,10 +6,13 @@ import std::bool::*
export ::([==], if, then, else, true, false)
import std::fn::*
export ::([$ |> =>], identity, pass, pass2, return)
import std::tuple::*
export ::(t)
import std::tuple
import std::list
import std::map
import std::option
export ::(list, map, option)
export ::(tuple, list, map, option)
import std::loop::*
export ::(loop_over, recursive)

View File

@@ -65,7 +65,7 @@ expr=x in
let mut graphs = s.as_str().graphemes(true);
let a = graphs.by_ref().take(i as usize).collect::<String>();
let b = graphs.collect::<String>();
Ok(tuple(vec![a.into(), b.into()]))
Ok(tuple([a.into(), b.into()]))
}
}

16
src/systems/stl/tuple.orc Normal file
View File

@@ -0,0 +1,16 @@
import super::(known::*, bool::*, num::*)
const discard_args := \n.\value. (
if n == 0 then value
else \_. discard_args (n - 1) value
)
export const pick := \tuple. \i.\n. tuple (
discard_args i \val. discard_args (n - 1 - i) val
)
macro t[...$item, ...$rest:1] =0x2p84=> (\f. t[...$rest] (f (...$item)))
macro t[...$end] =0x1p84=> (\f. f (...$end))
macro t[] =0x1p84=> \f.f
export ::(t)