@@ -17,7 +17,7 @@ use crate::symtab::{LookupOperation, RcAllocator, RcBlock};
1717use super :: eval:: { Evaluate , SymbolContext , SymbolDefinition , SymbolLookup , SymbolUse } ;
1818use super :: glyph;
1919use super :: state:: NumeralMode ;
20- use super :: symbol:: SymbolName ;
20+ use super :: symbol:: { SymbolName , SymbolOrHere } ;
2121use super :: symtab:: SymbolTable ;
2222use super :: types:: {
2323 offset_from_origin, AssemblerFailure , BlockIdentifier , MachineLimitExceededFailure , Span ,
@@ -36,6 +36,10 @@ impl LiteralValue {
3636 self . value << self . elevation . shift ( )
3737 }
3838
39+ pub ( crate ) fn unshifted_value ( & self ) -> Unsigned36Bit {
40+ self . value
41+ }
42+
3943 #[ cfg( test) ]
4044 pub ( crate ) fn span ( & self ) -> & Span {
4145 & self . span
@@ -272,14 +276,15 @@ impl Evaluate for ArithmeticExpression {
272276#[ derive( Debug , Clone , PartialEq , Eq ) ]
273277pub ( crate ) enum ConfigValue {
274278 Literal ( Span , Unsigned36Bit ) ,
275- Symbol ( Span , SymbolName ) ,
279+ Symbol ( Span , SymbolOrHere ) ,
276280}
277281
278282impl ConfigValue {
279283 pub ( crate ) fn symbol_uses ( & self ) -> impl Iterator < Item = ( SymbolName , Span , SymbolUse ) > {
280284 match self {
281285 ConfigValue :: Literal ( _span, _value) => None ,
282- ConfigValue :: Symbol ( span, name) => Some ( (
286+ ConfigValue :: Symbol ( _span, SymbolOrHere :: Here ) => None ,
287+ ConfigValue :: Symbol ( span, SymbolOrHere :: Named ( name) ) => Some ( (
283288 name. to_owned ( ) ,
284289 * span,
285290 SymbolUse :: Reference ( SymbolContext :: configuration ( ) ) ,
@@ -299,7 +304,10 @@ impl Evaluate for ConfigValue {
299304 ) -> Result < Unsigned36Bit , SymbolLookupFailure > {
300305 match self {
301306 ConfigValue :: Literal ( _span, value) => Ok ( * value) ,
302- ConfigValue :: Symbol ( span, name) => {
307+ ConfigValue :: Symbol ( span, SymbolOrHere :: Here ) => {
308+ Ok ( Unsigned36Bit :: from ( target_address. get_address ( span) ?) )
309+ }
310+ ConfigValue :: Symbol ( span, SymbolOrHere :: Named ( name) ) => {
303311 let context = SymbolContext :: configuration ( ) ;
304312 match symtab. lookup_with_op ( name, * span, target_address, rc_allocator, & context, op)
305313 {
@@ -318,8 +326,7 @@ impl Evaluate for ConfigValue {
318326#[ derive( Debug , Clone , PartialEq , Eq ) ]
319327pub ( crate ) enum Atom {
320328 Literal ( LiteralValue ) ,
321- Symbol ( Span , Script , SymbolName ) ,
322- Here ( Script ) , // the special symbol '#'.
329+ Symbol ( Span , Script , SymbolOrHere ) ,
323330 Parens ( Script , Box < ArithmeticExpression > ) ,
324331 RcRef ( Span , Vec < InstructionFragment > ) ,
325332}
@@ -328,10 +335,10 @@ impl Atom {
328335 pub ( crate ) fn symbol_uses ( & self ) -> impl Iterator < Item = ( SymbolName , Span , SymbolUse ) > {
329336 let mut result = Vec :: with_capacity ( 1 ) ;
330337 match self {
331- Atom :: Literal ( _) | Atom :: Here ( _ ) | Atom :: RcRef ( _, _) => ( ) ,
332- Atom :: Symbol ( span, script, symbol_name ) => {
338+ Atom :: Literal ( _) | Atom :: RcRef ( _ , _ ) | Atom :: Symbol ( _, _, SymbolOrHere :: Here ) => ( ) ,
339+ Atom :: Symbol ( span, script, SymbolOrHere :: Named ( name ) ) => {
333340 result. push ( (
334- symbol_name . clone ( ) ,
341+ name . clone ( ) ,
335342 * span,
336343 SymbolUse :: Reference ( SymbolContext :: from ( ( script, * span) ) ) ,
337344 ) ) ;
@@ -353,17 +360,12 @@ impl Evaluate for Atom {
353360 op : & mut LookupOperation ,
354361 ) -> Result < Unsigned36Bit , SymbolLookupFailure > {
355362 match self {
356- Atom :: Here ( elevation) => match target_address {
357- HereValue :: Address ( addr) => {
358- let value: Unsigned36Bit = ( * addr) . into ( ) ;
359- Ok ( value. shl ( elevation. shift ( ) ) )
360- }
361- HereValue :: NotAllowed => {
362- todo ! ( "# is not allowed in origins" )
363- }
364- } ,
363+ Atom :: Symbol ( span, elevation, SymbolOrHere :: Here ) => {
364+ let value: Unsigned36Bit = target_address. get_address ( span) ?. into ( ) ;
365+ Ok ( value. shl ( elevation. shift ( ) ) )
366+ }
365367 Atom :: Literal ( literal) => Ok ( literal. value ( ) ) ,
366- Atom :: Symbol ( span, elevation, name) => {
368+ Atom :: Symbol ( span, elevation, SymbolOrHere :: Named ( name) ) => {
367369 let context = SymbolContext :: from ( ( elevation, * span) ) ;
368370 match symtab. lookup_with_op ( name, * span, target_address, rc_allocator, & context, op)
369371 {
@@ -419,11 +421,13 @@ fn elevated_string<'a>(s: &'a str, elevation: &Script) -> Cow<'a, str> {
419421impl std:: fmt:: Display for Atom {
420422 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
421423 match self {
422- Atom :: Here ( Script :: Super ) => f. write_str ( "@super_hash@" ) ,
423- Atom :: Here ( Script :: Normal ) => f. write_char ( '#' ) ,
424- Atom :: Here ( Script :: Sub ) => f. write_str ( "@sub_hash@" ) ,
424+ Atom :: Symbol ( _span, elevation, SymbolOrHere :: Here ) => match elevation {
425+ Script :: Super => f. write_str ( "@super_hash@" ) ,
426+ Script :: Normal => f. write_char ( '#' ) ,
427+ Script :: Sub => f. write_str ( "@sub_hash@" ) ,
428+ } ,
425429 Atom :: Literal ( value) => value. fmt ( f) ,
426- Atom :: Symbol ( _span, elevation, name) => {
430+ Atom :: Symbol ( _span, elevation, SymbolOrHere :: Named ( name) ) => {
427431 elevated_string ( & name. to_string ( ) , elevation) . fmt ( f)
428432 }
429433 Atom :: Parens ( script, expr) => elevated_string ( & expr. to_string ( ) , script) . fmt ( f) ,
0 commit comments