Skip to content

Commit

Permalink
compile: add missing opcodeName[EXCH] (google#5)
Browse files Browse the repository at this point in the history
Also,
- make Opcode.String catch future missing entries.
- document (*Function).Param.
  • Loading branch information
adonovan authored Nov 2, 2018
1 parent 59a38fd commit 9b05555
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion internal/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var opcodeNames = [...]string{
DUP2: "dup2",
DUP: "dup",
EQL: "eql",
EXCH: "exch",
FALSE: "false",
FREE: "free",
GE: "ge",
Expand Down Expand Up @@ -271,7 +272,9 @@ var stackEffect = [...]int8{

func (op Opcode) String() string {
if op < OpcodeMax {
return opcodeNames[op]
if name := opcodeNames[op]; name != "" {
return name
}
}
return fmt.Sprintf("illegal op (%d)", op)
}
Expand Down
3 changes: 3 additions & 0 deletions starlark/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ func (fn *Function) Globals() StringDict {

func (fn *Function) Position() syntax.Position { return fn.funcode.Pos }
func (fn *Function) NumParams() int { return fn.funcode.NumParams }

// Param returns the name and position of the ith parameter,
// where 0 <= i < NumParams().
func (fn *Function) Param(i int) (string, syntax.Position) {
id := fn.funcode.Locals[i]
return id.Name, id.Pos
Expand Down

0 comments on commit 9b05555

Please sign in to comment.