From 6bc6da88ecbd2f922db37a40f3e3b75daceaf891 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Tue, 10 Sep 2013 12:08:55 -0400 Subject: [PATCH] go.tools/ssa/interp: implement unary negation of complex numbers. Fixes golang/go#6291. Also: call go/types.DefaultSizeof instead of hard-coding the initial value of runtime.sizeof_C_MStats. R=gri CC=golang-dev https://golang.org/cl/13648043 --- ssa/interp/interp.go | 9 +++------ ssa/interp/ops.go | 4 ++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ssa/interp/interp.go b/ssa/interp/interp.go index 2f206e0c..de37cdda 100644 --- a/ssa/interp/interp.go +++ b/ssa/interp/interp.go @@ -571,12 +571,9 @@ func Interpret(mainpkg *ssa.Package, mode Mode, filename string, args []string) setGlobal(i, pkg, "envs", envs) case "runtime": - // TODO(gri): expose go/types.sizeof so we can - // avoid this fragile magic number; - // unsafe.Sizeof(memStats) won't work since gc - // and go/types have different sizeof - // functions. - setGlobal(i, pkg, "sizeof_C_MStats", uintptr(3696)) + // (Assumes no custom Sizeof used during SSA construction.) + sz := types.DefaultSizeof(pkg.Object.Scope().Lookup("MemStats").Type()) + setGlobal(i, pkg, "sizeof_C_MStats", uintptr(sz)) case "os": Args := []value{filename} diff --git a/ssa/interp/ops.go b/ssa/interp/ops.go index 95c0a68b..432c5220 100644 --- a/ssa/interp/ops.go +++ b/ssa/interp/ops.go @@ -797,6 +797,10 @@ func unop(instr *ssa.UnOp, x value) value { return -x case float64: return -x + case complex64: + return -x + case complex128: + return -x } case token.MUL: return copyVal(*x.(*value)) // load