diff --git a/v.c b/v.c index cde7a09..64dbd3e 100644 --- a/v.c +++ b/v.c @@ -1,11 +1,11 @@ -#define V_COMMIT_HASH "b81f06e36" +#define V_COMMIT_HASH "b7f2ef78b" #ifndef V_COMMIT_HASH - #define V_COMMIT_HASH "9d764cd25" + #define V_COMMIT_HASH "b81f06e36" #endif #ifndef V_CURRENT_COMMIT_HASH - #define V_CURRENT_COMMIT_HASH "b81f06e" + #define V_CURRENT_COMMIT_HASH "b7f2ef7" #endif // V comptime_definitions: @@ -66,7 +66,6 @@ typedef struct multi_return_string_string_string_string multi_return_string_stri typedef struct multi_return_int_string_string_string multi_return_int_string_string_string; typedef struct multi_return_Array_string_Array_string_Array_bool multi_return_Array_string_Array_string_Array_bool; typedef struct multi_return_u64_string multi_return_u64_string; -typedef struct multi_return_int_literal_int_literal multi_return_int_literal_int_literal; // END_multi_return_typedefs typedef struct strconv__BF_param strconv__BF_param; @@ -4372,6 +4371,15 @@ struct v__dotgraph__NewEdgeConfig { +struct v__gen__c__Type { + v__ast__Type typ; + v__ast__TypeSymbol* sym; + v__ast__Type unaliased; + v__ast__TypeSymbol* unaliased_sym; +}; + + + struct v__gen__c__StrType { string styp; v__ast__Type typ; @@ -4398,15 +4406,6 @@ struct v__gen__c__GenSafeIntegerCfg { -struct v__gen__c__Type { - v__ast__Type typ; - v__ast__TypeSymbol* sym; - v__ast__Type unaliased; - v__ast__TypeSymbol* unaliased_sym; -}; - - - struct v__pkgconfig__MainOptions { bool modversion; bool description; @@ -6367,6 +6366,7 @@ struct v__gen__c__Gen { __shared__Map_string_bool* referenced_fns; int nr_closures; v__ast__Type expected_cast_type; + v__ast__Type or_expr_return_type; bool anon_fn; bool tests_inited; bool has_main; @@ -6705,11 +6705,6 @@ struct multi_return_u64_string { string arg1; }; -struct multi_return_int_literal_int_literal { - int_literal arg0; - int_literal arg1; -}; - // END_multi_return_structs @@ -7289,7 +7284,7 @@ void strconv__format_str_sb(string s, strconv__BF_param p, strings__Builder* sb) #define _const_strconv__max_size_f64_char 32 string _const_strconv__digit_pairs; // a string literal, inited later void strconv__format_dec_sb(u64 d, strconv__BF_param p, strings__Builder* res); -string strconv__f64_to_str_lnd1(f64 f, int dec_digit); +VV_LOCAL_SYMBOL string strconv__f64_to_str_lnd1(f64 f, int dec_digit); string strconv__format_fl(f64 f, strconv__BF_param p); string strconv__format_es(f64 f, strconv__BF_param p); string strconv__remove_tail_zeros(string s); @@ -7339,8 +7334,8 @@ string strconv__v_sprintf(string str, Array_voidptr pt); VV_LOCAL_SYMBOL void strconv__v_sprintf_panic(int idx, int len); VV_LOCAL_SYMBOL f64 strconv__fabs(f64 x); string strconv__format_fl_old(f64 f, strconv__BF_param p); -string strconv__format_es_old(f64 f, strconv__BF_param p); -string strconv__remove_tail_zeros_old(string s); +VV_LOCAL_SYMBOL string strconv__format_es_old(f64 f, strconv__BF_param p); +VV_LOCAL_SYMBOL string strconv__remove_tail_zeros_old(string s); string strconv__format_dec_old(u64 d, strconv__BF_param p); VV_LOCAL_SYMBOL array __new_array(int mylen, int cap, int elm_size); VV_LOCAL_SYMBOL array __new_array_with_default(int mylen, int cap, int elm_size, voidptr val); @@ -7518,6 +7513,7 @@ Array_u8 Array_u8_clone(Array_u8 b); string Array_u8_bytestr(Array_u8 b); Option_rune Array_u8_byterune(Array_u8 b); string u8_repeat(u8 b, int count); +VV_LOCAL_SYMBOL string _Atomic__int_str(int x); VV_LOCAL_SYMBOL bool fast_string_eq(string a, string b); VV_LOCAL_SYMBOL u64 map_hash_string(voidptr pkey); VV_LOCAL_SYMBOL u64 map_hash_int_1(voidptr pkey); @@ -9403,6 +9399,8 @@ void v__markused__Walker_struct_fields(v__markused__Walker* w, Array_v__ast__Str void v__markused__Walker_const_fields(v__markused__Walker* w, Array_v__ast__ConstField cfields); void v__markused__Walker_or_block(v__markused__Walker* w, v__ast__OrExpr node); VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayInit node); +VV_LOCAL_SYMBOL void v__gen__c__Gen_fixed_array_init(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type array_type); +VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init_with_fields(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type elem_type, bool is_amp, string shared_styp); VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_array_map(v__gen__c__Gen* g, v__ast__CallExpr node); VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_array_sort(v__gen__c__Gen* g, v__ast__CallExpr node); VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_array_sort_call(v__gen__c__Gen* g, v__ast__CallExpr node, string compare_fn); @@ -12749,7 +12747,7 @@ static int v_typeof_interface_idx_IError(int sidx) { /* IError */ if (sidx == _IError_semver__InvalidComparatorFormatError_index) return 66102; if (sidx == _IError_semver__EmptyInputError_index) return 66104; if (sidx == _IError_semver__InvalidVersionFormatError_index) return 66105; - if (sidx == _IError_v__gen__c__UnsupportedAssertCtempTransform_index) return 497; + if (sidx == _IError_v__gen__c__UnsupportedAssertCtempTransform_index) return 498; return 29; } static char * v_typeof_interface_rand__PRNG(int sidx) { /* rand.PRNG */ @@ -14791,9 +14789,9 @@ string strconv__f32_to_str(f32 f, int n_digit) { if ((exp == _const_strconv__maxexp32) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec32_bool mr_8747 = strconv__f32_to_decimal_exact_int(mant, exp); - strconv__Dec32 d = mr_8747.arg0; - bool ok = mr_8747.arg1; + multi_return_strconv__Dec32_bool mr_8753 = strconv__f32_to_decimal_exact_int(mant, exp); + strconv__Dec32 d = mr_8753.arg0; + bool ok = mr_8753.arg1; if (!ok) { d = strconv__f32_to_decimal(mant, exp); } @@ -14810,9 +14808,9 @@ string strconv__f32_to_str_pad(f32 f, int n_digit) { if ((exp == _const_strconv__maxexp32) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec32_bool mr_9521 = strconv__f32_to_decimal_exact_int(mant, exp); - strconv__Dec32 d = mr_9521.arg0; - bool ok = mr_9521.arg1; + multi_return_strconv__Dec32_bool mr_9537 = strconv__f32_to_decimal_exact_int(mant, exp); + strconv__Dec32 d = mr_9537.arg0; + bool ok = mr_9537.arg1; if (!ok) { d = strconv__f32_to_decimal(mant, exp); } @@ -15065,9 +15063,9 @@ string strconv__f64_to_str(f64 f, int n_digit) { if ((exp == _const_strconv__maxexp64) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec64_bool mr_9304 = strconv__f64_to_decimal_exact_int(mant, exp); - strconv__Dec64 d = mr_9304.arg0; - bool ok = mr_9304.arg1; + multi_return_strconv__Dec64_bool mr_9324 = strconv__f64_to_decimal_exact_int(mant, exp); + strconv__Dec64 d = mr_9324.arg0; + bool ok = mr_9324.arg1; if (!ok) { d = strconv__f64_to_decimal(mant, exp); } @@ -15084,9 +15082,9 @@ string strconv__f64_to_str_pad(f64 f, int n_digit) { if ((exp == _const_strconv__maxexp64) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec64_bool mr_10057 = strconv__f64_to_decimal_exact_int(mant, exp); - strconv__Dec64 d = mr_10057.arg0; - bool ok = mr_10057.arg1; + multi_return_strconv__Dec64_bool mr_10097 = strconv__f64_to_decimal_exact_int(mant, exp); + strconv__Dec64 d = mr_10097.arg0; + bool ok = mr_10097.arg1; if (!ok) { d = strconv__f64_to_decimal(mant, exp); } @@ -15219,7 +15217,7 @@ void strconv__format_dec_sb(u64 d, strconv__BF_param p, strings__Builder* res) { // Attr: [direct_array_access] // Attr: [manualfree] -string strconv__f64_to_str_lnd1(f64 f, int dec_digit) { +VV_LOCAL_SYMBOL string strconv__f64_to_str_lnd1(f64 f, int dec_digit) { { // Unsafe block string s = strconv__f64_to_str(f + ((f64*)_const_strconv__dec_round.data)[dec_digit], 18); if (s.len > 2 && (s.str[ 0] == 'n' || s.str[ 1] == 'i')) { @@ -16653,7 +16651,7 @@ strings__Builder res; } // Attr: [manualfree] -string strconv__format_es_old(f64 f, strconv__BF_param p) { +VV_LOCAL_SYMBOL string strconv__format_es_old(f64 f, strconv__BF_param p) { bool strconv__format_es_old_defer_0 = false; strings__Builder res; string fs; @@ -16724,7 +16722,7 @@ string s; return (string){.str=(byteptr)"", .is_lit=1}; } -string strconv__remove_tail_zeros_old(string s) { +VV_LOCAL_SYMBOL string strconv__remove_tail_zeros_old(string s) { int i = 0; int last_zero_start = -1; int dot_pos = -1; @@ -19028,6 +19026,10 @@ string u8_repeat(u8 b, int count) { return u8_vstring_with_len(ret, new_len); } +VV_LOCAL_SYMBOL string _Atomic__int_str(int x) { + return int_str(x); +} + // Attr: [inline] inline VV_LOCAL_SYMBOL bool fast_string_eq(string a, string b) { if (a.len != b.len) { @@ -35279,7 +35281,7 @@ void v__pref__Preferences_fill_with_defaults(v__pref__Preferences* p) { } #endif } - string vhash = _SLIT("9d764cd25"); + string vhash = _SLIT("b81f06e36"); p->cache_manager = v__vcache__new_cache_manager(new_array_from_c_array(7, 7, sizeof(string), _MOV((string[7]){string_clone(vhash), str_intp(6, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = v__pref__Backend_str(p->backend)}}, {_SLIT(" | "), 0xfe10, {.d_s = v__pref__OS_str(p->os)}}, {_SLIT(" | "), 0xfe10, {.d_s = p->ccompiler}}, {_SLIT(" | "), 0xfe10, {.d_s = p->is_prod ? _SLIT("true") : _SLIT("false")}}, {_SLIT(" | "), 0xfe10, {.d_s = p->sanitize ? _SLIT("true") : _SLIT("false")}}, {_SLIT0, 0, { .d_c = 0 }}})), string_clone(string_trim_space(p->cflags)), string_clone(string_trim_space(p->third_party_option)), string_clone(Array_string_str(p->compile_defines_all)), string_clone(Array_string_str(p->compile_defines)), string_clone(Array_string_str(p->lookup_path))}))); if (string__eq(os__user_os(), _SLIT("windows"))) { p->use_cache = false; @@ -37021,7 +37023,7 @@ VV_LOCAL_SYMBOL ChanState sync__Channel_try_push_priv(sync__Channel* ch, voidptr ChanState _t1 = ChanState__closed; return _t1; } - multi_return_int_literal_int_literal mr_4420 = (no_block ? ((multi_return_int_literal_int_literal){.arg0=1,.arg1=1}) : ((multi_return_int_literal_int_literal){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); + multi_return_int_int mr_4420 = (no_block ? ((multi_return_int_int){.arg0=1,.arg1=1}) : ((multi_return_int_int){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); int spinloops_sem_ = mr_4420.arg0; int spinloops_ = mr_4420.arg1; bool have_swapped = false; @@ -37210,7 +37212,7 @@ inline ChanState sync__Channel_try_pop(sync__Channel* ch, voidptr dest) { } VV_LOCAL_SYMBOL ChanState sync__Channel_try_pop_priv(sync__Channel* ch, voidptr dest, bool no_block) { - multi_return_int_literal_int_literal mr_9405 = (no_block ? ((multi_return_int_literal_int_literal){.arg0=1,.arg1=1}) : ((multi_return_int_literal_int_literal){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); + multi_return_int_int mr_9405 = (no_block ? ((multi_return_int_int){.arg0=1,.arg1=1}) : ((multi_return_int_int){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); int spinloops_sem_ = mr_9405.arg0; int spinloops_ = mr_9405.arg1; bool have_swapped = false; @@ -40930,7 +40932,7 @@ Option_bool v__ast__Table_parse_cflag(v__ast__Table* t, string cflg, string mod, return (Option_bool){ .state=2, .err=_const_none__, .data={EMPTY_STRUCT_INITIALIZATION} }; } string fos = _SLIT(""); - Array_string allowed_os_overrides = new_array_from_c_array(6, 6, sizeof(string), _MOV((string[6]){_SLIT("linux"), _SLIT("darwin"), _SLIT("freebsd"), _SLIT("windows"), _SLIT("mingw"), _SLIT("solaris")})); + Array_string allowed_os_overrides = new_array_from_c_array(7, 7, sizeof(string), _MOV((string[7]){_SLIT("linux"), _SLIT("darwin"), _SLIT("freebsd"), _SLIT("openbsd"), _SLIT("windows"), _SLIT("mingw"), _SLIT("solaris")})); _PUSH_MANY(&allowed_os_overrides, (ctimedefines), _t2, Array_string); for (int _t3 = 0; _t3 < allowed_os_overrides.len; ++_t3) { string os_override = ((string*)allowed_os_overrides.data)[_t3]; @@ -43737,10 +43739,10 @@ int v__ast__Table_find_or_register_multi_return(v__ast__Table* t, Array_v__ast__ string cname = _SLIT("multi_return"); for (int i = 0; i < mr_typs.len; ++i) { v__ast__Type mr_typ = ((v__ast__Type*)mr_typs.data)[i]; - v__ast__TypeSymbol* mr_type_sym = v__ast__Table_sym(t, mr_typ); - multi_return_string_string mr_31198 = (v__ast__Type_is_ptr(mr_typ) ? ((multi_return_string_string){.arg0=_SLIT("&"),.arg1=_SLIT("ref_")}) : ((multi_return_string_string){.arg0=_SLIT(""),.arg1=_SLIT("")})); - string ref = mr_31198.arg0; - string cref = mr_31198.arg1; + v__ast__TypeSymbol* mr_type_sym = v__ast__Table_sym(t, v__ast__mktyp(mr_typ)); + multi_return_string_string mr_31205 = (v__ast__Type_is_ptr(mr_typ) ? ((multi_return_string_string){.arg0=_SLIT("&"),.arg1=_SLIT("ref_")}) : ((multi_return_string_string){.arg0=_SLIT(""),.arg1=_SLIT("")})); + string ref = mr_31205.arg0; + string cref = mr_31205.arg1; name = /*f*/string__plus(name, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ref}}, {_SLIT0, 0xfe10, {.d_s = mr_type_sym->name}}, {_SLIT0, 0, { .d_c = 0 }}}))); cname = /*f*/string__plus(cname, str_intp(3, _MOV((StrIntpData[]){{_SLIT("_"), 0xfe10, {.d_s = cref}}, {_SLIT0, 0xfe10, {.d_s = mr_type_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}}))); if (i < mr_typs.len - 1) { @@ -45146,7 +45148,7 @@ string v__ast__Type_atomic_typename(v__ast__Type t) { return _t1; } else if (idx == (_const_v__ast__int_type_idx)) { - string _t2 = _SLIT("atomic_int"); + string _t2 = _SLIT("_Atomic int"); return _t2; } else if (idx == (_const_v__ast__u64_type_idx)) { @@ -46233,6 +46235,10 @@ string v__ast__Table_type_to_str_using_aliases(v__ast__Table* t, v__ast__Type ty nr_muls--; res = string__plus(_SLIT("shared "), res); } + if (v__ast__Type_has_flag(typ, v__ast__TypeFlag__atomic_f)) { + nr_muls--; + res = string__plus(_SLIT("atomic "), res); + } if (nr_muls > 0 && !v__ast__Type_has_flag(typ, v__ast__TypeFlag__variadic)) { res = string__plus(strings__repeat('&', nr_muls), res); } @@ -47506,105 +47512,109 @@ bool v__checker__Checker_check_types(v__checker__Checker* c, v__ast__Type got, v bool _t3 = true; return _t3; } + if (v__ast__Type_alias_eq(expected, _const_v__ast__bool_type) && (v__ast__Type_is_any_kind_of_pointer(got) || v__ast__Type_is_int(got))) { + bool _t4 = true; + return _t4; + } if (v__ast__Type_is_any_kind_of_pointer(expected)) { v__ast__Type deref = v__ast__Type_deref(expected); v__ast__TypeSymbol* got_sym = v__ast__Table_sym(c->table, got); if (v__ast__Type_is_number(deref) && (v__ast__TypeSymbol_is_number(got_sym) || got_sym->kind == v__ast__Kind__enum_)) { - bool _t4 = true; - return _t4; + bool _t5 = true; + return _t5; } } v__ast__TypeSymbol* got_sym = v__ast__Table_sym(c->table, got); v__ast__TypeSymbol* expected_sym = v__ast__Table_sym(c->table, expected); if (got_sym->kind == v__ast__Kind__enum_) { - if (v__ast__TypeSymbol_is_number(expected_sym)) { - bool _t5 = true; - return _t5; - } - } else if (got_sym->kind == v__ast__Kind__array_fixed) { if (v__ast__TypeSymbol_is_number(expected_sym)) { bool _t6 = true; return _t6; } + } else if (got_sym->kind == v__ast__Kind__array_fixed) { + if (v__ast__TypeSymbol_is_number(expected_sym)) { + bool _t7 = true; + return _t7; + } } if (expected_sym->kind == v__ast__Kind__enum_ && v__ast__TypeSymbol_is_number(got_sym)) { - bool _t7 = true; - return _t7; + bool _t8 = true; + return _t8; } if (got_is_ptr && exp_is_ptr) { if (v__ast__TypeSymbol_is_number(expected_sym) && v__ast__TypeSymbol_is_number(got_sym)) { - bool _t8 = true; - return _t8; + bool _t9 = true; + return _t9; } } } if (got_is_ptr && exp_is_ptr) { if (v__ast__Type_nr_muls(got) != v__ast__Type_nr_muls(expected)) { - bool _t9 = false; - return _t9; + bool _t10 = false; + return _t10; } } int exp_idx = v__ast__Type_idx(expected); int got_idx = v__ast__Type_idx(got); if (exp_idx == got_idx) { - bool _t10 = true; - return _t10; + bool _t11 = true; + return _t11; } if (exp_idx == _const_v__ast__voidptr_type_idx || exp_idx == _const_v__ast__byteptr_type_idx || (v__ast__Type_is_ptr(expected) && v__ast__Type_idx(v__ast__Type_deref(expected)) == _const_v__ast__byte_type_idx)) { if (v__ast__Type_is_ptr(got) || v__ast__Type_is_pointer(got)) { - bool _t11 = true; - return _t11; - } - } - if (v__ast__Type_is_real_pointer(expected)) { - if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type)) { bool _t12 = true; return _t12; } } - if (got_idx == _const_v__ast__voidptr_type_idx || got_idx == _const_v__ast__byteptr_type_idx || (got_idx == _const_v__ast__byte_type_idx && v__ast__Type_is_ptr(got))) { - if (v__ast__Type_is_ptr(expected) || v__ast__Type_is_pointer(expected)) { + if (v__ast__Type_is_real_pointer(expected)) { + if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type)) { bool _t13 = true; return _t13; } } + if (got_idx == _const_v__ast__voidptr_type_idx || got_idx == _const_v__ast__byteptr_type_idx || (got_idx == _const_v__ast__byte_type_idx && v__ast__Type_is_ptr(got))) { + if (v__ast__Type_is_ptr(expected) || v__ast__Type_is_pointer(expected)) { + bool _t14 = true; + return _t14; + } + } if (v__ast__Type_alias_eq(expected, _const_v__ast__charptr_type) && v__ast__Type_alias_eq(got, v__ast__Type_ref(_const_v__ast__char_type))) { - bool _t14 = true; - return _t14; + bool _t15 = true; + return _t15; } if (v__ast__Type_has_flag(expected, v__ast__TypeFlag__optional)) { v__ast__TypeSymbol* sym = v__ast__Table_sym(c->table, got); if (sym->idx == _const_v__ast__error_type_idx || (v__ast__Type_alias_eq(got, _const_v__ast__none_type) || v__ast__Type_alias_eq(got, _const_v__ast__error_type))) { - bool _t15 = true; - return _t15; - } else if (!v__checker__Checker_check_basic(c, got, v__ast__Type_clear_flag(expected, v__ast__TypeFlag__optional))) { - bool _t16 = false; + bool _t16 = true; return _t16; + } else if (!v__checker__Checker_check_basic(c, got, v__ast__Type_clear_flag(expected, v__ast__TypeFlag__optional))) { + bool _t17 = false; + return _t17; } } if (!v__checker__Checker_check_basic(c, got, expected)) { - bool _t17 = false; - return _t17; + bool _t18 = false; + return _t18; } if (v__ast__Type_is_number(got) && v__ast__Type_is_number(expected)) { if (v__ast__Type_alias_eq(got, _const_v__ast__rune_type) && v__ast__Type_alias_eq(expected, _const_v__ast__byte_type)) { - bool _t18 = true; - return _t18; - } else if (v__ast__Type_alias_eq(expected, _const_v__ast__rune_type) && v__ast__Type_alias_eq(got, _const_v__ast__byte_type)) { bool _t19 = true; return _t19; + } else if (v__ast__Type_alias_eq(expected, _const_v__ast__rune_type) && v__ast__Type_alias_eq(got, _const_v__ast__byte_type)) { + bool _t20 = true; + return _t20; } if (!v__ast__Type_alias_eq(v__checker__Checker_promote_num(c, expected, got), expected)) { - bool _t20 = false; - return _t20; + bool _t21 = false; + return _t21; } } if (v__ast__Type_has_flag(expected, v__ast__TypeFlag__generic)) { - bool _t21 = false; - return _t21; + bool _t22 = false; + return _t22; } - bool _t22 = true; - return _t22; + bool _t23 = true; + return _t23; } Option_void v__checker__Checker_check_expected_call_arg(v__checker__Checker* c, v__ast__Type got, v__ast__Type expected_, v__ast__Language language, v__ast__CallArg arg) { @@ -47712,43 +47722,69 @@ bool v__checker__Checker_check_basic(v__checker__Checker* c, v__ast__Type got, v } v__ast__TypeSymbol* got_sym = v__ast__Table_sym(c->table, got); v__ast__TypeSymbol* exp_sym = v__ast__Table_sym(c->table, expected); - if ((got_sym->kind == v__ast__Kind__array || got_sym->kind == v__ast__Kind__map || got_sym->kind == v__ast__Kind__array_fixed) && exp_sym->kind == got_sym->kind) { - if (string__eq(v__ast__Table_type_to_str(c->table, got), string_trim(v__ast__Table_type_to_str(c->table, expected), _SLIT("&")))) { - bool _t5 = true; - return _t5; + if (exp_sym->kind == v__ast__Kind__multi_return && got_sym->kind == v__ast__Kind__multi_return) { + Array_v__ast__Type exp_types = v__ast__TypeSymbol_mr_info(exp_sym).types; + Array_v__ast__Type _t5 = {0}; + Array_v__ast__Type _t5_orig = v__ast__TypeSymbol_mr_info(got_sym).types; + int _t5_len = _t5_orig.len; + _t5 = __new_array(0, _t5_len, sizeof(v__ast__Type)); + + for (int _t6 = 0; _t6 < _t5_len; ++_t6) { + v__ast__Type it = ((v__ast__Type*) _t5_orig.data)[_t6]; + v__ast__Type ti = v__ast__mktyp(it); + array_push((array*)&_t5, &ti); + } + Array_v__ast__Type got_types =_t5; + if (exp_types.len != got_types.len) { + bool _t7 = false; + return _t7; + } + for (int i = 0; i < exp_types.len; ++i) { + if (!v__checker__Checker_check_types(c, (*(v__ast__Type*)/*ee elem_sym */array_get(got_types, i)), (*(v__ast__Type*)/*ee elem_sym */array_get(exp_types, i)))) { + bool _t8 = false; + return _t8; + } } - } - if (!v__ast__Type_is_ptr(unalias_got) && got_sym->kind == v__ast__Kind__array_fixed && (v__ast__Type_is_pointer(unalias_expected) || v__ast__Type_is_ptr(unalias_expected))) { - bool _t6 = false; - return _t6; - } - if ((exp_sym->kind == v__ast__Kind__voidptr || exp_sym->kind == v__ast__Kind__any) || (got_sym->kind == v__ast__Kind__voidptr || got_sym->kind == v__ast__Kind__any)) { - bool _t7 = true; - return _t7; - } - if (v__ast__Table_sumtype_has_variant(c->table, expected, v__ast__mktyp(got), false)) { - bool _t8 = true; - return _t8; - } - if ((got_sym->kind == v__ast__Kind__alias && got_sym->parent_idx == v__ast__Type_idx(expected)) || (exp_sym->kind == v__ast__Kind__alias && exp_sym->parent_idx == v__ast__Type_idx(got))) { bool _t9 = true; return _t9; } - if (got_sym->kind == v__ast__Kind__function && exp_sym->kind == v__ast__Kind__function) { - bool _t10 = v__checker__Checker_check_matching_function_symbols(c, got_sym, exp_sym); - return _t10; + if ((got_sym->kind == v__ast__Kind__array || got_sym->kind == v__ast__Kind__map || got_sym->kind == v__ast__Kind__array_fixed) && exp_sym->kind == got_sym->kind) { + if (string__eq(v__ast__Table_type_to_str(c->table, got), string_trim(v__ast__Table_type_to_str(c->table, expected), _SLIT("&")))) { + bool _t10 = true; + return _t10; + } } - v__ast__Type expected_nonflagged = v__ast__Type_clear_flags(expected); - if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type) && v__ast__Type_is_int(expected_nonflagged)) { - bool _t11 = true; + if (!v__ast__Type_is_ptr(unalias_got) && got_sym->kind == v__ast__Kind__array_fixed && (v__ast__Type_is_pointer(unalias_expected) || v__ast__Type_is_ptr(unalias_expected))) { + bool _t11 = false; return _t11; } - if (v__ast__Type_alias_eq(got, _const_v__ast__float_literal_type) && v__ast__Type_is_float(expected_nonflagged)) { + if ((exp_sym->kind == v__ast__Kind__voidptr || exp_sym->kind == v__ast__Kind__any) || (got_sym->kind == v__ast__Kind__voidptr || got_sym->kind == v__ast__Kind__any)) { bool _t12 = true; return _t12; } - bool _t13 = false; - return _t13; + if (v__ast__Table_sumtype_has_variant(c->table, expected, v__ast__mktyp(got), false)) { + bool _t13 = true; + return _t13; + } + if ((got_sym->kind == v__ast__Kind__alias && got_sym->parent_idx == v__ast__Type_idx(expected)) || (exp_sym->kind == v__ast__Kind__alias && exp_sym->parent_idx == v__ast__Type_idx(got))) { + bool _t14 = true; + return _t14; + } + if (got_sym->kind == v__ast__Kind__function && exp_sym->kind == v__ast__Kind__function) { + bool _t15 = v__checker__Checker_check_matching_function_symbols(c, got_sym, exp_sym); + return _t15; + } + v__ast__Type expected_nonflagged = v__ast__Type_clear_flags(expected); + if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type) && v__ast__Type_is_int(expected_nonflagged)) { + bool _t16 = true; + return _t16; + } + if (v__ast__Type_alias_eq(got, _const_v__ast__float_literal_type) && v__ast__Type_is_float(expected_nonflagged)) { + bool _t17 = true; + return _t17; + } + bool _t18 = false; + return _t18; } bool v__checker__Checker_check_matching_function_symbols(v__checker__Checker* c, v__ast__TypeSymbol* got_type_sym, v__ast__TypeSymbol* exp_type_sym) { @@ -47921,10 +47957,10 @@ VV_LOCAL_SYMBOL v__ast__Type v__checker__Checker_promote_num(v__checker__Checker v__ast__Type type_hi = left_type; v__ast__Type type_lo = right_type; if (v__ast__Type_idx(type_hi) < v__ast__Type_idx(type_lo)) { - v__ast__Type _var_16316 = type_hi; - v__ast__Type _var_16325 = type_lo; - type_hi = _var_16325; - type_lo = _var_16316; + v__ast__Type _var_16786 = type_hi; + v__ast__Type _var_16795 = type_lo; + type_hi = _var_16795; + type_lo = _var_16786; } int idx_hi = v__ast__Type_idx(type_hi); int idx_lo = v__ast__Type_idx(type_lo); @@ -48988,7 +49024,9 @@ v__ast__Type former_expected_type; if ((left_sym->info)._typ == 431 /* v.ast.Alias */ && (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 431) /*expected idx: 431, name: v.ast.Alias */ ).language != v__ast__Language__c && string__eq(c->mod, (*(string*)/*ee elem_sym */array_get(string_split(v__ast__Table_type_to_str(c->table, left_type), _SLIT(".")), 0))) && v__ast__TypeSymbol_is_primitive(v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 431) /*expected idx: 431, name: v.ast.Alias */ ).parent_type))) { left_sym = v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 431) /*expected idx: 431, name: v.ast.Alias */ ).parent_type); } - if (!c->pref->translated && left_sym->kind == v__ast__Kind__alias && (left_sym->info)._typ == 431 /* v.ast.Alias */ && !(v__ast__TypeSymbol_is_primitive(v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 431) /*expected idx: 431, name: v.ast.Alias */ ).parent_type)))) { + if (c->pref->translated && (node->op == v__token__Kind__plus || node->op == v__token__Kind__minus || node->op == v__token__Kind__mul) && v__ast__Type_is_any_kind_of_pointer(left_type) && (v__ast__Type_is_any_kind_of_pointer(right_type) || v__ast__Type_is_int(right_type))) { + return_type = left_type; + } else if (!c->pref->translated && left_sym->kind == v__ast__Kind__alias && (left_sym->info)._typ == 431 /* v.ast.Alias */ && !(v__ast__TypeSymbol_is_primitive(v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 431) /*expected idx: 431, name: v.ast.Alias */ ).parent_type)))) { if (v__ast__TypeSymbol_has_method(left_sym, v__token__Kind_str(node->op))) { Option_v__ast__Fn _t5; if (_t5 = v__ast__TypeSymbol_find_method(left_sym, v__token__Kind_str(node->op)), _t5.state == 0) { @@ -49180,8 +49218,8 @@ v__ast__Type former_expected_type; v__checker__Checker_error(c, _SLIT("array append cannot be used in an expression"), node->pos); } v__checker__Checker_check_expr_opt_call(c, node->right, right_type); - multi_return_string_v__token__Pos mr_33737 = v__checker__Checker_fail_if_immutable(c, node->left); - node->auto_locked = mr_33737.arg0; + multi_return_string_v__token__Pos mr_33947 = v__checker__Checker_fail_if_immutable(c, node->left); + node->auto_locked = mr_33947.arg0; v__ast__Type left_value_type = v__ast__Table_value_type(c->table, v__checker__Checker_unwrap_generic(c, left_type)); v__ast__TypeSymbol* left_value_sym = v__ast__Table_sym(c->table, v__checker__Checker_unwrap_generic(c, left_value_type)); if (left_value_sym->kind == v__ast__Kind__interface_) { @@ -49617,19 +49655,19 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im if (v__ast__Type_has_flag(elem_type, v__ast__TypeFlag__shared_f)) { v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("you have to create a handle and `lock` it to modify `shared` "), 0xfe10, {.d_s = kind}}, {_SLIT(" element"), 0, { .d_c = 0 }}})), v__token__Pos_extend(v__ast__Expr_pos((*expr._v__ast__IndexExpr).left), (*expr._v__ast__IndexExpr).pos)); } - multi_return_string_v__token__Pos mr_44113 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); - to_lock = mr_44113.arg0; - pos = mr_44113.arg1; + multi_return_string_v__token__Pos mr_44323 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); + to_lock = mr_44323.arg0; + pos = mr_44323.arg1; } else if (expr._typ == 281 /* v.ast.ParExpr */) { - multi_return_string_v__token__Pos mr_44182 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); - to_lock = mr_44182.arg0; - pos = mr_44182.arg1; + multi_return_string_v__token__Pos mr_44392 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); + to_lock = mr_44392.arg0; + pos = mr_44392.arg1; } else if (expr._typ == 283 /* v.ast.PrefixExpr */) { - multi_return_string_v__token__Pos mr_44254 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); - to_lock = mr_44254.arg0; - pos = mr_44254.arg1; + multi_return_string_v__token__Pos mr_44464 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); + to_lock = mr_44464.arg0; + pos = mr_44464.arg1; } else if (expr._typ == 286 /* v.ast.SelectorExpr */) { if ((*expr._v__ast__SelectorExpr).expr_type == 0) { @@ -49679,9 +49717,9 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im string type_str = v__ast__Table_type_to_str(c->table, (*expr._v__ast__SelectorExpr).expr_type); v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("field `"), 0xfe10, {.d_s = (*expr._v__ast__SelectorExpr).field_name}}, {_SLIT("` of struct `"), 0xfe10, {.d_s = type_str}}, {_SLIT("` is immutable"), 0, { .d_c = 0 }}})), (*expr._v__ast__SelectorExpr).pos); } - multi_return_string_v__token__Pos mr_45718 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); - to_lock = mr_45718.arg0; - pos = mr_45718.arg1; + multi_return_string_v__token__Pos mr_45928 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); + to_lock = mr_45928.arg0; + pos = mr_45928.arg1; } if ((to_lock).len != 0) { explicit_lock_needed = true; @@ -49787,9 +49825,9 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im } else if (expr._typ == 252 /* v.ast.CallExpr */) { if (string__eq((*expr._v__ast__CallExpr).name, _SLIT("slice"))) { - multi_return_string_v__token__Pos mr_47541 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); - to_lock = mr_47541.arg0; - pos = mr_47541.arg1; + multi_return_string_v__token__Pos mr_47751 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); + to_lock = mr_47751.arg0; + pos = mr_47751.arg1; if ((to_lock).len != 0) { explicit_lock_needed = true; } @@ -50193,9 +50231,9 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t13.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.has_default_expr = 0,.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_pub = 0,.default_val = (string){.str=(byteptr)"", .is_lit=1},.is_mut = 0,.is_global = 0,.is_volatile = 0,.default_expr = {0},.default_expr_typ = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.typ = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_60742 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); - field = mr_60742.arg0; - embed_types = mr_60742.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_60952 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); + field = mr_60952.arg0; + embed_types = mr_60952.arg1; node->from_embed_types = embed_types; if (sym->kind == v__ast__Kind__aggregate || sym->kind == v__ast__Kind__sum_type) { unknown_field_msg = IError_name_table[err._typ]._method_msg(err._object); @@ -50229,9 +50267,9 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t15.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.has_default_expr = 0,.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_pub = 0,.default_val = (string){.str=(byteptr)"", .is_lit=1},.is_mut = 0,.is_global = 0,.is_volatile = 0,.default_expr = {0},.default_expr_typ = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.typ = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_61573 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); - field = mr_61573.arg0; - embed_types = mr_61573.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_61783 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); + field = mr_61783.arg0; + embed_types = mr_61783.arg1; node->from_embed_types = embed_types; } } @@ -52461,8 +52499,8 @@ v__ast__Type v__checker__Checker_postfix_expr(v__checker__Checker* c, v__ast__Po string typ_str = v__ast__Table_type_to_str(c->table, typ); v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("invalid operation: "), 0xfe10, {.d_s = v__token__Kind_str(node->op)}}, {_SLIT(" (non-numeric type `"), 0xfe10, {.d_s = typ_str}}, {_SLIT("`)"), 0, { .d_c = 0 }}})), node->pos); } else { - multi_return_string_v__token__Pos mr_115806 = v__checker__Checker_fail_if_immutable(c, node->expr); - node->auto_locked = mr_115806.arg0; + multi_return_string_v__token__Pos mr_116016 = v__checker__Checker_fail_if_immutable(c, node->expr); + node->auto_locked = mr_116016.arg0; } v__ast__Type _t1 = typ; return _t1; @@ -52634,7 +52672,7 @@ v__ast__Type v__checker__Checker_prefix_expr(v__checker__Checker* c, v__ast__Pre VV_LOCAL_SYMBOL void v__checker__Checker_check_index(v__checker__Checker* c, v__ast__TypeSymbol* typ_sym, v__ast__Expr index, v__ast__Type index_type, v__token__Pos pos, bool range_index, bool is_gated) { v__ast__TypeSymbol* index_type_sym = v__ast__Table_sym(c->table, index_type); if (typ_sym->kind == v__ast__Kind__array || typ_sym->kind == v__ast__Kind__array_fixed || typ_sym->kind == v__ast__Kind__string) { - if (!(v__ast__Type_is_int(index_type) || index_type_sym->kind == v__ast__Kind__enum_)) { + if (!(v__ast__Type_is_int(index_type) || index_type_sym->kind == v__ast__Kind__enum_ || (index_type_sym->kind == v__ast__Kind__alias && v__ast__Type_is_int((/* as */ *(v__ast__Alias*)__as_cast((index_type_sym->info)._v__ast__Alias,(index_type_sym->info)._typ, 431) /*expected idx: 431, name: v.ast.Alias */ ).parent_type)))) { string type_str = (typ_sym->kind == v__ast__Kind__string ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("non-integer string index `"), 0xfe10, {.d_s = index_type_sym->name}}, {_SLIT("`"), 0, { .d_c = 0 }}}))) : ( str_intp(3, _MOV((StrIntpData[]){{_SLIT("non-integer index `"), 0xfe10, {.d_s = index_type_sym->name}}, {_SLIT("` (array type `"), 0xfe10, {.d_s = typ_sym->name}}, {_SLIT("`)"), 0, { .d_c = 0 }}})))); v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = type_str}}, {_SLIT0, 0, { .d_c = 0 }}})), pos); } @@ -57259,7 +57297,7 @@ VV_LOCAL_SYMBOL void v__checker__Checker_for_in_stmt(v__checker__Checker* c, v__ if (node->is_range) { v__ast__Type high_type = v__checker__Checker_expr(c, node->high); int high_type_idx = v__ast__Type_idx(high_type); - if (Array_int_contains(_const_v__ast__integer_type_idxs, typ_idx) && !Array_int_contains(_const_v__ast__integer_type_idxs, high_type_idx)) { + if (Array_int_contains(_const_v__ast__integer_type_idxs, typ_idx) && !Array_int_contains(_const_v__ast__integer_type_idxs, high_type_idx) && high_type_idx != _const_v__ast__void_type_idx) { v__checker__Checker_error(c, _SLIT("range types do not match"), v__ast__Expr_pos(node->cond)); } else if (Array_int_contains(_const_v__ast__float_type_idxs, typ_idx) || Array_int_contains(_const_v__ast__float_type_idxs, high_type_idx)) { v__checker__Checker_error(c, _SLIT("range type can not be float"), v__ast__Expr_pos(node->cond)); @@ -57597,35 +57635,16 @@ bool v__checker__Checker_if_expr_defer_0 = false; if (v__checker__is_noreturn_callexpr(last_expr.expr)) { continue; } - v__ast__TypeSymbol* node_sym = v__ast__Table_sym(c->table, node->typ); - v__ast__TypeSymbol* last_sym = v__ast__Table_sym(c->table, last_expr.typ); - if (node_sym->kind == v__ast__Kind__multi_return && last_sym->kind == v__ast__Kind__multi_return) { - Array_v__ast__Type node_types = v__ast__TypeSymbol_mr_info(node_sym).types; - Array_v__ast__Type _t3 = {0}; - Array_v__ast__Type _t3_orig = v__ast__TypeSymbol_mr_info(last_sym).types; - int _t3_len = _t3_orig.len; - _t3 = __new_array(0, _t3_len, sizeof(v__ast__Type)); - - for (int _t4 = 0; _t4 < _t3_len; ++_t4) { - v__ast__Type it = ((v__ast__Type*) _t3_orig.data)[_t4]; - v__ast__Type ti = v__ast__mktyp(it); - array_push((array*)&_t3, &ti); - } - Array_v__ast__Type last_types =_t3; - if (Array_v__ast__Type_arr_eq(node_types, last_types)) { - continue; - } - } v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("mismatched types `"), 0xfe10, {.d_s = v__ast__Table_type_to_str(c->table, node->typ)}}, {_SLIT("` and `"), 0xfe10, {.d_s = v__ast__Table_type_to_str(c->table, last_expr.typ)}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); } } else { v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("`"), 0xfe10, {.d_s = if_kind}}, {_SLIT("` expression requires an expression as the last statement of every branch"), 0, { .d_c = 0 }}})), branch.pos); } - for (int _t5 = 0; _t5 < branch.stmts.len; ++_t5) { - v__ast__Stmt st = ((v__ast__Stmt*)branch.stmts.data)[_t5]; - Option_void _t6 = v__ast__Stmt_check_c_expr(st); - if (_t6.state != 0 && _t6.err._typ != _IError_None___index) { - IError err = _t6.err; + for (int _t3 = 0; _t3 < branch.stmts.len; ++_t3) { + v__ast__Stmt st = ((v__ast__Stmt*)branch.stmts.data)[_t3]; + Option_void _t4 = v__ast__Stmt_check_c_expr(st); + if (_t4.state != 0 && _t4.err._typ != _IError_None___index) { + IError err = _t4.err; v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("`if` expression branch has "), 0xfe10, {.d_s = IError_name_table[err._typ]._method_msg(err._object)}}, {_SLIT0, 0, { .d_c = 0 }}})), (*(st.pos))); ; } @@ -57647,9 +57666,9 @@ bool v__checker__Checker_if_expr_defer_0 = false; } } } - Option_bool _t7; - if (_t7 = v__checker__Checker_has_return(c, branch.stmts), _t7.state == 0) { - bool has_return = *(bool*)_t7.data; + Option_bool _t5; + if (_t5 = v__checker__Checker_has_return(c, branch.stmts), _t5.state == 0) { + bool has_return = *(bool*)_t5.data; if (has_return) { nbranches_with_return++; } else { @@ -57677,13 +57696,13 @@ bool v__checker__Checker_if_expr_defer_0 = false; string d = (node->is_comptime ? (_SLIT("$")) : (_SLIT(""))); v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("`"), 0xfe10, {.d_s = if_kind}}, {_SLIT("` expression needs `"), 0xfe10, {.d_s = d}}, {_SLIT("else` clause"), 0, { .d_c = 0 }}})), node->pos); } - v__ast__Type _t8 = node->typ; + v__ast__Type _t6 = node->typ; // Defer begin if (v__checker__Checker_if_expr_defer_0) { c->expected_expr_type = _const_v__ast__void_type; } // Defer end - return _t8; + return _t6; } VV_LOCAL_SYMBOL void v__checker__Checker_smartcast_if_conds(v__checker__Checker* c, v__ast__Expr node, v__ast__Scope* scope) { @@ -62184,73 +62203,63 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI array_styp = v__gen__c__Gen_typ(g, array_type.typ); v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("HEAP("), 0xfe10, {.d_s = array_styp}}, {_SLIT(", "), 0, { .d_c = 0 }}}))); } + int len = node.exprs.len; if (array_type.unaliased_sym->kind == v__ast__Kind__array_fixed) { - if (node.has_it) { - g->inside_lambda = true; - string tmp = v__gen__c__Gen_new_tmp_var(g); - string s = v__gen__c__Gen_go_before_stmt(g, 0); - bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); - s = string_trim_space(s); - string ret_typ = v__gen__c__Gen_typ(g, node.typ); - string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); - g->empty_line = true; - v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_write(g, _SLIT("{")); - if (node.has_val) { - for (int i = 0; i < node.exprs.len; ++i) { - v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; - if (v__ast__Expr_is_auto_deref_var(expr)) { - v__gen__c__Gen_write(g, _SLIT("*")); - } - v__gen__c__Gen_write(g, _SLIT("0")); - if (i != node.exprs.len - 1) { - v__gen__c__Gen_write(g, _SLIT(", ")); - } - } - } else if (node.has_default) { - v__gen__c__Gen_write(g, _SLIT("0")); - v__ast__ArrayFixed info = /* as */ *(v__ast__ArrayFixed*)__as_cast((array_type.unaliased_sym->info)._v__ast__ArrayFixed,(array_type.unaliased_sym->info)._typ, 439) /*expected idx: 439, name: v.ast.ArrayFixed */ ; - for (int _t1 = 1; _t1 < info.size; ++_t1) { + v__gen__c__Gen_fixed_array_init(g, node, array_type); + } else if (len == 0) { + v__gen__c__Gen_array_init_with_fields(g, node, elem_type, is_amp, shared_styp); + } else { + string elem_styp = v__gen__c__Gen_typ(g, elem_type.typ); + string noscan = v__gen__c__Gen_check_noscan(g, elem_type.typ); + if (elem_type.unaliased_sym->kind == v__ast__Kind__function) { + v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV((voidptr["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + } else if (v__gen__c__Gen_is_empty_struct(g, elem_type)) { + v__gen__c__Gen_write(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + } else { + v__gen__c__Gen_write(g, str_intp(7, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + } + if (len > 8) { + v__gen__c__Gen_writeln(g, _SLIT("")); + v__gen__c__Gen_write(g, _SLIT("\t\t")); + } + for (int i = 0; i < node.exprs.len; ++i) { + v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; + if (v__ast__Type_alias_eq((*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), _const_v__ast__string_type) && (expr)._typ != 290 /* v.ast.StringLiteral */ && (expr)._typ != 289 /* v.ast.StringInterLiteral */) { + v__gen__c__Gen_write(g, _SLIT("string_clone(")); + v__gen__c__Gen_expr(g, expr); + v__gen__c__Gen_write(g, _SLIT(")")); + } else { + v__gen__c__Gen_expr_with_cast(g, expr, (*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), node.elem_type); + } + if (i != len - 1) { + if (i > 0 && (i & 7) == 0) { + v__gen__c__Gen_writeln(g, _SLIT(",")); + v__gen__c__Gen_write(g, _SLIT("\t\t")); + } else { v__gen__c__Gen_write(g, _SLIT(", ")); - v__gen__c__Gen_write(g, _SLIT("0")); } - } else { - v__gen__c__Gen_write(g, _SLIT("0")); } - v__gen__c__Gen_write(g, _SLIT("}")); - v__gen__c__Gen_writeln(g, _SLIT(";")); - v__gen__c__Gen_writeln(g, _SLIT("{")); - g->indent++; - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("int _len = (int)sizeof("), 0xfe10, {.d_s = tmp}}, {_SLIT(") / sizeof("), 0xfe10, {.d_s = elem_typ}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_writeln(g, _SLIT("for(int it=0; it<_len; it++, pelem++) {")); - g->indent++; - v__gen__c__Gen_write(g, _SLIT("*pelem = ")); - v__gen__c__Gen_expr(g, node.default_expr); - v__gen__c__Gen_writeln(g, _SLIT(";")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - if (s_ends_with_ln) { - v__gen__c__Gen_writeln(g, s); - } else { - v__gen__c__Gen_write(g, s); - } - v__gen__c__Gen_write(g, tmp); - g->inside_lambda = false; - return; } - bool need_tmp_var = g->inside_call && !g->inside_struct_init && node.exprs.len == 0; - string stmt_str = _SLIT(""); - string tmp_var = _SLIT(""); - if (need_tmp_var) { - tmp_var = v__gen__c__Gen_new_tmp_var(g); - stmt_str = v__gen__c__Gen_go_before_stmt(g, 0); - string ret_typ = v__gen__c__Gen_typ(g, node.typ); - g->empty_line = true; - v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp_var}}, {_SLIT(" = "), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, _SLIT("}))")); + if (g->is_shared) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("}, sizeof("), 0xfe10, {.d_s = shared_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); + } else if (is_amp) { + v__gen__c__Gen_write(g, _SLIT(")")); } + } +} + +VV_LOCAL_SYMBOL void v__gen__c__Gen_fixed_array_init(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type array_type) { + if (node.has_it) { + g->inside_lambda = true; + string tmp = v__gen__c__Gen_new_tmp_var(g); + string s = v__gen__c__Gen_go_before_stmt(g, 0); + bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); + s = string_trim_space(s); + string ret_typ = v__gen__c__Gen_typ(g, node.typ); + string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); + g->empty_line = true; + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); v__gen__c__Gen_write(g, _SLIT("{")); if (node.has_val) { for (int i = 0; i < node.exprs.len; ++i) { @@ -62258,110 +62267,100 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI if (v__ast__Expr_is_auto_deref_var(expr)) { v__gen__c__Gen_write(g, _SLIT("*")); } - v__gen__c__Gen_expr(g, expr); + v__gen__c__Gen_write(g, _SLIT("0")); if (i != node.exprs.len - 1) { v__gen__c__Gen_write(g, _SLIT(", ")); } } } else if (node.has_default) { - v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_write(g, _SLIT("0")); v__ast__ArrayFixed info = /* as */ *(v__ast__ArrayFixed*)__as_cast((array_type.unaliased_sym->info)._v__ast__ArrayFixed,(array_type.unaliased_sym->info)._typ, 439) /*expected idx: 439, name: v.ast.ArrayFixed */ ; - for (int _t2 = 1; _t2 < info.size; ++_t2) { + for (int _t1 = 1; _t1 < info.size; ++_t1) { v__gen__c__Gen_write(g, _SLIT(", ")); - v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_write(g, _SLIT("0")); } } else { v__gen__c__Gen_write(g, _SLIT("0")); } v__gen__c__Gen_write(g, _SLIT("}")); - if (need_tmp_var) { - v__gen__c__Gen_writeln(g, _SLIT(";")); - v__gen__c__Gen_write(g, stmt_str); - v__gen__c__Gen_write(g, tmp_var); + v__gen__c__Gen_writeln(g, _SLIT(";")); + v__gen__c__Gen_writeln(g, _SLIT("{")); + g->indent++; + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("int _len = (int)sizeof("), 0xfe10, {.d_s = tmp}}, {_SLIT(") / sizeof("), 0xfe10, {.d_s = elem_typ}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_writeln(g, _SLIT("for(int it=0; it<_len; it++, pelem++) {")); + g->indent++; + v__gen__c__Gen_write(g, _SLIT("*pelem = ")); + v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_writeln(g, _SLIT(";")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + if (s_ends_with_ln) { + v__gen__c__Gen_writeln(g, s); + } else { + v__gen__c__Gen_write(g, s); } + v__gen__c__Gen_write(g, tmp); + g->inside_lambda = false; return; } + bool need_tmp_var = g->inside_call && !g->inside_struct_init && node.exprs.len == 0; + string stmt_str = _SLIT(""); + string tmp_var = _SLIT(""); + if (need_tmp_var) { + tmp_var = v__gen__c__Gen_new_tmp_var(g); + stmt_str = v__gen__c__Gen_go_before_stmt(g, 0); + string ret_typ = v__gen__c__Gen_typ(g, node.typ); + g->empty_line = true; + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp_var}}, {_SLIT(" = "), 0, { .d_c = 0 }}}))); + } + v__gen__c__Gen_write(g, _SLIT("{")); + if (node.has_val) { + for (int i = 0; i < node.exprs.len; ++i) { + v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; + if (v__ast__Expr_is_auto_deref_var(expr)) { + v__gen__c__Gen_write(g, _SLIT("*")); + } + v__gen__c__Gen_expr(g, expr); + if (i != node.exprs.len - 1) { + v__gen__c__Gen_write(g, _SLIT(", ")); + } + } + } else if (node.has_default) { + v__gen__c__Gen_expr(g, node.default_expr); + v__ast__ArrayFixed info = /* as */ *(v__ast__ArrayFixed*)__as_cast((array_type.unaliased_sym->info)._v__ast__ArrayFixed,(array_type.unaliased_sym->info)._typ, 439) /*expected idx: 439, name: v.ast.ArrayFixed */ ; + for (int _t2 = 1; _t2 < info.size; ++_t2) { + v__gen__c__Gen_write(g, _SLIT(", ")); + v__gen__c__Gen_expr(g, node.default_expr); + } + } else { + v__gen__c__Gen_write(g, _SLIT("0")); + } + v__gen__c__Gen_write(g, _SLIT("}")); + if (need_tmp_var) { + v__gen__c__Gen_writeln(g, _SLIT(";")); + v__gen__c__Gen_write(g, stmt_str); + v__gen__c__Gen_write(g, tmp_var); + } +} + +VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init_with_fields(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type elem_type, bool is_amp, string shared_styp) { string elem_styp = v__gen__c__Gen_typ(g, elem_type.typ); string noscan = v__gen__c__Gen_check_noscan(g, elem_type.typ); - if (node.exprs.len == 0) { - bool is_default_array = elem_type.unaliased_sym->kind == v__ast__Kind__array && node.has_default; - bool is_default_map = elem_type.unaliased_sym->kind == v__ast__Kind__map && node.has_default; - if (node.has_it) { - g->inside_lambda = true; - string tmp = v__gen__c__Gen_new_tmp_var(g); - string s = v__gen__c__Gen_go_before_stmt(g, 0); - bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); - s = string_trim_space(s); - string ret_typ = v__gen__c__Gen_typ(g, node.typ); - string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); - g->empty_line = true; - v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); - if (is_default_array) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_array_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); - } else if (is_default_map) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_map_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); - } else { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); - } - if (node.has_len) { - v__gen__c__Gen_expr(g, node.len_expr); - v__gen__c__Gen_write(g, _SLIT(", ")); - } else { - v__gen__c__Gen_write(g, _SLIT("0, ")); - } - if (node.has_cap) { - v__gen__c__Gen_expr(g, node.cap_expr); - v__gen__c__Gen_write(g, _SLIT(", ")); - } else { - v__gen__c__Gen_write(g, _SLIT("0, ")); - } - if (elem_type.unaliased_sym->kind == v__ast__Kind__function || v__gen__c__Gen_is_empty_struct(g, elem_type)) { - v__gen__c__Gen_write(g, _SLIT("sizeof(voidptr), ")); - } else { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), "), 0, { .d_c = 0 }}}))); - } - if (is_default_array) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_expr(g, node.default_expr); - v__gen__c__Gen_write(g, _SLIT("}[0])")); - } else if (node.has_len && v__ast__Type_alias_eq(node.elem_type, _const_v__ast__string_type)) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_write(g, _SLIT("_SLIT(\"\")")); - v__gen__c__Gen_write(g, _SLIT("})")); - } else if (node.has_len && (elem_type.unaliased_sym->kind == v__ast__Kind__array || elem_type.unaliased_sym->kind == v__ast__Kind__map)) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("(voidptr)&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_write(g, v__gen__c__Gen_type_default(g, node.elem_type)); - v__gen__c__Gen_write(g, _SLIT("}[0])")); - } else { - v__gen__c__Gen_write(g, _SLIT("0)")); - } - if (g->is_shared) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("}, sizeof("), 0xfe10, {.d_s = shared_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); - } else if (is_amp) { - v__gen__c__Gen_write(g, _SLIT(")")); - } - v__gen__c__Gen_writeln(g, _SLIT(";")); - v__gen__c__Gen_writeln(g, _SLIT("{")); - g->indent++; - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(".data;"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("for(int it=0; it<"), 0xfe10, {.d_s = tmp}}, {_SLIT(".len; it++, pelem++) {"), 0, { .d_c = 0 }}}))); - g->indent++; - v__gen__c__Gen_write(g, _SLIT("*pelem = ")); - v__gen__c__Gen_expr(g, node.default_expr); - v__gen__c__Gen_writeln(g, _SLIT(";")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - if (s_ends_with_ln) { - v__gen__c__Gen_writeln(g, s); - } else { - v__gen__c__Gen_write(g, s); - } - v__gen__c__Gen_write(g, tmp); - g->inside_lambda = false; - return; - } + bool is_default_array = elem_type.unaliased_sym->kind == v__ast__Kind__array && node.has_default; + bool is_default_map = elem_type.unaliased_sym->kind == v__ast__Kind__map && node.has_default; + if (node.has_it) { + g->inside_lambda = true; + string tmp = v__gen__c__Gen_new_tmp_var(g); + string s = v__gen__c__Gen_go_before_stmt(g, 0); + bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); + s = string_trim_space(s); + string ret_typ = v__gen__c__Gen_typ(g, node.typ); + string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); + g->empty_line = true; + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); if (is_default_array) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_array_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); } else if (is_default_map) { @@ -62386,14 +62385,10 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI } else { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), "), 0, { .d_c = 0 }}}))); } - if (is_default_array || is_default_map) { + if (is_default_array) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_expr(g, node.default_expr); v__gen__c__Gen_write(g, _SLIT("}[0])")); - } else if (node.has_default) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_expr_with_cast(g, node.default_expr, node.default_type, node.elem_type); - v__gen__c__Gen_write(g, _SLIT("})")); } else if (node.has_len && v__ast__Type_alias_eq(node.elem_type, _const_v__ast__string_type)) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_write(g, _SLIT("_SLIT(\"\")")); @@ -62410,39 +62405,71 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI } else if (is_amp) { v__gen__c__Gen_write(g, _SLIT(")")); } + v__gen__c__Gen_writeln(g, _SLIT(";")); + v__gen__c__Gen_writeln(g, _SLIT("{")); + g->indent++; + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(".data;"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("for(int it=0; it<"), 0xfe10, {.d_s = tmp}}, {_SLIT(".len; it++, pelem++) {"), 0, { .d_c = 0 }}}))); + g->indent++; + v__gen__c__Gen_write(g, _SLIT("*pelem = ")); + v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_writeln(g, _SLIT(";")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + if (s_ends_with_ln) { + v__gen__c__Gen_writeln(g, s); + } else { + v__gen__c__Gen_write(g, s); + } + v__gen__c__Gen_write(g, tmp); + g->inside_lambda = false; return; } - int len = node.exprs.len; - if (elem_type.unaliased_sym->kind == v__ast__Kind__function) { - v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV((voidptr["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); - } else if (v__gen__c__Gen_is_empty_struct(g, elem_type)) { - v__gen__c__Gen_write(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + if (is_default_array) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_array_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); + } else if (is_default_map) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_map_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); } else { - v__gen__c__Gen_write(g, str_intp(7, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); } - if (len > 8) { - v__gen__c__Gen_writeln(g, _SLIT("")); - v__gen__c__Gen_write(g, _SLIT("\t\t")); + if (node.has_len) { + v__gen__c__Gen_expr(g, node.len_expr); + v__gen__c__Gen_write(g, _SLIT(", ")); + } else { + v__gen__c__Gen_write(g, _SLIT("0, ")); } - for (int i = 0; i < node.exprs.len; ++i) { - v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; - if (v__ast__Type_alias_eq((*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), _const_v__ast__string_type) && (expr)._typ != 290 /* v.ast.StringLiteral */ && (expr)._typ != 289 /* v.ast.StringInterLiteral */) { - v__gen__c__Gen_write(g, _SLIT("string_clone(")); - v__gen__c__Gen_expr(g, expr); - v__gen__c__Gen_write(g, _SLIT(")")); - } else { - v__gen__c__Gen_expr_with_cast(g, expr, (*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), node.elem_type); - } - if (i != len - 1) { - if (i > 0 && (i & 7) == 0) { - v__gen__c__Gen_writeln(g, _SLIT(",")); - v__gen__c__Gen_write(g, _SLIT("\t\t")); - } else { - v__gen__c__Gen_write(g, _SLIT(", ")); - } - } + if (node.has_cap) { + v__gen__c__Gen_expr(g, node.cap_expr); + v__gen__c__Gen_write(g, _SLIT(", ")); + } else { + v__gen__c__Gen_write(g, _SLIT("0, ")); + } + if (elem_type.unaliased_sym->kind == v__ast__Kind__function || v__gen__c__Gen_is_empty_struct(g, elem_type)) { + v__gen__c__Gen_write(g, _SLIT("sizeof(voidptr), ")); + } else { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), "), 0, { .d_c = 0 }}}))); + } + if (is_default_array || is_default_map) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_write(g, _SLIT("}[0])")); + } else if (node.has_default) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_expr_with_cast(g, node.default_expr, node.default_type, node.elem_type); + v__gen__c__Gen_write(g, _SLIT("})")); + } else if (node.has_len && v__ast__Type_alias_eq(node.elem_type, _const_v__ast__string_type)) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, _SLIT("_SLIT(\"\")")); + v__gen__c__Gen_write(g, _SLIT("})")); + } else if (node.has_len && (elem_type.unaliased_sym->kind == v__ast__Kind__array || elem_type.unaliased_sym->kind == v__ast__Kind__map)) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("(voidptr)&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, v__gen__c__Gen_type_default(g, node.elem_type)); + v__gen__c__Gen_write(g, _SLIT("}[0])")); + } else { + v__gen__c__Gen_write(g, _SLIT("0)")); } - v__gen__c__Gen_write(g, _SLIT("}))")); if (g->is_shared) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("}, sizeof("), 0xfe10, {.d_s = shared_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); } else if (is_amp) { @@ -65315,32 +65342,32 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_interface(v__gen__c__Gen* g, v__ strings__Builder_writeln(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static string indent_"), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("("), 0xfe10, {.d_s = styp}}, {_SLIT(" x, int indent_count) { /* gen_str_for_interface */"), 0, { .d_c = 0 }}}))); for (int _t1 = 0; _t1 < info.types.len; ++_t1) { v__ast__Type typ = ((v__ast__Type*)info.types.data)[_t1]; - v__ast__TypeSymbol* subtype = v__ast__Table_sym(g->table, typ); + v__ast__TypeSymbol* sub_sym = v__ast__Table_sym(g->table, v__ast__mktyp(typ)); string func_name = v__gen__c__Gen_get_str_fn(g, typ); - multi_return_bool_bool_int mr_13661 = v__ast__TypeSymbol_str_method_info(subtype); - bool sym_has_str_method = mr_13661.arg0; - bool str_method_expects_ptr = mr_13661.arg1; - if (v__gen__c__should_use_indent_func(subtype->kind) && !sym_has_str_method) { + multi_return_bool_bool_int mr_13672 = v__ast__TypeSymbol_str_method_info(sub_sym); + bool sym_has_str_method = mr_13672.arg0; + bool str_method_expects_ptr = mr_13672.arg1; + if (v__gen__c__should_use_indent_func(sub_sym->kind) && !sym_has_str_method) { func_name = str_intp(2, _MOV((StrIntpData[]){{_SLIT("indent_"), 0xfe10, {.d_s = func_name}}, {_SLIT0, 0, { .d_c = 0 }}})); } string deref = (sym_has_str_method && str_method_expects_ptr ? (_SLIT(" ")) : (_SLIT("*"))); if (v__ast__Type_alias_eq(typ, _const_v__ast__string_type)) { - string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); - if (v__gen__c__should_use_indent_func(subtype->kind) && !sym_has_str_method) { + string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); + if (v__gen__c__should_use_indent_func(sub_sym->kind) && !sym_has_str_method) { val = /*f*/string__plus(val, _SLIT(", indent_count")); } val = /*f*/string__plus(val, _SLIT(")")); string res = str_intp(4, _MOV((StrIntpData[]){{_SLIT("str_intp(2, _MOV((StrIntpData[]){\n {_SLIT(\""), 0xfe10, {.d_s = clean_interface_v_type_name}}, {_SLIT("(\'\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s = "), 0xfe10, {.d_s = val}}, {_SLIT("}},\n {_SLIT(\"\')\"), 0, {.d_c = 0 }}\n }))"), 0, { .d_c = 0 }}})); - strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); + strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); strings__Builder_write_string(&fn_builder, str_intp(2, _MOV((StrIntpData[]){{_SLIT(" return "), 0xfe10, {.d_s = res}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); } else { - string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); - if (v__gen__c__should_use_indent_func(subtype->kind) && !sym_has_str_method) { + string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); + if (v__gen__c__should_use_indent_func(sub_sym->kind) && !sym_has_str_method) { val = /*f*/string__plus(val, _SLIT(", indent_count")); } val = /*f*/string__plus(val, _SLIT(")")); string res = str_intp(4, _MOV((StrIntpData[]){{_SLIT("str_intp(2, _MOV((StrIntpData[]){\n {_SLIT(\""), 0xfe10, {.d_s = clean_interface_v_type_name}}, {_SLIT("(\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s = "), 0xfe10, {.d_s = val}}, {_SLIT("}},\n {_SLIT(\")\"), 0, {.d_c = 0 }}\n }))"), 0, { .d_c = 0 }}})); - strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); + strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); strings__Builder_write_string(&fn_builder, str_intp(2, _MOV((StrIntpData[]){{_SLIT(" return "), 0xfe10, {.d_s = res}}, {_SLIT(";\n"), 0, { .d_c = 0 }}}))); } } @@ -65390,9 +65417,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_union_sum_type(v__gen__c__Gen* g string typ_str = v__gen__c__Gen_typ(g, typ); string func_name = v__gen__c__Gen_get_str_fn(g, typ); v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, typ); - multi_return_bool_bool_int mr_16578 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_16578.arg0; - bool str_method_expects_ptr = mr_16578.arg1; + multi_return_bool_bool_int mr_16589 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_16589.arg0; + bool str_method_expects_ptr = mr_16589.arg1; string deref = (sym_has_str_method && str_method_expects_ptr ? (_SLIT(" ")) : (_SLIT("*"))); if (v__gen__c__should_use_indent_func(sym->kind) && !sym_has_str_method) { func_name = str_intp(2, _MOV((StrIntpData[]){{_SLIT("indent_"), 0xfe10, {.d_s = func_name}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -65511,9 +65538,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array(v__gen__c__Gen* g, v__ast_ } string field_styp = v__gen__c__Gen_typ(g, typ); bool is_elem_ptr = v__ast__Type_is_ptr(typ); - multi_return_bool_bool_int mr_20654 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_20654.arg0; - bool str_method_expects_ptr = mr_20654.arg1; + multi_return_bool_bool_int mr_20665 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_20665.arg0; + bool str_method_expects_ptr = mr_20665.arg1; string elem_str_fn_name = v__gen__c__Gen_get_str_fn(g, typ); if (sym->kind == v__ast__Kind__u8) { elem_str_fn_name = string__plus(elem_str_fn_name, _SLIT("_escaped")); @@ -65555,9 +65582,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array(v__gen__c__Gen* g, v__ast_ strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT(\"\'\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s = it }}, {_SLIT(\"\'\"), 0, {.d_c = 0 }}}));\n"), 0, { .d_c = 0 }}}))); } } else { - multi_return_string_string mr_23178 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); - string deref = mr_23178.arg0; - string deref_label = mr_23178.arg1; + multi_return_string_string mr_23189 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); + string deref = mr_23189.arg0; + string deref_label = mr_23189.arg1; strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstrings__Builder_write_string(&sb, _SLIT(\""), 0xfe10, {.d_s = deref_label}}, {_SLIT("\"));"), 0, { .d_c = 0 }}}))); strings__Builder_writeln(&g->auto_str_funcs, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\t\tstring x = "), 0xfe10, {.d_s = elem_str_fn_name}}, {_SLIT("( "), 0xfe10, {.d_s = deref}}, {_SLIT(" it);"), 0, { .d_c = 0 }}}))); } @@ -65590,9 +65617,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array_fixed(v__gen__c__Gen* g, v sym = v__ast__Table_sym(g->table, typ); } bool is_elem_ptr = v__ast__Type_is_ptr(typ); - multi_return_bool_bool_int mr_24560 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_24560.arg0; - bool str_method_expects_ptr = mr_24560.arg1; + multi_return_bool_bool_int mr_24571 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_24571.arg0; + bool str_method_expects_ptr = mr_24571.arg1; string elem_str_fn_name = v__gen__c__Gen_get_str_fn(g, typ); strings__Builder_writeln(&g->definitions, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static string "), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("("), 0xfe10, {.d_s = styp}}, {_SLIT(" a); // auto"), 0, { .d_c = 0 }}}))); strings__Builder_writeln(&g->auto_str_funcs, str_intp(4, _MOV((StrIntpData[]){{_SLIT("static string "), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("("), 0xfe10, {.d_s = styp}}, {_SLIT(" a) { return indent_"), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("(a, 0);}"), 0, { .d_c = 0 }}}))); @@ -65605,9 +65632,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array_fixed(v__gen__c__Gen* g, v strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstring x = "), 0xfe10, {.d_s = elem_str_fn_name}}, {_SLIT("();"), 0, { .d_c = 0 }}}))); strings__Builder_writeln(&g->auto_str_funcs, _SLIT("\t\tstrings__Builder_write_string(&sb, x);")); } else { - multi_return_string_string mr_25437 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); - string deref = mr_25437.arg0; - string deref_label = mr_25437.arg1; + multi_return_string_string mr_25448 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); + string deref = mr_25448.arg0; + string deref_label = mr_25448.arg1; if (v__gen__c__should_use_indent_func(sym->kind) && !sym_has_str_method) { if (is_elem_ptr) { strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstrings__Builder_write_string(&sb, _SLIT(\""), 0xfe10, {.d_s = deref_label}}, {_SLIT("\"));"), 0, { .d_c = 0 }}}))); @@ -65834,9 +65861,9 @@ strings__Builder fn_body; } else { strings__Builder_write_string(&fn_body, str_intp(5, _MOV((StrIntpData[]){{_SLIT("\t\t{_SLIT(\"\\n\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s=indents}}, {_SLIT(\" "), 0xfe10, {.d_s = field.name}}, {_SLIT(": "), 0xfe10, {.d_s = ptr_amp}}, {_SLIT0, 0xfe10, {.d_s = prefix}}, {_SLIT("\"), 0, {.d_c=0}}, "), 0, { .d_c = 0 }}}))); } - multi_return_bool_bool_int mr_35259 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_35259.arg0; - bool str_method_expects_ptr = mr_35259.arg1; + multi_return_bool_bool_int mr_35270 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_35270.arg0; + bool str_method_expects_ptr = mr_35270.arg1; string sftyp = v__gen__c__Gen_typ(g, field.typ); string field_styp = string_replace(sftyp, _SLIT("*"), _SLIT("")); string _t2; /* if prepend */ @@ -65857,9 +65884,9 @@ strings__Builder fn_body; strings__Builder_write_string(&fn_body, str_intp(4, _MOV((StrIntpData[]){{_SLIT("{_SLIT(\""), 0xfe10, {.d_s = quote_str}}, {_SLIT("\"), "), 0xfe10, {.d_s = g_fmt}}, {_SLIT(", {."), 0xfe10, {.d_s = v__gen__c__data_str(base_fmt)}}, {_SLIT("="), 0, { .d_c = 0 }}}))); } string funcprefix = _SLIT(""); - multi_return_string_bool mr_36043 = v__gen__c__struct_auto_str_func(sym, field.typ, field_styp_fn_name, field.name, sym_has_str_method, str_method_expects_ptr); - string func = mr_36043.arg0; - bool caller_should_free = mr_36043.arg1; + multi_return_string_bool mr_36054 = v__gen__c__struct_auto_str_func(sym, field.typ, field_styp_fn_name, field.name, sym_has_str_method, str_method_expects_ptr); + string func = mr_36054.arg0; + bool caller_should_free = mr_36054.arg1; if (Array_v__ast__Type_contains(_const_v__ast__cptr_types, field.typ)) { func = str_intp(2, _MOV((StrIntpData[]){{_SLIT("(voidptr) it."), 0xfe10, {.d_s = field.name}}, {_SLIT0, 0, { .d_c = 0 }}})); caller_should_free = false; @@ -65916,8 +65943,8 @@ VV_LOCAL_SYMBOL multi_return_string_bool v__gen__c__struct_auto_str_func(v__ast_ eprintln( str_intp(6, _MOV((StrIntpData[]){{_SLIT("> struct_auto_str_func: "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" | field_type.debug() | "), 0xfe10, {.d_s = fn_name}}, {_SLIT(" | "), 0xfe10, {.d_s = field_name}}, {_SLIT(" | "), 0xfe10, {.d_s = has_custom_str ? _SLIT("true") : _SLIT("false")}}, {_SLIT(" | "), 0xfe10, {.d_s = expects_ptr ? _SLIT("true") : _SLIT("false")}}, {_SLIT0, 0, { .d_c = 0 }}}))); } #endif - multi_return_string_string mr_37955 = v__gen__c__deref_kind(expects_ptr, v__ast__Type_is_ptr(field_type), field_type); - string deref = mr_37955.arg0; + multi_return_string_string mr_37966 = v__gen__c__deref_kind(expects_ptr, v__ast__Type_is_ptr(field_type), field_type); + string deref = mr_37966.arg0; if (sym->kind == v__ast__Kind__enum_) { return (multi_return_string_bool){.arg0= str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = fn_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("it."), 0xfe10, {.d_s = v__gen__c__c_name(field_name)}}, {_SLIT(")"), 0, { .d_c = 0 }}})), .arg1=true}; } else if (v__gen__c__should_use_indent_func(sym->kind)) { @@ -66128,6 +66155,7 @@ string v__gen__c__gen(Array_v__ast__File_ptr files, v__ast__Table* table, v__pre .referenced_fns = (__shared__Map_string_bool*)__dup_shared_map(&(__shared__Map_string_bool){.mtx = {0}, .val =new_map(sizeof(string), sizeof(bool), &map_hash_string, &map_eq_string, &map_clone_string, &map_free_string)}, sizeof(__shared__Map_string_bool)), .nr_closures = 0, .expected_cast_type = 0, + .or_expr_return_type = 0, .anon_fn = 0, .tests_inited = 0, .has_main = 0, @@ -66802,6 +66830,7 @@ VV_LOCAL_SYMBOL v__gen__c__Gen* v__gen__c__cgen_process_one_file_cb(sync__pool__ .referenced_fns = global_g->referenced_fns, .nr_closures = 0, .expected_cast_type = 0, + .or_expr_return_type = 0, .anon_fn = 0, .tests_inited = 0, .has_main = 0, @@ -67145,8 +67174,8 @@ void v__gen__c__Gen_write_typeof_functions(v__gen__c__Gen* g) { v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static char * v_typeof_interface_"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("(int sidx) { /* "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); for (int _t5 = 0; _t5 < inter_info.types.len; ++_t5) { v__ast__Type t = ((v__ast__Type*)inter_info.types.data)[_t5]; - v__ast__TypeSymbol* subtype = v__ast__Table_sym(g->table, t); - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index) return \""), 0xfe10, {.d_s = v__util__strip_main_name(subtype->name)}}, {_SLIT("\";"), 0, { .d_c = 0 }}}))); + v__ast__TypeSymbol* sub_sym = v__ast__Table_sym(g->table, v__ast__mktyp(t)); + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index) return \""), 0xfe10, {.d_s = v__util__strip_main_name(sub_sym->name)}}, {_SLIT("\";"), 0, { .d_c = 0 }}}))); } v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\treturn \"unknown "), 0xfe10, {.d_s = v__util__strip_main_name(sym->name)}}, {_SLIT("\";"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_writeln(g, _SLIT("}")); @@ -67154,8 +67183,8 @@ void v__gen__c__Gen_write_typeof_functions(v__gen__c__Gen* g) { v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static int v_typeof_interface_idx_"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("(int sidx) { /* "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); for (int _t6 = 0; _t6 < inter_info.types.len; ++_t6) { v__ast__Type t = ((v__ast__Type*)inter_info.types.data)[_t6]; - v__ast__TypeSymbol* subtype = v__ast__Table_sym(g->table, t); - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index) return "), 0xfe07, {.d_i32 = ((int)(t))}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); + v__ast__TypeSymbol* sub_sym = v__ast__Table_sym(g->table, v__ast__mktyp(t)); + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index) return "), 0xfe07, {.d_i32 = ((int)(t))}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); } v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\treturn "), 0xfe07, {.d_i32 = ((int)(ityp))}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_writeln(g, _SLIT("}")); @@ -67264,9 +67293,9 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_optional_type_text(v__gen__c__Gen* g, stri } VV_LOCAL_SYMBOL string v__gen__c__Gen_register_optional(v__gen__c__Gen* g, v__ast__Type t) { - multi_return_string_string mr_36707 = v__gen__c__Gen_optional_type_name(g, t); - string styp = mr_36707.arg0; - string base = mr_36707.arg1; + multi_return_string_string mr_36786 = v__gen__c__Gen_optional_type_name(g, t); + string styp = mr_36786.arg0; + string base = mr_36786.arg1; map_set(&g->optionals, &(string[]){base}, &(string[]) { styp }); string _t1 = styp; return _t1; @@ -67648,7 +67677,11 @@ void v__gen__c__Gen_write_interface_typesymbol_declaration(v__gen__c__Gen* g, v_ strings__Builder_writeln(&g->type_definitions, _SLIT("\t\tvoid* _object;")); for (int _t1 = 0; _t1 < info.types.len; ++_t1) { v__ast__Type variant = ((v__ast__Type*)info.types.data)[_t1]; - string vcname = v__ast__Table_sym(g->table, variant)->cname; + v__ast__Type mk_typ = v__ast__mktyp(variant); + if (!v__ast__Type_alias_eq(mk_typ, variant) && Array_v__ast__Type_contains(info.types, mk_typ)) { + continue; + } + string vcname = v__ast__Table_sym(g->table, mk_typ)->cname; strings__Builder_writeln(&g->type_definitions, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\t\t"), 0xfe10, {.d_s = vcname}}, {_SLIT("* _"), 0xfe10, {.d_s = vcname}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); } strings__Builder_writeln(&g->type_definitions, _SLIT("\t};")); @@ -68336,8 +68369,8 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_write_sumtype_casting_fn(v__gen__c__Gen* g, *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t4.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.has_default_expr = 0,.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_pub = 0,.default_val = (string){.str=(byteptr)"", .is_lit=1},.is_mut = 0,.is_global = 0,.is_volatile = 0,.default_expr = {0},.default_expr_typ = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.typ = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_65835 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t4.data); - Array_v__ast__Type embed_types = mr_65835.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_66009 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t4.data); + Array_v__ast__Type embed_types = mr_66009.arg1; if (embed_types.len > 0) { v__ast__TypeSymbol* embed_sym = v__ast__Table_sym(g->table, (*(v__ast__Type*)array_last(embed_types))); ptr = str_intp(2, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = v__ast__TypeSymbol_embed_name(embed_sym)}}, {_SLIT("_ptr"), 0, { .d_c = 0 }}})); @@ -68390,10 +68423,10 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_expr_with_cast(v__gen__c__Gen* g, v__ast__Ex v__gen__c__Gen_expr(g, expr); return; } - if ((exp_sym->info)._typ == 434 /* v.ast.Interface */ && v__ast__Type_idx(got_type_raw) != v__ast__Type_idx(expected_type) && !v__ast__Type_has_flag(expected_type, v__ast__TypeFlag__optional)) { + if ((exp_sym->info)._typ == 434 /* v.ast.Interface */ && v__ast__Type_idx(got_type) != v__ast__Type_idx(expected_type) && !v__ast__Type_has_flag(expected_type, v__ast__TypeFlag__optional)) { if ((expr)._typ == 291 /* v.ast.StructInit */ && !v__ast__Type_is_ptr(got_type)) { g->inside_cast_in_heap++; - string got_styp = v__gen__c__Gen_cc_type(g, v__ast__Type_ref(got_type_raw), true); + string got_styp = v__gen__c__Gen_cc_type(g, v__ast__Type_ref(got_type), true); string exp_styp = exp_sym->cname; string fname = str_intp(3, _MOV((StrIntpData[]){{_SLIT("I_"), 0xfe10, {.d_s = got_styp}}, {_SLIT("_to_Interface_"), 0xfe10, {.d_s = exp_styp}}, {_SLIT0, 0, { .d_c = 0 }}})); if ((*exp_sym->info._v__ast__Interface).is_generic) { @@ -68402,7 +68435,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_expr_with_cast(v__gen__c__Gen* g, v__ast__Ex v__gen__c__Gen_call_cfn_for_casting_expr(g, fname, expr, expected_is_ptr, exp_styp, true, got_styp); g->inside_cast_in_heap--; } else { - string got_styp = v__gen__c__Gen_cc_type(g, got_type_raw, true); + string got_styp = v__gen__c__Gen_cc_type(g, got_type, true); bool got_is_shared = v__ast__Type_has_flag(got_type, v__ast__TypeFlag__shared_f); string exp_styp = (got_is_shared ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("__shared__"), 0xfe10, {.d_s = exp_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}}))) : (exp_sym->cname)); string fname = (got_is_shared ? ( str_intp(3, _MOV((StrIntpData[]){{_SLIT("I___shared__"), 0xfe10, {.d_s = got_styp}}, {_SLIT("_to_shared_Interface_"), 0xfe10, {.d_s = exp_styp}}, {_SLIT0, 0, { .d_c = 0 }}}))) : ( str_intp(3, _MOV((StrIntpData[]){{_SLIT("I_"), 0xfe10, {.d_s = got_styp}}, {_SLIT("_to_Interface_"), 0xfe10, {.d_s = exp_styp}}, {_SLIT0, 0, { .d_c = 0 }}})))); @@ -69783,11 +69816,11 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_map_init(v__gen__c__Gen* g, v__ast__MapInit string value_typ_str = v__gen__c__Gen_typ(g, unwrap_val_typ); v__ast__TypeSymbol* value_sym = v__ast__Table_sym(g->table, unwrap_val_typ); v__ast__TypeSymbol* key_sym = v__ast__Table_final_sym(g->table, unwrap_key_typ); - multi_return_string_string_string_string mr_105090 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); - string hash_fn = mr_105090.arg0; - string key_eq_fn = mr_105090.arg1; - string clone_fn = mr_105090.arg2; - string free_fn = mr_105090.arg3; + multi_return_string_string_string_string mr_105252 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); + string hash_fn = mr_105252.arg0; + string key_eq_fn = mr_105252.arg1; + string clone_fn = mr_105252.arg2; + string free_fn = mr_105252.arg3; int size = node.vals.len; string shared_styp = _SLIT(""); string styp = _SLIT(""); @@ -70169,6 +70202,8 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_concat_expr(v__gen__c__Gen* g, v__ast__Conca string styp = v__gen__c__Gen_typ(g, node.return_type); if (g->inside_return) { styp = v__gen__c__Gen_typ(g, g->fn_decl->return_type); + } else if (g->inside_or_block) { + styp = v__gen__c__Gen_typ(g, g->or_expr_return_type); } v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, node.return_type); bool is_multi = sym->kind == v__ast__Kind__multi_return; @@ -70957,9 +70992,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_write_types(v__gen__c__Gen* g, Array_v__ast_ for (int _t3 = 0; _t3 < (*sym->info._v__ast__Struct).fields.len; ++_t3) { v__ast__StructField field = ((v__ast__StructField*)(*sym->info._v__ast__Struct).fields.data)[_t3]; if (v__ast__Type_has_flag(field.typ, v__ast__TypeFlag__optional)) { - multi_return_string_string mr_142158 = v__gen__c__Gen_optional_type_name(g, field.typ); - string styp = mr_142158.arg0; - string base = mr_142158.arg1; + multi_return_string_string mr_142389 = v__gen__c__Gen_optional_type_name(g, field.typ); + string styp = mr_142389.arg0; + string base = mr_142389.arg1; sync__RwMutex_lock(&g->done_optionals->mtx); /*lock*/ { if (!Array_string_contains(g->done_optionals->val, base)) { @@ -71191,6 +71226,7 @@ bool v__gen__c__Gen_or_block_defer_0 = false; v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("if ("), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".state != 0) { /*or block*/ "), 0, { .d_c = 0 }}}))); } if (or_block.kind == v__ast__OrKind__block) { + g->or_expr_return_type = v__ast__Type_clear_flag(return_type, v__ast__TypeFlag__optional); if (g->inside_or_block) { v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\terr = "), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".err;"), 0, { .d_c = 0 }}}))); } else { @@ -71226,15 +71262,16 @@ bool v__gen__c__Gen_or_block_defer_0 = false; v__gen__c__Gen_writeln(g, _SLIT(";")); } } + g->or_expr_return_type = _const_v__ast__void_type; } else if (or_block.kind == v__ast__OrKind__propagate) { if (string__eq(g->file->mod.name, _SLIT("main")) && (isnil(g->fn_decl) || g->fn_decl->is_main)) { string err_msg = str_intp(3, _MOV((StrIntpData[]){{_SLIT("IError_name_table["), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._typ]._method_msg("), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._object)"), 0, { .d_c = 0 }}})); if (g->pref->is_debug) { - multi_return_int_string_string_string mr_151212 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); - int paline = mr_151212.arg0; - string pafile = mr_151212.arg1; - string pamod = mr_151212.arg2; - string pafn = mr_151212.arg3; + multi_return_int_string_string_string mr_151543 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); + int paline = mr_151543.arg0; + string pafile = mr_151543.arg1; + string pamod = mr_151543.arg2; + string pafn = mr_151543.arg3; v__gen__c__Gen_writeln(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("panic_debug("), 0xfe07, {.d_i32 = paline}}, {_SLIT(", tos3(\""), 0xfe10, {.d_s = pafile}}, {_SLIT("\"), tos3(\""), 0xfe10, {.d_s = pamod}}, {_SLIT("\"), tos3(\""), 0xfe10, {.d_s = pafn}}, {_SLIT("\"), "), 0xfe10, {.d_s = err_msg}}, {_SLIT(" );"), 0, { .d_c = 0 }}}))); } else { v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\tpanic_optional_not_set( "), 0xfe10, {.d_s = err_msg}}, {_SLIT(" );"), 0, { .d_c = 0 }}}))); @@ -71344,11 +71381,11 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_type_default(v__gen__c__Gen* g, v__ast__Ty { v__ast__Map info = v__ast__TypeSymbol_map_info(sym); v__ast__TypeSymbol* key_typ = v__ast__Table_sym(g->table, info.key_type); - multi_return_string_string_string_string mr_153794 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); - string hash_fn = mr_153794.arg0; - string key_eq_fn = mr_153794.arg1; - string clone_fn = mr_153794.arg2; - string free_fn = mr_153794.arg3; + multi_return_string_string_string_string mr_154125 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); + string hash_fn = mr_154125.arg0; + string key_eq_fn = mr_154125.arg1; + string clone_fn = mr_154125.arg2; + string free_fn = mr_154125.arg3; string noscan_key = v__gen__c__Gen_check_noscan(g, info.key_type); string noscan_value = v__gen__c__Gen_check_noscan(g, info.value_type); string noscan = (noscan_key.len != 0 || noscan_value.len != 0 ? (_SLIT("_noscan")) : (_SLIT(""))); @@ -71528,9 +71565,10 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_enum_val(v__gen__c__Gen* g, v__ast__EnumVal } VV_LOCAL_SYMBOL void v__gen__c__Gen_as_cast(v__gen__c__Gen* g, v__ast__AsCast node) { - string styp = v__gen__c__Gen_typ(g, node.typ); - v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, node.typ); - v__ast__TypeSymbol* expr_type_sym = v__ast__Table_sym(g->table, node.expr_type); + v__ast__Type unwrapped_node_typ = v__gen__c__Gen_unwrap_generic(g, node.typ); + string styp = v__gen__c__Gen_typ(g, unwrapped_node_typ); + v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, unwrapped_node_typ); + v__ast__TypeSymbol* expr_type_sym = v__ast__Table_sym(g->table, v__gen__c__Gen_unwrap_generic(g, node.expr_type)); if ((expr_type_sym->info)._typ == 435 /* v.ast.SumType */) { string dot = (v__ast__Type_is_ptr(node.expr_type) ? (_SLIT("->")) : (_SLIT("."))); v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("/* as */ *("), 0xfe10, {.d_s = styp}}, {_SLIT("*)__as_cast("), 0, { .d_c = 0 }}}))); @@ -71543,9 +71581,8 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_as_cast(v__gen__c__Gen* g, v__ast__AsCast no v__gen__c__Gen_expr(g, node.expr); v__gen__c__Gen_write(g, _SLIT(")")); v__gen__c__Gen_write(g, dot); - string sidx = v__gen__c__Gen_type_sidx(g, node.typ); - v__ast__TypeSymbol* expected_sym = v__ast__Table_sym(g->table, node.typ); - v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("_typ, "), 0xfe10, {.d_s = sidx}}, {_SLIT(") /*expected idx: "), 0xfe10, {.d_s = sidx}}, {_SLIT(", name: "), 0xfe10, {.d_s = expected_sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); + string sidx = v__gen__c__Gen_type_sidx(g, unwrapped_node_typ); + v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("_typ, "), 0xfe10, {.d_s = sidx}}, {_SLIT(") /*expected idx: "), 0xfe10, {.d_s = sidx}}, {_SLIT(", name: "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); for (int _t1 = 0; _t1 < (*expr_type_sym->info._v__ast__SumType).variants.len; ++_t1) { v__ast__Type variant = ((v__ast__Type*)(*expr_type_sym->info._v__ast__SumType).variants.data)[_t1]; string idx = u32_str(((u32)(variant))); @@ -71676,8 +71713,8 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_interface_table(v__gen__c__Gen* g) { int current_iinidx = iinidx_minimum_base; for (int _t2 = 0; _t2 < inter_info.types.len; ++_t2) { v__ast__Type st = ((v__ast__Type*)inter_info.types.data)[_t2]; - v__ast__TypeSymbol* st_sym = v__ast__Table_sym(g->table, st); - string cctype = v__gen__c__Gen_cc_type(g, st, true); + v__ast__TypeSymbol* st_sym = v__ast__Table_sym(g->table, v__ast__mktyp(st)); + string cctype = v__gen__c__Gen_cc_type(g, v__ast__mktyp(st), true); #if defined(CUSTOM_DEFINE_debug_interface_table) { eprintln( str_intp(4, _MOV((StrIntpData[]){{_SLIT(">> interface name: "), 0xfe10, {.d_s = isym->name}}, {_SLIT(" | concrete type: "), 0xfe10, {.d_s = Array_string_str(v__ast__Type_debug(st))}}, {_SLIT(" | st symname: "), 0xfe10, {.d_s = st_sym->name}}, {_SLIT0, 0, { .d_c = 0 }}}))); @@ -71878,8 +71915,8 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_interface_table(v__gen__c__Gen* g) { int params_start_pos = g->out.len; Array_v__ast__Param params = array_clone_to_depth(&method.params, 0); array_set(¶ms, 0, &(v__ast__Param[]) { ((v__ast__Param){(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).pos,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).name,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).is_mut,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).is_auto_rec,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).type_pos,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).is_hidden,.typ = v__ast__Type_set_nr_muls(st, 1),}) }); - multi_return_Array_string_Array_string_Array_bool mr_168158 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); - Array_string fargs = mr_168158.arg0; + multi_return_Array_string_Array_string_Array_bool mr_168560 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); + Array_string fargs = mr_168560.arg0; string parameter_name = strings__Builder_cut_last(&g->out, g->out.len - params_start_pos); if (v__ast__Type_is_ptr(st)) { parameter_name = string_trim_string_left(parameter_name, _SLIT("__shared__")); @@ -71896,8 +71933,8 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_interface_table(v__gen__c__Gen* g) { *(multi_return_v__ast__Fn_Array_v__ast__Type*) _t26.data = (multi_return_v__ast__Fn_Array_v__ast__Type){.arg0=((v__ast__Fn){.is_variadic = 0,.language = 0,.is_pub = 0,.is_ctor_new = 0,.is_deprecated = 0,.is_noreturn = 0,.is_unsafe = 0,.is_placeholder = 0,.is_main = 0,.is_test = 0,.is_keep_alive = 0,.is_method = 0,.no_body = 0,.mod = (string){.str=(byteptr)"", .is_lit=1},.file = (string){.str=(byteptr)"", .is_lit=1},.file_mode = 0,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.return_type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.return_type = 0,.receiver_type = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.params = __new_array(0, 0, sizeof(v__ast__Param)),.source_fn = 0,.usages = 0,.generic_names = __new_array(0, 0, sizeof(string)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_conditional = 0,.ctdefine_idx = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__Fn_Array_v__ast__Type mr_168622 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); - Array_v__ast__Type embed_types = mr_168622.arg1; + multi_return_v__ast__Fn_Array_v__ast__Type mr_169024 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); + Array_v__ast__Type embed_types = mr_169024.arg1; if (embed_types.len > 0 && !Array_string_contains(method_names, method.name)) { v__ast__TypeSymbol* embed_sym = v__ast__Table_sym(g->table, (*(v__ast__Type*)array_last(embed_types))); string method_name = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = embed_sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = method.name}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -86367,10 +86404,13 @@ v__ast__Type v__parser__Parser_parse_type(v__parser__Parser* p) { v__parser__Parser_error_with_pos(p, _SLIT("cannot use `mut` on struct field type"), v__token__Token_pos(&p->tok)); } } - if (p->tok.kind == v__token__Kind__key_mut || is_shared || is_atomic) { + if (p->tok.kind == v__token__Kind__key_mut || is_shared) { nr_muls++; v__parser__Parser_next(p); } + if (is_atomic) { + v__parser__Parser_next(p); + } if (p->tok.kind == v__token__Kind__mul) { v__parser__Parser_error(p, _SLIT("use `&Type` instead of `*Type` when declaring references")); v__ast__Type _t2 = 0; diff --git a/v_win.c b/v_win.c index b288ec0..1f9c173 100644 --- a/v_win.c +++ b/v_win.c @@ -1,11 +1,11 @@ -#define V_COMMIT_HASH "b81f06e36" +#define V_COMMIT_HASH "b7f2ef78b" #ifndef V_COMMIT_HASH - #define V_COMMIT_HASH "9d764cd25" + #define V_COMMIT_HASH "b81f06e36" #endif #ifndef V_CURRENT_COMMIT_HASH - #define V_CURRENT_COMMIT_HASH "b81f06e" + #define V_CURRENT_COMMIT_HASH "b7f2ef7" #endif // V comptime_definitions: @@ -66,7 +66,6 @@ typedef struct multi_return_string_string_string_string multi_return_string_stri typedef struct multi_return_int_string_string_string multi_return_int_string_string_string; typedef struct multi_return_Array_string_Array_string_Array_bool multi_return_Array_string_Array_string_Array_bool; typedef struct multi_return_u64_string multi_return_u64_string; -typedef struct multi_return_int_literal_int_literal multi_return_int_literal_int_literal; // END_multi_return_typedefs typedef struct strconv__BF_param strconv__BF_param; @@ -3951,6 +3950,15 @@ struct v__dotgraph__NewEdgeConfig { +struct v__gen__c__Type { + v__ast__Type typ; + v__ast__TypeSymbol* sym; + v__ast__Type unaliased; + v__ast__TypeSymbol* unaliased_sym; +}; + + + struct v__gen__c__StrType { string styp; v__ast__Type typ; @@ -3977,15 +3985,6 @@ struct v__gen__c__GenSafeIntegerCfg { -struct v__gen__c__Type { - v__ast__Type typ; - v__ast__TypeSymbol* sym; - v__ast__Type unaliased; - v__ast__TypeSymbol* unaliased_sym; -}; - - - struct v__pkgconfig__MainOptions { bool modversion; bool description; @@ -5999,6 +5998,7 @@ struct v__gen__c__Gen { __shared__Map_string_bool* referenced_fns; int nr_closures; v__ast__Type expected_cast_type; + v__ast__Type or_expr_return_type; bool anon_fn; bool tests_inited; bool has_main; @@ -6337,11 +6337,6 @@ struct multi_return_u64_string { string arg1; }; -struct multi_return_int_literal_int_literal { - int_literal arg0; - int_literal arg1; -}; - // END_multi_return_structs @@ -6927,7 +6922,7 @@ void strconv__format_str_sb(string s, strconv__BF_param p, strings__Builder* sb) #define _const_strconv__max_size_f64_char 32 string _const_strconv__digit_pairs; // a string literal, inited later void strconv__format_dec_sb(u64 d, strconv__BF_param p, strings__Builder* res); -string strconv__f64_to_str_lnd1(f64 f, int dec_digit); +VV_LOCAL_SYMBOL string strconv__f64_to_str_lnd1(f64 f, int dec_digit); string strconv__format_fl(f64 f, strconv__BF_param p); string strconv__format_es(f64 f, strconv__BF_param p); string strconv__remove_tail_zeros(string s); @@ -6977,8 +6972,8 @@ string strconv__v_sprintf(string str, Array_voidptr pt); VV_LOCAL_SYMBOL void strconv__v_sprintf_panic(int idx, int len); VV_LOCAL_SYMBOL f64 strconv__fabs(f64 x); string strconv__format_fl_old(f64 f, strconv__BF_param p); -string strconv__format_es_old(f64 f, strconv__BF_param p); -string strconv__remove_tail_zeros_old(string s); +VV_LOCAL_SYMBOL string strconv__format_es_old(f64 f, strconv__BF_param p); +VV_LOCAL_SYMBOL string strconv__remove_tail_zeros_old(string s); string strconv__format_dec_old(u64 d, strconv__BF_param p); VV_LOCAL_SYMBOL array __new_array(int mylen, int cap, int elm_size); VV_LOCAL_SYMBOL array __new_array_with_default(int mylen, int cap, int elm_size, voidptr val); @@ -7170,6 +7165,7 @@ Array_u8 Array_u8_clone(Array_u8 b); string Array_u8_bytestr(Array_u8 b); Option_rune Array_u8_byterune(Array_u8 b); string u8_repeat(u8 b, int count); +VV_LOCAL_SYMBOL string _Atomic__int_str(int x); VV_LOCAL_SYMBOL bool fast_string_eq(string a, string b); VV_LOCAL_SYMBOL u64 map_hash_string(voidptr pkey); VV_LOCAL_SYMBOL u64 map_hash_int_1(voidptr pkey); @@ -9159,6 +9155,8 @@ void v__markused__Walker_struct_fields(v__markused__Walker* w, Array_v__ast__Str void v__markused__Walker_const_fields(v__markused__Walker* w, Array_v__ast__ConstField cfields); void v__markused__Walker_or_block(v__markused__Walker* w, v__ast__OrExpr node); VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayInit node); +VV_LOCAL_SYMBOL void v__gen__c__Gen_fixed_array_init(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type array_type); +VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init_with_fields(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type elem_type, bool is_amp, string shared_styp); VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_array_map(v__gen__c__Gen* g, v__ast__CallExpr node); VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_array_sort(v__gen__c__Gen* g, v__ast__CallExpr node); VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_array_sort_call(v__gen__c__Gen* g, v__ast__CallExpr node, string compare_fn); @@ -12311,7 +12309,7 @@ static int v_typeof_interface_idx_IError(int sidx) { /* IError */ if (sidx == _IError_os__FileNotOpenedError_index) return 65657; if (sidx == _IError_os__SizeOfTypeIs0Error_index) return 65658; if (sidx == _IError_os__ExecutableNotFoundError_index) return 65672; - if (sidx == _IError_v__gen__c__UnsupportedAssertCtempTransform_index) return 536; + if (sidx == _IError_v__gen__c__UnsupportedAssertCtempTransform_index) return 537; return 29; } static char * v_typeof_interface_rand__PRNG(int sidx) { /* rand.PRNG */ @@ -14353,9 +14351,9 @@ string strconv__f32_to_str(f32 f, int n_digit) { if ((exp == _const_strconv__maxexp32) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec32_bool mr_8747 = strconv__f32_to_decimal_exact_int(mant, exp); - strconv__Dec32 d = mr_8747.arg0; - bool ok = mr_8747.arg1; + multi_return_strconv__Dec32_bool mr_8753 = strconv__f32_to_decimal_exact_int(mant, exp); + strconv__Dec32 d = mr_8753.arg0; + bool ok = mr_8753.arg1; if (!ok) { d = strconv__f32_to_decimal(mant, exp); } @@ -14372,9 +14370,9 @@ string strconv__f32_to_str_pad(f32 f, int n_digit) { if ((exp == _const_strconv__maxexp32) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec32_bool mr_9521 = strconv__f32_to_decimal_exact_int(mant, exp); - strconv__Dec32 d = mr_9521.arg0; - bool ok = mr_9521.arg1; + multi_return_strconv__Dec32_bool mr_9537 = strconv__f32_to_decimal_exact_int(mant, exp); + strconv__Dec32 d = mr_9537.arg0; + bool ok = mr_9537.arg1; if (!ok) { d = strconv__f32_to_decimal(mant, exp); } @@ -14627,9 +14625,9 @@ string strconv__f64_to_str(f64 f, int n_digit) { if ((exp == _const_strconv__maxexp64) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec64_bool mr_9304 = strconv__f64_to_decimal_exact_int(mant, exp); - strconv__Dec64 d = mr_9304.arg0; - bool ok = mr_9304.arg1; + multi_return_strconv__Dec64_bool mr_9324 = strconv__f64_to_decimal_exact_int(mant, exp); + strconv__Dec64 d = mr_9324.arg0; + bool ok = mr_9324.arg1; if (!ok) { d = strconv__f64_to_decimal(mant, exp); } @@ -14646,9 +14644,9 @@ string strconv__f64_to_str_pad(f64 f, int n_digit) { if ((exp == _const_strconv__maxexp64) || (exp == 0U && mant == 0U)) { return strconv__get_string_special(neg, exp == 0U, mant == 0U); } - multi_return_strconv__Dec64_bool mr_10057 = strconv__f64_to_decimal_exact_int(mant, exp); - strconv__Dec64 d = mr_10057.arg0; - bool ok = mr_10057.arg1; + multi_return_strconv__Dec64_bool mr_10097 = strconv__f64_to_decimal_exact_int(mant, exp); + strconv__Dec64 d = mr_10097.arg0; + bool ok = mr_10097.arg1; if (!ok) { d = strconv__f64_to_decimal(mant, exp); } @@ -14781,7 +14779,7 @@ void strconv__format_dec_sb(u64 d, strconv__BF_param p, strings__Builder* res) { // Attr: [direct_array_access] // Attr: [manualfree] -string strconv__f64_to_str_lnd1(f64 f, int dec_digit) { +VV_LOCAL_SYMBOL string strconv__f64_to_str_lnd1(f64 f, int dec_digit) { { // Unsafe block string s = strconv__f64_to_str(f + ((f64*)_const_strconv__dec_round.data)[dec_digit], 18); if (s.len > 2 && (s.str[ 0] == 'n' || s.str[ 1] == 'i')) { @@ -16215,7 +16213,7 @@ strings__Builder res; } // Attr: [manualfree] -string strconv__format_es_old(f64 f, strconv__BF_param p) { +VV_LOCAL_SYMBOL string strconv__format_es_old(f64 f, strconv__BF_param p) { bool strconv__format_es_old_defer_0 = false; strings__Builder res; string fs; @@ -16286,7 +16284,7 @@ string s; return (string){.str=(byteptr)"", .is_lit=1}; } -string strconv__remove_tail_zeros_old(string s) { +VV_LOCAL_SYMBOL string strconv__remove_tail_zeros_old(string s) { int i = 0; int last_zero_start = -1; int dot_pos = -1; @@ -18421,6 +18419,10 @@ string u8_repeat(u8 b, int count) { return u8_vstring_with_len(ret, new_len); } +VV_LOCAL_SYMBOL string _Atomic__int_str(int x) { + return int_str(x); +} + // Attr: [inline] inline VV_LOCAL_SYMBOL bool fast_string_eq(string a, string b) { if (a.len != b.len) { @@ -33632,7 +33634,7 @@ void v__pref__Preferences_fill_with_defaults(v__pref__Preferences* p) { if ((p->third_party_option).len == 0) { p->third_party_option = p->cflags; } - string vhash = _SLIT("9d764cd25"); + string vhash = _SLIT("b81f06e36"); p->cache_manager = v__vcache__new_cache_manager(new_array_from_c_array(7, 7, sizeof(string), _MOV((string[7]){string_clone(vhash), str_intp(6, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = v__pref__Backend_str(p->backend)}}, {_SLIT(" | "), 0xfe10, {.d_s = v__pref__OS_str(p->os)}}, {_SLIT(" | "), 0xfe10, {.d_s = p->ccompiler}}, {_SLIT(" | "), 0xfe10, {.d_s = p->is_prod ? _SLIT("true") : _SLIT("false")}}, {_SLIT(" | "), 0xfe10, {.d_s = p->sanitize ? _SLIT("true") : _SLIT("false")}}, {_SLIT0, 0, { .d_c = 0 }}})), string_clone(string_trim_space(p->cflags)), string_clone(string_trim_space(p->third_party_option)), string_clone(Array_string_str(p->compile_defines_all)), string_clone(Array_string_str(p->compile_defines)), string_clone(Array_string_str(p->lookup_path))}))); if (string__eq(os__user_os(), _SLIT("windows"))) { p->use_cache = false; @@ -35233,7 +35235,7 @@ VV_LOCAL_SYMBOL ChanState sync__Channel_try_push_priv(sync__Channel* ch, voidptr ChanState _t1 = ChanState__closed; return _t1; } - multi_return_int_literal_int_literal mr_4420 = (no_block ? ((multi_return_int_literal_int_literal){.arg0=1,.arg1=1}) : ((multi_return_int_literal_int_literal){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); + multi_return_int_int mr_4420 = (no_block ? ((multi_return_int_int){.arg0=1,.arg1=1}) : ((multi_return_int_int){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); int spinloops_sem_ = mr_4420.arg0; int spinloops_ = mr_4420.arg1; bool have_swapped = false; @@ -35422,7 +35424,7 @@ inline ChanState sync__Channel_try_pop(sync__Channel* ch, voidptr dest) { } VV_LOCAL_SYMBOL ChanState sync__Channel_try_pop_priv(sync__Channel* ch, voidptr dest, bool no_block) { - multi_return_int_literal_int_literal mr_9405 = (no_block ? ((multi_return_int_literal_int_literal){.arg0=1,.arg1=1}) : ((multi_return_int_literal_int_literal){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); + multi_return_int_int mr_9405 = (no_block ? ((multi_return_int_int){.arg0=1,.arg1=1}) : ((multi_return_int_int){.arg0=_const_sync__spinloops,.arg1=_const_sync__spinloops_sem})); int spinloops_sem_ = mr_9405.arg0; int spinloops_ = mr_9405.arg1; bool have_swapped = false; @@ -39101,7 +39103,7 @@ Option_bool v__ast__Table_parse_cflag(v__ast__Table* t, string cflg, string mod, return (Option_bool){ .state=2, .err=_const_none__, .data={EMPTY_STRUCT_INITIALIZATION} }; } string fos = _SLIT(""); - Array_string allowed_os_overrides = new_array_from_c_array(6, 6, sizeof(string), _MOV((string[6]){_SLIT("linux"), _SLIT("darwin"), _SLIT("freebsd"), _SLIT("windows"), _SLIT("mingw"), _SLIT("solaris")})); + Array_string allowed_os_overrides = new_array_from_c_array(7, 7, sizeof(string), _MOV((string[7]){_SLIT("linux"), _SLIT("darwin"), _SLIT("freebsd"), _SLIT("openbsd"), _SLIT("windows"), _SLIT("mingw"), _SLIT("solaris")})); _PUSH_MANY(&allowed_os_overrides, (ctimedefines), _t2, Array_string); for (int _t3 = 0; _t3 < allowed_os_overrides.len; ++_t3) { string os_override = ((string*)allowed_os_overrides.data)[_t3]; @@ -41872,10 +41874,10 @@ int v__ast__Table_find_or_register_multi_return(v__ast__Table* t, Array_v__ast__ string cname = _SLIT("multi_return"); for (int i = 0; i < mr_typs.len; ++i) { v__ast__Type mr_typ = ((v__ast__Type*)mr_typs.data)[i]; - v__ast__TypeSymbol* mr_type_sym = v__ast__Table_sym(t, mr_typ); - multi_return_string_string mr_31198 = (v__ast__Type_is_ptr(mr_typ) ? ((multi_return_string_string){.arg0=_SLIT("&"),.arg1=_SLIT("ref_")}) : ((multi_return_string_string){.arg0=_SLIT(""),.arg1=_SLIT("")})); - string ref = mr_31198.arg0; - string cref = mr_31198.arg1; + v__ast__TypeSymbol* mr_type_sym = v__ast__Table_sym(t, v__ast__mktyp(mr_typ)); + multi_return_string_string mr_31205 = (v__ast__Type_is_ptr(mr_typ) ? ((multi_return_string_string){.arg0=_SLIT("&"),.arg1=_SLIT("ref_")}) : ((multi_return_string_string){.arg0=_SLIT(""),.arg1=_SLIT("")})); + string ref = mr_31205.arg0; + string cref = mr_31205.arg1; name = /*f*/string__plus(name, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ref}}, {_SLIT0, 0xfe10, {.d_s = mr_type_sym->name}}, {_SLIT0, 0, { .d_c = 0 }}}))); cname = /*f*/string__plus(cname, str_intp(3, _MOV((StrIntpData[]){{_SLIT("_"), 0xfe10, {.d_s = cref}}, {_SLIT0, 0xfe10, {.d_s = mr_type_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}}))); if (i < mr_typs.len - 1) { @@ -43276,7 +43278,7 @@ string v__ast__Type_atomic_typename(v__ast__Type t) { return _t1; } else if (idx == (_const_v__ast__int_type_idx)) { - string _t2 = _SLIT("atomic_int"); + string _t2 = _SLIT("_Atomic int"); return _t2; } else if (idx == (_const_v__ast__u64_type_idx)) { @@ -44363,6 +44365,10 @@ string v__ast__Table_type_to_str_using_aliases(v__ast__Table* t, v__ast__Type ty nr_muls--; res = string__plus(_SLIT("shared "), res); } + if (v__ast__Type_has_flag(typ, v__ast__TypeFlag__atomic_f)) { + nr_muls--; + res = string__plus(_SLIT("atomic "), res); + } if (nr_muls > 0 && !v__ast__Type_has_flag(typ, v__ast__TypeFlag__variadic)) { res = string__plus(strings__repeat('&', nr_muls), res); } @@ -45636,105 +45642,109 @@ bool v__checker__Checker_check_types(v__checker__Checker* c, v__ast__Type got, v bool _t3 = true; return _t3; } + if (v__ast__Type_alias_eq(expected, _const_v__ast__bool_type) && (v__ast__Type_is_any_kind_of_pointer(got) || v__ast__Type_is_int(got))) { + bool _t4 = true; + return _t4; + } if (v__ast__Type_is_any_kind_of_pointer(expected)) { v__ast__Type deref = v__ast__Type_deref(expected); v__ast__TypeSymbol* got_sym = v__ast__Table_sym(c->table, got); if (v__ast__Type_is_number(deref) && (v__ast__TypeSymbol_is_number(got_sym) || got_sym->kind == v__ast__Kind__enum_)) { - bool _t4 = true; - return _t4; + bool _t5 = true; + return _t5; } } v__ast__TypeSymbol* got_sym = v__ast__Table_sym(c->table, got); v__ast__TypeSymbol* expected_sym = v__ast__Table_sym(c->table, expected); if (got_sym->kind == v__ast__Kind__enum_) { - if (v__ast__TypeSymbol_is_number(expected_sym)) { - bool _t5 = true; - return _t5; - } - } else if (got_sym->kind == v__ast__Kind__array_fixed) { if (v__ast__TypeSymbol_is_number(expected_sym)) { bool _t6 = true; return _t6; } + } else if (got_sym->kind == v__ast__Kind__array_fixed) { + if (v__ast__TypeSymbol_is_number(expected_sym)) { + bool _t7 = true; + return _t7; + } } if (expected_sym->kind == v__ast__Kind__enum_ && v__ast__TypeSymbol_is_number(got_sym)) { - bool _t7 = true; - return _t7; + bool _t8 = true; + return _t8; } if (got_is_ptr && exp_is_ptr) { if (v__ast__TypeSymbol_is_number(expected_sym) && v__ast__TypeSymbol_is_number(got_sym)) { - bool _t8 = true; - return _t8; + bool _t9 = true; + return _t9; } } } if (got_is_ptr && exp_is_ptr) { if (v__ast__Type_nr_muls(got) != v__ast__Type_nr_muls(expected)) { - bool _t9 = false; - return _t9; + bool _t10 = false; + return _t10; } } int exp_idx = v__ast__Type_idx(expected); int got_idx = v__ast__Type_idx(got); if (exp_idx == got_idx) { - bool _t10 = true; - return _t10; + bool _t11 = true; + return _t11; } if (exp_idx == _const_v__ast__voidptr_type_idx || exp_idx == _const_v__ast__byteptr_type_idx || (v__ast__Type_is_ptr(expected) && v__ast__Type_idx(v__ast__Type_deref(expected)) == _const_v__ast__byte_type_idx)) { if (v__ast__Type_is_ptr(got) || v__ast__Type_is_pointer(got)) { - bool _t11 = true; - return _t11; - } - } - if (v__ast__Type_is_real_pointer(expected)) { - if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type)) { bool _t12 = true; return _t12; } } - if (got_idx == _const_v__ast__voidptr_type_idx || got_idx == _const_v__ast__byteptr_type_idx || (got_idx == _const_v__ast__byte_type_idx && v__ast__Type_is_ptr(got))) { - if (v__ast__Type_is_ptr(expected) || v__ast__Type_is_pointer(expected)) { + if (v__ast__Type_is_real_pointer(expected)) { + if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type)) { bool _t13 = true; return _t13; } } + if (got_idx == _const_v__ast__voidptr_type_idx || got_idx == _const_v__ast__byteptr_type_idx || (got_idx == _const_v__ast__byte_type_idx && v__ast__Type_is_ptr(got))) { + if (v__ast__Type_is_ptr(expected) || v__ast__Type_is_pointer(expected)) { + bool _t14 = true; + return _t14; + } + } if (v__ast__Type_alias_eq(expected, _const_v__ast__charptr_type) && v__ast__Type_alias_eq(got, v__ast__Type_ref(_const_v__ast__char_type))) { - bool _t14 = true; - return _t14; + bool _t15 = true; + return _t15; } if (v__ast__Type_has_flag(expected, v__ast__TypeFlag__optional)) { v__ast__TypeSymbol* sym = v__ast__Table_sym(c->table, got); if (sym->idx == _const_v__ast__error_type_idx || (v__ast__Type_alias_eq(got, _const_v__ast__none_type) || v__ast__Type_alias_eq(got, _const_v__ast__error_type))) { - bool _t15 = true; - return _t15; - } else if (!v__checker__Checker_check_basic(c, got, v__ast__Type_clear_flag(expected, v__ast__TypeFlag__optional))) { - bool _t16 = false; + bool _t16 = true; return _t16; + } else if (!v__checker__Checker_check_basic(c, got, v__ast__Type_clear_flag(expected, v__ast__TypeFlag__optional))) { + bool _t17 = false; + return _t17; } } if (!v__checker__Checker_check_basic(c, got, expected)) { - bool _t17 = false; - return _t17; + bool _t18 = false; + return _t18; } if (v__ast__Type_is_number(got) && v__ast__Type_is_number(expected)) { if (v__ast__Type_alias_eq(got, _const_v__ast__rune_type) && v__ast__Type_alias_eq(expected, _const_v__ast__byte_type)) { - bool _t18 = true; - return _t18; - } else if (v__ast__Type_alias_eq(expected, _const_v__ast__rune_type) && v__ast__Type_alias_eq(got, _const_v__ast__byte_type)) { bool _t19 = true; return _t19; + } else if (v__ast__Type_alias_eq(expected, _const_v__ast__rune_type) && v__ast__Type_alias_eq(got, _const_v__ast__byte_type)) { + bool _t20 = true; + return _t20; } if (!v__ast__Type_alias_eq(v__checker__Checker_promote_num(c, expected, got), expected)) { - bool _t20 = false; - return _t20; + bool _t21 = false; + return _t21; } } if (v__ast__Type_has_flag(expected, v__ast__TypeFlag__generic)) { - bool _t21 = false; - return _t21; + bool _t22 = false; + return _t22; } - bool _t22 = true; - return _t22; + bool _t23 = true; + return _t23; } Option_void v__checker__Checker_check_expected_call_arg(v__checker__Checker* c, v__ast__Type got, v__ast__Type expected_, v__ast__Language language, v__ast__CallArg arg) { @@ -45842,43 +45852,69 @@ bool v__checker__Checker_check_basic(v__checker__Checker* c, v__ast__Type got, v } v__ast__TypeSymbol* got_sym = v__ast__Table_sym(c->table, got); v__ast__TypeSymbol* exp_sym = v__ast__Table_sym(c->table, expected); - if ((got_sym->kind == v__ast__Kind__array || got_sym->kind == v__ast__Kind__map || got_sym->kind == v__ast__Kind__array_fixed) && exp_sym->kind == got_sym->kind) { - if (string__eq(v__ast__Table_type_to_str(c->table, got), string_trim(v__ast__Table_type_to_str(c->table, expected), _SLIT("&")))) { - bool _t5 = true; - return _t5; + if (exp_sym->kind == v__ast__Kind__multi_return && got_sym->kind == v__ast__Kind__multi_return) { + Array_v__ast__Type exp_types = v__ast__TypeSymbol_mr_info(exp_sym).types; + Array_v__ast__Type _t5 = {0}; + Array_v__ast__Type _t5_orig = v__ast__TypeSymbol_mr_info(got_sym).types; + int _t5_len = _t5_orig.len; + _t5 = __new_array(0, _t5_len, sizeof(v__ast__Type)); + + for (int _t6 = 0; _t6 < _t5_len; ++_t6) { + v__ast__Type it = ((v__ast__Type*) _t5_orig.data)[_t6]; + v__ast__Type ti = v__ast__mktyp(it); + array_push((array*)&_t5, &ti); + } + Array_v__ast__Type got_types =_t5; + if (exp_types.len != got_types.len) { + bool _t7 = false; + return _t7; + } + for (int i = 0; i < exp_types.len; ++i) { + if (!v__checker__Checker_check_types(c, (*(v__ast__Type*)/*ee elem_sym */array_get(got_types, i)), (*(v__ast__Type*)/*ee elem_sym */array_get(exp_types, i)))) { + bool _t8 = false; + return _t8; + } } - } - if (!v__ast__Type_is_ptr(unalias_got) && got_sym->kind == v__ast__Kind__array_fixed && (v__ast__Type_is_pointer(unalias_expected) || v__ast__Type_is_ptr(unalias_expected))) { - bool _t6 = false; - return _t6; - } - if ((exp_sym->kind == v__ast__Kind__voidptr || exp_sym->kind == v__ast__Kind__any) || (got_sym->kind == v__ast__Kind__voidptr || got_sym->kind == v__ast__Kind__any)) { - bool _t7 = true; - return _t7; - } - if (v__ast__Table_sumtype_has_variant(c->table, expected, v__ast__mktyp(got), false)) { - bool _t8 = true; - return _t8; - } - if ((got_sym->kind == v__ast__Kind__alias && got_sym->parent_idx == v__ast__Type_idx(expected)) || (exp_sym->kind == v__ast__Kind__alias && exp_sym->parent_idx == v__ast__Type_idx(got))) { bool _t9 = true; return _t9; } - if (got_sym->kind == v__ast__Kind__function && exp_sym->kind == v__ast__Kind__function) { - bool _t10 = v__checker__Checker_check_matching_function_symbols(c, got_sym, exp_sym); - return _t10; + if ((got_sym->kind == v__ast__Kind__array || got_sym->kind == v__ast__Kind__map || got_sym->kind == v__ast__Kind__array_fixed) && exp_sym->kind == got_sym->kind) { + if (string__eq(v__ast__Table_type_to_str(c->table, got), string_trim(v__ast__Table_type_to_str(c->table, expected), _SLIT("&")))) { + bool _t10 = true; + return _t10; + } } - v__ast__Type expected_nonflagged = v__ast__Type_clear_flags(expected); - if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type) && v__ast__Type_is_int(expected_nonflagged)) { - bool _t11 = true; + if (!v__ast__Type_is_ptr(unalias_got) && got_sym->kind == v__ast__Kind__array_fixed && (v__ast__Type_is_pointer(unalias_expected) || v__ast__Type_is_ptr(unalias_expected))) { + bool _t11 = false; return _t11; } - if (v__ast__Type_alias_eq(got, _const_v__ast__float_literal_type) && v__ast__Type_is_float(expected_nonflagged)) { + if ((exp_sym->kind == v__ast__Kind__voidptr || exp_sym->kind == v__ast__Kind__any) || (got_sym->kind == v__ast__Kind__voidptr || got_sym->kind == v__ast__Kind__any)) { bool _t12 = true; return _t12; } - bool _t13 = false; - return _t13; + if (v__ast__Table_sumtype_has_variant(c->table, expected, v__ast__mktyp(got), false)) { + bool _t13 = true; + return _t13; + } + if ((got_sym->kind == v__ast__Kind__alias && got_sym->parent_idx == v__ast__Type_idx(expected)) || (exp_sym->kind == v__ast__Kind__alias && exp_sym->parent_idx == v__ast__Type_idx(got))) { + bool _t14 = true; + return _t14; + } + if (got_sym->kind == v__ast__Kind__function && exp_sym->kind == v__ast__Kind__function) { + bool _t15 = v__checker__Checker_check_matching_function_symbols(c, got_sym, exp_sym); + return _t15; + } + v__ast__Type expected_nonflagged = v__ast__Type_clear_flags(expected); + if (v__ast__Type_alias_eq(got, _const_v__ast__int_literal_type) && v__ast__Type_is_int(expected_nonflagged)) { + bool _t16 = true; + return _t16; + } + if (v__ast__Type_alias_eq(got, _const_v__ast__float_literal_type) && v__ast__Type_is_float(expected_nonflagged)) { + bool _t17 = true; + return _t17; + } + bool _t18 = false; + return _t18; } bool v__checker__Checker_check_matching_function_symbols(v__checker__Checker* c, v__ast__TypeSymbol* got_type_sym, v__ast__TypeSymbol* exp_type_sym) { @@ -46051,10 +46087,10 @@ VV_LOCAL_SYMBOL v__ast__Type v__checker__Checker_promote_num(v__checker__Checker v__ast__Type type_hi = left_type; v__ast__Type type_lo = right_type; if (v__ast__Type_idx(type_hi) < v__ast__Type_idx(type_lo)) { - v__ast__Type _var_16316 = type_hi; - v__ast__Type _var_16325 = type_lo; - type_hi = _var_16325; - type_lo = _var_16316; + v__ast__Type _var_16786 = type_hi; + v__ast__Type _var_16795 = type_lo; + type_hi = _var_16795; + type_lo = _var_16786; } int idx_hi = v__ast__Type_idx(type_hi); int idx_lo = v__ast__Type_idx(type_lo); @@ -47088,7 +47124,9 @@ v__ast__Type former_expected_type; if ((left_sym->info)._typ == 470 /* v.ast.Alias */ && (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 470) /*expected idx: 470, name: v.ast.Alias */ ).language != v__ast__Language__c && string__eq(c->mod, (*(string*)/*ee elem_sym */array_get(string_split(v__ast__Table_type_to_str(c->table, left_type), _SLIT(".")), 0))) && v__ast__TypeSymbol_is_primitive(v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 470) /*expected idx: 470, name: v.ast.Alias */ ).parent_type))) { left_sym = v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 470) /*expected idx: 470, name: v.ast.Alias */ ).parent_type); } - if (!c->pref->translated && left_sym->kind == v__ast__Kind__alias && (left_sym->info)._typ == 470 /* v.ast.Alias */ && !(v__ast__TypeSymbol_is_primitive(v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 470) /*expected idx: 470, name: v.ast.Alias */ ).parent_type)))) { + if (c->pref->translated && (node->op == v__token__Kind__plus || node->op == v__token__Kind__minus || node->op == v__token__Kind__mul) && v__ast__Type_is_any_kind_of_pointer(left_type) && (v__ast__Type_is_any_kind_of_pointer(right_type) || v__ast__Type_is_int(right_type))) { + return_type = left_type; + } else if (!c->pref->translated && left_sym->kind == v__ast__Kind__alias && (left_sym->info)._typ == 470 /* v.ast.Alias */ && !(v__ast__TypeSymbol_is_primitive(v__ast__Table_sym(c->table, (/* as */ *(v__ast__Alias*)__as_cast((left_sym->info)._v__ast__Alias,(left_sym->info)._typ, 470) /*expected idx: 470, name: v.ast.Alias */ ).parent_type)))) { if (v__ast__TypeSymbol_has_method(left_sym, v__token__Kind_str(node->op))) { Option_v__ast__Fn _t5; if (_t5 = v__ast__TypeSymbol_find_method(left_sym, v__token__Kind_str(node->op)), _t5.state == 0) { @@ -47280,8 +47318,8 @@ v__ast__Type former_expected_type; v__checker__Checker_error(c, _SLIT("array append cannot be used in an expression"), node->pos); } v__checker__Checker_check_expr_opt_call(c, node->right, right_type); - multi_return_string_v__token__Pos mr_33737 = v__checker__Checker_fail_if_immutable(c, node->left); - node->auto_locked = mr_33737.arg0; + multi_return_string_v__token__Pos mr_33947 = v__checker__Checker_fail_if_immutable(c, node->left); + node->auto_locked = mr_33947.arg0; v__ast__Type left_value_type = v__ast__Table_value_type(c->table, v__checker__Checker_unwrap_generic(c, left_type)); v__ast__TypeSymbol* left_value_sym = v__ast__Table_sym(c->table, v__checker__Checker_unwrap_generic(c, left_value_type)); if (left_value_sym->kind == v__ast__Kind__interface_) { @@ -47717,19 +47755,19 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im if (v__ast__Type_has_flag(elem_type, v__ast__TypeFlag__shared_f)) { v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("you have to create a handle and `lock` it to modify `shared` "), 0xfe10, {.d_s = kind}}, {_SLIT(" element"), 0, { .d_c = 0 }}})), v__token__Pos_extend(v__ast__Expr_pos((*expr._v__ast__IndexExpr).left), (*expr._v__ast__IndexExpr).pos)); } - multi_return_string_v__token__Pos mr_44113 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); - to_lock = mr_44113.arg0; - pos = mr_44113.arg1; + multi_return_string_v__token__Pos mr_44323 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); + to_lock = mr_44323.arg0; + pos = mr_44323.arg1; } else if (expr._typ == 320 /* v.ast.ParExpr */) { - multi_return_string_v__token__Pos mr_44182 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); - to_lock = mr_44182.arg0; - pos = mr_44182.arg1; + multi_return_string_v__token__Pos mr_44392 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); + to_lock = mr_44392.arg0; + pos = mr_44392.arg1; } else if (expr._typ == 322 /* v.ast.PrefixExpr */) { - multi_return_string_v__token__Pos mr_44254 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); - to_lock = mr_44254.arg0; - pos = mr_44254.arg1; + multi_return_string_v__token__Pos mr_44464 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); + to_lock = mr_44464.arg0; + pos = mr_44464.arg1; } else if (expr._typ == 325 /* v.ast.SelectorExpr */) { if ((*expr._v__ast__SelectorExpr).expr_type == 0) { @@ -47779,9 +47817,9 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im string type_str = v__ast__Table_type_to_str(c->table, (*expr._v__ast__SelectorExpr).expr_type); v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("field `"), 0xfe10, {.d_s = (*expr._v__ast__SelectorExpr).field_name}}, {_SLIT("` of struct `"), 0xfe10, {.d_s = type_str}}, {_SLIT("` is immutable"), 0, { .d_c = 0 }}})), (*expr._v__ast__SelectorExpr).pos); } - multi_return_string_v__token__Pos mr_45718 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); - to_lock = mr_45718.arg0; - pos = mr_45718.arg1; + multi_return_string_v__token__Pos mr_45928 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); + to_lock = mr_45928.arg0; + pos = mr_45928.arg1; } if ((to_lock).len != 0) { explicit_lock_needed = true; @@ -47887,9 +47925,9 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im } else if (expr._typ == 291 /* v.ast.CallExpr */) { if (string__eq((*expr._v__ast__CallExpr).name, _SLIT("slice"))) { - multi_return_string_v__token__Pos mr_47541 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); - to_lock = mr_47541.arg0; - pos = mr_47541.arg1; + multi_return_string_v__token__Pos mr_47751 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); + to_lock = mr_47751.arg0; + pos = mr_47751.arg1; if ((to_lock).len != 0) { explicit_lock_needed = true; } @@ -48288,9 +48326,9 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t13.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.has_default_expr = 0,.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_pub = 0,.default_val = (string){.str=(byteptr)"", .is_lit=1},.is_mut = 0,.is_global = 0,.is_volatile = 0,.default_expr = {0},.default_expr_typ = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.typ = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_60742 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); - field = mr_60742.arg0; - embed_types = mr_60742.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_60952 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); + field = mr_60952.arg0; + embed_types = mr_60952.arg1; node->from_embed_types = embed_types; if (sym->kind == v__ast__Kind__aggregate || sym->kind == v__ast__Kind__sum_type) { unknown_field_msg = IError_name_table[err._typ]._method_msg(err._object); @@ -48324,9 +48362,9 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t15.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.has_default_expr = 0,.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_pub = 0,.default_val = (string){.str=(byteptr)"", .is_lit=1},.is_mut = 0,.is_global = 0,.is_volatile = 0,.default_expr = {0},.default_expr_typ = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.typ = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_61573 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); - field = mr_61573.arg0; - embed_types = mr_61573.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_61783 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); + field = mr_61783.arg0; + embed_types = mr_61783.arg1; node->from_embed_types = embed_types; } } @@ -50550,8 +50588,8 @@ v__ast__Type v__checker__Checker_postfix_expr(v__checker__Checker* c, v__ast__Po string typ_str = v__ast__Table_type_to_str(c->table, typ); v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("invalid operation: "), 0xfe10, {.d_s = v__token__Kind_str(node->op)}}, {_SLIT(" (non-numeric type `"), 0xfe10, {.d_s = typ_str}}, {_SLIT("`)"), 0, { .d_c = 0 }}})), node->pos); } else { - multi_return_string_v__token__Pos mr_115806 = v__checker__Checker_fail_if_immutable(c, node->expr); - node->auto_locked = mr_115806.arg0; + multi_return_string_v__token__Pos mr_116016 = v__checker__Checker_fail_if_immutable(c, node->expr); + node->auto_locked = mr_116016.arg0; } v__ast__Type _t1 = typ; return _t1; @@ -50723,7 +50761,7 @@ v__ast__Type v__checker__Checker_prefix_expr(v__checker__Checker* c, v__ast__Pre VV_LOCAL_SYMBOL void v__checker__Checker_check_index(v__checker__Checker* c, v__ast__TypeSymbol* typ_sym, v__ast__Expr index, v__ast__Type index_type, v__token__Pos pos, bool range_index, bool is_gated) { v__ast__TypeSymbol* index_type_sym = v__ast__Table_sym(c->table, index_type); if (typ_sym->kind == v__ast__Kind__array || typ_sym->kind == v__ast__Kind__array_fixed || typ_sym->kind == v__ast__Kind__string) { - if (!(v__ast__Type_is_int(index_type) || index_type_sym->kind == v__ast__Kind__enum_)) { + if (!(v__ast__Type_is_int(index_type) || index_type_sym->kind == v__ast__Kind__enum_ || (index_type_sym->kind == v__ast__Kind__alias && v__ast__Type_is_int((/* as */ *(v__ast__Alias*)__as_cast((index_type_sym->info)._v__ast__Alias,(index_type_sym->info)._typ, 470) /*expected idx: 470, name: v.ast.Alias */ ).parent_type)))) { string type_str = (typ_sym->kind == v__ast__Kind__string ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("non-integer string index `"), 0xfe10, {.d_s = index_type_sym->name}}, {_SLIT("`"), 0, { .d_c = 0 }}}))) : ( str_intp(3, _MOV((StrIntpData[]){{_SLIT("non-integer index `"), 0xfe10, {.d_s = index_type_sym->name}}, {_SLIT("` (array type `"), 0xfe10, {.d_s = typ_sym->name}}, {_SLIT("`)"), 0, { .d_c = 0 }}})))); v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = type_str}}, {_SLIT0, 0, { .d_c = 0 }}})), pos); } @@ -55321,7 +55359,7 @@ VV_LOCAL_SYMBOL void v__checker__Checker_for_in_stmt(v__checker__Checker* c, v__ if (node->is_range) { v__ast__Type high_type = v__checker__Checker_expr(c, node->high); int high_type_idx = v__ast__Type_idx(high_type); - if (Array_int_contains(_const_v__ast__integer_type_idxs, typ_idx) && !Array_int_contains(_const_v__ast__integer_type_idxs, high_type_idx)) { + if (Array_int_contains(_const_v__ast__integer_type_idxs, typ_idx) && !Array_int_contains(_const_v__ast__integer_type_idxs, high_type_idx) && high_type_idx != _const_v__ast__void_type_idx) { v__checker__Checker_error(c, _SLIT("range types do not match"), v__ast__Expr_pos(node->cond)); } else if (Array_int_contains(_const_v__ast__float_type_idxs, typ_idx) || Array_int_contains(_const_v__ast__float_type_idxs, high_type_idx)) { v__checker__Checker_error(c, _SLIT("range type can not be float"), v__ast__Expr_pos(node->cond)); @@ -55659,35 +55697,16 @@ bool v__checker__Checker_if_expr_defer_0 = false; if (v__checker__is_noreturn_callexpr(last_expr.expr)) { continue; } - v__ast__TypeSymbol* node_sym = v__ast__Table_sym(c->table, node->typ); - v__ast__TypeSymbol* last_sym = v__ast__Table_sym(c->table, last_expr.typ); - if (node_sym->kind == v__ast__Kind__multi_return && last_sym->kind == v__ast__Kind__multi_return) { - Array_v__ast__Type node_types = v__ast__TypeSymbol_mr_info(node_sym).types; - Array_v__ast__Type _t3 = {0}; - Array_v__ast__Type _t3_orig = v__ast__TypeSymbol_mr_info(last_sym).types; - int _t3_len = _t3_orig.len; - _t3 = __new_array(0, _t3_len, sizeof(v__ast__Type)); - - for (int _t4 = 0; _t4 < _t3_len; ++_t4) { - v__ast__Type it = ((v__ast__Type*) _t3_orig.data)[_t4]; - v__ast__Type ti = v__ast__mktyp(it); - array_push((array*)&_t3, &ti); - } - Array_v__ast__Type last_types =_t3; - if (Array_v__ast__Type_arr_eq(node_types, last_types)) { - continue; - } - } v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("mismatched types `"), 0xfe10, {.d_s = v__ast__Table_type_to_str(c->table, node->typ)}}, {_SLIT("` and `"), 0xfe10, {.d_s = v__ast__Table_type_to_str(c->table, last_expr.typ)}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); } } else { v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("`"), 0xfe10, {.d_s = if_kind}}, {_SLIT("` expression requires an expression as the last statement of every branch"), 0, { .d_c = 0 }}})), branch.pos); } - for (int _t5 = 0; _t5 < branch.stmts.len; ++_t5) { - v__ast__Stmt st = ((v__ast__Stmt*)branch.stmts.data)[_t5]; - Option_void _t6 = v__ast__Stmt_check_c_expr(st); - if (_t6.state != 0 && _t6.err._typ != _IError_None___index) { - IError err = _t6.err; + for (int _t3 = 0; _t3 < branch.stmts.len; ++_t3) { + v__ast__Stmt st = ((v__ast__Stmt*)branch.stmts.data)[_t3]; + Option_void _t4 = v__ast__Stmt_check_c_expr(st); + if (_t4.state != 0 && _t4.err._typ != _IError_None___index) { + IError err = _t4.err; v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("`if` expression branch has "), 0xfe10, {.d_s = IError_name_table[err._typ]._method_msg(err._object)}}, {_SLIT0, 0, { .d_c = 0 }}})), (*(st.pos))); ; } @@ -55709,9 +55728,9 @@ bool v__checker__Checker_if_expr_defer_0 = false; } } } - Option_bool _t7; - if (_t7 = v__checker__Checker_has_return(c, branch.stmts), _t7.state == 0) { - bool has_return = *(bool*)_t7.data; + Option_bool _t5; + if (_t5 = v__checker__Checker_has_return(c, branch.stmts), _t5.state == 0) { + bool has_return = *(bool*)_t5.data; if (has_return) { nbranches_with_return++; } else { @@ -55739,13 +55758,13 @@ bool v__checker__Checker_if_expr_defer_0 = false; string d = (node->is_comptime ? (_SLIT("$")) : (_SLIT(""))); v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("`"), 0xfe10, {.d_s = if_kind}}, {_SLIT("` expression needs `"), 0xfe10, {.d_s = d}}, {_SLIT("else` clause"), 0, { .d_c = 0 }}})), node->pos); } - v__ast__Type _t8 = node->typ; + v__ast__Type _t6 = node->typ; // Defer begin if (v__checker__Checker_if_expr_defer_0) { c->expected_expr_type = _const_v__ast__void_type; } // Defer end - return _t8; + return _t6; } VV_LOCAL_SYMBOL void v__checker__Checker_smartcast_if_conds(v__checker__Checker* c, v__ast__Expr node, v__ast__Scope* scope) { @@ -60152,73 +60171,63 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI array_styp = v__gen__c__Gen_typ(g, array_type.typ); v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("HEAP("), 0xfe10, {.d_s = array_styp}}, {_SLIT(", "), 0, { .d_c = 0 }}}))); } + int len = node.exprs.len; if (array_type.unaliased_sym->kind == v__ast__Kind__array_fixed) { - if (node.has_it) { - g->inside_lambda = true; - string tmp = v__gen__c__Gen_new_tmp_var(g); - string s = v__gen__c__Gen_go_before_stmt(g, 0); - bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); - s = string_trim_space(s); - string ret_typ = v__gen__c__Gen_typ(g, node.typ); - string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); - g->empty_line = true; - v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_write(g, _SLIT("{")); - if (node.has_val) { - for (int i = 0; i < node.exprs.len; ++i) { - v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; - if (v__ast__Expr_is_auto_deref_var(expr)) { - v__gen__c__Gen_write(g, _SLIT("*")); - } - v__gen__c__Gen_write(g, _SLIT("0")); - if (i != node.exprs.len - 1) { - v__gen__c__Gen_write(g, _SLIT(", ")); - } - } - } else if (node.has_default) { - v__gen__c__Gen_write(g, _SLIT("0")); - v__ast__ArrayFixed info = /* as */ *(v__ast__ArrayFixed*)__as_cast((array_type.unaliased_sym->info)._v__ast__ArrayFixed,(array_type.unaliased_sym->info)._typ, 478) /*expected idx: 478, name: v.ast.ArrayFixed */ ; - for (int _t1 = 1; _t1 < info.size; ++_t1) { + v__gen__c__Gen_fixed_array_init(g, node, array_type); + } else if (len == 0) { + v__gen__c__Gen_array_init_with_fields(g, node, elem_type, is_amp, shared_styp); + } else { + string elem_styp = v__gen__c__Gen_typ(g, elem_type.typ); + string noscan = v__gen__c__Gen_check_noscan(g, elem_type.typ); + if (elem_type.unaliased_sym->kind == v__ast__Kind__function) { + v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV((voidptr["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + } else if (v__gen__c__Gen_is_empty_struct(g, elem_type)) { + v__gen__c__Gen_write(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + } else { + v__gen__c__Gen_write(g, str_intp(7, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + } + if (len > 8) { + v__gen__c__Gen_writeln(g, _SLIT("")); + v__gen__c__Gen_write(g, _SLIT("\t\t")); + } + for (int i = 0; i < node.exprs.len; ++i) { + v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; + if (v__ast__Type_alias_eq((*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), _const_v__ast__string_type) && (expr)._typ != 329 /* v.ast.StringLiteral */ && (expr)._typ != 328 /* v.ast.StringInterLiteral */) { + v__gen__c__Gen_write(g, _SLIT("string_clone(")); + v__gen__c__Gen_expr(g, expr); + v__gen__c__Gen_write(g, _SLIT(")")); + } else { + v__gen__c__Gen_expr_with_cast(g, expr, (*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), node.elem_type); + } + if (i != len - 1) { + if (i > 0 && (i & 7) == 0) { + v__gen__c__Gen_writeln(g, _SLIT(",")); + v__gen__c__Gen_write(g, _SLIT("\t\t")); + } else { v__gen__c__Gen_write(g, _SLIT(", ")); - v__gen__c__Gen_write(g, _SLIT("0")); } - } else { - v__gen__c__Gen_write(g, _SLIT("0")); } - v__gen__c__Gen_write(g, _SLIT("}")); - v__gen__c__Gen_writeln(g, _SLIT(";")); - v__gen__c__Gen_writeln(g, _SLIT("{")); - g->indent++; - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("int _len = (int)sizeof("), 0xfe10, {.d_s = tmp}}, {_SLIT(") / sizeof("), 0xfe10, {.d_s = elem_typ}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_writeln(g, _SLIT("for(int it=0; it<_len; it++, pelem++) {")); - g->indent++; - v__gen__c__Gen_write(g, _SLIT("*pelem = ")); - v__gen__c__Gen_expr(g, node.default_expr); - v__gen__c__Gen_writeln(g, _SLIT(";")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - if (s_ends_with_ln) { - v__gen__c__Gen_writeln(g, s); - } else { - v__gen__c__Gen_write(g, s); - } - v__gen__c__Gen_write(g, tmp); - g->inside_lambda = false; - return; } - bool need_tmp_var = g->inside_call && !g->inside_struct_init && node.exprs.len == 0; - string stmt_str = _SLIT(""); - string tmp_var = _SLIT(""); - if (need_tmp_var) { - tmp_var = v__gen__c__Gen_new_tmp_var(g); - stmt_str = v__gen__c__Gen_go_before_stmt(g, 0); - string ret_typ = v__gen__c__Gen_typ(g, node.typ); - g->empty_line = true; - v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp_var}}, {_SLIT(" = "), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, _SLIT("}))")); + if (g->is_shared) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("}, sizeof("), 0xfe10, {.d_s = shared_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); + } else if (is_amp) { + v__gen__c__Gen_write(g, _SLIT(")")); } + } +} + +VV_LOCAL_SYMBOL void v__gen__c__Gen_fixed_array_init(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type array_type) { + if (node.has_it) { + g->inside_lambda = true; + string tmp = v__gen__c__Gen_new_tmp_var(g); + string s = v__gen__c__Gen_go_before_stmt(g, 0); + bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); + s = string_trim_space(s); + string ret_typ = v__gen__c__Gen_typ(g, node.typ); + string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); + g->empty_line = true; + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); v__gen__c__Gen_write(g, _SLIT("{")); if (node.has_val) { for (int i = 0; i < node.exprs.len; ++i) { @@ -60226,110 +60235,100 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI if (v__ast__Expr_is_auto_deref_var(expr)) { v__gen__c__Gen_write(g, _SLIT("*")); } - v__gen__c__Gen_expr(g, expr); + v__gen__c__Gen_write(g, _SLIT("0")); if (i != node.exprs.len - 1) { v__gen__c__Gen_write(g, _SLIT(", ")); } } } else if (node.has_default) { - v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_write(g, _SLIT("0")); v__ast__ArrayFixed info = /* as */ *(v__ast__ArrayFixed*)__as_cast((array_type.unaliased_sym->info)._v__ast__ArrayFixed,(array_type.unaliased_sym->info)._typ, 478) /*expected idx: 478, name: v.ast.ArrayFixed */ ; - for (int _t2 = 1; _t2 < info.size; ++_t2) { + for (int _t1 = 1; _t1 < info.size; ++_t1) { v__gen__c__Gen_write(g, _SLIT(", ")); - v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_write(g, _SLIT("0")); } } else { v__gen__c__Gen_write(g, _SLIT("0")); } v__gen__c__Gen_write(g, _SLIT("}")); - if (need_tmp_var) { - v__gen__c__Gen_writeln(g, _SLIT(";")); - v__gen__c__Gen_write(g, stmt_str); - v__gen__c__Gen_write(g, tmp_var); + v__gen__c__Gen_writeln(g, _SLIT(";")); + v__gen__c__Gen_writeln(g, _SLIT("{")); + g->indent++; + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("int _len = (int)sizeof("), 0xfe10, {.d_s = tmp}}, {_SLIT(") / sizeof("), 0xfe10, {.d_s = elem_typ}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_writeln(g, _SLIT("for(int it=0; it<_len; it++, pelem++) {")); + g->indent++; + v__gen__c__Gen_write(g, _SLIT("*pelem = ")); + v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_writeln(g, _SLIT(";")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + if (s_ends_with_ln) { + v__gen__c__Gen_writeln(g, s); + } else { + v__gen__c__Gen_write(g, s); } + v__gen__c__Gen_write(g, tmp); + g->inside_lambda = false; return; } + bool need_tmp_var = g->inside_call && !g->inside_struct_init && node.exprs.len == 0; + string stmt_str = _SLIT(""); + string tmp_var = _SLIT(""); + if (need_tmp_var) { + tmp_var = v__gen__c__Gen_new_tmp_var(g); + stmt_str = v__gen__c__Gen_go_before_stmt(g, 0); + string ret_typ = v__gen__c__Gen_typ(g, node.typ); + g->empty_line = true; + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp_var}}, {_SLIT(" = "), 0, { .d_c = 0 }}}))); + } + v__gen__c__Gen_write(g, _SLIT("{")); + if (node.has_val) { + for (int i = 0; i < node.exprs.len; ++i) { + v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; + if (v__ast__Expr_is_auto_deref_var(expr)) { + v__gen__c__Gen_write(g, _SLIT("*")); + } + v__gen__c__Gen_expr(g, expr); + if (i != node.exprs.len - 1) { + v__gen__c__Gen_write(g, _SLIT(", ")); + } + } + } else if (node.has_default) { + v__gen__c__Gen_expr(g, node.default_expr); + v__ast__ArrayFixed info = /* as */ *(v__ast__ArrayFixed*)__as_cast((array_type.unaliased_sym->info)._v__ast__ArrayFixed,(array_type.unaliased_sym->info)._typ, 478) /*expected idx: 478, name: v.ast.ArrayFixed */ ; + for (int _t2 = 1; _t2 < info.size; ++_t2) { + v__gen__c__Gen_write(g, _SLIT(", ")); + v__gen__c__Gen_expr(g, node.default_expr); + } + } else { + v__gen__c__Gen_write(g, _SLIT("0")); + } + v__gen__c__Gen_write(g, _SLIT("}")); + if (need_tmp_var) { + v__gen__c__Gen_writeln(g, _SLIT(";")); + v__gen__c__Gen_write(g, stmt_str); + v__gen__c__Gen_write(g, tmp_var); + } +} + +VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init_with_fields(v__gen__c__Gen* g, v__ast__ArrayInit node, v__gen__c__Type elem_type, bool is_amp, string shared_styp) { string elem_styp = v__gen__c__Gen_typ(g, elem_type.typ); string noscan = v__gen__c__Gen_check_noscan(g, elem_type.typ); - if (node.exprs.len == 0) { - bool is_default_array = elem_type.unaliased_sym->kind == v__ast__Kind__array && node.has_default; - bool is_default_map = elem_type.unaliased_sym->kind == v__ast__Kind__map && node.has_default; - if (node.has_it) { - g->inside_lambda = true; - string tmp = v__gen__c__Gen_new_tmp_var(g); - string s = v__gen__c__Gen_go_before_stmt(g, 0); - bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); - s = string_trim_space(s); - string ret_typ = v__gen__c__Gen_typ(g, node.typ); - string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); - g->empty_line = true; - v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); - if (is_default_array) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_array_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); - } else if (is_default_map) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_map_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); - } else { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); - } - if (node.has_len) { - v__gen__c__Gen_expr(g, node.len_expr); - v__gen__c__Gen_write(g, _SLIT(", ")); - } else { - v__gen__c__Gen_write(g, _SLIT("0, ")); - } - if (node.has_cap) { - v__gen__c__Gen_expr(g, node.cap_expr); - v__gen__c__Gen_write(g, _SLIT(", ")); - } else { - v__gen__c__Gen_write(g, _SLIT("0, ")); - } - if (elem_type.unaliased_sym->kind == v__ast__Kind__function || v__gen__c__Gen_is_empty_struct(g, elem_type)) { - v__gen__c__Gen_write(g, _SLIT("sizeof(voidptr), ")); - } else { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), "), 0, { .d_c = 0 }}}))); - } - if (is_default_array) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_expr(g, node.default_expr); - v__gen__c__Gen_write(g, _SLIT("}[0])")); - } else if (node.has_len && v__ast__Type_alias_eq(node.elem_type, _const_v__ast__string_type)) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_write(g, _SLIT("_SLIT(\"\")")); - v__gen__c__Gen_write(g, _SLIT("})")); - } else if (node.has_len && (elem_type.unaliased_sym->kind == v__ast__Kind__array || elem_type.unaliased_sym->kind == v__ast__Kind__map)) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("(voidptr)&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_write(g, v__gen__c__Gen_type_default(g, node.elem_type)); - v__gen__c__Gen_write(g, _SLIT("}[0])")); - } else { - v__gen__c__Gen_write(g, _SLIT("0)")); - } - if (g->is_shared) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("}, sizeof("), 0xfe10, {.d_s = shared_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); - } else if (is_amp) { - v__gen__c__Gen_write(g, _SLIT(")")); - } - v__gen__c__Gen_writeln(g, _SLIT(";")); - v__gen__c__Gen_writeln(g, _SLIT("{")); - g->indent++; - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(".data;"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("for(int it=0; it<"), 0xfe10, {.d_s = tmp}}, {_SLIT(".len; it++, pelem++) {"), 0, { .d_c = 0 }}}))); - g->indent++; - v__gen__c__Gen_write(g, _SLIT("*pelem = ")); - v__gen__c__Gen_expr(g, node.default_expr); - v__gen__c__Gen_writeln(g, _SLIT(";")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - g->indent--; - v__gen__c__Gen_writeln(g, _SLIT("}")); - if (s_ends_with_ln) { - v__gen__c__Gen_writeln(g, s); - } else { - v__gen__c__Gen_write(g, s); - } - v__gen__c__Gen_write(g, tmp); - g->inside_lambda = false; - return; - } + bool is_default_array = elem_type.unaliased_sym->kind == v__ast__Kind__array && node.has_default; + bool is_default_map = elem_type.unaliased_sym->kind == v__ast__Kind__map && node.has_default; + if (node.has_it) { + g->inside_lambda = true; + string tmp = v__gen__c__Gen_new_tmp_var(g); + string s = v__gen__c__Gen_go_before_stmt(g, 0); + bool s_ends_with_ln = string_ends_with(s, _SLIT("\n")); + s = string_trim_space(s); + string ret_typ = v__gen__c__Gen_typ(g, node.typ); + string elem_typ = v__gen__c__Gen_typ(g, node.elem_type); + g->empty_line = true; + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = ret_typ}}, {_SLIT(" "), 0xfe10, {.d_s = tmp}}, {_SLIT(" ="), 0, { .d_c = 0 }}}))); if (is_default_array) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_array_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); } else if (is_default_map) { @@ -60354,14 +60353,10 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI } else { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), "), 0, { .d_c = 0 }}}))); } - if (is_default_array || is_default_map) { + if (is_default_array) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_expr(g, node.default_expr); v__gen__c__Gen_write(g, _SLIT("}[0])")); - } else if (node.has_default) { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); - v__gen__c__Gen_expr_with_cast(g, node.default_expr, node.default_type, node.elem_type); - v__gen__c__Gen_write(g, _SLIT("})")); } else if (node.has_len && v__ast__Type_alias_eq(node.elem_type, _const_v__ast__string_type)) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_write(g, _SLIT("_SLIT(\"\")")); @@ -60378,39 +60373,71 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_array_init(v__gen__c__Gen* g, v__ast__ArrayI } else if (is_amp) { v__gen__c__Gen_write(g, _SLIT(")")); } + v__gen__c__Gen_writeln(g, _SLIT(";")); + v__gen__c__Gen_writeln(g, _SLIT("{")); + g->indent++; + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = elem_typ}}, {_SLIT("* pelem = ("), 0xfe10, {.d_s = elem_typ}}, {_SLIT("*)"), 0xfe10, {.d_s = tmp}}, {_SLIT(".data;"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("for(int it=0; it<"), 0xfe10, {.d_s = tmp}}, {_SLIT(".len; it++, pelem++) {"), 0, { .d_c = 0 }}}))); + g->indent++; + v__gen__c__Gen_write(g, _SLIT("*pelem = ")); + v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_writeln(g, _SLIT(";")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + g->indent--; + v__gen__c__Gen_writeln(g, _SLIT("}")); + if (s_ends_with_ln) { + v__gen__c__Gen_writeln(g, s); + } else { + v__gen__c__Gen_write(g, s); + } + v__gen__c__Gen_write(g, tmp); + g->inside_lambda = false; return; } - int len = node.exprs.len; - if (elem_type.unaliased_sym->kind == v__ast__Kind__function) { - v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV((voidptr["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); - } else if (v__gen__c__Gen_is_empty_struct(g, elem_type)) { - v__gen__c__Gen_write(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof(voidptr), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + if (is_default_array) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_array_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); + } else if (is_default_map) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_map_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); } else { - v__gen__c__Gen_write(g, str_intp(7, _MOV((StrIntpData[]){{_SLIT("new_array_from_c_array"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0xfe07, {.d_i32 = len}}, {_SLIT(", "), 0xfe07, {.d_i32 = len}}, {_SLIT(", sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), _MOV(("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("["), 0xfe07, {.d_i32 = len}}, {_SLIT("]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__new_array_with_default"), 0xfe10, {.d_s = noscan}}, {_SLIT("("), 0, { .d_c = 0 }}}))); } - if (len > 8) { - v__gen__c__Gen_writeln(g, _SLIT("")); - v__gen__c__Gen_write(g, _SLIT("\t\t")); + if (node.has_len) { + v__gen__c__Gen_expr(g, node.len_expr); + v__gen__c__Gen_write(g, _SLIT(", ")); + } else { + v__gen__c__Gen_write(g, _SLIT("0, ")); } - for (int i = 0; i < node.exprs.len; ++i) { - v__ast__Expr expr = ((v__ast__Expr*)node.exprs.data)[i]; - if (v__ast__Type_alias_eq((*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), _const_v__ast__string_type) && (expr)._typ != 329 /* v.ast.StringLiteral */ && (expr)._typ != 328 /* v.ast.StringInterLiteral */) { - v__gen__c__Gen_write(g, _SLIT("string_clone(")); - v__gen__c__Gen_expr(g, expr); - v__gen__c__Gen_write(g, _SLIT(")")); - } else { - v__gen__c__Gen_expr_with_cast(g, expr, (*(v__ast__Type*)/*ee elem_sym */array_get(node.expr_types, i)), node.elem_type); - } - if (i != len - 1) { - if (i > 0 && (i & 7) == 0) { - v__gen__c__Gen_writeln(g, _SLIT(",")); - v__gen__c__Gen_write(g, _SLIT("\t\t")); - } else { - v__gen__c__Gen_write(g, _SLIT(", ")); - } - } + if (node.has_cap) { + v__gen__c__Gen_expr(g, node.cap_expr); + v__gen__c__Gen_write(g, _SLIT(", ")); + } else { + v__gen__c__Gen_write(g, _SLIT("0, ")); + } + if (elem_type.unaliased_sym->kind == v__ast__Kind__function || v__gen__c__Gen_is_empty_struct(g, elem_type)) { + v__gen__c__Gen_write(g, _SLIT("sizeof(voidptr), ")); + } else { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("sizeof("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("), "), 0, { .d_c = 0 }}}))); + } + if (is_default_array || is_default_map) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_expr(g, node.default_expr); + v__gen__c__Gen_write(g, _SLIT("}[0])")); + } else if (node.has_default) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_expr_with_cast(g, node.default_expr, node.default_type, node.elem_type); + v__gen__c__Gen_write(g, _SLIT("})")); + } else if (node.has_len && v__ast__Type_alias_eq(node.elem_type, _const_v__ast__string_type)) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, _SLIT("_SLIT(\"\")")); + v__gen__c__Gen_write(g, _SLIT("})")); + } else if (node.has_len && (elem_type.unaliased_sym->kind == v__ast__Kind__array || elem_type.unaliased_sym->kind == v__ast__Kind__map)) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("(voidptr)&("), 0xfe10, {.d_s = elem_styp}}, {_SLIT("[]){"), 0, { .d_c = 0 }}}))); + v__gen__c__Gen_write(g, v__gen__c__Gen_type_default(g, node.elem_type)); + v__gen__c__Gen_write(g, _SLIT("}[0])")); + } else { + v__gen__c__Gen_write(g, _SLIT("0)")); } - v__gen__c__Gen_write(g, _SLIT("}))")); if (g->is_shared) { v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("}, sizeof("), 0xfe10, {.d_s = shared_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); } else if (is_amp) { @@ -63243,32 +63270,32 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_interface(v__gen__c__Gen* g, v__ strings__Builder_writeln(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static string indent_"), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("("), 0xfe10, {.d_s = styp}}, {_SLIT(" x, int indent_count) { /* gen_str_for_interface */"), 0, { .d_c = 0 }}}))); for (int _t1 = 0; _t1 < info.types.len; ++_t1) { v__ast__Type typ = ((v__ast__Type*)info.types.data)[_t1]; - v__ast__TypeSymbol* subtype = v__ast__Table_sym(g->table, typ); + v__ast__TypeSymbol* sub_sym = v__ast__Table_sym(g->table, v__ast__mktyp(typ)); string func_name = v__gen__c__Gen_get_str_fn(g, typ); - multi_return_bool_bool_int mr_13661 = v__ast__TypeSymbol_str_method_info(subtype); - bool sym_has_str_method = mr_13661.arg0; - bool str_method_expects_ptr = mr_13661.arg1; - if (v__gen__c__should_use_indent_func(subtype->kind) && !sym_has_str_method) { + multi_return_bool_bool_int mr_13672 = v__ast__TypeSymbol_str_method_info(sub_sym); + bool sym_has_str_method = mr_13672.arg0; + bool str_method_expects_ptr = mr_13672.arg1; + if (v__gen__c__should_use_indent_func(sub_sym->kind) && !sym_has_str_method) { func_name = str_intp(2, _MOV((StrIntpData[]){{_SLIT("indent_"), 0xfe10, {.d_s = func_name}}, {_SLIT0, 0, { .d_c = 0 }}})); } string deref = (sym_has_str_method && str_method_expects_ptr ? (_SLIT(" ")) : (_SLIT("*"))); if (v__ast__Type_alias_eq(typ, _const_v__ast__string_type)) { - string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); - if (v__gen__c__should_use_indent_func(subtype->kind) && !sym_has_str_method) { + string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); + if (v__gen__c__should_use_indent_func(sub_sym->kind) && !sym_has_str_method) { val = /*f*/string__plus(val, _SLIT(", indent_count")); } val = /*f*/string__plus(val, _SLIT(")")); string res = str_intp(4, _MOV((StrIntpData[]){{_SLIT("str_intp(2, _MOV((StrIntpData[]){\n {_SLIT(\""), 0xfe10, {.d_s = clean_interface_v_type_name}}, {_SLIT("(\'\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s = "), 0xfe10, {.d_s = val}}, {_SLIT("}},\n {_SLIT(\"\')\"), 0, {.d_c = 0 }}\n }))"), 0, { .d_c = 0 }}})); - strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); + strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); strings__Builder_write_string(&fn_builder, str_intp(2, _MOV((StrIntpData[]){{_SLIT(" return "), 0xfe10, {.d_s = res}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); } else { - string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); - if (v__gen__c__should_use_indent_func(subtype->kind) && !sym_has_str_method) { + string val = str_intp(5, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = func_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("("), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("*)x._"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}})); + if (v__gen__c__should_use_indent_func(sub_sym->kind) && !sym_has_str_method) { val = /*f*/string__plus(val, _SLIT(", indent_count")); } val = /*f*/string__plus(val, _SLIT(")")); string res = str_intp(4, _MOV((StrIntpData[]){{_SLIT("str_intp(2, _MOV((StrIntpData[]){\n {_SLIT(\""), 0xfe10, {.d_s = clean_interface_v_type_name}}, {_SLIT("(\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s = "), 0xfe10, {.d_s = val}}, {_SLIT("}},\n {_SLIT(\")\"), 0, {.d_c = 0 }}\n }))"), 0, { .d_c = 0 }}})); - strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); + strings__Builder_write_string(&fn_builder, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\tif (x._typ == _"), 0xfe10, {.d_s = styp}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index)"), 0, { .d_c = 0 }}}))); strings__Builder_write_string(&fn_builder, str_intp(2, _MOV((StrIntpData[]){{_SLIT(" return "), 0xfe10, {.d_s = res}}, {_SLIT(";\n"), 0, { .d_c = 0 }}}))); } } @@ -63313,9 +63340,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_union_sum_type(v__gen__c__Gen* g string typ_str = v__gen__c__Gen_typ(g, typ); string func_name = v__gen__c__Gen_get_str_fn(g, typ); v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, typ); - multi_return_bool_bool_int mr_16578 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_16578.arg0; - bool str_method_expects_ptr = mr_16578.arg1; + multi_return_bool_bool_int mr_16589 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_16589.arg0; + bool str_method_expects_ptr = mr_16589.arg1; string deref = (sym_has_str_method && str_method_expects_ptr ? (_SLIT(" ")) : (_SLIT("*"))); if (v__gen__c__should_use_indent_func(sym->kind) && !sym_has_str_method) { func_name = str_intp(2, _MOV((StrIntpData[]){{_SLIT("indent_"), 0xfe10, {.d_s = func_name}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -63414,9 +63441,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array(v__gen__c__Gen* g, v__ast_ } string field_styp = v__gen__c__Gen_typ(g, typ); bool is_elem_ptr = v__ast__Type_is_ptr(typ); - multi_return_bool_bool_int mr_20654 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_20654.arg0; - bool str_method_expects_ptr = mr_20654.arg1; + multi_return_bool_bool_int mr_20665 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_20665.arg0; + bool str_method_expects_ptr = mr_20665.arg1; string elem_str_fn_name = v__gen__c__Gen_get_str_fn(g, typ); if (sym->kind == v__ast__Kind__u8) { elem_str_fn_name = string__plus(elem_str_fn_name, _SLIT("_escaped")); @@ -63458,9 +63485,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array(v__gen__c__Gen* g, v__ast_ strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstring x = str_intp(2, _MOV((StrIntpData[]){{_SLIT(\"\'\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s = it }}, {_SLIT(\"\'\"), 0, {.d_c = 0 }}}));\n"), 0, { .d_c = 0 }}}))); } } else { - multi_return_string_string mr_23178 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); - string deref = mr_23178.arg0; - string deref_label = mr_23178.arg1; + multi_return_string_string mr_23189 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); + string deref = mr_23189.arg0; + string deref_label = mr_23189.arg1; strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstrings__Builder_write_string(&sb, _SLIT(\""), 0xfe10, {.d_s = deref_label}}, {_SLIT("\"));"), 0, { .d_c = 0 }}}))); strings__Builder_writeln(&g->auto_str_funcs, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\t\tstring x = "), 0xfe10, {.d_s = elem_str_fn_name}}, {_SLIT("( "), 0xfe10, {.d_s = deref}}, {_SLIT(" it);"), 0, { .d_c = 0 }}}))); } @@ -63488,9 +63515,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array_fixed(v__gen__c__Gen* g, v sym = v__ast__Table_sym(g->table, typ); } bool is_elem_ptr = v__ast__Type_is_ptr(typ); - multi_return_bool_bool_int mr_24560 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_24560.arg0; - bool str_method_expects_ptr = mr_24560.arg1; + multi_return_bool_bool_int mr_24571 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_24571.arg0; + bool str_method_expects_ptr = mr_24571.arg1; string elem_str_fn_name = v__gen__c__Gen_get_str_fn(g, typ); strings__Builder_writeln(&g->definitions, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static string "), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("("), 0xfe10, {.d_s = styp}}, {_SLIT(" a); // auto"), 0, { .d_c = 0 }}}))); strings__Builder_writeln(&g->auto_str_funcs, str_intp(4, _MOV((StrIntpData[]){{_SLIT("static string "), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("("), 0xfe10, {.d_s = styp}}, {_SLIT(" a) { return indent_"), 0xfe10, {.d_s = str_fn_name}}, {_SLIT("(a, 0);}"), 0, { .d_c = 0 }}}))); @@ -63503,9 +63530,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_gen_str_for_array_fixed(v__gen__c__Gen* g, v strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstring x = "), 0xfe10, {.d_s = elem_str_fn_name}}, {_SLIT("();"), 0, { .d_c = 0 }}}))); strings__Builder_writeln(&g->auto_str_funcs, _SLIT("\t\tstrings__Builder_write_string(&sb, x);")); } else { - multi_return_string_string mr_25437 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); - string deref = mr_25437.arg0; - string deref_label = mr_25437.arg1; + multi_return_string_string mr_25448 = v__gen__c__deref_kind(str_method_expects_ptr, is_elem_ptr, typ); + string deref = mr_25448.arg0; + string deref_label = mr_25448.arg1; if (v__gen__c__should_use_indent_func(sym->kind) && !sym_has_str_method) { if (is_elem_ptr) { strings__Builder_writeln(&g->auto_str_funcs, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\t\tstrings__Builder_write_string(&sb, _SLIT(\""), 0xfe10, {.d_s = deref_label}}, {_SLIT("\"));"), 0, { .d_c = 0 }}}))); @@ -63722,9 +63749,9 @@ strings__Builder fn_body; } else { strings__Builder_write_string(&fn_body, str_intp(5, _MOV((StrIntpData[]){{_SLIT("\t\t{_SLIT(\"\\n\"), "), 0xfe10, {.d_s = _const_v__gen__c__si_s_code}}, {_SLIT(", {.d_s=indents}}, {_SLIT(\" "), 0xfe10, {.d_s = field.name}}, {_SLIT(": "), 0xfe10, {.d_s = ptr_amp}}, {_SLIT0, 0xfe10, {.d_s = prefix}}, {_SLIT("\"), 0, {.d_c=0}}, "), 0, { .d_c = 0 }}}))); } - multi_return_bool_bool_int mr_35259 = v__ast__TypeSymbol_str_method_info(sym); - bool sym_has_str_method = mr_35259.arg0; - bool str_method_expects_ptr = mr_35259.arg1; + multi_return_bool_bool_int mr_35270 = v__ast__TypeSymbol_str_method_info(sym); + bool sym_has_str_method = mr_35270.arg0; + bool str_method_expects_ptr = mr_35270.arg1; string sftyp = v__gen__c__Gen_typ(g, field.typ); string field_styp = string_replace(sftyp, _SLIT("*"), _SLIT("")); string _t2; /* if prepend */ @@ -63745,9 +63772,9 @@ strings__Builder fn_body; strings__Builder_write_string(&fn_body, str_intp(4, _MOV((StrIntpData[]){{_SLIT("{_SLIT(\""), 0xfe10, {.d_s = quote_str}}, {_SLIT("\"), "), 0xfe10, {.d_s = g_fmt}}, {_SLIT(", {."), 0xfe10, {.d_s = v__gen__c__data_str(base_fmt)}}, {_SLIT("="), 0, { .d_c = 0 }}}))); } string funcprefix = _SLIT(""); - multi_return_string_bool mr_36043 = v__gen__c__struct_auto_str_func(sym, field.typ, field_styp_fn_name, field.name, sym_has_str_method, str_method_expects_ptr); - string func = mr_36043.arg0; - bool caller_should_free = mr_36043.arg1; + multi_return_string_bool mr_36054 = v__gen__c__struct_auto_str_func(sym, field.typ, field_styp_fn_name, field.name, sym_has_str_method, str_method_expects_ptr); + string func = mr_36054.arg0; + bool caller_should_free = mr_36054.arg1; if (Array_v__ast__Type_contains(_const_v__ast__cptr_types, field.typ)) { func = str_intp(2, _MOV((StrIntpData[]){{_SLIT("(voidptr) it."), 0xfe10, {.d_s = field.name}}, {_SLIT0, 0, { .d_c = 0 }}})); caller_should_free = false; @@ -63799,8 +63826,8 @@ if (v__gen__c__Gen_gen_str_for_struct_defer_0) { } VV_LOCAL_SYMBOL multi_return_string_bool v__gen__c__struct_auto_str_func(v__ast__TypeSymbol* sym, v__ast__Type field_type, string fn_name, string field_name, bool has_custom_str, bool expects_ptr) { - multi_return_string_string mr_37955 = v__gen__c__deref_kind(expects_ptr, v__ast__Type_is_ptr(field_type), field_type); - string deref = mr_37955.arg0; + multi_return_string_string mr_37966 = v__gen__c__deref_kind(expects_ptr, v__ast__Type_is_ptr(field_type), field_type); + string deref = mr_37966.arg0; if (sym->kind == v__ast__Kind__enum_) { return (multi_return_string_bool){.arg0= str_intp(4, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = fn_name}}, {_SLIT("("), 0xfe10, {.d_s = deref}}, {_SLIT("it."), 0xfe10, {.d_s = v__gen__c__c_name(field_name)}}, {_SLIT(")"), 0, { .d_c = 0 }}})), .arg1=true}; } else if (v__gen__c__should_use_indent_func(sym->kind)) { @@ -64006,6 +64033,7 @@ string v__gen__c__gen(Array_v__ast__File_ptr files, v__ast__Table* table, v__pre .referenced_fns = (__shared__Map_string_bool*)__dup_shared_map(&(__shared__Map_string_bool){.mtx = {0}, .val =new_map(sizeof(string), sizeof(bool), &map_hash_string, &map_eq_string, &map_clone_string, &map_free_string)}, sizeof(__shared__Map_string_bool)), .nr_closures = 0, .expected_cast_type = 0, + .or_expr_return_type = 0, .anon_fn = 0, .tests_inited = 0, .has_main = 0, @@ -64671,6 +64699,7 @@ VV_LOCAL_SYMBOL v__gen__c__Gen* v__gen__c__cgen_process_one_file_cb(sync__pool__ .referenced_fns = global_g->referenced_fns, .nr_closures = 0, .expected_cast_type = 0, + .or_expr_return_type = 0, .anon_fn = 0, .tests_inited = 0, .has_main = 0, @@ -65014,8 +65043,8 @@ void v__gen__c__Gen_write_typeof_functions(v__gen__c__Gen* g) { v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static char * v_typeof_interface_"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("(int sidx) { /* "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); for (int _t5 = 0; _t5 < inter_info.types.len; ++_t5) { v__ast__Type t = ((v__ast__Type*)inter_info.types.data)[_t5]; - v__ast__TypeSymbol* subtype = v__ast__Table_sym(g->table, t); - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index) return \""), 0xfe10, {.d_s = v__util__strip_main_name(subtype->name)}}, {_SLIT("\";"), 0, { .d_c = 0 }}}))); + v__ast__TypeSymbol* sub_sym = v__ast__Table_sym(g->table, v__ast__mktyp(t)); + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index) return \""), 0xfe10, {.d_s = v__util__strip_main_name(sub_sym->name)}}, {_SLIT("\";"), 0, { .d_c = 0 }}}))); } v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\treturn \"unknown "), 0xfe10, {.d_s = v__util__strip_main_name(sym->name)}}, {_SLIT("\";"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_writeln(g, _SLIT("}")); @@ -65023,8 +65052,8 @@ void v__gen__c__Gen_write_typeof_functions(v__gen__c__Gen* g) { v__gen__c__Gen_writeln(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT("static int v_typeof_interface_idx_"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("(int sidx) { /* "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); for (int _t6 = 0; _t6 < inter_info.types.len; ++_t6) { v__ast__Type t = ((v__ast__Type*)inter_info.types.data)[_t6]; - v__ast__TypeSymbol* subtype = v__ast__Table_sym(g->table, t); - v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = subtype->cname}}, {_SLIT("_index) return "), 0xfe07, {.d_i32 = ((int)(t))}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); + v__ast__TypeSymbol* sub_sym = v__ast__Table_sym(g->table, v__ast__mktyp(t)); + v__gen__c__Gen_writeln(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("\tif (sidx == _"), 0xfe10, {.d_s = sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = sub_sym->cname}}, {_SLIT("_index) return "), 0xfe07, {.d_i32 = ((int)(t))}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); } v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\treturn "), 0xfe07, {.d_i32 = ((int)(ityp))}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); v__gen__c__Gen_writeln(g, _SLIT("}")); @@ -65133,9 +65162,9 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_optional_type_text(v__gen__c__Gen* g, stri } VV_LOCAL_SYMBOL string v__gen__c__Gen_register_optional(v__gen__c__Gen* g, v__ast__Type t) { - multi_return_string_string mr_36707 = v__gen__c__Gen_optional_type_name(g, t); - string styp = mr_36707.arg0; - string base = mr_36707.arg1; + multi_return_string_string mr_36786 = v__gen__c__Gen_optional_type_name(g, t); + string styp = mr_36786.arg0; + string base = mr_36786.arg1; map_set(&g->optionals, &(string[]){base}, &(string[]) { styp }); string _t1 = styp; return _t1; @@ -65517,7 +65546,11 @@ void v__gen__c__Gen_write_interface_typesymbol_declaration(v__gen__c__Gen* g, v_ strings__Builder_writeln(&g->type_definitions, _SLIT("\t\tvoid* _object;")); for (int _t1 = 0; _t1 < info.types.len; ++_t1) { v__ast__Type variant = ((v__ast__Type*)info.types.data)[_t1]; - string vcname = v__ast__Table_sym(g->table, variant)->cname; + v__ast__Type mk_typ = v__ast__mktyp(variant); + if (!v__ast__Type_alias_eq(mk_typ, variant) && Array_v__ast__Type_contains(info.types, mk_typ)) { + continue; + } + string vcname = v__ast__Table_sym(g->table, mk_typ)->cname; strings__Builder_writeln(&g->type_definitions, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\t\t"), 0xfe10, {.d_s = vcname}}, {_SLIT("* _"), 0xfe10, {.d_s = vcname}}, {_SLIT(";"), 0, { .d_c = 0 }}}))); } strings__Builder_writeln(&g->type_definitions, _SLIT("\t};")); @@ -66176,8 +66209,8 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_write_sumtype_casting_fn(v__gen__c__Gen* g, *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t4.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.has_default_expr = 0,.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_pub = 0,.default_val = (string){.str=(byteptr)"", .is_lit=1},.is_mut = 0,.is_global = 0,.is_volatile = 0,.default_expr = {0},.default_expr_typ = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.typ = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_65835 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t4.data); - Array_v__ast__Type embed_types = mr_65835.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_66009 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t4.data); + Array_v__ast__Type embed_types = mr_66009.arg1; if (embed_types.len > 0) { v__ast__TypeSymbol* embed_sym = v__ast__Table_sym(g->table, (*(v__ast__Type*)array_last(embed_types))); ptr = str_intp(2, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = v__ast__TypeSymbol_embed_name(embed_sym)}}, {_SLIT("_ptr"), 0, { .d_c = 0 }}})); @@ -66230,10 +66263,10 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_expr_with_cast(v__gen__c__Gen* g, v__ast__Ex v__gen__c__Gen_expr(g, expr); return; } - if ((exp_sym->info)._typ == 473 /* v.ast.Interface */ && v__ast__Type_idx(got_type_raw) != v__ast__Type_idx(expected_type) && !v__ast__Type_has_flag(expected_type, v__ast__TypeFlag__optional)) { + if ((exp_sym->info)._typ == 473 /* v.ast.Interface */ && v__ast__Type_idx(got_type) != v__ast__Type_idx(expected_type) && !v__ast__Type_has_flag(expected_type, v__ast__TypeFlag__optional)) { if ((expr)._typ == 330 /* v.ast.StructInit */ && !v__ast__Type_is_ptr(got_type)) { g->inside_cast_in_heap++; - string got_styp = v__gen__c__Gen_cc_type(g, v__ast__Type_ref(got_type_raw), true); + string got_styp = v__gen__c__Gen_cc_type(g, v__ast__Type_ref(got_type), true); string exp_styp = exp_sym->cname; string fname = str_intp(3, _MOV((StrIntpData[]){{_SLIT("I_"), 0xfe10, {.d_s = got_styp}}, {_SLIT("_to_Interface_"), 0xfe10, {.d_s = exp_styp}}, {_SLIT0, 0, { .d_c = 0 }}})); if ((*exp_sym->info._v__ast__Interface).is_generic) { @@ -66242,7 +66275,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_expr_with_cast(v__gen__c__Gen* g, v__ast__Ex v__gen__c__Gen_call_cfn_for_casting_expr(g, fname, expr, expected_is_ptr, exp_styp, true, got_styp); g->inside_cast_in_heap--; } else { - string got_styp = v__gen__c__Gen_cc_type(g, got_type_raw, true); + string got_styp = v__gen__c__Gen_cc_type(g, got_type, true); bool got_is_shared = v__ast__Type_has_flag(got_type, v__ast__TypeFlag__shared_f); string exp_styp = (got_is_shared ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("__shared__"), 0xfe10, {.d_s = exp_sym->cname}}, {_SLIT0, 0, { .d_c = 0 }}}))) : (exp_sym->cname)); string fname = (got_is_shared ? ( str_intp(3, _MOV((StrIntpData[]){{_SLIT("I___shared__"), 0xfe10, {.d_s = got_styp}}, {_SLIT("_to_shared_Interface_"), 0xfe10, {.d_s = exp_styp}}, {_SLIT0, 0, { .d_c = 0 }}}))) : ( str_intp(3, _MOV((StrIntpData[]){{_SLIT("I_"), 0xfe10, {.d_s = got_styp}}, {_SLIT("_to_Interface_"), 0xfe10, {.d_s = exp_styp}}, {_SLIT0, 0, { .d_c = 0 }}})))); @@ -67623,11 +67656,11 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_map_init(v__gen__c__Gen* g, v__ast__MapInit string value_typ_str = v__gen__c__Gen_typ(g, unwrap_val_typ); v__ast__TypeSymbol* value_sym = v__ast__Table_sym(g->table, unwrap_val_typ); v__ast__TypeSymbol* key_sym = v__ast__Table_final_sym(g->table, unwrap_key_typ); - multi_return_string_string_string_string mr_105090 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); - string hash_fn = mr_105090.arg0; - string key_eq_fn = mr_105090.arg1; - string clone_fn = mr_105090.arg2; - string free_fn = mr_105090.arg3; + multi_return_string_string_string_string mr_105252 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); + string hash_fn = mr_105252.arg0; + string key_eq_fn = mr_105252.arg1; + string clone_fn = mr_105252.arg2; + string free_fn = mr_105252.arg3; int size = node.vals.len; string shared_styp = _SLIT(""); string styp = _SLIT(""); @@ -68009,6 +68042,8 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_concat_expr(v__gen__c__Gen* g, v__ast__Conca string styp = v__gen__c__Gen_typ(g, node.return_type); if (g->inside_return) { styp = v__gen__c__Gen_typ(g, g->fn_decl->return_type); + } else if (g->inside_or_block) { + styp = v__gen__c__Gen_typ(g, g->or_expr_return_type); } v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, node.return_type); bool is_multi = sym->kind == v__ast__Kind__multi_return; @@ -68782,9 +68817,9 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_write_types(v__gen__c__Gen* g, Array_v__ast_ for (int _t3 = 0; _t3 < (*sym->info._v__ast__Struct).fields.len; ++_t3) { v__ast__StructField field = ((v__ast__StructField*)(*sym->info._v__ast__Struct).fields.data)[_t3]; if (v__ast__Type_has_flag(field.typ, v__ast__TypeFlag__optional)) { - multi_return_string_string mr_142158 = v__gen__c__Gen_optional_type_name(g, field.typ); - string styp = mr_142158.arg0; - string base = mr_142158.arg1; + multi_return_string_string mr_142389 = v__gen__c__Gen_optional_type_name(g, field.typ); + string styp = mr_142389.arg0; + string base = mr_142389.arg1; sync__RwMutex_lock(&g->done_optionals->mtx); /*lock*/ { if (!Array_string_contains(g->done_optionals->val, base)) { @@ -69016,6 +69051,7 @@ bool v__gen__c__Gen_or_block_defer_0 = false; v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("if ("), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".state != 0) { /*or block*/ "), 0, { .d_c = 0 }}}))); } if (or_block.kind == v__ast__OrKind__block) { + g->or_expr_return_type = v__ast__Type_clear_flag(return_type, v__ast__TypeFlag__optional); if (g->inside_or_block) { v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\terr = "), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".err;"), 0, { .d_c = 0 }}}))); } else { @@ -69051,15 +69087,16 @@ bool v__gen__c__Gen_or_block_defer_0 = false; v__gen__c__Gen_writeln(g, _SLIT(";")); } } + g->or_expr_return_type = _const_v__ast__void_type; } else if (or_block.kind == v__ast__OrKind__propagate) { if (string__eq(g->file->mod.name, _SLIT("main")) && (isnil(g->fn_decl) || g->fn_decl->is_main)) { string err_msg = str_intp(3, _MOV((StrIntpData[]){{_SLIT("IError_name_table["), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._typ]._method_msg("), 0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._object)"), 0, { .d_c = 0 }}})); if (g->pref->is_debug) { - multi_return_int_string_string_string mr_151212 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); - int paline = mr_151212.arg0; - string pafile = mr_151212.arg1; - string pamod = mr_151212.arg2; - string pafn = mr_151212.arg3; + multi_return_int_string_string_string mr_151543 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); + int paline = mr_151543.arg0; + string pafile = mr_151543.arg1; + string pamod = mr_151543.arg2; + string pafn = mr_151543.arg3; v__gen__c__Gen_writeln(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("panic_debug("), 0xfe07, {.d_i32 = paline}}, {_SLIT(", tos3(\""), 0xfe10, {.d_s = pafile}}, {_SLIT("\"), tos3(\""), 0xfe10, {.d_s = pamod}}, {_SLIT("\"), tos3(\""), 0xfe10, {.d_s = pafn}}, {_SLIT("\"), "), 0xfe10, {.d_s = err_msg}}, {_SLIT(" );"), 0, { .d_c = 0 }}}))); } else { v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\tpanic_optional_not_set( "), 0xfe10, {.d_s = err_msg}}, {_SLIT(" );"), 0, { .d_c = 0 }}}))); @@ -69169,11 +69206,11 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_type_default(v__gen__c__Gen* g, v__ast__Ty { v__ast__Map info = v__ast__TypeSymbol_map_info(sym); v__ast__TypeSymbol* key_typ = v__ast__Table_sym(g->table, info.key_type); - multi_return_string_string_string_string mr_153794 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); - string hash_fn = mr_153794.arg0; - string key_eq_fn = mr_153794.arg1; - string clone_fn = mr_153794.arg2; - string free_fn = mr_153794.arg3; + multi_return_string_string_string_string mr_154125 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); + string hash_fn = mr_154125.arg0; + string key_eq_fn = mr_154125.arg1; + string clone_fn = mr_154125.arg2; + string free_fn = mr_154125.arg3; string noscan_key = v__gen__c__Gen_check_noscan(g, info.key_type); string noscan_value = v__gen__c__Gen_check_noscan(g, info.value_type); string noscan = (noscan_key.len != 0 || noscan_value.len != 0 ? (_SLIT("_noscan")) : (_SLIT(""))); @@ -69353,9 +69390,10 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_enum_val(v__gen__c__Gen* g, v__ast__EnumVal } VV_LOCAL_SYMBOL void v__gen__c__Gen_as_cast(v__gen__c__Gen* g, v__ast__AsCast node) { - string styp = v__gen__c__Gen_typ(g, node.typ); - v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, node.typ); - v__ast__TypeSymbol* expr_type_sym = v__ast__Table_sym(g->table, node.expr_type); + v__ast__Type unwrapped_node_typ = v__gen__c__Gen_unwrap_generic(g, node.typ); + string styp = v__gen__c__Gen_typ(g, unwrapped_node_typ); + v__ast__TypeSymbol* sym = v__ast__Table_sym(g->table, unwrapped_node_typ); + v__ast__TypeSymbol* expr_type_sym = v__ast__Table_sym(g->table, v__gen__c__Gen_unwrap_generic(g, node.expr_type)); if ((expr_type_sym->info)._typ == 474 /* v.ast.SumType */) { string dot = (v__ast__Type_is_ptr(node.expr_type) ? (_SLIT("->")) : (_SLIT("."))); v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("/* as */ *("), 0xfe10, {.d_s = styp}}, {_SLIT("*)__as_cast("), 0, { .d_c = 0 }}}))); @@ -69368,9 +69406,8 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_as_cast(v__gen__c__Gen* g, v__ast__AsCast no v__gen__c__Gen_expr(g, node.expr); v__gen__c__Gen_write(g, _SLIT(")")); v__gen__c__Gen_write(g, dot); - string sidx = v__gen__c__Gen_type_sidx(g, node.typ); - v__ast__TypeSymbol* expected_sym = v__ast__Table_sym(g->table, node.typ); - v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("_typ, "), 0xfe10, {.d_s = sidx}}, {_SLIT(") /*expected idx: "), 0xfe10, {.d_s = sidx}}, {_SLIT(", name: "), 0xfe10, {.d_s = expected_sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); + string sidx = v__gen__c__Gen_type_sidx(g, unwrapped_node_typ); + v__gen__c__Gen_write(g, str_intp(4, _MOV((StrIntpData[]){{_SLIT("_typ, "), 0xfe10, {.d_s = sidx}}, {_SLIT(") /*expected idx: "), 0xfe10, {.d_s = sidx}}, {_SLIT(", name: "), 0xfe10, {.d_s = sym->name}}, {_SLIT(" */ "), 0, { .d_c = 0 }}}))); for (int _t1 = 0; _t1 < (*expr_type_sym->info._v__ast__SumType).variants.len; ++_t1) { v__ast__Type variant = ((v__ast__Type*)(*expr_type_sym->info._v__ast__SumType).variants.data)[_t1]; string idx = u32_str(((u32)(variant))); @@ -69501,8 +69538,8 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_interface_table(v__gen__c__Gen* g) { int current_iinidx = iinidx_minimum_base; for (int _t2 = 0; _t2 < inter_info.types.len; ++_t2) { v__ast__Type st = ((v__ast__Type*)inter_info.types.data)[_t2]; - v__ast__TypeSymbol* st_sym = v__ast__Table_sym(g->table, st); - string cctype = v__gen__c__Gen_cc_type(g, st, true); + v__ast__TypeSymbol* st_sym = v__ast__Table_sym(g->table, v__ast__mktyp(st)); + string cctype = v__gen__c__Gen_cc_type(g, v__ast__mktyp(st), true); string interface_index_name = str_intp(3, _MOV((StrIntpData[]){{_SLIT("_"), 0xfe10, {.d_s = interface_name}}, {_SLIT("_"), 0xfe10, {.d_s = cctype}}, {_SLIT("_index"), 0, { .d_c = 0 }}})); if ((*(int*)map_get(ADDR(map, already_generated_mwrappers), &(string[]){interface_index_name}, &(int[]){ 0 })) > 0) { continue; @@ -69698,8 +69735,8 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_interface_table(v__gen__c__Gen* g) { int params_start_pos = g->out.len; Array_v__ast__Param params = array_clone_to_depth(&method.params, 0); array_set(¶ms, 0, &(v__ast__Param[]) { ((v__ast__Param){(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).pos,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).name,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).is_mut,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).is_auto_rec,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).type_pos,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).is_hidden,.typ = v__ast__Type_set_nr_muls(st, 1),}) }); - multi_return_Array_string_Array_string_Array_bool mr_168158 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); - Array_string fargs = mr_168158.arg0; + multi_return_Array_string_Array_string_Array_bool mr_168560 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); + Array_string fargs = mr_168560.arg0; string parameter_name = strings__Builder_cut_last(&g->out, g->out.len - params_start_pos); if (v__ast__Type_is_ptr(st)) { parameter_name = string_trim_string_left(parameter_name, _SLIT("__shared__")); @@ -69716,8 +69753,8 @@ VV_LOCAL_SYMBOL string v__gen__c__Gen_interface_table(v__gen__c__Gen* g) { *(multi_return_v__ast__Fn_Array_v__ast__Type*) _t26.data = (multi_return_v__ast__Fn_Array_v__ast__Type){.arg0=((v__ast__Fn){.is_variadic = 0,.language = 0,.is_pub = 0,.is_ctor_new = 0,.is_deprecated = 0,.is_noreturn = 0,.is_unsafe = 0,.is_placeholder = 0,.is_main = 0,.is_test = 0,.is_keep_alive = 0,.is_method = 0,.no_body = 0,.mod = (string){.str=(byteptr)"", .is_lit=1},.file = (string){.str=(byteptr)"", .is_lit=1},.file_mode = 0,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.return_type_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.return_type = 0,.receiver_type = 0,.name = (string){.str=(byteptr)"", .is_lit=1},.params = __new_array(0, 0, sizeof(v__ast__Param)),.source_fn = 0,.usages = 0,.generic_names = __new_array(0, 0, sizeof(string)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.is_conditional = 0,.ctdefine_idx = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__Fn_Array_v__ast__Type mr_168622 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); - Array_v__ast__Type embed_types = mr_168622.arg1; + multi_return_v__ast__Fn_Array_v__ast__Type mr_169024 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); + Array_v__ast__Type embed_types = mr_169024.arg1; if (embed_types.len > 0 && !Array_string_contains(method_names, method.name)) { v__ast__TypeSymbol* embed_sym = v__ast__Table_sym(g->table, (*(v__ast__Type*)array_last(embed_types))); string method_name = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, 0xfe10, {.d_s = embed_sym->cname}}, {_SLIT("_"), 0xfe10, {.d_s = method.name}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -84071,10 +84108,13 @@ v__ast__Type v__parser__Parser_parse_type(v__parser__Parser* p) { v__parser__Parser_error_with_pos(p, _SLIT("cannot use `mut` on struct field type"), v__token__Token_pos(&p->tok)); } } - if (p->tok.kind == v__token__Kind__key_mut || is_shared || is_atomic) { + if (p->tok.kind == v__token__Kind__key_mut || is_shared) { nr_muls++; v__parser__Parser_next(p); } + if (is_atomic) { + v__parser__Parser_next(p); + } if (p->tok.kind == v__token__Kind__mul) { v__parser__Parser_error(p, _SLIT("use `&Type` instead of `*Type` when declaring references")); v__ast__Type _t2 = 0;