mirror of
https://github.com/bearlanguageorg/bear.git
synced 2026-08-26 14:57:18 +00:00
Executable vrmm
This commit is contained in:
@@ -106,6 +106,31 @@ A target that returns a nonzero integer, calls `exit(n)` with `n > 0`, or
|
|||||||
`throw`s fails the build. Paths are relative to the working directory;
|
`throw`s fails the build. Paths are relative to the working directory;
|
||||||
`build_root()` returns the module's own directory for absolute paths.
|
`build_root()` returns the module's own directory for absolute paths.
|
||||||
|
|
||||||
|
### Running build modules as scripts
|
||||||
|
|
||||||
|
A `.vrmm` (or `.vr`) file may start with a shebang line so it can be executed
|
||||||
|
directly like any script — the toolchain skips the shebang when compiling, so
|
||||||
|
error line numbers stay aligned with the file:
|
||||||
|
|
||||||
|
```
|
||||||
|
#!/usr/bin/env vr
|
||||||
|
fn main() {
|
||||||
|
build_compile("main.vr", "main.vobj")
|
||||||
|
build_link(["main.vobj"], "main.vbin")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x build.vrmm
|
||||||
|
./build.vrmm # equivalent to: vr make
|
||||||
|
./build.vrmm clean # run the clean() target
|
||||||
|
./build.vrmm deploy --prod
|
||||||
|
```
|
||||||
|
|
||||||
|
The kernel invokes `vr <script> [args...]`; the toolchain routes an existing
|
||||||
|
`.vrmm` path to `vr make -f <file>` and an existing `.vr` path to
|
||||||
|
`vr run <file>`, so `vr myprog.vr` also just works.
|
||||||
|
|
||||||
Build builtins:
|
Build builtins:
|
||||||
|
|
||||||
| builtin | description |
|
| builtin | description |
|
||||||
|
|||||||
+9
-1
@@ -2,7 +2,15 @@
|
|||||||
module compiler
|
module compiler
|
||||||
|
|
||||||
pub fn tokenize(src string) ![]Tok {
|
pub fn tokenize(src string) ![]Tok {
|
||||||
mut l := Lexer{ src: src, line: 1 }
|
// a script may start with a shebang line (#!...) so it can be executed
|
||||||
|
// directly (e.g. `#!/usr/bin/env vr`). Drop it, but keep the trailing
|
||||||
|
// newline so error line numbers stay aligned with the file on disk.
|
||||||
|
mut s := src
|
||||||
|
if s.starts_with('#!') {
|
||||||
|
nl := s.index('\n') or { s.len }
|
||||||
|
s = s[nl..]
|
||||||
|
}
|
||||||
|
mut l := Lexer{ src: s, line: 1 }
|
||||||
mut toks := []Tok{}
|
mut toks := []Tok{}
|
||||||
for {
|
for {
|
||||||
t := l.next()!
|
t := l.next()!
|
||||||
|
|||||||
Regular → Executable
+2
@@ -1,6 +1,8 @@
|
|||||||
|
#!/usr/bin/env vr
|
||||||
// build.vrmm — a VuurRaaf Make Module: build instructions for the toolchain,
|
// build.vrmm — a VuurRaaf Make Module: build instructions for the toolchain,
|
||||||
// written in VuurRaaf itself (like V's .vsh, but for this language).
|
// written in VuurRaaf itself (like V's .vsh, but for this language).
|
||||||
//
|
//
|
||||||
|
// ./examples/build.vrmm run directly (after chmod +x)
|
||||||
// ./bin/vr make -f examples/build.vrmm build + run hello
|
// ./bin/vr make -f examples/build.vrmm build + run hello
|
||||||
// ./bin/vr make -f examples/build.vrmm multi compile/link/run a 2-file program
|
// ./bin/vr make -f examples/build.vrmm multi compile/link/run a 2-file program
|
||||||
// ./bin/vr make -f examples/build.vrmm test run tests.vr
|
// ./bin/vr make -f examples/build.vrmm test run tests.vr
|
||||||
|
|||||||
@@ -113,6 +113,21 @@ fn main() {
|
|||||||
toolchain_unloader()
|
toolchain_unloader()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// direct script execution — this is what makes shebangs work:
|
||||||
|
// `#!/usr/bin/env vr` has the kernel call `vr <script> [args...]`,
|
||||||
|
// so route an existing .vrmm/.vr file to make/run accordingly
|
||||||
|
if os.exists(cmd) && cmd.ends_with('.vrmm') {
|
||||||
|
mut m := ['-f', cmd]
|
||||||
|
m << args[1..]
|
||||||
|
toolchain_make(m) or { die('make', err) }
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if os.exists(cmd) && cmd.ends_with('.vr') {
|
||||||
|
mut r := [cmd]
|
||||||
|
r << args[1..]
|
||||||
|
toolchain_run(r) or { die('run', err) }
|
||||||
|
return
|
||||||
|
}
|
||||||
eprintln('vr: unknown command "${cmd}"')
|
eprintln('vr: unknown command "${cmd}"')
|
||||||
eprintln("run 'vr help' for usage")
|
eprintln("run 'vr help' for usage")
|
||||||
exit(1)
|
exit(1)
|
||||||
@@ -183,6 +198,8 @@ fn toolchain_help() {
|
|||||||
println(' make [target] [args...] run build.vrmm (target = main)')
|
println(' make [target] [args...] run build.vrmm (target = main)')
|
||||||
println(' make -f <file.vrmm> [target] [args...] run another build module (.vrmm)')
|
println(' make -f <file.vrmm> [target] [args...] run another build module (.vrmm)')
|
||||||
println(' build alias for make')
|
println(' build alias for make')
|
||||||
|
println(' <script.vrmm> [target] [args...] run a build module directly (shebang)')
|
||||||
|
println(' <file.vr> [args...] run a program directly (shebang)')
|
||||||
println(' clean remove build artifacts')
|
println(' clean remove build artifacts')
|
||||||
println(' up rebuild the vr binary into bin/')
|
println(' up rebuild the vr binary into bin/')
|
||||||
println(' symlink link bin/vr into your PATH')
|
println(' symlink link bin/vr into your PATH')
|
||||||
|
|||||||
Reference in New Issue
Block a user