Delete old compile sketch files.

This commit is contained in:
Jesse Brault 2025-05-15 08:53:43 -05:00
parent c980eb8a72
commit a9fe5b473c
5 changed files with 0 additions and 202 deletions

View File

@ -1,10 +0,0 @@
pub enum DeclaredType {
Function(FunctionType),
}
pub enum FunctionType {
StaticFunction,
ObjectFunction,
StaticPlatformFunction,
ObjectPlatformFunction,
}

View File

@ -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<Identifier>,
}
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<Instruction>,
) {
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<Instruction>,
) {
todo!()
}
fn convert_statement(
context: &CompilationContext,
statement: &Statement,
instructions: &mut Vec<Instruction>,
) {
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<Instruction> {
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<Fqn>) -> 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
}

View File

@ -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
}
}

View File

@ -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!()
}
}

View File

@ -1,6 +1,5 @@
#![allow(warnings)]
pub mod ast;
pub mod compile;
pub mod module;
pub mod object_file;
pub mod parser;