From 36e28ae4a964e03bf7832b8462fbcb188875ed73 Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Sat, 4 Oct 2025 21:32:33 -0500 Subject: [PATCH] Sketching out IR structs/enums. --- src/ir/mod.rs | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 200 insertions(+) create mode 100644 src/ir/mod.rs diff --git a/src/ir/mod.rs b/src/ir/mod.rs new file mode 100644 index 0000000..e0f89df --- /dev/null +++ b/src/ir/mod.rs @@ -0,0 +1,199 @@ +pub enum DvmIr { + Struct(Box), + Function(DvmIrFunction), + Const(DvmIrConst), +} + +pub struct DvmIrStruct { + name: String, + kind: Box, + is_public: bool, + members: Vec> +} + +pub struct DvmIrStructMember { + name: String, + kind: Box, + is_public: bool, + is_mut: bool, +} + +pub enum DvmIrKind { + Primitive(Box), + Struct(Box), +} + +pub enum DvmIrPrimitiveKind { + I8, + I16, + I32, + I64, + I128, + ISize, + U8, + U16, + U32, + U64, + U128, + USize, + Boolean, + Array(Box), + String, + Closure(Box), + Ref(Box), + Void, +} + +pub struct DvmIrStructKind { + name: String, +} + +pub struct DvmIrClosureKind { + captures_name: String, + parameters: Vec>, + return_type: Box, +} + +pub struct DvmIrFunction { + name: String, + parameters: Vec>, + return_type: Box, + statements: Vec>, +} + +pub enum DvmIrStatement { + Alloc(DvmIrAlloc), + Call(DvmIrCallStmt), + Ret(DvmIrRet), + Assign(DvmIrAssign), + MakeClosure(DvmIrMakeClosure), + Drop(DvmIrDrop), +} + +pub enum DvmIrAllocable { + Struct(Box), + Array(Box), +} + +pub enum DvmIrArrayKind { + StaticSize(Box), + DynamicSize(Box) +} + +pub struct DvmIrStaticArrayKind { + inner_kind: Box, + size: usize, +} + +pub struct DvmIrDynamicArrayKind { + inner_kind: Box, + size_expr: Box +} + +pub struct DvmIrAlloc { + declared_kind: Box, + name: String, + kind_to_alloc: Box, +} + +pub enum DvmIrConst { + String(DvmIrStringConst), + StringArray(DvmIrStringArrayConst), +} + +pub struct DvmIrStringConst { + name: String, + value: String, +} + +pub struct DvmIrStringArrayConst { + name: String, + value: Vec, +} + +pub enum DvmIrExpr { + Call(Box), + Variable(Box), + ConstRef(Box), + Literal(Box) +} + +pub struct DvmIrVariable { + name: String, +} + +pub struct DvmIrConstRef { + name: String, +} + +pub enum DvmIrLiteral { + I8(i8), + I16(i16), + I32(i32), + I64(i64), + I128(i128), + ISize(isize), + U8(u8), + U16(u16), + U32(u32), + U64(u64), + U128(u128), + USize(usize), + Boolean(bool), +} + +pub struct DvmIrCallStmt { + declared_type: Box, + name: String, + call_expr: Box, +} + +pub struct DvmIrCallExpr { + name: String, + arguments: Vec>, +} + +pub struct DvmIrAssign { + lhs: Box, + rhs: Box +} + +pub struct DvmIrAssignLhs { + base: Box, + suffixes: Vec> +} + +pub enum DvmIrAssignLhsSuffix { + Index(DvmIrAssignLhsIndex), + Property(DvmIrAssignLhsProperty) +} + +pub struct DvmIrAssignLhsIndex { + expr: Box, +} + +pub struct DvmIrAssignLhsProperty { + name: String, +} + +pub struct DvmIrRet { + value: Box +} + +pub enum DvmIrReturnable { + Variable(DvmIrVariable), + Literal(DvmIrLiteral) +} + +pub struct DvmIrMakeClosure { + captures_kind: Option>, + parameters: Vec>, + return_type: Box, + name: String, + fn_name: String, + captures_variable: Box, +} + +pub struct DvmIrDrop { + variable: Box, +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index e34be93..930efd2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,3 +11,4 @@ pub mod parser; pub mod std_core; pub mod util; pub mod vm; +pub mod ir;