diff options
| author | Eugen Wissner <belka@caraus.de> | 2026-02-15 04:10:38 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2026-02-15 04:10:38 +0100 |
| commit | 5959fbb5524bbeb05a96eb15aba59e961a3efcb7 (patch) | |
| tree | 811be9bb8fba9bec6ae549c50f9cf92000b259c9 /source/common.elna | |
| download | elna-5959fbb5524bbeb05a96eb15aba59e961a3efcb7.tar.gz | |
Initial commit
Diffstat (limited to 'source/common.elna')
| -rw-r--r-- | source/common.elna | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/source/common.elna b/source/common.elna new file mode 100644 index 0000000..e7b30ca --- /dev/null +++ b/source/common.elna @@ -0,0 +1,72 @@ +(* 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 cstring, cstdio; + +type + Identifier = [256]Char; + TextLocation* = record + line: Word; + column: Word + end; + +proc write*(fd: Int, buf: Pointer, Word: Int) -> Int; extern; + +proc write_s*(value: String); +begin + (* fwrite(cast(value.ptr: Pointer), value.length, 1u, stdout) *) + write(1, cast(value.ptr: Pointer), cast(value.length: Int)) +end; + +proc write_z*(value: ^Char); +begin + write(1, cast(value: Pointer), cast(strlen(value): Int)) +end; + +proc write_b*(value: Bool); +begin + if value then + write_s("true") + else + write_s("false") + end +end; + +proc write_c*(value: Char); +begin + putchar(cast(value: Int)); + fflush(nil) +end; + +proc write_i*(value: Int); +var + digit: Int; + n: Word; + buffer: [10]Char; +begin + n := 10u; + + if value = 0 then + write_c('0') + end; + while value <> 0 do + digit := value % 10; + value := value / 10; + + buffer[n] := cast(cast('0': Int) + digit: Char); + n := n - 1u + end; + while n < 10u do + n := n + 1u; + write_c(buffer[n]) + end +end; + +proc write_u*(value: Word); +begin + write_i(cast(value: Int)) +end; + +end. |
