Commit b751be4c authored by Austin Clements's avatar Austin Clements

Cleanup func literals. "func (" -> "func("

R=rsc
APPROVED=rsc
DELTA=41  (0 added, 0 deleted, 41 changed)
OCL=31773
CL=31773
parent 96e84439
...@@ -31,18 +31,18 @@ type exprCompiler struct { ...@@ -31,18 +31,18 @@ type exprCompiler struct {
pos token.Position; pos token.Position;
t Type; t Type;
// Evaluate this node as the given type. // Evaluate this node as the given type.
evalBool func (f *Frame) bool; evalBool func(f *Frame) bool;
evalUint func (f *Frame) uint64; evalUint func(f *Frame) uint64;
evalInt func (f *Frame) int64; evalInt func(f *Frame) int64;
evalIdealInt func () *bignum.Integer; evalIdealInt func() *bignum.Integer;
evalFloat func (f *Frame) float64; evalFloat func(f *Frame) float64;
evalIdealFloat func () *bignum.Rational; evalIdealFloat func() *bignum.Rational;
evalString func (f *Frame) string; evalString func(f *Frame) string;
evalPtr func (f *Frame) Value; evalPtr func(f *Frame) Value;
// Evaluate to the "address of" this value; that is, the // Evaluate to the "address of" this value; that is, the
// settable Value object. nil for expressions whose address // settable Value object. nil for expressions whose address
// cannot be taken. // cannot be taken.
evalAddr func (f *Frame) Value; evalAddr func(f *Frame) Value;
// A short string describing this expression for error // A short string describing this expression for error
// messages. Only necessary if t != nil. // messages. Only necessary if t != nil.
desc string; desc string;
...@@ -93,56 +93,56 @@ func (a *exprCompiler) diagOpTypes(op token.Token, lt Type, rt Type) { ...@@ -93,56 +93,56 @@ func (a *exprCompiler) diagOpTypes(op token.Token, lt Type, rt Type) {
a.diag("illegal operand types for '%v' operator\n\t%v\n\t%v", op, lt, rt); a.diag("illegal operand types for '%v' operator\n\t%v\n\t%v", op, lt, rt);
} }
func (a *exprCompiler) asBool() (func (f *Frame) bool) { func (a *exprCompiler) asBool() (func(f *Frame) bool) {
if a.evalBool == nil { if a.evalBool == nil {
log.Crashf("tried to get %v node as boolType", a.t); log.Crashf("tried to get %v node as boolType", a.t);
} }
return a.evalBool; return a.evalBool;
} }
func (a *exprCompiler) asUint() (func (f *Frame) uint64) { func (a *exprCompiler) asUint() (func(f *Frame) uint64) {
if a.evalUint == nil { if a.evalUint == nil {
log.Crashf("tried to get %v node as uintType", a.t); log.Crashf("tried to get %v node as uintType", a.t);
} }
return a.evalUint; return a.evalUint;
} }
func (a *exprCompiler) asInt() (func (f *Frame) int64) { func (a *exprCompiler) asInt() (func(f *Frame) int64) {
if a.evalInt == nil { if a.evalInt == nil {
log.Crashf("tried to get %v node as intType", a.t); log.Crashf("tried to get %v node as intType", a.t);
} }
return a.evalInt; return a.evalInt;
} }
func (a *exprCompiler) asIdealInt() (func () *bignum.Integer) { func (a *exprCompiler) asIdealInt() (func() *bignum.Integer) {
if a.evalIdealInt == nil { if a.evalIdealInt == nil {
log.Crashf("tried to get %v node as idealIntType", a.t); log.Crashf("tried to get %v node as idealIntType", a.t);
} }
return a.evalIdealInt; return a.evalIdealInt;
} }
func (a *exprCompiler) asFloat() (func (f *Frame) float64) { func (a *exprCompiler) asFloat() (func(f *Frame) float64) {
if a.evalFloat == nil { if a.evalFloat == nil {
log.Crashf("tried to get %v node as floatType", a.t); log.Crashf("tried to get %v node as floatType", a.t);
} }
return a.evalFloat; return a.evalFloat;
} }
func (a *exprCompiler) asIdealFloat() (func () *bignum.Rational) { func (a *exprCompiler) asIdealFloat() (func() *bignum.Rational) {
if a.evalIdealFloat == nil { if a.evalIdealFloat == nil {
log.Crashf("tried to get %v node as idealFloatType", a.t); log.Crashf("tried to get %v node as idealFloatType", a.t);
} }
return a.evalIdealFloat; return a.evalIdealFloat;
} }
func (a *exprCompiler) asString() (func (f *Frame) string) { func (a *exprCompiler) asString() (func(f *Frame) string) {
if a.evalString == nil { if a.evalString == nil {
log.Crashf("tried to get %v node as stringType", a.t); log.Crashf("tried to get %v node as stringType", a.t);
} }
return a.evalString; return a.evalString;
} }
func (a *exprCompiler) asPtr() (func (f *Frame) Value) { func (a *exprCompiler) asPtr() (func(f *Frame) Value) {
if a.evalPtr == nil { if a.evalPtr == nil {
log.Crashf("tried to get %v node as PtrType", a.t); log.Crashf("tried to get %v node as PtrType", a.t);
} }
...@@ -165,10 +165,10 @@ func (a *exprCompiler) DoIdent(x *ast.Ident) { ...@@ -165,10 +165,10 @@ func (a *exprCompiler) DoIdent(x *ast.Ident) {
switch _ := a.t.literal().(type) { switch _ := a.t.literal().(type) {
case *idealIntType: case *idealIntType:
val := def.Value.(IdealIntValue).Get(); val := def.Value.(IdealIntValue).Get();
a.evalIdealInt = func () *bignum.Integer { return val; }; a.evalIdealInt = func() *bignum.Integer { return val; };
case *idealFloatType: case *idealFloatType:
val := def.Value.(IdealFloatValue).Get(); val := def.Value.(IdealFloatValue).Get();
a.evalIdealFloat = func () *bignum.Rational { return val; }; a.evalIdealFloat = func() *bignum.Rational { return val; };
default: default:
log.Crashf("unexpected constant type: %v", a.t); log.Crashf("unexpected constant type: %v", a.t);
} }
...@@ -181,7 +181,7 @@ func (a *exprCompiler) DoIdent(x *ast.Ident) { ...@@ -181,7 +181,7 @@ func (a *exprCompiler) DoIdent(x *ast.Ident) {
a.t = def.Type; a.t = def.Type;
defidx := def.Index; defidx := def.Index;
a.genIdentOp(def.Type, dscope, defidx); a.genIdentOp(def.Type, dscope, defidx);
a.evalAddr = func (f *Frame) Value { a.evalAddr = func(f *Frame) Value {
return f.Get(dscope, defidx); return f.Get(dscope, defidx);
}; };
a.desc = "variable"; a.desc = "variable";
...@@ -194,7 +194,7 @@ func (a *exprCompiler) DoIdent(x *ast.Ident) { ...@@ -194,7 +194,7 @@ func (a *exprCompiler) DoIdent(x *ast.Ident) {
func (a *exprCompiler) doIdealInt(i *bignum.Integer) { func (a *exprCompiler) doIdealInt(i *bignum.Integer) {
a.t = IdealIntType; a.t = IdealIntType;
a.evalIdealInt = func () *bignum.Integer { return i }; a.evalIdealInt = func() *bignum.Integer { return i };
} }
func (a *exprCompiler) DoIntLit(x *ast.IntLit) { func (a *exprCompiler) DoIntLit(x *ast.IntLit) {
...@@ -224,13 +224,13 @@ func (a *exprCompiler) DoCharLit(x *ast.CharLit) { ...@@ -224,13 +224,13 @@ func (a *exprCompiler) DoCharLit(x *ast.CharLit) {
func (a *exprCompiler) DoFloatLit(x *ast.FloatLit) { func (a *exprCompiler) DoFloatLit(x *ast.FloatLit) {
a.t = IdealFloatType; a.t = IdealFloatType;
f, _, _2 := bignum.RatFromString(string(x.Value), 0); f, _, _2 := bignum.RatFromString(string(x.Value), 0);
a.evalIdealFloat = func () *bignum.Rational { return f }; a.evalIdealFloat = func() *bignum.Rational { return f };
a.desc = "float literal"; a.desc = "float literal";
} }
func (a *exprCompiler) doString(s string) { func (a *exprCompiler) doString(s string) {
a.t = StringType; a.t = StringType;
a.evalString = func (*Frame) string { return s }; a.evalString = func(*Frame) string { return s };
} }
func (a *exprCompiler) DoStringLit(x *ast.StringLit) { func (a *exprCompiler) DoStringLit(x *ast.StringLit) {
...@@ -296,7 +296,7 @@ func (a *exprCompiler) DoStarExpr(x *ast.StarExpr) { ...@@ -296,7 +296,7 @@ func (a *exprCompiler) DoStarExpr(x *ast.StarExpr) {
a.t = vt.Elem(); a.t = vt.Elem();
a.genStarOp(v); a.genStarOp(v);
vf := v.asPtr(); vf := v.asPtr();
a.evalAddr = func (f *Frame) Value { return vf(f) }; a.evalAddr = func(f *Frame) Value { return vf(f) };
a.desc = "* expression"; a.desc = "* expression";
default: default:
...@@ -383,7 +383,7 @@ func (a *exprCompiler) DoUnaryExpr(x *ast.UnaryExpr) { ...@@ -383,7 +383,7 @@ func (a *exprCompiler) DoUnaryExpr(x *ast.UnaryExpr) {
case token.AND: case token.AND:
vf := v.evalAddr; vf := v.evalAddr;
a.evalPtr = func (f *Frame) Value { return vf(f) }; a.evalPtr = func(f *Frame) Value { return vf(f) };
default: default:
log.Crashf("Compilation of unary op %v not implemented", x.Op); log.Crashf("Compilation of unary op %v not implemented", x.Op);
...@@ -439,22 +439,22 @@ func (a *exprCompiler) convertTo(t Type) *exprCompiler { ...@@ -439,22 +439,22 @@ func (a *exprCompiler) convertTo(t Type) *exprCompiler {
n, d := rat.Value(); n, d := rat.Value();
f := n.Quo(bignum.MakeInt(false, d)); f := n.Quo(bignum.MakeInt(false, d));
v := f.Abs().Value(); v := f.Abs().Value();
res.evalUint = func (*Frame) uint64 { return v }; res.evalUint = func(*Frame) uint64 { return v };
case *intType: case *intType:
n, d := rat.Value(); n, d := rat.Value();
f := n.Quo(bignum.MakeInt(false, d)); f := n.Quo(bignum.MakeInt(false, d));
v := f.Value(); v := f.Value();
res.evalInt = func (*Frame) int64 { return v }; res.evalInt = func(*Frame) int64 { return v };
case *idealIntType: case *idealIntType:
n, d := rat.Value(); n, d := rat.Value();
f := n.Quo(bignum.MakeInt(false, d)); f := n.Quo(bignum.MakeInt(false, d));
res.evalIdealInt = func () *bignum.Integer { return f }; res.evalIdealInt = func() *bignum.Integer { return f };
case *floatType: case *floatType:
n, d := rat.Value(); n, d := rat.Value();
v := float64(n.Value())/float64(d.Value()); v := float64(n.Value())/float64(d.Value());
res.evalFloat = func (*Frame) float64 { return v }; res.evalFloat = func(*Frame) float64 { return v };
case *idealFloatType: case *idealFloatType:
res.evalIdealFloat = func () *bignum.Rational { return rat }; res.evalIdealFloat = func() *bignum.Rational { return rat };
default: default:
log.Crashf("cannot convert to type %T", t); log.Crashf("cannot convert to type %T", t);
} }
...@@ -774,7 +774,7 @@ func compileExpr(expr ast.Expr, scope *Scope) *exprCompiler { ...@@ -774,7 +774,7 @@ func compileExpr(expr ast.Expr, scope *Scope) *exprCompiler {
*/ */
type Expr struct { type Expr struct {
f func (f *Frame) Value; f func(f *Frame) Value;
} }
func (expr *Expr) Eval(f *Frame) Value { func (expr *Expr) Eval(f *Frame) Value {
...@@ -791,21 +791,21 @@ func CompileExpr(expr ast.Expr, scope *Scope) *Expr { ...@@ -791,21 +791,21 @@ func CompileExpr(expr ast.Expr, scope *Scope) *Expr {
// Need to figure out a better way to do this. // Need to figure out a better way to do this.
switch t := ec.t.(type) { switch t := ec.t.(type) {
case *boolType: case *boolType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalBool(f)) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalBool(f)) }};
case *uintType: case *uintType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalUint(f)) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalUint(f)) }};
case *intType: case *intType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalInt(f)) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalInt(f)) }};
case *idealIntType: case *idealIntType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalIdealInt()) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalIdealInt()) }};
case *floatType: case *floatType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalFloat(f)) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalFloat(f)) }};
case *idealFloatType: case *idealFloatType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalIdealFloat()) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalIdealFloat()) }};
case *stringType: case *stringType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalString(f)) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalString(f)) }};
case *PtrType: case *PtrType:
return &Expr{func (f *Frame) Value { return t.value(ec.evalPtr(f)) }}; return &Expr{func(f *Frame) Value { return t.value(ec.evalPtr(f)) }};
} }
log.Crashf("unexpected type %v", ec.t); log.Crashf("unexpected type %v", ec.t);
return nil; return nil;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment