Skip to content

Commit

Permalink
Merge pull request #3786 from onflow/bastian/3773-test-compilation
Browse files Browse the repository at this point in the history
[Compiler] Test compilation of currently supported features
  • Loading branch information
turbolent authored Feb 21, 2025
2 parents 049c7ef + 6291723 commit 2719e99
Show file tree
Hide file tree
Showing 2 changed files with 1,080 additions and 50 deletions.
24 changes: 12 additions & 12 deletions bbq/compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ func (c *Compiler[_]) popLoop() {

var previousLoop *loop
if lastIndex > 0 {
previousLoop = c.loops[lastIndex]
previousLoop = c.loops[lastIndex-1]
}
c.currentLoop = previousLoop
}
Expand Down Expand Up @@ -1085,24 +1085,24 @@ func (c *Compiler[_]) VisitBinaryExpression(expression *ast.BinaryExpression) (_

switch expression.Operation {
case ast.OperationNilCoalesce:
// create a duplicate to perform the equal check.
// So if the condition succeeds, then the condition's result will be at the top of the stack.
// Duplicate the value for the nil equality check.
c.codeGen.Emit(opcode.InstructionDup{})
elseJump := c.emitUndefinedJumpIfNil()

c.codeGen.Emit(opcode.InstructionNil{})
c.codeGen.Emit(opcode.InstructionEqual{})
elseJump := c.emitUndefinedJumpIfFalse()
// Then branch
c.codeGen.Emit(opcode.InstructionUnwrap{})
thenJump := c.emitUndefinedJump()

// Drop the duplicated condition result.
// It is not needed for the 'then' path.
// Else branch
c.patchJump(elseJump)
// Drop the duplicated condition result,
// as it is not needed for the 'else' path.
c.codeGen.Emit(opcode.InstructionDrop{})

c.compileExpression(expression.Right)

thenJump := c.emitUndefinedJump()
c.patchJump(elseJump)
c.codeGen.Emit(opcode.InstructionUnwrap{})
// End
c.patchJump(thenJump)

default:
c.compileExpression(expression.Right)

Expand Down
Loading

0 comments on commit 2719e99

Please sign in to comment.