Skip to content

Instantly share code, notes, and snippets.

@linkdd
Created September 23, 2022 16:15
Show Gist options
  • Save linkdd/7233c319fe3f2048b3b6b472459fcf0d to your computer and use it in GitHub Desktop.
Save linkdd/7233c319fe3f2048b3b6b472459fcf0d to your computer and use it in GitHub Desktop.
Letlang basic structure of a block of code
let task_args: Vec<Value> = vec![];
let mut block = func.call(&mut context, task_args);
let ignored = Value::Boolean(bool::default());
let mut state = block.resume_with(ignored);
loop {
match &state {
GeneratorState::Yielded(FunctionInterruption::Effect { name, args }) => {
// try to handle side effect
if unknown_side_effect {
// print debug information
return Err(RuntimeError::EffectNotImplemented);
}
else {
let effect_return_value = { /* ... */ };
state = block.resume_with(effect_return_value);
}
},
GeneratorState::Yielded(FunctionInterruption::Exception(exc)) => {
// print exception
return Err(RuntimeError::UncaughtException);
},
GeneratorState::Complete(val) => {
// type check function's return value
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment