@@ -37,11 +37,7 @@ class Connection () extends ConnectionSignal {
37
37
def isDriven () = { ! input.isEmpty }
38
38
}
39
39
40
- class Value () { }
41
-
42
- class ConnectionValue () extends Value {}
43
-
44
- class ModuleInstance () extends Value {}
40
+ class ModuleInstance ( module: ModuleSymbol , lhs: ConnectionSignal , rhs: ConnectionSignal ) extends ConnectionSignal {}
45
41
46
42
class TemporaryConnection () extends ConnectionSignal {}
47
43
@@ -52,9 +48,11 @@ class Gate_OR ( val a:ConnectionSignal, val b:ConnectionSignal ) extends Connec
52
48
trait ExpressionState
53
49
{
54
50
def processExpression ( expression: ast.Expression ): Unit
51
+
52
+ def getValue (): ConnectionSignal
55
53
}
56
54
57
- class ExpressionModuleState ( val machine : ExpressionStateMachine , val value : Unit ) extends ExpressionState {
55
+ class ExpressionModuleState ( val machine : ExpressionStateMachine , val value : ConnectionSignal ) extends ExpressionState {
58
56
def processExpression ( expression: ast.Expression ) = {
59
57
expression.next match {
60
58
case None =>
@@ -67,10 +65,10 @@ class ExpressionModuleState( val machine:ExpressionStateMachine, val value:Unit
67
65
symbol match {
68
66
case Some ( DeclarationSymbol ( connection ) ) =>
69
67
throw new Exception (" Value followed by value" )
70
- case Some ( ModuleSymbol ( name, parameters ) ) =>
68
+ case Some ( symbol @ ModuleSymbol ( name, parameters ) ) =>
71
69
// TODO: Handle parameters
72
70
println( " ID is Module in Module State" )
73
- machine.state = new ExpressionModuleHalfState ( machine, (), () )
71
+ machine.state = new ExpressionModuleHalfState ( machine, symbol, value )
74
72
case None =>
75
73
println( " No ID" )
76
74
}
@@ -85,9 +83,11 @@ class ExpressionModuleState( val machine:ExpressionStateMachine, val value:Unit
85
83
println(" Chain Expressions not implemented." )
86
84
}
87
85
}
86
+
87
+ def getValue () = { value }
88
88
}
89
89
90
- class ExpressionModuleHalfState ( val machine : ExpressionStateMachine , val module : Unit , val rhs : Unit ) extends ExpressionState {
90
+ class ExpressionModuleHalfState ( val machine : ExpressionStateMachine , val module : ModuleSymbol , val rhs : ConnectionSignal ) extends ExpressionState {
91
91
def processExpression ( expression: ast.Expression ) = {
92
92
expression.next match {
93
93
case None =>
@@ -100,7 +100,7 @@ class ExpressionModuleHalfState( val machine:ExpressionStateMachine, val module:
100
100
symbol match {
101
101
case Some ( DeclarationSymbol ( connection ) ) =>
102
102
println( " ID is Value in HalfState" )
103
- machine.state = new ExpressionModuleState ( machine, ( ) )
103
+ machine.state = new ExpressionModuleState ( machine, new ModuleInstance ( module, connection, rhs ) )
104
104
case Some ( ModuleSymbol ( name, parameters ) ) =>
105
105
println( " ID is Module" )
106
106
throw new Exception (" Value expected got module" )
@@ -115,7 +115,7 @@ class ExpressionModuleHalfState( val machine:ExpressionStateMachine, val module:
115
115
val submachine = new ExpressionStateMachine ( machine.scope, machine.table )
116
116
expressions.reverseIterator foreach ( submachine.processExpression _ )
117
117
118
- machine.state = new ExpressionModuleState ( machine, ( ) )
118
+ machine.state = new ExpressionModuleState ( machine, new ModuleInstance ( module, submachine.getValue, rhs ) )
119
119
120
120
case unknown =>
121
121
println( " Value State Unknown: " + unknown.toString() )
@@ -124,9 +124,11 @@ class ExpressionModuleHalfState( val machine:ExpressionStateMachine, val module:
124
124
println(" Chain Expressions not implemented." )
125
125
}
126
126
}
127
+
128
+ def getValue (): ConnectionSignal = { throw new Exception (" Module missing left-hand-side" ) }
127
129
}
128
130
129
- class ExpressionValueState ( val machine : ExpressionStateMachine , val value : Unit ) extends ExpressionState {
131
+ class ExpressionValueState ( val machine : ExpressionStateMachine , val value : ConnectionSignal ) extends ExpressionState {
130
132
def processExpression ( expression: ast.Expression ) = {
131
133
expression.next match {
132
134
case None =>
@@ -139,10 +141,10 @@ class ExpressionValueState( val machine:ExpressionStateMachine, val value:Unit )
139
141
symbol match {
140
142
case Some ( DeclarationSymbol ( connection ) ) =>
141
143
throw new Exception (" Value followed by value" )
142
- case Some ( ModuleSymbol ( name, parameters ) ) =>
144
+ case Some ( symbol @ ModuleSymbol ( name, parameters ) ) =>
143
145
// TODO: Handle parameters
144
146
println( " ID is Module" )
145
- machine.state = new ExpressionModuleHalfState ( machine, (), () )
147
+ machine.state = new ExpressionModuleHalfState ( machine, symbol, value )
146
148
case None =>
147
149
println( " No ID" )
148
150
}
@@ -158,9 +160,7 @@ class ExpressionValueState( val machine:ExpressionStateMachine, val value:Unit )
158
160
}
159
161
}
160
162
161
- def getValue (): Unit = {
162
- value
163
- }
163
+ def getValue (): ConnectionSignal = { value }
164
164
}
165
165
166
166
class ExpressionValueEmptyState ( val machine : ExpressionStateMachine ) extends ExpressionState {
@@ -176,7 +176,7 @@ class ExpressionValueEmptyState( val machine:ExpressionStateMachine ) extends Ex
176
176
177
177
symbol match {
178
178
case Some ( DeclarationSymbol ( connection ) ) =>
179
- machine.state = new ExpressionValueState ( machine, () )
179
+ machine.state = new ExpressionValueState ( machine, connection )
180
180
case Some ( ModuleSymbol ( name, parameters ) ) =>
181
181
println( " ID is Module" )
182
182
throw new Exception (" Value expected got module" )
@@ -192,7 +192,7 @@ class ExpressionValueEmptyState( val machine:ExpressionStateMachine ) extends Ex
192
192
expressions.reverseIterator foreach ( submachine.processExpression _ )
193
193
println( " )" )
194
194
195
- machine.state = new ExpressionValueState ( machine, () )
195
+ machine.state = new ExpressionValueState ( machine, submachine.getValue )
196
196
case unknown =>
197
197
println( " Value State Unknown: " + unknown.toString() )
198
198
}
@@ -201,17 +201,15 @@ class ExpressionValueEmptyState( val machine:ExpressionStateMachine ) extends Ex
201
201
}
202
202
}
203
203
204
- def getValue (): Unit = {
205
- throw new Exception (" Missing Value" )
206
- }
204
+ def getValue () = { throw new Exception (" Missing Value" ) }
207
205
}
208
206
209
207
class ExpressionStateMachine ( val scope : SymbolScope , val table : SymbolTable ) {
210
208
var state : ExpressionState = new ExpressionValueEmptyState ( this )
211
209
212
210
def processExpression ( expression: ast.Expression ): Unit = { state.processExpression( expression ) }
213
211
214
- def getValue (): Unit = { }
212
+ def getValue (): ConnectionSignal = { state.getValue }
215
213
}
216
214
217
215
class SemanticModule ( ) {
0 commit comments