1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
|
@echo off
setlocal enabledelayedexpansion
set "SOURCE_ARG=%~f2"
cd /d "%~dp0"
title TinyVM - Windows Interactive Build ^& Run
if /i "%~1"=="help" goto :show_help
if /i "%~1"=="--help" goto :show_help
if /i "%~1"=="-h" goto :show_help
REM everything built or generated goes under build\ (executables in build\bin);
REM the tree holds sources only. the cores take their genome in with c23 #embed,
REM so the compiler has to be clang 19 or gcc 15 or later.
REM =========================================================================
REM Compiler Detection & Environment Setup
REM =========================================================================
set "CC_NAME="
if not exist "build\probe" mkdir "build\probe"
> "build\probe\probe.bin" echo ab
> "build\probe\probe.c" echo static const unsigned char probe[] = {
>> "build\probe\probe.c" echo #embed "probe.bin"
>> "build\probe\probe.c" echo };
>> "build\probe\probe.c" echo int main(void) { return sizeof probe ^> 0 ? 0 : 1; }
REM preserve a compiler selected by the caller, if it can #embed.
if defined CC (
call :probe_cc "%CC%"
if not errorlevel 1 (
set "CC_NAME=Configured [%CC%]"
goto :has_compiler
)
echo [ERROR] CC=%CC% does not support #embed; clang 19 or gcc 15 is needed.
exit /b 1
)
REM 1. WinGet LLVM-MinGW portable packages (self-contained with CRT headers)
for /d %%D in ("%LOCALAPPDATA%\Microsoft\WinGet\Packages\MartinStorsjo.LLVM-MinGW*") do (
for /d %%B in ("%%D\llvm-mingw*") do (
if exist "%%B\bin\clang.exe" (
call :probe_cc "%%B\bin\clang.exe"
if not errorlevel 1 (
set "PATH=%%B\bin;!PATH!"
set "CC=clang"
set "CC_NAME=LLVM-MinGW Clang [WinGet]"
goto :has_compiler
)
)
)
)
REM 2. clang or gcc already in PATH
for %%C in (clang gcc) do (
where %%C >nul 2>nul
if !errorlevel! equ 0 (
call :probe_cc %%C
if not errorlevel 1 (
set "CC=%%C"
set "CC_NAME=%%C [in PATH]"
goto :has_compiler
)
)
)
REM 3. C:\Program Files\LLVM\bin and the x86 variant
if exist "%ProgramFiles%\LLVM\bin\clang.exe" (
call :probe_cc "%ProgramFiles%\LLVM\bin\clang.exe"
if not errorlevel 1 (
set "PATH=%ProgramFiles%\LLVM\bin;%PATH%"
set "CC=clang"
set "CC_NAME=LLVM Clang [Program Files]"
goto :has_compiler
)
)
set "PFX86=%ProgramFiles(x86)%"
if defined PFX86 if exist "!PFX86!\LLVM\bin\clang.exe" (
call :probe_cc "!PFX86!\LLVM\bin\clang.exe"
if not errorlevel 1 (
set "PATH=!PFX86!\LLVM\bin;%PATH%"
set "CC=clang"
set "CC_NAME=LLVM Clang [Program Files x86]"
goto :has_compiler
)
)
echo [ERROR] No C compiler with #embed support [clang 19 or gcc 15 and later] was found.
echo.
echo Please install LLVM / Clang:
echo winget install MartinStorsjo.LLVM-MinGW.UCRT
echo or: winget install LLVM.LLVM
echo.
pause
exit /b 1
REM :probe_cc compiler - errorlevel 0 when it compiles a file that uses #embed
:probe_cc
%1 -w --embed-dir=build\probe build\probe\probe.c -o build\probe\probe.exe >nul 2>nul
exit /b %errorlevel%
:has_compiler
REM the include and embed paths of a core that carries the compiler genome
set "COREINC=-Isrc/core -Ibuild/core/map --embed-dir=build/core"
REM Handle CLI Arguments if provided
if not "%~1"=="" goto :handle_cli
REM =========================================================================
REM Interactive Main Menu
REM =========================================================================
:main_menu
cls
echo ===============================================================================
echo TinyVM - Windows Toolchain
echo ===============================================================================
echo Compiler : %CC_NAME%
echo Working : %CD%
echo -------------------------------------------------------------------------------
echo executable status:
if exist "build\bin\zy.exe" ( echo [X] build\bin\zy.exe - VM core interpreter ) else ( echo [ ] build\bin\zy.exe - not built )
if exist "build\bin\zym.exe" ( echo [X] build\bin\zym.exe - portable microcore ) else ( echo [ ] build\bin\zym.exe - not built )
if exist "build\bin\zc0.exe" ( echo [X] build\bin\zc0.exe - stage 0 bootstrap compiler ) else ( echo [ ] build\bin\zc0.exe - not built )
if exist "build\bin\mkgenome.exe" ( echo [X] build\bin\mkgenome.exe - genome image checker ) else ( echo [ ] build\bin\mkgenome.exe - not built )
if exist "build\bin\genmap.exe" ( echo [X] build\bin\genmap.exe - memory map generator ) else ( echo [ ] build\bin\genmap.exe - not built )
if exist "build\bin\zclsp.exe" ( echo [X] build\bin\zclsp.exe - language server protocol ^& highlighter ) else ( echo [ ] build\bin\zclsp.exe - not built )
echo ===============================================================================
echo [1] build VM core (build\bin\zy.exe)
echo [2] build microcore (build\bin\zym.exe)
echo [3] build bootstrap tools (zc0.exe, mkgenome.exe, genmap.exe)
echo [4] build LSP server ^& highlighter (build\bin\zclsp.exe)
echo [5] build everything
echo [6] run Windows test suite (native, LSP, JS, bootstrap)
echo [7] run an example on the native VM (build\bin\zy.exe)
echo [8] run an example in the JavaScript VM (node build\js\tinyvm.js)
echo [9] run a custom .zc source file
echo [L] check/highlight .zc with LSP (build\bin\zclsp.exe)
echo [R] launch the interactive REPL (resident compiler)
echo [G] rebuild the compiler genome and check the fixpoint
echo [C] clean generated output (build)
echo [Q] quit
echo ===============================================================================
set /p "CHOICE=select an option [1-9, L, R, G, C, Q]: "
if /i "%CHOICE%"=="1" goto :menu_build_core
if /i "%CHOICE%"=="2" goto :menu_build_micro
if /i "%CHOICE%"=="3" goto :menu_build_tools
if /i "%CHOICE%"=="4" goto :menu_build_lsp
if /i "%CHOICE%"=="5" goto :menu_build_all
if /i "%CHOICE%"=="6" goto :menu_test
if /i "%CHOICE%"=="7" goto :menu_examples
if /i "%CHOICE%"=="8" goto :menu_examples_js
if /i "%CHOICE%"=="9" goto :menu_run_custom
if /i "%CHOICE%"=="l" goto :menu_lsp_check
if /i "%CHOICE%"=="r" goto :menu_repl
if /i "%CHOICE%"=="g" goto :menu_genome
if /i "%CHOICE%"=="c" goto :menu_clean
if /i "%CHOICE%"=="q" exit /b 0
echo Invalid choice. Please try again.
timeout /t 2 >nul
goto :main_menu
REM =========================================================================
REM Actions
REM =========================================================================
:menu_build_core
echo.
call :build_core
echo.
pause
goto :main_menu
:menu_build_micro
echo.
call :build_micro
echo.
pause
goto :main_menu
:menu_build_tools
echo.
call :build_tools
echo.
pause
goto :main_menu
:menu_build_lsp
echo.
call :build_lsp
echo.
pause
goto :main_menu
:menu_build_all
echo.
call :build_all
if errorlevel 1 goto :build_failed
echo.
echo [OK] Build complete.
pause
goto :main_menu
:build_failed
echo.
echo [ERROR] Build failed. See the messages above.
pause
goto :main_menu
:menu_test
echo.
call :run_tests
if errorlevel 1 echo [ERROR] Test suite failed.
echo.
pause
goto :main_menu
:menu_genome
echo.
call :build_genome
if errorlevel 1 goto :build_failed
echo.
pause
goto :main_menu
:menu_clean
echo.
call :clean
echo.
pause
goto :main_menu
:menu_run_custom
echo.
set /p "CUSTOM_FILE=Enter path to .zc file (or drag & drop here): "
REM Remove quotes if user dragged & dropped
set "CUSTOM_FILE=%CUSTOM_FILE:"=%"
if not exist "%CUSTOM_FILE%" (
echo [ERROR] File not found: %CUSTOM_FILE%
echo.
pause
goto :main_menu
)
if not exist "build\bin\zy.exe" (
call :build_core
if errorlevel 1 goto :build_failed
)
echo.
echo ===============================================================================
echo Running: %CUSTOM_FILE%
echo ===============================================================================
build\bin\zy.exe < "%CUSTOM_FILE%"
echo.
echo ===============================================================================
pause
goto :main_menu
:menu_lsp_check
echo.
set /p "LSP_FILE=Enter path to .zc file to check/highlight (or drag & drop here): "
set "LSP_FILE=%LSP_FILE:"=%"
if not exist "%LSP_FILE%" (
echo [ERROR] File not found: %LSP_FILE%
echo.
pause
goto :main_menu
)
if not exist "build\bin\zclsp.exe" (
call :build_lsp
if errorlevel 1 goto :build_failed
)
echo.
echo ===============================================================================
echo Analyzing with build\bin\zclsp.exe: %LSP_FILE%
echo ===============================================================================
build\bin\zclsp.exe < "%LSP_FILE%"
echo.
echo ===============================================================================
pause
goto :main_menu
:menu_repl
echo.
if not exist "build\bin\zy.exe" (
call :build_core
if errorlevel 1 goto :build_failed
)
echo ===============================================================================
echo TinyVM Interactive REPL (resident compiler)
echo Each input chunk separated by backtick (`) is compiled and run.
echo Type expression or function, terminate with ` (or EOF / Ctrl+Z).
echo Type 'quit;' then backtick or press Ctrl+C to exit.
echo ===============================================================================
(type examples\repl.zc & echo ` & more) | build\bin\zy.exe
echo.
pause
goto :main_menu
REM =========================================================================
REM Example Selection Sub-menu
REM =========================================================================
:menu_examples
cls
echo ===============================================================================
echo Run TinyVM Examples on Native VM (zy.exe)
echo ===============================================================================
call :example_list
set /p "EX_CHOICE=Select an example [1-9, B]: "
if /i "%EX_CHOICE%"=="b" goto :main_menu
call :example_file "%EX_CHOICE%"
if "%EX_FILE%"=="" (
echo Invalid choice.
timeout /t 2 >nul
goto :menu_examples
)
if not exist "build\bin\zy.exe" (
call :build_core
if errorlevel 1 goto :build_failed
)
echo.
echo ===============================================================================
echo Running: %EX_FILE%
echo ===============================================================================
build\bin\zy.exe < "%EX_FILE%"
echo.
echo ===============================================================================
pause
goto :menu_examples
:menu_examples_js
cls
echo ===============================================================================
echo Run TinyVM Examples in JavaScript VM (Node.js)
echo ===============================================================================
call :example_list
set /p "EX_CHOICE=Select an example [1-9, B]: "
if /i "%EX_CHOICE%"=="b" goto :main_menu
call :example_file "%EX_CHOICE%"
if "%EX_FILE%"=="" (
echo Invalid choice.
timeout /t 2 >nul
goto :menu_examples_js
)
call :build_js
if errorlevel 1 goto :build_failed
echo.
echo ===============================================================================
echo Running in JS: %EX_FILE%
echo ===============================================================================
node build\js\tinyvm.js "%EX_FILE%"
echo.
echo ===============================================================================
pause
goto :menu_examples_js
:example_list
echo [1] hello.zc - Classic "hello, world!"
echo [2] fact.zc - Recursive ^& iterative factorial computation
echo [3] mandel.zc - Mandelbrot ASCII set using custom enhancement opcode
echo [4] primes.zc - Sieve of Eratosthenes with o3 region compilation
echo [5] life.zc - Conway's Game of Life on a typed torus board
echo [6] lists.zc - Dynamic array with ownership tracking (u, m, d tags)
echo [7] typed.zc - Structs, generic vectors, and reflection
echo [8] wiring.zc - Runtime custom enhancement opcodes demo
echo [9] bf.zc - Brainfuck compiler running inside TinyVM
echo [B] Back to main menu
echo ===============================================================================
exit /b 0
:example_file
set "EX_FILE="
if "%~1"=="1" set "EX_FILE=examples\hello.zc"
if "%~1"=="2" set "EX_FILE=examples\fact.zc"
if "%~1"=="3" set "EX_FILE=examples\mandel.zc"
if "%~1"=="4" set "EX_FILE=examples\primes.zc"
if "%~1"=="5" set "EX_FILE=examples\life.zc"
if "%~1"=="6" set "EX_FILE=examples\lists.zc"
if "%~1"=="7" set "EX_FILE=examples\typed.zc"
if "%~1"=="8" set "EX_FILE=examples\wiring.zc"
if "%~1"=="9" set "EX_FILE=examples\bf.zc"
exit /b 0
REM =========================================================================
REM Build Routines
REM =========================================================================
REM genmap needs no map; the default map comes from it and the zc sources' const blocks
:build_tools
if not exist "build\bin" mkdir build\bin
echo Compiling genmap.exe (memory map generator)...
"%CC%" -O2 -w -fwrapv src\tools\genmap.c -o build\bin\genmap.exe
if errorlevel 1 (echo [ERROR] Failed to build build\bin\genmap.exe.& exit /b 1)
if exist build\core\map rmdir /s /q build\core\map
if not exist build\core mkdir build\core
build\bin\genmap.exe --preset default --check -o build\core\map >nul
if errorlevel 1 (echo [ERROR] The default memory map does not match the sources.& exit /b 1)
echo Compiling zc0.exe (bootstrap compiler)...
"%CC%" -O1 -w -fwrapv src\tools\zc0.c -Isrc/core -Ibuild/core/map -o build\bin\zc0.exe
if errorlevel 1 (echo [ERROR] Failed to build build\bin\zc0.exe.& exit /b 1)
echo Compiling mkgenome.exe (genome image checker)...
"%CC%" -O1 -w -fwrapv src\tools\mkgenome.c -Ibuild/core/map -o build\bin\mkgenome.exe
if errorlevel 1 (echo [ERROR] Failed to build build\bin\mkgenome.exe.& exit /b 1)
echo [OK] Bootstrap tools built in build\bin.
exit /b 0
REM zc0 compiles the compiler to g0, g0 compiles it to g1, g1 to g2. g1 and g2
REM must be identical, and g1 becomes build\core\genome.bin.
:build_genome
call :build_tools
if errorlevel 1 exit /b 1
echo Bootstrapping the compiler genome...
if not exist build\s0 mkdir build\s0
if not exist build\s1 mkdir build\s1
(type src\runtime\rt.zc & type src\core\core.zc & type src\compiler\compiler.zc) | build\bin\zc0.exe > build\s0\g0.bin
if errorlevel 1 (echo [ERROR] Stage 0 failed.& exit /b 1)
build\bin\mkgenome.exe < build\s0\g0.bin > build\s0\genome.bin
if errorlevel 1 (echo [ERROR] Stage 0 did not produce a genome.& exit /b 1)
"%CC%" -O2 -w -fwrapv -DJTYPE=int src\core\core.c src\core\io_win.c -Isrc/core -Ibuild/core/map --embed-dir=build/s0 -o build\s0\zy0.exe
if errorlevel 1 (echo [ERROR] Failed to build the stage 0 core.& exit /b 1)
(type src\tools\build.zc & echo ` & type src\runtime\rt.zc & type src\core\core.zc & type src\compiler\compiler.zc) | build\s0\zy0.exe > build\s1\g1.bin
build\bin\mkgenome.exe < build\s1\g1.bin > build\s1\genome.bin
if errorlevel 1 (echo [ERROR] The compiler did not compile itself; its diagnostics are above.& exit /b 1)
"%CC%" -O2 -w -fwrapv -DJTYPE=int src\core\core.c src\core\io_win.c -Isrc/core -Ibuild/core/map --embed-dir=build/s1 -o build\s1\zy1.exe
if errorlevel 1 (echo [ERROR] Failed to build the stage 1 core.& exit /b 1)
(type src\tools\build.zc & echo ` & type src\runtime\rt.zc & type src\core\core.zc & type src\compiler\compiler.zc) | build\s1\zy1.exe > build\s1\g2.bin
fc /b build\s1\g1.bin build\s1\g2.bin >nul
if errorlevel 1 (echo [ERROR] Fixpoint failed: the compiler does not compile itself to the same image.& exit /b 1)
copy /y build\s1\genome.bin build\core\genome.bin >nul
echo [OK] Fixpoint reached; build\core\genome.bin updated.
exit /b 0
:need_genome
if exist build\core\genome.bin if exist build\core\map\memmap.h exit /b 0
call :build_genome
exit /b %errorlevel%
:build_core
call :need_genome
if errorlevel 1 exit /b 1
echo Compiling zy.exe (VM core with the compiler genome)...
"%CC%" -O2 -w -fwrapv -DJTYPE=int src\core\core.c src\core\io_win.c %COREINC% -o build\bin\zy.exe
if errorlevel 1 (echo [ERROR] Failed to build build\bin\zy.exe.& exit /b 1)
echo [OK] build\bin\zy.exe built.
exit /b 0
:build_micro
call :need_genome
if errorlevel 1 exit /b 1
echo Compiling zym.exe (portable microcore)...
"%CC%" -O2 -w -fwrapv src\micro\micro.c src\micro\port_win.c %COREINC% -Isrc/micro -o build\bin\zym.exe
if errorlevel 1 (echo [ERROR] Failed to build build\bin\zym.exe.& exit /b 1)
echo [OK] build\bin\zym.exe built.
exit /b 0
REM the language server: the compiler in check mode plus src\lsp\server.zc, on a
REM map sized to the image (the steps of src/tools/automap.sh lsp with DOCS=1)
:build_lsp
if not exist "build\bin\genmap.exe" (
call :build_tools
if errorlevel 1 exit /b 1
)
echo Compiling zclsp.exe (language server ^& semantic highlighter)...
if exist build\lsp rmdir /s /q build\lsp
mkdir build\lsp
call :lsp_pass "" "" image.bin
if errorlevel 1 exit /b 1
call :words build\lsp\image.bin
set /a SLOT=(WORDS+4095)/4096*4096
set /a DOCS_WORK=SLOT+65536
call :lsp_pass %DOCS_WORK% -DZC0DOCS image.bin
if errorlevel 1 exit /b 1
call :words build\lsp\image.bin
set /a DOCS_SLOT=(WORDS+4095)/4096*4096
set "DOCS_WORDS=!WORDS!"
call :lsp_pass %DOCS_SLOT% -DZC0DOCS lsp_genome.bin
if errorlevel 1 exit /b 1
call :words build\lsp\lsp_genome.bin
if not "!WORDS!"=="!DOCS_WORDS!" (echo [ERROR] LSP genome changed length after map sizing.& exit /b 1)
copy /y build\lsp\map\memmap.h build\lsp\memmap.h >nul
"%CC%" -O2 -w -fwrapv -DJTYPE=int -DZY_SANDBOX -DUSE_LSP_GENOME src\core\core.c src\core\io_win.c -Isrc/core -Ibuild/lsp --embed-dir=build/lsp -o build\lsp\zclsp.exe
if errorlevel 1 (echo [ERROR] Failed to build zclsp.exe.& exit /b 1)
if not exist "build\bin" mkdir build\bin
copy /y build\lsp\zclsp.exe build\bin\zclsp.exe >nul
echo [OK] build\bin\zclsp.exe built with !WORDS! words.
exit /b 0
REM :lsp_pass genome-slot zc0-define output - lay out the lsp map (with that genome
REM slot, or the preset's own when it is empty) and compile the server image into it
:lsp_pass
if exist build\lsp\map rmdir /s /q build\lsp\map
if "%~1"=="" (
build\bin\genmap.exe --preset lsp --grow -o build\lsp\map >nul 2>nul
) else (
build\bin\genmap.exe --preset lsp --grow --genome %~1 -o build\lsp\map >nul 2>nul
)
if errorlevel 1 (echo [ERROR] Could not generate the LSP map.& exit /b 1)
"%CC%" -O1 -w -fwrapv %~2 src\tools\zc0.c -Ibuild/lsp/map -Isrc/core -o build\lsp\zc0.exe
if errorlevel 1 (echo [ERROR] Could not build the LSP stage 0 compiler.& exit /b 1)
"%CC%" -O1 -w -fwrapv src\tools\mkgenome.c -Ibuild/lsp/map -o build\lsp\mkgenome.exe
if errorlevel 1 (echo [ERROR] Could not build the LSP image checker.& exit /b 1)
(type build\lsp\map\rt.zc & type src\core\core.zc & type build\lsp\map\compiler.zc & type src\lsp\server.zc) | build\lsp\zc0.exe > build\lsp\raw.bin
if errorlevel 1 (echo [ERROR] Could not compile the LSP image.& exit /b 1)
build\lsp\mkgenome.exe < build\lsp\raw.bin > build\lsp\%~3
if errorlevel 1 (echo [ERROR] The LSP image does not match its map.& exit /b 1)
exit /b 0
REM :words file - WORDS is the file's length in 64-bit words
:words
set /a WORDS=%~z1/8
exit /b 0
REM the javascript vm: layout, genome and the compiled vm in build\js (needs node and tsc)
:build_js
call :need_genome
if errorlevel 1 exit /b 1
if not exist build\js mkdir build\js
node src\js\mklayout.js --map build\core\map\memmap.h --out build\js >nul
if errorlevel 1 (echo [ERROR] Could not write the javascript layout.& exit /b 1)
copy /y build\core\genome.bin build\js\genome.bin >nul
call tsc src\js\tinyvm.ts --target es2020 --lib es2020,dom --module commonjs --outDir build\js
if errorlevel 1 (echo [ERROR] Could not compile the javascript vm; tsc is needed.& exit /b 1)
exit /b 0
:build_all
call :build_genome
if errorlevel 1 exit /b 1
call :build_core
if errorlevel 1 exit /b 1
call :build_micro
if errorlevel 1 exit /b 1
call :build_lsp
exit /b %errorlevel%
:run_tests
call :build_core
if errorlevel 1 exit /b 1
call :build_micro
if errorlevel 1 exit /b 1
powershell -NoProfile -ExecutionPolicy Bypass -File "tests\test_win.ps1"
exit /b %errorlevel%
:clean
rmdir /s /q build 2>nul
echo [OK] Generated build directory removed.
exit /b 0
REM =========================================================================
REM CLI Command Handler
REM =========================================================================
:handle_cli
set "CMD=%~1"
set "ARG2=%~2"
if /i "%CMD%"=="build" (
if "%ARG2%"=="" ( call :build_all & exit /b !errorlevel! )
if /i "%ARG2%"=="all" ( call :build_all & exit /b !errorlevel! )
if /i "%ARG2%"=="core" ( call :build_core & exit /b !errorlevel! )
if /i "%ARG2%"=="micro" ( call :build_micro & exit /b !errorlevel! )
if /i "%ARG2%"=="tools" ( call :build_tools & exit /b !errorlevel! )
if /i "%ARG2%"=="lsp" ( call :build_lsp & exit /b !errorlevel! )
if /i "%ARG2%"=="js" ( call :build_js & exit /b !errorlevel! )
echo Unknown build target: %ARG2%
exit /b 1
)
if /i "%CMD%"=="genome" (
call :build_genome
exit /b !errorlevel!
)
if /i "%CMD%"=="test" (
call :run_tests
exit /b !errorlevel!
)
if /i "%CMD%"=="run" (
if "%ARG2%"=="" (
echo Error: Missing .zc file to run.
echo Usage: tinyvm.bat run path\to\program.zc
exit /b 1
)
if not exist "build\bin\zy.exe" (
call :build_core
if errorlevel 1 exit /b 1
)
build\bin\zy.exe < "%SOURCE_ARG%"
exit /b !errorlevel!
)
if /i "%CMD%"=="run-micro" (
if "%ARG2%"=="" (
echo Error: Missing .zc file to run.
echo Usage: tinyvm.bat run-micro path\to\program.zc
exit /b 1
)
if not exist "build\bin\zym.exe" (
call :build_micro
if errorlevel 1 exit /b 1
)
build\bin\zym.exe < "%SOURCE_ARG%"
exit /b !errorlevel!
)
if /i "%CMD%"=="js" (
if "%ARG2%"=="" (
echo Error: Missing .zc file to run.
echo Usage: tinyvm.bat js path\to\program.zc
exit /b 1
)
call :build_js
if errorlevel 1 exit /b 1
node build\js\tinyvm.js "%SOURCE_ARG%"
exit /b !errorlevel!
)
if /i "%CMD%"=="lsp" (
if "%ARG2%"=="" (
echo Error: Missing .zc file to check.
echo Usage: tinyvm.bat lsp path\to\program.zc
exit /b 1
)
if not exist "build\bin\zclsp.exe" (
call :build_lsp
if errorlevel 1 exit /b 1
)
build\bin\zclsp.exe < "%SOURCE_ARG%"
exit /b !errorlevel!
)
if /i "%CMD%"=="repl" (
if not exist "build\bin\zy.exe" (
call :build_core
if errorlevel 1 exit /b 1
)
(type examples\repl.zc & echo ` & more) | build\bin\zy.exe
exit /b !errorlevel!
)
if /i "%CMD%"=="clean" (
call :clean
exit /b 0
)
echo Unknown command: %CMD%
echo.
exit /b 1
:show_help
echo usage: tinyvm.bat [command]
echo tinyvm.bat launch interactive build ^& run menu
echo tinyvm.bat build [all^|core^|micro^|tools^|lsp^|js]
echo compile TinyVM executables into build\bin
echo tinyvm.bat genome rebuild build\core\genome.bin and check the fixpoint
echo tinyvm.bat run ^<file.zc^> run a .zc program on VM core (zy.exe)
echo tinyvm.bat run-micro ^<file.zc^> run a .zc program on microcore (zym.exe)
echo tinyvm.bat js ^<file.zc^> run a .zc program on the JavaScript VM (node)
echo tinyvm.bat lsp ^<file.zc^> check/highlight a .zc program with zclsp.exe
echo tinyvm.bat test run the Windows test suite
echo tinyvm.bat repl launch the resident compiler REPL
echo tinyvm.bat clean remove the generated build directory
echo the compiler must support c23 #embed: clang 19 or gcc 15 and later.
exit /b 0
|