Skip to content

Commit 9eb2e5b

Browse files
authored
Merge branch 'main' into vm-module-memory
2 parents f7b1d02 + b138156 commit 9eb2e5b

File tree

3 files changed

+66
-63
lines changed

3 files changed

+66
-63
lines changed

.github/workflows/build_and_test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ jobs:
8282
run: nim c -d:nimStrictMode --outdir:bin koch.nim
8383

8484
- name: Build all programs
85-
run: bin/koch all -d:nimStrictMode -d:release
85+
run: bin/koch build all-ws -d:nimStrictMode -d:release
8686

8787
# use a debug build (with optimizations enabled) for testing, in order
8888
# to better catch bugs
8989
- name: Build `phy` for testing
90-
run: bin/koch single phy --opt:speed
90+
run: bin/koch build phy --opt:speed
9191

9292
- name: "Run tests"
9393
run: bin/tester
@@ -118,7 +118,7 @@ jobs:
118118
run: bin/koch build-defs
119119

120120
- name: Build passtool
121-
run: bin/koch single passtool -d:nimStrictMode -d:release
121+
run: bin/koch build passtool -d:nimStrictMode -d:release
122122

123123
# run the passtool for the highest-level language:
124124
- name: "Check the IL grammar"
@@ -148,10 +148,10 @@ jobs:
148148
run: nim c -d:nimStrictMode --outdir:bin koch.nim
149149

150150
- name: Build phy
151-
run: bin/koch single phy -d:release
151+
run: bin/koch build phy -d:release
152152

153153
- name: Build skully
154-
run: bin/koch single skully -d:nimStrictMode -d:release
154+
run: bin/koch build skully -d:nimStrictMode -d:release
155155

