Skip to content

Commit 37b2508

Browse files
committed
[assembler] Rename SymbolLookupFailure to EvaluationFailure.
1 parent 1a160d2 commit 37b2508

File tree

4 files changed

+47
-48
lines changed

4 files changed

+47
-48
lines changed

assembler/src/asmlib/ast.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use base::u18;
2727

2828
use super::collections::OneOrMore;
2929
use super::eval::{
30-
Evaluate, EvaluationContext, HereValue, ScopeIdentifier, SymbolLookupFailure,
31-
symbol_name_lookup,
30+
Evaluate, EvaluationContext, EvaluationFailure, HereValue, ScopeIdentifier, symbol_name_lookup,
3231
};
3332
use super::glyph;
3433
use super::listing::{Listing, ListingLine};
@@ -424,7 +423,7 @@ fn fold_step<R: RcUpdater>(
424423
(binop, right): &(Operator, SignedAtom),
425424
ctx: &mut EvaluationContext<R>,
426425
scope: ScopeIdentifier,
427-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
426+
) -> Result<Unsigned36Bit, EvaluationFailure> {
428427
let right: Unsigned36Bit = right.evaluate(ctx, scope)?;
429428
Ok(ArithmeticExpression::eval_binop(acc, binop, right))
430429
}

assembler/src/asmlib/ast/asteval.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ impl Evaluate for LiteralValue {
66
&self,
77
_ctx: &mut EvaluationContext<R>,
88
_scope: ScopeIdentifier,
9-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
9+
) -> Result<Unsigned36Bit, EvaluationFailure> {
1010
Ok(self.value())
1111
}
1212
}
@@ -16,7 +16,7 @@ impl Evaluate for SignedAtom {
1616
&self,
1717
ctx: &mut EvaluationContext<R>,
1818
scope: ScopeIdentifier,
19-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
19+
) -> Result<Unsigned36Bit, EvaluationFailure> {
2020
self.magnitude.evaluate(ctx, scope).map(|magnitude| {
2121
if self.negated {
2222
let s36 = magnitude.reinterpret_as_signed();
@@ -34,9 +34,9 @@ impl Evaluate for ArithmeticExpression {
3434
&self,
3535
ctx: &mut EvaluationContext<R>,
3636
scope: ScopeIdentifier,
37-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
37+
) -> Result<Unsigned36Bit, EvaluationFailure> {
3838
let first: Unsigned36Bit = self.first.evaluate(ctx, scope)?;
39-
let result: Result<Unsigned36Bit, SymbolLookupFailure> = self
39+
let result: Result<Unsigned36Bit, EvaluationFailure> = self
4040
.tail
4141
.iter()
4242
.try_fold(first, |acc, curr| fold_step(acc, curr, ctx, scope));
@@ -49,7 +49,7 @@ impl Evaluate for ConfigValue {
4949
&self,
5050
ctx: &mut EvaluationContext<R>,
5151
scope: ScopeIdentifier,
52-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
52+
) -> Result<Unsigned36Bit, EvaluationFailure> {
5353
// The `expr` member was either originally in superscript (in
5454
// which case the `evaluate` value will already have been
5555
// shifted into the correct position in the word, or in normal
@@ -64,7 +64,7 @@ impl Evaluate for RegistersContaining {
6464
&self,
6565
ctx: &mut EvaluationContext<R>,
6666
scope: ScopeIdentifier,
67-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
67+
) -> Result<Unsigned36Bit, EvaluationFailure> {
6868
let mut first_addr: Option<Unsigned36Bit> = None;
6969
for rc_word in self.words() {
7070
// Evaluation of the RegisterContaining value will compute
@@ -97,7 +97,7 @@ impl Evaluate for RegisterContaining {
9797
// the address of the instruction which refers to it.
9898
ctx: &mut EvaluationContext<R>,
9999
scope: ScopeIdentifier,
100-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
100+
) -> Result<Unsigned36Bit, EvaluationFailure> {
101101
match self {
102102
RegisterContaining::Unallocated(_) => {
103103
unreachable!(
@@ -166,7 +166,7 @@ impl Evaluate for Atom {
166166
&self,
167167
ctx: &mut EvaluationContext<R>,
168168
scope: ScopeIdentifier,
169-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
169+
) -> Result<Unsigned36Bit, EvaluationFailure> {
170170
match self {
171171
Atom::SymbolOrLiteral(value) => value.evaluate(ctx, scope),
172172
Atom::Parens(_span, _script, expr) => expr.evaluate(ctx, scope),
@@ -180,7 +180,7 @@ impl Evaluate for SymbolOrLiteral {
180180
&self,
181181
ctx: &mut EvaluationContext<R>,
182182
scope: ScopeIdentifier,
183-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
183+
) -> Result<Unsigned36Bit, EvaluationFailure> {
184184
match self {
185185
SymbolOrLiteral::Symbol(script, symbol_name, span) => {
186186
symbol_name_lookup(symbol_name, *script, *span, ctx, scope)
@@ -200,7 +200,7 @@ impl Evaluate for InstructionFragment {
200200
&self,
201201
ctx: &mut EvaluationContext<R>,
202202
scope: ScopeIdentifier,
203-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
203+
) -> Result<Unsigned36Bit, EvaluationFailure> {
204204
match self {
205205
InstructionFragment::Null(_) => Ok(Unsigned36Bit::ZERO),
206206
InstructionFragment::Arithmetic(expr) => expr.evaluate(ctx, scope),
@@ -237,7 +237,7 @@ impl Evaluate for Origin {
237237
&self,
238238
ctx: &mut EvaluationContext<R>,
239239
scope: ScopeIdentifier,
240-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
240+
) -> Result<Unsigned36Bit, EvaluationFailure> {
241241
match self {
242242
Origin::Deduced(_span, _, address) | Origin::Literal(_span, address) => {
243243
Ok(address.into())
@@ -298,7 +298,7 @@ impl Evaluate for CommaDelimitedFragment {
298298
&self,
299299
ctx: &mut EvaluationContext<R>,
300300
scope: ScopeIdentifier,
301-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
301+
) -> Result<Unsigned36Bit, EvaluationFailure> {
302302
self.fragment
303303
.evaluate(ctx, scope)
304304
.map(|word| {
@@ -332,12 +332,12 @@ impl Evaluate for UntaggedProgramInstruction {
332332
&self,
333333
ctx: &mut EvaluationContext<R>,
334334
scope: ScopeIdentifier,
335-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
335+
) -> Result<Unsigned36Bit, EvaluationFailure> {
336336
fn evaluate_and_combine_values<'a, R, E, I>(
337337
mut items: I,
338338
ctx: &mut EvaluationContext<R>,
339339
scope: ScopeIdentifier,
340-
) -> Result<Unsigned36Bit, SymbolLookupFailure>
340+
) -> Result<Unsigned36Bit, EvaluationFailure>
341341
where
342342
R: RcUpdater,
343343
E: Evaluate + 'a,
@@ -362,7 +362,7 @@ impl Evaluate for EqualityValue {
362362
&self,
363363
ctx: &mut EvaluationContext<R>,
364364
scope: ScopeIdentifier,
365-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
365+
) -> Result<Unsigned36Bit, EvaluationFailure> {
366366
self.inner.evaluate(ctx, scope)
367367
}
368368
}
@@ -372,7 +372,7 @@ impl Evaluate for TaggedProgramInstruction {
372372
&self,
373373
ctx: &mut EvaluationContext<R>,
374374
scope: ScopeIdentifier,
375-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
375+
) -> Result<Unsigned36Bit, EvaluationFailure> {
376376
self.instruction.evaluate(ctx, scope)
377377
}
378378
}

assembler/src/asmlib/eval.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ pub(crate) struct ExhaustedIndexRegisters {
4242
/// We failed while evaluating the value of a word (typically, the
4343
/// value of a word in the final assembled output).
4444
#[derive(Debug, PartialEq, Eq)]
45-
pub(crate) enum SymbolLookupFailure {
45+
pub(crate) enum EvaluationFailure {
4646
/// Evaluation failed because there was a loop in the definition
4747
/// of a symbol (i.e. in one of the equaities we needed to
4848
/// evaluate to determine the final result).
@@ -61,23 +61,23 @@ pub(crate) enum SymbolLookupFailure {
6161
HereIsNotAllowedHere(Span),
6262
}
6363

64-
impl Spanned for SymbolLookupFailure {
64+
impl Spanned for EvaluationFailure {
6565
fn span(&self) -> Span {
6666
match self {
67-
SymbolLookupFailure::HereIsNotAllowedHere(span)
68-
| SymbolLookupFailure::FailedToAssignIndexRegister(ExhaustedIndexRegisters {
67+
EvaluationFailure::HereIsNotAllowedHere(span)
68+
| EvaluationFailure::FailedToAssignIndexRegister(ExhaustedIndexRegisters {
6969
span,
7070
..
7171
})
72-
| SymbolLookupFailure::SymbolDefinitionLoop { span, .. }
73-
| SymbolLookupFailure::BlockTooLarge(span, _) => *span,
72+
| EvaluationFailure::SymbolDefinitionLoop { span, .. }
73+
| EvaluationFailure::BlockTooLarge(span, _) => *span,
7474
}
7575
}
7676
}
7777

78-
impl Display for SymbolLookupFailure {
78+
impl Display for EvaluationFailure {
7979
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> {
80-
use SymbolLookupFailure::*;
80+
use EvaluationFailure::*;
8181
match self {
8282
SymbolDefinitionLoop {
8383
deps_in_order,
@@ -107,33 +107,33 @@ impl Display for SymbolLookupFailure {
107107
}
108108
}
109109

110-
impl SymbolLookupFailure {
110+
impl EvaluationFailure {
111111
/// Convert an instance of `EvaluationFailure` (which describes
112112
/// why an evaluation failed) into an instance of [`ProgramError`]
113113
/// (which describes why the user's program cannot be assembled).
114114
pub(crate) fn into_program_error(self) -> ProgramError {
115115
match self {
116-
SymbolLookupFailure::FailedToAssignIndexRegister(ExhaustedIndexRegisters {
116+
EvaluationFailure::FailedToAssignIndexRegister(ExhaustedIndexRegisters {
117117
span,
118118
name,
119119
}) => ProgramError::FailedToAssignIndexRegister(span, name),
120-
SymbolLookupFailure::BlockTooLarge(span, mle) => ProgramError::BlockTooLong(span, mle),
121-
SymbolLookupFailure::SymbolDefinitionLoop {
120+
EvaluationFailure::BlockTooLarge(span, mle) => ProgramError::BlockTooLong(span, mle),
121+
EvaluationFailure::SymbolDefinitionLoop {
122122
deps_in_order,
123123
span,
124124
} => ProgramError::SymbolDefinitionLoop {
125125
symbol_names: deps_in_order,
126126
span,
127127
},
128-
SymbolLookupFailure::HereIsNotAllowedHere(span) => ProgramError::SyntaxError {
128+
EvaluationFailure::HereIsNotAllowedHere(span) => ProgramError::SyntaxError {
129129
span,
130130
msg: "# is not allowed in this context".to_string(),
131131
},
132132
}
133133
}
134134
}
135135

136-
impl std::error::Error for SymbolLookupFailure {}
136+
impl std::error::Error for EvaluationFailure {}
137137

138138
/// HereValue specifies the value used for `#`. A `#` always
139139
/// signifies the address of the word we are trying to assemble.
@@ -147,10 +147,10 @@ pub(crate) enum HereValue {
147147
}
148148

149149
impl HereValue {
150-
pub(crate) fn get_address(&self, span: &Span) -> Result<Address, SymbolLookupFailure> {
150+
pub(crate) fn get_address(&self, span: &Span) -> Result<Address, EvaluationFailure> {
151151
match self {
152152
HereValue::Address(addr) => Ok(*addr),
153-
HereValue::NotAllowed => Err(SymbolLookupFailure::HereIsNotAllowedHere(*span)),
153+
HereValue::NotAllowed => Err(EvaluationFailure::HereIsNotAllowedHere(*span)),
154154
}
155155
}
156156
}
@@ -238,7 +238,7 @@ impl<R: RcUpdater> EvaluationContext<'_, R> {
238238
pub(super) fn fetch_or_assign_default(
239239
&mut self,
240240
name: &SymbolName,
241-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
241+
) -> Result<Unsigned36Bit, EvaluationFailure> {
242242
let existing_def: &mut ImplicitDefinition = match self.implicit_symtab.get_mut(name) {
243243
Some(def) => def,
244244
None => {
@@ -305,7 +305,7 @@ impl<R: RcUpdater> EvaluationContext<'_, R> {
305305
*existing_def = ImplicitDefinition::DefaultAssigned(value, context);
306306
Ok(value)
307307
}
308-
Err(e) => Err(SymbolLookupFailure::FailedToAssignIndexRegister(e)),
308+
Err(e) => Err(EvaluationFailure::FailedToAssignIndexRegister(e)),
309309
}
310310
}
311311
}
@@ -461,7 +461,7 @@ pub(super) trait Evaluate: Spanned {
461461
&self,
462462
ctx: &mut EvaluationContext<R>,
463463
scope: ScopeIdentifier,
464-
) -> Result<Unsigned36Bit, SymbolLookupFailure>;
464+
) -> Result<Unsigned36Bit, EvaluationFailure>;
465465
}
466466

467467
// Represents the RC-block; see [section 6-2.6 of the Users
@@ -547,14 +547,14 @@ pub(crate) fn symbol_name_lookup<R: RcUpdater>(
547547
span: Span,
548548
ctx: &mut EvaluationContext<R>,
549549
scope: ScopeIdentifier,
550-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
550+
) -> Result<Unsigned36Bit, EvaluationFailure> {
551551
ctx.lookup_operation.deps_in_order.push(name.clone());
552552
if !ctx.lookup_operation.depends_on.insert(name.clone()) {
553553
// `name` was already in `depends_on`; in other words,
554554
// we have a loop.
555555
match OneOrMore::try_from_vec(ctx.lookup_operation.deps_in_order.clone()) {
556556
Ok(deps_in_order) => {
557-
return Err(SymbolLookupFailure::SymbolDefinitionLoop {
557+
return Err(EvaluationFailure::SymbolDefinitionLoop {
558558
span,
559559
deps_in_order,
560560
});
@@ -611,7 +611,7 @@ pub(super) fn extract_final_equalities<R: RcUpdater>(
611611
FinalSymbolDefinition::PositionIndependent(value),
612612
);
613613
}
614-
Err(SymbolLookupFailure::HereIsNotAllowedHere(_)) => {
614+
Err(EvaluationFailure::HereIsNotAllowedHere(_)) => {
615615
// The value of this equality would depend on the
616616
// address at which it is evaluated, so it has no
617617
// single final value. This is OK.
@@ -664,7 +664,7 @@ impl Evaluate for BlockPosition {
664664
&self,
665665
ctx: &mut EvaluationContext<R>,
666666
scope: ScopeIdentifier,
667-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
667+
) -> Result<Unsigned36Bit, EvaluationFailure> {
668668
// Resolve the address of this block by evaluating its origin
669669
// specification if it has one.
670670
if let Some(origin) = self.origin.as_ref() {
@@ -712,7 +712,7 @@ impl Evaluate for BlockPosition {
712712
// of the address of the previous block and
713713
// the size of the previous block which is the
714714
// problem.
715-
Err(SymbolLookupFailure::BlockTooLarge(
715+
Err(EvaluationFailure::BlockTooLarge(
716716
prev_span,
717717
MachineLimitExceededFailure::BlockTooLarge {
718718
span: prev_span,
@@ -730,7 +730,7 @@ impl Evaluate for (&Span, &SymbolName, &ExplicitDefinition) {
730730
&self,
731731
ctx: &mut EvaluationContext<R>,
732732
scope: ScopeIdentifier,
733-
) -> Result<Unsigned36Bit, SymbolLookupFailure> {
733+
) -> Result<Unsigned36Bit, EvaluationFailure> {
734734
let (_span, name, def): (&Span, &SymbolName, &ExplicitDefinition) = *self;
735735
match def {
736736
ExplicitDefinition::Origin(Origin::Symbolic(_span, name), _block_id) => {
@@ -755,7 +755,7 @@ impl Evaluate for (&Span, &SymbolName, &ExplicitDefinition) {
755755
subword::right_half(block_position.evaluate(ctx, scope)?).into();
756756
match offset_from_origin(&block_origin, *block_offset) {
757757
Ok(computed_address) => Ok(computed_address.into()),
758-
Err(_overflow_error) => Err(SymbolLookupFailure::BlockTooLarge(
758+
Err(_overflow_error) => Err(EvaluationFailure::BlockTooLarge(
759759
*span,
760760
MachineLimitExceededFailure::BlockTooLarge {
761761
span: *span,

assembler/src/asmlib/symtab.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use base::prelude::*;
66

77
use super::ast::{EqualityValue, Origin};
88
use super::collections::OneOrMore;
9-
use super::eval::SymbolLookupFailure;
9+
use super::eval::EvaluationFailure;
1010
use super::memorymap::{RcAllocator, RcWordAllocationFailure, RcWordKind, RcWordSource};
1111
use super::source::Source;
1212
use super::span::*;
@@ -467,10 +467,10 @@ pub(super) fn assign_default_rc_word_tags<R: RcAllocator>(
467467

468468
pub(super) fn record_undefined_symbol_or_return_failure(
469469
source_file_body: &Source<'_>,
470-
e: SymbolLookupFailure,
470+
e: EvaluationFailure,
471471
undefined_symbols: &mut BTreeMap<SymbolName, ProgramError>,
472472
) -> Result<(), AssemblerFailure> {
473-
use SymbolLookupFailure::*;
473+
use EvaluationFailure::*;
474474
match e {
475475
SymbolDefinitionLoop {
476476
span,

0 commit comments

Comments
 (0)