Skip to content

Commit 914d0cd

Browse files
committed
[assembler] Move symbol table code out of eval.rs into symtab.rs.
1 parent e0f9d08 commit 914d0cd

File tree

6 files changed

+269
-259
lines changed

6 files changed

+269
-259
lines changed

assembler/src/asmlib/ast.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ use std::hash::Hash;
88
use base::charset::{subscript_char, superscript_char, Script};
99
use base::prelude::*;
1010

11-
use super::eval::{RcBlock, SymbolContext, SymbolDefinition, SymbolUse};
11+
use super::eval::RcBlock;
1212
use super::glyph;
1313
use super::span::*;
1414
use super::state::NumeralMode;
15-
use super::symbol::{SymbolName, SymbolOrHere};
15+
use super::symbol::{SymbolContext, SymbolName, SymbolOrHere};
16+
use super::symtab::SymbolDefinition;
1617
use super::types::*;
1718

19+
#[derive(Debug, PartialEq, Eq, Clone)]
20+
enum SymbolUse {
21+
Reference(SymbolContext),
22+
Definition(SymbolDefinition),
23+
Origin(SymbolName, BlockIdentifier),
24+
}
25+
1826
pub(crate) trait RcAllocator {
1927
fn allocate(&mut self, span: Span, value: Unsigned36Bit) -> Address;
2028
}
@@ -170,7 +178,7 @@ impl ArithmeticExpression {
170178
ArithmeticExpression { first, tail }
171179
}
172180

173-
pub(crate) fn symbol_uses(
181+
fn symbol_uses(
174182
&self,
175183
block_id: BlockIdentifier,
176184
block_offset: Unsigned18Bit,
@@ -251,7 +259,7 @@ pub(crate) enum ConfigValue {
251259
}
252260

253261
impl ConfigValue {
254-
pub(crate) fn symbol_uses(&self) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> {
262+
fn symbol_uses(&self) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> {
255263
match self {
256264
ConfigValue::Literal(_span, _value) => None,
257265
ConfigValue::Symbol(_span, SymbolOrHere::Here) => None,
@@ -288,7 +296,7 @@ impl From<SymbolOrLiteral> for Atom {
288296
}
289297

290298
impl Atom {
291-
pub(crate) fn symbol_uses(
299+
fn symbol_uses(
292300
&self,
293301
block_id: BlockIdentifier,
294302
block_offset: Unsigned18Bit,
@@ -408,7 +416,7 @@ pub(crate) enum SymbolOrLiteral {
408416
}
409417

410418
impl SymbolOrLiteral {
411-
pub(crate) fn symbol_uses(&self) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> {
419+
fn symbol_uses(&self) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> {
412420
let mut result: Vec<(SymbolName, Span, SymbolUse)> = Vec::with_capacity(1);
413421
match self {
414422
SymbolOrLiteral::Literal(_) => (),
@@ -445,7 +453,7 @@ pub(crate) enum InstructionFragment {
445453
}
446454

447455
impl InstructionFragment {
448-
pub(crate) fn symbol_uses(
456+
fn symbol_uses(
449457
&self,
450458
block_id: BlockIdentifier,
451459
block_offset: Unsigned18Bit,
@@ -572,7 +580,7 @@ impl Octal for Origin {
572580
}
573581

574582
impl Origin {
575-
pub(crate) fn symbol_uses(
583+
fn symbol_uses(
576584
&self,
577585
block_id: BlockIdentifier,
578586
) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> {
@@ -637,7 +645,7 @@ impl CommaDelimitedInstruction {
637645
}
638646
}
639647

640-
pub(crate) fn symbol_uses(
648+
fn symbol_uses(
641649
&self,
642650
block_id: BlockIdentifier,
643651
block_offset: Unsigned18Bit,
@@ -683,7 +691,7 @@ pub(crate) struct UntaggedProgramInstruction {
683691
}
684692

685693
impl UntaggedProgramInstruction {
686-
pub(crate) fn symbol_uses(
694+
fn symbol_uses(
687695
&self,
688696
block_id: BlockIdentifier,
689697
block_offset: Unsigned18Bit,
@@ -703,7 +711,7 @@ pub(crate) struct Tag {
703711
}
704712

705713
impl Tag {
706-
pub(crate) fn symbol_uses(
714+
fn symbol_uses(
707715
&self,
708716
block_id: BlockIdentifier,
709717
block_offset: Unsigned18Bit,
@@ -728,7 +736,7 @@ pub(crate) struct TaggedProgramInstruction {
728736
}
729737

730738
impl TaggedProgramInstruction {
731-
pub(crate) fn symbol_uses(
739+
fn symbol_uses(
732740
&self,
733741
block_id: BlockIdentifier,
734742
offset: Unsigned18Bit,
@@ -798,7 +806,7 @@ pub(crate) struct SourceFile {
798806
}
799807

800808
impl SourceFile {
801-
pub(crate) fn symbol_uses(&self) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> + '_ {
809+
fn symbol_uses(&self) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> + '_ {
802810
self.blocks
803811
.iter()
804812
.flat_map(|(block_id, block)| block.symbol_uses(*block_id))
@@ -882,7 +890,7 @@ impl Statement {
882890
}
883891
}
884892

885-
pub(crate) fn symbol_uses(
893+
fn symbol_uses(
886894
&self,
887895
block_id: BlockIdentifier,
888896
offset: Unsigned18Bit,
@@ -959,7 +967,7 @@ pub(crate) struct ManuscriptBlock {
959967
}
960968

961969
impl ManuscriptBlock {
962-
pub(crate) fn symbol_uses(
970+
fn symbol_uses(
963971
&self,
964972
block_id: BlockIdentifier,
965973
) -> impl Iterator<Item = (SymbolName, Span, SymbolUse)> {

assembler/src/asmlib/driver.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use chumsky::error::Rich;
1616
use tracing::{event, span, Level};
1717

1818
use super::ast::*;
19-
use super::eval::{BadSymbolDefinition, Evaluate, HereValue, RcBlock, SymbolDefinition};
19+
use super::eval::{Evaluate, HereValue, RcBlock};
2020
use super::lexer;
2121
use super::parser::parse_source_file;
2222
use super::span::*;
2323
use super::state::NumeralMode;
2424
use super::symbol::SymbolName;
2525
use super::symtab::{
26-
FinalSymbolDefinition, FinalSymbolTable, FinalSymbolType, LookupOperation, SymbolTable,
26+
BadSymbolDefinition, FinalSymbolDefinition, FinalSymbolTable, FinalSymbolType, LookupOperation,
27+
SymbolDefinition, SymbolTable,
2728
};
2829
use super::types::*;
2930
use base::prelude::{Address, IndexBy, Unsigned18Bit, Unsigned36Bit};

assembler/src/asmlib/driver/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ use super::super::ast::{
88
InstructionFragment, LiteralValue, LocatedBlock, ManuscriptBlock, PunchCommand, SourceFile,
99
Statement, TaggedProgramInstruction, UntaggedProgramInstruction,
1010
};
11-
use super::super::eval::{make_empty_rc_block_for_test, SymbolContext, SymbolLookup, SymbolValue};
11+
use super::super::eval::{make_empty_rc_block_for_test, SymbolLookup, SymbolValue};
1212
use super::super::span::*;
13-
use super::super::symbol::SymbolName;
13+
use super::super::symbol::{SymbolContext, SymbolName};
1414
use super::super::symtab::LookupOperation;
1515
use super::super::types::BlockIdentifier;
1616
use super::assemble_pass1;

0 commit comments

Comments
 (0)