feat: Add purr core
This commit is contained in:
parent
62419f50f2
commit
0d100086f6
2 changed files with 116 additions and 0 deletions
4
purr_core/Cargo.toml
Normal file
4
purr_core/Cargo.toml
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
[package]
|
||||||
|
name = "purr_core"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
112
purr_core/src/lib.rs
Normal file
112
purr_core/src/lib.rs
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
type StructID = usize;
|
||||||
|
type EnumID = usize;
|
||||||
|
type GenericID = usize;
|
||||||
|
type EffectID = usize;
|
||||||
|
|
||||||
|
pub type IRString = Rc<str>;
|
||||||
|
|
||||||
|
pub struct IRFunctionType {
|
||||||
|
pub params: Vec<IRType>,
|
||||||
|
pub result: Box<IRType>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum IRType {
|
||||||
|
Integer,
|
||||||
|
Float,
|
||||||
|
String,
|
||||||
|
Bool,
|
||||||
|
|
||||||
|
Array(Box<IRType>),
|
||||||
|
Struct(StructID),
|
||||||
|
Enum(EnumID),
|
||||||
|
|
||||||
|
Func(IRFunctionType),
|
||||||
|
|
||||||
|
Unit,
|
||||||
|
Void,
|
||||||
|
|
||||||
|
Generic(GenericID),
|
||||||
|
|
||||||
|
Effect(EffectID, Box<IRType>),
|
||||||
|
}
|
||||||
|
|
||||||
|
type StructFieldID = usize;
|
||||||
|
type EnumFieldID = usize;
|
||||||
|
|
||||||
|
pub struct IRStructField {
|
||||||
|
pub id: StructFieldID,
|
||||||
|
pub ty: IRType,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum IREnumFieldPayload {
|
||||||
|
Unit,
|
||||||
|
Single(IRType),
|
||||||
|
Struct(Vec<IRStructField>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct IREnumField {
|
||||||
|
pub id: EnumFieldID,
|
||||||
|
pub payload: IREnumFieldPayload,
|
||||||
|
}
|
||||||
|
|
||||||
|
type FunctionID = usize;
|
||||||
|
|
||||||
|
pub enum IRDeclaration {
|
||||||
|
Func {
|
||||||
|
id: FunctionID,
|
||||||
|
ty: IRFunctionType,
|
||||||
|
body: IRBlock,
|
||||||
|
},
|
||||||
|
|
||||||
|
Struct {
|
||||||
|
id: StructID,
|
||||||
|
fields: Vec<IRStructField>,
|
||||||
|
},
|
||||||
|
|
||||||
|
Enum {
|
||||||
|
id: EnumID,
|
||||||
|
fields: Vec<IREnumField>,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
type VariableID = usize;
|
||||||
|
|
||||||
|
pub enum IRLiteral {
|
||||||
|
Integer(isize),
|
||||||
|
Float(f32),
|
||||||
|
String(IRString),
|
||||||
|
Bool(bool),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum IRAtom {
|
||||||
|
Literal(IRLiteral),
|
||||||
|
Variable(VariableID),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum IRExpressionKind {
|
||||||
|
Atom(IRAtom),
|
||||||
|
Call(FunctionID, Vec<IRExpression>),
|
||||||
|
If {
|
||||||
|
condition: Box<IRAtom>,
|
||||||
|
then_branch: IRBlock,
|
||||||
|
else_branch: IRBlock,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct IRExpression {
|
||||||
|
pub expr: Box<IRExpressionKind>,
|
||||||
|
pub ty: IRType,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum IRStatement {
|
||||||
|
Define(VariableID, IRExpression),
|
||||||
|
Expression(IRExpression),
|
||||||
|
Return(IRExpression),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct IRBlock {
|
||||||
|
pub statements: Vec<IRStatement>,
|
||||||
|
pub result: Option<IRExpression>,
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue