cgen: remove tos3() call: part 1
parent
dd1ee39271
commit
fde929ee30
|
@ -1127,6 +1127,12 @@ fn (mut g Gen) expr(node ast.Expr) {
|
||||||
// `C.printf("hi")` => `printf("hi");`
|
// `C.printf("hi")` => `printf("hi");`
|
||||||
g.write('"$escaped_val"')
|
g.write('"$escaped_val"')
|
||||||
} else {
|
} else {
|
||||||
|
// TODO calculate the literal's length in V, it's a bit tricky with all the
|
||||||
|
// escape characters.
|
||||||
|
// Clang and GCC optimize `strlen("lorem ipsum")` to `11`
|
||||||
|
// g.write('tos4("$escaped_val", strlen("$escaped_val"))')
|
||||||
|
// g.write('tos4("$escaped_val", $it.val.len)')
|
||||||
|
// g.write('_SLIT("$escaped_val")')
|
||||||
g.write('tos3("$escaped_val")')
|
g.write('tos3("$escaped_val")')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2727,7 +2733,7 @@ fn (g Gen) type_default(typ table.Type) string {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
match sym.name {
|
match sym.name {
|
||||||
'string' { return 'tos3("")' }
|
'string' { return '(string){.str=""}' }
|
||||||
'rune' { return '0' }
|
'rune' { return '0' }
|
||||||
else {}
|
else {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,6 +173,8 @@ extern wchar_t **_wenviron;
|
||||||
|
|
||||||
|
|
||||||
//============================== HELPER C MACROS =============================*/
|
//============================== HELPER C MACROS =============================*/
|
||||||
|
//#define tos4(s, slen) ((string){.str=(s), .len=(slen)})
|
||||||
|
#define _SLIT(s) ((string){.str=(s), .len=(strlen(s))})
|
||||||
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);}
|
#define _PUSH_MANY(arr, val, tmp, tmp_typ) {tmp_typ tmp = (val); array_push_many(arr, tmp.data, tmp.len);}
|
||||||
#define _IN(typ, val, arr) array_##typ##_contains(arr, val)
|
#define _IN(typ, val, arr) array_##typ##_contains(arr, val)
|
||||||
#define _IN_MAP(val, m) map_exists(m, val)
|
#define _IN_MAP(val, m) map_exists(m, val)
|
||||||
|
|
Loading…
Reference in New Issue