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`.
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(¶m->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) {
}
#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);
+ }
});
}
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;
}
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
__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 :: () {