diff --git a/v.c b/v.c index 2980f8c..38329e6 100644 --- a/v.c +++ b/v.c @@ -1,11 +1,11 @@ -#define V_COMMIT_HASH "b10cf3e0f" +#define V_COMMIT_HASH "12ec3b9d5" #ifndef V_COMMIT_HASH - #define V_COMMIT_HASH "0bd8d872d" + #define V_COMMIT_HASH "b10cf3e0f" #endif #ifndef V_CURRENT_COMMIT_HASH - #define V_CURRENT_COMMIT_HASH "b10cf3e" + #define V_CURRENT_COMMIT_HASH "12ec3b9" #endif // V comptime_definitions: @@ -5220,6 +5220,7 @@ struct v__ast__SelectorExpr { v__token__Kind next_token : 7; v__ast__GenericKindField gkind_field : 2; bool is_mut : 1; + bool has_hidden_receiver : 1; }; @@ -7845,6 +7846,7 @@ Array_string string_fields(string s); string string_strip_margin(string s); string string_strip_margin_custom(string s, u8 del); bool string_match_glob(string name, string pattern); +bool string_is_ascii(string s); Array_u8 byteptr_vbytes(byteptr data, int len); string byteptr_vstring(byteptr bp); string byteptr_vstring_with_len(byteptr bp, int len); @@ -7941,6 +7943,17 @@ VV_LOCAL_SYMBOL IError os__error_file_not_opened(void); VV_LOCAL_SYMBOL IError os__error_size_of_type_0(void); _option_void os__File_seek(os__File* f, i64 pos, os__SeekMode mode); _option_i64 os__File_tell(os__File* f); +rune _const_os__fslash = '/'; // precomputed +#define _const_os__bslash '\\' +rune _const_os__dot = '.'; // precomputed +bool os__is_abs_path(string path); +VV_LOCAL_SYMBOL int os__win_volume_len(string path); +VV_LOCAL_SYMBOL bool os__is_slash(u8 b); +VV_LOCAL_SYMBOL bool os__is_device_path(string path); +VV_LOCAL_SYMBOL bool os__has_drive_letter(string path); +VV_LOCAL_SYMBOL bool os__starts_w_slash_slash(string path); +VV_LOCAL_SYMBOL bool os__is_drive_rooted(string path); +VV_LOCAL_SYMBOL bool os__is_normal_path(string path); u32 os__FilePermission_bitmask(os__FilePermission p); u32 os__FileMode_bitmask(os__FileMode m); os__FileMode os__inode(string path); @@ -8027,7 +8040,6 @@ VV_LOCAL_SYMBOL IError os__error_failed_to_find_executable(void); _option_string os__find_abs_path_of_executable(string exepath); bool os__exists_in_system_path(string prog); bool os__is_file(string path); -bool os__is_abs_path(string path); string os__join_path(string base, Array_string dirs); string os__join_path_single(string base, string elem); Array_string os__walk_ext(string path, string ext); @@ -8907,6 +8919,7 @@ i64 _const_time__absolute_zero_year; // inited later #define _const_time__days_per_400_years 146097 #define _const_time__days_per_100_years 36524 #define _const_time__days_per_4_years 1461 +#define _const_time__days_in_year 365 Array_int _const_time__days_before; // inited later string time__Time_smonth(time__Time* t); i64 time__Time_unix_time(time__Time* t); @@ -22446,6 +22459,20 @@ bool string_match_glob(string name, string pattern) { return true; } +bool string_is_ascii(string s) { + bool _t2 = false; + Array_u8 _t2_orig = string_bytes(s); + int _t2_len = _t2_orig.len; + for (int _t3 = 0; _t3 < _t2_len; ++_t3) { + u8 it = ((u8*) _t2_orig.data)[_t3]; + if (it < ((u8)(' ')) || it > ((u8)('~'))) { + _t2 = true; + break; + } + } + return !_t2; +} + // Attr: [unsafe] Array_u8 byteptr_vbytes(byteptr data, int len) { return voidptr_vbytes(((voidptr)(data)), len); @@ -24338,6 +24365,94 @@ _option_i64 os__File_tell(os__File* f) { return _t3; } +bool os__is_abs_path(string path) { + if (path.len == 0) { + bool _t1 = false; + return _t1; + } + #if defined(_WIN32) + { + bool _t2 = os__is_device_path(path) || os__is_drive_rooted(path) || os__is_normal_path(path); + return _t2; + } + #endif + bool _t3 = string_at(path, 0) == _const_os__fslash; + return _t3; +} + +VV_LOCAL_SYMBOL int os__win_volume_len(string path) { + int plen = path.len; + if (plen < 2) { + int _t1 = 0; + return _t1; + } + if (os__has_drive_letter(path)) { + int _t2 = 2; + return _t2; + } + if (path.len >= 5 && os__starts_w_slash_slash(path) && !os__is_slash(string_at(path, 2))) { + for (int i = 3; i < plen; i++) { + if (os__is_slash(string_at(path, i))) { + if (i + 1 >= plen || os__is_slash(string_at(path, i + 1))) { + break; + } + i++; + for (; i < plen; i++) { + if (os__is_slash(string_at(path, i))) { + int _t3 = i; + return _t3; + } + } + int _t4 = i; + return _t4; + } + } + } + int _t5 = 0; + return _t5; +} + +VV_LOCAL_SYMBOL bool os__is_slash(u8 b) { + #if defined(_WIN32) + { + bool _t1 = b == _const_os__bslash || b == _const_os__fslash; + return _t1; + } + #endif + bool _t2 = b == _const_os__fslash; + return _t2; +} + +VV_LOCAL_SYMBOL bool os__is_device_path(string path) { + bool _t1 = os__win_volume_len(path) >= 5 && os__starts_w_slash_slash(path); + return _t1; +} + +VV_LOCAL_SYMBOL bool os__has_drive_letter(string path) { + bool _t1 = path.len >= 2 && u8_is_letter(string_at(path, 0)) && string_at(path, 1) == ':'; + return _t1; +} + +VV_LOCAL_SYMBOL bool os__starts_w_slash_slash(string path) { + bool _t1 = path.len >= 2 && os__is_slash(string_at(path, 0)) && os__is_slash(string_at(path, 1)); + return _t1; +} + +VV_LOCAL_SYMBOL bool os__is_drive_rooted(string path) { + bool _t1 = path.len >= 3 && os__has_drive_letter(path) && os__is_slash(string_at(path, 2)); + return _t1; +} + +VV_LOCAL_SYMBOL bool os__is_normal_path(string path) { + int plen = path.len; + if (plen == 0) { + bool _t1 = false; + return _t1; + } + bool _t2 = (plen == 1 && os__is_slash(string_at(path, 0))) || (plen >= 2 && os__is_slash(string_at(path, 0)) && !os__is_slash(string_at(path, 1))); + return _t2; +} + u32 os__FilePermission_bitmask(os__FilePermission p) { u32 mask = ((u32)(0U)); if (p.read) { @@ -26733,21 +26848,6 @@ bool os__is_file(string path) { return _t1; } -bool os__is_abs_path(string path) { - if (path.len == 0) { - bool _t1 = false; - return _t1; - } - #if defined(_WIN32) - { - bool _t2 = string_at(path, 0) == '/' || (u8_is_letter(string_at(path, 0)) && path.len > 1 && string_at(path, 1) == ':'); - return _t2; - } - #endif - bool _t3 = string_at(path, 0) == '/'; - return _t3; -} - // Attr: [manualfree] string os__join_path(string base, Array_string dirs) { bool os__join_path_defer_0 = false; @@ -30860,16 +30960,16 @@ VV_LOCAL_SYMBOL _option_semver__Version semver__parse_xrange(string input) { } if (typ == (_const_semver__ver_major)) { - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_major)) = _SLIT("0"); - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_minor)) = _SLIT("0"); - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_patch)) = _SLIT("0"); + array_set(&raw_ver.raw_ints, _const_semver__ver_major, &(string[]) { _SLIT("0") }); + array_set(&raw_ver.raw_ints, _const_semver__ver_minor, &(string[]) { _SLIT("0") }); + array_set(&raw_ver.raw_ints, _const_semver__ver_patch, &(string[]) { _SLIT("0") }); } else if (typ == (_const_semver__ver_minor)) { - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_minor)) = _SLIT("0"); - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_patch)) = _SLIT("0"); + array_set(&raw_ver.raw_ints, _const_semver__ver_minor, &(string[]) { _SLIT("0") }); + array_set(&raw_ver.raw_ints, _const_semver__ver_patch, &(string[]) { _SLIT("0") }); } else if (typ == (_const_semver__ver_patch)) { - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_patch)) = _SLIT("0"); + array_set(&raw_ver.raw_ints, _const_semver__ver_patch, &(string[]) { _SLIT("0") }); } else { }; @@ -33016,11 +33116,11 @@ f64 math__cbrt(f64 a) { x = -x; sign = true; } - f64 t = math__f64_from_bits(math__f64_bits(x) / ((u64)(3 + (((u64)(b1)) << 32U)))); + f64 t = math__f64_from_bits(math__f64_bits(x) / ((u64)(3U)) + (((u64)(b1)) << 32U)); if (x < smallest_normal) { t = ((f64)(((u64)(1U)) << 54U)); t *= x; - t = math__f64_from_bits(math__f64_bits(t) / ((u64)(3 + (((u64)(b2)) << 32U)))); + t = math__f64_from_bits(math__f64_bits(t) / ((u64)(3U)) + (((u64)(b2)) << 32U)); } f64 r = t * t / x; f64 s = c + r * t; @@ -36688,7 +36788,7 @@ string time__Time_relative(time__Time* t) { string _t7 = str_intp(4, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT0, /*100 &i64*/0xfe09, {.d_i64 = d}}, {_SLIT(" days"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t7; } - if (secs < _const_time__seconds_per_hour * 24 * 365) { + if (secs < _const_time__seconds_per_hour * 24 * _const_time__days_in_year) { if (string__eq(prefix, _SLIT("in "))) { string _t8 = str_intp(2, _MOV((StrIntpData[]){{_SLIT("on "), /*115 &string*/0xfe10, {.d_s = time__Time_md(/*rec*/*t)}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t8; @@ -36696,7 +36796,7 @@ string time__Time_relative(time__Time* t) { string _t9 = str_intp(2, _MOV((StrIntpData[]){{_SLIT("last "), /*115 &string*/0xfe10, {.d_s = time__Time_md(/*rec*/*t)}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t9; } - i64 y = secs / _const_time__seconds_per_hour / 24 / 365; + i64 y = secs / _const_time__seconds_per_hour / 24 / _const_time__days_in_year; if (y == 1) { string _t10 = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT("1 year"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t10; @@ -36738,7 +36838,7 @@ string time__Time_relative_short(time__Time* t) { string _t5 = str_intp(4, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT0, /*100 &i64*/0xfe09, {.d_i64 = h}}, {_SLIT("h"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t5; } - if (secs < _const_time__seconds_per_hour * 24 * 365) { + if (secs < _const_time__seconds_per_hour * 24 * _const_time__days_in_year) { i64 d = secs / _const_time__seconds_per_hour / 24; if (d == 1) { string _t6 = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT("1d"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -36747,7 +36847,7 @@ string time__Time_relative_short(time__Time* t) { string _t7 = str_intp(4, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT0, /*100 &i64*/0xfe09, {.d_i64 = d}}, {_SLIT("d"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t7; } - i64 y = secs / _const_time__seconds_per_hour / 24 / 365; + i64 y = secs / _const_time__seconds_per_hour / 24 / _const_time__days_in_year; if (y == 1) { string _t8 = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT("1y"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t8; @@ -37087,60 +37187,29 @@ time__Time time__unix2(i64 abs, int microsecond) { VV_LOCAL_SYMBOL multi_return_int_int_int time__calculate_date_from_offset(i64 day_offset_) { i64 day_offset = day_offset_; - int year = 2001; - day_offset -= 11323; - year += ((int)(day_offset / _const_time__days_per_400_years)) * 400; - day_offset %= _const_time__days_per_400_years; - if (day_offset == _const_time__days_per_100_years * 4) { - year += 300; - day_offset -= _const_time__days_per_100_years * 3; + day_offset += 719468; + int era = 0; + if (day_offset >= 0) { + era = ((int)(day_offset / _const_time__days_per_400_years)); } else { - year += ((int)(day_offset / _const_time__days_per_100_years)) * 100; - day_offset %= _const_time__days_per_100_years; + era = ((int)((day_offset - _const_time__days_per_400_years - 1) / _const_time__days_per_400_years)); } - if (day_offset == _const_time__days_per_4_years * 25) { - year += 96; - day_offset -= _const_time__days_per_4_years * 24; + i64 doe = day_offset - era * _const_time__days_per_400_years; + i64 yoe = (doe - doe / (_const_time__days_per_4_years - 1) + doe / _const_time__days_per_100_years - doe / (_const_time__days_per_400_years - 1)) / _const_time__days_in_year; + int y = ((int)(yoe + era * 400)); + i64 doy = doe - (_const_time__days_in_year * yoe + yoe / 4 - yoe / 100); + i64 mp = (5 * doy + 2) / 153; + int d = ((int)(doy - (153 * mp + 2) / 5 + 1)); + int m = ((int)(mp)); + if (mp < 10) { + m += 3; } else { - year += ((int)(day_offset / _const_time__days_per_4_years)) * 4; - day_offset %= _const_time__days_per_4_years; + m -= 9; } - if (day_offset == 1460) { - year += 3; - day_offset -= 1095; - } else { - year += ((int)(day_offset / 365)); - day_offset %= 365; + if (m <= 2) { + y += 1; } - if (day_offset < 0) { - year--; - if (time__is_leap_year(year)) { - day_offset += 366; - } else { - day_offset += 365; - } - } - if (time__is_leap_year(year)) { - if (day_offset > 59) { - day_offset--; - } else if (day_offset == 59) { - return (multi_return_int_int_int){.arg0=year, .arg1=2, .arg2=29}; - } - } - i64 estimated_month = day_offset / 31; - for (;;) { - if (!(day_offset >= (*(int*)/*ee elem_sym */array_get(_const_time__days_before, estimated_month + 1)))) break; - estimated_month++; - } - for (;;) { - if (!(day_offset < (*(int*)/*ee elem_sym */array_get(_const_time__days_before, estimated_month)))) break; - if (estimated_month == 0) { - break; - } - estimated_month--; - } - day_offset -= (*(int*)/*ee elem_sym */array_get(_const_time__days_before, estimated_month)); - return (multi_return_int_int_int){.arg0=year, .arg1=((int)(estimated_month + 1)), .arg2=((int)(day_offset + 1))}; + return (multi_return_int_int_int){.arg0=y, .arg1=m, .arg2=d}; } VV_LOCAL_SYMBOL multi_return_int_int_int time__calculate_time_from_offset(i64 second_offset_) { @@ -38113,7 +38182,7 @@ void v__pref__Preferences_fill_with_defaults(v__pref__Preferences* p) { } #endif } - string vhash = _SLIT("0bd8d872d"); + string vhash = _SLIT("b10cf3e0f"); 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, /*115 &v.pref.Backend*/0xfe10, {.d_s = v__pref__Backend_str(p->backend)}}, {_SLIT(" | "), /*115 &v.pref.OS*/0xfe10, {.d_s = v__pref__OS_str(p->os)}}, {_SLIT(" | "), /*115 &string*/0xfe10, {.d_s = p->ccompiler}}, {_SLIT(" | "), /*115 &bool*/0xfe10, {.d_s = p->is_prod ? _SLIT("true") : _SLIT("false")}}, {_SLIT(" | "), /*115 &bool*/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; @@ -42235,7 +42304,7 @@ VV_LOCAL_SYMBOL void sync__pool__process_in_thread(sync__pool__PoolProcessor* po if (idx >= ilen) { break; } - (*(voidptr*)/*ee elem_sym */array_get(pool->results, idx)) = cb(pool, idx, task_id); + array_set(&pool->results, idx, &(voidptr[]) { cb(pool, idx, task_id) }); } sync__WaitGroup_done(&pool->waitgroup); } @@ -42264,7 +42333,7 @@ voidptr sync__pool__PoolProcessor_get_shared_context(sync__pool__PoolProcessor* } void sync__pool__PoolProcessor_set_thread_context(sync__pool__PoolProcessor* pool, int idx, voidptr context) { - (*(voidptr*)/*ee elem_sym */array_get(pool->thread_contexts, idx)) = context; + array_set(&pool->thread_contexts, idx, &(voidptr[]) { context }); } voidptr sync__pool__PoolProcessor_get_thread_context(sync__pool__PoolProcessor* pool, int idx) { @@ -46292,7 +46361,7 @@ VV_LOCAL_SYMBOL int v__ast__Table_rewrite_already_registered_symbol(v__ast__Tabl } #endif if (existing_symbol->kind == v__ast__Kind__placeholder) { - (*(v__ast__TypeSymbol**)/*ee elem_sym */array_get(t->type_symbols, existing_idx)) = ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){.methods = existing_symbol->methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))); + array_set(&t->type_symbols, existing_idx, &(v__ast__TypeSymbol*[]) { ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){.methods = existing_symbol->methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))) }); int _t1 = existing_idx; return _t1; } @@ -46302,7 +46371,7 @@ VV_LOCAL_SYMBOL int v__ast__Table_rewrite_already_registered_symbol(v__ast__Tabl *existing_symbol = *((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){typ.methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,.kind = existing_symbol->kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))); } } else { - (*(v__ast__TypeSymbol**)/*ee elem_sym */array_get(t->type_symbols, existing_idx)) = ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){typ.methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))); + array_set(&t->type_symbols, existing_idx, &(v__ast__TypeSymbol*[]) { ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){typ.methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))) }); } int _t2 = existing_idx; return _t2; @@ -49546,7 +49615,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t9; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t9), sizeof(v__ast__Fn)); return _t9; @@ -49583,7 +49651,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t15; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t15), sizeof(v__ast__Fn)); return _t15; @@ -49620,7 +49687,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t21; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t21), sizeof(v__ast__Fn)); return _t21; @@ -49670,7 +49736,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t28; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t28), sizeof(v__ast__Fn)); return _t28; @@ -49707,7 +49772,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t34; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t34), sizeof(v__ast__Fn)); return _t34; @@ -49744,7 +49808,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t40; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t40), sizeof(v__ast__Fn)); return _t40; @@ -49794,7 +49857,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t47; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t47), sizeof(v__ast__Fn)); return _t47; @@ -49831,7 +49893,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t53; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t53), sizeof(v__ast__Fn)); return _t53; @@ -49868,7 +49929,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t59; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t59), sizeof(v__ast__Fn)); return _t59; @@ -50250,7 +50310,7 @@ bool v__checker__Checker_assign_stmt_defer_0 = false; if (left->_typ == 268 /* v.ast.Ident */) { if ((*left->_v__ast__Ident).kind == v__ast__IdentKind__blank_ident) { left_type = right_type; - (*(v__ast__Type*)/*ee elem_sym */array_get(node->left_types, i)) = right_type; + array_set(&node->left_types, i, &(v__ast__Type[]) { right_type }); if (!(node->op == v__token__Kind__assign || node->op == v__token__Kind__decl_assign)) { v__checker__Checker_error(c, _SLIT("cannot modify blank `_` identifier"), (*left->_v__ast__Ident).pos); } @@ -50278,7 +50338,7 @@ bool v__checker__Checker_assign_stmt_defer_0 = false; if (ident_var_info.share == v__ast__ShareType__atomic_t) { left_type = v__ast__Type_set_flag(left_type, v__ast__TypeFlag__atomic_f); } - (*(v__ast__Type*)/*ee elem_sym */array_get(node->left_types, i)) = left_type; + array_set(&node->left_types, i, &(v__ast__Type[]) { left_type }); ident_var_info.typ = left_type; (*left->_v__ast__Ident).info = v__ast__IdentVar_to_sumtype_v__ast__IdentInfo(&ident_var_info); if (left_type != 0) { @@ -52372,8 +52432,9 @@ v__ast__Type former_expected_type; } } } - } else if (v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional) && v__ast__Type_has_flag(right_type, v__ast__TypeFlag__optional)) { - v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be compared in an infix expression"), left_right_pos); + } else if (v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional) || v__ast__Type_has_flag(right_type, v__ast__TypeFlag__optional)) { + v__token__Pos opt_comp_pos = (v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional) ? (left_pos) : (right_pos)); + v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be compared in an infix expression"), opt_comp_pos); } break; } @@ -52384,8 +52445,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_34962 = v__checker__Checker_fail_if_immutable(c, node->left); - node->auto_locked = mr_34962.arg0; + multi_return_string_v__token__Pos mr_35045 = v__checker__Checker_fail_if_immutable(c, node->left); + node->auto_locked = mr_35045.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_) { @@ -52729,8 +52790,11 @@ v__ast__Type former_expected_type; } bool left_is_optional = v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional); bool right_is_optional = v__ast__Type_has_flag(right_type, v__ast__TypeFlag__optional); - if ((left_is_optional && !right_is_optional) || (!left_is_optional && right_is_optional)) { - v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be used in an infix expression"), left_right_pos); + if (left_is_optional && right_is_optional) { + v__checker__Checker_error(c, _SLIT("unwrapped optionals cannot be used in an infix expression"), left_right_pos); + } else if (left_is_optional || right_is_optional) { + v__token__Pos opt_infix_pos = (left_is_optional ? (left_pos) : (right_pos)); + v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be used in an infix expression"), opt_infix_pos); } if (!(v__checker__Checker_symmetric_check(c, left_type, right_type) && v__checker__Checker_symmetric_check(c, right_type, left_type)) && !c->pref->translated && !c->file->is_translated && !v__ast__Expr_is_auto_deref_var(node->left) && !v__ast__Expr_is_auto_deref_var(node->right)) { if (v__ast__Type_alias_eq(left_type, _const_v__ast__void_type) || v__ast__Type_alias_eq(right_type, _const_v__ast__void_type)) { @@ -52821,19 +52885,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` "), /*115 &string*/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_45479 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); - to_lock = mr_45479.arg0; - pos = mr_45479.arg1; + multi_return_string_v__token__Pos mr_45723 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); + to_lock = mr_45723.arg0; + pos = mr_45723.arg1; } else if (expr._typ == 283 /* v.ast.ParExpr */) { - multi_return_string_v__token__Pos mr_45548 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); - to_lock = mr_45548.arg0; - pos = mr_45548.arg1; + multi_return_string_v__token__Pos mr_45792 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); + to_lock = mr_45792.arg0; + pos = mr_45792.arg1; } else if (expr._typ == 285 /* v.ast.PrefixExpr */) { - multi_return_string_v__token__Pos mr_45620 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); - to_lock = mr_45620.arg0; - pos = mr_45620.arg1; + multi_return_string_v__token__Pos mr_45864 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); + to_lock = mr_45864.arg0; + pos = mr_45864.arg1; } else if (expr._typ == 288 /* v.ast.SelectorExpr */) { if ((*expr._v__ast__SelectorExpr).expr_type == 0) { @@ -52883,9 +52947,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 `"), /*115 &string*/0xfe10, {.d_s = (*expr._v__ast__SelectorExpr).field_name}}, {_SLIT("` of struct `"), /*115 &string*/0xfe10, {.d_s = type_str}}, {_SLIT("` is immutable"), 0, { .d_c = 0 }}})), (*expr._v__ast__SelectorExpr).pos); } - multi_return_string_v__token__Pos mr_47084 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); - to_lock = mr_47084.arg0; - pos = mr_47084.arg1; + multi_return_string_v__token__Pos mr_47328 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); + to_lock = mr_47328.arg0; + pos = mr_47328.arg1; } if ((to_lock).len != 0) { explicit_lock_needed = true; @@ -52991,9 +53055,9 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im } else if (expr._typ == 254 /* v.ast.CallExpr */) { if (string__eq((*expr._v__ast__CallExpr).name, _SLIT("slice"))) { - multi_return_string_v__token__Pos mr_48907 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); - to_lock = mr_48907.arg0; - pos = mr_48907.arg1; + multi_return_string_v__token__Pos mr_49151 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); + to_lock = mr_49151.arg0; + pos = mr_49151.arg1; if ((to_lock).len != 0) { explicit_lock_needed = true; } @@ -53411,9 +53475,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){.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.default_val = (string){.str=(byteptr)"", .is_lit=1},.default_expr = {0},.name = (string){.str=(byteptr)"", .is_lit=1},.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,},.i = 0,.default_expr_typ = 0,.typ = 0,.has_default_expr = 0,.is_pub = 0,.is_mut = 0,.is_global = 0,.is_volatile = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_63001 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); - field = mr_63001.arg0; - embed_types = mr_63001.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_63245 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); + field = mr_63245.arg0; + embed_types = mr_63245.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); @@ -53447,9 +53511,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){.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.default_val = (string){.str=(byteptr)"", .is_lit=1},.default_expr = {0},.name = (string){.str=(byteptr)"", .is_lit=1},.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,},.i = 0,.default_expr_typ = 0,.typ = 0,.has_default_expr = 0,.is_pub = 0,.is_mut = 0,.is_global = 0,.is_volatile = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_63832 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); - field = mr_63832.arg0; - embed_types = mr_63832.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_64076 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); + field = mr_64076.arg0; + embed_types = mr_64076.arg1; node->from_embed_types = embed_types; } } @@ -53488,13 +53552,41 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S v__ast__Type _t21 = field.typ; return _t21; } + _option_v__ast__Fn _t22; + if (_t22 = v__ast__Table_find_method(c->table, sym, field_name), _t22.state == 0) { + v__ast__Fn method = *(v__ast__Fn*)_t22.data; + if (c->expected_type != 0 && !v__ast__Type_alias_eq(c->expected_type, _const_v__ast__none_type)) { + v__ast__Type fn_type = v__ast__new_type(v__ast__Table_find_or_register_fn_type(c->table, c->mod, method, false, true)); + if (v__checker__Checker_check_types(c, fn_type, c->expected_type)) { + v__ast__Type _t23 = fn_type; + return _t23; + } + } + v__ast__Type receiver = (*(v__ast__Param*)/*ee elem_sym */array_get(method.params, 0)).typ; + if (v__ast__Type_nr_muls(receiver) > 0) { + if (!c->inside_unsafe) { + v__ast__TypeSymbol* rec_sym = v__ast__Table_sym(c->table, v__ast__Type_set_nr_muls(receiver, 0)); + if (!v__ast__TypeSymbol_is_heap(rec_sym)) { + string suggestion = (rec_sym->kind == v__ast__Kind__struct_ ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("declaring `"), /*115 &string*/0xfe10, {.d_s = rec_sym->name}}, {_SLIT("` as `[heap]`"), 0, { .d_c = 0 }}}))) : ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("wrapping the `"), /*115 &string*/0xfe10, {.d_s = rec_sym->name}}, {_SLIT("` object in a `struct` declared as `[heap]`"), 0, { .d_c = 0 }}})))); + v__checker__Checker_error(c, str_intp(4, _MOV((StrIntpData[]){{_SLIT("method `"), /*115 &string*/0xfe10, {.d_s = v__ast__Table_type_to_str(c->table, v__ast__Type_idx(receiver))}}, {_SLIT("."), /*115 &string*/0xfe10, {.d_s = method.name}}, {_SLIT("` cannot be used as a variable outside `unsafe` blocks as its receiver might refer to an object stored on stack. Consider "), /*115 &string*/0xfe10, {.d_s = suggestion}}, {_SLIT("."), 0, { .d_c = 0 }}})), v__token__Pos_extend(v__ast__Expr_pos(node->expr), node->pos)); + } + } + } + Array_v__ast__Param _t24; + method.params = (_t24 = method.params, array_slice(_t24, 1, _t24.len)); + node->has_hidden_receiver = true; + method.name = _SLIT(""); + v__ast__Type fn_type = v__ast__new_type(v__ast__Table_find_or_register_fn_type(c->table, c->mod, method, false, true)); + v__ast__Type _t25 = fn_type; + return _t25; + } if (!(sym->kind == v__ast__Kind__struct_ || sym->kind == v__ast__Kind__aggregate || sym->kind == v__ast__Kind__interface_ || sym->kind == v__ast__Kind__sum_type)) { if (sym->kind != v__ast__Kind__placeholder) { v__ast__TypeSymbol* unwrapped_sym = v__ast__Table_sym(c->table, v__checker__Checker_unwrap_generic(c, typ)); if (unwrapped_sym->kind == v__ast__Kind__array_fixed && string__eq(node->field_name, _SLIT("len"))) { node->typ = _const_v__ast__int_type; - v__ast__Type _t22 = _const_v__ast__int_type; - return _t22; + v__ast__Type _t26 = _const_v__ast__int_type; + return _t26; } v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("`"), /*115 &string*/0xfe10, {.d_s = unwrapped_sym->name}}, {_SLIT("` has no property `"), /*115 &string*/0xfe10, {.d_s = node->field_name}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); } @@ -53503,20 +53595,20 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S if (!v__token__Pos_struct_eq(c->smartcast_mut_pos, ((v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,}))) { v__checker__Checker_note(c, _SLIT("smartcasting requires either an immutable value, or an explicit mut keyword before the value"), c->smartcast_mut_pos); } - Array_string _t23 = {0}; - Array_v__ast__StructField _t23_orig = (*sym->info._v__ast__Struct).fields; - int _t23_len = _t23_orig.len; - _t23 = __new_array(0, _t23_len, sizeof(string)); + Array_string _t27 = {0}; + Array_v__ast__StructField _t27_orig = (*sym->info._v__ast__Struct).fields; + int _t27_len = _t27_orig.len; + _t27 = __new_array(0, _t27_len, sizeof(string)); - for (int _t24 = 0; _t24 < _t23_len; ++_t24) { - v__ast__StructField it = ((v__ast__StructField*) _t23_orig.data)[_t24]; + for (int _t28 = 0; _t28 < _t27_len; ++_t28) { + v__ast__StructField it = ((v__ast__StructField*) _t27_orig.data)[_t28]; string ti = it.name; - array_push((array*)&_t23, &ti); + array_push((array*)&_t27, &ti); } - v__util__Suggestion suggestion = v__util__new_suggestion(field_name,_t23); + v__util__Suggestion suggestion = v__util__new_suggestion(field_name,_t27); v__checker__Checker_error(c, v__util__Suggestion_say(suggestion, unknown_field_msg), node->pos); - v__ast__Type _t25 = _const_v__ast__void_type; - return _t25; + v__ast__Type _t29 = _const_v__ast__void_type; + return _t29; } if (!v__token__Pos_struct_eq(c->smartcast_mut_pos, ((v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,}))) { v__checker__Checker_note(c, _SLIT("smartcasting requires either an immutable value, or an explicit mut keyword before the value"), c->smartcast_mut_pos); @@ -53526,8 +53618,8 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S } v__checker__Checker_error(c, unknown_field_msg, node->pos); } - v__ast__Type _t26 = _const_v__ast__void_type; - return _t26; + v__ast__Type _t30 = _const_v__ast__void_type; + return _t30; } void v__checker__Checker_const_decl(v__checker__Checker* c, v__ast__ConstDecl* node) { @@ -53686,7 +53778,7 @@ VV_LOCAL_SYMBOL void v__checker__Checker_stmt(v__checker__Checker* c, v__ast__St v__ast__Ident id = ident; if ((id.info)._typ == 378 /* v.ast.IdentVar */) { if (id.comptime && Array_string_contains(_const_v__checker__valid_comptime_not_user_defined, id.name)) { - (*(v__ast__Ident*)/*ee elem_sym */array_get((*node._v__ast__DeferStmt).defer_vars, i)) = ((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = _SLIT(""),.info = {0},.scope = 0,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,}); + array_set(&(*node._v__ast__DeferStmt).defer_vars, i, &(v__ast__Ident[]) { ((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = _SLIT(""),.info = {0},.scope = 0,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,}) }); continue; } v__ast__Type typ = v__checker__Checker_ident(c, (voidptr)&/*qq*/id); @@ -53694,7 +53786,7 @@ VV_LOCAL_SYMBOL void v__checker__Checker_stmt(v__checker__Checker* c, v__ast__St continue; } (*id.info._v__ast__IdentVar).typ = typ; - (*(v__ast__Ident*)/*ee elem_sym */array_get((*node._v__ast__DeferStmt).defer_vars, i)) = id; + array_set(&(*node._v__ast__DeferStmt).defer_vars, i, &(v__ast__Ident[]) { id }); } } c->inside_defer = true; @@ -55353,15 +55445,38 @@ v__ast__Type v__checker__Checker_ident(v__checker__Checker* c, v__ast__Ident* no if (c->inside_ct_attr) { v__checker__Checker_note(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("`[if "), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("]` is deprecated. Use `[if "), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("?]` instead"), 0, { .d_c = 0 }}})), node->pos); } else { - v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("undefined ident: `"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); + string cname_mod = string_all_before(node->name, _SLIT(".")); + if (cname_mod.len != node->name.len) { + Array_string const_names_in_mod = __new_array_with_default(0, 0, sizeof(string), 0); + Map_string_v__ast__ScopeObject _t21 = c->table->global_scope->objects; + int _t23 = _t21.key_values.len; + for (int _t22 = 0; _t22 < _t23; ++_t22 ) { + int _t24 = _t21.key_values.len - _t23; + _t23 = _t21.key_values.len; + if (_t24 < 0) { + _t22 = -1; + continue; + } + if (!DenseArray_has_index(&_t21.key_values, _t22)) {continue;} + v__ast__ScopeObject so = (*(v__ast__ScopeObject*)DenseArray_value(&_t21.key_values, _t22)); + if ((so)._typ == 324 /* v.ast.ConstField */) { + if (string__eq((*so._v__ast__ConstField).mod, cname_mod)) { + array_push((array*)&const_names_in_mod, _MOV((string[]){ string_clone((*so._v__ast__ConstField).name) })); + } + } + } + v__checker__Checker_error(c, v__util__Suggestion_say(v__util__new_suggestion(node->name, const_names_in_mod), str_intp(2, _MOV((StrIntpData[]){{_SLIT("undefined ident: `"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("`"), 0, { .d_c = 0 }}}))), node->pos); + } else { + v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("undefined ident: `"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); + } } } if (v__ast__Table_known_type(c->table, node->name)) { - v__ast__Type _t21 = _const_v__ast__void_type; - return _t21; + v__ast__Type _t26 = _const_v__ast__void_type; + return _t26; } - v__ast__Type _t22 = _const_v__ast__void_type; - return _t22; + v__ast__Type _t27 = _const_v__ast__void_type; + return _t27; } v__ast__Type v__checker__Checker_concat_expr(v__checker__Checker* c, v__ast__ConcatExpr* node) { @@ -55530,6 +55645,7 @@ v__ast__Type v__checker__Checker_select_expr(v__checker__Checker* c, v__ast__Sel } v__ast__Type v__checker__Checker_lock_expr(v__checker__Checker* c, v__ast__LockExpr* node) { + v__ast__Type expected_type = c->expected_type; if (c->rlocked_names.len > 0 || c->locked_names.len > 0) { v__checker__Checker_error(c, _SLIT("nested `lock`/`rlock` not allowed"), node->pos); } @@ -55552,15 +55668,16 @@ v__ast__Type v__checker__Checker_lock_expr(v__checker__Checker* c, v__ast__LockE } } v__checker__Checker_stmts(c, node->stmts); - c->rlocked_names = __new_array_with_default(0, 0, sizeof(string), 0); - c->locked_names = __new_array_with_default(0, 0, sizeof(string), 0); v__ast__Type ret_type = _const_v__ast__void_type; if (node->stmts.len > 0) { v__ast__Stmt last_stmt = (*(v__ast__Stmt*)array_last(node->stmts)); if ((last_stmt)._typ == 308 /* v.ast.ExprStmt */) { - ret_type = (*last_stmt._v__ast__ExprStmt).typ; + c->expected_type = expected_type; + ret_type = v__checker__Checker_expr(c, (*last_stmt._v__ast__ExprStmt).expr); } } + c->rlocked_names = __new_array_with_default(0, 0, sizeof(string), 0); + c->locked_names = __new_array_with_default(0, 0, sizeof(string), 0); if (!v__ast__Type_alias_eq(ret_type, _const_v__ast__void_type)) { node->is_expr = true; } @@ -55663,8 +55780,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: "), /*115 &string*/0xfe10, {.d_s = v__token__Kind_str(node->op)}}, {_SLIT(" (non-numeric type `"), /*115 &string*/0xfe10, {.d_s = typ_str}}, {_SLIT("`)"), 0, { .d_c = 0 }}})), node->pos); } else { - multi_return_string_v__token__Pos mr_117590 = v__checker__Checker_fail_if_immutable(c, node->expr); - node->auto_locked = mr_117590.arg0; + multi_return_string_v__token__Pos mr_119540 = v__checker__Checker_fail_if_immutable(c, node->expr); + node->auto_locked = mr_119540.arg0; } v__ast__Type _t1 = typ; return _t1; @@ -59391,11 +59508,23 @@ v__ast__Type v__checker__Checker_fn_call(v__checker__Checker* c, v__ast__CallExp if (param.typ == _const_v__ast__voidptr_type_idx || arg_typ == _const_v__ast__voidptr_type_idx) { continue; } + if (v__ast__Type_is_any_kind_of_pointer(param.typ) && v__ast__Type_is_any_kind_of_pointer(arg_typ)) { + continue; + } v__ast__TypeSymbol* param_typ_sym_ = v__ast__Table_sym(c->table, v__ast__Table_unaliased_type(c->table, param.typ)); v__ast__TypeSymbol* arg_typ_sym_ = v__ast__Table_sym(c->table, v__ast__Table_unaliased_type(c->table, arg_typ)); if (((arg_typ_sym_->kind == v__ast__Kind__array_fixed || arg_typ_sym_->kind == v__ast__Kind__array) && (param_is_number || v__ast__Type_is_any_kind_of_pointer(v__ast__Table_unaliased_type(c->table, param.typ)))) || ((param_typ_sym_->kind == v__ast__Kind__array_fixed || param_typ_sym_->kind == v__ast__Kind__array) && (typ_is_number || v__ast__Type_is_any_kind_of_pointer(v__ast__Table_unaliased_type(c->table, arg_typ))))) { continue; } + if (arg_typ_sym_->kind == v__ast__Kind__array && param_typ_sym_->kind == v__ast__Kind__array) { + if (v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__Array*)__as_cast((arg_typ_sym_->info)._v__ast__Array,(arg_typ_sym_->info)._typ, 413) /*expected idx: 413, name: v.ast.Array */ ).elem_type) && v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__Array*)__as_cast((param_typ_sym_->info)._v__ast__Array,(param_typ_sym_->info)._typ, 413) /*expected idx: 413, name: v.ast.Array */ ).elem_type)) { + continue; + } + } else if (arg_typ_sym_->kind == v__ast__Kind__array_fixed && param_typ_sym_->kind == v__ast__Kind__array_fixed) { + if (v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__ArrayFixed*)__as_cast((arg_typ_sym_->info)._v__ast__ArrayFixed,(arg_typ_sym_->info)._typ, 441) /*expected idx: 441, name: v.ast.ArrayFixed */ ).elem_type) && v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__ArrayFixed*)__as_cast((param_typ_sym_->info)._v__ast__ArrayFixed,(param_typ_sym_->info)._typ, 441) /*expected idx: 441, name: v.ast.ArrayFixed */ ).elem_type)) { + continue; + } + } if (v__ast__Type_is_any_kind_of_pointer(param.typ) && typ_is_number) { continue; } @@ -59644,9 +59773,9 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal *(multi_return_v__ast__Fn_Array_v__ast__Type*) _t19.data = (multi_return_v__ast__Fn_Array_v__ast__Type){.arg0=((v__ast__Fn){.params = __new_array(0, 0, sizeof(v__ast__Param)),.generic_names = __new_array(0, 0, sizeof(string)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.mod = (string){.str=(byteptr)"", .is_lit=1},.file = (string){.str=(byteptr)"", .is_lit=1},.name = (string){.str=(byteptr)"", .is_lit=1},.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,.usages = 0,.ctdefine_idx = 0,.source_fn = 0,.language = 0,.file_mode = 0,.is_variadic = 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,.is_conditional = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__Fn_Array_v__ast__Type mr_42804 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t19.data); - method = mr_42804.arg0; - embed_types = mr_42804.arg1; + multi_return_v__ast__Fn_Array_v__ast__Type mr_43470 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t19.data); + method = mr_43470.arg0; + embed_types = mr_43470.arg1; if (embed_types.len != 0) { is_method_from_embed = true; node->from_embed_types = embed_types; @@ -59694,9 +59823,9 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal v__checker__Checker_error(c, _SLIT("method with `shared` receiver cannot be called inside `lock`/`rlock` block"), node->pos); } if ((*(v__ast__Param*)/*ee elem_sym */array_get(method.params, 0)).is_mut) { - multi_return_string_v__token__Pos mr_45114 = v__checker__Checker_fail_if_immutable(c, node->left); - string to_lock = mr_45114.arg0; - v__token__Pos pos = mr_45114.arg1; + multi_return_string_v__token__Pos mr_45780 = v__checker__Checker_fail_if_immutable(c, node->left); + string to_lock = mr_45780.arg0; + v__token__Pos pos = mr_45780.arg1; if (!v__ast__Expr_is_lvalue(node->left)) { v__checker__Checker_error(c, _SLIT("cannot pass expression as `mut`"), v__ast__Expr_pos(node->left)); } @@ -59804,9 +59933,9 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal v__checker__Checker_error(c, _SLIT("method with `shared` arguments cannot be called inside `lock`/`rlock` block"), arg->pos); } if (arg->is_mut) { - multi_return_string_v__token__Pos mr_49016 = v__checker__Checker_fail_if_immutable(c, arg->expr); - string to_lock = mr_49016.arg0; - v__token__Pos pos = mr_49016.arg1; + multi_return_string_v__token__Pos mr_49682 = v__checker__Checker_fail_if_immutable(c, arg->expr); + string to_lock = mr_49682.arg0; + v__token__Pos pos = mr_49682.arg1; if (!param_is_mut) { string tok = v__ast__ShareType_str(arg->share); v__checker__Checker_error(c, str_intp(5, _MOV((StrIntpData[]){{_SLIT("`"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("` parameter `"), /*115 &string*/0xfe10, {.d_s = param.name}}, {_SLIT("` is not `"), /*115 &string*/0xfe10, {.d_s = tok}}, {_SLIT("`, `"), /*115 &string*/0xfe10, {.d_s = tok}}, {_SLIT("` is not needed`"), 0, { .d_c = 0 }}})), v__ast__Expr_pos(arg->expr)); @@ -59996,8 +60125,8 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal return _t45; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_56382 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t44.data); - node->from_embed_types = mr_56382.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_57048 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t44.data); + node->from_embed_types = mr_57048.arg1; v__ast__Type _t46 = info.func.return_type; return _t46; } @@ -61880,7 +62009,7 @@ bool v__checker__Checker_sql_stmt_line_defer_0 = false; continue; } v__ast__StructField field = (*(v__ast__StructField*)/*ee elem_sym */array_get(x, 0)); - (*(string*)/*ee elem_sym */array_get(node->updated_columns, i)) = v__checker__Checker_fetch_field_name(c, field); + array_set(&node->updated_columns, i, &(string[]) { v__checker__Checker_fetch_field_name(c, field) }); } if (node->kind == v__ast__SqlStmtKind__update) { for (int _t10 = 0; _t10 < node->update_exprs.len; ++_t10) { @@ -62348,8 +62477,8 @@ v__ast__Type v__checker__Checker_string_inter_lit(v__checker__Checker* c, v__ast v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("no known default format for type `"), /*115 &string*/0xfe10, {.d_s = v__ast__Table_get_type_name(c->table, ftyp)}}, {_SLIT("`"), 0, { .d_c = 0 }}})), (*(v__token__Pos*)/*ee elem_sym */array_get(node->fmt_poss, i))); } } else { - (*(u8*)/*ee elem_sym */array_get(node->fmts, i)) = fmt; - (*(bool*)/*ee elem_sym */array_get(node->need_fmts, i)) = false; + array_set(&node->fmts, i, &(u8[]) { fmt }); + array_set(&node->need_fmts, i, &(bool[]) { false }); } } else { if ((*(int*)/*ee elem_sym */array_get(node->precisions, i)) != 987698 && !v__ast__Type_is_float(typ)) { @@ -62361,7 +62490,7 @@ v__ast__Type v__checker__Checker_string_inter_lit(v__checker__Checker* c, v__ast if ((v__ast__Type_is_unsigned(typ) && !(fmt == 'u' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'c' || fmt == 'b')) || (v__ast__Type_is_signed(typ) && !(fmt == 'd' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'c' || fmt == 'b')) || (v__ast__Type_is_int_literal(typ) && !(fmt == 'd' || fmt == 'c' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'u' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'b')) || (v__ast__Type_is_float(typ) && !(fmt == 'E' || fmt == 'F' || fmt == 'G' || fmt == 'e' || fmt == 'f' || fmt == 'g')) || (v__ast__Type_is_pointer(typ) && !(fmt == 'p' || fmt == 'x' || fmt == 'X')) || (v__ast__Type_is_string(typ) && !(fmt == 's' || fmt == 'S')) || ((v__ast__Type_idx(typ) == _const_v__ast__i64_type_idx || v__ast__Type_idx(typ) == _const_v__ast__f64_type_idx) && fmt == 'c')) { v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("illegal format specifier `"), /*99 &u8*/0xfe01, {.d_c = fmt}}, {_SLIT("` for type `"), /*115 &string*/0xfe10, {.d_s = v__ast__Table_get_type_name(c->table, ftyp)}}, {_SLIT("`"), 0, { .d_c = 0 }}})), (*(v__token__Pos*)/*ee elem_sym */array_get(node->fmt_poss, i))); } - (*(bool*)/*ee elem_sym */array_get(node->need_fmts, i)) = fmt != v__checker__Checker_get_default_fmt(c, ftyp, typ); + array_set(&node->need_fmts, i, &(bool[]) { fmt != v__checker__Checker_get_default_fmt(c, ftyp, typ) }); } if (c->table->cur_fn->is_method && string__eq(c->table->cur_fn->name, _SLIT("str")) && string__eq(c->table->cur_fn->receiver.name, v__ast__Expr_str(expr))) { v__checker__Checker_error(c, _SLIT("cannot call `str()` method recursively"), v__ast__Expr_pos(expr)); @@ -65256,6 +65385,13 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex } else if (node._typ == 288 /* v.ast.SelectorExpr */) { v__markused__Walker_expr(w, (*node._v__ast__SelectorExpr).expr); + if ((*node._v__ast__SelectorExpr).expr_type != 0) { + _option_v__ast__Fn _t4; + if (_t4 = v__ast__Table_find_method(w->table, v__ast__Table_sym(w->table, (*node._v__ast__SelectorExpr).expr_type), (*node._v__ast__SelectorExpr).field_name), _t4.state == 0) { + v__ast__Fn method = *(v__ast__Fn*)_t4.data; + v__markused__Walker_fn_by_name(w, v__ast__Fn_fkey(&method)); + } + } } else if (node._typ == 290 /* v.ast.SqlExpr */) { v__markused__Walker_expr(w, (*node._v__ast__SqlExpr).db_expr); @@ -65271,8 +65407,8 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex v__ast__TypeSymbol* sym = v__ast__Table_sym(w->table, (*node._v__ast__StructInit).typ); if (sym->kind == v__ast__Kind__struct_) { v__ast__Struct info = /* as */ *(v__ast__Struct*)__as_cast((sym->info)._v__ast__Struct,(sym->info)._typ, 418) /*expected idx: 418, name: v.ast.Struct */ ; - for (int _t4 = 0; _t4 < info.fields.len; ++_t4) { - v__ast__StructField ifield = ((v__ast__StructField*)info.fields.data)[_t4]; + for (int _t5 = 0; _t5 < info.fields.len; ++_t5) { + v__ast__StructField ifield = ((v__ast__StructField*)info.fields.data)[_t5]; if (ifield.has_default_expr) { v__markused__Walker_expr(w, ifield.default_expr); } @@ -65287,12 +65423,12 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex if ((*node._v__ast__StructInit).has_update_expr) { v__markused__Walker_expr(w, (*node._v__ast__StructInit).update_expr); } - for (int _t5 = 0; _t5 < (*node._v__ast__StructInit).fields.len; ++_t5) { - v__ast__StructInitField sif = ((v__ast__StructInitField*)(*node._v__ast__StructInit).fields.data)[_t5]; + for (int _t6 = 0; _t6 < (*node._v__ast__StructInit).fields.len; ++_t6) { + v__ast__StructInitField sif = ((v__ast__StructInitField*)(*node._v__ast__StructInit).fields.data)[_t6]; v__markused__Walker_expr(w, sif.expr); } - for (int _t6 = 0; _t6 < (*node._v__ast__StructInit).embeds.len; ++_t6) { - v__ast__StructInitEmbed sie = ((v__ast__StructInitEmbed*)(*node._v__ast__StructInit).embeds.data)[_t6]; + for (int _t7 = 0; _t7 < (*node._v__ast__StructInit).embeds.len; ++_t7) { + v__ast__StructInitEmbed sie = ((v__ast__StructInitEmbed*)(*node._v__ast__StructInit).embeds.data)[_t7]; v__markused__Walker_expr(w, sie.expr); } } @@ -65330,8 +65466,8 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex v__markused__Walker_or_block(w, (*node._v__ast__OrExpr)); } else if (node._typ == 287 /* v.ast.SelectExpr */) { - for (int _t7 = 0; _t7 < (*node._v__ast__SelectExpr).branches.len; ++_t7) { - v__ast__SelectBranch branch = ((v__ast__SelectBranch*)(*node._v__ast__SelectExpr).branches.data)[_t7]; + for (int _t8 = 0; _t8 < (*node._v__ast__SelectExpr).branches.len; ++_t8) { + v__ast__SelectBranch branch = ((v__ast__SelectBranch*)(*node._v__ast__SelectExpr).branches.data)[_t8]; v__markused__Walker_stmt(w, branch.stmt); v__markused__Walker_stmts(w, branch.stmts); } @@ -66896,7 +67032,11 @@ string sref_name; } else if (g->inside_for_c_stmt) { v__gen__c__Gen_expr(g, val); } else { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("{"), /*115 &string*/0xfe10, {.d_s = styp}}, {_SLIT(" _ = "), 0, { .d_c = 0 }}}))); + if (left_sym->kind == v__ast__Kind__function) { + v__gen__c__Gen_write(g, _SLIT("{void* _ = ")); + } else { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("{"), /*115 &string*/0xfe10, {.d_s = styp}}, {_SLIT(" _ = "), 0, { .d_c = 0 }}}))); + } v__gen__c__Gen_expr(g, val); v__gen__c__Gen_writeln(g, _SLIT(";}")); } @@ -67139,6 +67279,8 @@ string sref_name; } if ((val)._typ == 248 /* v.ast.ArrayInit */) { v__gen__c__Gen_array_init(g, (*val._v__ast__ArrayInit), ident.name); + } else if (v__ast__Type_has_flag(val_type, v__ast__TypeFlag__shared_f)) { + v__gen__c__Gen_expr_with_cast(g, val, val_type, var_type); } else { v__gen__c__Gen_expr(g, val); } @@ -73027,15 +73169,16 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_selector_expr(v__gen__c__Gen* g, v__ast__Sel string sum_type_deref_field = _SLIT(""); string sum_type_dot = _SLIT("."); _option_v__ast__StructField _t3; + _option_v__ast__Fn _t4; if (_t3 = v__ast__Table_find_field(g->table, sym, node.field_name), _t3.state == 0) { v__ast__StructField f = *(v__ast__StructField*)_t3.data; v__ast__TypeSymbol* field_sym = v__ast__Table_sym(g->table, f.typ); if (field_sym->kind == v__ast__Kind__sum_type || field_sym->kind == v__ast__Kind__interface_) { if (!prevent_sum_type_unwrapping_once) { v__ast__Scope* scope = v__ast__Scope_innermost(g->file->scope, node.pos.pos); - _option_v__ast__ScopeStructField _t4; - if (_t4 = v__ast__Scope_find_struct_field(scope, v__ast__Expr_str(node.expr), node.expr_type, node.field_name), _t4.state == 0) { - v__ast__ScopeStructField field = *(v__ast__ScopeStructField*)_t4.data; + _option_v__ast__ScopeStructField _t5; + if (_t5 = v__ast__Scope_find_struct_field(scope, v__ast__Expr_str(node.expr), node.expr_type, node.field_name), _t5.state == 0) { + v__ast__ScopeStructField field = *(v__ast__ScopeStructField*)_t5.data; if (v__ast__Type_is_ptr(field.orig_type)) { sum_type_dot = _SLIT("->"); } @@ -73060,6 +73203,67 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_selector_expr(v__gen__c__Gen* g, v__ast__Sel } } } + } else if (_t4 = v__ast__Table_find_method(g->table, sym, node.field_name), _t4.state == 0) { + v__ast__Fn m = *(v__ast__Fn*)_t4.data; + bool has_embeds = false; + if ((sym->info)._typ == 418 /* v.ast.Struct */ || (sym->info)._typ == 431 /* v.ast.Aggregate */) { + if (node.from_embed_types.len > 0) { + has_embeds = true; + } + } + if (!has_embeds) { + if (!node.has_hidden_receiver) { + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = v__gen__c__Gen_typ(g, v__ast__Type_idx(node.expr_type))}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = m.name}}, {_SLIT0, 0, { .d_c = 0 }}}))); + return; + } + v__ast__Param receiver = (*(v__ast__Param*)/*ee elem_sym */array_get(m.params, 0)); + string expr_styp = v__gen__c__Gen_typ(g, v__ast__Type_idx(node.expr_type)); + string data_styp = v__gen__c__Gen_typ(g, v__ast__Type_idx(receiver.typ)); + strings__Builder sb = strings__new_builder(256); + string name = str_intp(4, _MOV((StrIntpData[]){{_SLIT("_V_closure_"), /*115 &string*/0xfe10, {.d_s = expr_styp}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = m.name}}, {_SLIT("_"), /*100 &int*/0xfe07, {.d_i32 = node.pos.pos}}, {_SLIT0, 0, { .d_c = 0 }}})); + strings__Builder_write_string(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = v__gen__c__Gen_typ(g, m.return_type)}}, {_SLIT(" "), /*115 &string*/0xfe10, {.d_s = name}}, {_SLIT("("), 0, { .d_c = 0 }}}))); + for (int i = 1; i < m.params.len; ++i) { + v__ast__Param param = (*(v__ast__Param*)/*ee elem_sym */array_get(m.params, i)); + if (i != 1) { + strings__Builder_write_string(&sb, _SLIT(", ")); + } + strings__Builder_write_string(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = v__gen__c__Gen_typ(g, param.typ)}}, {_SLIT(" a"), /*100 &int literal*/0xfe07, {.d_i32 = i}}, {_SLIT0, 0, { .d_c = 0 }}}))); + } + strings__Builder_writeln(&sb, _SLIT(") {")); + strings__Builder_writeln(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\t"), /*115 &string*/0xfe10, {.d_s = data_styp}}, {_SLIT("* a0 = *("), /*115 &string*/0xfe10, {.d_s = data_styp}}, {_SLIT("**)(__RETURN_ADDRESS() - __CLOSURE_DATA_OFFSET);"), 0, { .d_c = 0 }}}))); + if (!v__ast__Type_alias_eq(m.return_type, _const_v__ast__void_type)) { + strings__Builder_write_string(&sb, _SLIT("\treturn ")); + } else { + strings__Builder_write_string(&sb, _SLIT("\t")); + } + strings__Builder_write_string(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = expr_styp}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = m.name}}, {_SLIT("("), 0, { .d_c = 0 }}}))); + if (!v__ast__Type_is_ptr(receiver.typ)) { + strings__Builder_write_string(&sb, _SLIT("*")); + } + for (int i = 0; i < m.params.len; ++i) { + if (i != 0) { + strings__Builder_write_string(&sb, _SLIT(", ")); + } + strings__Builder_write_string(&sb, str_intp(2, _MOV((StrIntpData[]){{_SLIT("a"), /*100 &int literal*/0xfe07, {.d_i32 = i}}, {_SLIT0, 0, { .d_c = 0 }}}))); + } + strings__Builder_writeln(&sb, _SLIT(");")); + strings__Builder_writeln(&sb, _SLIT("}")); + array_push((array*)&g->anon_fn_definitions, _MOV((string[]){ string_clone(strings__Builder_str(&sb)) })); + g->nr_closures++; + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__closure_create("), /*115 &string*/0xfe10, {.d_s = name}}, {_SLIT(", "), 0, { .d_c = 0 }}}))); + if (!v__ast__Type_is_ptr(receiver.typ)) { + v__gen__c__Gen_write(g, _SLIT("memdup(")); + } + if (!v__ast__Type_is_ptr(node.expr_type)) { + v__gen__c__Gen_write(g, _SLIT("&")); + } + v__gen__c__Gen_expr(g, node.expr); + if (!v__ast__Type_is_ptr(receiver.typ)) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT(", sizeof("), /*115 &string*/0xfe10, {.d_s = expr_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); + } + v__gen__c__Gen_write(g, _SLIT(")")); + return; + } } int n_ptr = v__ast__Type_nr_muls(node.expr_type) - 1; if (n_ptr > 0) { @@ -73263,11 +73467,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_106889 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); - string hash_fn = mr_106889.arg0; - string key_eq_fn = mr_106889.arg1; - string clone_fn = mr_106889.arg2; - string free_fn = mr_106889.arg3; + multi_return_string_string_string_string mr_108466 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); + string hash_fn = mr_108466.arg0; + string key_eq_fn = mr_108466.arg1; + string clone_fn = mr_108466.arg2; + string free_fn = mr_108466.arg3; int size = node.vals.len; string shared_styp = _SLIT(""); string styp = _SLIT(""); @@ -74539,9 +74743,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_146906 = v__gen__c__Gen_optional_type_name(g, field.typ); - string styp = mr_146906.arg0; - string base = mr_146906.arg1; + multi_return_string_string mr_148483 = v__gen__c__Gen_optional_type_name(g, field.typ); + string styp = mr_148483.arg0; + string base = mr_148483.arg1; sync__RwMutex_lock(&g->done_optionals->mtx); /*lock*/ { if (!Array_string_contains(g->done_optionals->val, base)) { @@ -74836,11 +75040,11 @@ bool v__gen__c__Gen_or_block_defer_0 = false; 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["), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._typ]._method_msg("), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._object)"), 0, { .d_c = 0 }}})); if (g->pref->is_debug) { - multi_return_int_string_string_string mr_156689 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); - int paline = mr_156689.arg0; - string pafile = mr_156689.arg1; - string pamod = mr_156689.arg2; - string pafn = mr_156689.arg3; + multi_return_int_string_string_string mr_158266 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); + int paline = mr_158266.arg0; + string pafile = mr_158266.arg1; + string pamod = mr_158266.arg2; + string pafn = mr_158266.arg3; v__gen__c__Gen_writeln(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("panic_debug("), /*100 &int*/0xfe07, {.d_i32 = paline}}, {_SLIT(", tos3(\""), /*115 &string*/0xfe10, {.d_s = pafile}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pamod}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pafn}}, {_SLIT("\"), "), /*115 &string*/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( "), /*115 &string*/0xfe10, {.d_s = err_msg}}, {_SLIT(" );"), 0, { .d_c = 0 }}}))); @@ -74863,11 +75067,11 @@ bool v__gen__c__Gen_or_block_defer_0 = false; 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["), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._typ]._method_msg("), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._object)"), 0, { .d_c = 0 }}})); if (g->pref->is_debug) { - multi_return_int_string_string_string mr_157956 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); - int paline = mr_157956.arg0; - string pafile = mr_157956.arg1; - string pamod = mr_157956.arg2; - string pafn = mr_157956.arg3; + multi_return_int_string_string_string mr_159533 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); + int paline = mr_159533.arg0; + string pafile = mr_159533.arg1; + string pamod = mr_159533.arg2; + string pafn = mr_159533.arg3; v__gen__c__Gen_writeln(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("panic_debug("), /*100 &int*/0xfe07, {.d_i32 = paline}}, {_SLIT(", tos3(\""), /*115 &string*/0xfe10, {.d_s = pafile}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pamod}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pafn}}, {_SLIT("\"), "), /*115 &string*/0xfe10, {.d_s = err_msg}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); } else { v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\tpanic_result_not_set("), /*115 &string*/0xfe10, {.d_s = err_msg}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); @@ -74977,11 +75181,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_160566 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); - string hash_fn = mr_160566.arg0; - string key_eq_fn = mr_160566.arg1; - string clone_fn = mr_160566.arg2; - string free_fn = mr_160566.arg3; + multi_return_string_string_string_string mr_162143 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); + string hash_fn = mr_162143.arg0; + string key_eq_fn = mr_162143.arg1; + string clone_fn = mr_162143.arg2; + string free_fn = mr_162143.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(""))); @@ -75512,8 +75716,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)).name,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).pos,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).type_pos,.typ = v__ast__Type_set_nr_muls(st, 1),(*(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)).is_hidden,}) }); - multi_return_Array_string_Array_string_Array_bool mr_175048 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); - Array_string fargs = mr_175048.arg0; + multi_return_Array_string_Array_string_Array_bool mr_176625 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); + Array_string fargs = mr_176625.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__")); @@ -75530,8 +75734,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){.params = __new_array(0, 0, sizeof(v__ast__Param)),.generic_names = __new_array(0, 0, sizeof(string)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.mod = (string){.str=(byteptr)"", .is_lit=1},.file = (string){.str=(byteptr)"", .is_lit=1},.name = (string){.str=(byteptr)"", .is_lit=1},.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,.usages = 0,.ctdefine_idx = 0,.source_fn = 0,.language = 0,.file_mode = 0,.is_variadic = 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,.is_conditional = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__Fn_Array_v__ast__Type mr_175512 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); - Array_v__ast__Type embed_types = mr_175512.arg1; + multi_return_v__ast__Fn_Array_v__ast__Type mr_177089 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); + Array_v__ast__Type embed_types = mr_177089.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, /*115 &string*/0xfe10, {.d_s = embed_sym->cname}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = method.name}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -78845,19 +79049,37 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_call_args(v__gen__c__Gen* g, v__ast__CallExp v__ast__TypeSymbol* arr_sym = v__ast__Table_sym(g->table, varg_type); v__ast__Array arr_info = /* as */ *(v__ast__Array*)__as_cast((arr_sym->info)._v__ast__Array,(arr_sym->info)._typ, 413) /*expected idx: 413, name: v.ast.Array */ ; if (v__ast__Type_has_flag(varg_type, v__ast__TypeFlag__generic)) { - _option_v__ast__Fn _t10; - if (_t10 = v__ast__Table_find_fn(g->table, node.name), _t10.state == 0) { - v__ast__Fn fn_def = *(v__ast__Fn*)_t10.data; - v__ast__Table* muttable = ((v__ast__Table*)(g->table)); - _option_v__ast__Type _t11; - if (_t11 = v__ast__Table_resolve_generic_to_concrete(muttable, arr_info.elem_type, fn_def.generic_names, node.concrete_types), _t11.state == 0) { - v__ast__Type utyp = *(v__ast__Type*)_t11.data; - arr_info.elem_type = utyp; + if (node.is_method) { + v__ast__TypeSymbol* left_sym = v__ast__Table_sym(g->table, node.left_type); + _option_v__ast__Fn _t10; + if (_t10 = v__ast__TypeSymbol_find_method_with_generic_parent(left_sym, node.name), _t10.state == 0) { + v__ast__Fn fn_def = *(v__ast__Fn*)_t10.data; + v__ast__Table* muttable = ((v__ast__Table*)(g->table)); + _option_v__ast__Type _t11; + if (_t11 = v__ast__Table_resolve_generic_to_concrete(muttable, arr_info.elem_type, fn_def.generic_names, node.concrete_types), _t11.state == 0) { + v__ast__Type utyp = *(v__ast__Type*)_t11.data; + arr_info.elem_type = utyp; + } + } else { + IError err = _t10.err; + v__gen__c__Gen_error(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("unable to find method "), /*115 &string*/0xfe10, {.d_s = node.name}}, {_SLIT0, 0, { .d_c = 0 }}})), node.pos); + VUNREACHABLE(); } } else { - IError err = _t10.err; - v__gen__c__Gen_error(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("unable to find function "), /*115 &string*/0xfe10, {.d_s = node.name}}, {_SLIT0, 0, { .d_c = 0 }}})), node.pos); - VUNREACHABLE(); + _option_v__ast__Fn _t12; + if (_t12 = v__ast__Table_find_fn(g->table, node.name), _t12.state == 0) { + v__ast__Fn fn_def = *(v__ast__Fn*)_t12.data; + v__ast__Table* muttable = ((v__ast__Table*)(g->table)); + _option_v__ast__Type _t13; + if (_t13 = v__ast__Table_resolve_generic_to_concrete(muttable, arr_info.elem_type, fn_def.generic_names, node.concrete_types), _t13.state == 0) { + v__ast__Type utyp = *(v__ast__Type*)_t13.data; + arr_info.elem_type = utyp; + } + } else { + IError err = _t12.err; + v__gen__c__Gen_error(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("unable to find function "), /*115 &string*/0xfe10, {.d_s = node.name}}, {_SLIT0, 0, { .d_c = 0 }}})), node.pos); + VUNREACHABLE(); + } } } string elem_type = v__gen__c__Gen_typ(g, arr_info.elem_type); @@ -79783,7 +80005,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_if_expr(v__gen__c__Gen* g, v__ast__IfExpr no v__gen__c__Gen_write(g, _SLIT(" ? ")); } v__ast__Type prev_expected_cast_type = g->expected_cast_type; - if (node.is_expr && v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type) { + if (node.is_expr && (v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type || v__ast__Type_has_flag(node.typ, v__ast__TypeFlag__shared_f))) { g->expected_cast_type = node.typ; } v__gen__c__Gen_stmts(g, branch.stmts); @@ -79907,7 +80129,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_if_expr(v__gen__c__Gen* g, v__ast__IfExpr no } if (needs_tmp_var) { v__ast__Type prev_expected_cast_type = g->expected_cast_type; - if (node.is_expr && v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type) { + if (node.is_expr && (v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type || v__ast__Type_has_flag(node.typ, v__ast__TypeFlag__shared_f))) { g->expected_cast_type = node.typ; } v__gen__c__Gen_stmts_with_tmp_var(g, branch.stmts, tmp); @@ -80094,8 +80316,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_index_of_array(v__gen__c__Gen* g, v__ast__In if (elem_sym->kind == v__ast__Kind__function) { elem_type_str = _SLIT("voidptr"); } - bool is_selector = (node.left)._typ == 288 /* v.ast.SelectorExpr */; - if (g->is_assign_lhs && !is_selector && node.is_setter) { + if (g->is_assign_lhs && node.is_setter) { bool is_direct_array_access = (g->fn_decl != 0 && g->fn_decl->is_direct_arr) || node.is_direct; bool is_op_assign = g->assign_op != v__token__Kind__assign && !v__ast__Type_alias_eq(info.elem_type, _const_v__ast__string_type); if (is_direct_array_access) { @@ -80716,21 +80937,25 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_infix_expr_eq_op(v__gen__c__Gen* g, v__ast__ } case v__ast__Kind__struct_: { - string ptr_typ = v__gen__c__Gen_equality_fn(g, left.unaliased); - if (node.op == v__token__Kind__ne) { - v__gen__c__Gen_write(g, _SLIT("!")); + if (g->pref->translated) { + v__gen__c__Gen_gen_plain_infix_expr(g, node); + } else { + string ptr_typ = v__gen__c__Gen_equality_fn(g, left.unaliased); + if (node.op == v__token__Kind__ne) { + v__gen__c__Gen_write(g, _SLIT("!")); + } + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = ptr_typ}}, {_SLIT("_struct_eq("), 0, { .d_c = 0 }}}))); + if (v__ast__Type_is_ptr(left.typ)) { + v__gen__c__Gen_write(g, _SLIT("*")); + } + v__gen__c__Gen_expr(g, node.left); + v__gen__c__Gen_write(g, _SLIT(", ")); + if (v__ast__Type_is_ptr(right.typ)) { + v__gen__c__Gen_write(g, _SLIT("*")); + } + v__gen__c__Gen_expr(g, node.right); + v__gen__c__Gen_write(g, _SLIT(")")); } - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = ptr_typ}}, {_SLIT("_struct_eq("), 0, { .d_c = 0 }}}))); - if (v__ast__Type_is_ptr(left.typ)) { - v__gen__c__Gen_write(g, _SLIT("*")); - } - v__gen__c__Gen_expr(g, node.left); - v__gen__c__Gen_write(g, _SLIT(", ")); - if (v__ast__Type_is_ptr(right.typ)) { - v__gen__c__Gen_write(g, _SLIT("*")); - } - v__gen__c__Gen_expr(g, node.right); - v__gen__c__Gen_write(g, _SLIT(")")); break; } case v__ast__Kind__sum_type: @@ -83265,6 +83490,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_sql_select(v__gen__c__Gen* g, v__ast__SqlExp .next_token = 0, .gkind_field = 0, .is_mut = false, + .has_hidden_receiver = 0, })))); v__ast__SqlExpr arr = ((v__ast__SqlExpr){ .typ = field.typ, @@ -83714,7 +83940,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_string_inter_literal(v__gen__c__Gen* g, v__a v__ast__Expr* expr = ((v__ast__Expr*)node_.exprs.data) + i; if ((expr)->_typ == 268 /* v.ast.Ident */) { if (((*expr->_v__ast__Ident).obj)._typ == 326 /* v.ast.Var */) { - (*(v__ast__Type*)/*ee elem_sym */array_get(node_.expr_types, i)) = (*(*expr->_v__ast__Ident).obj._v__ast__Var).typ; + array_set(&node_.expr_types, i, &(v__ast__Type[]) { (*(*expr->_v__ast__Ident).obj._v__ast__Var).typ }); } } } @@ -83957,6 +84183,8 @@ bool v__gen__c__Gen_struct_init_defer_0 = false; } } if (!cloned) { + int inside_cast_in_heap = g->inside_cast_in_heap; + g->inside_cast_in_heap = 0; if (field_type_sym->kind == v__ast__Kind__array_fixed && (sfield.expr)._typ == 268 /* v.ast.Ident */) { v__ast__ArrayFixed fixed_array_info = /* as */ *(v__ast__ArrayFixed*)__as_cast((field_type_sym->info)._v__ast__ArrayFixed,(field_type_sym->info)._typ, 441) /*expected idx: 441, name: v.ast.ArrayFixed */ ; v__gen__c__Gen_write(g, _SLIT("{")); @@ -83974,6 +84202,7 @@ bool v__gen__c__Gen_struct_init_defer_0 = false; } v__gen__c__Gen_expr_with_cast(g, sfield.expr, sfield.typ, sfield.expected_type); } + g->inside_cast_in_heap = inside_cast_in_heap; } if (is_multiline) { v__gen__c__Gen_writeln(g, _SLIT(",")); @@ -84010,8 +84239,8 @@ bool v__gen__c__Gen_struct_init_defer_0 = false; *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t15.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.default_val = (string){.str=(byteptr)"", .is_lit=1},.default_expr = {0},.name = (string){.str=(byteptr)"", .is_lit=1},.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,},.i = 0,.default_expr_typ = 0,.typ = 0,.has_default_expr = 0,.is_pub = 0,.is_mut = 0,.is_global = 0,.is_volatile = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_6986 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); - Array_v__ast__Type embeds = mr_6986.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_6823 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); + Array_v__ast__Type embeds = mr_6823.arg1; for (int _t16 = 0; _t16 < embeds.len; ++_t16) { v__ast__Type embed = ((v__ast__Type*)embeds.data)[_t16]; v__ast__TypeSymbol* esym = v__ast__Table_sym(g->table, embed); @@ -89386,6 +89615,7 @@ VV_LOCAL_SYMBOL v__ast__Expr v__parser__Parser_lockable(v__parser__Parser* p) { .next_token = (i < names.len - 1 ? (v__token__Kind__dot) : (p->tok.kind)), .gkind_field = 0, .is_mut = true, + .has_hidden_receiver = 0, })))); } v__ast__Expr _t3 = expr; @@ -92768,7 +92998,7 @@ v__ast__Expr v__parser__Parser_name_expr(v__parser__Parser* p) { string field = v__parser__Parser_check_name(p); v__ast__GenericKindField fkind = ((string__eq(field, _SLIT("name")))? (v__ast__GenericKindField__name) : (string__eq(field, _SLIT("typ")))? (v__ast__GenericKindField__typ) : (v__ast__GenericKindField__unknown)); v__token__Pos_extend(pos, v__token__Token_pos(&p->tok)); - v__ast__Expr _t21 = v__ast__SelectorExpr_to_sumtype_v__ast__Expr(ADDR(v__ast__SelectorExpr, (((v__ast__SelectorExpr){.from_embed_types = __new_array(0, 0, sizeof(v__ast__Type)),.field_name = field,.expr = v__ast__Ident_to_sumtype_v__ast__Expr(ADDR(v__ast__Ident, (((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = name,.info = {0},.scope = p->scope,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,})))),.scope = p->scope,.pos = pos,.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.expr_type = 0,.typ = 0,.name_type = 0,.next_token = 0,.gkind_field = fkind,.is_mut = 0,})))); + v__ast__Expr _t21 = v__ast__SelectorExpr_to_sumtype_v__ast__Expr(ADDR(v__ast__SelectorExpr, (((v__ast__SelectorExpr){.from_embed_types = __new_array(0, 0, sizeof(v__ast__Type)),.field_name = field,.expr = v__ast__Ident_to_sumtype_v__ast__Expr(ADDR(v__ast__Ident, (((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = name,.info = {0},.scope = p->scope,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,})))),.scope = p->scope,.pos = pos,.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.expr_type = 0,.typ = 0,.name_type = 0,.next_token = 0,.gkind_field = fkind,.is_mut = 0,.has_hidden_receiver = 0,})))); return _t21; } if (v__parser__Parser_peek_token(p, 2).kind == v__token__Kind__name && v__parser__Parser_peek_token(p, 3).kind == v__token__Kind__lpar && !known_var) { @@ -93097,6 +93327,7 @@ VV_LOCAL_SYMBOL v__ast__Expr v__parser__Parser_dot_expr(v__parser__Parser* p, v_ .next_token = p->tok.kind, .gkind_field = 0, .is_mut = is_mut, + .has_hidden_receiver = 0, }); if (is_filter) { v__parser__Parser_close_scope(p); @@ -95581,11 +95812,7 @@ string v__parser__Parser_compile_template_file(v__parser__Parser* p, string temp } } else if (state == (v__parser__State__js)) { - if (string_contains(line, _SLIT("//V_TEMPLATE"))) { - strings__Builder_writeln(&source, v__parser__insert_template_code(fn_name, tmpl_str_start, line)); - } else { - strings__Builder_writeln(&source, string_replace(string_replace(string_replace(string_replace(line, _SLIT("$"), _SLIT("\\$")), _SLIT("$$"), _SLIT("@")), _SLIT(".$"), _SLIT(".@")), _SLIT("'"), _SLIT("\\'"))); - } + strings__Builder_writeln(&source, v__parser__insert_template_code(fn_name, tmpl_str_start, line)); continue; } else if (state == (v__parser__State__css)) { diff --git a/v_win.c b/v_win.c index 04690c5..452e5e1 100644 --- a/v_win.c +++ b/v_win.c @@ -1,11 +1,11 @@ -#define V_COMMIT_HASH "b10cf3e0f" +#define V_COMMIT_HASH "12ec3b9d5" #ifndef V_COMMIT_HASH - #define V_COMMIT_HASH "0bd8d872d" + #define V_COMMIT_HASH "b10cf3e0f" #endif #ifndef V_CURRENT_COMMIT_HASH - #define V_CURRENT_COMMIT_HASH "b10cf3e" + #define V_CURRENT_COMMIT_HASH "12ec3b9" #endif // V comptime_definitions: @@ -4845,6 +4845,7 @@ struct v__ast__SelectorExpr { v__token__Kind next_token; v__ast__GenericKindField gkind_field; bool is_mut; + bool has_hidden_receiver; }; @@ -7497,6 +7498,7 @@ Array_string string_fields(string s); string string_strip_margin(string s); string string_strip_margin_custom(string s, u8 del); bool string_match_glob(string name, string pattern); +bool string_is_ascii(string s); Array_u8 byteptr_vbytes(byteptr data, int len); string byteptr_vstring(byteptr bp); string byteptr_vstring_with_len(byteptr bp, int len); @@ -7962,6 +7964,17 @@ VV_LOCAL_SYMBOL IError os__error_file_not_opened(void); VV_LOCAL_SYMBOL IError os__error_size_of_type_0(void); _option_void os__File_seek(os__File* f, i64 pos, os__SeekMode mode); _option_i64 os__File_tell(os__File* f); +rune _const_os__fslash = '/'; // precomputed +#define _const_os__bslash '\\' +rune _const_os__dot = '.'; // precomputed +bool os__is_abs_path(string path); +VV_LOCAL_SYMBOL int os__win_volume_len(string path); +VV_LOCAL_SYMBOL bool os__is_slash(u8 b); +VV_LOCAL_SYMBOL bool os__is_device_path(string path); +VV_LOCAL_SYMBOL bool os__has_drive_letter(string path); +VV_LOCAL_SYMBOL bool os__starts_w_slash_slash(string path); +VV_LOCAL_SYMBOL bool os__is_drive_rooted(string path); +VV_LOCAL_SYMBOL bool os__is_normal_path(string path); u32 os__FilePermission_bitmask(os__FilePermission p); u32 os__FileMode_bitmask(os__FileMode m); os__FileMode os__inode(string path); @@ -8049,7 +8062,6 @@ VV_LOCAL_SYMBOL IError os__error_failed_to_find_executable(void); _option_string os__find_abs_path_of_executable(string exepath); bool os__exists_in_system_path(string prog); bool os__is_file(string path); -bool os__is_abs_path(string path); string os__join_path(string base, Array_string dirs); string os__join_path_single(string base, string elem); Array_string os__walk_ext(string path, string ext); @@ -8587,6 +8599,7 @@ i64 _const_time__absolute_zero_year; // inited later #define _const_time__days_per_400_years 146097 #define _const_time__days_per_100_years 36524 #define _const_time__days_per_4_years 1461 +#define _const_time__days_in_year 365 Array_int _const_time__days_before; // inited later string time__Time_smonth(time__Time* t); i64 time__Time_unix_time(time__Time* t); @@ -21817,6 +21830,20 @@ bool string_match_glob(string name, string pattern) { return true; } +bool string_is_ascii(string s) { + bool _t2 = false; + Array_u8 _t2_orig = string_bytes(s); + int _t2_len = _t2_orig.len; + for (int _t3 = 0; _t3 < _t2_len; ++_t3) { + u8 it = ((u8*) _t2_orig.data)[_t3]; + if (it < ((u8)(' ')) || it > ((u8)('~'))) { + _t2 = true; + break; + } + } + return !_t2; +} + // Attr: [unsafe] Array_u8 byteptr_vbytes(byteptr data, int len) { return voidptr_vbytes(((voidptr)(data)), len); @@ -25568,16 +25595,16 @@ VV_LOCAL_SYMBOL _option_semver__Version semver__parse_xrange(string input) { } if (typ == (_const_semver__ver_major)) { - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_major)) = _SLIT("0"); - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_minor)) = _SLIT("0"); - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_patch)) = _SLIT("0"); + array_set(&raw_ver.raw_ints, _const_semver__ver_major, &(string[]) { _SLIT("0") }); + array_set(&raw_ver.raw_ints, _const_semver__ver_minor, &(string[]) { _SLIT("0") }); + array_set(&raw_ver.raw_ints, _const_semver__ver_patch, &(string[]) { _SLIT("0") }); } else if (typ == (_const_semver__ver_minor)) { - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_minor)) = _SLIT("0"); - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_patch)) = _SLIT("0"); + array_set(&raw_ver.raw_ints, _const_semver__ver_minor, &(string[]) { _SLIT("0") }); + array_set(&raw_ver.raw_ints, _const_semver__ver_patch, &(string[]) { _SLIT("0") }); } else if (typ == (_const_semver__ver_patch)) { - (*(string*)/*ee elem_sym */array_get(raw_ver.raw_ints, _const_semver__ver_patch)) = _SLIT("0"); + array_set(&raw_ver.raw_ints, _const_semver__ver_patch, &(string[]) { _SLIT("0") }); } else { }; @@ -26680,6 +26707,86 @@ _option_i64 os__File_tell(os__File* f) { return _t3; } +bool os__is_abs_path(string path) { + if (path.len == 0) { + bool _t1 = false; + return _t1; + } + bool _t2 = os__is_device_path(path) || os__is_drive_rooted(path) || os__is_normal_path(path); + return _t2; + bool _t3 = string_at(path, 0) == _const_os__fslash; + return _t3; +} + +VV_LOCAL_SYMBOL int os__win_volume_len(string path) { + int plen = path.len; + if (plen < 2) { + int _t1 = 0; + return _t1; + } + if (os__has_drive_letter(path)) { + int _t2 = 2; + return _t2; + } + if (path.len >= 5 && os__starts_w_slash_slash(path) && !os__is_slash(string_at(path, 2))) { + for (int i = 3; i < plen; i++) { + if (os__is_slash(string_at(path, i))) { + if (i + 1 >= plen || os__is_slash(string_at(path, i + 1))) { + break; + } + i++; + for (; i < plen; i++) { + if (os__is_slash(string_at(path, i))) { + int _t3 = i; + return _t3; + } + } + int _t4 = i; + return _t4; + } + } + } + int _t5 = 0; + return _t5; +} + +VV_LOCAL_SYMBOL bool os__is_slash(u8 b) { + bool _t1 = b == _const_os__bslash || b == _const_os__fslash; + return _t1; + bool _t2 = b == _const_os__fslash; + return _t2; +} + +VV_LOCAL_SYMBOL bool os__is_device_path(string path) { + bool _t1 = os__win_volume_len(path) >= 5 && os__starts_w_slash_slash(path); + return _t1; +} + +VV_LOCAL_SYMBOL bool os__has_drive_letter(string path) { + bool _t1 = path.len >= 2 && u8_is_letter(string_at(path, 0)) && string_at(path, 1) == ':'; + return _t1; +} + +VV_LOCAL_SYMBOL bool os__starts_w_slash_slash(string path) { + bool _t1 = path.len >= 2 && os__is_slash(string_at(path, 0)) && os__is_slash(string_at(path, 1)); + return _t1; +} + +VV_LOCAL_SYMBOL bool os__is_drive_rooted(string path) { + bool _t1 = path.len >= 3 && os__has_drive_letter(path) && os__is_slash(string_at(path, 2)); + return _t1; +} + +VV_LOCAL_SYMBOL bool os__is_normal_path(string path) { + int plen = path.len; + if (plen == 0) { + bool _t1 = false; + return _t1; + } + bool _t2 = (plen == 1 && os__is_slash(string_at(path, 0))) || (plen >= 2 && os__is_slash(string_at(path, 0)) && !os__is_slash(string_at(path, 1))); + return _t2; +} + u32 os__FilePermission_bitmask(os__FilePermission p) { u32 mask = ((u32)(0U)); if (p.read) { @@ -28351,17 +28458,6 @@ bool os__is_file(string path) { return _t1; } -bool os__is_abs_path(string path) { - if (path.len == 0) { - bool _t1 = false; - return _t1; - } - bool _t2 = string_at(path, 0) == '/' || (u8_is_letter(string_at(path, 0)) && path.len > 1 && string_at(path, 1) == ':'); - return _t2; - bool _t3 = string_at(path, 0) == '/'; - return _t3; -} - // Attr: [manualfree] string os__join_path(string base, Array_string dirs) { bool os__join_path_defer_0 = false; @@ -29974,11 +30070,11 @@ f64 math__cbrt(f64 a) { x = -x; sign = true; } - f64 t = math__f64_from_bits(math__f64_bits(x) / ((u64)(3 + (((u64)(b1)) << 32U)))); + f64 t = math__f64_from_bits(math__f64_bits(x) / ((u64)(3U)) + (((u64)(b1)) << 32U)); if (x < smallest_normal) { t = ((f64)(((u64)(1U)) << 54U)); t *= x; - t = math__f64_from_bits(math__f64_bits(t) / ((u64)(3 + (((u64)(b2)) << 32U)))); + t = math__f64_from_bits(math__f64_bits(t) / ((u64)(3U)) + (((u64)(b2)) << 32U)); } f64 r = t * t / x; f64 s = c + r * t; @@ -33846,7 +33942,7 @@ string time__Time_relative(time__Time* t) { string _t7 = str_intp(4, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT0, /*100 &i64*/0xfe09, {.d_i64 = d}}, {_SLIT(" days"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t7; } - if (secs < _const_time__seconds_per_hour * 24 * 365) { + if (secs < _const_time__seconds_per_hour * 24 * _const_time__days_in_year) { if (string__eq(prefix, _SLIT("in "))) { string _t8 = str_intp(2, _MOV((StrIntpData[]){{_SLIT("on "), /*115 &string*/0xfe10, {.d_s = time__Time_md(/*rec*/*t)}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t8; @@ -33854,7 +33950,7 @@ string time__Time_relative(time__Time* t) { string _t9 = str_intp(2, _MOV((StrIntpData[]){{_SLIT("last "), /*115 &string*/0xfe10, {.d_s = time__Time_md(/*rec*/*t)}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t9; } - i64 y = secs / _const_time__seconds_per_hour / 24 / 365; + i64 y = secs / _const_time__seconds_per_hour / 24 / _const_time__days_in_year; if (y == 1) { string _t10 = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT("1 year"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t10; @@ -33896,7 +33992,7 @@ string time__Time_relative_short(time__Time* t) { string _t5 = str_intp(4, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT0, /*100 &i64*/0xfe09, {.d_i64 = h}}, {_SLIT("h"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t5; } - if (secs < _const_time__seconds_per_hour * 24 * 365) { + if (secs < _const_time__seconds_per_hour * 24 * _const_time__days_in_year) { i64 d = secs / _const_time__seconds_per_hour / 24; if (d == 1) { string _t6 = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT("1d"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -33905,7 +34001,7 @@ string time__Time_relative_short(time__Time* t) { string _t7 = str_intp(4, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT0, /*100 &i64*/0xfe09, {.d_i64 = d}}, {_SLIT("d"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t7; } - i64 y = secs / _const_time__seconds_per_hour / 24 / 365; + i64 y = secs / _const_time__seconds_per_hour / 24 / _const_time__days_in_year; if (y == 1) { string _t8 = str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = prefix}}, {_SLIT("1y"), /*115 &string*/0xfe10, {.d_s = suffix}}, {_SLIT0, 0, { .d_c = 0 }}})); return _t8; @@ -34281,60 +34377,29 @@ time__Time time__unix2(i64 abs, int microsecond) { VV_LOCAL_SYMBOL multi_return_int_int_int time__calculate_date_from_offset(i64 day_offset_) { i64 day_offset = day_offset_; - int year = 2001; - day_offset -= 11323; - year += ((int)(day_offset / _const_time__days_per_400_years)) * 400; - day_offset %= _const_time__days_per_400_years; - if (day_offset == _const_time__days_per_100_years * 4) { - year += 300; - day_offset -= _const_time__days_per_100_years * 3; + day_offset += 719468; + int era = 0; + if (day_offset >= 0) { + era = ((int)(day_offset / _const_time__days_per_400_years)); } else { - year += ((int)(day_offset / _const_time__days_per_100_years)) * 100; - day_offset %= _const_time__days_per_100_years; + era = ((int)((day_offset - _const_time__days_per_400_years - 1) / _const_time__days_per_400_years)); } - if (day_offset == _const_time__days_per_4_years * 25) { - year += 96; - day_offset -= _const_time__days_per_4_years * 24; + i64 doe = day_offset - era * _const_time__days_per_400_years; + i64 yoe = (doe - doe / (_const_time__days_per_4_years - 1) + doe / _const_time__days_per_100_years - doe / (_const_time__days_per_400_years - 1)) / _const_time__days_in_year; + int y = ((int)(yoe + era * 400)); + i64 doy = doe - (_const_time__days_in_year * yoe + yoe / 4 - yoe / 100); + i64 mp = (5 * doy + 2) / 153; + int d = ((int)(doy - (153 * mp + 2) / 5 + 1)); + int m = ((int)(mp)); + if (mp < 10) { + m += 3; } else { - year += ((int)(day_offset / _const_time__days_per_4_years)) * 4; - day_offset %= _const_time__days_per_4_years; + m -= 9; } - if (day_offset == 1460) { - year += 3; - day_offset -= 1095; - } else { - year += ((int)(day_offset / 365)); - day_offset %= 365; + if (m <= 2) { + y += 1; } - if (day_offset < 0) { - year--; - if (time__is_leap_year(year)) { - day_offset += 366; - } else { - day_offset += 365; - } - } - if (time__is_leap_year(year)) { - if (day_offset > 59) { - day_offset--; - } else if (day_offset == 59) { - return (multi_return_int_int_int){.arg0=year, .arg1=2, .arg2=29}; - } - } - i64 estimated_month = day_offset / 31; - for (;;) { - if (!(day_offset >= (*(int*)/*ee elem_sym */array_get(_const_time__days_before, estimated_month + 1)))) break; - estimated_month++; - } - for (;;) { - if (!(day_offset < (*(int*)/*ee elem_sym */array_get(_const_time__days_before, estimated_month)))) break; - if (estimated_month == 0) { - break; - } - estimated_month--; - } - day_offset -= (*(int*)/*ee elem_sym */array_get(_const_time__days_before, estimated_month)); - return (multi_return_int_int_int){.arg0=year, .arg1=((int)(estimated_month + 1)), .arg2=((int)(day_offset + 1))}; + return (multi_return_int_int_int){.arg0=y, .arg1=m, .arg2=d}; } VV_LOCAL_SYMBOL multi_return_int_int_int time__calculate_time_from_offset(i64 second_offset_) { @@ -36460,7 +36525,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("0bd8d872d"); + string vhash = _SLIT("b10cf3e0f"); 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, /*115 &v.pref.Backend*/0xfe10, {.d_s = v__pref__Backend_str(p->backend)}}, {_SLIT(" | "), /*115 &v.pref.OS*/0xfe10, {.d_s = v__pref__OS_str(p->os)}}, {_SLIT(" | "), /*115 &string*/0xfe10, {.d_s = p->ccompiler}}, {_SLIT(" | "), /*115 &bool*/0xfe10, {.d_s = p->is_prod ? _SLIT("true") : _SLIT("false")}}, {_SLIT(" | "), /*115 &bool*/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; @@ -40346,7 +40411,7 @@ VV_LOCAL_SYMBOL void sync__pool__process_in_thread(sync__pool__PoolProcessor* po if (idx >= ilen) { break; } - (*(voidptr*)/*ee elem_sym */array_get(pool->results, idx)) = cb(pool, idx, task_id); + array_set(&pool->results, idx, &(voidptr[]) { cb(pool, idx, task_id) }); } sync__WaitGroup_done(&pool->waitgroup); } @@ -40375,7 +40440,7 @@ voidptr sync__pool__PoolProcessor_get_shared_context(sync__pool__PoolProcessor* } void sync__pool__PoolProcessor_set_thread_context(sync__pool__PoolProcessor* pool, int idx, voidptr context) { - (*(voidptr*)/*ee elem_sym */array_get(pool->thread_contexts, idx)) = context; + array_set(&pool->thread_contexts, idx, &(voidptr[]) { context }); } voidptr sync__pool__PoolProcessor_get_thread_context(sync__pool__PoolProcessor* pool, int idx) { @@ -44398,7 +44463,7 @@ inline v__ast__Type v__ast__Table_unaliased_type(v__ast__Table* t, v__ast__Type VV_LOCAL_SYMBOL int v__ast__Table_rewrite_already_registered_symbol(v__ast__Table* t, v__ast__TypeSymbol typ, int existing_idx) { v__ast__TypeSymbol* existing_symbol = (*(v__ast__TypeSymbol**)/*ee elem_sym */array_get(t->type_symbols, existing_idx)); if (existing_symbol->kind == v__ast__Kind__placeholder) { - (*(v__ast__TypeSymbol**)/*ee elem_sym */array_get(t->type_symbols, existing_idx)) = ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){.methods = existing_symbol->methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))); + array_set(&t->type_symbols, existing_idx, &(v__ast__TypeSymbol*[]) { ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){.methods = existing_symbol->methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))) }); int _t1 = existing_idx; return _t1; } @@ -44408,7 +44473,7 @@ VV_LOCAL_SYMBOL int v__ast__Table_rewrite_already_registered_symbol(v__ast__Tabl *existing_symbol = *((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){typ.methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,.kind = existing_symbol->kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))); } } else { - (*(v__ast__TypeSymbol**)/*ee elem_sym */array_get(t->type_symbols, existing_idx)) = ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){typ.methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))); + array_set(&t->type_symbols, existing_idx, &(v__ast__TypeSymbol*[]) { ((v__ast__TypeSymbol*)memdup(&(v__ast__TypeSymbol){typ.methods,typ.info,typ.name,typ.cname,typ.mod,typ.parent_idx,.idx = existing_idx,typ.size,typ.align,typ.kind,typ.language,typ.is_pub,}, sizeof(v__ast__TypeSymbol))) }); } int _t2 = existing_idx; return _t2; @@ -47616,7 +47681,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t9; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t9), sizeof(v__ast__Fn)); return _t9; @@ -47653,7 +47717,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t15; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t15), sizeof(v__ast__Fn)); return _t15; @@ -47690,7 +47753,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t21; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t21), sizeof(v__ast__Fn)); return _t21; @@ -47740,7 +47802,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t28; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t28), sizeof(v__ast__Fn)); return _t28; @@ -47777,7 +47838,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t34; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t34), sizeof(v__ast__Fn)); return _t34; @@ -47814,7 +47874,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t40; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t40), sizeof(v__ast__Fn)); return _t40; @@ -47864,7 +47923,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t47; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t47), sizeof(v__ast__Fn)); return _t47; @@ -47901,7 +47959,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t53; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t53), sizeof(v__ast__Fn)); return _t53; @@ -47938,7 +47995,6 @@ _option_v__ast__Fn v__ast__TypeSymbol_find_method_with_generic_parent(v__ast__Ty param->typ = pt; } } - array_clear(&method.generic_names); _option_v__ast__Fn _t59; opt_ok2(&(v__ast__Fn[]) { method }, (_option*)(&_t59), sizeof(v__ast__Fn)); return _t59; @@ -48320,7 +48376,7 @@ bool v__checker__Checker_assign_stmt_defer_0 = false; if (left->_typ == 307 /* v.ast.Ident */) { if ((*left->_v__ast__Ident).kind == v__ast__IdentKind__blank_ident) { left_type = right_type; - (*(v__ast__Type*)/*ee elem_sym */array_get(node->left_types, i)) = right_type; + array_set(&node->left_types, i, &(v__ast__Type[]) { right_type }); if (!(node->op == v__token__Kind__assign || node->op == v__token__Kind__decl_assign)) { v__checker__Checker_error(c, _SLIT("cannot modify blank `_` identifier"), (*left->_v__ast__Ident).pos); } @@ -48348,7 +48404,7 @@ bool v__checker__Checker_assign_stmt_defer_0 = false; if (ident_var_info.share == v__ast__ShareType__atomic_t) { left_type = v__ast__Type_set_flag(left_type, v__ast__TypeFlag__atomic_f); } - (*(v__ast__Type*)/*ee elem_sym */array_get(node->left_types, i)) = left_type; + array_set(&node->left_types, i, &(v__ast__Type[]) { left_type }); ident_var_info.typ = left_type; (*left->_v__ast__Ident).info = v__ast__IdentVar_to_sumtype_v__ast__IdentInfo(&ident_var_info); if (left_type != 0) { @@ -50412,8 +50468,9 @@ v__ast__Type former_expected_type; } } } - } else if (v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional) && v__ast__Type_has_flag(right_type, v__ast__TypeFlag__optional)) { - v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be compared in an infix expression"), left_right_pos); + } else if (v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional) || v__ast__Type_has_flag(right_type, v__ast__TypeFlag__optional)) { + v__token__Pos opt_comp_pos = (v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional) ? (left_pos) : (right_pos)); + v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be compared in an infix expression"), opt_comp_pos); } break; } @@ -50424,8 +50481,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_34962 = v__checker__Checker_fail_if_immutable(c, node->left); - node->auto_locked = mr_34962.arg0; + multi_return_string_v__token__Pos mr_35045 = v__checker__Checker_fail_if_immutable(c, node->left); + node->auto_locked = mr_35045.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_) { @@ -50769,8 +50826,11 @@ v__ast__Type former_expected_type; } bool left_is_optional = v__ast__Type_has_flag(left_type, v__ast__TypeFlag__optional); bool right_is_optional = v__ast__Type_has_flag(right_type, v__ast__TypeFlag__optional); - if ((left_is_optional && !right_is_optional) || (!left_is_optional && right_is_optional)) { - v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be used in an infix expression"), left_right_pos); + if (left_is_optional && right_is_optional) { + v__checker__Checker_error(c, _SLIT("unwrapped optionals cannot be used in an infix expression"), left_right_pos); + } else if (left_is_optional || right_is_optional) { + v__token__Pos opt_infix_pos = (left_is_optional ? (left_pos) : (right_pos)); + v__checker__Checker_error(c, _SLIT("unwrapped optional cannot be used in an infix expression"), opt_infix_pos); } if (!(v__checker__Checker_symmetric_check(c, left_type, right_type) && v__checker__Checker_symmetric_check(c, right_type, left_type)) && !c->pref->translated && !c->file->is_translated && !v__ast__Expr_is_auto_deref_var(node->left) && !v__ast__Expr_is_auto_deref_var(node->right)) { if (v__ast__Type_alias_eq(left_type, _const_v__ast__void_type) || v__ast__Type_alias_eq(right_type, _const_v__ast__void_type)) { @@ -50861,19 +50921,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` "), /*115 &string*/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_45479 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); - to_lock = mr_45479.arg0; - pos = mr_45479.arg1; + multi_return_string_v__token__Pos mr_45723 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__IndexExpr).left); + to_lock = mr_45723.arg0; + pos = mr_45723.arg1; } else if (expr._typ == 322 /* v.ast.ParExpr */) { - multi_return_string_v__token__Pos mr_45548 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); - to_lock = mr_45548.arg0; - pos = mr_45548.arg1; + multi_return_string_v__token__Pos mr_45792 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__ParExpr).expr); + to_lock = mr_45792.arg0; + pos = mr_45792.arg1; } else if (expr._typ == 324 /* v.ast.PrefixExpr */) { - multi_return_string_v__token__Pos mr_45620 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); - to_lock = mr_45620.arg0; - pos = mr_45620.arg1; + multi_return_string_v__token__Pos mr_45864 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__PrefixExpr).right); + to_lock = mr_45864.arg0; + pos = mr_45864.arg1; } else if (expr._typ == 327 /* v.ast.SelectorExpr */) { if ((*expr._v__ast__SelectorExpr).expr_type == 0) { @@ -50923,9 +50983,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 `"), /*115 &string*/0xfe10, {.d_s = (*expr._v__ast__SelectorExpr).field_name}}, {_SLIT("` of struct `"), /*115 &string*/0xfe10, {.d_s = type_str}}, {_SLIT("` is immutable"), 0, { .d_c = 0 }}})), (*expr._v__ast__SelectorExpr).pos); } - multi_return_string_v__token__Pos mr_47084 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); - to_lock = mr_47084.arg0; - pos = mr_47084.arg1; + multi_return_string_v__token__Pos mr_47328 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__SelectorExpr).expr); + to_lock = mr_47328.arg0; + pos = mr_47328.arg1; } if ((to_lock).len != 0) { explicit_lock_needed = true; @@ -51031,9 +51091,9 @@ VV_LOCAL_SYMBOL multi_return_string_v__token__Pos v__checker__Checker_fail_if_im } else if (expr._typ == 293 /* v.ast.CallExpr */) { if (string__eq((*expr._v__ast__CallExpr).name, _SLIT("slice"))) { - multi_return_string_v__token__Pos mr_48907 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); - to_lock = mr_48907.arg0; - pos = mr_48907.arg1; + multi_return_string_v__token__Pos mr_49151 = v__checker__Checker_fail_if_immutable(c, (*expr._v__ast__CallExpr).left); + to_lock = mr_49151.arg0; + pos = mr_49151.arg1; if ((to_lock).len != 0) { explicit_lock_needed = true; } @@ -51446,9 +51506,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){.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.default_val = (string){.str=(byteptr)"", .is_lit=1},.default_expr = {0},.name = (string){.str=(byteptr)"", .is_lit=1},.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,},.i = 0,.default_expr_typ = 0,.typ = 0,.has_default_expr = 0,.is_pub = 0,.is_mut = 0,.is_global = 0,.is_volatile = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_63001 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); - field = mr_63001.arg0; - embed_types = mr_63001.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_63245 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t13.data); + field = mr_63245.arg0; + embed_types = mr_63245.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); @@ -51482,9 +51542,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){.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.default_val = (string){.str=(byteptr)"", .is_lit=1},.default_expr = {0},.name = (string){.str=(byteptr)"", .is_lit=1},.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,},.i = 0,.default_expr_typ = 0,.typ = 0,.has_default_expr = 0,.is_pub = 0,.is_mut = 0,.is_global = 0,.is_volatile = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_63832 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); - field = mr_63832.arg0; - embed_types = mr_63832.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_64076 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); + field = mr_64076.arg0; + embed_types = mr_64076.arg1; node->from_embed_types = embed_types; } } @@ -51523,13 +51583,41 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S v__ast__Type _t21 = field.typ; return _t21; } + _option_v__ast__Fn _t22; + if (_t22 = v__ast__Table_find_method(c->table, sym, field_name), _t22.state == 0) { + v__ast__Fn method = *(v__ast__Fn*)_t22.data; + if (c->expected_type != 0 && !v__ast__Type_alias_eq(c->expected_type, _const_v__ast__none_type)) { + v__ast__Type fn_type = v__ast__new_type(v__ast__Table_find_or_register_fn_type(c->table, c->mod, method, false, true)); + if (v__checker__Checker_check_types(c, fn_type, c->expected_type)) { + v__ast__Type _t23 = fn_type; + return _t23; + } + } + v__ast__Type receiver = (*(v__ast__Param*)/*ee elem_sym */array_get(method.params, 0)).typ; + if (v__ast__Type_nr_muls(receiver) > 0) { + if (!c->inside_unsafe) { + v__ast__TypeSymbol* rec_sym = v__ast__Table_sym(c->table, v__ast__Type_set_nr_muls(receiver, 0)); + if (!v__ast__TypeSymbol_is_heap(rec_sym)) { + string suggestion = (rec_sym->kind == v__ast__Kind__struct_ ? ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("declaring `"), /*115 &string*/0xfe10, {.d_s = rec_sym->name}}, {_SLIT("` as `[heap]`"), 0, { .d_c = 0 }}}))) : ( str_intp(2, _MOV((StrIntpData[]){{_SLIT("wrapping the `"), /*115 &string*/0xfe10, {.d_s = rec_sym->name}}, {_SLIT("` object in a `struct` declared as `[heap]`"), 0, { .d_c = 0 }}})))); + v__checker__Checker_error(c, str_intp(4, _MOV((StrIntpData[]){{_SLIT("method `"), /*115 &string*/0xfe10, {.d_s = v__ast__Table_type_to_str(c->table, v__ast__Type_idx(receiver))}}, {_SLIT("."), /*115 &string*/0xfe10, {.d_s = method.name}}, {_SLIT("` cannot be used as a variable outside `unsafe` blocks as its receiver might refer to an object stored on stack. Consider "), /*115 &string*/0xfe10, {.d_s = suggestion}}, {_SLIT("."), 0, { .d_c = 0 }}})), v__token__Pos_extend(v__ast__Expr_pos(node->expr), node->pos)); + } + } + } + Array_v__ast__Param _t24; + method.params = (_t24 = method.params, array_slice(_t24, 1, _t24.len)); + node->has_hidden_receiver = true; + method.name = _SLIT(""); + v__ast__Type fn_type = v__ast__new_type(v__ast__Table_find_or_register_fn_type(c->table, c->mod, method, false, true)); + v__ast__Type _t25 = fn_type; + return _t25; + } if (!(sym->kind == v__ast__Kind__struct_ || sym->kind == v__ast__Kind__aggregate || sym->kind == v__ast__Kind__interface_ || sym->kind == v__ast__Kind__sum_type)) { if (sym->kind != v__ast__Kind__placeholder) { v__ast__TypeSymbol* unwrapped_sym = v__ast__Table_sym(c->table, v__checker__Checker_unwrap_generic(c, typ)); if (unwrapped_sym->kind == v__ast__Kind__array_fixed && string__eq(node->field_name, _SLIT("len"))) { node->typ = _const_v__ast__int_type; - v__ast__Type _t22 = _const_v__ast__int_type; - return _t22; + v__ast__Type _t26 = _const_v__ast__int_type; + return _t26; } v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("`"), /*115 &string*/0xfe10, {.d_s = unwrapped_sym->name}}, {_SLIT("` has no property `"), /*115 &string*/0xfe10, {.d_s = node->field_name}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); } @@ -51538,20 +51626,20 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S if (!v__token__Pos_struct_eq(c->smartcast_mut_pos, ((v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,}))) { v__checker__Checker_note(c, _SLIT("smartcasting requires either an immutable value, or an explicit mut keyword before the value"), c->smartcast_mut_pos); } - Array_string _t23 = {0}; - Array_v__ast__StructField _t23_orig = (*sym->info._v__ast__Struct).fields; - int _t23_len = _t23_orig.len; - _t23 = __new_array(0, _t23_len, sizeof(string)); + Array_string _t27 = {0}; + Array_v__ast__StructField _t27_orig = (*sym->info._v__ast__Struct).fields; + int _t27_len = _t27_orig.len; + _t27 = __new_array(0, _t27_len, sizeof(string)); - for (int _t24 = 0; _t24 < _t23_len; ++_t24) { - v__ast__StructField it = ((v__ast__StructField*) _t23_orig.data)[_t24]; + for (int _t28 = 0; _t28 < _t27_len; ++_t28) { + v__ast__StructField it = ((v__ast__StructField*) _t27_orig.data)[_t28]; string ti = it.name; - array_push((array*)&_t23, &ti); + array_push((array*)&_t27, &ti); } - v__util__Suggestion suggestion = v__util__new_suggestion(field_name,_t23); + v__util__Suggestion suggestion = v__util__new_suggestion(field_name,_t27); v__checker__Checker_error(c, v__util__Suggestion_say(suggestion, unknown_field_msg), node->pos); - v__ast__Type _t25 = _const_v__ast__void_type; - return _t25; + v__ast__Type _t29 = _const_v__ast__void_type; + return _t29; } if (!v__token__Pos_struct_eq(c->smartcast_mut_pos, ((v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,}))) { v__checker__Checker_note(c, _SLIT("smartcasting requires either an immutable value, or an explicit mut keyword before the value"), c->smartcast_mut_pos); @@ -51561,8 +51649,8 @@ v__ast__Type v__checker__Checker_selector_expr(v__checker__Checker* c, v__ast__S } v__checker__Checker_error(c, unknown_field_msg, node->pos); } - v__ast__Type _t26 = _const_v__ast__void_type; - return _t26; + v__ast__Type _t30 = _const_v__ast__void_type; + return _t30; } void v__checker__Checker_const_decl(v__checker__Checker* c, v__ast__ConstDecl* node) { @@ -51715,7 +51803,7 @@ VV_LOCAL_SYMBOL void v__checker__Checker_stmt(v__checker__Checker* c, v__ast__St v__ast__Ident id = ident; if ((id.info)._typ == 417 /* v.ast.IdentVar */) { if (id.comptime && Array_string_contains(_const_v__checker__valid_comptime_not_user_defined, id.name)) { - (*(v__ast__Ident*)/*ee elem_sym */array_get((*node._v__ast__DeferStmt).defer_vars, i)) = ((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = _SLIT(""),.info = {0},.scope = 0,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,}); + array_set(&(*node._v__ast__DeferStmt).defer_vars, i, &(v__ast__Ident[]) { ((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = _SLIT(""),.info = {0},.scope = 0,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,}) }); continue; } v__ast__Type typ = v__checker__Checker_ident(c, (voidptr)&/*qq*/id); @@ -51723,7 +51811,7 @@ VV_LOCAL_SYMBOL void v__checker__Checker_stmt(v__checker__Checker* c, v__ast__St continue; } (*id.info._v__ast__IdentVar).typ = typ; - (*(v__ast__Ident*)/*ee elem_sym */array_get((*node._v__ast__DeferStmt).defer_vars, i)) = id; + array_set(&(*node._v__ast__DeferStmt).defer_vars, i, &(v__ast__Ident[]) { id }); } } c->inside_defer = true; @@ -53382,15 +53470,38 @@ v__ast__Type v__checker__Checker_ident(v__checker__Checker* c, v__ast__Ident* no if (c->inside_ct_attr) { v__checker__Checker_note(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("`[if "), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("]` is deprecated. Use `[if "), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("?]` instead"), 0, { .d_c = 0 }}})), node->pos); } else { - v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("undefined ident: `"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); + string cname_mod = string_all_before(node->name, _SLIT(".")); + if (cname_mod.len != node->name.len) { + Array_string const_names_in_mod = __new_array_with_default(0, 0, sizeof(string), 0); + Map_string_v__ast__ScopeObject _t21 = c->table->global_scope->objects; + int _t23 = _t21.key_values.len; + for (int _t22 = 0; _t22 < _t23; ++_t22 ) { + int _t24 = _t21.key_values.len - _t23; + _t23 = _t21.key_values.len; + if (_t24 < 0) { + _t22 = -1; + continue; + } + if (!DenseArray_has_index(&_t21.key_values, _t22)) {continue;} + v__ast__ScopeObject so = (*(v__ast__ScopeObject*)DenseArray_value(&_t21.key_values, _t22)); + if ((so)._typ == 363 /* v.ast.ConstField */) { + if (string__eq((*so._v__ast__ConstField).mod, cname_mod)) { + array_push((array*)&const_names_in_mod, _MOV((string[]){ string_clone((*so._v__ast__ConstField).name) })); + } + } + } + v__checker__Checker_error(c, v__util__Suggestion_say(v__util__new_suggestion(node->name, const_names_in_mod), str_intp(2, _MOV((StrIntpData[]){{_SLIT("undefined ident: `"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("`"), 0, { .d_c = 0 }}}))), node->pos); + } else { + v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("undefined ident: `"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("`"), 0, { .d_c = 0 }}})), node->pos); + } } } if (v__ast__Table_known_type(c->table, node->name)) { - v__ast__Type _t21 = _const_v__ast__void_type; - return _t21; + v__ast__Type _t26 = _const_v__ast__void_type; + return _t26; } - v__ast__Type _t22 = _const_v__ast__void_type; - return _t22; + v__ast__Type _t27 = _const_v__ast__void_type; + return _t27; } v__ast__Type v__checker__Checker_concat_expr(v__checker__Checker* c, v__ast__ConcatExpr* node) { @@ -53559,6 +53670,7 @@ v__ast__Type v__checker__Checker_select_expr(v__checker__Checker* c, v__ast__Sel } v__ast__Type v__checker__Checker_lock_expr(v__checker__Checker* c, v__ast__LockExpr* node) { + v__ast__Type expected_type = c->expected_type; if (c->rlocked_names.len > 0 || c->locked_names.len > 0) { v__checker__Checker_error(c, _SLIT("nested `lock`/`rlock` not allowed"), node->pos); } @@ -53581,15 +53693,16 @@ v__ast__Type v__checker__Checker_lock_expr(v__checker__Checker* c, v__ast__LockE } } v__checker__Checker_stmts(c, node->stmts); - c->rlocked_names = __new_array_with_default(0, 0, sizeof(string), 0); - c->locked_names = __new_array_with_default(0, 0, sizeof(string), 0); v__ast__Type ret_type = _const_v__ast__void_type; if (node->stmts.len > 0) { v__ast__Stmt last_stmt = (*(v__ast__Stmt*)array_last(node->stmts)); if ((last_stmt)._typ == 347 /* v.ast.ExprStmt */) { - ret_type = (*last_stmt._v__ast__ExprStmt).typ; + c->expected_type = expected_type; + ret_type = v__checker__Checker_expr(c, (*last_stmt._v__ast__ExprStmt).expr); } } + c->rlocked_names = __new_array_with_default(0, 0, sizeof(string), 0); + c->locked_names = __new_array_with_default(0, 0, sizeof(string), 0); if (!v__ast__Type_alias_eq(ret_type, _const_v__ast__void_type)) { node->is_expr = true; } @@ -53692,8 +53805,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: "), /*115 &string*/0xfe10, {.d_s = v__token__Kind_str(node->op)}}, {_SLIT(" (non-numeric type `"), /*115 &string*/0xfe10, {.d_s = typ_str}}, {_SLIT("`)"), 0, { .d_c = 0 }}})), node->pos); } else { - multi_return_string_v__token__Pos mr_117590 = v__checker__Checker_fail_if_immutable(c, node->expr); - node->auto_locked = mr_117590.arg0; + multi_return_string_v__token__Pos mr_119540 = v__checker__Checker_fail_if_immutable(c, node->expr); + node->auto_locked = mr_119540.arg0; } v__ast__Type _t1 = typ; return _t1; @@ -57405,11 +57518,23 @@ v__ast__Type v__checker__Checker_fn_call(v__checker__Checker* c, v__ast__CallExp if (param.typ == _const_v__ast__voidptr_type_idx || arg_typ == _const_v__ast__voidptr_type_idx) { continue; } + if (v__ast__Type_is_any_kind_of_pointer(param.typ) && v__ast__Type_is_any_kind_of_pointer(arg_typ)) { + continue; + } v__ast__TypeSymbol* param_typ_sym_ = v__ast__Table_sym(c->table, v__ast__Table_unaliased_type(c->table, param.typ)); v__ast__TypeSymbol* arg_typ_sym_ = v__ast__Table_sym(c->table, v__ast__Table_unaliased_type(c->table, arg_typ)); if (((arg_typ_sym_->kind == v__ast__Kind__array_fixed || arg_typ_sym_->kind == v__ast__Kind__array) && (param_is_number || v__ast__Type_is_any_kind_of_pointer(v__ast__Table_unaliased_type(c->table, param.typ)))) || ((param_typ_sym_->kind == v__ast__Kind__array_fixed || param_typ_sym_->kind == v__ast__Kind__array) && (typ_is_number || v__ast__Type_is_any_kind_of_pointer(v__ast__Table_unaliased_type(c->table, arg_typ))))) { continue; } + if (arg_typ_sym_->kind == v__ast__Kind__array && param_typ_sym_->kind == v__ast__Kind__array) { + if (v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__Array*)__as_cast((arg_typ_sym_->info)._v__ast__Array,(arg_typ_sym_->info)._typ, 452) /*expected idx: 452, name: v.ast.Array */ ).elem_type) && v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__Array*)__as_cast((param_typ_sym_->info)._v__ast__Array,(param_typ_sym_->info)._typ, 452) /*expected idx: 452, name: v.ast.Array */ ).elem_type)) { + continue; + } + } else if (arg_typ_sym_->kind == v__ast__Kind__array_fixed && param_typ_sym_->kind == v__ast__Kind__array_fixed) { + if (v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__ArrayFixed*)__as_cast((arg_typ_sym_->info)._v__ast__ArrayFixed,(arg_typ_sym_->info)._typ, 480) /*expected idx: 480, name: v.ast.ArrayFixed */ ).elem_type) && v__ast__Type_is_any_kind_of_pointer((/* as */ *(v__ast__ArrayFixed*)__as_cast((param_typ_sym_->info)._v__ast__ArrayFixed,(param_typ_sym_->info)._typ, 480) /*expected idx: 480, name: v.ast.ArrayFixed */ ).elem_type)) { + continue; + } + } if (v__ast__Type_is_any_kind_of_pointer(param.typ) && typ_is_number) { continue; } @@ -57658,9 +57783,9 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal *(multi_return_v__ast__Fn_Array_v__ast__Type*) _t19.data = (multi_return_v__ast__Fn_Array_v__ast__Type){.arg0=((v__ast__Fn){.params = __new_array(0, 0, sizeof(v__ast__Param)),.generic_names = __new_array(0, 0, sizeof(string)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.mod = (string){.str=(byteptr)"", .is_lit=1},.file = (string){.str=(byteptr)"", .is_lit=1},.name = (string){.str=(byteptr)"", .is_lit=1},.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,.usages = 0,.ctdefine_idx = 0,.source_fn = 0,.language = 0,.file_mode = 0,.is_variadic = 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,.is_conditional = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__Fn_Array_v__ast__Type mr_42804 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t19.data); - method = mr_42804.arg0; - embed_types = mr_42804.arg1; + multi_return_v__ast__Fn_Array_v__ast__Type mr_43470 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t19.data); + method = mr_43470.arg0; + embed_types = mr_43470.arg1; if (embed_types.len != 0) { is_method_from_embed = true; node->from_embed_types = embed_types; @@ -57708,9 +57833,9 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal v__checker__Checker_error(c, _SLIT("method with `shared` receiver cannot be called inside `lock`/`rlock` block"), node->pos); } if ((*(v__ast__Param*)/*ee elem_sym */array_get(method.params, 0)).is_mut) { - multi_return_string_v__token__Pos mr_45114 = v__checker__Checker_fail_if_immutable(c, node->left); - string to_lock = mr_45114.arg0; - v__token__Pos pos = mr_45114.arg1; + multi_return_string_v__token__Pos mr_45780 = v__checker__Checker_fail_if_immutable(c, node->left); + string to_lock = mr_45780.arg0; + v__token__Pos pos = mr_45780.arg1; if (!v__ast__Expr_is_lvalue(node->left)) { v__checker__Checker_error(c, _SLIT("cannot pass expression as `mut`"), v__ast__Expr_pos(node->left)); } @@ -57818,9 +57943,9 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal v__checker__Checker_error(c, _SLIT("method with `shared` arguments cannot be called inside `lock`/`rlock` block"), arg->pos); } if (arg->is_mut) { - multi_return_string_v__token__Pos mr_49016 = v__checker__Checker_fail_if_immutable(c, arg->expr); - string to_lock = mr_49016.arg0; - v__token__Pos pos = mr_49016.arg1; + multi_return_string_v__token__Pos mr_49682 = v__checker__Checker_fail_if_immutable(c, arg->expr); + string to_lock = mr_49682.arg0; + v__token__Pos pos = mr_49682.arg1; if (!param_is_mut) { string tok = v__ast__ShareType_str(arg->share); v__checker__Checker_error(c, str_intp(5, _MOV((StrIntpData[]){{_SLIT("`"), /*115 &string*/0xfe10, {.d_s = node->name}}, {_SLIT("` parameter `"), /*115 &string*/0xfe10, {.d_s = param.name}}, {_SLIT("` is not `"), /*115 &string*/0xfe10, {.d_s = tok}}, {_SLIT("`, `"), /*115 &string*/0xfe10, {.d_s = tok}}, {_SLIT("` is not needed`"), 0, { .d_c = 0 }}})), v__ast__Expr_pos(arg->expr)); @@ -58010,8 +58135,8 @@ v__ast__Type v__checker__Checker_method_call(v__checker__Checker* c, v__ast__Cal return _t45; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_56382 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t44.data); - node->from_embed_types = mr_56382.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_57048 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t44.data); + node->from_embed_types = mr_57048.arg1; v__ast__Type _t46 = info.func.return_type; return _t46; } @@ -59882,7 +60007,7 @@ bool v__checker__Checker_sql_stmt_line_defer_0 = false; continue; } v__ast__StructField field = (*(v__ast__StructField*)/*ee elem_sym */array_get(x, 0)); - (*(string*)/*ee elem_sym */array_get(node->updated_columns, i)) = v__checker__Checker_fetch_field_name(c, field); + array_set(&node->updated_columns, i, &(string[]) { v__checker__Checker_fetch_field_name(c, field) }); } if (node->kind == v__ast__SqlStmtKind__update) { for (int _t10 = 0; _t10 < node->update_exprs.len; ++_t10) { @@ -60324,8 +60449,8 @@ v__ast__Type v__checker__Checker_string_inter_lit(v__checker__Checker* c, v__ast v__checker__Checker_error(c, str_intp(2, _MOV((StrIntpData[]){{_SLIT("no known default format for type `"), /*115 &string*/0xfe10, {.d_s = v__ast__Table_get_type_name(c->table, ftyp)}}, {_SLIT("`"), 0, { .d_c = 0 }}})), (*(v__token__Pos*)/*ee elem_sym */array_get(node->fmt_poss, i))); } } else { - (*(u8*)/*ee elem_sym */array_get(node->fmts, i)) = fmt; - (*(bool*)/*ee elem_sym */array_get(node->need_fmts, i)) = false; + array_set(&node->fmts, i, &(u8[]) { fmt }); + array_set(&node->need_fmts, i, &(bool[]) { false }); } } else { if ((*(int*)/*ee elem_sym */array_get(node->precisions, i)) != 987698 && !v__ast__Type_is_float(typ)) { @@ -60337,7 +60462,7 @@ v__ast__Type v__checker__Checker_string_inter_lit(v__checker__Checker* c, v__ast if ((v__ast__Type_is_unsigned(typ) && !(fmt == 'u' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'c' || fmt == 'b')) || (v__ast__Type_is_signed(typ) && !(fmt == 'd' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'c' || fmt == 'b')) || (v__ast__Type_is_int_literal(typ) && !(fmt == 'd' || fmt == 'c' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'u' || fmt == 'x' || fmt == 'X' || fmt == 'o' || fmt == 'b')) || (v__ast__Type_is_float(typ) && !(fmt == 'E' || fmt == 'F' || fmt == 'G' || fmt == 'e' || fmt == 'f' || fmt == 'g')) || (v__ast__Type_is_pointer(typ) && !(fmt == 'p' || fmt == 'x' || fmt == 'X')) || (v__ast__Type_is_string(typ) && !(fmt == 's' || fmt == 'S')) || ((v__ast__Type_idx(typ) == _const_v__ast__i64_type_idx || v__ast__Type_idx(typ) == _const_v__ast__f64_type_idx) && fmt == 'c')) { v__checker__Checker_error(c, str_intp(3, _MOV((StrIntpData[]){{_SLIT("illegal format specifier `"), /*99 &u8*/0xfe01, {.d_c = fmt}}, {_SLIT("` for type `"), /*115 &string*/0xfe10, {.d_s = v__ast__Table_get_type_name(c->table, ftyp)}}, {_SLIT("`"), 0, { .d_c = 0 }}})), (*(v__token__Pos*)/*ee elem_sym */array_get(node->fmt_poss, i))); } - (*(bool*)/*ee elem_sym */array_get(node->need_fmts, i)) = fmt != v__checker__Checker_get_default_fmt(c, ftyp, typ); + array_set(&node->need_fmts, i, &(bool[]) { fmt != v__checker__Checker_get_default_fmt(c, ftyp, typ) }); } if (c->table->cur_fn->is_method && string__eq(c->table->cur_fn->name, _SLIT("str")) && string__eq(c->table->cur_fn->receiver.name, v__ast__Expr_str(expr))) { v__checker__Checker_error(c, _SLIT("cannot call `str()` method recursively"), v__ast__Expr_pos(expr)); @@ -63164,6 +63289,13 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex } else if (node._typ == 327 /* v.ast.SelectorExpr */) { v__markused__Walker_expr(w, (*node._v__ast__SelectorExpr).expr); + if ((*node._v__ast__SelectorExpr).expr_type != 0) { + _option_v__ast__Fn _t4; + if (_t4 = v__ast__Table_find_method(w->table, v__ast__Table_sym(w->table, (*node._v__ast__SelectorExpr).expr_type), (*node._v__ast__SelectorExpr).field_name), _t4.state == 0) { + v__ast__Fn method = *(v__ast__Fn*)_t4.data; + v__markused__Walker_fn_by_name(w, v__ast__Fn_fkey(&method)); + } + } } else if (node._typ == 329 /* v.ast.SqlExpr */) { v__markused__Walker_expr(w, (*node._v__ast__SqlExpr).db_expr); @@ -63179,8 +63311,8 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex v__ast__TypeSymbol* sym = v__ast__Table_sym(w->table, (*node._v__ast__StructInit).typ); if (sym->kind == v__ast__Kind__struct_) { v__ast__Struct info = /* as */ *(v__ast__Struct*)__as_cast((sym->info)._v__ast__Struct,(sym->info)._typ, 457) /*expected idx: 457, name: v.ast.Struct */ ; - for (int _t4 = 0; _t4 < info.fields.len; ++_t4) { - v__ast__StructField ifield = ((v__ast__StructField*)info.fields.data)[_t4]; + for (int _t5 = 0; _t5 < info.fields.len; ++_t5) { + v__ast__StructField ifield = ((v__ast__StructField*)info.fields.data)[_t5]; if (ifield.has_default_expr) { v__markused__Walker_expr(w, ifield.default_expr); } @@ -63195,12 +63327,12 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex if ((*node._v__ast__StructInit).has_update_expr) { v__markused__Walker_expr(w, (*node._v__ast__StructInit).update_expr); } - for (int _t5 = 0; _t5 < (*node._v__ast__StructInit).fields.len; ++_t5) { - v__ast__StructInitField sif = ((v__ast__StructInitField*)(*node._v__ast__StructInit).fields.data)[_t5]; + for (int _t6 = 0; _t6 < (*node._v__ast__StructInit).fields.len; ++_t6) { + v__ast__StructInitField sif = ((v__ast__StructInitField*)(*node._v__ast__StructInit).fields.data)[_t6]; v__markused__Walker_expr(w, sif.expr); } - for (int _t6 = 0; _t6 < (*node._v__ast__StructInit).embeds.len; ++_t6) { - v__ast__StructInitEmbed sie = ((v__ast__StructInitEmbed*)(*node._v__ast__StructInit).embeds.data)[_t6]; + for (int _t7 = 0; _t7 < (*node._v__ast__StructInit).embeds.len; ++_t7) { + v__ast__StructInitEmbed sie = ((v__ast__StructInitEmbed*)(*node._v__ast__StructInit).embeds.data)[_t7]; v__markused__Walker_expr(w, sie.expr); } } @@ -63238,8 +63370,8 @@ VV_LOCAL_SYMBOL void v__markused__Walker_expr(v__markused__Walker* w, v__ast__Ex v__markused__Walker_or_block(w, (*node._v__ast__OrExpr)); } else if (node._typ == 326 /* v.ast.SelectExpr */) { - for (int _t7 = 0; _t7 < (*node._v__ast__SelectExpr).branches.len; ++_t7) { - v__ast__SelectBranch branch = ((v__ast__SelectBranch*)(*node._v__ast__SelectExpr).branches.data)[_t7]; + for (int _t8 = 0; _t8 < (*node._v__ast__SelectExpr).branches.len; ++_t8) { + v__ast__SelectBranch branch = ((v__ast__SelectBranch*)(*node._v__ast__SelectExpr).branches.data)[_t8]; v__markused__Walker_stmt(w, branch.stmt); v__markused__Walker_stmts(w, branch.stmts); } @@ -64804,7 +64936,11 @@ string sref_name; } else if (g->inside_for_c_stmt) { v__gen__c__Gen_expr(g, val); } else { - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("{"), /*115 &string*/0xfe10, {.d_s = styp}}, {_SLIT(" _ = "), 0, { .d_c = 0 }}}))); + if (left_sym->kind == v__ast__Kind__function) { + v__gen__c__Gen_write(g, _SLIT("{void* _ = ")); + } else { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("{"), /*115 &string*/0xfe10, {.d_s = styp}}, {_SLIT(" _ = "), 0, { .d_c = 0 }}}))); + } v__gen__c__Gen_expr(g, val); v__gen__c__Gen_writeln(g, _SLIT(";}")); } @@ -65047,6 +65183,8 @@ string sref_name; } if ((val)._typ == 287 /* v.ast.ArrayInit */) { v__gen__c__Gen_array_init(g, (*val._v__ast__ArrayInit), ident.name); + } else if (v__ast__Type_has_flag(val_type, v__ast__TypeFlag__shared_f)) { + v__gen__c__Gen_expr_with_cast(g, val, val_type, var_type); } else { v__gen__c__Gen_expr(g, val); } @@ -70811,15 +70949,16 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_selector_expr(v__gen__c__Gen* g, v__ast__Sel string sum_type_deref_field = _SLIT(""); string sum_type_dot = _SLIT("."); _option_v__ast__StructField _t3; + _option_v__ast__Fn _t4; if (_t3 = v__ast__Table_find_field(g->table, sym, node.field_name), _t3.state == 0) { v__ast__StructField f = *(v__ast__StructField*)_t3.data; v__ast__TypeSymbol* field_sym = v__ast__Table_sym(g->table, f.typ); if (field_sym->kind == v__ast__Kind__sum_type || field_sym->kind == v__ast__Kind__interface_) { if (!prevent_sum_type_unwrapping_once) { v__ast__Scope* scope = v__ast__Scope_innermost(g->file->scope, node.pos.pos); - _option_v__ast__ScopeStructField _t4; - if (_t4 = v__ast__Scope_find_struct_field(scope, v__ast__Expr_str(node.expr), node.expr_type, node.field_name), _t4.state == 0) { - v__ast__ScopeStructField field = *(v__ast__ScopeStructField*)_t4.data; + _option_v__ast__ScopeStructField _t5; + if (_t5 = v__ast__Scope_find_struct_field(scope, v__ast__Expr_str(node.expr), node.expr_type, node.field_name), _t5.state == 0) { + v__ast__ScopeStructField field = *(v__ast__ScopeStructField*)_t5.data; if (v__ast__Type_is_ptr(field.orig_type)) { sum_type_dot = _SLIT("->"); } @@ -70844,6 +70983,67 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_selector_expr(v__gen__c__Gen* g, v__ast__Sel } } } + } else if (_t4 = v__ast__Table_find_method(g->table, sym, node.field_name), _t4.state == 0) { + v__ast__Fn m = *(v__ast__Fn*)_t4.data; + bool has_embeds = false; + if ((sym->info)._typ == 457 /* v.ast.Struct */ || (sym->info)._typ == 470 /* v.ast.Aggregate */) { + if (node.from_embed_types.len > 0) { + has_embeds = true; + } + } + if (!has_embeds) { + if (!node.has_hidden_receiver) { + v__gen__c__Gen_write(g, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = v__gen__c__Gen_typ(g, v__ast__Type_idx(node.expr_type))}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = m.name}}, {_SLIT0, 0, { .d_c = 0 }}}))); + return; + } + v__ast__Param receiver = (*(v__ast__Param*)/*ee elem_sym */array_get(m.params, 0)); + string expr_styp = v__gen__c__Gen_typ(g, v__ast__Type_idx(node.expr_type)); + string data_styp = v__gen__c__Gen_typ(g, v__ast__Type_idx(receiver.typ)); + strings__Builder sb = strings__new_builder(256); + string name = str_intp(4, _MOV((StrIntpData[]){{_SLIT("_V_closure_"), /*115 &string*/0xfe10, {.d_s = expr_styp}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = m.name}}, {_SLIT("_"), /*100 &int*/0xfe07, {.d_i32 = node.pos.pos}}, {_SLIT0, 0, { .d_c = 0 }}})); + strings__Builder_write_string(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = v__gen__c__Gen_typ(g, m.return_type)}}, {_SLIT(" "), /*115 &string*/0xfe10, {.d_s = name}}, {_SLIT("("), 0, { .d_c = 0 }}}))); + for (int i = 1; i < m.params.len; ++i) { + v__ast__Param param = (*(v__ast__Param*)/*ee elem_sym */array_get(m.params, i)); + if (i != 1) { + strings__Builder_write_string(&sb, _SLIT(", ")); + } + strings__Builder_write_string(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = v__gen__c__Gen_typ(g, param.typ)}}, {_SLIT(" a"), /*100 &int literal*/0xfe07, {.d_i32 = i}}, {_SLIT0, 0, { .d_c = 0 }}}))); + } + strings__Builder_writeln(&sb, _SLIT(") {")); + strings__Builder_writeln(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT("\t"), /*115 &string*/0xfe10, {.d_s = data_styp}}, {_SLIT("* a0 = *("), /*115 &string*/0xfe10, {.d_s = data_styp}}, {_SLIT("**)(__RETURN_ADDRESS() - __CLOSURE_DATA_OFFSET);"), 0, { .d_c = 0 }}}))); + if (!v__ast__Type_alias_eq(m.return_type, _const_v__ast__void_type)) { + strings__Builder_write_string(&sb, _SLIT("\treturn ")); + } else { + strings__Builder_write_string(&sb, _SLIT("\t")); + } + strings__Builder_write_string(&sb, str_intp(3, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = expr_styp}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = m.name}}, {_SLIT("("), 0, { .d_c = 0 }}}))); + if (!v__ast__Type_is_ptr(receiver.typ)) { + strings__Builder_write_string(&sb, _SLIT("*")); + } + for (int i = 0; i < m.params.len; ++i) { + if (i != 0) { + strings__Builder_write_string(&sb, _SLIT(", ")); + } + strings__Builder_write_string(&sb, str_intp(2, _MOV((StrIntpData[]){{_SLIT("a"), /*100 &int literal*/0xfe07, {.d_i32 = i}}, {_SLIT0, 0, { .d_c = 0 }}}))); + } + strings__Builder_writeln(&sb, _SLIT(");")); + strings__Builder_writeln(&sb, _SLIT("}")); + array_push((array*)&g->anon_fn_definitions, _MOV((string[]){ string_clone(strings__Builder_str(&sb)) })); + g->nr_closures++; + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("__closure_create("), /*115 &string*/0xfe10, {.d_s = name}}, {_SLIT(", "), 0, { .d_c = 0 }}}))); + if (!v__ast__Type_is_ptr(receiver.typ)) { + v__gen__c__Gen_write(g, _SLIT("memdup(")); + } + if (!v__ast__Type_is_ptr(node.expr_type)) { + v__gen__c__Gen_write(g, _SLIT("&")); + } + v__gen__c__Gen_expr(g, node.expr); + if (!v__ast__Type_is_ptr(receiver.typ)) { + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT(", sizeof("), /*115 &string*/0xfe10, {.d_s = expr_styp}}, {_SLIT("))"), 0, { .d_c = 0 }}}))); + } + v__gen__c__Gen_write(g, _SLIT(")")); + return; + } } int n_ptr = v__ast__Type_nr_muls(node.expr_type) - 1; if (n_ptr > 0) { @@ -71047,11 +71247,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_106889 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); - string hash_fn = mr_106889.arg0; - string key_eq_fn = mr_106889.arg1; - string clone_fn = mr_106889.arg2; - string free_fn = mr_106889.arg3; + multi_return_string_string_string_string mr_108466 = v__gen__c__Gen_map_fn_ptrs(g, *key_sym); + string hash_fn = mr_108466.arg0; + string key_eq_fn = mr_108466.arg1; + string clone_fn = mr_108466.arg2; + string free_fn = mr_108466.arg3; int size = node.vals.len; string shared_styp = _SLIT(""); string styp = _SLIT(""); @@ -72308,9 +72508,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_146906 = v__gen__c__Gen_optional_type_name(g, field.typ); - string styp = mr_146906.arg0; - string base = mr_146906.arg1; + multi_return_string_string mr_148483 = v__gen__c__Gen_optional_type_name(g, field.typ); + string styp = mr_148483.arg0; + string base = mr_148483.arg1; sync__RwMutex_lock(&g->done_optionals->mtx); /*lock*/ { if (!Array_string_contains(g->done_optionals->val, base)) { @@ -72605,11 +72805,11 @@ bool v__gen__c__Gen_or_block_defer_0 = false; 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["), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._typ]._method_msg("), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._object)"), 0, { .d_c = 0 }}})); if (g->pref->is_debug) { - multi_return_int_string_string_string mr_156689 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); - int paline = mr_156689.arg0; - string pafile = mr_156689.arg1; - string pamod = mr_156689.arg2; - string pafn = mr_156689.arg3; + multi_return_int_string_string_string mr_158266 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); + int paline = mr_158266.arg0; + string pafile = mr_158266.arg1; + string pamod = mr_158266.arg2; + string pafn = mr_158266.arg3; v__gen__c__Gen_writeln(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("panic_debug("), /*100 &int*/0xfe07, {.d_i32 = paline}}, {_SLIT(", tos3(\""), /*115 &string*/0xfe10, {.d_s = pafile}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pamod}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pafn}}, {_SLIT("\"), "), /*115 &string*/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( "), /*115 &string*/0xfe10, {.d_s = err_msg}}, {_SLIT(" );"), 0, { .d_c = 0 }}}))); @@ -72632,11 +72832,11 @@ bool v__gen__c__Gen_or_block_defer_0 = false; 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["), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._typ]._method_msg("), /*115 &string*/0xfe10, {.d_s = cvar_name}}, {_SLIT(".err._object)"), 0, { .d_c = 0 }}})); if (g->pref->is_debug) { - multi_return_int_string_string_string mr_157956 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); - int paline = mr_157956.arg0; - string pafile = mr_157956.arg1; - string pamod = mr_157956.arg2; - string pafn = mr_157956.arg3; + multi_return_int_string_string_string mr_159533 = v__gen__c__Gen_panic_debug_info(g, or_block.pos); + int paline = mr_159533.arg0; + string pafile = mr_159533.arg1; + string pamod = mr_159533.arg2; + string pafn = mr_159533.arg3; v__gen__c__Gen_writeln(g, str_intp(6, _MOV((StrIntpData[]){{_SLIT("panic_debug("), /*100 &int*/0xfe07, {.d_i32 = paline}}, {_SLIT(", tos3(\""), /*115 &string*/0xfe10, {.d_s = pafile}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pamod}}, {_SLIT("\"), tos3(\""), /*115 &string*/0xfe10, {.d_s = pafn}}, {_SLIT("\"), "), /*115 &string*/0xfe10, {.d_s = err_msg}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); } else { v__gen__c__Gen_writeln(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("\tpanic_result_not_set("), /*115 &string*/0xfe10, {.d_s = err_msg}}, {_SLIT(");"), 0, { .d_c = 0 }}}))); @@ -72746,11 +72946,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_160566 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); - string hash_fn = mr_160566.arg0; - string key_eq_fn = mr_160566.arg1; - string clone_fn = mr_160566.arg2; - string free_fn = mr_160566.arg3; + multi_return_string_string_string_string mr_162143 = v__gen__c__Gen_map_fn_ptrs(g, *key_typ); + string hash_fn = mr_162143.arg0; + string key_eq_fn = mr_162143.arg1; + string clone_fn = mr_162143.arg2; + string free_fn = mr_162143.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(""))); @@ -73276,8 +73476,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)).name,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).pos,(*(v__ast__Param*)/*ee elem_sym */array_get(params, 0)).type_pos,.typ = v__ast__Type_set_nr_muls(st, 1),(*(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)).is_hidden,}) }); - multi_return_Array_string_Array_string_Array_bool mr_175048 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); - Array_string fargs = mr_175048.arg0; + multi_return_Array_string_Array_string_Array_bool mr_176625 = v__gen__c__Gen_fn_decl_params(g, params, ((voidptr)(0)), false); + Array_string fargs = mr_176625.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__")); @@ -73294,8 +73494,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){.params = __new_array(0, 0, sizeof(v__ast__Param)),.generic_names = __new_array(0, 0, sizeof(string)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.mod = (string){.str=(byteptr)"", .is_lit=1},.file = (string){.str=(byteptr)"", .is_lit=1},.name = (string){.str=(byteptr)"", .is_lit=1},.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,.usages = 0,.ctdefine_idx = 0,.source_fn = 0,.language = 0,.file_mode = 0,.is_variadic = 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,.is_conditional = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__Fn_Array_v__ast__Type mr_175512 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); - Array_v__ast__Type embed_types = mr_175512.arg1; + multi_return_v__ast__Fn_Array_v__ast__Type mr_177089 = (*(multi_return_v__ast__Fn_Array_v__ast__Type*)_t26.data); + Array_v__ast__Type embed_types = mr_177089.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, /*115 &string*/0xfe10, {.d_s = embed_sym->cname}}, {_SLIT("_"), /*115 &string*/0xfe10, {.d_s = method.name}}, {_SLIT0, 0, { .d_c = 0 }}})); @@ -76563,19 +76763,37 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_call_args(v__gen__c__Gen* g, v__ast__CallExp v__ast__TypeSymbol* arr_sym = v__ast__Table_sym(g->table, varg_type); v__ast__Array arr_info = /* as */ *(v__ast__Array*)__as_cast((arr_sym->info)._v__ast__Array,(arr_sym->info)._typ, 452) /*expected idx: 452, name: v.ast.Array */ ; if (v__ast__Type_has_flag(varg_type, v__ast__TypeFlag__generic)) { - _option_v__ast__Fn _t10; - if (_t10 = v__ast__Table_find_fn(g->table, node.name), _t10.state == 0) { - v__ast__Fn fn_def = *(v__ast__Fn*)_t10.data; - v__ast__Table* muttable = ((v__ast__Table*)(g->table)); - _option_v__ast__Type _t11; - if (_t11 = v__ast__Table_resolve_generic_to_concrete(muttable, arr_info.elem_type, fn_def.generic_names, node.concrete_types), _t11.state == 0) { - v__ast__Type utyp = *(v__ast__Type*)_t11.data; - arr_info.elem_type = utyp; + if (node.is_method) { + v__ast__TypeSymbol* left_sym = v__ast__Table_sym(g->table, node.left_type); + _option_v__ast__Fn _t10; + if (_t10 = v__ast__TypeSymbol_find_method_with_generic_parent(left_sym, node.name), _t10.state == 0) { + v__ast__Fn fn_def = *(v__ast__Fn*)_t10.data; + v__ast__Table* muttable = ((v__ast__Table*)(g->table)); + _option_v__ast__Type _t11; + if (_t11 = v__ast__Table_resolve_generic_to_concrete(muttable, arr_info.elem_type, fn_def.generic_names, node.concrete_types), _t11.state == 0) { + v__ast__Type utyp = *(v__ast__Type*)_t11.data; + arr_info.elem_type = utyp; + } + } else { + IError err = _t10.err; + v__gen__c__Gen_error(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("unable to find method "), /*115 &string*/0xfe10, {.d_s = node.name}}, {_SLIT0, 0, { .d_c = 0 }}})), node.pos); + VUNREACHABLE(); } } else { - IError err = _t10.err; - v__gen__c__Gen_error(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("unable to find function "), /*115 &string*/0xfe10, {.d_s = node.name}}, {_SLIT0, 0, { .d_c = 0 }}})), node.pos); - VUNREACHABLE(); + _option_v__ast__Fn _t12; + if (_t12 = v__ast__Table_find_fn(g->table, node.name), _t12.state == 0) { + v__ast__Fn fn_def = *(v__ast__Fn*)_t12.data; + v__ast__Table* muttable = ((v__ast__Table*)(g->table)); + _option_v__ast__Type _t13; + if (_t13 = v__ast__Table_resolve_generic_to_concrete(muttable, arr_info.elem_type, fn_def.generic_names, node.concrete_types), _t13.state == 0) { + v__ast__Type utyp = *(v__ast__Type*)_t13.data; + arr_info.elem_type = utyp; + } + } else { + IError err = _t12.err; + v__gen__c__Gen_error(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT("unable to find function "), /*115 &string*/0xfe10, {.d_s = node.name}}, {_SLIT0, 0, { .d_c = 0 }}})), node.pos); + VUNREACHABLE(); + } } } string elem_type = v__gen__c__Gen_typ(g, arr_info.elem_type); @@ -77501,7 +77719,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_if_expr(v__gen__c__Gen* g, v__ast__IfExpr no v__gen__c__Gen_write(g, _SLIT(" ? ")); } v__ast__Type prev_expected_cast_type = g->expected_cast_type; - if (node.is_expr && v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type) { + if (node.is_expr && (v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type || v__ast__Type_has_flag(node.typ, v__ast__TypeFlag__shared_f))) { g->expected_cast_type = node.typ; } v__gen__c__Gen_stmts(g, branch.stmts); @@ -77625,7 +77843,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_if_expr(v__gen__c__Gen* g, v__ast__IfExpr no } if (needs_tmp_var) { v__ast__Type prev_expected_cast_type = g->expected_cast_type; - if (node.is_expr && v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type) { + if (node.is_expr && (v__ast__Table_sym(g->table, node.typ)->kind == v__ast__Kind__sum_type || v__ast__Type_has_flag(node.typ, v__ast__TypeFlag__shared_f))) { g->expected_cast_type = node.typ; } v__gen__c__Gen_stmts_with_tmp_var(g, branch.stmts, tmp); @@ -77812,8 +78030,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_index_of_array(v__gen__c__Gen* g, v__ast__In if (elem_sym->kind == v__ast__Kind__function) { elem_type_str = _SLIT("voidptr"); } - bool is_selector = (node.left)._typ == 327 /* v.ast.SelectorExpr */; - if (g->is_assign_lhs && !is_selector && node.is_setter) { + if (g->is_assign_lhs && node.is_setter) { bool is_direct_array_access = (g->fn_decl != 0 && g->fn_decl->is_direct_arr) || node.is_direct; bool is_op_assign = g->assign_op != v__token__Kind__assign && !v__ast__Type_alias_eq(info.elem_type, _const_v__ast__string_type); if (is_direct_array_access) { @@ -78434,21 +78651,25 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_infix_expr_eq_op(v__gen__c__Gen* g, v__ast__ } case v__ast__Kind__struct_: { - string ptr_typ = v__gen__c__Gen_equality_fn(g, left.unaliased); - if (node.op == v__token__Kind__ne) { - v__gen__c__Gen_write(g, _SLIT("!")); + if (g->pref->translated) { + v__gen__c__Gen_gen_plain_infix_expr(g, node); + } else { + string ptr_typ = v__gen__c__Gen_equality_fn(g, left.unaliased); + if (node.op == v__token__Kind__ne) { + v__gen__c__Gen_write(g, _SLIT("!")); + } + v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = ptr_typ}}, {_SLIT("_struct_eq("), 0, { .d_c = 0 }}}))); + if (v__ast__Type_is_ptr(left.typ)) { + v__gen__c__Gen_write(g, _SLIT("*")); + } + v__gen__c__Gen_expr(g, node.left); + v__gen__c__Gen_write(g, _SLIT(", ")); + if (v__ast__Type_is_ptr(right.typ)) { + v__gen__c__Gen_write(g, _SLIT("*")); + } + v__gen__c__Gen_expr(g, node.right); + v__gen__c__Gen_write(g, _SLIT(")")); } - v__gen__c__Gen_write(g, str_intp(2, _MOV((StrIntpData[]){{_SLIT0, /*115 &string*/0xfe10, {.d_s = ptr_typ}}, {_SLIT("_struct_eq("), 0, { .d_c = 0 }}}))); - if (v__ast__Type_is_ptr(left.typ)) { - v__gen__c__Gen_write(g, _SLIT("*")); - } - v__gen__c__Gen_expr(g, node.left); - v__gen__c__Gen_write(g, _SLIT(", ")); - if (v__ast__Type_is_ptr(right.typ)) { - v__gen__c__Gen_write(g, _SLIT("*")); - } - v__gen__c__Gen_expr(g, node.right); - v__gen__c__Gen_write(g, _SLIT(")")); break; } case v__ast__Kind__sum_type: @@ -80955,6 +81176,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_sql_select(v__gen__c__Gen* g, v__ast__SqlExp .next_token = 0, .gkind_field = 0, .is_mut = false, + .has_hidden_receiver = 0, })))); v__ast__SqlExpr arr = ((v__ast__SqlExpr){ .typ = field.typ, @@ -81404,7 +81626,7 @@ VV_LOCAL_SYMBOL void v__gen__c__Gen_string_inter_literal(v__gen__c__Gen* g, v__a v__ast__Expr* expr = ((v__ast__Expr*)node_.exprs.data) + i; if ((expr)->_typ == 307 /* v.ast.Ident */) { if (((*expr->_v__ast__Ident).obj)._typ == 365 /* v.ast.Var */) { - (*(v__ast__Type*)/*ee elem_sym */array_get(node_.expr_types, i)) = (*(*expr->_v__ast__Ident).obj._v__ast__Var).typ; + array_set(&node_.expr_types, i, &(v__ast__Type[]) { (*(*expr->_v__ast__Ident).obj._v__ast__Var).typ }); } } } @@ -81647,6 +81869,8 @@ bool v__gen__c__Gen_struct_init_defer_0 = false; } } if (!cloned) { + int inside_cast_in_heap = g->inside_cast_in_heap; + g->inside_cast_in_heap = 0; if (field_type_sym->kind == v__ast__Kind__array_fixed && (sfield.expr)._typ == 307 /* v.ast.Ident */) { v__ast__ArrayFixed fixed_array_info = /* as */ *(v__ast__ArrayFixed*)__as_cast((field_type_sym->info)._v__ast__ArrayFixed,(field_type_sym->info)._typ, 480) /*expected idx: 480, name: v.ast.ArrayFixed */ ; v__gen__c__Gen_write(g, _SLIT("{")); @@ -81664,6 +81888,7 @@ bool v__gen__c__Gen_struct_init_defer_0 = false; } v__gen__c__Gen_expr_with_cast(g, sfield.expr, sfield.typ, sfield.expected_type); } + g->inside_cast_in_heap = inside_cast_in_heap; } if (is_multiline) { v__gen__c__Gen_writeln(g, _SLIT(",")); @@ -81700,8 +81925,8 @@ bool v__gen__c__Gen_struct_init_defer_0 = false; *(multi_return_v__ast__StructField_Array_v__ast__Type*) _t15.data = (multi_return_v__ast__StructField_Array_v__ast__Type){.arg0=((v__ast__StructField){.comments = __new_array(0, 0, sizeof(v__ast__Comment)),.attrs = __new_array(0, 0, sizeof(v__ast__Attr)),.default_val = (string){.str=(byteptr)"", .is_lit=1},.default_expr = {0},.name = (string){.str=(byteptr)"", .is_lit=1},.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,},.i = 0,.default_expr_typ = 0,.typ = 0,.has_default_expr = 0,.is_pub = 0,.is_mut = 0,.is_global = 0,.is_volatile = 0,}),.arg1=__new_array_with_default(0, 0, sizeof(v__ast__Type), 0)}; } - multi_return_v__ast__StructField_Array_v__ast__Type mr_6986 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); - Array_v__ast__Type embeds = mr_6986.arg1; + multi_return_v__ast__StructField_Array_v__ast__Type mr_6823 = (*(multi_return_v__ast__StructField_Array_v__ast__Type*)_t15.data); + Array_v__ast__Type embeds = mr_6823.arg1; for (int _t16 = 0; _t16 < embeds.len; ++_t16) { v__ast__Type embed = ((v__ast__Type*)embeds.data)[_t16]; v__ast__TypeSymbol* esym = v__ast__Table_sym(g->table, embed); @@ -87034,6 +87259,7 @@ VV_LOCAL_SYMBOL v__ast__Expr v__parser__Parser_lockable(v__parser__Parser* p) { .next_token = (i < names.len - 1 ? (v__token__Kind__dot) : (p->tok.kind)), .gkind_field = 0, .is_mut = true, + .has_hidden_receiver = 0, })))); } v__ast__Expr _t3 = expr; @@ -90381,7 +90607,7 @@ v__ast__Expr v__parser__Parser_name_expr(v__parser__Parser* p) { string field = v__parser__Parser_check_name(p); v__ast__GenericKindField fkind = ((string__eq(field, _SLIT("name")))? (v__ast__GenericKindField__name) : (string__eq(field, _SLIT("typ")))? (v__ast__GenericKindField__typ) : (v__ast__GenericKindField__unknown)); v__token__Pos_extend(pos, v__token__Token_pos(&p->tok)); - v__ast__Expr _t21 = v__ast__SelectorExpr_to_sumtype_v__ast__Expr(ADDR(v__ast__SelectorExpr, (((v__ast__SelectorExpr){.from_embed_types = __new_array(0, 0, sizeof(v__ast__Type)),.field_name = field,.expr = v__ast__Ident_to_sumtype_v__ast__Expr(ADDR(v__ast__Ident, (((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = name,.info = {0},.scope = p->scope,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,})))),.scope = p->scope,.pos = pos,.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.expr_type = 0,.typ = 0,.name_type = 0,.next_token = 0,.gkind_field = fkind,.is_mut = 0,})))); + v__ast__Expr _t21 = v__ast__SelectorExpr_to_sumtype_v__ast__Expr(ADDR(v__ast__SelectorExpr, (((v__ast__SelectorExpr){.from_embed_types = __new_array(0, 0, sizeof(v__ast__Type)),.field_name = field,.expr = v__ast__Ident_to_sumtype_v__ast__Expr(ADDR(v__ast__Ident, (((v__ast__Ident){.obj = {0},.mod = (string){.str=(byteptr)"", .is_lit=1},.name = name,.info = {0},.scope = p->scope,.pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.tok_kind = 0,.language = 0,.kind = 0,.comptime = 0,.is_mut = 0,})))),.scope = p->scope,.pos = pos,.mut_pos = (v__token__Pos){.len = 0,.line_nr = 0,.pos = 0,.col = 0,.last_line = 0,},.expr_type = 0,.typ = 0,.name_type = 0,.next_token = 0,.gkind_field = fkind,.is_mut = 0,.has_hidden_receiver = 0,})))); return _t21; } if (v__parser__Parser_peek_token(p, 2).kind == v__token__Kind__name && v__parser__Parser_peek_token(p, 3).kind == v__token__Kind__lpar && !known_var) { @@ -90710,6 +90936,7 @@ VV_LOCAL_SYMBOL v__ast__Expr v__parser__Parser_dot_expr(v__parser__Parser* p, v_ .next_token = p->tok.kind, .gkind_field = 0, .is_mut = is_mut, + .has_hidden_receiver = 0, }); if (is_filter) { v__parser__Parser_close_scope(p); @@ -93174,11 +93401,7 @@ string v__parser__Parser_compile_template_file(v__parser__Parser* p, string temp } } else if (state == (v__parser__State__js)) { - if (string_contains(line, _SLIT("//V_TEMPLATE"))) { - strings__Builder_writeln(&source, v__parser__insert_template_code(fn_name, tmpl_str_start, line)); - } else { - strings__Builder_writeln(&source, string_replace(string_replace(string_replace(string_replace(line, _SLIT("$"), _SLIT("\\$")), _SLIT("$$"), _SLIT("@")), _SLIT(".$"), _SLIT(".@")), _SLIT("'"), _SLIT("\\'"))); - } + strings__Builder_writeln(&source, v__parser__insert_template_code(fn_name, tmpl_str_start, line)); continue; } else if (state == (v__parser__State__css)) {