From 9b055554f3041bf94f47bef9747f9f291b0f7392 Mon Sep 17 00:00:00 2001 From: alandonovan Date: Fri, 2 Nov 2018 14:29:51 -0400 Subject: [PATCH] compile: add missing opcodeName[EXCH] (#5) Also, - make Opcode.String catch future missing entries. - document (*Function).Param. --- internal/compile/compile.go | 5 ++++- starlark/value.go | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/compile/compile.go b/internal/compile/compile.go index 99e9d542..8da415b8 100644 --- a/internal/compile/compile.go +++ b/internal/compile/compile.go @@ -152,6 +152,7 @@ var opcodeNames = [...]string{ DUP2: "dup2", DUP: "dup", EQL: "eql", + EXCH: "exch", FALSE: "false", FREE: "free", GE: "ge", @@ -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) } diff --git a/starlark/value.go b/starlark/value.go index 880329a5..9ec67c82 100644 --- a/starlark/value.go +++ b/starlark/value.go @@ -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