Skip to content

Commit

Permalink
refactor: move to project root
Browse files Browse the repository at this point in the history
  • Loading branch information
aripiprazole committed Nov 22, 2023
1 parent 13fa555 commit e62b383
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 507 deletions.
303 changes: 1 addition & 302 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[workspace.package]
[package]
name = "soft"
edition = "2021"
authors = ["Gabrielle Guimarães de Oliveira", "Sofia da Silva Rodrigues"]
description = "The simpliest lisp compiler"
documentation = "https://github.com/aripiprazole/soft"
version = "0.3.0"

[workspace]
members = ["softc"]

resolver = "1"
[dependencies]
bupropion = "0.0.18"
clap = {version = "4.4.7", features = ["derive"]}
eyre = "0.6.8"
libc = "0.2.149"
miette = "5.10.0"
rustyline = {version = "12.0.0", features = ["derive"]}
thiserror = "1.0.50"
19 changes: 0 additions & 19 deletions softc/Cargo.toml

This file was deleted.

116 changes: 0 additions & 116 deletions softc/src/codegen.rs

This file was deleted.

31 changes: 0 additions & 31 deletions softc/src/ffi.rs

This file was deleted.

File renamed without changes.
2 changes: 0 additions & 2 deletions softc/src/lib.rs → src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use std::fmt::Display;
pub mod semantic;
pub mod runtime;
pub mod allocator;
pub mod codegen;
pub mod parser;
pub mod ffi;

/// Term is a recursive data structure that represents a list of terms, an atom, an identifier,
/// or an integer.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
47 changes: 15 additions & 32 deletions softc/src/semantic.rs → src/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ define_ast!(Expression, {
Fun, // (fun (a b) (+ a b))
List, // (a b c) or (list a b c)
Appl, // (a b c) or (apply a b c)
Define, // (define a 123)
MacroDefine, // (macro-define a (fun (a b) (+ a b))
Def, // (define a 123)
DefMacro, // (macro-define a (fun (a b) (+ a b))
Quote, // '(fun (a b) (+ a b))
Literal // 123 | "bla" | :bla | bla
});

define_builtin!(MacroDefine, "macro-define", 2);
define_builtin!(Define, "define", 2);
define_builtin!(Fun, "fun", 2);
define_builtin!(DefMacro, "defmacro*", 2);
define_builtin!(Def, "def*", 2);
define_builtin!(Fun, "fun*", 2);
define_builtin!(Quote, "'", 2);
define_builtin!(List, "list");
define_builtin!(Appl, "apply");
Expand Down Expand Up @@ -83,7 +83,7 @@ pub mod appl {
pub mod define {
pub use super::*;

impl Define {
impl Def {
/// Returns the name of the definition.
pub fn name(&self) -> Result<Expression> {
self.0
Expand All @@ -106,7 +106,7 @@ pub mod define {
pub mod macro_define {
pub use super::*;

impl MacroDefine {
impl DefMacro {
/// Returns the name of the definition.
pub fn name(&self) -> Result<Expression> {
self.0
Expand Down Expand Up @@ -203,37 +203,21 @@ impl TryFrom<Term> for Expression {
type Error = SemanticError;

fn try_from(value: Term) -> Result<Self, Self::Error> {
try_new!(value, [
Define,
MacroDefine,
Fun,
Appl,
List,
Quote,
Literal
])
.ok_or(SemanticError::InvalidExpression)
DefMacro::try_new(value.clone())
.or_else(|_| Def::try_new(value.clone()))
.or_else(|_| Fun::try_new(value.clone()))
.or_else(|_| Quote::try_new(value.clone()))
.or_else(|_| Appl::try_new(value.clone()))
.or_else(|_| List::try_new(value.clone()))
.or_else(|_| Literal::try_new(value.clone()))?
.ok_or(SemanticError::InvalidExpression)
}
}

pub trait ExpressionKind: Sized {
fn try_new(term: Term) -> Result<Option<Expression>>;
}

/// Pipes try new functions to each other, it's useful to create a try_from function for enums
/// that have multiple variants.
macro_rules! try_new {
($target:expr, [$($value:ident),+]) => {{
use crate::semantic::ExpressionKind;
let mut value = None;
$(value = match value {
Some(value) => Some(value),
None => $value::try_new($target.clone())?,
};)+
value
}};
}

macro_rules! define_builtin {
($name:ident, $keyword:expr, $length:expr) => {
impl $crate::semantic::ExpressionKind for $name {
Expand Down Expand Up @@ -305,4 +289,3 @@ macro_rules! define_ast {

use define_ast;
use define_builtin;
use try_new;

0 comments on commit e62b383

Please sign in to comment.