Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compiler] Test compilation of currently supported features #3786

Merged
merged 6 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1076,24 +1076,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
Loading