-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ir,lexer): fix build errors, expand ir types
- Loading branch information
1 parent
3ccb55c
commit 0b2af02
Showing
14 changed files
with
183 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,2 @@ | ||
[package] | ||
name = "maple" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
|
||
[workspace] | ||
members = ["crates/*"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use crate::expr::Expr; | ||
|
||
pub struct Block { | ||
pub code: Vec<Box<dyn Expr>>, | ||
} | ||
|
||
impl Expr for Block {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
use std::iter::Map; | ||
use crate::block::Block; | ||
use crate::types::Type; | ||
use crate::values::Value; | ||
|
||
pub struct Closure<'a> { | ||
pub name: &'a str, | ||
pub closed_values: Map<String, Box<dyn Value<dyn Type>>>, | ||
pub body: Block, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub trait Expr {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
mod types; | ||
mod values; | ||
mod prototype; | ||
|
||
pub fn add(left: usize, right: usize) -> usize { | ||
left + right | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
} | ||
} | ||
pub mod types; | ||
pub mod values; | ||
pub mod prototype; | ||
pub mod closure; | ||
pub mod block; | ||
pub mod variable; | ||
pub mod expr; | ||
pub mod tuple; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
use std::collections::HashMap; | ||
use crate::closure::Closure; | ||
use crate::types::Type; | ||
use crate::values::Value; | ||
|
||
pub struct Prototype <T : Type, V : Value<T>> { | ||
value: V, | ||
pub struct PrototypeMethod<'a> { | ||
closure: &'a mut Closure<'a>, | ||
} | ||
|
||
impl<'a> PrototypeMethod<'a> { | ||
pub fn new(closure: &'a mut Closure<'a>) -> Self { | ||
Self { | ||
closure, | ||
} | ||
} | ||
|
||
pub fn get_name(&self) -> String { | ||
self.closure.name.to_owned() | ||
} | ||
} | ||
|
||
pub struct Prototype<'a, T : Type, V : Value<T>> { | ||
pub(crate) value: V, | ||
pub(crate) methods: HashMap<String, &'a mut PrototypeMethod<'a>>, | ||
pub(crate) associated_type: T, | ||
} | ||
|
||
impl<'a, T : Type, V : Value<T>> Prototype<'a, T, V> { | ||
pub fn add_method(mut self, method: &'a mut PrototypeMethod<'a>) -> Result<(), String> { | ||
let method_name = method.get_name().to_owned(); | ||
if self.methods.contains_key(&method_name) { | ||
return Err(format!("Method with name '{}' already exists for type {}", &method_name, self.associated_type.name())); | ||
} | ||
self.methods.insert(method_name, method); | ||
Ok(()) | ||
} | ||
} | ||
|
||
pub trait PrototypeDefinition<T : Type, V : Value<T>> { | ||
fn build_proto<'a>(self, _type: T) -> Prototype<'a, T, V>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
use std::collections::HashMap; | ||
use std::marker::PhantomData; | ||
use std::ops::Index; | ||
use crate::expr::Expr; | ||
use crate::prototype::{Prototype, PrototypeDefinition}; | ||
use crate::types::{Type, TypeInfo}; | ||
use crate::values::Value; | ||
|
||
type TupleInnerValue = Box<dyn Value<Box<dyn Type>>>; | ||
|
||
pub struct TupleValue { | ||
pub size: i8, | ||
pub values: Vec<TupleInnerValue>, | ||
pub _type: TupleDefinition, | ||
} | ||
|
||
impl TypeInfo<TupleDefinition> for TupleValue { | ||
fn get_type(self) -> TupleDefinition { | ||
self._type | ||
} | ||
} | ||
|
||
impl Value<TupleDefinition> for TupleValue {} | ||
|
||
impl Index<usize> for TupleValue { | ||
type Output = TupleInnerValue; | ||
|
||
fn index(&self, index: usize) -> &Self::Output { | ||
&self.values[index] | ||
} | ||
} | ||
|
||
pub struct TupleDefinition { | ||
pub type_name: String, | ||
pub size: i8, | ||
pub shape: Vec<Box<dyn Type>>, | ||
} | ||
|
||
impl Expr for TupleDefinition {} | ||
|
||
impl Type for TupleDefinition { | ||
fn name(self) -> String { | ||
self.type_name | ||
} | ||
} | ||
|
||
/// | ||
/// | ||
/// # Type Arguments | ||
/// `T` The Tuple type this prototype definition is associated with | ||
pub struct TuplePrototypeDefinition<T : Type, V> where V : Value<T> { | ||
recipient: V, | ||
type_name: String, | ||
__marker: PhantomData<T>, | ||
} | ||
|
||
impl<T : Type, V : Value<T>> Expr for TuplePrototypeDefinition<T, V> {} | ||
|
||
impl<T : Type, V : Value<T>> PrototypeDefinition<T, V> for TuplePrototypeDefinition<T, V> { | ||
fn build_proto<'a>(self, _type: T) -> Prototype<'a, T, V> { | ||
Prototype { | ||
value: self.recipient, | ||
associated_type: _type, | ||
methods: HashMap::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<T: Type, V: Value<T>> TuplePrototypeDefinition<T, V> { | ||
pub fn new(recipient: V, _type: T) -> Self { | ||
Self { | ||
recipient, | ||
type_name: _type.name(), | ||
__marker: PhantomData::default(), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::expr::Expr; | ||
use crate::types::Type; | ||
use crate::values::Value; | ||
|
||
pub enum VariableMetaType { | ||
Static, | ||
} | ||
|
||
pub struct VariableDeclaration<T : Type, V : Value<T>> { | ||
pub meta_type: VariableMetaType, | ||
pub _type: T, | ||
pub value: V, | ||
} | ||
|
||
impl<T : Type, V : Value<T>> Expr for VariableDeclaration<T, V> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters