coda-runtime 0.1.1

the runtime for coda, an experimental scripting language
Documentation
  • Coverage
  • 0%
    0 out of 151 items documented0 out of 32 items with examples
  • Size
  • Source code size: 41.79 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 5.32 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 12s Average build duration of successful builds.
  • all releases: 13s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • playvoxel/coda
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Primiti-ve

coda-runtime

coda-runtime is the script interpreter for coda, an experimental scripting language.

you can see more information about coda in the github repository.

embedding

[!TIP] the coda runtime has zero dependencies, meaning you can use it in any project without worrying about compatibility issues.

embedding the coda runtime into your own projects is as easy and simple as:

  • creating an interpreter using coda_runtime::runtime::interpreter::Interpreter::new
  • getting the source code in any way you want
  • scanning the source code into tokens using coda_runtime::frontend::lexer::scan
  • parsing the tokens into an ast using coda_runtime::frontend::parser::parse
  • running the ast using coda_runtime::runtime::interpreter::Interpreter::run

this code sample is directly taken from the cli run subcommand!

use coda_runtime::{
    frontend::{lexer, parser},
    runtime::{interpreter::Interpreter},
    env::Env,
};
use coda_std::std_loader;

let env = Env::new();

let source_path = std::path::PathBuf::from(&self.file);
let base_path = source_path.parent().unwrap_or(std::path::Path::new(".")).to_path_buf();

let mut interpreter = Interpreter::new(env, base_path, Some(std_loader));

let source = std::fs::read_to_string(&self.file)?;
let tokens = lexer::scan(&source)?;
let ast = parser::parse(tokens)?;

interpreter.run(ast)?;

features

  • let/const variables
  • importing from standard library and other files
  • string addition
  • compound assignment
  • functions
    • anonymous functions
    • closures
  • if statements
  • while loops
  • arrays
    • nested arrays