From: Brendan Hansen Date: Thu, 4 Mar 2021 00:51:25 +0000 (-0600) Subject: bug fixes; added 'map.get_ptr' X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=b70dda05578fb665fd175edbba291895d7754514;p=onyx.git bug fixes; added 'map.get_ptr' --- diff --git a/build.sh b/build.sh index 40b6533e..07fbeb47 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,12 @@ #!/bin/sh +echo "Installing core libs" +CORE_DIR='/usr/share/onyx' +sudo mkdir -p "$CORE_DIR" +sudo cp -r ./core/ "$CORE_DIR" + +[ "$1" = "libs_only" ] && exit 0 + C_FILES="onyx onyxastnodes onyxbuiltins onyxchecker onyxclone onyxdoc onyxentities onyxerrors onyxlex onyxparser onyxsymres onyxtypes onyxutils onyxwasm" TARGET='./bin/onyx' CC='gcc' @@ -30,10 +37,5 @@ echo "Installing onyx executable" BIN_DIR='/usr/bin' sudo cp ./bin/onyx "$BIN_DIR/onyx" -echo "Installing core libs" -CORE_DIR='/usr/share/onyx' -sudo mkdir -p "$CORE_DIR" -sudo cp -r ./core/ "$CORE_DIR" - # Otherwise the prompt ends on the same line -printf "\n" \ No newline at end of file +printf "\n" diff --git a/core/builtin.onyx b/core/builtin.onyx index 9323fe01..2cb9c2a9 100644 --- a/core/builtin.onyx +++ b/core/builtin.onyx @@ -107,7 +107,7 @@ use package build_opts as build_opts use package core.intrinsics.wasm { __initialize } new :: ($T: type_expr, allocator := context.allocator, initialize := true) -> ^T { - res := cast(^T) calloc(sizeof T); + res := cast(^T) raw_alloc(allocator, sizeof T); // @Robustness: This should be a '#if' when those are added in procedures because // otherwise the __initialize intrinsic is going to be generated no matter what. diff --git a/core/map.onyx b/core/map.onyx index 42a293cf..9c588706 100644 --- a/core/map.onyx +++ b/core/map.onyx @@ -68,6 +68,13 @@ get :: (use map: ^Map($K, $V), key: K) -> V { return default_value; } +get_ptr :: (use map: ^Map($K, $V), key: K) -> ^V { + lr := lookup(map, key); + if lr.entry_index >= 0 do return ^entries[lr.entry_index].value; + + return null; +} + delete :: (use map: ^Map($K, $V), key: K) { lr := lookup(map, key); if lr.entry_index < 0 do return;