From a9fe5b473c78761fcdc851bb185dd9836f7ec58b Mon Sep 17 00:00:00 2001 From: Jesse Brault Date: Thu, 15 May 2025 08:53:43 -0500 Subject: [PATCH] Delete old compile sketch files. --- src/compile/declared_type.rs | 10 --- src/compile/mod.rs | 164 ----------------------------------- src/compile/symbol.rs | 17 ---- src/compile/symbol_table.rs | 10 --- src/lib.rs | 1 - 5 files changed, 202 deletions(-) delete mode 100644 src/compile/declared_type.rs delete mode 100644 src/compile/mod.rs delete mode 100644 src/compile/symbol.rs delete mode 100644 src/compile/symbol_table.rs diff --git a/src/compile/declared_type.rs b/src/compile/declared_type.rs deleted file mode 100644 index 129d8d0..0000000 --- a/src/compile/declared_type.rs +++ /dev/null @@ -1,10 +0,0 @@ -pub enum DeclaredType { - Function(FunctionType), -} - -pub enum FunctionType { - StaticFunction, - ObjectFunction, - StaticPlatformFunction, - ObjectPlatformFunction, -} diff --git a/src/compile/mod.rs b/src/compile/mod.rs deleted file mode 100644 index 76f380a..0000000 --- a/src/compile/mod.rs +++ /dev/null @@ -1,164 +0,0 @@ -use crate::ast::{ - AssignExpression, BlockStatement, CallExpression, CompilationUnit, Expression, Fqn, - FunctionDeclaration, Identifier, LValue, ModuleLevelDeclaration, Statement, -}; -use crate::object_file::{DvmObjectFile, DvmPath}; -use crate::vm::function::DvmFunction; -use crate::vm::instruction::Instruction; -use declared_type::{DeclaredType, FunctionType}; -use std::rc::Rc; -use symbol_table::SymbolTable; - -mod declared_type; -mod symbol; -mod symbol_table; - -struct CompilationState { - fqn_part_stack: Vec, -} - -impl CompilationState { - fn push_fqn_identifier(&mut self, identifier: &Identifier) { - self.fqn_part_stack.push(identifier.clone()); - } - - fn pop_fqn_identifier(&mut self) { - self.fqn_part_stack.pop(); - } - - fn get_current_fqn(&self) -> Fqn { - Fqn::new(self.fqn_part_stack.clone()) - } -} - -struct CompilationContext { - source_file_name: String, - symbol_table: SymbolTable, -} - -fn compile_call_expression( - context: &CompilationContext, - call_expression: &CallExpression, - instructions: &mut Vec, -) { - match call_expression.receiver() { - Expression::LValue(lvalue) => { - let lvalue = &**lvalue; - if let LValue::Fqn(fqn) = lvalue { - let symbol = context.symbol_table.resolve(fqn); - match symbol.declared_type() { - DeclaredType::Function(function_type) => match function_type { - FunctionType::StaticFunction => { - instructions.push(Instruction::InvokeStatic { - function_name: Rc::new(convert_fqn(&fqn)), - source_code_location: call_expression - .source_code_location() - .clone(), - }); - } - _ => todo!(), - }, - } - } else { - todo!() - } - } - _ => todo!(), - } -} - -fn compile_assign_expression( - assign_expression: &AssignExpression, - instruction: &mut Vec, -) { - todo!() -} - -fn convert_statement( - context: &CompilationContext, - statement: &Statement, - instructions: &mut Vec, -) { - match statement { - Statement::CallStatement(call_expression) => { - compile_call_expression(context, call_expression, instructions); - } - Statement::AssignStatement(assign_expression) => { - compile_assign_expression(assign_expression, instructions); - } - } -} - -fn convert_block_statement( - context: &CompilationContext, - block_statement: &BlockStatement, -) -> Vec { - let mut instructions = vec![]; - for statement in block_statement.statements() { - convert_statement(context, statement, &mut instructions); - } - instructions -} - -fn convert_static_function( - compilation_state: &CompilationState, - context: &CompilationContext, - function_declaration: &FunctionDeclaration, -) -> DvmFunction { - let mut fqn = compilation_state.get_current_fqn(); - fqn.push_identifier(function_declaration.identifier().clone()); - - let instructions = convert_block_statement(context, function_declaration.block_statement()); - - DvmFunction::new( - &convert_fqn(&fqn), - &instructions, - function_declaration.source_code_location().clone(), - ) -} - -fn convert_fqn(fqn: &Fqn) -> String { - let mut as_string = String::new(); - let mut i = 0; - let identifiers = fqn.identifiers(); - while i < identifiers.len() { - as_string.push_str(identifiers[i].name()); - i += 1; - if i < identifiers.len() { - as_string.push_str("::"); - } - } - as_string -} - -fn make_path(file_name: &str, file_namespace: &Option) -> DvmPath { - if let Some(namespace) = file_namespace { - DvmPath::new(&convert_fqn(namespace), file_name) - } else { - DvmPath::new("", file_name) - } -} - -pub fn convert(file_name: &str, ast: CompilationUnit) -> DvmObjectFile { - let path = make_path(file_name, ast.namespace()); - let mut object_file = DvmObjectFile::new(path); - - let mut state = CompilationState { - fqn_part_stack: Vec::new(), - }; - let context = CompilationContext { - source_file_name: file_name.to_string(), - symbol_table: SymbolTable {}, - }; - - for declaration in ast.declarations() { - match declaration { - ModuleLevelDeclaration::Function(function_declaration) => { - let function = convert_static_function(&state, &context, function_declaration); - object_file.add_function(function); - } - _ => todo!("Unimplemented declaration {:?}", declaration), - } - } - object_file -} diff --git a/src/compile/symbol.rs b/src/compile/symbol.rs deleted file mode 100644 index 3a13dbe..0000000 --- a/src/compile/symbol.rs +++ /dev/null @@ -1,17 +0,0 @@ -use crate::ast::Fqn; -use crate::compile::declared_type::DeclaredType; - -pub struct Symbol { - fqn: Fqn, - declared_type: DeclaredType, -} - -impl Symbol { - pub fn fqn(&self) -> &Fqn { - &self.fqn - } - - pub fn declared_type(&self) -> &DeclaredType { - &self.declared_type - } -} diff --git a/src/compile/symbol_table.rs b/src/compile/symbol_table.rs deleted file mode 100644 index 3897afa..0000000 --- a/src/compile/symbol_table.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::ast::Fqn; -use crate::compile::symbol::Symbol; - -pub struct SymbolTable {} - -impl SymbolTable { - pub fn resolve(&self, fqn: &Fqn) -> Symbol { - todo!() - } -} diff --git a/src/lib.rs b/src/lib.rs index c0a8b56..55ec8d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![allow(warnings)] pub mod ast; -pub mod compile; pub mod module; pub mod object_file; pub mod parser;