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


Golang halt.As函数代码示例

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


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

示例1: This

func This(typ Type, _x interface{}) (ret Value) {
	switch typ {
	case INTEGER:
		switch x := _x.(type) {
		case int64:
			ret.V = x
		case int:
			ret.V = int64(x)
		default:
			halt.As(101, reflect.TypeOf(x))
		}
	case FLOAT:
		switch x := _x.(type) {
		case float64:
			ret.V = x
		default:
			halt.As(102, reflect.TypeOf(x))
		}
	case COMPLEX:
		switch x := _x.(type) {
		case complex128:
			ret.V = x
		}
	default:
		halt.As(100, typ)
	}
	ret.T = typ
	return
}
开发者ID:kpmy,项目名称:clac,代码行数:29,代码来源:val.go

示例2: Load

func (w *Words) Load() (err error) {
	w.Lock()
	const docId = "map"
	tmp := make(map[string]interface{})
	if err = wordsDb.Get(docId, &tmp, nil); err == nil {
		for k, _v := range tmp {
			switch v := _v.(type) {
			case map[string]interface{}:
				mm := make(map[string]int)
				for k, _v := range v {
					switch v := _v.(type) {
					case float64:
						mm[k] = int(v)
					default:
						halt.As(100, k, " ", reflect.TypeOf(v))
					}
				}
				w.wm[k] = mm
			case string: //do nothing
			default:
				halt.As(100, k, " ", reflect.TypeOf(v))
			}
		}
	} else if couchdb.NotFound(err) {
		if _, err = wordsDb.Put(docId, tmp, ""); err == nil {
			err = w.Load()
		}
	} else {
		log.Println(err)
	}
	w.Unlock()
	return
}
开发者ID:golang-cjr,项目名称:xep,代码行数:33,代码来源:stem.go

示例3: prettyPrint

func prettyPrint(t *ir.Template, log *testing.T) {
	wr := bytes.NewBufferString("")
	depth := 0
	tab := func() {
		for i := 0; i < depth; i++ {
			fmt.Fprint(wr, " ")
		}
	}
	tab()
	for _, _s := range t.Stmt {
		switch s := _s.(type) {
		case *ir.Emit:
			tab()
			fmt.Fprint(wr, fn.MaybeString(s.Template, "~"), s.Class, fn.MaybeString("(", s.Ident, ")"))
			if s.ChildCount == 0 {
				fmt.Fprintln(wr)
			}
		case *ir.Dive:
			if !s.Reuse {
				fmt.Fprintln(wr, ":")
			} else {
				fmt.Fprintln(wr, " ::")
			}
			depth++
		case *ir.Rise:
			depth--
			tab()
			fmt.Fprintln(wr, ";")
		case *ir.Put:
			tab()
			switch s.Type {
			case types.STRING:
				fmt.Fprint(wr, "`", s.Value, "`")
			case types.REAL, types.INTEGER, types.TRILEAN:
				fmt.Fprint(wr, s.Value)
			case types.CHAR:
				fmt.Fprint(wr, "0", strings.ToUpper(strconv.FormatUint(uint64(s.Value.(rune)), 16)), "U")
			case types.LINK:
				fmt.Fprint(wr, "@", s.Value)
			default:
				halt.As(100, s.Type)
			}
			fmt.Fprintln(wr)
		default:
			halt.As(100, reflect.TypeOf(s))
		}
	}
	log.Log(wr.String())
}
开发者ID:kpmy,项目名称:ot,代码行数:49,代码来源:ot_test_stuff.go

示例4: prettyPrintObject

func prettyPrintObject(o otm.Object, log *testing.T) {
	parent := ""
	for x := o.Parent(); !fn.IsNil(x); x = x.Parent() {
		parent = fmt.Sprint(x.Qualident(), "<-", parent)
	}
	log.Log(parent, o.Qualident())
	if o.ChildrenCount() > 0 {
		log.Log(":")
		for _x := range o.Children() {
			switch x := _x.(type) {
			case otm.Object:
				prettyPrintObject(x, log)
			case otm.Link:
				log.Log("@", x.Object().Qualident())
			case string, float64, int64, rune, tri.Trit:
				log.Log(_x)
			case []uint8:
				s := zbase32.EncodeToString(x)
				log.Log("zbase32(", s, ")", x)
			default:
				halt.As(100, reflect.TypeOf(x))
			}
		}
		log.Log(";")
	}
}
开发者ID:kpmy,项目名称:ot,代码行数:26,代码来源:ot_test_stuff.go

示例5: push

func (b *exprBuilder) push(_e ir.Expression) {
	b.init()
	switch e := _e.(type) {
	case *exprBuilder:
		b.stack.PushFront(e.final())
	case *ir.ConstExpr, *ir.SelectExpr, *ir.ListExpr, *ir.MapExpr, *ir.SetExpr:
		b.stack.PushFront(e)
	case *ir.Monadic:
		e.Expr = b.pop()
		b.stack.PushFront(e)
	case *ir.TypeTest:
		e.Operand = b.pop()
		b.stack.PushFront(e)
	case *ir.Dyadic:
		e.Right = b.pop()
		e.Left = b.pop()
		b.stack.PushFront(e)
	case *ir.Ternary:
		e.Else = b.pop()
		e.Then = b.pop()
		e.If = b.pop()
		b.stack.PushFront(e)
	case *ir.InfixExpr:
		for i := 1; i < len(e.Unit.Infix()); i++ {
			e.Args = append(e.Args, b.pop())
		}
		b.stack.PushFront(e)
	default:
		halt.As(100, reflect.TypeOf(e))
	}
	//fmt.Println("push", _e)
}
开发者ID:kpmy,项目名称:lomo,代码行数:32,代码来源:builder.go

