added: docs and tiny performance improvements
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Jun 2023 01:08:05 +0000 (20:08 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 19 Jun 2023 01:08:05 +0000 (20:08 -0500)
core/os/path.onyx
interpreter/src/vm/code_builder.c
tests/left_to_right_order [new file with mode: 0644]
tests/left_to_right_order.onyx [new file with mode: 0644]

index d0d8312bf8a144024f5b6008ced84378e5d2b843..9d540d90ac716421ecb0b8e72b957576e51a08a1 100644 (file)
@@ -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];
index 41cb2a4850716f3162243cf7dc9ad20a679e4b83..20c99658eaa5e2095297cbb6a2e50891de8472bf 100644 (file)
@@ -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 (file)
index 0000000..fdb417f
--- /dev/null
@@ -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 (file)
index 0000000..24946f3
--- /dev/null
@@ -0,0 +1,10 @@
+
+use core {*}
+
+main :: () {
+    a := 1;
+    b := a + do { a += 1; return a; };
+    printf("{} == 3\n", b);
+}
+
+