« Previous: Execution Engines · Guide Index · Next: Command-Line Interface »
Beyond running source directly, QuantoScript can compile a program ahead of time — either to portable bytecode or to a native binary.
qs build compiles a .qs file to a .qvm bytecode file:
qs build program.qs # writes program.qvm
qs build program.qs -o custom.qvm # custom output pathRun the compiled file with the VM:
qs run program.qvm
qs vm program.qvmCompiling ahead of time gives faster startup and lets you distribute a program without shipping its source.
A .qvm file begins with a magic header and a format version, and carries a
CRC32 checksum of the source. The loader validates the header, the version, and
the checksum, and reports a clear error on malformed files.
Disassemble a program for debugging:
qs vm --dump-bytecode program.qsThe native compiler lowers the full abstract syntax tree to a self-contained C file that embeds the QuantoScript runtime, so the resulting program runs without the interpreter or the VM:
qs native program.qs # emits a_native.c
qs native program.qs --build # emits a_native.c and builds program.exe (program on Unix)
./programWithout --build, qs native only writes the C file. With --build, it also
invokes gcc on that file to produce a binary named after the source
(program.qs → program.exe on Windows, program elsewhere).
You can also build the generated C yourself:
gcc -O2 -I <quanto-src> a_native.c -o program_native \
-lssl -lcrypto -lws2_32 -lwinhttp -lwininet -lcrypt32 -lbcrypt -lregexBecause a_native.c does #include "quanto.c", compile it with the directory
that holds quanto.c on the include path (-I <quanto-src>); the link line
above is the same set of libraries used to build qs itself. --build locates
the runtime sources the same way qs compile does (next to the binary, under
QUANTO_HOME, or via QS_SOURCE_DIR).
If you prefer a single command that always produces a binary:
qs compile program.qs # writes a.exe (a.out on Unix); pass an output path to change itqs compile needs two things: a C compiler (gcc) on your PATH, and the
QuantoScript runtime sources (quanto.c and src/parts/). The sources are
looked up next to the installed binary, under QUANTO_HOME, and in the current
directory tree; if you keep them somewhere else, point QS_SOURCE_DIR at the
directory that contains quanto.c.
The native backend covers the whole language:
- Integer and float arithmetic, string concatenation, comparison and logic
if/elif/else,while, counted and collectionrepeat,break/continue- Every variable, list, map, and string operation
- Functions (including default parameters,
*args, and**kwargs), lambdas, and recursion - Classes, fields, methods, and object construction
try/oopsexception handlingprintand f-strings- Imports
Programs that use default parameters, *args/**kwargs, or keyword arguments
delegate those calls to the interpreter at run time (the compiler embeds the
source to build the interpreter's function table), so they behave exactly as
they do under qs and qs vm.
- The generated C relies on GCC/Clang-style builtins for exception handling
(
__builtin_setjmp/__builtin_longjmp), which are stable across optimization levels on MinGW. qs nativeis not part of theqs,qs vm, andqs buildexecution paths; it is a separate ahead-of-time compilation target.
Command-Line Interface lists every command and flag.
« Previous: Execution Engines · Guide Index · Next: Command-Line Interface »