v2: minor fixes

pull/3699/head
Alexander Medvednikov 2020-02-07 21:29:28 +01:00
parent 99217da6ca
commit f782388148
4 changed files with 33 additions and 10 deletions

View File

@ -368,10 +368,10 @@ pub fn (b []byte) hex() string {
mut ptr := &hex[0]
for i := 0; i < b.len; i++ {
// QTODO
ptr += C.sprintf(ptr as charptr, '%02x', b[i])
ptr += C.sprintf(ptr, '%02x', b[i])
}
return hex as string
//return string(hex)
//return hex as string
return string(hex)
}
// copy copies the `src` byte array elements to the `dst` byte array.

View File

@ -64,7 +64,7 @@ fn print_backtrace_skipping_top_frames_mac(skipframes int) bool {
$if macos {
buffer := [100]byteptr
nr_ptrs := C.backtrace(buffer, 100)
C.backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 1)
backtrace_symbols_fd(&buffer[skipframes], nr_ptrs - skipframes, 1)
}
return true
}

View File

@ -157,7 +157,7 @@ pub fn (c &Checker) call_expr(call_expr ast.CallExpr) table.TypeRef {
c.error('too few arguments in call to `$fn_name`', call_expr.pos)
}
else if call_expr.args.len > f.args.len {
c.error('too many arguments in call to `$fn_name`', call_expr.pos)
c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos)
}
}
for i, arg in f.args {
@ -206,6 +206,7 @@ pub fn (c &Checker) selector_expr(selector_expr ast.SelectorExpr) table.TypeRef
return c.table.type_ref(table.int_type_idx)
}
}
.string {}
else {
c.error('`$typ.typ.name` is not a struct', selector_expr.pos)
}

View File

@ -466,13 +466,35 @@ pub fn (p mut Parser) name_expr() (ast.Expr,table.TypeRef) {
p.check_name()
return node,typ
}
// fn call
// fn call or type cast
if p.peek_tok.kind == .lpar {
name := p.tok.lit
// type cast. TODO: finish
if name in p.table.type_idxs {
// ['byte', 'string', 'int']
// SKIP FOR NOW
mut par_d := 0
for {
if p.tok.kind == .lpar {
par_d++
}
if p.tok.kind == .rpar {
par_d--
if par_d == 0 {
p.next()
break
}
}
p.next()
}
}
else {
println('calling $p.tok.lit')
x,ti2 := p.call_expr() // TODO `node,typ :=` should work
node = x
typ = ti2
}
}
// struct init
else if p.peek_tok.kind == .lcbr && (p.tok.lit[0].is_capital() || p.tok.lit in ['array', 'string', 'ustring', 'mapnode', 'map']) && !p.tok.lit[p.tok.lit.len - 1].is_capital() {
// || p.table.known_type(p.tok.lit)) {