cgen/checker: fixes & fixes & tmp fixes :D
parent
c0df54b7d3
commit
076bc2b773
|
@ -389,6 +389,7 @@ pub:
|
|||
// cond Expr
|
||||
val string
|
||||
stmts []Stmt
|
||||
is_not bool
|
||||
pos token.Position
|
||||
mut:
|
||||
has_else bool
|
||||
|
|
|
@ -178,11 +178,11 @@ pub fn (c mut Checker) call_expr(call_expr mut ast.CallExpr) table.Type {
|
|||
return table.string_type
|
||||
}
|
||||
// start hack: until v1 is fixed and c definitions are added for these
|
||||
if fn_name in ['C.calloc', 'C.exit', 'C.free'] {
|
||||
if fn_name in ['C.calloc', 'C.malloc', 'C.exit', 'C.free'] {
|
||||
for arg in call_expr.args {
|
||||
c.expr(arg.expr)
|
||||
}
|
||||
if fn_name == 'C.calloc' {
|
||||
if fn_name in ['C.calloc', 'C.malloc'] {
|
||||
return table.byteptr_type
|
||||
}
|
||||
return table.void_type
|
||||
|
|
|
@ -268,8 +268,14 @@ fn (g mut Gen) stmt(node ast.Stmt) {
|
|||
g.const_decl(it)
|
||||
}
|
||||
ast.CompIf {
|
||||
if it.is_not {
|
||||
g.writeln('\n#ifndef ' + comp_if_to_ifdef(it.val))
|
||||
g.writeln('// #if not $it.val')
|
||||
}
|
||||
else {
|
||||
g.writeln('\n#ifdef ' + comp_if_to_ifdef(it.val))
|
||||
g.writeln('// #if $it.val')
|
||||
}
|
||||
// println('comp if stmts $g.file.path:$it.pos.line_nr')
|
||||
g.stmts(it.stmts)
|
||||
if it.has_else {
|
||||
|
@ -2025,6 +2031,9 @@ fn comp_if_to_ifdef(name string) string {
|
|||
'mingw' {
|
||||
return '__MINGW32__'
|
||||
}
|
||||
'glibc' {
|
||||
return '__GLIBC__'
|
||||
}
|
||||
'no_bounds_checking' {
|
||||
return 'NO_BOUNDS_CHECK'
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ pub fn (p mut Parser) comp_if() ast.CompIf {
|
|||
pos := p.tok.position()
|
||||
p.next()
|
||||
p.check(.key_if)
|
||||
if p.tok.kind == .not {
|
||||
is_not := p.tok.kind == .not
|
||||
if is_not {
|
||||
p.next()
|
||||
}
|
||||
val := p.check_name()
|
||||
|
@ -16,6 +17,7 @@ pub fn (p mut Parser) comp_if() ast.CompIf {
|
|||
p.next()
|
||||
}
|
||||
mut node := ast.CompIf{
|
||||
is_not: is_not
|
||||
stmts: p.parse_block()
|
||||
pos: pos
|
||||
val: val
|
||||
|
|
|
@ -205,7 +205,7 @@ pub const (
|
|||
pub const (
|
||||
builtin_type_names = ['void', 'voidptr', 'charptr', 'byteptr', 'i8', 'i16', 'int', 'i64', 'u16', 'u32', 'u64',
|
||||
'f32', 'f64', 'string', 'char', 'byte', 'bool', 'none', 'array', 'array_fixed', 'map', 'struct',
|
||||
'mapnode', 'ustring']
|
||||
'mapnode', 'ustring', 'size_t']
|
||||
)
|
||||
|
||||
pub struct MultiReturn {
|
||||
|
@ -411,6 +411,10 @@ pub fn (t mut Table) register_builtin_type_symbols() {
|
|||
kind: .map
|
||||
name: 'map'
|
||||
})
|
||||
t.register_type_symbol(TypeSymbol{
|
||||
kind: .placeholder
|
||||
name: 'size_t'
|
||||
})
|
||||
// TODO: remove. for v1 map compatibility
|
||||
map_string_string_idx := t.find_or_register_map(string_type, string_type)
|
||||
map_string_int_idx := t.find_or_register_map(string_type, int_type)
|
||||
|
|
|
@ -470,6 +470,15 @@ pub fn (t &Table) check(got, expected Type) bool {
|
|||
&& (got_idx in pointer_type_idxs || got_idx in number_type_idxs) {
|
||||
return true
|
||||
}
|
||||
// see hack in checker IndexExpr line #691
|
||||
if (got_idx == byte_type_idx && exp_idx == byteptr_type_idx) //
|
||||
|| (exp_idx == byte_type_idx && got_idx == byteptr_type_idx) {
|
||||
return true
|
||||
}
|
||||
if (got_idx == char_type_idx && exp_idx == charptr_type_idx) //
|
||||
|| (exp_idx == char_type_idx && got_idx == charptr_type_idx) {
|
||||
return true
|
||||
}
|
||||
// # NOTE: use symbols from this point on for perf
|
||||
got_type_sym := t.get_type_symbol(got)
|
||||
exp_type_sym := t.get_type_symbol(expected)
|
||||
|
@ -477,11 +486,6 @@ pub fn (t &Table) check(got, expected Type) bool {
|
|||
if (got_type_sym.is_int() && exp_type_sym.kind == .enum_) || (exp_type_sym.is_int() && got_type_sym.kind == .enum_) {
|
||||
return true
|
||||
}
|
||||
// TODO: actually check for & handle pointers with name_expr
|
||||
// see hack in checker IndexExpr line #691
|
||||
if (got_type_sym.kind == .byte && exp_type_sym.kind == .byteptr) || (exp_type_sym.kind == .byte && got_type_sym.kind == .byteptr) {
|
||||
return true
|
||||
}
|
||||
// TODO
|
||||
// if got_type_sym.kind == .array && exp_type_sym.kind == .array {
|
||||
// return true
|
||||
|
|
Loading…
Reference in New Issue