import (
"bignum";
"go/ast";
- "go/scanner";
"go/token";
"log";
- "os";
"strconv";
"strings";
)
// expression.
func (a *expr) derefArray() *expr {
if pt, ok := a.t.lit().(*PtrType); ok {
- if at, ok := pt.Elem.lit().(*ArrayType); ok {
+ if _, ok := pt.Elem.lit().(*ArrayType); ok {
deref := a.compileStarExpr(a);
if deref == nil {
log.Crashf("failed to dereference *array");
switch x := x.(type) {
// Literals
- case *ast.CharLit:
- return ei.compileCharLit(string(x.Value));
+ case *ast.BasicLit:
+ switch x.Kind {
+ case token.INT:
+ return ei.compileIntLit(string(x.Value));
+ case token.FLOAT:
+ return ei.compileFloatLit(string(x.Value));
+ case token.CHAR:
+ return ei.compileCharLit(string(x.Value));
+ case token.STRING:
+ return ei.compileStringLit(string(x.Value));
+ default:
+ log.Crashf("unexpected basic literal type %v", x.Kind);
+ }
case *ast.CompositeLit:
goto notimpl;
- case *ast.FloatLit:
- return ei.compileFloatLit(string(x.Value));
-
case *ast.FuncLit:
decl := ei.compileFuncType(a.block, x.Type);
if decl == nil {
}
return ei.compileFuncLit(decl, fn);
- case *ast.IntLit:
- return ei.compileIntLit(string(x.Value));
-
- case *ast.StringLit:
- return ei.compileStringLit(string(x.Value));
-
// Types
case *ast.ArrayType:
// TODO(austin) Use a multi-type case
}
func (a *exprInfo) compileIntLit(lit string) *expr {
- i, _, _2 := bignum.IntFromString(lit, 0);
+ i, _, _ := bignum.IntFromString(lit, 0);
return a.compileIdealInt(i, "integer literal");
}
a.silentErrors++;
return nil;
}
- v, mb, tail, err := strconv.UnquoteChar(lit[1:len(lit)], '\'');
+ v, _, tail, err := strconv.UnquoteChar(lit[1:len(lit)], '\'');
if err != nil || tail != "'" {
// Caught by parser
a.silentErrors++;
// If it's a named type, look for methods
if ti, ok := t.(*NamedType); ok {
- method, ok := ti.methods[name];
+ _, ok := ti.methods[name];
if ok {
mark(depth, pathName + "." + name);
log.Crash("Methods not implemented");
return nil;
}
// Arrays and structs may not be compared to anything.
- // TODO(austin) Use a multi-type switch
- if _, ok := l.t.(*ArrayType); ok {
- a.diagOpTypes(op, origlt, origrt);
- return nil;
- }
- if _, ok := l.t.(*StructType); ok {
+ switch l.t.(type) {
+ case *ArrayType, *StructType:
a.diagOpTypes(op, origlt, origrt);
return nil;
}
import (
"bignum";
"log";
- "os";
"go/ast";
- "go/scanner";
"go/token";
- "strconv";
)
const (
// Count cases
ncases := 0;
hasDefault := false;
- for i, c := range s.Body.List {
+ for _, c := range s.Body.List {
clause, ok := c.(*ast.CaseClause);
if !ok {
a.diagAt(clause, "switch statement must contain case clauses");
// Save jump PC's
pc := a.nextPC();
if clause.Values != nil {
- for _, v := range clause.Values {
+ for _ = range clause.Values {
casePCs[i] = &pc;
i++;
}
}
func (a *blockCompiler) compileStmts(block *ast.BlockStmt) {
- for i, sub := range block.List {
+ for _, sub := range block.List {
a.compileStmt(sub);
}
}
var BoolType = universe.DefineType("bool", universePos, &boolType{})
func (t *boolType) compat(o Type, conv bool) bool {
- t2, ok := o.lit().(*boolType);
+ _, ok := o.lit().(*boolType);
return ok;
}
var IdealIntType Type = &idealIntType{}
func (t *idealIntType) compat(o Type, conv bool) bool {
- t2, ok := o.lit().(*idealIntType);
+ _, ok := o.lit().(*idealIntType);
return ok;
}
var IdealFloatType Type = &idealFloatType{};
func (t *idealFloatType) compat(o Type, conv bool) bool {
- t2, ok := o.lit().(*idealFloatType);
+ _, ok := o.lit().(*idealFloatType);
return ok;
}
var StringType = universe.DefineType("string", universePos, &stringType{})
func (t *stringType) compat(o Type, conv bool) bool {
- t2, ok := o.lit().(*stringType);
+ _, ok := o.lit().(*stringType);
return ok;
}
package eval
import (
- "fmt";
"go/ast";
"go/parser";
"go/scanner";
block: w.scope.block,
};
nerr := cc.numError();
- for i, stmt := range stmts {
+ for _, stmt := range stmts {
bc.compileStmt(stmt);
}
fc.checkLabels();
return nil, errors.GetError(scanner.Sorted);
}
var eval func(Value, *Thread);
- switch _ := ec.t.(type) {
+ switch t := ec.t.(type) {
case *idealIntType:
// nothing
case *idealFloatType:
// nothing
+ case *MultiType:
+ if len(t.Elems) == 0 {
+ return &stmtCode{w, code{ec.exec}}, nil;
+ }
+ fallthrough;
default:
eval = genAssign(ec.t, ec);
}