Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/tools/vself.v
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module main

import os
import os.cmdline
import v.pref
import v.util.recompilation

const args_ = arguments()
Expand All @@ -10,7 +11,7 @@ const is_debug = args_.contains('-debug')
// support a renamed `v` executable too:
const vexe = os.getenv_opt('VEXE') or { @VEXE }

const vroot = os.dir(vexe)
const vroot = pref.vroot_from_vexe(vexe)
const vself_flags_with_values = ['-o', '-os', '-cc', '-gc', '-cf', '-cflags', '-d', '-define']

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion vlib/v/parser/enum.v
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn (mut p Parser) enum_decl() ast.EnumDecl {
}
isb.write_string(' match val {\n')
for f in fields {
isb.write_string(' \'${f.name}\' { return ${enum_name}.${f.source_name} }\n')
isb.write_string(" '${f.name}' { return ${enum_name}.${f.source_name} }\n")
}
isb.write_string(' else{}\n')
isb.write_string(' }\n')
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/parser/expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr {
if p.prev_tok.kind.is_assign() {
is_expr = true
}
return p.if_expr(true, is_expr)
node = p.if_expr(true, is_expr)
}
.key_match {
return p.match_expr(true, p.prev_tok.kind.is_assign())
node = p.match_expr(true, p.prev_tok.kind.is_assign())
}
else {
return p.unexpected_with_pos(p.peek_tok.pos(),
Expand Down
39 changes: 37 additions & 2 deletions vlib/v/pref/default.v
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn (p &Preferences) is_linux_wayland_only_session() bool {
fn (mut p Preferences) expand_lookup_paths() {
if p.vroot == '' {
// Location of all vlib files
p.vroot = os.dir(vexe_path())
p.vroot = vroot_from_vexe(vexe_path())
}
p.vlib = os.join_path(p.vroot, 'vlib')
p.vmodules_paths = os.vmodules_paths()
Expand Down Expand Up @@ -486,7 +486,7 @@ fn usable_bundled_tcc_compiler(vroot string) string {
// default_tcc_compiler returns the preferred TinyCC path when it exists and works on the host.
pub fn default_tcc_compiler() string {
vexe := vexe_path()
vroot := os.dir(vexe)
vroot := vroot_from_vexe(vexe)
bundled_tcc := usable_bundled_tcc_compiler(vroot)
if bundled_tcc != '' {
return bundled_tcc
Expand Down Expand Up @@ -622,6 +622,41 @@ pub fn vexe_path() string {
return real_vexe_path
}

fn is_vroot_dir(dir string) bool {
return dir.len > 0 && os.is_dir(os.join_path(dir, 'vlib', 'builtin'))
}

// vroot_from_dir returns the nearest parent source root containing `vlib/builtin`.
pub fn vroot_from_dir(start string) string {
if start.len == 0 {
return start
}
mut dir := start
if !os.is_abs_path(dir) {
dir = os.abs_path(dir)
}
if !os.is_dir(dir) {
dir = os.dir(dir)
}
original_dir := dir
for {
if is_vroot_dir(dir) {
return os.real_path(dir)
}
parent := os.dir(dir)
if parent == dir || parent.len == 0 {
return original_dir
}
dir = parent
}
return original_dir
}

// vroot_from_vexe returns the source root for a compiler executable path.
pub fn vroot_from_vexe(vexe string) string {
return vroot_from_dir(resolve_vexe_path(vexe))
}

pub fn (p &Preferences) vcross_linker_name() string {
vlname := os.getenv('VCROSS_LINKER_NAME')
if vlname != '' {
Expand Down
4 changes: 2 additions & 2 deletions vlib/v/util/util.v
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub fn is_escape_sequence(c u8) bool {
@[noreturn]
pub fn launch_tool(is_verbose bool, tool_name string, args []string) {
vexe := pref.vexe_path()
vroot := os.dir(vexe)
vroot := pref.vroot_from_vexe(vexe)
set_vroot_folder(vroot)
tool_args := args_quote_paths(args)
tools_folder := os.join_path(vroot, 'cmd', 'tools')
Expand Down Expand Up @@ -588,7 +588,7 @@ pub fn no_cur_mod(typename string, cur_mod string) string {

pub fn prepare_tool_when_needed(source_name string) {
vexe := os.getenv('VEXE')
vroot := os.dir(vexe)
vroot := pref.vroot_from_vexe(vexe)
stool := os.join_path(vroot, 'cmd', 'tools', source_name)
tool_name, tool_exe := tool_source2name_and_exe(stool)
if should_recompile_tool(vexe, stool, tool_name, tool_exe) {
Expand Down
3 changes: 1 addition & 2 deletions vlib/v3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ source to binary uses no external tools.
| type checker | 974 |
| universe | 97 |
| scopes | 34 |
| C gen (AST) | 669 |
| SSA IR+build | 1,510 |
| SSA optimize | 474 |
| ARM64 gen | 873 |
Expand All @@ -138,7 +137,7 @@ source to binary uses no external tools.
| scanner | 593 |
| token | 338 |
| bench | 81 |
| **total** | **~18,300** |
| **total** | **~16,300** |

## Performance

Expand Down
Loading
Loading