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