From bfcdb4217ee4141c389405188b89d697d5ef55bc Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sun, 18 Jun 2023 20:08:05 -0500 Subject: [PATCH] added: docs and tiny performance improvements --- core/os/path.onyx | 16 ++++++++++++++++ interpreter/src/vm/code_builder.c | 24 +++++------------------- tests/left_to_right_order | 1 + tests/left_to_right_order.onyx | 10 ++++++++++ 4 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 tests/left_to_right_order create mode 100644 tests/left_to_right_order.onyx diff --git a/core/os/path.onyx b/core/os/path.onyx index d0d8312b..9d540d90 100644 --- a/core/os/path.onyx +++ b/core/os/path.onyx @@ -98,6 +98,13 @@ path_directory :: (path: str) -> str { return path_clean(dir); } +#doc """ + Returns the extension of the file on the end of the path, if present. + + path_extension("foo.txt") -> "txt" + path_extension("foo/bar") -> "" + path_extension("foo/bar.txt") -> "txt" +""" path_extension :: (path: str) -> str { for i: range.{ path.length - 1, 0, -1 } { if path[i] == '/' do break; @@ -106,6 +113,12 @@ path_extension :: (path: str) -> str { return ""; } +#doc """ + Returns the last element of the path, sans its extension. + + path_basename("foo.txt") -> "foo" + path_basename("test/bar.txt") -> "bar" +""" path_basename :: (path: str) -> str { if path == "" do return "."; @@ -114,6 +127,9 @@ path_basename :: (path: str) -> str { return path[start + 1 .. end]; } +#doc """ + Splits the last path element off. +""" path_split :: (path: str) -> (parent: str, child: str) { index := string.last_index_of(path, PATH_SEP); return path[0 .. index], path[index+1 .. path.length]; diff --git a/interpreter/src/vm/code_builder.c b/interpreter/src/vm/code_builder.c index 41cb2a48..20c99658 100644 --- a/interpreter/src/vm/code_builder.c +++ b/interpreter/src/vm/code_builder.c @@ -433,25 +433,11 @@ void ovm_code_builder_add_local_set(ovm_code_builder_t *builder, i32 local_idx) maybe_copy_register_if_going_to_be_replaced(builder, local_idx); // :PrimitiveOptimization - // Perform a simple optimization that an immediate temporary moved to - // a local can be optimized as an immediate loaded directly to a local. - { - ovm_instr_t *last_instr = &bh_arr_last(builder->program->code); - if (OVM_INSTR_INSTR(*last_instr) == OVMI_IMM) { - if (IS_TEMPORARY_VALUE(builder, last_instr->r) && last_instr->r == LAST_VALUE(builder)) { - last_instr->r = local_idx; - POP_VALUE(builder); - return; - } - } - - if (OVM_INSTR_INSTR(*last_instr) == OVMI_REG_GET) { - if (IS_TEMPORARY_VALUE(builder, last_instr->r) && last_instr->r == LAST_VALUE(builder)) { - last_instr->r = local_idx; - POP_VALUE(builder); - return; - } - } + ovm_instr_t *last_instr = &bh_arr_last(builder->program->code); + if (IS_TEMPORARY_VALUE(builder, last_instr->r) && last_instr->r == LAST_VALUE(builder)) { + last_instr->r = local_idx; + POP_VALUE(builder); + return; } ovm_instr_t instr = {0}; diff --git a/tests/left_to_right_order b/tests/left_to_right_order new file mode 100644 index 00000000..fdb417f1 --- /dev/null +++ b/tests/left_to_right_order @@ -0,0 +1 @@ +3 == 3 diff --git a/tests/left_to_right_order.onyx b/tests/left_to_right_order.onyx new file mode 100644 index 00000000..24946f34 --- /dev/null +++ b/tests/left_to_right_order.onyx @@ -0,0 +1,10 @@ + +use core {*} + +main :: () { + a := 1; + b := a + do { a += 1; return a; }; + printf("{} == 3\n", b); +} + + -- 2.25.1