bugfixes and fixed spelling of "polymoprhic"
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 23 Aug 2021 20:24:01 +0000 (15:24 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Mon, 23 Aug 2021 20:24:01 +0000 (15:24 -0500)
CHANGELOG
bin/onyx
core/io/file.onyx
core/math.onyx
core/stdio.onyx
docs/todo
modules/ui/ui.onyx
src/onyxclone.c
src/onyxutils.c
src/onyxwasm.c
tests/lazy_iterators.onyx

index d7217c3f46130a52204dc9bf864d5691b67af04d..c99f480678e4a016f1547f858b059d420789f1f3 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -51,7 +51,7 @@ Additions:
     it will work on many systems. ARM / PowerPC may not work correctly.
 * procedures can be polymorphic on an array size.
 * structures can be polymorphic on any compile-time known value.
-* procedures can be polymoprhic on any compile-time known value, including type expressions.
+* procedures can be polymorphic on any compile-time known value, including type expressions.
 * basics of operator overloading using `#operator +`.
 * multiple return values and multiple assignment / declarations.
 * #solidify directive for explicitly specifying type variables in polymorphic procs.
@@ -74,7 +74,7 @@ Changes:
     value, but one that was still computed at the assignment site. Now, they instead are used to
     declare top level expressions in the procedure scope. This means that things like structs and
     enums can be declared at any block scope. The top-level expressions currently do not have
-    access to polymoprhic variables in the procedure.
+    access to polymorphic variables in the procedure.
 * `#include_file` is now `#load` and `#include_folder` is now `#load_path`. I like the shorter names.
 * enum values are compile time known.
 * struct literals are compile time known can be used at top level scope.
@@ -176,7 +176,7 @@ Changes:
 Bug fixes:
 * many bugs related to var args and procedure calls in general.
 * polymorphic structs caused segmentation fault when trying to produce an error message.
-* polymorhpic structs caused scope to change when using a struct literal of a polymoprhic type.
+* polymorhpic structs caused scope to change when using a struct literal of a polymorphic type.
 * #char "\"" did not work.
 * nested function calls returning non-basic types would simply be wrong.
 * Recursive structs are no longer possible.
index 1873432ac0305919d7fd731d517657bdf0ed8bd2..4c0e4e12d2606c9c3ad36d494ee7a2153cedf581 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 5d250d817d31de34a4640b97b3a5ab1f04917ab2..1bd7f76bacf647737d4e7f2d127d0193d852aae9 100644 (file)
@@ -180,6 +180,11 @@ open :: (path: str, mode := OpenMode.Read) -> (Error, FileStream) {
     return .None, fs;
 }
 
+close :: (file: ^FileStream) {
+    file_close(file.file);
+    file.stream.vtable = null;
+}
+
 #private
 file_stream_vtable := Stream_Vtable.{
     seek = (use fs: ^FileStream, to: i32, whence: SeekFrom) -> Error {
index 054738fef5eb2788462340f83980c3cc4484c1b6..2886c730f0b6ad5f773dc55855d7149289da3284 100644 (file)
@@ -223,7 +223,7 @@ log :: (a: $T, base: $R) -> T {
 
 
 // These function are overloaded in order to use the builtin WASM intrinsics for the
-// operation first, and then default to a polymoprhic function that works on any type.
+// operation first, and then default to a polymorphic function that works on any type.
 // The clunky part about these at the moment is that, if you wanted to pass 'max' to
 // a procedure, you would have to pass 'max_poly' instead, because overloaded functions
 // are not resolved when used by value, i.e. foo : (f32, f32) -> f32 = math.max; Even if
index a28e47354e2a923d815b585e67d9be244387a68a..9891061baf58a79899c29ad0600d889bdc77e100 100644 (file)
@@ -20,11 +20,11 @@ print :: #match {
         if x[x.count - 1] == #char "\n" && auto_flush_stdio do __flush_stdio();
     },
 
-    (x: $T)        { io.write(^stdio.print_writer, x); },
-    (x: $T, y: $R) { io.write(^stdio.print_writer, x, y); },
+    (x)    => { io.write(^stdio.print_writer, x); },
+    (x, y) => { io.write(^stdio.print_writer, x, y); },
 }
 
-println :: (x: $T) {
+println :: (x) => {
     print(x);
     print("\n");
 }
index f7eab465ebb8b650f7a152fa329ff488d2aaf7a8..a3445f3e22bce75fa660cd9f91981ba25678f177 100644 (file)
--- a/docs/todo
+++ b/docs/todo
@@ -129,7 +129,7 @@ Language Cohesion:
         if val.Property2 { ... }
         ```
 
-    [X] #solidify polymoprhic procedures.
+    [X] #solidify polymorphic procedures.
 
 API Expansion:
     There are many different places where the standard API for WASI and JS
index 66db315abb9c02d76eab1ece8a3b82a4bd901ae0..327efcc9c531504688d077e16ab6764be7a3f1d7 100644 (file)
@@ -215,7 +215,7 @@ get_text_height  :: (text: str, size := DEFAULT_TEXT_SIZE) -> f32 {
 }
 
 @Relocate
-move_towards :: (value: ^$T, target: T, step: T) {
+move_towards :: macro (value: ^$T, target: T, step: T) {
     if *value < target do *value += step;
     if *value > target do *value -= step;
     if *value > target - step && *value < target + step do *value = target;
index 63b9a46d61ad5f71b157d2d8f01cf672390e3395..dbc3677350921b03a898ed9cbf5f27c7650b53cb 100644 (file)
@@ -18,6 +18,7 @@ static inline b32 should_clone(AstNode* node) {
                case Ast_Kind_Alias:
                case Ast_Kind_Code_Block:
                case Ast_Kind_Macro:
+               case Ast_Kind_File_Contents:
                        return 0;
 
                default: return 1;
index 6a0c4bb427cabe1aee64ab749716c01f48a915fd..e3810567a1f8bdc750f7c2a49d6e59fb9c486632 100644 (file)
@@ -246,6 +246,9 @@ void scope_clear(Scope* scope) {
 // Polymorphic Procedures
 //
 
+// HACK HACK HACK nocheckin
+static b32 flag_to_yield = 0;
+
 AstNode node_that_signals_a_yield = { 0 };
 
 static void ensure_polyproc_cache_is_created(AstPolyProc* pp) {
@@ -424,7 +427,7 @@ static void ensure_solidified_function_has_body(AstPolyProc* pp, AstSolidifiedFu
 }
 
 // NOTE: These are temporary data structures used to represent the pattern matching system
-// of polymoprhic type resolution.
+// of polymorphic type resolution.
 typedef struct PolySolveResult {
     PolySolutionKind kind;
     union {
@@ -444,7 +447,7 @@ typedef struct PolySolveElem {
 } PolySolveElem;
 
 // NOTE: The job of this function is to solve for the type/value that belongs in a
-// polymoprhic variable. This function takes in three arguments:
+// polymorphic variable. This function takes in three arguments:
 //  * The symbol node of the polymorphic parameter being searched for
 //  * The type expression that should contain the symbol node it is some where
 //  * The actual type to pattern match against
@@ -681,8 +684,6 @@ static void solve_for_polymorphic_param_type(PolySolveResult* resolved, AstPolyP
     *resolved = solve_poly_type(param->poly_sym, param->type_expr, actual_type);
 }
 
-// HACK HACK HACK nocheckin
-static b32 flag_to_yield = 0;
 
 // NOTE: The job of this function is to look through the arguments provided and find a matching
 // value that is to be baked into the polymorphic procedures poly-scope. It expected that param
@@ -775,7 +776,7 @@ static bh_arr(AstPolySolution) find_polymorphic_slns(AstPolyProc* pp, PolyProcLo
         }
         if (already_solved) continue;
 
-        // NOTE: Solve for the polymoprhic parameter's value
+        // NOTE: Solve for the polymorphic parameter's value
         PolySolveResult resolved = { PSK_Undefined };
         switch (param->kind) {
             case PPK_Poly_Type:   solve_for_polymorphic_param_type (&resolved, pp, param, pp_lookup, actual, err_msg); break;
@@ -792,7 +793,7 @@ static bh_arr(AstPolySolution) find_polymorphic_slns(AstPolyProc* pp, PolyProcLo
                 // resolution was unsuccessful, provide a basic dummy one.
                 if (err_msg && *err_msg == NULL)
                     *err_msg = bh_aprintf(global_scratch_allocator,
-                        "Unable to solve for polymoprhic variable '%b'.",
+                        "Unable to solve for polymorphic variable '%b'.",
                         param->poly_sym->token->text,
                         param->poly_sym->token->length);
 
@@ -824,8 +825,8 @@ static bh_arr(AstPolySolution) find_polymorphic_slns(AstPolyProc* pp, PolyProcLo
 }
 
 // NOTE: The job of this function is to be a wrapper to other functions, providing an error
-// message if a solution could not be found. This can't be merged with polymoprhic_proc_solidify
-// because polymoprhic_proc_try_solidify uses the aforementioned function.
+// message if a solution could not be found. This can't be merged with polymorphic_proc_solidify
+// because polymorphic_proc_try_solidify uses the aforementioned function.
 AstFunction* polymorphic_proc_lookup(AstPolyProc* pp, PolyProcLookupMethod pp_lookup, ptr actual, OnyxToken* tkn) {
     ensure_polyproc_cache_is_created(pp);
 
index 1114c59c78ed9113446505d097c81e6f13dc3b85..fa757f6ae618551a6e580ed50b5058971bd1d9f1 100644 (file)
@@ -2623,6 +2623,9 @@ EMIT_FUNC(expression, AstTyped* expr) {
         case Ast_Kind_File_Contents: {
             AstFileContents* fc = (AstFileContents *) expr;
 
+            assert(fc->addr > 0);
+            assert(fc->size > 0);
+
             WID(WI_PTR_CONST, fc->addr);
             WID(WI_I32_CONST, fc->size);
             break;
index b0f1abe46c00328c31e88c3db3f2b617705e6b8a..98d08cc3920078c55f086fc8bb4257c07e544be7 100644 (file)
@@ -36,12 +36,19 @@ count_iterator :: (lo: i32, hi: i32, step := 1) -> Iterator(i32) {
 
 main :: (args: [] cstr) {
     // Hopefully soon, the following will be possible.
-    // iterator := count_iterator(1, 10)
-    //             |> iter.map(x => x * 2)
-    //             |> iter.filter(x => x > 10)
-    //             |> iter.map(x => x + 42)
-    //             |> iter.take(5)
-    //             |> iter.to_array();
+/*
+    quick_iterator :=
+                count_iterator(1, 10)
+                |> iter.map((x) => x * 2)
+                |> iter.filter((x) => x > 10)
+                |> iter.map((x) => x + 42)
+                |> iter.take(5)
+                |> iter.to_array();
+
+    for v: quick_iterator {
+        println(v);
+    }
+*/
 
     iterator := count_iterator(1, 10)
                 |> iter.map((x: i32) -> i32     { return x * 2; })