cgen: GotoStmt, err variable

pull/4116/head
Alexander Medvednikov 2020-03-25 17:24:55 +01:00
parent 26fab9b274
commit 7070b1cda9
2 changed files with 9 additions and 4 deletions

View File

@ -178,16 +178,16 @@ pub fn cp_all(osource_path, odest_path string, overwrite bool) ?bool {
}
// single file copy
if !os.is_dir(source_path) {
adjasted_path := if os.is_dir(dest_path) { os.join_path(dest_path,os.file_name(source_path)) } else { dest_path }
if os.exists(adjasted_path) {
adjusted_path := if os.is_dir(dest_path) {os.join_path(dest_path,os.file_name(source_path)) } else { dest_path }
if os.exists(adjusted_path) {
if overwrite {
os.rm(adjasted_path)
os.rm(adjusted_path)
}
else {
return error('Destination file path already exist')
}
}
os.cp(source_path, adjasted_path) or {
os.cp(source_path, adjusted_path) or {
return error(err)
}
return true

View File

@ -438,6 +438,9 @@ fn (g mut Gen) stmt(node ast.Stmt) {
ast.GotoLabel {
g.writeln('$it.name:')
}
ast.GotoStmt {
g.writeln('goto $it.name;')
}
ast.HashStmt {
// #include etc
typ := it.val.all_before(' ')
@ -2081,6 +2084,8 @@ fn (g mut Gen) call_expr(it ast.CallExpr) {
// `foo() or { return }`
g.writeln(';') // or')
g.writeln('if (!${g.expr_var_name}.ok) {')
g.writeln('string err = ${g.expr_var_name}.v_error;')
g.writeln('int errcode = ${g.expr_var_name}.ecode;')
g.stmts(it.or_block.stmts)
g.writeln('}')
}