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

Delyan Angelov 2022-04-28 13:15:09 +03:00 committed by Jef Roosens
parent 705e260180
commit 47dccd56a2
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
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,25 +135,10 @@ 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 {
if known_os := pref.os_from_string(branch.cond.name) {
do_if = e.pref.os == known_os
} else {
match branch.cond.name { match branch.cond.name {
'windows' {
do_if = e.pref.os == .windows
}
'macos' {
do_if = e.pref.os == .macos
}
'linux' {
do_if = e.pref.os == .linux
}
'android' {
do_if = e.pref.os == .android
}
'freebsd' {
do_if = e.pref.os == .freebsd
}
'openbsd' {
do_if = e.pref.os == .openbsd
}
'prealloc' { 'prealloc' {
do_if = e.pref.prealloc do_if = e.pref.prealloc
} }
@ -160,6 +146,7 @@ pub fn (mut e Eval) expr(expr ast.Expr, expecting ast.Type) Object {
e.error('unknown compile time if: $branch.cond.name') e.error('unknown compile time if: $branch.cond.name')
} }
} }
}
} else if branch.cond is ast.PostfixExpr { } else if branch.cond is ast.PostfixExpr {
do_if = (branch.cond.expr as ast.Ident).name in e.pref.compile_defines do_if = (branch.cond.expr as ast.Ident).name in e.pref.compile_defines
} }