1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v: split the interpreter to cmd/tools/vinterpret.v

This commit is contained in:
Delyan Angelov
2021-12-11 23:51:42 +02:00
parent adf353702e
commit 9b7a50b1a2
8 changed files with 111 additions and 88 deletions

View File

@ -98,7 +98,7 @@ fn (app App) gen_api_for_module_in_os(mod_name string, os_name string) string {
tmpname := '/tmp/${mod_name}_${os_name}.c'
prefs, _ := pref.parse_args([], ['-os', os_name, '-o', tmpname, '-shared', mpath])
mut b := builder.new_builder(prefs)
b.compile_c()
builder.compile_c(mut b)
mut res := []string{}
for f in b.parsed_files {
for s in f.stmts {

24
cmd/tools/vinterpret.v Normal file
View File

@ -0,0 +1,24 @@
module main
import v.pref
import v.eval
import v.util
import v.builder
fn main() {
mut args_and_flags := util.join_env_vflags_and_os_args()[1..].filter(it != 'interpret')
prefs, _ := pref.parse_args([], args_and_flags)
builder.compile('interpret', prefs, v_interpret)
}
fn v_interpret(mut b builder.Builder) {
mut files := b.get_builtin_files()
files << b.get_user_files()
b.set_module_lookup_paths()
b.front_and_middle_stages(files) or { return }
util.timing_start('INTERPRET')
mut e := eval.new_eval(b.table, b.pref)
e.eval(b.parsed_files)
util.timing_measure('INTERPRET')
}

View File

@ -27,6 +27,7 @@ const (
'doctor',
'fmt',
'gret',
'interpret',
'repl',
'self',
'setup-freetype',
@ -61,10 +62,9 @@ fn main() {
timers.show('v start')
timers.start('parse_CLI_args')
args := os.args[1..]
// args = 123
if args.len == 0 || args[0] in ['-', 'repl'] {
// Running `./v` without args launches repl
if args.len == 0 {
// Running `./v` without args launches repl
if os.is_atty(0) != 0 {
cmd_exit := term.highlight_command('exit')
cmd_help := term.highlight_command('v help')
@ -125,11 +125,26 @@ fn main() {
}
else {}
}
if command in ['run', 'build', 'build-module', 'interpret'] || command.ends_with('.v')
|| os.exists(command) {
if command in ['run', 'build', 'build-module'] || command.ends_with('.v') || os.exists(command) {
// println('command')
// println(prefs.path)
builder.compile(command, prefs)
backend_cb := match prefs.backend {
.c {
builder.FnBackend(builder.compile_c)
}
.js_node, .js_freestanding, .js_browser {
builder.compile_js
}
.native {
builder.compile_native
}
.interpret {
eprintln('use `v interpret file.v`')
exit(1)
builder.compile_c
}
}
builder.compile(command, prefs, backend_cb)
return
}
if prefs.is_help {