cgen: array and fixed array fixes
parent
750f37fde7
commit
24bcc7a93b
|
@ -273,6 +273,10 @@ pub fn (c mut Checker) method_call_expr(method_call_expr mut ast.MethodCallExpr)
|
||||||
info := typ_sym.info as table.Array
|
info := typ_sym.info as table.Array
|
||||||
return info.elem_type
|
return info.elem_type
|
||||||
}
|
}
|
||||||
|
// repeat() returns `array`, need to return `array_xxx`
|
||||||
|
else if typ_sym.kind == .array && name in ['repeat'] {
|
||||||
|
return typ
|
||||||
|
}
|
||||||
if method := typ_sym.find_method(name) {
|
if method := typ_sym.find_method(name) {
|
||||||
for i, arg_expr in method_call_expr.args {
|
for i, arg_expr in method_call_expr.args {
|
||||||
c.expected_type = method.args[i].typ
|
c.expected_type = method.args[i].typ
|
||||||
|
|
|
@ -66,12 +66,19 @@ pub fn (g &Gen) styp(t string) string {
|
||||||
|
|
||||||
pub fn (g mut Gen) write_array_types() {
|
pub fn (g mut Gen) write_array_types() {
|
||||||
for typ in g.table.types {
|
for typ in g.table.types {
|
||||||
if typ.kind != .array {
|
if typ.kind == .array {
|
||||||
continue
|
|
||||||
}
|
|
||||||
styp := typ.name.replace('.', '__')
|
styp := typ.name.replace('.', '__')
|
||||||
g.definitions.writeln('typedef array $styp;')
|
g.definitions.writeln('typedef array $styp;')
|
||||||
}
|
}
|
||||||
|
else if typ.kind == .array_fixed {
|
||||||
|
styp := typ.name.replace('.', '__')
|
||||||
|
// array_fixed_char_300 => char x[300]
|
||||||
|
mut fixed := styp[12..]
|
||||||
|
len := styp.after('_')
|
||||||
|
fixed = fixed[..fixed.len - len.len - 1]
|
||||||
|
g.definitions.writeln('typedef $fixed $styp [$len];')
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (g mut Gen) write_multi_return_types() {
|
pub fn (g mut Gen) write_multi_return_types() {
|
||||||
|
@ -491,6 +498,13 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||||
g.expr(it.right)
|
g.expr(it.right)
|
||||||
g.write(')')
|
g.write(')')
|
||||||
}
|
}
|
||||||
|
else if it.op == .eq && it.left_type == table.string_type_idx {
|
||||||
|
g.write('string_eq(')
|
||||||
|
g.expr(it.left)
|
||||||
|
g.write(', ')
|
||||||
|
g.expr(it.right)
|
||||||
|
g.write(')')
|
||||||
|
}
|
||||||
// arr << val
|
// arr << val
|
||||||
else if it.op == .left_shift && g.table.get_type_symbol(it.left_type).kind == .array {
|
else if it.op == .left_shift && g.table.get_type_symbol(it.left_type).kind == .array {
|
||||||
g.write('array_push(')
|
g.write('array_push(')
|
||||||
|
@ -576,6 +590,9 @@ fn (g mut Gen) expr(node ast.Expr) {
|
||||||
if it.typ != 0 {
|
if it.typ != 0 {
|
||||||
typ_sym := g.table.get_type_symbol(it.typ)
|
typ_sym := g.table.get_type_symbol(it.typ)
|
||||||
receiver_name = typ_sym.name
|
receiver_name = typ_sym.name
|
||||||
|
// if typ_sym.kind == .array {
|
||||||
|
// receiver_name = 'array'
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
name := '${receiver_name}_$it.name'.replace('.', '__')
|
name := '${receiver_name}_$it.name'.replace('.', '__')
|
||||||
g.write('${name}(')
|
g.write('${name}(')
|
||||||
|
|
Loading…
Reference in New Issue