(* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can 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. @param value Initial optional value. @return Constructed optional. *) proc std_optional_make#[T]*(value: ^T) -> StdOptional#[T] return { StdOptional#[T]; has_value: true, value: value } end.