当前位置: 首页>>代码示例>>Golang>>正文


Golang value.Errorf函数代码示例

本文整理汇总了Golang中robpike/io/ivy/value.Errorf函数的典型用法代码示例。如果您正苦于以下问题:Golang Errorf函数的具体用法?Golang Errorf怎么用?Golang Errorf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Errorf函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: noOp

// noOp is the dual of noVar. It also checks for assignment to builtins.
// It just errors out if there is a conflict.
func (c *Context) noOp(name string) {
	if name == "pi" || name == "e" { // Cannot redefine these.
		value.Errorf("cannot reassign %q", name)
	}
	if c.UnaryFn[name] == nil && c.BinaryFn[name] == nil {
		return
	}
	value.Errorf("cannot define variable %s; it is an op", name)
}
开发者ID:ghost-dog,项目名称:ivy,代码行数:11,代码来源:context.go

示例2: noVar

// noVar guarantees that there is no global variable with that name,
// preventing an op from being defined with the same name as a variable,
// which could cause problems. A variable with value zero is considered to
// be OK, so one can clear a variable before defining a symbol. A cleared
// variable is removed from the global symbol table.
// noVar also prevents defining builtin variables as ops.
func (c *Context) noVar(name string) {
	if name == "_" || name == "pi" || name == "e" { // Cannot redefine these.
		value.Errorf(`cannot define op with name %q`, name)
	}
	sym := c.Stack[0][name]
	if sym == nil {
		return
	}
	if i, ok := sym.(value.Int); ok && i == 0 {
		delete(c.Stack[0], name)
		return
	}
	value.Errorf("cannot define op %s; it is a variable (%[1]s=0 to clear)", name)
}
开发者ID:ghost-dog,项目名称:ivy,代码行数:20,代码来源:context.go

示例3: Eval

func (e variableExpr) Eval(context value.Context) value.Value {
	v := context.Lookup(e.name)
	if v == nil {
		value.Errorf("undefined variable %q", e.name)
	}
	return v
}
开发者ID:db47h,项目名称:ivy,代码行数:7,代码来源:parse.go

示例4: Eval

func (u *unaryCall) Eval(context value.Context) value.Value {
	arg := u.arg.Eval(context)
	context.Push()
	defer context.Pop()
	exec := context.(*execContext) // Sigh.
	fn := exec.unaryFn[u.name]
	if fn == nil || fn.body == nil {
		value.Errorf("unary %q undefined", u.name)
	}
	context.AssignLocal(fn.right.name, arg)
	var v value.Value
	for _, e := range fn.body {
		v = e.Eval(context)
	}
	if v == nil {
		value.Errorf("no value returned by %q", u.name)
	}
	return v
}
开发者ID:nathangrigg,项目名称:ivy,代码行数:19,代码来源:function.go

示例5: EvalUnary

// EvalUnary evaluates a unary operator.
func (c *Context) EvalUnary(op string, right value.Value) value.Value {
	right = right.Eval(c)
	fn := c.UnaryFn[op]
	if fn == nil {
		return value.Unary(c, op, right)
	}
	if fn.Body == nil {
		value.Errorf("unary %q undefined", op)
	}
	c.push()
	defer c.pop()
	c.assignLocal(fn.Right, right)
	var v value.Value
	for _, e := range fn.Body {
		v = e.Eval(c)
	}
	if v == nil {
		value.Errorf("no value returned by %q", op)
	}
	return v
}
开发者ID:ghost-dog,项目名称:ivy,代码行数:22,代码来源:context.go

示例6: Assign

// Assign assigns the variable the value. The variable must
// be defined either in the current function or globally.
// Inside a function, new variables become locals.
func (c *Context) Assign(name string, val value.Value) {
	n := len(c.Stack)
	if n == 0 {
		value.Errorf("empty stack; cannot happen")
	}
	globals := c.Stack[0]
	if n > 1 {
		// In this function?
		frame := c.Stack[n-1]
		_, globallyDefined := globals[name]
		if _, ok := frame[name]; ok || !globallyDefined {
			frame[name] = val
			return
		}
	}
	// Assign global variable.
	c.noOp(name)
	globals[name] = val
}
开发者ID:ghost-dog,项目名称:ivy,代码行数:22,代码来源:context.go

示例7: put

