eval: small cleanup in the handling of `$if platform {`

master
Delyan Angelov 2022-04-28 13:15:09 +03:00
parent e0ed8f8278
commit 4538efd8f4
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
2 changed files with 16 additions and 29 deletions

View File

@ -117,7 +117,6 @@ pub fn (mut e Eval) register_symbols(mut files []&ast.File) {
for mut file in files { for mut file in files {
file.idx = e.trace_file_paths.len file.idx = e.trace_file_paths.len
e.trace_file_paths << file.path e.trace_file_paths << file.path
// eprintln('registering file: $file.path_base')
mod := file.mod.name mod := file.mod.name
for mut stmt in file.stmts { for mut stmt in file.stmts {
if mut stmt is ast.FnDecl { if mut stmt is ast.FnDecl {
@ -205,7 +204,7 @@ pub fn (mut e Eval) register_symbol(stmt ast.Stmt, mod string, file string) {
} }
} }
else { else {
eprintln('unsupported expression') e.error('unsupported expression')
} }
} }
} }
@ -223,9 +222,10 @@ pub fn (mut e Eval) register_symbol(stmt ast.Stmt, mod string, file string) {
fn (e Eval) error(msg string) { fn (e Eval) error(msg string) {
eprintln('> V interpeter backtrace:') eprintln('> V interpeter backtrace:')
for idx, t in e.back_trace { for t in e.back_trace {
eprintln(' ${e.trace_file_paths[t.file_idx]}:${t.line + 1}:${e.trace_function_names[t.fn_idx]}') file_path := e.trace_file_paths[t.file_idx] or { t.file_idx.str() }
// eprintln('${e.trace_file_paths[t.file_idx]}:${t.line + 1}:$t.fn_idx') fn_name := e.trace_function_names[t.fn_idx] or { t.fn_idx.str() }
eprintln(' $file_path:${t.line + 1}:$fn_name}')
} }
util.verror('interpreter', msg) util.verror('interpreter', msg)
} }

View File

@ -1,5 +1,6 @@
module eval module eval
import v.pref
import v.ast import v.ast
import v.util import v.util
import math import math
@ -134,30 +135,16 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
do_if = true do_if = true
} else { } else {
if branch.cond is ast.Ident { if branch.cond is ast.Ident {
match branch.cond.name { if known_os := pref.os_from_string(branch.cond.name) {
'windows' { do_if = e.pref.os == known_os
do_if = e.pref.os == .windows } else {
} match branch.cond.name {
'macos' { 'prealloc' {
do_if = e.pref.os == .macos do_if = e.pref.prealloc
} }
'linux' { else {
do_if = e.pref.os == .linux e.error('unknown compile time if: $branch.cond.name')
} }
'android' {
do_if = e.pref.os == .android
}
'freebsd' {
do_if = e.pref.os == .freebsd
}
'openbsd' {
do_if = e.pref.os == .openbsd
}
'prealloc' {
do_if = e.pref.prealloc
}
else {
e.error('unknown compile time if: $branch.cond.name')
} }
} }
} else if branch.cond is ast.PostfixExpr { } else if branch.cond is ast.PostfixExpr {