os: fix get_raw_line() + minor v2 fixes

pull/3871/head
Alexander Medvednikov 2020-02-28 14:05:20 +01:00
parent c4b9ef388f
commit 7f5a15372f
6 changed files with 31 additions and 13 deletions

View File

@ -24,7 +24,7 @@ bmark.stop() // call when you want to finalize the benchmark
println( bmark.total_message('remarks about the benchmark') )
```
benchmark.start() and b.measure() are convenience methods,
benchmark.start() and b.measure() are convenience methods,
intended to be used in combination. Their goal is to make
benchmarking of small snippets of code as *short*, easy to
write, and then to read and analyze the results, as possible.

View File

@ -704,14 +704,15 @@ pub fn get_raw_line() string {
}
} $else {
max := size_t(0)
mut buf := byteptr(0)
nr_chars := C.getline(&charptr(buf), &max, stdin)
defer { unsafe{ free(buf) } }
mut buf := charptr(0)
nr_chars := C.getline(&buf, &max, stdin)
//defer { unsafe{ free(buf) } }
if nr_chars == 0 || nr_chars == -1 {
return ''
}
res := tos_clone( buf )
return res
return tos3(buf)
//res := tos_clone(buf)
//return res
}
}

View File

@ -12,7 +12,7 @@ import (
)
const (
max_nr_errors = 30
max_nr_errors = 50
)
pub struct Checker {

View File

@ -15,6 +15,7 @@ pub struct Eval {
mut:
checker checker.Checker
vars map[string]Var
table &table.Table
}
pub struct Var {
@ -22,6 +23,7 @@ pub struct Var {
}
pub fn (e mut Eval) eval(file ast.File, table &table.Table) string {
e.table = table
mut res := ''
e.checker = checker.new_checker(table)
for stmt in file.stmts {
@ -61,6 +63,9 @@ fn (e mut Eval) stmt(node ast.Stmt) string {
print_object(o)
return o.str()
}
// ast.StructDecl {
// println('s decl')
// }
ast.VarDecl {
e.vars[it.name] = Var{
value: e.expr(it.expr)

View File

@ -762,7 +762,7 @@ pub fn (p mut Parser) expr(precedence int) (ast.Expr,table.Type) {
p.check(.rcbr)
}
else {
p.error('pexpr(): bad token `$p.tok.str()`')
p.error('parser: expr(): bad token `$p.tok.str()`')
}
}
// Infix

View File

@ -10,8 +10,11 @@ import (
)
fn test_eval() {
/*
inputs := [
//
'2+2',
'struct User { age int }',
'2+3',
'4',
'x := 10',
@ -32,9 +35,11 @@ fn test_eval() {
'20',
//
]
/*
table := table.new_table()
mut scope := &ast.Scope{start_pos: 0, parent: 0}
mut scope := &ast.Scope{
start_pos: 0
parent: 0
}
mut stmts := []ast.Stmt
for input in inputs {
stmts << parse_stmt(input, table, scope)
@ -50,8 +55,9 @@ fn test_eval() {
println('eval done')
println(s)
assert s == expected.join('\n')
// exit(0)
exit(0)
*/
return
}
fn test_parse_file() {
@ -87,7 +93,10 @@ fn test_one() {
]
expected := 'int a = 10;int b = -a;int c = 20;'
table := table.new_table()
mut scope := &ast.Scope{start_pos: 0, parent: 0}
mut scope := &ast.Scope{
start_pos: 0
parent: 0
}
mut e := []ast.Stmt
for line in input {
e << parse_stmt(line, table, scope)
@ -179,7 +188,10 @@ fn test_parse_expr() {
mut e := []ast.Stmt
table := table.new_table()
mut checker := checker.new_checker(table)
mut scope := &ast.Scope{start_pos: 0, parent: 0}
mut scope := &ast.Scope{
start_pos: 0
parent: 0
}
for s in input {
println('\n\nst="$s"')
e << parse_stmt(s, table, scope)