// put writes to out a version of the value that will recreate it when parsed.
func put(out io.Writer, val value.Value) {
	switch val := val.(type) {
	case value.Char:
		fmt.Fprintf(out, "%q", rune(val))
	case value.Int:
		fmt.Fprintf(out, "%d", int(val))
	case value.BigInt:
		fmt.Fprintf(out, "%d", val.Int)
	case value.BigRat:
		fmt.Fprintf(out, "%d/%d", val.Num(), val.Denom())
	case value.BigFloat:
		// TODO The actual value might not have the same prec as
		// the configuration, so we might not get this right
		// Probably not important but it would be nice to fix it.
		if val.Sign() == 0 || val.IsInf() {
			// These have prec 0 and are easy.
			// They shouldn't appear anyway, but be safe.
			fmt.Fprintf(out, "%g", val)
			return
		}
		digits := int(float64(val.Prec()) * 0.301029995664) // 10 log 2.
		fmt.Fprintf(out, "%.*g", digits, val.Float)
	case value.Vector:
		if val.AllChars() {
			fmt.Fprintf(out, "%q", val)
			return
		}
		for i, v := range val {
			if i > 0 {
				fmt.Fprint(out, " ")
			}
			put(out, v)
		}
	case value.Matrix:
		put(out, val.Shape())
		fmt.Fprint(out, " rho ")
		put(out, val.Data())
	default:
		value.Errorf("internal error: can't save type %T", val)
	}
}
开发者ID:zzn01,项目名称:ivy,代码行数:42,代码来源:save.go

示例8: save

// save writes the state of the workspace to the named file.
// The format of the output is ivy source text.
func save(c *exec.Context, file string, conf *config.Config) {
	// "<conf.out>" is a special case for testing.
	out := conf.Output()
	if file != "<conf.out>" {
		fd, err := os.Create(file)
		if err != nil {
			value.Errorf("%s", err)
		}
		defer fd.Close()
		buf := bufio.NewWriter(fd)
		defer buf.Flush()
		out = buf
	}

	// Configuration settings. We will set the base below,
	// after we have printed all numbers in base 10.
	fmt.Fprintf(out, ")prec %d\n", conf.FloatPrec())
	ibase, obase := conf.Base()
	fmt.Fprintf(out, ")maxbits %d\n", conf.MaxBits())
	fmt.Fprintf(out, ")maxdigits %d\n", conf.MaxDigits())
	fmt.Fprintf(out, ")origin %d\n", conf.Origin())
	fmt.Fprintf(out, ")prompt %q\n", conf.Prompt())
	fmt.Fprintf(out, ")format %q\n", conf.Format())

	// Ops.
	printed := make(map[exec.OpDef]bool)
	for _, def := range c.Defs {
		var fn *exec.Function
		if def.IsBinary {
			fn = c.BinaryFn[def.Name]
		} else {
			fn = c.UnaryFn[def.Name]
		}
		for _, ref := range references(c, fn.Body) {
			if !printed[ref] {
				if ref.IsBinary {
					fmt.Fprintf(out, "op _ %s _\n", ref.Name)
				} else {
					fmt.Fprintf(out, "op %s _\n", ref.Name)
				}
				printed[ref] = true
			}
		}
		printed[def] = true
		fmt.Fprintln(out, fn)
	}

	// Global variables.
	syms := c.Stack[0]
	if len(syms) > 0 {
		// Set the base strictly to 10 for output.
		fmt.Fprintf(out, "# Set base 10 for parsing numbers.\n)base 10\n")
		// Sort the names for consistent output.
		sorted := sortSyms(syms)
		for _, sym := range sorted {
			// pi and e are generated
			if sym.name == "pi" || sym.name == "e" {
				continue
			}
			fmt.Fprintf(out, "%s = ", sym.name)
			put(out, sym.val)
			fmt.Fprint(out, "\n")
		}
	}

	// Now we can set the base.
	fmt.Fprintf(out, ")ibase %d\n", ibase)
	fmt.Fprintf(out, ")obase %d\n", obase)
}
开发者ID:zzn01,项目名称:ivy,代码行数:71,代码来源:save.go

示例9: errorf

func (p *Parser) errorf(format string, args ...interface{}) {
	p.peekTok = scan.Token{Type: scan.EOF}
	value.Errorf(format, args...)
}
开发者ID:db47h,项目名称:ivy,代码行数:4,代码来源:parse.go


注:本文中的robpike/io/ivy/value.Errorf函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。