22using FanScript . Compiler . Emit ;
33using FanScript . Compiler . Emit . BlockPlacers ;
44using FanScript . Compiler . Emit . CodeBuilders ;
5+ using FanScript . Compiler . Emit . Utils ;
56using FanScript . FCInfo ;
67using MathUtils . Vectors ;
78using System . Collections . Frozen ;
@@ -34,16 +35,13 @@ public void Manual_TerminalsAreCorrect()
3435
3536 using ( placer . StatementBlock ( ) )
3637 {
37- Block ? lastBlock = null ;
38+ EmitConnector connector = new EmitConnector ( builder . Connect ) ;
3839
3940 foreach ( var def in active )
4041 {
4142 Block block = placeAndConnectAllTerminals ( def ) ;
4243
43- if ( lastBlock is not null )
44- builder . Connect ( new BlockConnectTarget ( lastBlock , lastBlock . Type . After ) , new BlockConnectTarget ( block , block . Type . Before ) ) ;
45-
46- lastBlock = block ;
44+ connector . Add ( new BasicEmitStore ( block ) ) ;
4745 }
4846
4947 foreach ( var def in pasive )
@@ -65,23 +63,21 @@ Block placeAndConnectAllTerminals(BlockDef def)
6563
6664 ( Block , Terminal ) [ ] connectToTerminals = new ( Block , Terminal ) [ terminals . Length ] ;
6765
68- using ( placer . StatementBlock ( ) )
66+ Block block = placer . PlaceBlock ( def ) ;
67+
68+ using ( placer . ExpressionBlock ( ) )
6969 {
70- for ( int i = 0 ; i < terminals . Length ; i ++ )
70+ for ( int i = terminals . Length - 1 ; i >= 0 ; i -- )
7171 {
7272 Terminal terminal = terminals [ i ] ;
7373
7474 WireType type = terminal . WireType ;
75- if ( type != WireType . Void )
76- type = ( WireType ) ( ( int ) type & ( int . MaxValue ^ 1 ) ) ; // xPtr => x
7775
7876 var ( _def , _terminal ) = terminalDict [ ( terminal . Type , type ) ] ;
7977 connectToTerminals [ i ] = ( placer . PlaceBlock ( _def ) , _terminal ) ;
8078 }
8179 }
8280
83- Block block = placer . PlaceBlock ( def ) ;
84-
8581 for ( int i = 0 ; i < connectToTerminals . Length ; i ++ )
8682 {
8783 var ( _block , _terminal ) = connectToTerminals [ i ] ;
@@ -106,33 +102,33 @@ Block placeAndConnectAllTerminals(BlockDef def)
106102
107103 IEnumerable < KeyValuePair < ( TerminalType , WireType ) , ( BlockDef , Terminal ) > > generateTerminalDict ( )
108104 {
109- foreach ( var _type in Enum . GetValues < WireType > ( ) )
105+ foreach ( var type in Enum . GetValues < WireType > ( ) )
110106 {
111- if ( _type == WireType . Error ||
112- ( _type != WireType . Void && ( int ) _type % 2 == 1 ) )
107+ if ( type == WireType . Error )
113108 continue ;
114109
115- BlockDef def = _type == WireType . Void ? Blocks . Variables . Set_Variable_Num : Blocks . Variables . VariableByType ( _type ) ;
110+ BlockDef def = type == WireType . Void ? Blocks . Variables . Set_Variable_Num : Blocks . Variables . VariableByType ( type ) ;
116111
117- var type = ( WireType ) ( ( int ) _type | 1 ) ;
112+ WireType ptrType = type . ToPointer ( ) ;
118113
119- var terminal = def . TerminalArray . First ( term => term . Type == TerminalType . Out && term . WireType == type ) ;
114+ var terminal = def . TerminalArray . First ( term => term . Type == TerminalType . Out && term . WireType == ptrType ) ;
120115
121- yield return new KeyValuePair < ( TerminalType , WireType ) , ( BlockDef , Terminal ) > ( ( TerminalType . In , _type ) , ( def , terminal ) ) ;
116+ yield return new KeyValuePair < ( TerminalType , WireType ) , ( BlockDef , Terminal ) > ( ( TerminalType . In , type ) , ( def , terminal ) ) ;
122117 }
123118
124119 // this *could* be names "type", but for some fuckinf reason if it is, it's always WireType.Error
125- foreach ( var _type in Enum . GetValues < WireType > ( ) )
120+ foreach ( var type in Enum . GetValues < WireType > ( ) )
126121 {
127- if ( _type == WireType . Error ||
128- ( _type != WireType . Void && ( int ) _type % 2 == 1 ) )
122+ if ( type == WireType . Error )
129123 continue ;
130124
131- BlockDef def = _type == WireType . Void ? Blocks . Variables . Set_Variable_Num : Blocks . Variables . Set_VariableByType ( _type ) ;
125+ BlockDef def = type == WireType . Void ? Blocks . Variables . Set_Variable_Num : Blocks . Variables . Set_VariableByType ( type ) ;
126+
127+ WireType nonPtrType = type . ToNormal ( ) ;
132128
133- var terminal = def . TerminalArray . First ( term => term . Type == TerminalType . In && term . WireType == _type ) ;
129+ var terminal = def . TerminalArray . First ( term => term . Type == TerminalType . In && term . WireType == nonPtrType ) ;
134130
135- yield return new KeyValuePair < ( TerminalType , WireType ) , ( BlockDef , Terminal ) > ( ( TerminalType . Out , _type ) , ( def , terminal ) ) ;
131+ yield return new KeyValuePair < ( TerminalType , WireType ) , ( BlockDef , Terminal ) > ( ( TerminalType . Out , type ) , ( def , terminal ) ) ;
136132 }
137133 }
138134 }
0 commit comments