diff options
| author | Laurenz <laurmaedje@gmail.com> | 2022-05-25 11:46:51 +0200 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2022-05-25 11:51:28 +0200 |
| commit | 6935cf8dfefff3d6cf234f077a7d61661fd5ca57 (patch) | |
| tree | cf40e5c6eb99ff28c62edde75f0eab748672ba30 /src/library | |
| parent | 3309ff9fe5ea36134e8ddf11ac2c84613b569856 (diff) | |
Virtual machine
Diffstat (limited to 'src/library')
| -rw-r--r-- | src/library/utility/mod.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/library/utility/mod.rs b/src/library/utility/mod.rs index c4e847c3..6f0f9a4c 100644 --- a/src/library/utility/mod.rs +++ b/src/library/utility/mod.rs @@ -10,7 +10,7 @@ pub use string::*; use std::mem; -use crate::eval::{Eval, Scopes}; +use crate::eval::{Eval, Machine, Scopes}; use crate::library::prelude::*; use crate::source::SourceFile; @@ -33,22 +33,24 @@ pub fn eval(ctx: &mut Context, args: &mut Args) -> TypResult<Value> { let Spanned { v: src, span } = args.expect::<Spanned<String>>("source")?; // Parse the source and set a synthetic span for all nodes. - let mut source = SourceFile::detached(src); - source.synthesize(span); + let source = SourceFile::synthesized(src, span); let ast = source.ast()?; - // Save the old context, then detach it. - let prev_flow = ctx.flow.take(); + // Save the old route, then detach it. let prev_route = mem::take(&mut ctx.route); // Evaluate the source. let std = ctx.config.std.clone(); - let mut scp = Scopes::new(Some(&std)); - let result = ast.eval(ctx, &mut scp); + let scopes = Scopes::new(Some(&std)); + let mut vm = Machine::new(ctx, scopes); + let result = ast.eval(&mut vm); + let flow = vm.flow; - // Restore the old context and handle control flow. + // Restore the old route. ctx.route = prev_route; - if let Some(flow) = mem::replace(&mut ctx.flow, prev_flow) { + + // Handle control flow. + if let Some(flow) = flow { return Err(flow.forbidden()); } |
