@@ -19,9 +19,7 @@ use super::glyph;
1919use super :: state:: NumeralMode ;
2020use super :: symbol:: { SymbolName , SymbolOrHere } ;
2121use super :: symtab:: SymbolTable ;
22- use super :: types:: {
23- offset_from_origin, AssemblerFailure , BlockIdentifier , MachineLimitExceededFailure , Span ,
24- } ;
22+ use super :: types:: { BlockIdentifier , Span } ;
2523
2624/// Eventually we will support symbolic expressions.
2725#[ derive( Debug , Clone , PartialEq , Eq ) ]
@@ -876,13 +874,6 @@ impl Evaluate for TaggedProgramInstruction {
876874
877875const HELD_MASK : Unsigned36Bit = u36 ! ( 1 << 35 ) ;
878876
879- pub ( crate ) fn bad_offset ( block_id : BlockIdentifier , offset : usize ) -> AssemblerFailure {
880- AssemblerFailure :: MachineLimitExceeded ( MachineLimitExceededFailure :: BlockTooLarge {
881- block_id,
882- offset,
883- } )
884- }
885-
886877#[ derive( Debug , Clone , PartialEq , Eq ) ]
887878pub ( crate ) struct SourceFile {
888879 pub ( crate ) punch : Option < PunchCommand > ,
@@ -911,27 +902,6 @@ impl SourceFile {
911902 } )
912903 }
913904
914- //pub(crate) fn define_rc_word(
915- // &mut self,
916- // value: TaggedProgramInstruction,
917- //) -> Result<RcReference, AssemblerFailure> {
918- // let rcblock: &mut ManuscriptBlock = self
919- // .blocks
920- // .entry(BlockIdentifier::RcWords)
921- // .or_insert_with(|| ManuscriptBlock {
922- // origin: None,
923- // statements: Vec::new(),
924- // });
925- // let offset = rcblock.statements.len();
926- // match Unsigned18Bit::try_from(offset) {
927- // Ok(id) => {
928- // rcblock.statements.push(Statement::Instruction(value));
929- // Ok(RcReference::new(id))
930- // }
931- // Err(_) => Err(bad_offset(BlockIdentifier::RcWords, offset)),
932- // }
933- //}
934-
935905 pub ( crate ) fn global_symbol_definitions (
936906 & self ,
937907 ) -> impl Iterator < Item = ( SymbolName , Span , SymbolDefinition ) > + ' _ {
@@ -979,13 +949,11 @@ pub(crate) enum Statement {
979949 // on the RHS, the value cannot be a TaggedProgramInstruction.
980950 Assignment ( Span , SymbolName , UntaggedProgramInstruction ) , // User Guide calls these "equalities".
981951 Instruction ( TaggedProgramInstruction ) ,
982- RcWord ( Span , Unsigned36Bit ) ,
983952}
984953
985954impl Statement {
986955 fn span ( & self ) -> Span {
987956 match self {
988- Statement :: RcWord ( span, _) => * span,
989957 Statement :: Assignment ( span, _, _) => * span,
990958 Statement :: Instruction ( TaggedProgramInstruction { tag, instruction } ) => {
991959 if let Some ( t) = tag {
@@ -1000,7 +968,7 @@ impl Statement {
1000968 fn emitted_instruction_count ( & self ) -> Unsigned18Bit {
1001969 match self {
1002970 Statement :: Assignment ( _, _, _) => Unsigned18Bit :: ZERO ,
1003- Statement :: Instruction ( _) | Statement :: RcWord ( _ , _ ) => Unsigned18Bit :: ONE ,
971+ Statement :: Instruction ( _) => Unsigned18Bit :: ONE ,
1004972 }
1005973 }
1006974
@@ -1010,7 +978,6 @@ impl Statement {
1010978 offset : Unsigned18Bit ,
1011979 ) -> impl Iterator < Item = ( SymbolName , Span , SymbolUse ) > {
1012980 match self {
1013- Statement :: RcWord ( _, _) => Vec :: new ( ) ,
1014981 Statement :: Assignment ( span, symbol, expression) => {
1015982 vec ! [ (
1016983 symbol. clone( ) ,
@@ -1027,6 +994,25 @@ impl Statement {
1027994 }
1028995}
1029996
997+ impl From < ( Span , Unsigned36Bit ) > for Statement {
998+ fn from ( ( span, value) : ( Span , Unsigned36Bit ) ) -> Statement {
999+ Statement :: Instruction ( TaggedProgramInstruction {
1000+ tag : None ,
1001+ instruction : UntaggedProgramInstruction {
1002+ span,
1003+ holdbit : HoldBit :: Unspecified ,
1004+ parts : vec ! [ InstructionFragment :: from( ArithmeticExpression :: from(
1005+ Atom :: Literal ( LiteralValue {
1006+ span,
1007+ elevation: Script :: Normal ,
1008+ value,
1009+ } ) ,
1010+ ) ) ] ,
1011+ } ,
1012+ } )
1013+ }
1014+ }
1015+
10301016#[ derive( Debug , Clone , PartialEq , Eq ) ]
10311017pub ( crate ) struct MacroArgument {
10321018 pub ( crate ) name : SymbolName ,
@@ -1127,57 +1113,40 @@ impl Directive {
11271113 pub ( crate ) fn take_rc_block ( & mut self ) -> RcBlock {
11281114 let max_occupied_addr: Option < Address > =
11291115 self . blocks . values ( ) . map ( LocatedBlock :: following_addr) . max ( ) ;
1130- fn make_rc_block ( max_occupied_addr : Option < Address > ) -> LocatedBlock {
1131- let rc_block_address: Address =
1132- max_occupied_addr. unwrap_or_else ( Origin :: default_address) ;
1133- LocatedBlock {
1134- location : rc_block_address,
1135- items : Vec :: new ( ) ,
1136- }
1116+ RcBlock {
1117+ address : max_occupied_addr. unwrap_or_else ( Origin :: default_address) ,
1118+ words : Vec :: new ( ) ,
11371119 }
1138- self . blocks
1139- . remove ( & BlockIdentifier :: RcWords )
1140- . unwrap_or_else ( || make_rc_block ( max_occupied_addr) )
1141- . into ( )
11421120 }
11431121
11441122 pub ( crate ) fn entry_point ( & self ) -> Option < Address > {
11451123 self . entry_point
11461124 }
11471125}
11481126
1149- impl RcAllocator for Directive {
1150- fn allocate ( & mut self , span : Span , value : Unsigned36Bit ) -> Address {
1151- match self . blocks . get_mut ( & BlockIdentifier :: RcWords ) {
1152- None => {
1153- panic ! (
1154- "precondition did not hold: no RC-word block was allocated in the directive"
1155- ) ;
1156- }
1157- Some ( rc_word_block) => match Unsigned18Bit :: try_from ( rc_word_block. items . len ( ) ) {
1158- Ok ( offset) => {
1159- let addr = rc_word_block. location . index_by ( offset) ;
1160- rc_word_block. items . push ( Statement :: RcWord ( span, value) ) ;
1161- addr
1162- }
1163- Err ( _) => {
1164- unimplemented ! ( "handle overflow" )
1165- }
1166- } ,
1167- }
1168- }
1169- }
1127+ //impl RcAllocator for Directive {
1128+ // fn allocate(&mut self, span: Span, value: Unsigned36Bit) -> Address {
1129+ // match self.blocks.get_mut(&BlockIdentifier::RcWords) {
1130+ // None => {
1131+ // panic!(
1132+ // "precondition did not hold: no RC-word block was allocated in the directive"
1133+ // );
1134+ // }
1135+ // Some(rc_word_block) => rc_word_block.allocate(span, value),
1136+ // }
1137+ // }
1138+ //}
11701139
11711140#[ derive( Debug , Clone , PartialEq , Eq ) ]
11721141pub ( crate ) struct Block {
11731142 pub ( crate ) origin : Option < Origin > ,
11741143 pub ( crate ) location : Option < Address > ,
1175- pub ( crate ) items : Vec < Statement > ,
1144+ pub ( crate ) statements : Vec < Statement > ,
11761145}
11771146
11781147impl Block {
11791148 pub ( crate ) fn emitted_instruction_count ( & self ) -> Unsigned18Bit {
1180- self . items
1149+ self . statements
11811150 . iter ( )
11821151 . map ( |stmt| stmt. emitted_instruction_count ( ) )
11831152 . sum ( )
@@ -1187,33 +1156,18 @@ impl Block {
11871156#[ derive( Debug , Clone , PartialEq , Eq ) ]
11881157pub ( crate ) struct LocatedBlock {
11891158 pub ( crate ) location : Address ,
1190- pub ( crate ) items : Vec < Statement > ,
1159+ pub ( crate ) statements : Vec < Statement > ,
11911160}
11921161
11931162impl LocatedBlock {
1194- pub ( crate ) fn get_offset (
1195- & self ,
1196- block_id : BlockIdentifier ,
1197- offset : usize ,
1198- ) -> Result < Address , AssemblerFailure > {
1199- if let Ok ( h) = Unsigned18Bit :: try_from ( offset)
1200- . map_err ( |_| ( ) )
1201- . and_then ( |n| offset_from_origin ( & self . location , n) . map_err ( |_| ( ) ) )
1202- {
1203- Ok ( h)
1204- } else {
1205- Err ( bad_offset ( block_id, offset) )
1206- }
1207- }
1208-
1209- pub ( crate ) fn following_addr ( & self ) -> Address {
1210- self . location . index_by ( self . emitted_instruction_count ( ) )
1211- }
1212-
1213- pub ( crate ) fn emitted_instruction_count ( & self ) -> Unsigned18Bit {
1214- self . items
1163+ pub ( crate ) fn emitted_word_count ( & self ) -> Unsigned18Bit {
1164+ self . statements
12151165 . iter ( )
12161166 . map ( |stmt| stmt. emitted_instruction_count ( ) )
12171167 . sum ( )
12181168 }
1169+
1170+ pub ( crate ) fn following_addr ( & self ) -> Address {
1171+ self . location . index_by ( self . emitted_word_count ( ) )
1172+ }
12191173}
0 commit comments