From fa92a157746ae17f295d31b7a047dfeb99624a13 Mon Sep 17 00:00:00 2001 From: Baitinq Date: Wed, 11 Jun 2025 00:16:17 +0200 Subject: Misc: Rename lang --- std/mem.pry | 29 ++++++++++++++++++++ std/mem.src | 29 -------------------- std/stdlib.pry | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ std/stdlib.src | 83 ---------------------------------------------------------- 4 files changed, 112 insertions(+), 112 deletions(-) create mode 100644 std/mem.pry delete mode 100644 std/mem.src create mode 100644 std/stdlib.pry delete mode 100644 std/stdlib.src (limited to 'std') diff --git a/std/mem.pry b/std/mem.pry new file mode 100644 index 0000000..75f3d1d --- /dev/null +++ b/std/mem.pry @@ -0,0 +1,29 @@ +extern calloc = (i64, i64) => *void; +extern realloc = (*void, i64) => *void; +extern free = (*void) => void; + +import "!stdlib.pry"; + +let arena = struct { + buf: *void, + offset: i64, +}; + +let arena_init = (size: i64) => *arena { + let a = cast(*arena, calloc(1, sizeof(arena))); + (*a).buf = calloc(1, size); + (*a).offset = 0; + return a; +}; + +let arena_free = (a: *arena) => void { + free((*a).buf); + free(cast(*void, a)); + return; +}; + +let arena_alloc = (a: *arena, size: i64) => *void { + let old_offset = (*a).offset; + (*a).offset = (*a).offset + size; + return cast(*void, cast(*i8, (*a).buf) + cast(*i8, old_offset)); +}; diff --git a/std/mem.src b/std/mem.src deleted file mode 100644 index 3bb1a0a..0000000 --- a/std/mem.src +++ /dev/null @@ -1,29 +0,0 @@ -extern calloc = (i64, i64) => *void; -extern realloc = (*void, i64) => *void; -extern free = (*void) => void; - -import "!stdlib.src"; - -let arena = struct { - buf: *void, - offset: i64, -}; - -let arena_init = (size: i64) => *arena { - let a = cast(*arena, calloc(1, sizeof(arena))); - (*a).buf = calloc(1, size); - (*a).offset = 0; - return a; -}; - -let arena_free = (a: *arena) => void { - free((*a).buf); - free(cast(*void, a)); - return; -}; - -let arena_alloc = (a: *arena, size: i64) => *void { - let old_offset = (*a).offset; - (*a).offset = (*a).offset + size; - return cast(*void, cast(*i8, (*a).buf) + cast(*i8, old_offset)); -}; diff --git a/std/stdlib.pry b/std/stdlib.pry new file mode 100644 index 0000000..aecd4df --- /dev/null +++ b/std/stdlib.pry @@ -0,0 +1,83 @@ +extern printf = (*i8, varargs) => void; +extern exit = (i64) => void; + +let strcmp = (stra: *i8, strb: *i8) => bool { + let i = 0; + while true { + let ca = (*(stra + cast(*i8, i))); + let cb = (*(strb + cast(*i8, i))); + + if ca == '\0' { + return cb == '\0'; + }; + + if cb == '\0' { + return ca == '\0'; + }; + + if !(ca == cb) { + return false; + }; + + i = i + 1; + }; + + return true; +}; + +let isdigit = (c: i8) => bool { + if c >= '0' { + if c <= '9' { + return true; + }; + }; + return false; +}; + +let isalpha = (c: i8) => bool { + if c >= 'a' { + if c <= 'z' { + return true; + }; + }; + if c >= 'A' { + if c <= 'Z' { + return true; + }; + }; + return false; +}; + +let isalphanum = (c: i8) => bool { + if isalpha(c) { + return true; + }; + if isdigit(c) { + return true; + }; + + return false; +}; + +let iswhitespace = (c: i8) => bool { + if c == ' ' { + return true; + }; + + if c >= '\t' { + if c <= '\r' { + return true; + }; + }; + + return false; +}; + +let assert = (cond: bool) => void { + if !cond { + printf("ASSERTION FAILED\n"); + exit(1); + }; + + return; +}; diff --git a/std/stdlib.src b/std/stdlib.src deleted file mode 100644 index aecd4df..0000000 --- a/std/stdlib.src +++ /dev/null @@ -1,83 +0,0 @@ -extern printf = (*i8, varargs) => void; -extern exit = (i64) => void; - -let strcmp = (stra: *i8, strb: *i8) => bool { - let i = 0; - while true { - let ca = (*(stra + cast(*i8, i))); - let cb = (*(strb + cast(*i8, i))); - - if ca == '\0' { - return cb == '\0'; - }; - - if cb == '\0' { - return ca == '\0'; - }; - - if !(ca == cb) { - return false; - }; - - i = i + 1; - }; - - return true; -}; - -let isdigit = (c: i8) => bool { - if c >= '0' { - if c <= '9' { - return true; - }; - }; - return false; -}; - -let isalpha = (c: i8) => bool { - if c >= 'a' { - if c <= 'z' { - return true; - }; - }; - if c >= 'A' { - if c <= 'Z' { - return true; - }; - }; - return false; -}; - -let isalphanum = (c: i8) => bool { - if isalpha(c) { - return true; - }; - if isdigit(c) { - return true; - }; - - return false; -}; - -let iswhitespace = (c: i8) => bool { - if c == ' ' { - return true; - }; - - if c >= '\t' { - if c <= '\r' { - return true; - }; - }; - - return false; -}; - -let assert = (cond: bool) => void { - if !cond { - printf("ASSERTION FAILED\n"); - exit(1); - }; - - return; -}; -- cgit 1.4.1