Add AST -> MIR for custom binops
This commit is contained in:
parent
5ef329d570
commit
974c7e98f1
@ -212,11 +212,11 @@ pub enum TopLevelStatement {
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BinopDefinition {
|
||||
lhs: (String, Type),
|
||||
op: BinaryOperator,
|
||||
rhs: (String, Type),
|
||||
return_ty: Type,
|
||||
block: Block,
|
||||
pub lhs: (String, Type),
|
||||
pub op: BinaryOperator,
|
||||
pub rhs: (String, Type),
|
||||
pub return_ty: Type,
|
||||
pub block: Block,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
@ -23,6 +23,7 @@ impl ast::Module {
|
||||
let mut imports = Vec::new();
|
||||
let mut functions = Vec::new();
|
||||
let mut typedefs = Vec::new();
|
||||
let mut binops = Vec::new();
|
||||
|
||||
use ast::TopLevelStatement::*;
|
||||
for stmt in &self.top_level_statements {
|
||||
@ -97,13 +98,28 @@ impl ast::Module {
|
||||
};
|
||||
typedefs.push(def);
|
||||
}
|
||||
BinopDefinition(binop_definition) => todo!(),
|
||||
BinopDefinition(ast::BinopDefinition {
|
||||
lhs,
|
||||
op,
|
||||
rhs,
|
||||
return_ty,
|
||||
block,
|
||||
}) => {
|
||||
binops.push(mir::BinopDefinition {
|
||||
lhs: (lhs.0.clone(), lhs.1 .0.into_mir(module_id)),
|
||||
op: op.mir(),
|
||||
rhs: (rhs.0.clone(), rhs.1 .0.into_mir(module_id)),
|
||||
return_ty: return_ty.0.into_mir(module_id),
|
||||
block: block.into_mir(module_id),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mir::Module {
|
||||
name: self.name.clone(),
|
||||
module_id: module_id,
|
||||
binop_defs: binops,
|
||||
imports,
|
||||
functions,
|
||||
path: self.path.clone(),
|
||||
|
@ -365,6 +365,15 @@ pub enum TypeDefinitionKind {
|
||||
Struct(StructType),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct BinopDefinition {
|
||||
pub lhs: (String, TypeKind),
|
||||
pub op: BinaryOperator,
|
||||
pub rhs: (String, TypeKind),
|
||||
pub return_ty: TypeKind,
|
||||
pub block: Block,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Module {
|
||||
pub name: String,
|
||||
@ -372,6 +381,7 @@ pub struct Module {
|
||||
pub imports: Vec<Import>,
|
||||
pub functions: Vec<FunctionDefinition>,
|
||||
pub typedefs: Vec<TypeDefinition>,
|
||||
pub binop_defs: Vec<BinopDefinition>,
|
||||
pub path: Option<PathBuf>,
|
||||
pub tokens: Vec<FullToken>,
|
||||
pub is_main: bool,
|
||||
|
Loading…
Reference in New Issue
Block a user