示例6: calcDyadic

func calcDyadic(left *value, op ops.Operation, right *value) (ret *value) {
	if ml, ok := dyadic[left.typ].(tm); ml != nil && ok {
		if dml, ok := ml[right.typ].(df); dml != nil && ok {
			if df := dml[op]; df != nil {
				ret = df(left, right)
			} else {
				halt.As(102, "operation not found ", op, " for ", left.typ, " ", right.typ)
			}
		} else {
			halt.As(101, "unexpected right ", right.typ, " for ", left.typ, " ", op)
		}
	} else {
		halt.As(100, "unexpected left ", left.typ, " ", right.typ, " for ", op)
	}
	return
}
开发者ID:kpmy,项目名称:lomo,代码行数:16,代码来源:calc.go

示例7: attr

func (u *extern) attr(start *xml.StartElement, name string, value interface{}) {
	str := func(value string) {
		assert.For(value != "", 20)
		a := xml.Attr{}
		a.Name.Local = name
		a.Value = value
		start.Attr = append(start.Attr, a)
	}
	switch v := value.(type) {
	case string:
		str(v)
	case bool:
		if v {
			str("true")
		} else {
			str("false")
		}
	case int:
		str(strconv.Itoa(v))
	case types.Type:
		str(v.String())
	default:
		halt.As(100, reflect.TypeOf(v), v)
	}
}
开发者ID:kpmy,项目名称:lomo,代码行数:25,代码来源:st.go

示例8: data

func (i *intern) data(t types.Type, cd xml.CharData) (ret interface{}) {
	switch t {
	case types.INTEGER, types.REAL:
		ret = string(cd)
	case types.BOOLEAN:
		ret = string(cd) == "true"
	case types.TRILEAN:
		if s := string(cd); s == "null" {
			ret = tri.NIL
		} else if s == "true" {
			ret = tri.TRUE
		} else {
			ret = tri.FALSE
		}
	case types.CHAR:
		c, _ := strconv.ParseUint(string(cd), 16, 64)
		ret = rune(c)
	case types.STRING:
		data, err := base64.StdEncoding.DecodeString(string(cd))
		assert.For(err == nil, 30)
		ret = strings.TrimPrefix(string(data), prefix)
	case types.ANY:
		assert.For(string(cd) == "null", 20)
		ret = nil
	default:
		halt.As(100, t)
	}
	return
}
开发者ID:kpmy,项目名称:lomo,代码行数:29,代码来源:st.go

示例9: init

func init() {
	if client, err := couchdb.NewClient(dbUrl, nil); err == nil {
		statsDb, _ = client.CreateDB(dbStatsName)
		wordsDb, _ = client.CreateDB(dbWordsName)
	} else {
		halt.As(100, err)
	}
}
开发者ID:golang-cjr,项目名称:xep,代码行数:8,代码来源:db.go

示例10: do

func (r *stdLd) do(this *Unit, o object) {
	n := get(this.objects["name"]).toStr()
	if u := this.loader(n); u != nil {
		set(o, &value{typ: types.UNIT, val: NewRef(u)})
	} else {
		halt.As(100, "unresolved unit ", n)
	}
}
开发者ID:kpmy,项目名称:lomo,代码行数:8,代码来源:std.go

示例11: init

func init() {
	if client, err := couchdb.NewClient(dbUrl, nil); err == nil {
		db, _ = client.CreateDB(dbName)
	} else {
		halt.As(100, err)
	}

}
开发者ID:postman0,项目名称:xep,代码行数:8,代码来源:stat.go

示例12: put

func put(op Op, l Type, r Type, fn dfn) {
	key := key{op, l, r}
	if _, ok := om[key]; !ok {
		om[key] = dfs{f: fn, err: false}
	} else {
		halt.As(100, "op already exists ", key)
	}
}
开发者ID:kpmy,项目名称:clac,代码行数:8,代码来源:clac.go

示例13: Produce

func (x *domm) Produce() (ret *bytes.Buffer) {
	if data, err := xml.Marshal(x); err == nil {
		ret = bytes.NewBuffer(data)
	} else {
		halt.As(100, ret)
	}
	return
}
开发者ID:kpmy,项目名称:xippo,代码行数:8,代码来源:entity.go

示例14: NewCode

func (i *impl) NewCode(u *ir.Unit, wr io.Writer) {
	e := &extern{x: u}
	if data, err := xml.Marshal(e); err == nil {
		wr.Write([]byte(xml.Header))
		io.Copy(wr, bytes.NewBuffer(data))
	} else {
		halt.As(100, err)
	}
}
开发者ID:kpmy,项目名称:lomo,代码行数:9,代码来源:st.go

示例15: pop

func (s *exprStack) pop() (ret *value) {
	if s.vl.Len() > 0 {
		el := s.vl.Front()
		ret = s.vl.Remove(el).(*value)
	} else {
		halt.As(100, "pop on empty stack")
	}
	return
}
开发者ID:kpmy,项目名称:lomo,代码行数:9,代码来源:val.go


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