156156
- name: Compile phy to L25 code with skully
157157
run: bin/skully phy/phy.nim build/phy.txt

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ with the minimum required version found [here](https://github.com/nim-works/phy/
1414
To get everything built, run the following from the command line
1515

1616
```cmd
17-
nim c --outdir:bin -r koch.nim all
17+
nim c --outdir:bin -r koch.nim build all
1818
```
1919

2020
The above will:

koch.nim

Lines changed: 60 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,22 @@ Options:
1212
--nim:path use the specified NimSkull compiler
1313
1414
Commands:
15-
all [args] builds all programs
16-
single <name> [args] builds the single program with the given name
17-
generate [dir] generates the various language-related modules
15+
build <program> [<arg> ...] builds a program, using the given compiler args
16+
build all [<arg> ...] builds all programs
17+
generate <dir> generates the various language-related modules
1818
build-defs verifies the language definitions and generates
1919
the textual representation for them
2020
"""
21-
Programs: seq[(string, string, bool, bool)] = @[
22-
("tester", "tools/tester.nim", true, true),
23-
("passtool", "tools/passtool/passtool.nim", true, true),
24-
("queryshell", "phy/queryshell.nim", true, true),
25-
("repl", "phy/repl.nim", false, true),
26-
("phy", "phy/phy.nim", false, true),
27-
("skully", "skully/skully.nim", true, false)
28-
# ^^ excluded from 'all' because the program takes too long to compile
29-
]
30-
## program name, module path, whether the program doesn't depend on
31-
## generated modules, and whether the program is built with 'all'
21+
Programs = {
22+
"tester" : ("tools/tester.nim", true),
23+
"passtool" : ("tools/passtool/passtool.nim", true),
24+
"queryshell" : ("phy/queryshell.nim", true),
25+
"repl" : ("phy/repl.nim", false),
26+
"phy" : ("phy/phy.nim", false),
27+
"skully" : ("skully/skully.nim", true),
28+
}.toOrderedTable
29+
## program name, module path, and whether the program doesn't depend on
30+
## generated modules
3231

3332
DefaultGenerated = "generated"
3433
## the default path for the generated modules
@@ -86,52 +85,43 @@ proc generateModules(dir: string) =
8685
require run(passtool, "gen-checks", "languages", "specification",
8786
"passes/syntax_source", dir / "source_checks.nim")
8887

89-
proc buildSingle(args: string): bool
88+
proc build(name: string, args: openArray[string])
9089

9190
proc regenerate() =
9291
## Makes sure the generated modules are up-to-date.
9392
if not dirExists(DefaultGenerated):
9493
# assume that the 'generated' folder existing means that it's up-to-date.
95-
# This is usually *not* correct, but it's the simplest heuristic we have
96-
discard buildSingle("passtool -d:release")
94+
# This is usually *not* correct, but it's the simplest heuristic there is
95+
build("passtool", ["-d:release"])
9796
generateModules(DefaultGenerated)
9897

9998
# command implementations:
10099

101-
proc buildSingle(args: string): bool =
102-
## Builds the single program specified by `args`.
103-
var args = args.saneSplit()
104-
if args.len == 0:
105-
return false # not enough arguments, show the help
106-
107-
let progName = args[0]
108-
args.delete(0)
109-
110-
result = true
111-
112-
for (name, path, standalone, _) in Programs.items:
113-
if name == progName:
114-
if not standalone:
115-
# depends on some generated modules; first make sure they're
116-
# up-to-date
117-
regenerate()
118-
119-
if not compile(getCurrentDir() / path, name, args):
120-
echo "Failure"
121-
quit(1)
122-
return
123-
124-
# report a "not found" error
125-
echo "no program with name: '", progName, "' exists. Candidates are:"
126-
echo " ", mapIt(Programs, it[0]).join(", ")
127-
quit(1)
100+
proc build(name: string, args: openArray[string]) =
101+
## Builds the program identified by `name`, passing `args` along to
102+
## the compiler.
103+
if name in Programs:
104+
let (path, standalone) = Programs[name]
105+
if not standalone:
106+
# depends on some generated modules; first make sure they're
107+
# up-to-date
108+
regenerate()
109+
110+
if not compile(getCurrentDir() / path, name, args):
111+
echo "Failure"
112+
quit(1)
113+
else:
114+
# report a "not found" error
115+
echo "no program with name: '", name, "' exists. Candidates are:"
116+
echo " ", toSeq(Programs.keys).join(", ")
117+
quit(1)
128118

129-
proc buildAll(args: string): bool =
119+
proc build(names, extra: openArray[string]) =
130120
## Builds all programs, passing `args` along to the compiler.
131-
let extra = args.saneSplit()
132121
# build all standalone programs first:
133-
for (name, path, standalone, inAll) in Programs.items:
134-
if standalone and inAll:
122+
for name in names.items:
123+
let (path, standalone) = Programs[name]
124+
if standalone:
135125
if not compile(getCurrentDir() / path, name, extra):
136126
echo "Failure"
137127
quit(1)
@@ -140,12 +130,29 @@ proc buildAll(args: string): bool =
140130
generateModules(DefaultGenerated)
141131

142132
# finally, build the remaining programs:
143-
for (name, path, standalone, inAll) in Programs.items:
144-
if not standalone and inAll:
133+
for name in names.items:
134+
let (path, standalone) = Programs[name]
135+
if not standalone:
145136
if not compile(getCurrentDir() / path, name, extra):
146137
echo "Failure"
147138
quit(1)
148139

140+
proc build(args: string): bool =
141+
## Implements the `build` command.
142+
let args = args.saneSplit()
143+
if args.len == 0:
144+
return false
145+
146+
case args[0]
147+
of "all":
148+
build(toSeq(Programs.keys), args.toOpenArray(1, args.high))
149+
of "all-ws":
150+
# ws = without skully
151+
build(toSeq(Programs.keys).filterIt(it != "skully"),
152+
args.toOpenArray(1, args.high))
153+
else:
154+
build(args[0], args.toOpenArray(1, args.high))
155+
149156
result = true
150157

151158
proc generate(args: string): bool =
@@ -156,9 +163,7 @@ proc generate(args: string): bool =
156163
return false
157164

158165
# the passtool binary might be out-of-date; it's better to always compile it
159-
result = buildSingle("passtool -d:release")
160-
if not result:
161-
return
166+
build("passtool", ["-d:release"])
162167

163168
generateModules():
164169
if args.len == 1: args[0] else: DefaultGenerated
@@ -202,10 +207,8 @@ while true:
202207
of cmdArgument:
203208
success =
204209
case normalize(opts.key)
205-
of "all":
206-
buildAll(opts.cmdLineRest)
207-
of "single":
208-
buildSingle(opts.cmdLineRest)
210+
of "build":
211+
build(opts.cmdLineRest)
209212
of "generate":
210213
generate(opts.cmdLineRest)
211214
of "build-defs":

0 commit comments

Comments
 (0)