@@ -34,7 +34,7 @@ func (c *WaitCompiler) compileEvent(ctx fql.IWaitForEventExpressionContext) byte
3434 end := c .ctx .Program .Emitter .NewLabel ()
3535
3636 c .ctx .Program .Emitter .MarkLabel (start )
37- c .emitWaitEventIteration (ctx , state , streamReg , bytecode .NoopOperand , start , end )
37+ c .emitWaitEventIteration (ctx , state , streamReg , resultReg , bytecode .NoopOperand , start , end )
3838
3939 c .ctx .Program .Emitter .MarkLabel (end )
4040 c .emitWaitEventCleanup (state , streamReg )
@@ -65,7 +65,7 @@ func (c *WaitCompiler) compileEventWithTimeoutRecovery(
6565 cleanup := c .ctx .Program .Emitter .NewLabel ()
6666
6767 c .ctx .Program .Emitter .MarkLabel (start )
68- c .emitWaitEventIteration (ctx , state , streamReg , timeoutStateReg , start , iterationDone )
68+ c .emitWaitEventIteration (ctx , state , streamReg , resultReg , timeoutStateReg , start , iterationDone )
6969
7070 c .ctx .Program .Emitter .EmitJump (cleanup )
7171 c .ctx .Program .Emitter .MarkLabel (iterationDone )
@@ -112,7 +112,7 @@ func (c *WaitCompiler) emitWaitEventStreamSetup(state waitEventCompileState, str
112112func (c * WaitCompiler ) emitWaitEventIteration (
113113 ctx fql.IWaitForEventExpressionContext ,
114114 state waitEventCompileState ,
115- streamReg , timeoutStateReg bytecode.Operand ,
115+ streamReg , resultReg , timeoutStateReg bytecode.Operand ,
116116 restartLabel , doneLabel core.Label ,
117117) {
118118 c .ctx .Program .Emitter .WithSpan (state .span , func () {
@@ -124,16 +124,26 @@ func (c *WaitCompiler) emitWaitEventIteration(
124124 c .ctx .Program .Emitter .EmitIterNext (streamReg , doneLabel )
125125 })
126126
127- if filter := ctx .EventFilterClause (); filter != nil {
128- eventValReg , _ := c .ctx .Function .Symbols .DeclareLocal (core .PseudoVariable , core .TypeUnknown )
129-
127+ filter := ctx .EventFilterClause ()
128+ if filter == nil {
130129 c .ctx .Program .Emitter .WithSpan (state .span , func () {
131- c .ctx .Program .Emitter .EmitAB ( bytecode . OpIterValue , eventValReg , streamReg )
130+ c .ctx .Program .Emitter .EmitIterValue ( resultReg , streamReg )
132131 })
133-
134- cond := c .exprs .CompileWithImplicitCurrent (filter .Expression ())
135- c .ctx .Program .Emitter .EmitJumpIfFalse (cond , restartLabel )
132+ return
136133 }
134+
135+ eventValReg , _ := c .ctx .Function .Symbols .DeclareLocal (core .PseudoVariable , core .TypeUnknown )
136+
137+ c .ctx .Program .Emitter .WithSpan (state .span , func () {
138+ c .ctx .Program .Emitter .EmitIterValue (eventValReg , streamReg )
139+ })
140+
141+ cond := c .exprs .CompileWithImplicitCurrent (filter .Expression ())
142+ c .ctx .Program .Emitter .EmitJumpIfFalse (cond , restartLabel )
143+
144+ c .ctx .Program .Emitter .WithSpan (state .span , func () {
145+ c .ctx .Program .Emitter .EmitMove (resultReg , eventValReg )
146+ })
137147}
138148
139149func (c * WaitCompiler ) emitWaitEventCleanup (state waitEventCompileState , streamReg bytecode.Operand ) {
0 commit comments