SPy language
At the moment, the only supported installation method for SPy is by doing an "editable install" of the git repo checkout.
The most up to date version of the requirements and the installation steps is the Github action workflow.
Prerequisites:
-
Python 3.12
-
wasi-sdk: this is used by some tests to check that we can compile to WASM using
wasi-sdk
. Currently, the test suite expects thatclang
points to/path/to/wask-sdk/bin/clang
(PRs to improve the situation are welcome). -
unbuffer
(apt install expect
), which is used to force gcc to emit colored error messages
Installation:
-
Install the
spy
package in editable mode:$ cd /path/to/spy/ $ pip install -e .
-
Build the
libspy
runtime library:$ make -C spy/libspy
Run the test suite:
$ pytest
All the tests in spy/tests/compiler/
are executed in three modes:
interp
: run the SPy code via the interpreterdoppler
: perform redshift, then run the redshifted code via the interpreterC
: generate C code, compile to WASM, then run it usingwasmtime
.
-
Execute a program in interpreted mode:
$ spy examples/hello.spy Hello world!
-
Perform redshift and dump the generated source code:
$ spy -r examples/hello.spy def main() -> void: print_str('Hello world!')
-
Perform redshift and THEN execute the code:
$ spy -r -x examples/hello.spy Hello world!
-
Compile to executable:
$ spy -c -t native examples/hello.spy $ ./examples/hello Hello world!
Moreover, there are more flags to stop the compilation pipeline and inspect the result at each phase.
The full compilation pipeline is:
pyparse
: source code -> generate Python ASTparse
: Python AST -> SPy ASTsymtable
: Analize the SPy AST and produce a symbol table for each scoperedshift
: SPy AST -> redshifted SPy ASTcwrite
: redshifted SPy AST -> C codecompile
: C code -> executable
Each of this step has a corresponding command line option which stops the compiler at that stage and dumps human-readable results.
Examples:
$ spy --pyparse examples/hello.spy
$ spy --parse examples/hello.spy
$ spy --symtable examples/hello.spy
$ spy --redshift examples/hello.spy
$ spy --cwrite examples/hello.spy
Moreover, the execute
step performs the actual execution: it can happen
either after symtable
(in "interp mode") or after redshift
(in "doppler
mode").