Skip to content

Commit

Permalink
Add apply, values, let-values, among others (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
maplant authored Nov 6, 2024
1 parent 453918e commit 56f652f
Show file tree
Hide file tree
Showing 21 changed files with 1,014 additions and 456 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Rust

on:
push:
branches: [ "master" ]
branches: [ "main" ]
pull_request:
branches: [ "master" ]
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ edition = "2021"

[dependencies]
async-trait = "0.1"
derive_more = "0.99"
derive_more = { version = "1.0", features = ["debug", "from"]}
dyn-clone = "1.0.13"
futures = "0.3"
inventory = "0.3"
Expand All @@ -18,9 +18,9 @@ rand = "0.8"
thiserror = "1"
tokio = { version = "1", features = ["full"] }
unicode_categories = "0.1"
reedline = "0.23"
reedline = "0.36"
# TODO: Get rid of this dependency
derivative = "2"

[profile.release]
lto = true
lto = true
4 changes: 2 additions & 2 deletions proc-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub fn builtin(name: TokenStream, item: TokenStream) -> TokenStream {
fn #wrapper_name(
cont: Option<std::sync::Arc<crate::continuation::Continuation>>,
args: Vec<crate::gc::Gc<crate::value::Value>>
) -> futures::future::BoxFuture<'static, Result<crate::gc::Gc<crate::value::Value>, crate::error::RuntimeError>> {
) -> futures::future::BoxFuture<'static, Result<Vec<crate::gc::Gc<crate::value::Value>>, crate::error::RuntimeError>> {
Box::pin(
async move {
#impl_name(
Expand All @@ -47,7 +47,7 @@ pub fn builtin(name: TokenStream, item: TokenStream) -> TokenStream {
fn #wrapper_name(
cont: Option<std::sync::Arc<crate::continuation::Continuation>>,
mut required_args: Vec<crate::gc::Gc<crate::value::Value>>
) -> futures::future::BoxFuture<'static, Result<crate::gc::Gc<crate::value::Value>, crate::error::RuntimeError>> {
) -> futures::future::BoxFuture<'static, Result<Vec<crate::gc::Gc<crate::value::Value>>, crate::error::RuntimeError>> {
let var_args = required_args.split_off(#num_args);
Box::pin(
async move {
Expand Down
53 changes: 40 additions & 13 deletions src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use crate::{
env::{Env, LexicalContour},
env::Env,
eval::Eval,
expand::Transformer,
gc::Gc,
num::Number,
syntax::{Identifier, Mark, Span, Syntax},
util::ArcSlice,
Expand Down Expand Up @@ -35,7 +34,6 @@ pub struct SyntaxQuote {

#[derive(Clone)]
pub struct Call {
// pub operator: Arc<dyn Eval>,
pub args: ArcSlice<Arc<dyn Eval>>,
pub location: Span,
pub proc_name: String,
Expand All @@ -45,7 +43,6 @@ pub struct Call {
pub struct DefineFunc {
pub name: Identifier,
pub args: Formals,
pub mark: Mark,
pub body: Body,
}

Expand All @@ -62,16 +59,12 @@ pub enum Define {
}

#[derive(Clone)]
pub struct DefineSyntax {
pub name: Identifier,
pub transformer: Arc<dyn Eval>,
}
pub struct DefineSyntax;

#[derive(Clone)]
pub struct Lambda {
pub args: Formals,
pub body: Body,
pub mark: Mark,
}

#[derive(Debug, Clone)]
Expand All @@ -92,13 +85,13 @@ impl Formals {
}
}

#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct Body {
pub exprs: ArcSlice<Syntax>,
pub exprs: ArcSlice<Arc<dyn Eval>>,
}

impl Body {
pub fn new(exprs: Vec<Syntax>) -> Self {
pub fn new(exprs: Vec<Arc<dyn Eval>>) -> Self {
Self {
exprs: ArcSlice::from(exprs),
}
Expand All @@ -107,7 +100,6 @@ impl Body {

#[derive(Clone)]
pub struct Let {
pub scope: Gc<LexicalContour>,
pub bindings: Arc<[(Identifier, Arc<dyn Eval>)]>,
pub body: Body,
}
Expand Down Expand Up @@ -170,6 +162,41 @@ pub struct SyntaxRules {
pub transformer: Transformer,
}

#[derive(Clone)]
pub struct Apply {
pub proc_name: String,
pub location: Span,
pub args: ArcSlice<Arc<dyn Eval>>,
pub rest_args: Arc<dyn Eval>,
}

#[derive(Clone)]
pub struct FetchVar {
pub ident: Identifier,
}

impl FetchVar {
pub fn new(ident: Identifier) -> Self {
Self { ident }
}
}

#[derive(Clone)]
pub struct MacroExpansionPoint {
pub mark: Mark,
pub macro_env: Env,
pub expr: Arc<dyn Eval>,
}

impl MacroExpansionPoint {
pub fn new(mark: Mark, macro_env: Env, expr: Arc<dyn Eval>) -> Self {
Self {
mark,
macro_env,
expr,
}
}
}
/*
struct Export {}
Expand Down
2 changes: 1 addition & 1 deletion src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{
use futures::future::BoxFuture;
use std::sync::Arc;

type ExprFuture = BoxFuture<'static, Result<Gc<Value>, RuntimeError>>;
type ExprFuture = BoxFuture<'static, Result<Vec<Gc<Value>>, RuntimeError>>;

pub struct Builtin {
pub name: &'static str,
Expand Down
Loading

0 comments on commit 56f652f

Please sign in to comment.