Skip to content

Commit

Permalink
Flesh out new structure for interpreter (and eventual comp)
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant committed Dec 25, 2024
1 parent dd88133 commit f85ed81
Show file tree
Hide file tree
Showing 19 changed files with 1,600 additions and 1,083 deletions.
2 changes: 1 addition & 1 deletion benches/fib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async fn fib() {
}

fn fib_benchmark(c: &mut Criterion) {
c.bench_function("fib 100", |b| {
c.bench_function("fib 10000", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(fib)
});
Expand Down
2 changes: 1 addition & 1 deletion benches/fib.scm
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
(iter b (+ a b) (- count 1))))
(iter 0 1 n))

(fib 100)
(fib 10000)
8 changes: 4 additions & 4 deletions proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ pub fn builtin(name: TokenStream, item: TokenStream) -> TokenStream {
fn #wrapper_name(
cont: Option<std::sync::Arc<::scheme_rs::continuation::Continuation>>,
args: Vec<::scheme_rs::gc::Gc<::scheme_rs::value::Value>>
) -> futures::future::BoxFuture<'static, Result<::scheme_rs::eval::ValuesOrPreparedCall, ::scheme_rs::error::RuntimeError>> {
) -> futures::future::BoxFuture<'static, Result<::scheme_rs::proc::ValuesOrPreparedCall, ::scheme_rs::error::RuntimeError>> {
Box::pin(
async move {
#impl_name(
&cont,
#( &args[#arg_indices], )*
).await.map(::scheme_rs::eval::ValuesOrPreparedCall::from)
).await.map(::scheme_rs::proc::ValuesOrPreparedCall::from)
}
)
}
Expand All @@ -50,15 +50,15 @@ pub fn builtin(name: TokenStream, item: TokenStream) -> TokenStream {
fn #wrapper_name(
cont: Option<std::sync::Arc<::scheme_rs::continuation::Continuation>>,
mut required_args: Vec<::scheme_rs::gc::Gc<::scheme_rs::value::Value>>
) -> futures::future::BoxFuture<'static, Result<::scheme_rs::eval::ValuesOrPreparedCall, ::scheme_rs::error::RuntimeError>> {
) -> futures::future::BoxFuture<'static, Result<::scheme_rs::proc::ValuesOrPreparedCall, ::scheme_rs::error::RuntimeError>> {
let var_args = required_args.split_off(#num_args);
Box::pin(
async move {
#impl_name(
&cont,
#( &required_args[#arg_indices], )*
var_args
).await.map(::scheme_rs::eval::ValuesOrPreparedCall::from)
).await.map(::scheme_rs::proc::ValuesOrPreparedCall::from)
}
)
}
Expand Down
211 changes: 0 additions & 211 deletions src/ast.rs

This file was deleted.

25 changes: 25 additions & 0 deletions src/ast/eval.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! todo
use crate::continuation::*;
use super::*;

impl Body {
pub async fn tail_eval(
&self,
env: &Env,
cont: &Option<Arc<Continuation>>,
) -> Result<ValuesOrPreparedCall, RuntimeError> {
let Some(last) = self.forms.last() else {
return Ok(ValuesOrPreparedCall::Values(vec![Gc::new(Value::Null)]));
};
for (form, tail) in self.forms.skip_last() {
let cont = Some(Arc::new(Continuation::new(
Arc::new(ResumableBody::new(env, &tail)),
cont,
)));
// Discard values that aren't returned
form.eval(env, &cont).await?;
}
last.tail_eval(env, cont).await
}
}
Loading

0 comments on commit f85ed81

Please sign in to comment.