本文整理汇总了Golang中github.com/kpmy/ypk/assert.For函数的典型用法代码示例。如果您正苦于以下问题:Golang For函数的具体用法?Golang For怎么用?Golang For使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了For函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: conv
func conv(v *value, target types.Type) (ret *value) {
switch {
case v.typ == types.ANY && target == types.UNIT:
a := v.toAny()
assert.For(a.x == nil, 20)
ret = &value{typ: types.UNIT, val: &Ref{}}
case v.typ == types.INTEGER && target == types.REAL:
i := v.toInt()
x := big.NewRat(0, 1)
ret = &value{typ: target, val: ThisRat(x.SetInt(i))}
case v.typ == types.BOOLEAN && target == types.TRILEAN:
b := v.toBool()
x := tri.This(b)
ret = &value{typ: target, val: x}
case v.typ == types.ANY && target == types.ATOM:
ret = &value{typ: target, val: Atom("")}
case target == types.ANY && v.typ != types.ANY:
x := ThisAny(v)
ret = &value{typ: target, val: x}
case target == types.ANY && v.typ == types.ANY:
x := v.toAny()
ret = &value{typ: target, val: x}
case v.typ == target:
ret = v
}
assert.For(ret != nil, 60, v.typ, target, v.val)
return
}
开发者ID:kpmy,项目名称:lomo,代码行数:28,代码来源:typ.go
示例2: dyPTR
/*
func dyPTR() {
putDyadic(types.PTR, types.PTR, ops.Eq, b_(b_ptr_(b_ptr_ptr_(func(lp *Ptr, rp *Ptr) bool {
return lp.adr == rp.adr
}))))
putDyadic(types.PTR, types.PTR, ops.Neq, b_(b_ptr_(b_ptr_ptr_(func(lp *Ptr, rp *Ptr) bool {
return lp.adr != rp.adr
}))))
}
*/
func dyPROC() {
putDyadic(types.UNIT, types.UNIT, ops.Eq, b_(b_proc_(b_proc_proc_(func(lp *Ref, rp *Ref) bool {
return lp.u == rp.u
}))))
putDyadic(types.UNIT, types.UNIT, ops.Neq, b_(b_proc_(b_proc_proc_(func(lp *Ref, rp *Ref) bool {
return lp.u != rp.u
}))))
putDyadic(types.UNIT, types.ANY, ops.Eq, b_(b_proc_(b_proc_z_(func(la *Ref, ra *Any) bool {
assert.For(ra.x == nil, 40, "UNDEF comparision only")
return la.u == nil
}))))
putDyadic(types.ANY, types.UNIT, ops.Eq, b_(b_z_(b_z_proc_(func(la *Any, ra *Ref) bool {
assert.For(la.x == nil, 40, "UNDEF comparision only")
return ra.u == nil
}))))
putDyadic(types.UNIT, types.ANY, ops.Neq, b_(b_proc_(b_proc_z_(func(la *Ref, ra *Any) bool {
assert.For(ra.x == nil, 40, "UNDEF comparision only")
return la.u != nil
}))))
putDyadic(types.ANY, types.UNIT, ops.Neq, b_(b_z_(b_z_proc_(func(la *Any, ra *Ref) bool {
assert.For(la.x == nil, 40, "UNDEF comparision only")
return ra.u != nil
}))))
}
开发者ID:kpmy,项目名称:lomo,代码行数:40,代码来源:calc.go
示例3: 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
示例4: rulesDecl
func (p *pr) rulesDecl() {
assert.For(p.sym.Code == lss.Process, 20, "PROCESS block expected")
p.next()
for stop := false; !stop; {
p.pass(lss.Delimiter, lss.Separator)
expr := &exprBuilder{tgt: &p.target, marker: p}
p.expression(expr)
p.expect(lss.ArrowRight, "assign expected", lss.Delimiter, lss.Separator)
p.next()
p.pass(lss.Delimiter, lss.Separator)
id := p.ident()
var fid string
p.next()
if p.is(lss.Period) {
u := p.target.unit.Variables[id]
if u.Type.Basic {
p.mark("only foreign types are selectable")
}
p.next()
p.expect(lss.Ident, "foreign variable expected")
fid = p.ident()
p.next()
} else {
fid = id
id = p.target.unit.Name
}
assert.For(fid != "", 40)
p.target.assign(id, fid, expr)
p.pass(lss.Separator, lss.Delimiter)
stop = p.is(lss.End)
}
}
开发者ID:kpmy,项目名称:lomo,代码行数:32,代码来源:lpp.go
示例5: Construct
func Construct(name otm.Qualident) (ret schema.Guide) {
assert.For(name.Template == "ng", 20, name)
fn := Constructors[name.Class]
assert.For(fn != nil, 40, name)
ret = fn()
assert.For(ret != nil, 60, name)
return
}
开发者ID:kpmy,项目名称:ot,代码行数:8,代码来源:load.go
示例6: Object
func (l *futureLink) Object() otm.Object {
if l.o == nil {
assert.For(!fn.IsNil(l.up), 20)
l.o = otm.RootOf(l.up).FindById(l.to).(*object)
assert.For(l.o != nil, 60, "object not found ", l.to)
}
return l.o
}
开发者ID:kpmy,项目名称:ot,代码行数:8,代码来源:i2m.go
示例7: dyINT2REAL
func dyINT2REAL() {
putDyadic(types.REAL, types.INTEGER, ops.Quot,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Quo(l, r)
}))))
putDyadic(types.INTEGER, types.REAL, ops.Quot,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Quo(l, r)
}))))
putDyadic(types.REAL, types.INTEGER, ops.Pow,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
n := l.Num()
d := l.Denom()
assert.For(r.IsInt(), 40)
p := r.Num()
assert.For(p.Cmp(big.NewInt(0)) >= 0, 40, "positive only")
n = n.Exp(n, p, nil)
d = d.Exp(d, p, nil)
ret := big.NewRat(0, 1)
ret = ret.SetFrac(n, d)
return ret
}))))
putDyadic(types.INTEGER, types.REAL, ops.Pow,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
assert.For(l.IsInt(), 40)
n := l.Num()
p := r.Num()
q := r.Denom()
assert.For(p.Cmp(big.NewInt(0)) >= 0, 40, "positive only")
assert.For(q.Cmp(big.NewInt(1)) == 0, 41, "извлечение корня не поддерживается")
n = n.Exp(n, p, q)
ret := big.NewRat(0, 1)
ret = ret.SetFrac(n, big.NewInt(1))
return ret
}))))
putDyadic(types.INTEGER, types.REAL, ops.Prod,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Mul(l, r)
}))))
putDyadic(types.REAL, types.INTEGER, ops.Prod,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Mul(l, r)
}))))
putDyadic(types.REAL, types.INTEGER, ops.Sum,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Add(l, r)
}))))
putDyadic(types.REAL, types.INTEGER, ops.Diff,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Sub(l, r)
}))))
putDyadic(types.INTEGER, types.INTEGER, ops.Quot,
r_(r_ir_(r_ir_ir_(func(l *big.Rat, r *big.Rat) *big.Rat {
return l.Quo(l, r)
}))))
}
开发者ID:kpmy,项目名称:lomo,代码行数:56,代码来源:calc.go
示例8: TestSome
func TestSome(t *testing.T) {
assert.For(Do2(Do2(Int(4), SUM, Int(24)), EQ, Int(4+24)).ToBool(), 20)
assert.For(Do2(Do2(Int(4), DIFF, Int(24)), EQ, Int(4-24)).ToBool(), 20)
assert.For(Do2(Do2(Int(4), MULT, Int(24)), EQ, Int(4*24)).ToBool(), 20)
t.Log(Do2(Int(4), QUOT, Int(24)))
t.Log(Do(NEG, Int(45)))
t.Log(Flo(34.5))
t.Log(Cpx(complex(3, 5)))
t.Log(Do(CON, Cpx(complex(3.5, 14))))
}
开发者ID:kpmy,项目名称:clac,代码行数:10,代码来源:clac_test.go
示例9: Child
func (b *builder) Child(prod otm.Producer, mod ...otm.Modifier) otm.Builder {
assert.For(b.root != nil, 20)
n := prod(mod...).(*object)
if n.id != "" {
old := b.root.FindById(n.id)
assert.For(fn.IsNil(old), 40, "non unique id")
}
b.root.vl = append(b.root.vl, n)
n.up = b.root
return b
}
开发者ID:kpmy,项目名称:ot,代码行数:11,代码来源:build.go
示例10: expect
//expect is the most powerful step forward runner, breaks the compilation if unexpected sym found
func (p *common) expect(sym lss.Symbol, msg string, skip ...lss.Symbol) {
assert.For(p.done, 20)
if !p.await(sym, skip...) {
p.mark(msg)
}
p.done = false
}
开发者ID:kpmy,项目名称:lomo,代码行数:8,代码来源:common.go
示例11: comment
func (s *sc) comment() {
assert.For(s.ch == '*', 20, "expected ", s.opts.CommentTriplet[1], "got ", Token(s.ch))
for {
for s.err == nil && s.ch != s.opts.CommentTriplet[1] {
if s.ch == s.opts.CommentTriplet[0] {
if s.next() == s.opts.CommentTriplet[1] {
s.comment()
}
} else {
s.next()
}
}
for s.err == nil && s.ch == s.opts.CommentTriplet[1] {
s.next()
}
if s.err != nil || s.ch == s.opts.CommentTriplet[2] {
break
}
}
if s.err == nil {
s.next()
} else {
s.mark("unclosed comment")
}
}
开发者ID:kpmy,项目名称:tier,代码行数:25,代码来源:sc.go
示例12: emit
func (t *target) emit(_s ir.Statement) {
assert.For(!fn.IsNil(_s), 20)
switch s := _s.(type) {
default:
t.tpl.Stmt = append(t.tpl.Stmt, s)
}
}
开发者ID:kpmy,项目名称:ot,代码行数:7,代码来源:target.go
示例13: expect
//expect is the most powerful step forward runner, breaks the compilation if unexpected sym found
func (p *common) expect(sym ots.SymCode, msg string, skip ...ots.SymCode) {
assert.For(p.done, 20)
if !p.await(sym, skip...) {
p.mark(msg)
}
p.done = false
}
开发者ID:kpmy,项目名称:ot,代码行数:8,代码来源:common.go
示例14: Join
func Join(in *model.Layer, out *model.Layer) {
j := 0
type im map[int]interface{}
cache := make([]im, len(out.Nodes))
for k, n := range in.Nodes {
for i := 0; i < len(n.Out); {
assert.For(len(n.Out) <= len(out.Nodes), 20, len(n.Out), len(out.Nodes))
l := model.Link{NodeId: k, LinkId: i}
skip := false
if cache[j] != nil {
if _, ok := cache[j][k]; ok {
skip = true
j++
if j == len(cache) {
j = 0
}
}
}
if !skip {
out.Nodes[j].In[l] = nil
if cache[j] == nil {
cache[j] = make(im)
}
cache[j][k] = l
//log.Println(l, "to", j)
i++
}
//log.Println(k, len(n.Out), i, j)
}
}
in.Next = out
}
开发者ID:kpmy,项目名称:gone,代码行数:32,代码来源:sm.go
示例15: Expect
//expect is the most powerful step forward runner, breaks the compilation if unexpected sym found
func (r *rn) Expect(sym SymCode, msg interface{}, skip ...SymCode) {
assert.For(r.done, 20, "previous symbol unhandled")
if !r.Await(sym, skip...) {
r.marker.Mark(msg)
}
r.done = false
}
开发者ID:kpmy,项目名称:tier,代码行数:8,代码来源:run.go
示例16: comment
func (s *sc) comment() {
assert.For(s.ch == '*', 20, "expected * ", "got ", Token(s.ch))
for {
for s.err == nil && s.ch != '*' {
if s.ch == '(' {
if s.next() == '*' {
s.comment()
}
} else {
s.next()
}
}
for s.err == nil && s.ch == '*' {
s.next()
}
if s.err != nil || s.ch == ')' {
break
}
}
if s.err == nil {
s.next()
} else {
s.mark("unclosed comment")
}
}
开发者ID:kpmy,项目名称:lomo,代码行数:25,代码来源:sc.go
示例17: num
//first char always 0..9
func (s *sc) num() (sym Sym) {
assert.For(unicode.IsDigit(s.ch), 20, "digit expected")
var buf []rune
var mbuf []rune
hasDot := false
for {
buf = append(buf, s.ch)
s.next()
if s.ch == '.' {
if !hasDot {
hasDot = true
} else if hasDot {
s.mark("dot unexpected")
}
}
if s.err != nil || !(s.ch == '.' || s.is(hex, s.ch)) {
break
}
}
if s.is(modifier, s.ch) {
mbuf = append(mbuf, s.ch)
s.next()
}
if s.err == nil {
sym.Code = Number
sym.Str = string(buf)
sym.NumberOpts.Modifier = string(mbuf)
sym.NumberOpts.Period = hasDot
} else {
s.mark("error reading number")
}
return
}
开发者ID:kpmy,项目名称:lomo,代码行数:35,代码来源:sc.go
示例18: Init
func Init(_top string, ld Loader) (ret map[string]*Unit) {
assert.For(ld != nil, 20, _top)
ret = make(map[string]*Unit)
var run func(*Unit)
run = func(u *Unit) {
u.imps = ret
for _, v := range u.code.Variables {
if !v.Type.Basic {
if dep := ld(v.Type.Foreign.Name()); dep != nil {
ret[imp(v)] = &Unit{code: dep, loader: ld}
v.Type.Foreign = ir.NewForeign(dep)
run(ret[imp(v)])
}
}
}
}
if std := lpp.Std[_top]; std != nil {
ret[_top] = stdUnit(std, ld)
run(ret[_top])
} else if top := ld(_top); top != nil {
ret[_top] = &Unit{code: top, loader: ld}
run(ret[_top])
}
return
}
开发者ID:kpmy,项目名称:lomo,代码行数:25,代码来源:do2.go
示例19: ident
func (s *sc) ident() (sym Sym) {
assert.For(unicode.IsLetter(s.ch), 20, "character expected")
var buf []rune
for {
buf = append(buf, s.ch)
s.next()
if s.err != nil || !(unicode.IsLetter(s.ch) || unicode.IsDigit(s.ch)) {
break
}
}
if s.err == nil {
sym.Str = string(buf)
key := sym.Str
if s.evil == nil {
x := true
s.evil = &x
if keyTab[key] == None && keyTab[strings.ToUpper(key)] == s.useTab[0] {
*s.evil = true
} else if keyTab[key] == s.useTab[0] {
*s.evil = false
}
}
set := func() {
if sym.Code = keyTab[key]; sym.Code == None {
sym.Code = Ident
sym.User = s.foreignTab[key]
} else if sym.Code != None {
ok := false
for _, u := range s.useTab {
if u == sym.Code {
ok = true
break
}
}
if !ok {
sym.Code = Ident
sym.User = s.foreignTab[key]
}
}
}
if s.evil != nil {
if *s.evil {
key = strings.ToUpper(sym.Str)
if key != sym.Str {
set()
} else {
sym.Code = Ident
}
} else {
set()
}
} else {
sym.Code = Ident
}
} else {
s.mark("error while ident read")
}
return
}
开发者ID:kpmy,项目名称:lomo,代码行数:60,代码来源:sc.go
示例20: 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
注:本文中的github.com/kpmy/ypk/assert.For函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论