native: define println and exit builtins or verror()

pull/9900/head
pancake 2021-04-26 23:43:00 +02:00 committed by Delyan Angelov
parent 1eac6eee59
commit a31a1eb9cb
2 changed files with 12 additions and 3 deletions

View File

@ -12,6 +12,7 @@ import v.pref
import v.util
import v.errors
import v.pkgconfig
import v.gen.native
const int_min = int(0x80000000)
@ -2069,7 +2070,14 @@ pub fn (mut c Checker) fn_call(mut call_expr ast.CallExpr) ast.Type {
c.table.fns[fn_name].usages++
}
}
if c.pref.is_script && !found {
if !found && c.pref.backend == .native {
if fn_name in native.builtins {
found = true
c.table.fns[fn_name].usages++
return ast.string_type
}
}
if !found && c.pref.is_script && !found {
os_name := 'os.$fn_name'
if f := c.table.find_fn(os_name) {
if f.generic_names.len == call_expr.concrete_types.len {

View File

@ -11,6 +11,8 @@ import v.errors
import v.pref
import term
pub const builtins = ['println', 'exit']
interface CodeGen {
g Gen
allocate_var(name string, size int, initial_val int)
@ -70,8 +72,7 @@ pub fn gen(files []ast.File, table &ast.Table, out_name string, pref &pref.Prefe
eprintln('Warning: ${file.warnings[0]}')
}
if file.errors.len > 0 {
eprintln('Error ${file.errors[0]}')
// verror('Error ${file.errors[0]}')
verror('Error ${file.errors[0]}')
}
g.stmts(file.stmts)
}