From: Brendan Hansen Date: Mon, 23 Aug 2021 20:24:01 +0000 (-0500) Subject: bugfixes and fixed spelling of "polymoprhic" X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=5300a255c1499584b74c35f468b7f1996e946597;p=onyx.git bugfixes and fixed spelling of "polymoprhic" --- diff --git a/CHANGELOG b/CHANGELOG index d7217c3f..c99f4806 100644 --- 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. diff --git a/bin/onyx b/bin/onyx index 1873432a..4c0e4e12 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/core/io/file.onyx b/core/io/file.onyx index 5d250d81..1bd7f76b 100644 --- a/core/io/file.onyx +++ b/core/io/file.onyx @@ -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 { diff --git a/core/math.onyx b/core/math.onyx index 054738fe..2886c730 100644 --- a/core/math.onyx +++ b/core/math.onyx @@ -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 diff --git a/core/stdio.onyx b/core/stdio.onyx index a28e4735..9891061b 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -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"); } diff --git a/docs/todo b/docs/todo index f7eab465..a3445f3e 100644 --- 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 diff --git a/modules/ui/ui.onyx b/modules/ui/ui.onyx index 66db315a..327efcc9 100644 --- a/modules/ui/ui.onyx +++ b/modules/ui/ui.onyx @@ -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; diff --git a/src/onyxclone.c b/src/onyxclone.c index 63b9a46d..dbc36773 100644 --- a/src/onyxclone.c +++ b/src/onyxclone.c @@ -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; diff --git a/src/onyxutils.c b/src/onyxutils.c index 6a0c4bb4..e3810567 100644 --- a/src/onyxutils.c +++ b/src/onyxutils.c @@ -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); diff --git a/src/onyxwasm.c b/src/onyxwasm.c index 1114c59c..fa757f6a 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -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; diff --git a/tests/lazy_iterators.onyx b/tests/lazy_iterators.onyx index b0f1abe4..98d08cc3 100644 --- a/tests/lazy_iterators.onyx +++ b/tests/lazy_iterators.onyx @@ -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; })