Skip to content

Commit

Permalink
Clarify doc comments around closing variables
Browse files Browse the repository at this point in the history
  • Loading branch information
zombiezen committed Dec 15, 2024
1 parent 9d6c945 commit e024d8b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 5 additions & 3 deletions internal/luacode/funcstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ type funcState struct {
// instructionsSinceLastAbsLineInfo is a counter
// of instructions added since the last [absLineInfo].
instructionsSinceLastAbsLineInfo uint8
// needClose is true if the function needs to close upvalues when returning.
// needClose is true if the function needs to close upvalues and/or to-be-closed variables
// when returning.
needClose bool
}

Expand All @@ -53,8 +54,9 @@ type blockControl struct {
numActiveVariables uint8

// upval is true if some variable in the block is an upvalue.
upval bool
isLoop bool
upval bool
isLoop bool
// insideTBC is true if any to-be-closed locals are in scope.
insideTBC bool
}

Expand Down
10 changes: 8 additions & 2 deletions internal/luacode/instruction.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,17 @@ const (
OpReturn OpCode = 70 // RETURN
// OpReturn0 instructs control flow to return to the function's caller
// with zero results.
// This instruction cannot be used in a variadic function.
// This instruction cannot be used in a function
// that is variadic,
// has variables referenced by its functions,
// or has to-be-closed variables.
OpReturn0 OpCode = 71 // RETURN0
// OpReturn1 instructs control flow to return to the function's caller
// with a single result stored in R[A].
// This instruction cannot be used in a variadic function.
// This instruction cannot be used in a function
// that is variadic,
// has variables referenced by its functions,
// or has to-be-closed variables.
//
// A return R[A]
OpReturn1 OpCode = 72 // RETURN1
Expand Down

0 comments on commit e024d8b

Please sign in to comment.