bugfixes and additions
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 17 May 2023 22:47:48 +0000 (17:47 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Wed, 17 May 2023 22:47:48 +0000 (17:47 -0500)
See changes in CHANGELOG

CHANGELOG
compiler/src/checker.c
core/container/iter.onyx
core/encoding/json/encoder.onyx
core/io/writer.onyx
core/runtime/platform/js/platform.onyx

index 065676e41ff1a19b6efe16a1b3f228147e50b9a6..3caae89883d3e00ab4004bd56e8a275a5e922998 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -11,9 +11,13 @@ Additions:
 Removals:
 
 Changes:
+* `iter.single` can take a `dispose` function, which is called on close of the
+    iterator, with the single value yielded.
+* `io.write_escaped_str` supports escaping "\\" now.
 
-Bugfixes:
 
+Bugfixes:
+* `json` encoder was wrongly not encoding strings when using `encode` on an `any`.
 
 
 
index 2f6be84acca79f03ddb70028265d1c52fe5d0ec5..e59cf45139bfea4583a77aa57e92e8dcbacfda70 100644 (file)
@@ -2912,20 +2912,6 @@ CheckStatus check_function_header(AstFunction* func) {
             ERROR(param->local->token->pos, "Compound types are not allowed as parameter types. Try splitting this into multiple parameters.");
         }
 
-        // NOTE: I decided to make parameter default values not type checked against
-        // the actual parameter type. The actual type checking will happen in check_call
-        // when the default value is used as an argument and then has to be checked against
-        // the parameter type                                  - brendanfh 2021/01/06
-        // if (param->default_value != NULL) {
-        //     if (!unify_node_and_type(&param->default_value, param->local->type)) {
-        //         onyx_report_error(param->local->token->pos,
-        //                 "Expected default value of type '%s', was of type '%s'.",
-        //                 type_get_name(param->local->type),
-        //                 type_get_name(param->default_value->type));
-        //         return Check_Error;
-        //     }
-        // }
-
         if (param->vararg_kind != VA_Kind_Not_VA) has_had_varargs = 1;
 
         if (local->type->kind != Type_Kind_Array && type_size_of(local->type) == 0) {
index 5e37c928919e5b0a57341159bde025535a1795c1..e4fbe30488d46eb96ef45409724eba6522956f30 100644 (file)
@@ -451,14 +451,18 @@ const :: (value: $T) -> Iterator(T) {
 }
 
 #doc "Yields a single value, then stops."
-single :: (value: $T) -> Iterator(T) {
-    return generator(&.{ v = value, yielded = false }, c => {
+single :: (value: $T, dispose: (T) -> void = null_proc) -> Iterator(T) {
+    return generator(&.{ v = value, yielded = false, dispose = dispose }, c => {
         if !c.yielded {
             c.yielded = true;
             return c.v, true;
         }
 
         return .{}, false;
+    }, c => {
+        if c.dispose != null_proc {
+            c.dispose(c.v);
+        }
     });
 }
 
index c2d981a06ded41e874989fe052ddb988a9e5a61e..f0522c476de9b3c6491bceba8b363f493d544e0b 100644 (file)
@@ -174,7 +174,7 @@ encode :: (w: ^io.Writer, data: any) -> Encoding_Error {
 
         case .Slice, .Dynamic_Array {
             if data.type == str {
-                io.write_format_va(w, "{\"}", .[data]);
+                io.write_escaped_str(w, *misc.any_as(data, str));
                 break;
             }
 
index f01b57e49f41aef1c79b5fafae8bd64b939d4322..ad94c566bb75f321269f0be2b0b1b947cb7c721c 100644 (file)
@@ -175,6 +175,7 @@ write_escaped_str :: (use writer: &Writer, s: str) {
             case #char "\f" { write_byte(writer, #char "\\"); write_byte(writer, #char "f");  }
             case #char "\0" { write_byte(writer, #char "\\"); write_byte(writer, #char "0");  }
             case #char "\"" { write_byte(writer, #char "\\"); write_byte(writer, #char "\""); }
+            case #char "\\" { write_byte(writer, #char "\\"); write_byte(writer, #char "\\"); }
 
             case #default {
                 // @Speed
index fe162d8e68b4597b270f7de214bd42bdd38c66f3..fe919cfa8b801aeeb979688c5fee323217cc3c41 100644 (file)
@@ -24,7 +24,10 @@ __output_string   :: (s: str)      -> u32  #foreign "host" "print_str" ---
 __output_error    :: (s: str)      -> u32  #foreign "host" "print_str" ---
 __exit            :: (status: i32) -> void #foreign "host" "exit" ---
 __time            :: ()            -> i64  #foreign "host" "time" ---
-__read_from_input :: (buf: [] u8)  -> u32 do return 0;
+
+#if !#defined(__read_from_input) {
+    __read_from_input :: (buf: [] u8)  -> u32 do return 0;
+}
 
 // Sets up everything needed for execution.
 __start :: () {