move LinkDeclaration SourceRef to enum (like other variants)

This commit is contained in:
Leandro Pacheco
2024-02-05 19:21:23 -03:00
parent df14ab8be0
commit 36c3a78fe7
5 changed files with 8 additions and 14 deletions

View File

@@ -78,12 +78,7 @@ impl<T: FieldElement> TypeChecker<T> {
Err(e) => errors.extend(e),
}
}
MachineStatement::LinkDeclaration(LinkDeclaration {
source,
flag,
params,
to,
}) => {
MachineStatement::LinkDeclaration(source, LinkDeclaration { flag, params, to }) => {
links.push(LinkDefinitionStatement {
source,
flag,

View File

@@ -383,7 +383,7 @@ impl<T: Clone> Machine<T> {
MachineStatement::Degree(_, _)
| MachineStatement::Submachine(_, _, _)
| MachineStatement::InstructionDeclaration(_, _, _)
| MachineStatement::LinkDeclaration(_)
| MachineStatement::LinkDeclaration(_, _)
| MachineStatement::FunctionDeclaration(_, _, _, _)
| MachineStatement::OperationDeclaration(_, _, _, _) => Box::new(empty()),
}))
@@ -455,14 +455,13 @@ pub enum MachineStatement<T> {
Submachine(SourceRef, SymbolPath, String),
RegisterDeclaration(SourceRef, String, Option<RegisterFlag>),
InstructionDeclaration(SourceRef, String, Instruction<T>),
LinkDeclaration(LinkDeclaration<T>),
LinkDeclaration(SourceRef, LinkDeclaration<T>),
FunctionDeclaration(SourceRef, String, Params<T>, Vec<FunctionStatement<T>>),
OperationDeclaration(SourceRef, String, OperationId<T>, Params<T>),
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone)]
pub struct LinkDeclaration<T> {
pub source: SourceRef,
pub flag: Expression<T>,
pub params: Params<T>,
pub to: CallableRef,

View File

@@ -176,7 +176,7 @@ impl<T: Display> Display for MachineStatement<T> {
MachineStatement::InstructionDeclaration(_, name, instruction) => {
write!(f, "instr {}{}", name, instruction)
}
MachineStatement::LinkDeclaration(link) => {
MachineStatement::LinkDeclaration(_, link) => {
write!(f, "{link}")
}
MachineStatement::FunctionDeclaration(_, name, params, statements) => {

View File

@@ -247,8 +247,8 @@ mod test {
// helper function to clear SourceRef's inside the AST so we can compare for equality
fn asm_clear_source_refs<T>(ast: &mut ASMProgram<T>) {
use powdr_ast::parsed::asm::{
ASMModule, FunctionStatement, Instruction, InstructionBody, LinkDeclaration, Machine,
MachineStatement, Module, ModuleStatement, SymbolDefinition, SymbolValue,
ASMModule, FunctionStatement, Instruction, InstructionBody, Machine, MachineStatement,
Module, ModuleStatement, SymbolDefinition, SymbolValue,
};
fn clear_machine_stmt<T>(stmt: &mut MachineStatement<T>) {
@@ -257,7 +257,7 @@ mod test {
| MachineStatement::Submachine(s, _, _)
| MachineStatement::RegisterDeclaration(s, _, _)
| MachineStatement::OperationDeclaration(s, _, _, _)
| MachineStatement::LinkDeclaration(LinkDeclaration { source: s, .. }) => {
| MachineStatement::LinkDeclaration(s, _) => {
*s = SourceRef::unknown();
}
MachineStatement::Pil(s, stmt) => {

View File

@@ -252,7 +252,7 @@ pub Instruction: Instruction<T> = {
}
pub LinkDeclaration: MachineStatement<T> = {
<start:@L> "link" <flag:Expression> <params:Params> "=" <to:CallableRef> ";" => MachineStatement::LinkDeclaration(LinkDeclaration { source: ctx.source_ref(start), flag, params, to })
<start:@L> "link" <flag:Expression> <params:Params> "=" <to:CallableRef> ";" => MachineStatement::LinkDeclaration(ctx.source_ref(start), LinkDeclaration { flag, params, to })
}
pub InstructionBody: InstructionBody<T> = {