Skip to content

Commit

Permalink
Improve compilation for detached tree parts
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed May 30, 2024
1 parent a601192 commit 7e6e6f5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,10 @@ func (c *compiler) StringNode(node *ast.StringNode) {
}

func (c *compiler) ConstantNode(node *ast.ConstantNode) {
if node.Value == nil {
c.emit(OpNil)
return
}
c.emitPush(node.Value)
}

Expand Down Expand Up @@ -695,7 +699,9 @@ func (c *compiler) MemberNode(node *ast.MemberNode) {
}

c.compile(base)
if node.Optional {
// If the field is optional, we need to jump over the fetch operation.
// If no ChainNode (none c.chains) is used, do not compile the optional fetch.
if node.Optional && len(c.chains) > 0 {
ph := c.emit(OpJumpIfNil, placeholder)
c.chains[len(c.chains)-1] = append(c.chains[len(c.chains)-1], ph)
}
Expand Down

0 comments on commit 7e6e6f5

Please sign in to comment.