@@ -265,6 +265,53 @@ impl Evaluate for ArithmeticExpression {
265265 }
266266}
267267
268+ /// A configuration syllable can be specified by putting it in a
269+ /// superscript, or by putting it in normal script after a ‖ symbol
270+ /// (‖x or ‖2, for example). This is described in section 6-2.1 of
271+ /// the Users Handbook.
272+ #[ derive( Debug , Clone , PartialEq , Eq ) ]
273+ pub ( crate ) enum ConfigValue {
274+ Literal ( Span , Unsigned36Bit ) ,
275+ Symbol ( Span , SymbolName ) ,
276+ }
277+
278+ impl ConfigValue {
279+ pub ( crate ) fn symbol_uses ( & self ) -> impl Iterator < Item = ( SymbolName , Span , SymbolUse ) > {
280+ match self {
281+ ConfigValue :: Literal ( _span, _value) => None ,
282+ ConfigValue :: Symbol ( span, name) => Some ( (
283+ name. to_owned ( ) ,
284+ * span,
285+ SymbolUse :: Reference ( SymbolContext :: configuration ( ) ) ,
286+ ) ) ,
287+ }
288+ . into_iter ( )
289+ }
290+ }
291+
292+ impl Evaluate for ConfigValue {
293+ fn evaluate < R : RcAllocator > (
294+ & self ,
295+ target_address : & HereValue ,
296+ symtab : & mut SymbolTable ,
297+ rc_allocator : & mut R ,
298+ op : & mut LookupOperation ,
299+ ) -> Result < Unsigned36Bit , SymbolLookupFailure > {
300+ match self {
301+ ConfigValue :: Literal ( _span, value) => Ok ( * value) ,
302+ ConfigValue :: Symbol ( span, name) => {
303+ let context = SymbolContext :: configuration ( ) ;
304+ match symtab. lookup_with_op ( name, * span, target_address, rc_allocator, & context, op)
305+ {
306+ Ok ( SymbolValue :: Final ( value) ) => Ok ( value) ,
307+ Err ( e) => Err ( e) ,
308+ }
309+ }
310+ }
311+ . map ( |value| value. shl ( 30u32 ) )
312+ }
313+ }
314+
268315/// Eventually we will support real expressions, but for now we only
269316/// suport literals and references to symbols ("equalities" in the
270317/// User Handbook).
@@ -396,8 +443,9 @@ pub(crate) enum InstructionFragment {
396443 /// allows them in subscript/superscript too.
397444 Arithmetic ( ArithmeticExpression ) ,
398445 DeferredAddressing ,
399- // TODO: subscript/superscript atom (if the `Arithmetic` variant
400- // disallows subscript/superscript).
446+ Config ( ConfigValue ) , // some configuration values are specified as Arithmetic variants.
447+ // TODO: subscript/superscript atom (if the `Arithmetic` variant
448+ // disallows subscript/superscript).
401449}
402450
403451impl InstructionFragment {
@@ -408,6 +456,9 @@ impl InstructionFragment {
408456 result. extend ( expr. symbol_uses ( ) ) ;
409457 }
410458 InstructionFragment :: DeferredAddressing => ( ) ,
459+ InstructionFragment :: Config ( value) => {
460+ result. extend ( value. symbol_uses ( ) ) ;
461+ }
411462 }
412463 result. into_iter ( )
413464 }
@@ -426,6 +477,9 @@ impl Evaluate for InstructionFragment {
426477 expr. evaluate ( target_address, symtab, rc_allocator, op)
427478 }
428479 InstructionFragment :: DeferredAddressing => Ok ( DEFER_BIT ) ,
480+ InstructionFragment :: Config ( value) => {
481+ value. evaluate ( target_address, symtab, rc_allocator, op)
482+ }
429483 }
430484 }
431485}
0 commit comments