Skip to content

Commit

Permalink
add koto bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
llogiq committed Aug 12, 2021
1 parent e34fca2 commit b33fb40
Show file tree
Hide file tree
Showing 25 changed files with 1,798 additions and 21 deletions.
93 changes: 93 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[workspace]
members = [
"bindlang",
"lang_bindings",
"gen",
"core",
"synth",
Expand Down
15 changes: 15 additions & 0 deletions bindlang/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "bindlang"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

[dependencies]
syn = { version = "1.0", features = ["extra-traits", "full", "fold", "parsing", "proc-macro"] }
quote = "1.0"
koto = { git = "https://github.com/llogiq/koto", branch = "vtable" }
koto_runtime = { git = "https://github.com/llogiq/koto", branch = "vtable" }
lang_bindings = { path = "../lang_bindings" }
lazy_static = "1.4.0"
42 changes: 42 additions & 0 deletions bindlang/examples/ex.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use bindlang::{bindlang, bindlang_main};
use std::fmt::{Display, Formatter, Result as FmtResult};

#[bindlang]
pub fn bound(_b: bool, _i: i64, _f: f32, _u: u8) {
// nothing to see here
}

#[bindlang]
pub fn anotherone() {
// still nothing
}

#[bindlang]
#[derive(Clone, Debug, Default)]
pub struct MyType;

//#[bindlang]
impl Display for MyType {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "{:?}", self)
}
}

#[bindlang]
impl MyType {
pub fn new() -> Self { MyType }

pub fn answer(&self) -> usize {
42
}
}

bindlang_main!();

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut koto = koto::Koto::default();
bindlang_init(&mut koto.prelude());
koto.compile("import MyType\nMyType.new().answer()")?;
println!("{}", koto.run()?);
Ok(())
}

0 comments on commit b33fb40

Please sign in to comment.