basic jit

This commit is contained in:
Romain Paquet 2024-03-08 17:38:23 +01:00
parent 374daaff7f
commit 511be952aa
16 changed files with 971 additions and 495 deletions

View file

@ -1,10 +1,17 @@
use crate::typing::Type;
use std::path::Path;
pub mod expr;
pub mod typed;
pub mod untyped;
pub use expr::Expr;
#[derive(Debug, PartialEq, Clone)]
pub enum BinaryOperator {
// Logic
And,
Or,
// Arithmetic
Add,
Sub,
Mul,
@ -14,13 +21,19 @@ pub enum BinaryOperator {
NotEqual,
}
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum UnaryOperator {
Not,
}
pub type Identifier = String;
#[derive(Debug, PartialEq, Clone)]
#[derive(Debug, PartialEq)]
pub struct Location {
pub line_col: (usize, usize),
}
#[derive(Debug, PartialEq, Clone, Default)]
pub struct ModulePath {
components: Vec<String>,
}
@ -65,3 +78,75 @@ impl From<&str> for ModulePath {
#[derive(Eq, PartialEq, Debug)]
pub struct Import(pub String);
#[derive(Debug, PartialEq)]
pub enum Statement {
DeclareStatement(Identifier, Box<Expr>),
AssignStatement(Identifier, Box<Expr>),
ReturnStatement(Option<Expr>),
CallStatement(Box<Call>),
UseStatement(Box<Import>),
IfStatement(Box<Expr>, Box<Block>),
WhileStatement(Box<Expr>, Box<Block>),
}
#[derive(Debug, PartialEq)]
pub struct Block {
pub statements: Vec<Statement>,
pub value: Option<Expr>,
pub typ: Type,
}
impl Block {
pub fn empty() -> Block {
Block {
typ: Type::Unit,
statements: Vec::with_capacity(0),
value: None,
}
}
}
#[derive(Debug, PartialEq)]
pub enum Definition {
FunctionDefinition(FunctionDefinition),
}
#[derive(Debug, PartialEq)]
pub struct FunctionDefinition {
pub name: Identifier,
pub parameters: Vec<Parameter>,
pub return_type: Option<Type>,
pub body: Box<Block>,
pub location: Location,
}
#[derive(Debug, PartialEq, Default)]
pub struct Module {
pub file: Option<std::path::PathBuf>,
pub path: ModulePath,
pub functions: Vec<FunctionDefinition>,
pub imports: Vec<Import>,
}
impl Module {
pub fn new(path: ModulePath) -> Self {
Self {
path,
..Default::default()
}
}
}
#[derive(Debug, PartialEq)]
pub struct Call {
pub callee: Box<Expr>,
pub args: Vec<Expr>,
pub typ: Type,
}
#[derive(Debug, PartialEq)]
pub struct Parameter {
pub name: Identifier,
pub typ: Type,
}