• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang halt.As函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ToInt

func (v Value) ToInt() (ret int64) {
	switch v.T {
	case INTEGER:
		ret = v.V.(int64)
	default:
		halt.As(100, v.T)
	}
	return
}
开发者ID:kpmy,项目名称:clac,代码行数:9,代码来源:val.go


示例17: ToBool

func (v Value) ToBool() (ret bool) {
	switch v.T {
	case BOOLEAN:
		ret = v.V.(bool)
	default:
		halt.As(100, v.T)
	}
	return
}
开发者ID:kpmy,项目名称:clac,代码行数:9,代码来源:val.go


示例18: thisVal

func thisVal(x interface{}) (ret interface{}) {
	switch x.(type) {
	case int64, complex128, float64:
		ret = x
	default:
		halt.As(100, reflect.TypeOf(x))
	}
	return
}
开发者ID:kpmy,项目名称:clac,代码行数:9,代码来源:val.go


示例19: cval

func cval(e *ir.ConstExpr) (ret *value) {
	t := e.Type
	switch t {
	case types.INTEGER:
		b := big.NewInt(0)
		if err := b.UnmarshalText([]byte(e.Value.(string))); err == nil {
			v := ThisInt(b)
			ret = &value{typ: t, val: v}
		} else {
			halt.As(100, "wrong integer")
		}
	case types.REAL:
		r := big.NewRat(0, 1)
		if err := r.UnmarshalText([]byte(e.Value.(string))); err == nil {
			v := ThisRat(r)
			ret = &value{typ: t, val: v}
		} else {
			halt.As(100, "wrong real")
		}
	case types.BOOLEAN:
		ret = &value{typ: t, val: e.Value.(bool)}
	case types.TRILEAN:
		ret = &value{typ: t, val: tri.NIL}
	case types.CHAR:
		var v rune
		switch x := e.Value.(type) {
		case int32:
			v = rune(x)
		case int:
			v = rune(x)
		default:
			halt.As(100, "unsupported rune coding")
		}
		ret = &value{typ: t, val: v}
	case types.STRING:
		v := e.Value.(string)
		ret = &value{typ: t, val: v}
	case types.ANY:
		ret = &value{typ: t, val: &Any{}}
	default:
		halt.As(100, "unknown type ", t, " for ", e)
	}
	return
}
开发者ID:kpmy,项目名称:lomo,代码行数:44,代码来源:val.go


示例20: toAny

func (v *value) toAny() (ret *Any) {
	assert.For(v.typ == types.ANY, 20)
	switch x := v.val.(type) {
	case *Any:
		ret = ThisAny(&value{typ: x.typ, val: x.x})
	default:
		halt.As(100, "wrong any ", reflect.TypeOf(x))
	}
	return
}
开发者ID:kpmy,项目名称:lomo,代码行数:10,代码来源:val.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang beanstalk.Dial函数代码示例发布时间:2022-05-23
下一篇:
Golang assert.For函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap