Skip to content

jprochazk/hebi4

Repository files navigation

Work-in-progress programming language.

Heavily inspired by other languages in the same category: Lua, Python, and JavaScript.

Development

Working in this repository only requires a recent version of the Rust compiler and Cargo.

Local usage

# Install `hebi4` cli
cargo install --locked --path ./cli
hebi4 --help

Testing

Run tests:

cargo test

Update snapshot tests (requires cargo-insta):

cargo review

New tests can be created by adding a .hi file to tests/inputs.

Files in tests/inputs are passed through the tokenize and parse stages.

They may begin with a comment (//) to control how it will be tested:

  • //tokenize will only go through the tokenizer (src/token.rs)
  • //parse will only go through the parser (src/parser.rs)
  • By default, codegen and run tests have all optimizations enabled.
    • Available optimizations are: dce (dead code elimination)
    • // (empty comment) in codegen and run tests will disable all optimizations
    • //a,b,c will enable optimizations a, b, c.

This can also be used to completely disable test files. Adding an empty comment to the top of the file will cause it to not be tested against any stage.

Multiple different stages may be combined, e.g. tokenize,parse will run only through those two stages, but not through the bytecode emit.

Files in tests/inputs/codegen are passed through codegen. These tests always fail if they fail to parse. The resulting bytecode is disassembled for the snapshot.

Files in tests/inputs/run are passed through the runtime, end-to-end.

Try to keep tests minimal and to the point as much as possible. Separate tests should be written for each stage where the behavior may have changed. If a change in codegen may result in different runtime behavior, it should have both a codegen test and a run test.

To get syntax highlighting in tests, see tree-sitter-hebi.

Codegen

The implementation heavily relies on code generated from custom DSLs:

Both code generators have a runtime.rs file, which is the place for any helpers and types used by the generated code. It is concatenated together with the generated code to produce the final result.

After changing anything, run

cargo x codegen

To re-generate code.

CI

CI is driven by xtask. Run cargo x ci to execute the full suite of checks locally.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Scripting language

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Contributors