diff --git a/purr_core/Cargo.toml b/purr_core/Cargo.toml new file mode 100644 index 0000000..720a8c3 --- /dev/null +++ b/purr_core/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "purr_core" +version = "0.1.0" +edition = "2024" diff --git a/purr_core/src/lib.rs b/purr_core/src/lib.rs new file mode 100644 index 0000000..6e21d2c --- /dev/null +++ b/purr_core/src/lib.rs @@ -0,0 +1,112 @@ +use std::rc::Rc; + +type StructID = usize; +type EnumID = usize; +type GenericID = usize; +type EffectID = usize; + +pub type IRString = Rc; + +pub struct IRFunctionType { + pub params: Vec, + pub result: Box, +} + +pub enum IRType { + Integer, + Float, + String, + Bool, + + Array(Box), + Struct(StructID), + Enum(EnumID), + + Func(IRFunctionType), + + Unit, + Void, + + Generic(GenericID), + + Effect(EffectID, Box), +} + +type StructFieldID = usize; +type EnumFieldID = usize; + +pub struct IRStructField { + pub id: StructFieldID, + pub ty: IRType, +} + +pub enum IREnumFieldPayload { + Unit, + Single(IRType), + Struct(Vec), +} + +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, + }, + + Enum { + id: EnumID, + fields: Vec, + }, +} + +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), + If { + condition: Box, + then_branch: IRBlock, + else_branch: IRBlock, + }, +} + +pub struct IRExpression { + pub expr: Box, + pub ty: IRType, +} + +pub enum IRStatement { + Define(VariableID, IRExpression), + Expression(IRExpression), + Return(IRExpression), +} + +pub struct IRBlock { + pub statements: Vec, + pub result: Option, +}