A small, compact scripting language and virtual machine implemented in C. pico includes a compiler, virtual machine, REPL, and a set of core modules for working with values, objects, and I/O.
- Register-based bytecode VM
- REPL
- Functions and closures
- Classes and methods
- Modules
- Lists, maps, strings, and slicing
- Small standard library
- Manual / automatic GC modes
See the included manual.md for a detailed language reference and usage examples: https://github.com/the0cp/pico/blob/master/manual.md
# A tiny PiCo demo:
func slug(s) {
return s.trim().lower().replace(" ", "-");
}
func badge(s) {
return "[" + s + "]";
}
func makeCounter(prefix) {
var n = 0;
return func(name) {
n++;
return "${prefix}-${n}: ${name}";
};
}
var next = makeCounter("demo");
var topics = [" Register VM ", " Pipe Operator ", " Path Join "];
for (var topic : topics) {
var name = topic |> slug |> badge;
print next(name);
}
print "path: ${"examples" / "data" / "sample.txt"}";
print "slice: ${"register-vm"[0:8]}, reverse: ${"PiCo"[::-1]}";
$> echo hello from the host shell
print "shell exit code = ${_exit_code}";More examples are available in examples/.
Try more examples:
./build/debug/pico examples/tour.pcs
./build/debug/pico examples/file_indexer.pcs
./build/debug/pico examples/modules/main.pcs
# ...Requirements: gcc and CMake. The code uses GCC-specific techniques such as computed goto / dispatch table, so GCC is required. On Windows, GCC can be installed through MinGW-w64, Chocolatey, or MSYS2.
Clone the repo:
git clone --recursive https://github.com/the0cp/pico.gitConfigure and build a debug version:
cmake --preset debug
cmake --build --preset debugConfigure and build a release version:
cmake --preset release
cmake --build --preset releaseOn Windows:
cmake --preset release-windows
cmake --build --preset release-windowsThe executable is generated under the corresponding build directory, for example:
build/debug/pico
build/release/pico
build/release-windows/pico.exe
Run the test suite with CTest:
ctest --preset debug --output-on-failureor for release:
ctest --preset release --output-on-failureRun the interactive REPL:
./build/release/picoRun a script:
./build/release/pico path/to/script.pcsFor a debug build, use:
./build/debug/pico path/to/script.pcsCheck manual.md for language syntax, built-in functions, and examples.
This project is distributed under the GNU GPL v3. See gpl-3.0.txt for details.