This commit is contained in:
Nilton Constantino
2026-01-28 19:16:41 +00:00
parent 9515bddce8
commit 127ec789bc
8 changed files with 86 additions and 14 deletions
@@ -161,6 +161,13 @@ impl<'a> BytecodeEmitter<'a> {
asm_instrs.push(Asm::Op(OpCode::Syscall, vec![Operand::U32(*id)]));
}
InstrKind::FrameSync => asm_instrs.push(Asm::Op(OpCode::FrameSync, vec![])),
InstrKind::Alloc => asm_instrs.push(Asm::Op(OpCode::Alloc, vec![])),
InstrKind::LoadRef(offset) => {
asm_instrs.push(Asm::Op(OpCode::LoadRef, vec![Operand::U32(*offset)]));
}
InstrKind::StoreRef(offset) => {
asm_instrs.push(Asm::Op(OpCode::StoreRef, vec![Operand::U32(*offset)]));
}
}
let end_idx = asm_instrs.len();
@@ -179,8 +179,15 @@ impl<'a> TypeChecker<'a> {
// In v0, we assume target is a gate. We bind the inner type to the binding.
let inner_ty = match target_ty {
PbsType::Contract(name) if name.starts_with("Gate<") => {
// Try to extract type name from Gate<TypeName>
PbsType::Void // Simplified
// Extract type name from Gate<TypeName>
let inner_name = &name[5..name.len()-1];
match inner_name {
"int" => PbsType::Int,
"float" => PbsType::Float,
"bool" => PbsType::Bool,
"string" => PbsType::String,
_ => PbsType::Void, // Should be PbsType::Struct(inner_name) if we had better info
}
}
_ => PbsType::Void
};
+9
View File
@@ -136,4 +136,13 @@ pub enum InstrKind {
Syscall(u32),
/// Special instruction to synchronize with the hardware frame clock.
FrameSync,
// --- HIP / Memory ---
/// Allocates memory on the heap. Pops size from stack.
Alloc,
/// Reads from heap at reference + offset. Pops reference, pushes value.
LoadRef(u32),
/// Writes to heap at reference + offset. Pops reference and value.
StoreRef(u32),
}
+5 -5
View File
@@ -1,7 +1,7 @@
//! # Prometeu Compiler
//!
//! This crate provides the official compiler for the Prometeu ecosystem.
//! It translates high-level source code (primarily TypeScript/JavaScript) into
//! It translates high-level source code (primarily Prometeu Base Script - PBS) into
//! Prometeu ByteCode (.pbc), which runs on the Prometeu Virtual Machine.
//!
//! ## Architecture Overview:
@@ -9,8 +9,8 @@
//! The compiler follows a multi-stage pipeline:
//!
//! 1. **Frontend (Parsing & Analysis)**:
//! - Uses the `oxc` parser to generate an Abstract Syntax Tree (AST).
//! - Performs semantic analysis and validation (e.g., ensuring only supported TS features are used).
//! - Uses the PBS parser to generate an Abstract Syntax Tree (AST).
//! - Performs semantic analysis and validation.
//! - Lowers the AST into the **Intermediate Representation (IR)**.
//! - *Example*: Converting a `a + b` expression into IR instructions like `Push(a)`, `Push(b)`, `Add`.
//!
@@ -30,7 +30,7 @@
//!
//! ```bash
//! # Build a project from a directory
//! prometeu-compiler build ./my-game --entry ./src/main.ts --out ./game.pbc
//! prometeu-compiler build ./my-game --entry ./src/main.pbs --out ./game.pbc
//! ```
//!
//! ## Programmatic Entry Point:
@@ -67,7 +67,7 @@ pub enum Commands {
/// Path to the project root directory.
project_dir: PathBuf,
/// Explicit path to the entry file (defaults to src/main.ts).
/// Explicit path to the entry file (defaults to src/main.pbs).
#[arg(short, long)]
entry: Option<PathBuf>,
@@ -71,11 +71,10 @@ pub fn lower_function(core_func: &ir_core::Function) -> Result<ir::Function> {
ir_core::Instr::And => ir::InstrKind::And,
ir_core::Instr::Or => ir::InstrKind::Or,
ir_core::Instr::Not => ir::InstrKind::Not,
ir_core::Instr::Alloc | ir_core::Instr::Free | ir_core::Instr::ReadGate | ir_core::Instr::WriteGate => {
// HIP effects are not yet supported in VM IR, so we emit Nop or similar.
// For now, let's use Nop.
ir::InstrKind::Nop
}
ir_core::Instr::Alloc => ir::InstrKind::Alloc,
ir_core::Instr::ReadGate => ir::InstrKind::LoadRef(0),
ir_core::Instr::WriteGate => ir::InstrKind::StoreRef(0),
ir_core::Instr::Free => ir::InstrKind::Nop,
};
vm_func.body.push(ir::Instruction::new(kind, None));
}