aboutsummaryrefslogtreecommitdiff
path: root/internal/compile
diff options
context:
space:
mode:
authoralandonovan <adonovan@google.com>2018-04-02 13:19:37 -0400
committerGitHub <noreply@github.com>2018-04-02 13:19:37 -0400
commitc67265e374b0d3814379f37ff33e0e2cdfe4811a (patch)
tree4680f9366664153d071bfe74e47e4e07d6d7df1e /internal/compile
parent8c4023ca890bad71d4936423cee71acfd0a93a8e (diff)
downloadstarlark-go-c67265e374b0d3814379f37ff33e0e2cdfe4811a.tar.gz
compile: add test update missing from previous CL (#99)
Diffstat (limited to 'internal/compile')
-rw-r--r--internal/compile/codegen_test.go29
1 files changed, 15 insertions, 14 deletions
diff --git a/internal/compile/codegen_test.go b/internal/compile/codegen_test.go
index a37ac29..6539946 100644
--- a/internal/compile/codegen_test.go
+++ b/internal/compile/codegen_test.go
@@ -20,39 +20,37 @@ func TestPlusFolding(t *testing.T) {
}{
{
// string folding
- // const + const + const + const => const
`"a" + "b" + "c" + "d"`,
- `string "abcd"; return`,
+ `constant "abcd"; return`,
},
{
// string folding with variable:
- // const + const + var + const + const => sum(const, var, const)
`"a" + "b" + x + "c" + "d"`,
- `string "ab"; predeclared x; plus; string "cd"; plus; return`,
+ `constant "ab"; predeclared x; plus; constant "cd"; plus; return`,
},
{
// list folding
`[1] + [2] + [3]`,
- `int 1; int 2; int 3; makelist<3>; return`,
+ `constant 1; constant 2; constant 3; makelist<3>; return`,
},
{
// list folding with variable
`[1] + [2] + x + [3]`,
- `int 1; int 2; makelist<2>; ` +
+ `constant 1; constant 2; makelist<2>; ` +
`predeclared x; plus; ` +
- `int 3; makelist<1>; plus; ` +
+ `constant 3; makelist<1>; plus; ` +
`return`,
},
{
// tuple folding
`() + (1,) + (2, 3)`,
- `int 1; int 2; int 3; maketuple<3>; return`,
+ `constant 1; constant 2; constant 3; maketuple<3>; return`,
},
{
// tuple folding with variable
`() + (1,) + x + (2, 3)`,
- `int 1; maketuple<1>; predeclared x; plus; ` +
- `int 2; int 3; maketuple<2>; plus; ` +
+ `constant 1; maketuple<1>; predeclared x; plus; ` +
+ `constant 2; constant 3; maketuple<2>; plus; ` +
`return`,
},
} {
@@ -100,10 +98,13 @@ func disassemble(f *Funcode) string {
fmt.Fprintf(out, "%s", op)
if op >= OpcodeArgMin {
switch op {
- case INT, FLOAT, BIGINT:
- fmt.Fprintf(out, " %v", f.Prog.Constants[arg])
- case STRING:
- fmt.Fprintf(out, " %q", f.Prog.Constants[arg])
+ case CONSTANT:
+ switch x := f.Prog.Constants[arg].(type) {
+ case string:
+ fmt.Fprintf(out, " %q", x)
+ default:
+ fmt.Fprintf(out, " %v", x)
+ }
case LOCAL:
fmt.Fprintf(out, " %s", f.Locals[arg].Name)
case PREDECLARED: