-
-
Notifications
You must be signed in to change notification settings - Fork 55
Closed
Labels
Description
Dyon is designed to be used with Rust only, but not designed to replace Rust. It complements Rust on some areas where Rust has lacking features.
- It uses no garbage collector, but instead uses a lifetime checker
- For simple game and interactive programming environments
- A simple object model to make introspection and reflection easy
Because Dyon uses a simple object model, the values must be converted when talking with Rust.
A more complex example is the dyon_interactive library.
Functions that helps talking with Rust
dyon::embed::obj_field
Runtime::pop
Runtime::push
Runtime::pop_vec4
Runtime::push_vec4
Runtime::var
Runtime::expected
External functions
Example:
fn say_hello(_: &mut Runtime) -> Result<(), String> {
println!("hi!");
Ok(())
}
To use it with Dyon, it must be registered with a name and type information:
module.add(Arc::new("say_hello".into()), say_hello, PreludeFunction {
lts: vec![], // lifetime constraints
tys: vec![], // type constraints
ret: Type::Void // return type
});
If any arguments are mutated, add pattern (mut,_,_,...)
to the function name.
For example, if 2 of 2 arguments are mutable to function foo
, you register foo(mut,mut)
.
Mutating a variable on the stack
When mutating a variable on the stack, you need to resolve the reference first. This is because
let ind = rt.stack.pop().expect("There is no value on the stack");
let id = if let Variable::Ref(id) = rt.stack[ind] {
id
} else {
rt.stack[ind]
};
if let Variable::Array(ref mut arr) = rt.stack[id] {
// mutate array here
}