mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 15:37:18 +00:00
stdlin
This commit is contained in:
+11
-4
@@ -4,6 +4,10 @@ module compiler
|
||||
import os
|
||||
import obj
|
||||
|
||||
// stdlib_dir is the toolchain's bundled library (lib/*.vr), resolved at build
|
||||
// time so `import os` works from any working directory.
|
||||
const stdlib_dir = @VMODROOT + '/lib'
|
||||
|
||||
// compile parses and compiles VuurRaaf source into an object file.
|
||||
pub fn compile(src string) !obj.Obj {
|
||||
toks := tokenize(src)!
|
||||
@@ -19,16 +23,19 @@ pub fn compile_file(path string) !obj.Obj {
|
||||
}
|
||||
|
||||
// resolve_import turns an import path into a readable source file. It tries
|
||||
// the path as given first, then falls back to the package-manager layout so
|
||||
// `import "pkg/file.vr"` finds vendor/pkg/file.vr.
|
||||
// the path as given first, then the package-manager layout (vendor/) and the
|
||||
// toolchain's own standard library (lib/), so both `import "pkg/file.vr"`
|
||||
// and the bare module form `import os` resolve from anywhere.
|
||||
pub fn resolve_import(path string) !string {
|
||||
if os.exists(path) {
|
||||
return path
|
||||
}
|
||||
for cand in ['vendor/${path}', 'vendor/${path}.vr', 'vendor/${path}/main.vr', 'vendor/${path}/src/main.vr'] {
|
||||
for cand in ['vendor/${path}', 'vendor/${path}.vr', 'vendor/${path}/main.vr',
|
||||
'vendor/${path}/src/main.vr', os.join_path(stdlib_dir, path + '.vr'),
|
||||
os.join_path(stdlib_dir, path, 'main.vr')] {
|
||||
if os.exists(cand) {
|
||||
return cand
|
||||
}
|
||||
}
|
||||
return error('cannot resolve import "${path}" (tried vendor/)"')
|
||||
return error('cannot resolve import "${path}" (tried vendor/ and lib/)')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user