aboutsummaryrefslogtreecommitdiff
path: root/source/std.elna
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-11-14 23:39:52 +0100
committerEugen Wissner <belka@caraus.de>2026-11-14 23:39:52 +0100
commit9b4b13e0d9030bb21c86eea6c4ba00bf4d91f0a0 (patch)
treedd1c8fa2336b098d6380e579125d01ac8711a3c6 /source/std.elna
parent7ab6e1021611cc6913ee4ab5faf1b31f928a65e9 (diff)
downloadelna-9b4b13e0d9030bb21c86eea6c4ba00bf4d91f0a0.tar.gz
Add arity check for generic parameters
Diffstat (limited to 'source/std.elna')
-rw-r--r--source/std.elna62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/std.elna b/source/std.elna
index c028b93..98fb35d 100644
--- a/source/std.elna
+++ b/source/std.elna
@@ -3,12 +3,74 @@
obtain one at https://mozilla.org/MPL/2.0/. *)
module
+import sys.posix.stdlib
+
type
StdString* = []const Word8
+ (*
+ Stores a nullable pointer.
+
+ An empty StdOptional can created by just using the default initializer.
+ std_optional_make should be used to create an StdOptional holding a pointer.
+
+ @param T Pointer target type.
+ *)
StdOptional#[T]* = record
has_value: Bool;
value: ^T
end
+ (*
+ Initializes a sinlgy-linked list.
+
+ @param T List element type.
+ *)
+ StdSListNode#[T]* = record
+ next: ^StdSListNode#[T];
+ value: ^T
+ end
+ (*
+ Singly-linked list.
+
+ @param T List element type.
+ *)
+ StdSList#[T]* = record
+ head: StdOptional#[StdSListNode#[T]];
+ tail: ^StdSListNode#[T]
+ end
+
+(*
+ Inserts a new element into the list.
+
+ @param list List.
+ @param element Element to insert.
+*)
+proc std_slist_append#[T]*(list: ^StdSList#[T]; element: ^T)
+var
+ node := malloc#[StdSListNode#[T]](#size(StdSListNode#[T]))
+begin
+ node^.value := element;
+
+ if list^.head.has_value then
+ node^.next := list^.head.value;
+
+ list^.tail^.next := node;
+ list^.tail := node
+ else
+ node^.next := node;
+
+ list^.head := std_optional_make(node);
+ list^.tail := node
+ end
+return
+
+(*
+ Tells whether the list is empty.
+
+ @param list List to exemine.
+ @return Whether the provided list is empty.
+*)
+proc std_slist_empty#[T]*(list: ^StdSList#[T]) -> Bool
+return ~list^.head.has_value
(*
Constructs an optional holding the pointer value.