compiler: cast correctly strings between byte* and char* when needed

pull/1742/head
Henrixounez 2019-08-25 00:12:11 +02:00 committed by Alexander Medvednikov
parent 0a0d6536c2
commit ad32a3770b
4 changed files with 10 additions and 10 deletions

View File

@ -779,7 +779,7 @@ fn (p mut Parser) fn_call_args(f mut Fn) *Fn {
file_path := p.file_path.replace('\\', '\\\\') // escape \ file_path := p.file_path.replace('\\', '\\\\') // escape \
p.cgen.resetln(p.cgen.cur_line.replace( p.cgen.resetln(p.cgen.cur_line.replace(
'v_panic (', 'v_panic (',
'_panic_debug ($p.scanner.line_nr, tos2("$file_path"), tos2("$mod_name"), tos2("$fn_name"), ' '_panic_debug ($p.scanner.line_nr, tos2((byte *)"$file_path"), tos2((byte *)"$mod_name"), tos2((byte *)"$fn_name"), '
)) ))
} }
// Receiver - first arg // Receiver - first arg

View File

@ -357,7 +357,7 @@ string _STR(const char *fmt, ...) {
va_end(argptr); va_end(argptr);
byte* buf = malloc(len); byte* buf = malloc(len);
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(buf, fmt, argptr); vsprintf((char *)buf, fmt, argptr);
va_end(argptr); va_end(argptr);
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
puts("_STR:"); puts("_STR:");
@ -369,10 +369,10 @@ string _STR(const char *fmt, ...) {
string _STR_TMP(const char *fmt, ...) { string _STR_TMP(const char *fmt, ...) {
va_list argptr; va_list argptr;
va_start(argptr, fmt); va_start(argptr, fmt);
size_t len = vsnprintf(0, 0, fmt, argptr) + 1; //size_t len = vsnprintf(0, 0, fmt, argptr) + 1;
va_end(argptr); va_end(argptr);
va_start(argptr, fmt); va_start(argptr, fmt);
vsprintf(g_str_buf, fmt, argptr); vsprintf((char *)g_str_buf, fmt, argptr);
va_end(argptr); va_end(argptr);
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
//puts("_STR_TMP:"); //puts("_STR_TMP:");

View File

@ -2088,7 +2088,7 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
// TODO what about user types? // TODO what about user types?
if is_map && typ == 'string' { if is_map && typ == 'string' {
// p.cgen.insert_before('if (!${tmp}.str) $tmp = tos("", 0);') // p.cgen.insert_before('if (!${tmp}.str) $tmp = tos("", 0);')
p.cgen.insert_before('if (!$tmp_ok) $tmp = tos("", 0);') p.cgen.insert_before('if (!$tmp_ok) $tmp = tos((byte *)"", 0);')
} }
} }
// else if is_arr && is_indexer{} // else if is_arr && is_indexer{}
@ -2608,7 +2608,7 @@ fn (p mut Parser) map_init() string {
mut i := 0 mut i := 0
for { for {
key := p.lit key := p.lit
keys_gen += 'tos2("$key"), ' keys_gen += 'tos2((byte*)"$key"), '
p.check(.str) p.check(.str)
p.check(.colon) p.check(.colon)
p.cgen.start_tmp() p.cgen.start_tmp()
@ -2974,7 +2974,7 @@ fn (p mut Parser) cast(typ string) string {
if is_byteptr || is_bytearr { if is_byteptr || is_bytearr {
if p.tok == .comma { if p.tok == .comma {
p.check(.comma) p.check(.comma)
p.cgen.set_placeholder(pos, 'tos(') p.cgen.set_placeholder(pos, 'tos((byte *)')
if is_bytearr { if is_bytearr {
p.gen('.data') p.gen('.data')
} }
@ -2984,7 +2984,7 @@ fn (p mut Parser) cast(typ string) string {
if is_bytearr { if is_bytearr {
p.gen('.data') p.gen('.data')
} }
p.cgen.set_placeholder(pos, 'tos2(') p.cgen.set_placeholder(pos, 'tos2((byte *)')
} }
} }
// `string(234)` => error // `string(234)` => error
@ -3359,7 +3359,7 @@ fn (p mut Parser) assert_statement() {
filename := p.file_path.replace('\\', '\\\\') filename := p.file_path.replace('\\', '\\\\')
p.genln(';\n p.genln(';\n
if (!$tmp) { if (!$tmp) {
println(tos2("\\x1B[31mFAILED: $p.cur_fn.name() in $filename:$p.scanner.line_nr\\x1B[0m")); println(tos2((byte *)"\\x1B[31mFAILED: $p.cur_fn.name() in $filename:$p.scanner.line_nr\\x1B[0m"));
g_test_ok = 0 ; g_test_ok = 0 ;
// TODO // TODO
// Maybe print all vars in a test function if it fails? // Maybe print all vars in a test function if it fails?

View File

@ -608,7 +608,7 @@ fn type_default(typ string) string {
// Default values for other types are not needed because of mandatory initialization // Default values for other types are not needed because of mandatory initialization
switch typ { switch typ {
case 'bool': return '0' case 'bool': return '0'
case 'string': return 'tos("", 0)' case 'string': return 'tos((byte *)"", 0)'
case 'i8': return '0' case 'i8': return '0'
case 'i16': return '0' case 'i16': return '0'
case 'i32': return '0' case 'i32': return '0'