this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cue: move to external builtin packages

This includes a new generator for builtin packages.

Change-Id: Ieab84e16d9136c2ad5d2d8e8cad49c84a6e0b658
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/6885
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
Reviewed-by: CUE cueckoo <cueckoo@gmail.com>

+3716 -4366
+4 -2
cue/ast/astutil/file_test.go
··· 18 18 "strings" 19 19 "testing" 20 20 21 + "github.com/google/go-cmp/cmp" 22 + 21 23 "cuelang.org/go/cue" 22 24 "cuelang.org/go/cue/ast" 23 25 "cuelang.org/go/cue/ast/astutil" 24 26 "cuelang.org/go/cue/format" 25 27 "cuelang.org/go/cue/token" 26 - "github.com/google/go-cmp/cmp" 28 + _ "cuelang.org/go/pkg" 27 29 ) 28 30 29 31 func TestToFile(t *testing.T) { ··· 93 95 got := string(b) 94 96 want := strings.TrimLeft(tc.want, "\n") 95 97 if got != want { 96 - t.Error(cmp.Diff(got, want)) 98 + t.Error(cmp.Diff(want, got)) 97 99 } 98 100 }) 99 101 }
+1 -1
cue/ast/ident.go
··· 16 16 17 17 import ( 18 18 "strconv" 19 + "strings" 19 20 "unicode" 20 21 "unicode/utf8" 21 22 22 23 "cuelang.org/go/cue/errors" 23 24 "cuelang.org/go/cue/token" 24 - "cuelang.org/go/pkg/strings" 25 25 ) 26 26 27 27 func isLetter(ch rune) bool {
+13 -549
cue/builtin.go
··· 12 12 // See the License for the specific language governing permissions and 13 13 // limitations under the License. 14 14 15 - //go:generate go run golang.org/x/tools/cmd/goimports -w -local cuelang.org/go builtins.go 16 - //go:generate gofmt -s -w builtins.go 17 - 18 15 package cue 19 16 20 17 import ( 21 - "encoding/json" 22 - "fmt" 23 - "io" 24 - "math/big" 25 18 "path" 26 - "sort" 27 19 "strings" 28 20 29 - "github.com/cockroachdb/apd/v2" 30 - 31 - "cuelang.org/go/cue/errors" 32 - "cuelang.org/go/cue/parser" 33 21 "cuelang.org/go/cue/token" 34 22 "cuelang.org/go/internal" 35 23 "cuelang.org/go/internal/core/adt" 36 - "cuelang.org/go/internal/core/compile" 37 - "cuelang.org/go/internal/core/convert" 38 24 ) 39 25 40 - // A Builtin is a builtin function or constant. 41 - // 42 - // A function may return and a constant may be any of the following types: 43 - // 44 - // error (translates to bottom) 45 - // nil (translates to null) 46 - // bool 47 - // int* 48 - // uint* 49 - // float64 50 - // string 51 - // *big.Float 52 - // *big.Int 53 - // 54 - // For any of the above, including interface{} and these types recursively: 55 - // []T 56 - // map[string]T 57 - // 58 - type Builtin struct { 59 - Name string 60 - Pkg adt.Feature 61 - Params []adt.Kind 62 - Result adt.Kind 63 - Func func(c *CallCtxt) 64 - Const string 65 - } 66 - 67 - type Package struct { 68 - Native []*Builtin 69 - CUE string 70 - } 71 - 72 - func (p *Package) MustCompile(ctx *adt.OpContext, pkgName string) *adt.Vertex { 73 - obj := &adt.Vertex{} 74 - pkgLabel := ctx.StringLabel(pkgName) 75 - st := &adt.StructLit{} 76 - if len(p.Native) > 0 { 77 - obj.AddConjunct(adt.MakeConjunct(nil, st)) 78 - } 79 - for _, b := range p.Native { 80 - b.Pkg = pkgLabel 81 - 82 - f := ctx.StringLabel(b.Name) // never starts with _ 83 - // n := &node{baseValue: newBase(imp.Path)} 84 - var v adt.Expr = toBuiltin(ctx, b) 85 - if b.Const != "" { 86 - v = mustParseConstBuiltin(ctx, b.Name, b.Const) 87 - } 88 - st.Decls = append(st.Decls, &adt.Field{ 89 - Label: f, 90 - Value: v, 91 - }) 92 - } 93 - 94 - // Parse builtin CUE 95 - if p.CUE != "" { 96 - expr, err := parser.ParseExpr(pkgName, p.CUE) 97 - if err != nil { 98 - panic(fmt.Errorf("could not parse %v: %v", p.CUE, err)) 99 - } 100 - c, err := compile.Expr(nil, ctx.Runtime, expr) 101 - if err != nil { 102 - panic(fmt.Errorf("could compile parse %v: %v", p.CUE, err)) 103 - } 104 - obj.AddConjunct(c) 105 - } 106 - 107 - // We could compile lazily, but this is easier for debugging. 108 - obj.Finalize(ctx) 109 - if err := obj.Err(ctx, adt.Finalized); err != nil { 110 - panic(err.Err) 111 - } 112 - 113 - return obj 114 - } 115 - 116 - func toBuiltin(ctx *adt.OpContext, b *Builtin) *adt.Builtin { 117 - x := &adt.Builtin{ 118 - Params: b.Params, 119 - Result: b.Result, 120 - Package: b.Pkg, 121 - Name: b.Name, 122 - } 123 - x.Func = func(ctx *adt.OpContext, args []adt.Value) (ret adt.Expr) { 124 - // call, _ := ctx.Source().(*ast.CallExpr) 125 - c := &CallCtxt{ 126 - // src: call, 127 - ctx: ctx, 128 - args: args, 129 - builtin: b, 130 - } 131 - defer func() { 132 - var errVal interface{} = c.Err 133 - if err := recover(); err != nil { 134 - errVal = err 135 - } 136 - ret = processErr(c, errVal, ret) 137 - }() 138 - b.Func(c) 139 - switch v := c.Ret.(type) { 140 - case adt.Value: 141 - return v 142 - case bottomer: 143 - return v.Bottom() 144 - } 145 - if c.Err != nil { 146 - return nil 147 - } 148 - return convert.GoValueToValue(ctx, c.Ret, true) 149 - } 150 - return x 151 - } 152 - 153 - // newConstBuiltin parses and creates any CUE expression that does not have 154 - // fields. 155 - func mustParseConstBuiltin(ctx *adt.OpContext, name, val string) adt.Expr { 156 - expr, err := parser.ParseExpr("<builtin:"+name+">", val) 157 - if err != nil { 158 - panic(err) 159 - } 160 - c, err := compile.Expr(nil, ctx, expr) 161 - if err != nil { 162 - panic(err) 163 - } 164 - return c.Expr() 165 - 166 - } 167 - 168 26 func pos(n adt.Node) (p token.Pos) { 169 27 if n == nil { 170 28 return ··· 176 34 return src.Pos() 177 35 } 178 36 179 - func (x *Builtin) name(ctx *adt.OpContext) string { 180 - if x.Pkg == 0 { 181 - return x.Name 182 - } 183 - return fmt.Sprintf("%s.%s", x.Pkg.StringValue(ctx), x.Name) 184 - } 185 - 186 - func (x *Builtin) isValidator() bool { 187 - return len(x.Params) == 1 && x.Result == adt.BoolKind 188 - } 189 - 190 - func processErr(call *CallCtxt, errVal interface{}, ret adt.Expr) adt.Expr { 191 - ctx := call.ctx 192 - switch err := errVal.(type) { 193 - case nil: 194 - case *callError: 195 - ret = err.b 196 - case *json.MarshalerError: 197 - if err, ok := err.Err.(bottomer); ok { 198 - if b := err.Bottom(); b != nil { 199 - ret = b 200 - } 201 - } 202 - case bottomer: 203 - ret = wrapCallErr(call, err.Bottom()) 204 - case errors.Error: 205 - ret = wrapCallErr(call, &adt.Bottom{Err: err}) 206 - case error: 207 - if call.Err == internal.ErrIncomplete { 208 - err := ctx.NewErrf("incomplete value") 209 - err.Code = adt.IncompleteError 210 - ret = err 211 - } else { 212 - // TODO: store the underlying error explicitly 213 - ret = wrapCallErr(call, &adt.Bottom{Err: errors.Promote(err, "")}) 214 - } 215 - default: 216 - // Likely a string passed to panic. 217 - ret = wrapCallErr(call, &adt.Bottom{ 218 - Err: errors.Newf(call.Pos(), "%s", err), 219 - }) 220 - } 221 - return ret 222 - } 223 - 224 - func wrapCallErr(c *CallCtxt, b *adt.Bottom) *adt.Bottom { 225 - pos := token.NoPos 226 - if c.src != nil { 227 - if src := c.src.Source(); src != nil { 228 - pos = src.Pos() 229 - } 230 - } 231 - const msg = "error in call to %s" 232 - return &adt.Bottom{ 233 - Code: b.Code, 234 - Err: errors.Wrapf(b.Err, pos, msg, c.builtin.name(c.ctx)), 235 - } 236 - } 237 - 238 - func (c *CallCtxt) convertError(x interface{}, name string) *adt.Bottom { 239 - var err errors.Error 240 - switch v := x.(type) { 241 - case nil: 242 - return nil 243 - 244 - case *adt.Bottom: 245 - return v 246 - 247 - case *json.MarshalerError: 248 - err = errors.Promote(v, "marshal error") 249 - 250 - case errors.Error: 251 - err = v 252 - 253 - case error: 254 - if name != "" { 255 - err = errors.Newf(c.Pos(), "%s: %v", name, v) 256 - } else { 257 - err = errors.Newf(c.Pos(), "error in call to %s: %v", c.Name(), v) 258 - } 259 - 260 - default: 261 - err = errors.Newf(token.NoPos, "%s", name) 262 - } 263 - if err != internal.ErrIncomplete { 264 - return &adt.Bottom{ 265 - // Wrap to preserve position information. 266 - Err: errors.Wrapf(err, c.Pos(), "error in call to %s", c.Name()), 267 - } 268 - } 269 - return &adt.Bottom{ 270 - Code: adt.IncompleteError, 271 - Err: errors.Newf(c.Pos(), "incomplete values in call to %s", c.Name()), 272 - } 273 - } 274 - 275 - // CallCtxt is passed to builtin implementations that need to use a cue.Value. This is an internal type. It's interface may change. 276 - type CallCtxt struct { 277 - src adt.Expr // *adt.CallExpr 278 - ctx *adt.OpContext 279 - builtin *Builtin 280 - Err interface{} 281 - Ret interface{} 282 - 283 - args []adt.Value 284 - } 285 - 286 - func (c *CallCtxt) Pos() token.Pos { 287 - return c.ctx.Pos() 288 - } 289 - 290 - func (c *CallCtxt) Name() string { 291 - return c.builtin.name(c.ctx) 292 - } 293 - 294 37 var builtins = map[string]*Instance{} 295 38 296 - func initBuiltins(pkgs map[string]*Package) { 39 + func AddBuiltinPackage(importPath string, f func(*adt.OpContext) (*adt.Vertex, error)) { 297 40 ctx := sharedIndex.newContext().opCtx 298 - keys := []string{} 299 - for k := range pkgs { 300 - keys = append(keys, k) 41 + 42 + v, err := f(ctx) 43 + if err != nil { 44 + panic(err) 301 45 } 302 - sort.Strings(keys) 303 - for _, k := range keys { 304 - b := pkgs[k] 305 - e := b.MustCompile(ctx, k) 306 46 307 - i := sharedIndex.addInst(&Instance{ 308 - ImportPath: k, 309 - PkgName: path.Base(k), 310 - root: e, 311 - }) 47 + k := importPath 48 + i := sharedIndex.addInst(&Instance{ 49 + ImportPath: k, 50 + PkgName: path.Base(k), 51 + root: v, 52 + }) 312 53 313 - builtins[k] = i 314 - builtins["-/"+path.Base(k)] = i 315 - } 54 + builtins[k] = i 55 + builtins["-/"+path.Base(k)] = i 316 56 } 317 57 318 58 func getBuiltinPkg(ctx *context, path string) *structLit { ··· 342 82 return v.Unify(makeValue(v.idx, a)) 343 83 } 344 84 } 345 - 346 - // Do returns whether the call should be done. 347 - func (c *CallCtxt) Do() bool { 348 - return c.Err == nil 349 - } 350 - 351 - type bottomer interface { 352 - error 353 - Bottom() *adt.Bottom 354 - } 355 - 356 - type callError struct { 357 - b *adt.Bottom 358 - } 359 - 360 - func (e *callError) Error() string { 361 - return fmt.Sprint(e.b) 362 - } 363 - 364 - func (c *CallCtxt) errf(src adt.Node, underlying error, format string, args ...interface{}) { 365 - var errs errors.Error 366 - if err, ok := underlying.(bottomer); ok { 367 - errs = err.Bottom().Err 368 - } 369 - errs = errors.Wrapf(errs, c.ctx.Pos(), format, args...) 370 - c.Err = &callError{&adt.Bottom{Err: errs}} 371 - } 372 - 373 - func (c *CallCtxt) errcf(src adt.Node, code adt.ErrorCode, format string, args ...interface{}) { 374 - err := c.ctx.NewErrf(format, args...) 375 - err.Code = code 376 - c.Err = &callError{err} 377 - } 378 - 379 - func (c *CallCtxt) Value(i int) Value { 380 - v := MakeValue(c.ctx, c.args[i]) 381 - // TODO: remove default 382 - // v, _ = v.Default() 383 - if !v.IsConcrete() { 384 - c.errcf(c.src, adt.IncompleteError, "non-concrete argument %d", i) 385 - } 386 - return v 387 - } 388 - 389 - func (c *CallCtxt) Struct(i int) *Struct { 390 - v := MakeValue(c.ctx, c.args[i]) 391 - s, err := v.Struct() 392 - if err != nil { 393 - c.invalidArgType(c.args[i], i, "struct", err) 394 - return nil 395 - } 396 - return s 397 - } 398 - 399 - func (c *CallCtxt) invalidArgType(arg adt.Expr, i int, typ string, err error) { 400 - if ve, ok := err.(bottomer); ok && ve.Bottom().IsIncomplete() { 401 - c.Err = ve 402 - return 403 - } 404 - v, ok := arg.(adt.Value) 405 - // TODO: make these permanent errors if the value did not originate from 406 - // a reference. 407 - if !ok { 408 - c.errf(c.src, nil, 409 - "cannot use incomplete value %s as %s in argument %d to %s: %v", 410 - c.ctx.Str(arg), typ, i, c.Name(), err) 411 - } 412 - if err != nil { 413 - c.errf(c.src, err, 414 - "cannot use %s (type %s) as %s in argument %d to %s: %v", 415 - c.ctx.Str(arg), v.Kind(), typ, i, c.Name(), err) 416 - } else { 417 - c.errf(c.src, err, 418 - "cannot use %s (type %s) as %s in argument %d to %s", 419 - c.ctx.Str(arg), v.Kind(), typ, i, c.Name()) 420 - } 421 - } 422 - 423 - func (c *CallCtxt) Int(i int) int { return int(c.intValue(i, 64, "int64")) } 424 - func (c *CallCtxt) Int8(i int) int8 { return int8(c.intValue(i, 8, "int8")) } 425 - func (c *CallCtxt) Int16(i int) int16 { return int16(c.intValue(i, 16, "int16")) } 426 - func (c *CallCtxt) Int32(i int) int32 { return int32(c.intValue(i, 32, "int32")) } 427 - func (c *CallCtxt) Rune(i int) rune { return rune(c.intValue(i, 32, "rune")) } 428 - func (c *CallCtxt) Int64(i int) int64 { return int64(c.intValue(i, 64, "int64")) } 429 - 430 - func (c *CallCtxt) intValue(i, bits int, typ string) int64 { 431 - arg := c.args[i] 432 - x := MakeValue(c.ctx, arg) 433 - n, err := x.Int(nil) 434 - if err != nil { 435 - c.invalidArgType(arg, i, typ, err) 436 - return 0 437 - } 438 - if n.BitLen() > bits { 439 - c.errf(c.src, err, "int %s overflows %s in argument %d in call to %s", 440 - n, typ, i, c.Name()) 441 - } 442 - res, _ := x.Int64() 443 - return res 444 - } 445 - 446 - func (c *CallCtxt) Uint(i int) uint { return uint(c.uintValue(i, 64, "uint64")) } 447 - func (c *CallCtxt) Uint8(i int) uint8 { return uint8(c.uintValue(i, 8, "uint8")) } 448 - func (c *CallCtxt) Byte(i int) uint8 { return byte(c.uintValue(i, 8, "byte")) } 449 - func (c *CallCtxt) Uint16(i int) uint16 { return uint16(c.uintValue(i, 16, "uint16")) } 450 - func (c *CallCtxt) Uint32(i int) uint32 { return uint32(c.uintValue(i, 32, "uint32")) } 451 - func (c *CallCtxt) Uint64(i int) uint64 { return uint64(c.uintValue(i, 64, "uint64")) } 452 - 453 - func (c *CallCtxt) uintValue(i, bits int, typ string) uint64 { 454 - x := MakeValue(c.ctx, c.args[i]) 455 - n, err := x.Int(nil) 456 - if err != nil || n.Sign() < 0 { 457 - c.invalidArgType(c.args[i], i, typ, err) 458 - return 0 459 - } 460 - if n.BitLen() > bits { 461 - c.errf(c.src, err, "int %s overflows %s in argument %d in call to %s", 462 - n, typ, i, c.Name()) 463 - } 464 - res, _ := x.Uint64() 465 - return res 466 - } 467 - 468 - func (c *CallCtxt) Decimal(i int) *apd.Decimal { 469 - x := MakeValue(c.ctx, c.args[i]) 470 - if _, err := x.MantExp(nil); err != nil { 471 - c.invalidArgType(c.args[i], i, "Decimal", err) 472 - return nil 473 - } 474 - return &c.args[i].(*adt.Num).X 475 - } 476 - 477 - func (c *CallCtxt) Float64(i int) float64 { 478 - x := MakeValue(c.ctx, c.args[i]) 479 - res, err := x.Float64() 480 - if err != nil { 481 - c.invalidArgType(c.args[i], i, "float64", err) 482 - return 0 483 - } 484 - return res 485 - } 486 - 487 - func (c *CallCtxt) BigInt(i int) *big.Int { 488 - x := MakeValue(c.ctx, c.args[i]) 489 - n, err := x.Int(nil) 490 - if err != nil { 491 - c.invalidArgType(c.args[i], i, "int", err) 492 - return nil 493 - } 494 - return n 495 - } 496 - 497 - var ten = big.NewInt(10) 498 - 499 - func (c *CallCtxt) BigFloat(i int) *big.Float { 500 - x := MakeValue(c.ctx, c.args[i]) 501 - var mant big.Int 502 - exp, err := x.MantExp(&mant) 503 - if err != nil { 504 - c.invalidArgType(c.args[i], i, "float", err) 505 - return nil 506 - } 507 - f := &big.Float{} 508 - f.SetInt(&mant) 509 - if exp != 0 { 510 - var g big.Float 511 - e := big.NewInt(int64(exp)) 512 - f.Mul(f, g.SetInt(e.Exp(ten, e, nil))) 513 - } 514 - return f 515 - } 516 - 517 - func (c *CallCtxt) String(i int) string { 518 - x := MakeValue(c.ctx, c.args[i]) 519 - v, err := x.String() 520 - if err != nil { 521 - c.invalidArgType(c.args[i], i, "string", err) 522 - return "" 523 - } 524 - return v 525 - } 526 - 527 - func (c *CallCtxt) Bytes(i int) []byte { 528 - x := MakeValue(c.ctx, c.args[i]) 529 - v, err := x.Bytes() 530 - if err != nil { 531 - c.invalidArgType(c.args[i], i, "bytes", err) 532 - return nil 533 - } 534 - return v 535 - } 536 - 537 - func (c *CallCtxt) Reader(i int) io.Reader { 538 - x := MakeValue(c.ctx, c.args[i]) 539 - // TODO: optimize for string and bytes cases 540 - r, err := x.Reader() 541 - if err != nil { 542 - c.invalidArgType(c.args[i], i, "bytes|string", err) 543 - return nil 544 - } 545 - return r 546 - } 547 - 548 - func (c *CallCtxt) Bool(i int) bool { 549 - x := MakeValue(c.ctx, c.args[i]) 550 - b, err := x.Bool() 551 - if err != nil { 552 - c.invalidArgType(c.args[i], i, "bool", err) 553 - return false 554 - } 555 - return b 556 - } 557 - 558 - func (c *CallCtxt) List(i int) (a []Value) { 559 - arg := c.args[i] 560 - x := MakeValue(c.ctx, arg) 561 - v, err := x.List() 562 - if err != nil { 563 - c.invalidArgType(c.args[i], i, "list", err) 564 - return a 565 - } 566 - for v.Next() { 567 - a = append(a, v.Value()) 568 - } 569 - return a 570 - } 571 - 572 - func (c *CallCtxt) Iter(i int) (a Iterator) { 573 - arg := c.args[i] 574 - x := MakeValue(c.ctx, arg) 575 - v, err := x.List() 576 - if err != nil { 577 - c.invalidArgType(c.args[i], i, "list", err) 578 - } 579 - return v 580 - } 581 - 582 - func (c *CallCtxt) DecimalList(i int) (a []*apd.Decimal) { 583 - arg := c.args[i] 584 - x := MakeValue(c.ctx, arg) 585 - v, err := x.List() 586 - if err != nil { 587 - c.invalidArgType(c.args[i], i, "list", err) 588 - return nil 589 - } 590 - for j := 0; v.Next(); j++ { 591 - num, err := v.Value().Decimal() 592 - if err != nil { 593 - c.errf(c.src, err, "invalid list element %d in argument %d to %s: %v", 594 - j, i, c.Name(), err) 595 - break 596 - } 597 - a = append(a, num) 598 - } 599 - return a 600 - } 601 - 602 - func (c *CallCtxt) StringList(i int) (a []string) { 603 - arg := c.args[i] 604 - x := MakeValue(c.ctx, arg) 605 - v, err := x.List() 606 - if err != nil { 607 - c.invalidArgType(c.args[i], i, "list", err) 608 - return nil 609 - } 610 - for j := 0; v.Next(); j++ { 611 - str, err := v.Value().String() 612 - if err != nil { 613 - c.Err = errors.Wrapf(err, c.Pos(), 614 - "element %d of list argument %d", j, i) 615 - break 616 - } 617 - a = append(a, str) 618 - } 619 - return a 620 - }
+60 -7
cue/builtin_test.go
··· 12 12 // See the License for the specific language governing permissions and 13 13 // limitations under the License. 14 14 15 - package cue 15 + package cue_test 16 16 17 17 import ( 18 18 "fmt" ··· 20 20 "strconv" 21 21 "strings" 22 22 "testing" 23 + 24 + "cuelang.org/go/cue" 25 + "cuelang.org/go/cue/build" 26 + "cuelang.org/go/cue/token" 27 + 28 + _ "cuelang.org/go/pkg" 23 29 ) 24 30 25 31 func TestBuiltins(t *testing.T) { ··· 667 673 }} 668 674 for i, tc := range testCases { 669 675 t.Run(fmt.Sprint(i), func(t *testing.T) { 670 - insts := Build(makeInstances(tc.instances)) 676 + insts := cue.Build(makeInstances(tc.instances)) 671 677 if err := insts[0].Err; err != nil { 672 678 t.Fatal(err) 673 679 } 674 680 v := insts[0].Value() 675 - ctx := v.ctx() 676 - got := ctx.opCtx.Str(v.v) 681 + got := fmt.Sprintf("%+v", v) 677 682 if got != tc.emit { 678 683 t.Errorf("\n got: %s\nwant: %s", got, tc.emit) 679 684 } ··· 699 704 }} 700 705 for i, tc := range testCases { 701 706 t.Run(fmt.Sprint(i), func(t *testing.T) { 702 - insts := Build(makeInstances(tc.instances)) 707 + insts := cue.Build(makeInstances(tc.instances)) 703 708 if err := insts[0].Err; err != nil { 704 709 t.Fatal(err) 705 710 } 706 711 v := insts[0].Value() 707 - ctx := v.ctx() 708 - got := ctx.opCtx.Str(v.v) 712 + got := fmt.Sprint(v) 709 713 if got != tc.emit { 710 714 t.Errorf("\n got: %s\nwant: %s", got, tc.emit) 711 715 } 712 716 }) 713 717 } 714 718 } 719 + 720 + type builder struct { 721 + ctxt *build.Context 722 + imports map[string]*bimport 723 + } 724 + 725 + func (b *builder) load(pos token.Pos, path string) *build.Instance { 726 + bi := b.imports[path] 727 + if bi == nil { 728 + return nil 729 + } 730 + return b.build(bi) 731 + } 732 + 733 + type bimport struct { 734 + path string // "" means top-level 735 + files []string 736 + } 737 + 738 + func makeInstances(insts []*bimport) (instances []*build.Instance) { 739 + b := builder{ 740 + ctxt: build.NewContext(), 741 + imports: map[string]*bimport{}, 742 + } 743 + for _, bi := range insts { 744 + if bi.path != "" { 745 + b.imports[bi.path] = bi 746 + } 747 + } 748 + for _, bi := range insts { 749 + if bi.path == "" { 750 + instances = append(instances, b.build(bi)) 751 + } 752 + } 753 + return 754 + } 755 + 756 + func (b *builder) build(bi *bimport) *build.Instance { 757 + path := bi.path 758 + if path == "" { 759 + path = "dir" 760 + } 761 + p := b.ctxt.NewInstance(path, b.load) 762 + for i, f := range bi.files { 763 + _ = p.AddFile(fmt.Sprintf("file%d.cue", i), f) 764 + } 765 + _ = p.Complete() 766 + return p 767 + }
-3784
cue/builtins.go
··· 1 - // Code generated by go generate. DO NOT EDIT. 2 - 3 - package cue 4 - 5 - import ( 6 - "bytes" 7 - "crypto/md5" 8 - "crypto/sha1" 9 - "crypto/sha256" 10 - "crypto/sha512" 11 - "encoding/base64" 12 - "encoding/csv" 13 - "encoding/hex" 14 - "encoding/json" 15 - "fmt" 16 - "html" 17 - "io" 18 - "math" 19 - "math/big" 20 - "math/bits" 21 - "net" 22 - "path" 23 - "regexp" 24 - "sort" 25 - "strconv" 26 - "strings" 27 - "text/tabwriter" 28 - "text/template" 29 - "time" 30 - "unicode" 31 - "unicode/utf8" 32 - 33 - "github.com/cockroachdb/apd/v2" 34 - "golang.org/x/net/idna" 35 - 36 - "cuelang.org/go/cue/errors" 37 - "cuelang.org/go/cue/literal" 38 - "cuelang.org/go/cue/parser" 39 - "cuelang.org/go/internal" 40 - cueyaml "cuelang.org/go/internal/encoding/yaml" 41 - "cuelang.org/go/internal/third_party/yaml" 42 - ) 43 - 44 - func init() { 45 - initBuiltins(builtinPackages) 46 - } 47 - 48 - var _ io.Reader 49 - 50 - var roundTruncContext = apd.Context{Rounding: apd.RoundDown} 51 - 52 - var roundUpContext = apd.Context{Rounding: apd.RoundHalfUp} 53 - 54 - var roundEvenContext = apd.Context{Rounding: apd.RoundHalfEven} 55 - 56 - var mulContext = apd.BaseContext.WithPrecision(1) 57 - 58 - var apdContext = apd.BaseContext.WithPrecision(24) 59 - 60 - var zero = apd.New(0, 0) 61 - 62 - var two = apd.New(2, 0) 63 - 64 - var idnaProfile = idna.New( 65 - idna.ValidateLabels(true), 66 - idna.VerifyDNSLength(true), 67 - idna.StrictDomainName(true), 68 - ) 69 - 70 - func netGetIP(ip Value) (goip net.IP) { 71 - switch ip.Kind() { 72 - case StringKind: 73 - s, err := ip.String() 74 - if err != nil { 75 - return nil 76 - } 77 - goip := net.ParseIP(s) 78 - if goip == nil { 79 - return nil 80 - } 81 - return goip 82 - 83 - case BytesKind: 84 - b, err := ip.Bytes() 85 - if err != nil { 86 - return nil 87 - } 88 - goip := net.ParseIP(string(b)) 89 - if goip == nil { 90 - return nil 91 - } 92 - return goip 93 - 94 - case ListKind: 95 - iter, err := ip.List() 96 - if err != nil { 97 - return nil 98 - } 99 - for iter.Next() { 100 - v, err := iter.Value().Int64() 101 - if err != nil { 102 - return nil 103 - } 104 - if v < 0 || 255 < v { 105 - return nil 106 - } 107 - goip = append(goip, byte(v)) 108 - } 109 - return goip 110 - 111 - default: 112 - 113 - return nil 114 - } 115 - } 116 - 117 - func netToList(ip net.IP) []uint { 118 - a := make([]uint, len(ip)) 119 - for i, p := range ip { 120 - a[i] = uint(p) 121 - } 122 - return a 123 - } 124 - 125 - var split = path.Split 126 - 127 - var pathClean = path.Clean 128 - 129 - var pathExt = path.Ext 130 - 131 - var pathBase = path.Base 132 - 133 - var pathIsAbs = path.IsAbs 134 - 135 - var pathDir = path.Dir 136 - 137 - var errNoMatch = errors.New("no match") 138 - 139 - var errNoNamedGroup = errors.New("no named groups") 140 - 141 - func timeFormat(value, layout string) (bool, error) { 142 - _, err := time.Parse(layout, value) 143 - if err != nil { 144 - 145 - return false, fmt.Errorf("invalid time %q", value) 146 - } 147 - return true, nil 148 - } 149 - 150 - var builtinPackages = map[string]*Package{ 151 - // "": { 152 - // native: []*builtin{}, 153 - // }, 154 - "crypto/md5": { 155 - Native: []*Builtin{{ 156 - Name: "Size", 157 - Const: "16", 158 - }, { 159 - Name: "BlockSize", 160 - Const: "64", 161 - }, { 162 - Name: "Sum", 163 - Params: []kind{bytesKind | stringKind}, 164 - Result: bytesKind | stringKind, 165 - Func: func(c *CallCtxt) { 166 - data := c.Bytes(0) 167 - if c.Do() { 168 - c.Ret = func() interface{} { 169 - a := md5.Sum(data) 170 - return a[:] 171 - }() 172 - } 173 - }, 174 - }}, 175 - }, 176 - "crypto/sha1": { 177 - Native: []*Builtin{{ 178 - Name: "Size", 179 - Const: "20", 180 - }, { 181 - Name: "BlockSize", 182 - Const: "64", 183 - }, { 184 - Name: "Sum", 185 - Params: []kind{bytesKind | stringKind}, 186 - Result: bytesKind | stringKind, 187 - Func: func(c *CallCtxt) { 188 - data := c.Bytes(0) 189 - if c.Do() { 190 - c.Ret = func() interface{} { 191 - a := sha1.Sum(data) 192 - return a[:] 193 - }() 194 - } 195 - }, 196 - }}, 197 - }, 198 - "crypto/sha256": { 199 - Native: []*Builtin{{ 200 - Name: "Size", 201 - Const: "32", 202 - }, { 203 - Name: "Size224", 204 - Const: "28", 205 - }, { 206 - Name: "BlockSize", 207 - Const: "64", 208 - }, { 209 - Name: "Sum256", 210 - Params: []kind{bytesKind | stringKind}, 211 - Result: bytesKind | stringKind, 212 - Func: func(c *CallCtxt) { 213 - data := c.Bytes(0) 214 - if c.Do() { 215 - c.Ret = func() interface{} { 216 - a := sha256.Sum256(data) 217 - return a[:] 218 - }() 219 - } 220 - }, 221 - }, { 222 - Name: "Sum224", 223 - Params: []kind{bytesKind | stringKind}, 224 - Result: bytesKind | stringKind, 225 - Func: func(c *CallCtxt) { 226 - data := c.Bytes(0) 227 - if c.Do() { 228 - c.Ret = func() interface{} { 229 - a := sha256.Sum224(data) 230 - return a[:] 231 - }() 232 - } 233 - }, 234 - }}, 235 - }, 236 - "crypto/sha512": { 237 - Native: []*Builtin{{ 238 - Name: "Size", 239 - Const: "64", 240 - }, { 241 - Name: "Size224", 242 - Const: "28", 243 - }, { 244 - Name: "Size256", 245 - Const: "32", 246 - }, { 247 - Name: "Size384", 248 - Const: "48", 249 - }, { 250 - Name: "BlockSize", 251 - Const: "128", 252 - }, { 253 - Name: "Sum512", 254 - Params: []kind{bytesKind | stringKind}, 255 - Result: bytesKind | stringKind, 256 - Func: func(c *CallCtxt) { 257 - data := c.Bytes(0) 258 - if c.Do() { 259 - c.Ret = func() interface{} { 260 - a := sha512.Sum512(data) 261 - return a[:] 262 - }() 263 - } 264 - }, 265 - }, { 266 - Name: "Sum384", 267 - Params: []kind{bytesKind | stringKind}, 268 - Result: bytesKind | stringKind, 269 - Func: func(c *CallCtxt) { 270 - data := c.Bytes(0) 271 - if c.Do() { 272 - c.Ret = func() interface{} { 273 - a := sha512.Sum384(data) 274 - return a[:] 275 - }() 276 - } 277 - }, 278 - }, { 279 - Name: "Sum512_224", 280 - Params: []kind{bytesKind | stringKind}, 281 - Result: bytesKind | stringKind, 282 - Func: func(c *CallCtxt) { 283 - data := c.Bytes(0) 284 - if c.Do() { 285 - c.Ret = func() interface{} { 286 - a := sha512.Sum512_224(data) 287 - return a[:] 288 - }() 289 - } 290 - }, 291 - }, { 292 - Name: "Sum512_256", 293 - Params: []kind{bytesKind | stringKind}, 294 - Result: bytesKind | stringKind, 295 - Func: func(c *CallCtxt) { 296 - data := c.Bytes(0) 297 - if c.Do() { 298 - c.Ret = func() interface{} { 299 - a := sha512.Sum512_256(data) 300 - return a[:] 301 - }() 302 - } 303 - }, 304 - }}, 305 - }, 306 - "encoding/base64": { 307 - Native: []*Builtin{{ 308 - Name: "EncodedLen", 309 - Params: []kind{topKind, intKind}, 310 - Result: intKind, 311 - Func: func(c *CallCtxt) { 312 - encoding, n := c.Value(0), c.Int(1) 313 - if c.Do() { 314 - c.Ret, c.Err = func() (interface{}, error) { 315 - if err := encoding.Null(); err != nil { 316 - return 0, fmt.Errorf("base64: unsupported encoding: %v", err) 317 - } 318 - return base64.StdEncoding.EncodedLen(n), nil 319 - }() 320 - } 321 - }, 322 - }, { 323 - Name: "DecodedLen", 324 - Params: []kind{topKind, intKind}, 325 - Result: intKind, 326 - Func: func(c *CallCtxt) { 327 - encoding, x := c.Value(0), c.Int(1) 328 - if c.Do() { 329 - c.Ret, c.Err = func() (interface{}, error) { 330 - if err := encoding.Null(); err != nil { 331 - return 0, fmt.Errorf("base64: unsupported encoding: %v", err) 332 - } 333 - return base64.StdEncoding.DecodedLen(x), nil 334 - }() 335 - } 336 - }, 337 - }, { 338 - Name: "Encode", 339 - Params: []kind{topKind, bytesKind | stringKind}, 340 - Result: stringKind, 341 - Func: func(c *CallCtxt) { 342 - encoding, src := c.Value(0), c.Bytes(1) 343 - if c.Do() { 344 - c.Ret, c.Err = func() (interface{}, error) { 345 - if err := encoding.Null(); err != nil { 346 - return "", fmt.Errorf("base64: unsupported encoding: %v", err) 347 - } 348 - return base64.StdEncoding.EncodeToString(src), nil 349 - }() 350 - } 351 - }, 352 - }, { 353 - Name: "Decode", 354 - Params: []kind{topKind, stringKind}, 355 - Result: bytesKind | stringKind, 356 - Func: func(c *CallCtxt) { 357 - encoding, s := c.Value(0), c.String(1) 358 - if c.Do() { 359 - c.Ret, c.Err = func() (interface{}, error) { 360 - if err := encoding.Null(); err != nil { 361 - return nil, fmt.Errorf("base64: unsupported encoding: %v", err) 362 - } 363 - return base64.StdEncoding.DecodeString(s) 364 - }() 365 - } 366 - }, 367 - }}, 368 - }, 369 - "encoding/csv": { 370 - Native: []*Builtin{{ 371 - Name: "Encode", 372 - Params: []kind{topKind}, 373 - Result: stringKind, 374 - Func: func(c *CallCtxt) { 375 - x := c.Value(0) 376 - if c.Do() { 377 - c.Ret, c.Err = func() (interface{}, error) { 378 - buf := &bytes.Buffer{} 379 - w := csv.NewWriter(buf) 380 - iter, err := x.List() 381 - if err != nil { 382 - return "", err 383 - } 384 - for iter.Next() { 385 - row, err := iter.Value().List() 386 - if err != nil { 387 - return "", err 388 - } 389 - a := []string{} 390 - for row.Next() { 391 - col := row.Value() 392 - if str, err := col.String(); err == nil { 393 - a = append(a, str) 394 - } else { 395 - b, err := col.MarshalJSON() 396 - if err != nil { 397 - return "", err 398 - } 399 - a = append(a, string(b)) 400 - } 401 - } 402 - _ = w.Write(a) 403 - } 404 - w.Flush() 405 - return buf.String(), nil 406 - }() 407 - } 408 - }, 409 - }, { 410 - Name: "Decode", 411 - Params: []kind{bytesKind | stringKind}, 412 - Result: listKind, 413 - Func: func(c *CallCtxt) { 414 - r := c.Reader(0) 415 - if c.Do() { 416 - c.Ret, c.Err = func() (interface{}, error) { 417 - return csv.NewReader(r).ReadAll() 418 - }() 419 - } 420 - }, 421 - }}, 422 - }, 423 - "encoding/hex": { 424 - Native: []*Builtin{{ 425 - Name: "EncodedLen", 426 - Params: []kind{intKind}, 427 - Result: intKind, 428 - Func: func(c *CallCtxt) { 429 - n := c.Int(0) 430 - if c.Do() { 431 - c.Ret = func() interface{} { 432 - return hex.EncodedLen(n) 433 - }() 434 - } 435 - }, 436 - }, { 437 - Name: "DecodedLen", 438 - Params: []kind{intKind}, 439 - Result: intKind, 440 - Func: func(c *CallCtxt) { 441 - x := c.Int(0) 442 - if c.Do() { 443 - c.Ret = func() interface{} { 444 - return hex.DecodedLen(x) 445 - }() 446 - } 447 - }, 448 - }, { 449 - Name: "Decode", 450 - Params: []kind{stringKind}, 451 - Result: bytesKind | stringKind, 452 - Func: func(c *CallCtxt) { 453 - s := c.String(0) 454 - if c.Do() { 455 - c.Ret, c.Err = func() (interface{}, error) { 456 - return hex.DecodeString(s) 457 - }() 458 - } 459 - }, 460 - }, { 461 - Name: "Dump", 462 - Params: []kind{bytesKind | stringKind}, 463 - Result: stringKind, 464 - Func: func(c *CallCtxt) { 465 - data := c.Bytes(0) 466 - if c.Do() { 467 - c.Ret = func() interface{} { 468 - return hex.Dump(data) 469 - }() 470 - } 471 - }, 472 - }, { 473 - Name: "Encode", 474 - Params: []kind{bytesKind | stringKind}, 475 - Result: stringKind, 476 - Func: func(c *CallCtxt) { 477 - src := c.Bytes(0) 478 - if c.Do() { 479 - c.Ret = func() interface{} { 480 - return hex.EncodeToString(src) 481 - }() 482 - } 483 - }, 484 - }}, 485 - }, 486 - "encoding/json": { 487 - Native: []*Builtin{{ 488 - Name: "Valid", 489 - Params: []kind{bytesKind | stringKind}, 490 - Result: boolKind, 491 - Func: func(c *CallCtxt) { 492 - data := c.Bytes(0) 493 - if c.Do() { 494 - c.Ret = func() interface{} { 495 - return json.Valid(data) 496 - }() 497 - } 498 - }, 499 - }, { 500 - Name: "Compact", 501 - Params: []kind{bytesKind | stringKind}, 502 - Result: stringKind, 503 - Func: func(c *CallCtxt) { 504 - src := c.Bytes(0) 505 - if c.Do() { 506 - c.Ret, c.Err = func() (interface{}, error) { 507 - dst := bytes.Buffer{} 508 - if err := json.Compact(&dst, src); err != nil { 509 - return "", err 510 - } 511 - return dst.String(), nil 512 - }() 513 - } 514 - }, 515 - }, { 516 - Name: "Indent", 517 - Params: []kind{bytesKind | stringKind, stringKind, stringKind}, 518 - Result: stringKind, 519 - Func: func(c *CallCtxt) { 520 - src, prefix, indent := c.Bytes(0), c.String(1), c.String(2) 521 - if c.Do() { 522 - c.Ret, c.Err = func() (interface{}, error) { 523 - dst := bytes.Buffer{} 524 - if err := json.Indent(&dst, src, prefix, indent); err != nil { 525 - return "", err 526 - } 527 - return dst.String(), nil 528 - }() 529 - } 530 - }, 531 - }, { 532 - Name: "HTMLEscape", 533 - Params: []kind{bytesKind | stringKind}, 534 - Result: stringKind, 535 - Func: func(c *CallCtxt) { 536 - src := c.Bytes(0) 537 - if c.Do() { 538 - c.Ret = func() interface{} { 539 - dst := &bytes.Buffer{} 540 - json.HTMLEscape(dst, src) 541 - return dst.String() 542 - }() 543 - } 544 - }, 545 - }, { 546 - Name: "Marshal", 547 - Params: []kind{topKind}, 548 - Result: stringKind, 549 - Func: func(c *CallCtxt) { 550 - v := c.Value(0) 551 - if c.Do() { 552 - c.Ret, c.Err = func() (interface{}, error) { 553 - b, err := json.Marshal(v) 554 - return string(b), err 555 - }() 556 - } 557 - }, 558 - }, { 559 - Name: "MarshalStream", 560 - Params: []kind{topKind}, 561 - Result: stringKind, 562 - Func: func(c *CallCtxt) { 563 - v := c.Value(0) 564 - if c.Do() { 565 - c.Ret, c.Err = func() (interface{}, error) { 566 - 567 - iter, err := v.List() 568 - if err != nil { 569 - return "", err 570 - } 571 - buf := &bytes.Buffer{} 572 - for iter.Next() { 573 - b, err := json.Marshal(iter.Value()) 574 - if err != nil { 575 - return "", err 576 - } 577 - buf.Write(b) 578 - buf.WriteByte('\n') 579 - } 580 - return buf.String(), nil 581 - }() 582 - } 583 - }, 584 - }, { 585 - Name: "Unmarshal", 586 - Params: []kind{bytesKind | stringKind}, 587 - Result: topKind, 588 - Func: func(c *CallCtxt) { 589 - b := c.Bytes(0) 590 - if c.Do() { 591 - c.Ret, c.Err = func() (interface{}, error) { 592 - if !json.Valid(b) { 593 - return nil, fmt.Errorf("json: invalid JSON") 594 - } 595 - expr, err := parser.ParseExpr("json", b) 596 - if err != nil { 597 - 598 - return nil, fmt.Errorf("json: could not parse JSON: %v", err) 599 - } 600 - return expr, nil 601 - }() 602 - } 603 - }, 604 - }, { 605 - Name: "Validate", 606 - Params: []kind{bytesKind | stringKind, topKind}, 607 - Result: boolKind, 608 - Func: func(c *CallCtxt) { 609 - b, v := c.Bytes(0), c.Value(1) 610 - if c.Do() { 611 - c.Ret, c.Err = func() (interface{}, error) { 612 - if !json.Valid(b) { 613 - return false, fmt.Errorf("json: invalid JSON") 614 - } 615 - r := internal.GetRuntimeNew(v).(*Runtime) 616 - inst, err := r.Compile("json.Validate", b) 617 - if err != nil { 618 - return false, err 619 - } 620 - 621 - t := inst.Value() 622 - 623 - v = v.Unify(t) 624 - if v.Err() != nil { 625 - return false, v.Err() 626 - } 627 - return true, nil 628 - }() 629 - } 630 - }, 631 - }}, 632 - }, 633 - "encoding/yaml": { 634 - Native: []*Builtin{{ 635 - Name: "Marshal", 636 - Params: []kind{topKind}, 637 - Result: stringKind, 638 - Func: func(c *CallCtxt) { 639 - v := c.Value(0) 640 - if c.Do() { 641 - c.Ret, c.Err = func() (interface{}, error) { 642 - if err := v.Validate(Concrete(true)); err != nil { 643 - if err := v.Validate(); err != nil { 644 - return "", err 645 - } 646 - return "", internal.ErrIncomplete 647 - } 648 - n := v.Syntax(Final(), Concrete(true)) 649 - b, err := cueyaml.Encode(n) 650 - return string(b), err 651 - }() 652 - } 653 - }, 654 - }, { 655 - Name: "MarshalStream", 656 - Params: []kind{topKind}, 657 - Result: stringKind, 658 - Func: func(c *CallCtxt) { 659 - v := c.Value(0) 660 - if c.Do() { 661 - c.Ret, c.Err = func() (interface{}, error) { 662 - 663 - iter, err := v.List() 664 - if err != nil { 665 - return "", err 666 - } 667 - buf := &bytes.Buffer{} 668 - for i := 0; iter.Next(); i++ { 669 - if i > 0 { 670 - buf.WriteString("---\n") 671 - } 672 - v := iter.Value() 673 - if err := v.Validate(Concrete(true)); err != nil { 674 - if err := v.Validate(); err != nil { 675 - return "", err 676 - } 677 - return "", internal.ErrIncomplete 678 - } 679 - n := v.Syntax(Final(), Concrete(true)) 680 - b, err := cueyaml.Encode(n) 681 - if err != nil { 682 - return "", err 683 - } 684 - buf.Write(b) 685 - } 686 - return buf.String(), nil 687 - }() 688 - } 689 - }, 690 - }, { 691 - Name: "Unmarshal", 692 - Params: []kind{bytesKind | stringKind}, 693 - Result: topKind, 694 - Func: func(c *CallCtxt) { 695 - data := c.Bytes(0) 696 - if c.Do() { 697 - c.Ret, c.Err = func() (interface{}, error) { 698 - return yaml.Unmarshal("", data) 699 - }() 700 - } 701 - }, 702 - }, { 703 - Name: "Validate", 704 - Params: []kind{bytesKind | stringKind, topKind}, 705 - Result: boolKind, 706 - Func: func(c *CallCtxt) { 707 - b, v := c.Bytes(0), c.Value(1) 708 - if c.Do() { 709 - c.Ret, c.Err = func() (interface{}, error) { 710 - d, err := yaml.NewDecoder("yaml.Validate", b) 711 - if err != nil { 712 - return false, err 713 - } 714 - r := internal.GetRuntimeNew(v).(*Runtime) 715 - for { 716 - expr, err := d.Decode() 717 - if err != nil { 718 - if err == io.EOF { 719 - return true, nil 720 - } 721 - return false, err 722 - } 723 - 724 - inst, err := r.CompileExpr(expr) 725 - if err != nil { 726 - return false, err 727 - } 728 - 729 - x := v.Unify(inst.Value()) 730 - if err := x.Err(); err != nil { 731 - return false, err 732 - } 733 - if err := x.Validate(Concrete(true)); err != nil { 734 - return false, err 735 - } 736 - 737 - } 738 - }() 739 - } 740 - }, 741 - }, { 742 - Name: "ValidatePartial", 743 - Params: []kind{bytesKind | stringKind, topKind}, 744 - Result: boolKind, 745 - Func: func(c *CallCtxt) { 746 - b, v := c.Bytes(0), c.Value(1) 747 - if c.Do() { 748 - c.Ret, c.Err = func() (interface{}, error) { 749 - d, err := yaml.NewDecoder("yaml.ValidatePartial", b) 750 - if err != nil { 751 - return false, err 752 - } 753 - r := internal.GetRuntimeNew(v).(*Runtime) 754 - for { 755 - expr, err := d.Decode() 756 - if err != nil { 757 - if err == io.EOF { 758 - return true, nil 759 - } 760 - return false, err 761 - } 762 - 763 - inst, err := r.CompileExpr(expr) 764 - if err != nil { 765 - return false, err 766 - } 767 - 768 - if x := v.Unify(inst.Value()); x.Err() != nil { 769 - return false, x.Err() 770 - } 771 - } 772 - }() 773 - } 774 - }, 775 - }}, 776 - }, 777 - "html": { 778 - Native: []*Builtin{{ 779 - Name: "Escape", 780 - Params: []kind{stringKind}, 781 - Result: stringKind, 782 - Func: func(c *CallCtxt) { 783 - s := c.String(0) 784 - if c.Do() { 785 - c.Ret = func() interface{} { 786 - return html.EscapeString(s) 787 - }() 788 - } 789 - }, 790 - }, { 791 - Name: "Unescape", 792 - Params: []kind{stringKind}, 793 - Result: stringKind, 794 - Func: func(c *CallCtxt) { 795 - s := c.String(0) 796 - if c.Do() { 797 - c.Ret = func() interface{} { 798 - return html.UnescapeString(s) 799 - }() 800 - } 801 - }, 802 - }}, 803 - }, 804 - "list": { 805 - Native: []*Builtin{{ 806 - Name: "Drop", 807 - Params: []kind{listKind, intKind}, 808 - Result: listKind, 809 - Func: func(c *CallCtxt) { 810 - x, n := c.List(0), c.Int(1) 811 - if c.Do() { 812 - c.Ret, c.Err = func() (interface{}, error) { 813 - if n < 0 { 814 - return nil, fmt.Errorf("negative index") 815 - } 816 - 817 - if n > len(x) { 818 - return []Value{}, nil 819 - } 820 - 821 - return x[n:], nil 822 - }() 823 - } 824 - }, 825 - }, { 826 - Name: "FlattenN", 827 - Params: []kind{topKind, intKind}, 828 - Result: listKind, 829 - Func: func(c *CallCtxt) { 830 - xs, depth := c.Value(0), c.Int(1) 831 - if c.Do() { 832 - c.Ret, c.Err = func() (interface{}, error) { 833 - var flattenN func(Value, int) ([]Value, error) 834 - flattenN = func(xs Value, depth int) ([]Value, error) { 835 - var res []Value 836 - iter, err := xs.List() 837 - if err != nil { 838 - return nil, err 839 - } 840 - for iter.Next() { 841 - val, _ := iter.Value().Default() 842 - if val.Kind() == ListKind && depth != 0 { 843 - d := depth - 1 844 - values, err := flattenN(val, d) 845 - if err != nil { 846 - return nil, err 847 - } 848 - res = append(res, values...) 849 - } else { 850 - res = append(res, val) 851 - } 852 - } 853 - return res, nil 854 - } 855 - return flattenN(xs, depth) 856 - }() 857 - } 858 - }, 859 - }, { 860 - Name: "Take", 861 - Params: []kind{listKind, intKind}, 862 - Result: listKind, 863 - Func: func(c *CallCtxt) { 864 - x, n := c.List(0), c.Int(1) 865 - if c.Do() { 866 - c.Ret, c.Err = func() (interface{}, error) { 867 - if n < 0 { 868 - return nil, fmt.Errorf("negative index") 869 - } 870 - 871 - if n > len(x) { 872 - return x, nil 873 - } 874 - 875 - return x[:n], nil 876 - }() 877 - } 878 - }, 879 - }, { 880 - Name: "Slice", 881 - Params: []kind{listKind, intKind, intKind}, 882 - Result: listKind, 883 - Func: func(c *CallCtxt) { 884 - x, i, j := c.List(0), c.Int(1), c.Int(2) 885 - if c.Do() { 886 - c.Ret, c.Err = func() (interface{}, error) { 887 - if i < 0 { 888 - return nil, fmt.Errorf("negative index") 889 - } 890 - 891 - if i > j { 892 - return nil, fmt.Errorf("invalid index: %v > %v", i, j) 893 - } 894 - 895 - if i > len(x) { 896 - return nil, fmt.Errorf("slice bounds out of range") 897 - } 898 - 899 - if j > len(x) { 900 - return nil, fmt.Errorf("slice bounds out of range") 901 - } 902 - 903 - return x[i:j], nil 904 - }() 905 - } 906 - }, 907 - }, { 908 - Name: "MinItems", 909 - Params: []kind{listKind, intKind}, 910 - Result: boolKind, 911 - Func: func(c *CallCtxt) { 912 - a, n := c.List(0), c.Int(1) 913 - if c.Do() { 914 - c.Ret = func() interface{} { 915 - return len(a) >= n 916 - }() 917 - } 918 - }, 919 - }, { 920 - Name: "MaxItems", 921 - Params: []kind{listKind, intKind}, 922 - Result: boolKind, 923 - Func: func(c *CallCtxt) { 924 - a, n := c.List(0), c.Int(1) 925 - if c.Do() { 926 - c.Ret = func() interface{} { 927 - return len(a) <= n 928 - }() 929 - } 930 - }, 931 - }, { 932 - Name: "UniqueItems", 933 - Params: []kind{listKind}, 934 - Result: boolKind, 935 - Func: func(c *CallCtxt) { 936 - a := c.List(0) 937 - if c.Do() { 938 - c.Ret = func() interface{} { 939 - b := []string{} 940 - for _, v := range a { 941 - b = append(b, fmt.Sprint(v)) 942 - } 943 - sort.Strings(b) 944 - for i := 1; i < len(b); i++ { 945 - if b[i-1] == b[i] { 946 - return false 947 - } 948 - } 949 - return true 950 - }() 951 - } 952 - }, 953 - }, { 954 - Name: "Contains", 955 - Params: []kind{listKind, topKind}, 956 - Result: boolKind, 957 - Func: func(c *CallCtxt) { 958 - a, v := c.List(0), c.Value(1) 959 - if c.Do() { 960 - c.Ret = func() interface{} { 961 - for _, w := range a { 962 - if v.Equals(w) { 963 - return true 964 - } 965 - } 966 - return false 967 - }() 968 - } 969 - }, 970 - }, { 971 - Name: "Avg", 972 - Params: []kind{listKind}, 973 - Result: numKind, 974 - Func: func(c *CallCtxt) { 975 - xs := c.DecimalList(0) 976 - if c.Do() { 977 - c.Ret, c.Err = func() (interface{}, error) { 978 - if 0 == len(xs) { 979 - return nil, fmt.Errorf("empty list") 980 - } 981 - 982 - s := apd.New(0, 0) 983 - for _, x := range xs { 984 - _, err := internal.BaseContext.Add(s, x, s) 985 - if err != nil { 986 - return nil, err 987 - } 988 - } 989 - 990 - var d apd.Decimal 991 - l := apd.New(int64(len(xs)), 0) 992 - _, err := internal.BaseContext.Quo(&d, s, l) 993 - if err != nil { 994 - return nil, err 995 - } 996 - return &d, nil 997 - }() 998 - } 999 - }, 1000 - }, { 1001 - Name: "Max", 1002 - Params: []kind{listKind}, 1003 - Result: numKind, 1004 - Func: func(c *CallCtxt) { 1005 - xs := c.DecimalList(0) 1006 - if c.Do() { 1007 - c.Ret, c.Err = func() (interface{}, error) { 1008 - if 0 == len(xs) { 1009 - return nil, fmt.Errorf("empty list") 1010 - } 1011 - 1012 - max := xs[0] 1013 - for _, x := range xs[1:] { 1014 - if -1 == max.Cmp(x) { 1015 - max = x 1016 - } 1017 - } 1018 - return max, nil 1019 - }() 1020 - } 1021 - }, 1022 - }, { 1023 - Name: "Min", 1024 - Params: []kind{listKind}, 1025 - Result: numKind, 1026 - Func: func(c *CallCtxt) { 1027 - xs := c.DecimalList(0) 1028 - if c.Do() { 1029 - c.Ret, c.Err = func() (interface{}, error) { 1030 - if 0 == len(xs) { 1031 - return nil, fmt.Errorf("empty list") 1032 - } 1033 - 1034 - min := xs[0] 1035 - for _, x := range xs[1:] { 1036 - if +1 == min.Cmp(x) { 1037 - min = x 1038 - } 1039 - } 1040 - return min, nil 1041 - }() 1042 - } 1043 - }, 1044 - }, { 1045 - Name: "Product", 1046 - Params: []kind{listKind}, 1047 - Result: numKind, 1048 - Func: func(c *CallCtxt) { 1049 - xs := c.DecimalList(0) 1050 - if c.Do() { 1051 - c.Ret, c.Err = func() (interface{}, error) { 1052 - d := apd.New(1, 0) 1053 - for _, x := range xs { 1054 - _, err := internal.BaseContext.Mul(d, x, d) 1055 - if err != nil { 1056 - return nil, err 1057 - } 1058 - } 1059 - return d, nil 1060 - }() 1061 - } 1062 - }, 1063 - }, { 1064 - Name: "Range", 1065 - Params: []kind{numKind, numKind, numKind}, 1066 - Result: listKind, 1067 - Func: func(c *CallCtxt) { 1068 - start, limit, step := c.Decimal(0), c.Decimal(1), c.Decimal(2) 1069 - if c.Do() { 1070 - c.Ret, c.Err = func() (interface{}, error) { 1071 - if step.IsZero() { 1072 - return nil, fmt.Errorf("step must be non zero") 1073 - } 1074 - 1075 - if !step.Negative && +1 == start.Cmp(limit) { 1076 - return nil, fmt.Errorf("end must be greater than start when step is positive") 1077 - } 1078 - 1079 - if step.Negative && -1 == start.Cmp(limit) { 1080 - return nil, fmt.Errorf("end must be less than start when step is negative") 1081 - } 1082 - 1083 - var vals []*internal.Decimal 1084 - num := start 1085 - for { 1086 - if !step.Negative && -1 != num.Cmp(limit) { 1087 - break 1088 - } 1089 - 1090 - if step.Negative && +1 != num.Cmp(limit) { 1091 - break 1092 - } 1093 - 1094 - vals = append(vals, num) 1095 - d := apd.New(0, 0) 1096 - _, err := internal.BaseContext.Add(d, step, num) 1097 - if err != nil { 1098 - return nil, err 1099 - } 1100 - num = d 1101 - } 1102 - return vals, nil 1103 - }() 1104 - } 1105 - }, 1106 - }, { 1107 - Name: "Sum", 1108 - Params: []kind{listKind}, 1109 - Result: numKind, 1110 - Func: func(c *CallCtxt) { 1111 - xs := c.DecimalList(0) 1112 - if c.Do() { 1113 - c.Ret, c.Err = func() (interface{}, error) { 1114 - d := apd.New(0, 0) 1115 - for _, x := range xs { 1116 - _, err := internal.BaseContext.Add(d, x, d) 1117 - if err != nil { 1118 - return nil, err 1119 - } 1120 - } 1121 - return d, nil 1122 - }() 1123 - } 1124 - }, 1125 - }, { 1126 - Name: "Sort", 1127 - Params: []kind{listKind, topKind}, 1128 - Result: listKind, 1129 - Func: func(c *CallCtxt) { 1130 - list, cmp := c.List(0), c.Value(1) 1131 - if c.Do() { 1132 - c.Ret, c.Err = func() (interface{}, error) { 1133 - s := valueSorter{list, cmp, nil} 1134 - 1135 - sort.Sort(&s) 1136 - return s.ret() 1137 - }() 1138 - } 1139 - }, 1140 - }, { 1141 - Name: "SortStable", 1142 - Params: []kind{listKind, topKind}, 1143 - Result: listKind, 1144 - Func: func(c *CallCtxt) { 1145 - list, cmp := c.List(0), c.Value(1) 1146 - if c.Do() { 1147 - c.Ret, c.Err = func() (interface{}, error) { 1148 - s := valueSorter{list, cmp, nil} 1149 - sort.Stable(&s) 1150 - return s.ret() 1151 - }() 1152 - } 1153 - }, 1154 - }, { 1155 - Name: "SortStrings", 1156 - Params: []kind{listKind}, 1157 - Result: listKind, 1158 - Func: func(c *CallCtxt) { 1159 - a := c.StringList(0) 1160 - if c.Do() { 1161 - c.Ret = func() interface{} { 1162 - sort.Strings(a) 1163 - return a 1164 - }() 1165 - } 1166 - }, 1167 - }, { 1168 - Name: "IsSorted", 1169 - Params: []kind{listKind, topKind}, 1170 - Result: boolKind, 1171 - Func: func(c *CallCtxt) { 1172 - list, cmp := c.List(0), c.Value(1) 1173 - if c.Do() { 1174 - c.Ret = func() interface{} { 1175 - s := valueSorter{list, cmp, nil} 1176 - return sort.IsSorted(&s) 1177 - }() 1178 - } 1179 - }, 1180 - }, { 1181 - Name: "IsSortedStrings", 1182 - Params: []kind{listKind}, 1183 - Result: boolKind, 1184 - Func: func(c *CallCtxt) { 1185 - a := c.StringList(0) 1186 - if c.Do() { 1187 - c.Ret = func() interface{} { 1188 - return sort.StringsAreSorted(a) 1189 - }() 1190 - } 1191 - }, 1192 - }}, 1193 - CUE: `{ 1194 - Comparer: { 1195 - T: _ 1196 - less: bool 1197 - x: T 1198 - y: T 1199 - } 1200 - Ascending: { 1201 - T: number | string 1202 - less: true && x < y 1203 - x: T 1204 - y: T 1205 - Comparer 1206 - } 1207 - Descending: { 1208 - T: number | string 1209 - less: x > y 1210 - x: T 1211 - y: T 1212 - Comparer 1213 - } 1214 - }`, 1215 - }, 1216 - "math": { 1217 - Native: []*Builtin{{ 1218 - Name: "MaxExp", 1219 - Const: "2147483647", 1220 - }, { 1221 - Name: "MinExp", 1222 - Const: "-2147483648", 1223 - }, { 1224 - Name: "MaxPrec", 1225 - Const: "4294967295", 1226 - }, { 1227 - Name: "ToNearestEven", 1228 - Const: "0", 1229 - }, { 1230 - Name: "ToNearestAway", 1231 - Const: "1", 1232 - }, { 1233 - Name: "ToZero", 1234 - Const: "2", 1235 - }, { 1236 - Name: "AwayFromZero", 1237 - Const: "3", 1238 - }, { 1239 - Name: "ToNegativeInf", 1240 - Const: "4", 1241 - }, { 1242 - Name: "ToPositiveInf", 1243 - Const: "5", 1244 - }, { 1245 - Name: "Below", 1246 - Const: "-1", 1247 - }, { 1248 - Name: "Exact", 1249 - Const: "0", 1250 - }, { 1251 - Name: "Above", 1252 - Const: "1", 1253 - }, { 1254 - Name: "Jacobi", 1255 - Params: []kind{intKind, intKind}, 1256 - Result: intKind, 1257 - Func: func(c *CallCtxt) { 1258 - x, y := c.BigInt(0), c.BigInt(1) 1259 - if c.Do() { 1260 - c.Ret = func() interface{} { 1261 - return big.Jacobi(x, y) 1262 - }() 1263 - } 1264 - }, 1265 - }, { 1266 - Name: "MaxBase", 1267 - Const: "62", 1268 - }, { 1269 - Name: "Floor", 1270 - Params: []kind{numKind}, 1271 - Result: numKind, 1272 - Func: func(c *CallCtxt) { 1273 - x := c.Decimal(0) 1274 - if c.Do() { 1275 - c.Ret, c.Err = func() (interface{}, error) { 1276 - var d internal.Decimal 1277 - _, err := apdContext.Floor(&d, x) 1278 - return &d, err 1279 - }() 1280 - } 1281 - }, 1282 - }, { 1283 - Name: "Ceil", 1284 - Params: []kind{numKind}, 1285 - Result: numKind, 1286 - Func: func(c *CallCtxt) { 1287 - x := c.Decimal(0) 1288 - if c.Do() { 1289 - c.Ret, c.Err = func() (interface{}, error) { 1290 - var d internal.Decimal 1291 - _, err := apdContext.Ceil(&d, x) 1292 - return &d, err 1293 - }() 1294 - } 1295 - }, 1296 - }, { 1297 - Name: "Trunc", 1298 - Params: []kind{numKind}, 1299 - Result: numKind, 1300 - Func: func(c *CallCtxt) { 1301 - x := c.Decimal(0) 1302 - if c.Do() { 1303 - c.Ret, c.Err = func() (interface{}, error) { 1304 - var d internal.Decimal 1305 - _, err := roundTruncContext.RoundToIntegralExact(&d, x) 1306 - return &d, err 1307 - }() 1308 - } 1309 - }, 1310 - }, { 1311 - Name: "Round", 1312 - Params: []kind{numKind}, 1313 - Result: numKind, 1314 - Func: func(c *CallCtxt) { 1315 - x := c.Decimal(0) 1316 - if c.Do() { 1317 - c.Ret, c.Err = func() (interface{}, error) { 1318 - var d internal.Decimal 1319 - _, err := roundUpContext.RoundToIntegralExact(&d, x) 1320 - return &d, err 1321 - }() 1322 - } 1323 - }, 1324 - }, { 1325 - Name: "RoundToEven", 1326 - Params: []kind{numKind}, 1327 - Result: numKind, 1328 - Func: func(c *CallCtxt) { 1329 - x := c.Decimal(0) 1330 - if c.Do() { 1331 - c.Ret, c.Err = func() (interface{}, error) { 1332 - var d internal.Decimal 1333 - _, err := roundEvenContext.RoundToIntegralExact(&d, x) 1334 - return &d, err 1335 - }() 1336 - } 1337 - }, 1338 - }, { 1339 - Name: "MultipleOf", 1340 - Params: []kind{numKind, numKind}, 1341 - Result: boolKind, 1342 - Func: func(c *CallCtxt) { 1343 - x, y := c.Decimal(0), c.Decimal(1) 1344 - if c.Do() { 1345 - c.Ret, c.Err = func() (interface{}, error) { 1346 - var d apd.Decimal 1347 - cond, err := mulContext.Quo(&d, x, y) 1348 - return !cond.Inexact(), err 1349 - }() 1350 - } 1351 - }, 1352 - }, { 1353 - Name: "Abs", 1354 - Params: []kind{numKind}, 1355 - Result: numKind, 1356 - Func: func(c *CallCtxt) { 1357 - x := c.Decimal(0) 1358 - if c.Do() { 1359 - c.Ret, c.Err = func() (interface{}, error) { 1360 - var d internal.Decimal 1361 - _, err := apdContext.Abs(&d, x) 1362 - return &d, err 1363 - }() 1364 - } 1365 - }, 1366 - }, { 1367 - Name: "Acosh", 1368 - Params: []kind{numKind}, 1369 - Result: numKind, 1370 - Func: func(c *CallCtxt) { 1371 - x := c.Float64(0) 1372 - if c.Do() { 1373 - c.Ret = func() interface{} { 1374 - return math.Acosh(x) 1375 - }() 1376 - } 1377 - }, 1378 - }, { 1379 - Name: "Asin", 1380 - Params: []kind{numKind}, 1381 - Result: numKind, 1382 - Func: func(c *CallCtxt) { 1383 - x := c.Float64(0) 1384 - if c.Do() { 1385 - c.Ret = func() interface{} { 1386 - return math.Asin(x) 1387 - }() 1388 - } 1389 - }, 1390 - }, { 1391 - Name: "Acos", 1392 - Params: []kind{numKind}, 1393 - Result: numKind, 1394 - Func: func(c *CallCtxt) { 1395 - x := c.Float64(0) 1396 - if c.Do() { 1397 - c.Ret = func() interface{} { 1398 - return math.Acos(x) 1399 - }() 1400 - } 1401 - }, 1402 - }, { 1403 - Name: "Asinh", 1404 - Params: []kind{numKind}, 1405 - Result: numKind, 1406 - Func: func(c *CallCtxt) { 1407 - x := c.Float64(0) 1408 - if c.Do() { 1409 - c.Ret = func() interface{} { 1410 - return math.Asinh(x) 1411 - }() 1412 - } 1413 - }, 1414 - }, { 1415 - Name: "Atan", 1416 - Params: []kind{numKind}, 1417 - Result: numKind, 1418 - Func: func(c *CallCtxt) { 1419 - x := c.Float64(0) 1420 - if c.Do() { 1421 - c.Ret = func() interface{} { 1422 - return math.Atan(x) 1423 - }() 1424 - } 1425 - }, 1426 - }, { 1427 - Name: "Atan2", 1428 - Params: []kind{numKind, numKind}, 1429 - Result: numKind, 1430 - Func: func(c *CallCtxt) { 1431 - y, x := c.Float64(0), c.Float64(1) 1432 - if c.Do() { 1433 - c.Ret = func() interface{} { 1434 - return math.Atan2(y, x) 1435 - }() 1436 - } 1437 - }, 1438 - }, { 1439 - Name: "Atanh", 1440 - Params: []kind{numKind}, 1441 - Result: numKind, 1442 - Func: func(c *CallCtxt) { 1443 - x := c.Float64(0) 1444 - if c.Do() { 1445 - c.Ret = func() interface{} { 1446 - return math.Atanh(x) 1447 - }() 1448 - } 1449 - }, 1450 - }, { 1451 - Name: "Cbrt", 1452 - Params: []kind{numKind}, 1453 - Result: numKind, 1454 - Func: func(c *CallCtxt) { 1455 - x := c.Decimal(0) 1456 - if c.Do() { 1457 - c.Ret, c.Err = func() (interface{}, error) { 1458 - var d internal.Decimal 1459 - _, err := apdContext.Cbrt(&d, x) 1460 - return &d, err 1461 - }() 1462 - } 1463 - }, 1464 - }, { 1465 - Name: "E", 1466 - Const: "2.71828182845904523536028747135266249775724709369995957496696763", 1467 - }, { 1468 - Name: "Pi", 1469 - Const: "3.14159265358979323846264338327950288419716939937510582097494459", 1470 - }, { 1471 - Name: "Phi", 1472 - Const: "1.61803398874989484820458683436563811772030917980576286213544861", 1473 - }, { 1474 - Name: "Sqrt2", 1475 - Const: "1.41421356237309504880168872420969807856967187537694807317667974", 1476 - }, { 1477 - Name: "SqrtE", 1478 - Const: "1.64872127070012814684865078781416357165377610071014801157507931", 1479 - }, { 1480 - Name: "SqrtPi", 1481 - Const: "1.77245385090551602729816748334114518279754945612238712821380779", 1482 - }, { 1483 - Name: "SqrtPhi", 1484 - Const: "1.27201964951406896425242246173749149171560804184009624861664038", 1485 - }, { 1486 - Name: "Ln2", 1487 - Const: "0.693147180559945309417232121458176568075500134360255254120680009", 1488 - }, { 1489 - Name: "Log2E", 1490 - Const: "1.442695040888963407359924681001892137426645954152985934135449408", 1491 - }, { 1492 - Name: "Ln10", 1493 - Const: "2.3025850929940456840179914546843642076011014886287729760333278", 1494 - }, { 1495 - Name: "Log10E", 1496 - Const: "0.43429448190325182765112891891660508229439700580366656611445378", 1497 - }, { 1498 - Name: "Copysign", 1499 - Params: []kind{numKind, numKind}, 1500 - Result: numKind, 1501 - Func: func(c *CallCtxt) { 1502 - x, y := c.Decimal(0), c.Decimal(1) 1503 - if c.Do() { 1504 - c.Ret = func() interface{} { 1505 - var d internal.Decimal 1506 - d.Set(x) 1507 - d.Negative = y.Negative 1508 - return &d 1509 - }() 1510 - } 1511 - }, 1512 - }, { 1513 - Name: "Dim", 1514 - Params: []kind{numKind, numKind}, 1515 - Result: numKind, 1516 - Func: func(c *CallCtxt) { 1517 - x, y := c.Decimal(0), c.Decimal(1) 1518 - if c.Do() { 1519 - c.Ret, c.Err = func() (interface{}, error) { 1520 - var d internal.Decimal 1521 - _, err := apdContext.Sub(&d, x, y) 1522 - if err != nil { 1523 - return nil, err 1524 - } 1525 - if d.Negative { 1526 - return zero, nil 1527 - } 1528 - return &d, nil 1529 - }() 1530 - } 1531 - }, 1532 - }, { 1533 - Name: "Erf", 1534 - Params: []kind{numKind}, 1535 - Result: numKind, 1536 - Func: func(c *CallCtxt) { 1537 - x := c.Float64(0) 1538 - if c.Do() { 1539 - c.Ret = func() interface{} { 1540 - return math.Erf(x) 1541 - }() 1542 - } 1543 - }, 1544 - }, { 1545 - Name: "Erfc", 1546 - Params: []kind{numKind}, 1547 - Result: numKind, 1548 - Func: func(c *CallCtxt) { 1549 - x := c.Float64(0) 1550 - if c.Do() { 1551 - c.Ret = func() interface{} { 1552 - return math.Erfc(x) 1553 - }() 1554 - } 1555 - }, 1556 - }, { 1557 - Name: "Erfinv", 1558 - Params: []kind{numKind}, 1559 - Result: numKind, 1560 - Func: func(c *CallCtxt) { 1561 - x := c.Float64(0) 1562 - if c.Do() { 1563 - c.Ret = func() interface{} { 1564 - return math.Erfinv(x) 1565 - }() 1566 - } 1567 - }, 1568 - }, { 1569 - Name: "Erfcinv", 1570 - Params: []kind{numKind}, 1571 - Result: numKind, 1572 - Func: func(c *CallCtxt) { 1573 - x := c.Float64(0) 1574 - if c.Do() { 1575 - c.Ret = func() interface{} { 1576 - return math.Erfcinv(x) 1577 - }() 1578 - } 1579 - }, 1580 - }, { 1581 - Name: "Exp", 1582 - Params: []kind{numKind}, 1583 - Result: numKind, 1584 - Func: func(c *CallCtxt) { 1585 - x := c.Decimal(0) 1586 - if c.Do() { 1587 - c.Ret, c.Err = func() (interface{}, error) { 1588 - var d internal.Decimal 1589 - _, err := apdContext.Exp(&d, x) 1590 - return &d, err 1591 - }() 1592 - } 1593 - }, 1594 - }, { 1595 - Name: "Exp2", 1596 - Params: []kind{numKind}, 1597 - Result: numKind, 1598 - Func: func(c *CallCtxt) { 1599 - x := c.Decimal(0) 1600 - if c.Do() { 1601 - c.Ret, c.Err = func() (interface{}, error) { 1602 - var d internal.Decimal 1603 - _, err := apdContext.Pow(&d, two, x) 1604 - return &d, err 1605 - }() 1606 - } 1607 - }, 1608 - }, { 1609 - Name: "Expm1", 1610 - Params: []kind{numKind}, 1611 - Result: numKind, 1612 - Func: func(c *CallCtxt) { 1613 - x := c.Float64(0) 1614 - if c.Do() { 1615 - c.Ret = func() interface{} { 1616 - return math.Expm1(x) 1617 - }() 1618 - } 1619 - }, 1620 - }, { 1621 - Name: "Gamma", 1622 - Params: []kind{numKind}, 1623 - Result: numKind, 1624 - Func: func(c *CallCtxt) { 1625 - x := c.Float64(0) 1626 - if c.Do() { 1627 - c.Ret = func() interface{} { 1628 - return math.Gamma(x) 1629 - }() 1630 - } 1631 - }, 1632 - }, { 1633 - Name: "Hypot", 1634 - Params: []kind{numKind, numKind}, 1635 - Result: numKind, 1636 - Func: func(c *CallCtxt) { 1637 - p, q := c.Float64(0), c.Float64(1) 1638 - if c.Do() { 1639 - c.Ret = func() interface{} { 1640 - return math.Hypot(p, q) 1641 - }() 1642 - } 1643 - }, 1644 - }, { 1645 - Name: "J0", 1646 - Params: []kind{numKind}, 1647 - Result: numKind, 1648 - Func: func(c *CallCtxt) { 1649 - x := c.Float64(0) 1650 - if c.Do() { 1651 - c.Ret = func() interface{} { 1652 - return math.J0(x) 1653 - }() 1654 - } 1655 - }, 1656 - }, { 1657 - Name: "Y0", 1658 - Params: []kind{numKind}, 1659 - Result: numKind, 1660 - Func: func(c *CallCtxt) { 1661 - x := c.Float64(0) 1662 - if c.Do() { 1663 - c.Ret = func() interface{} { 1664 - return math.Y0(x) 1665 - }() 1666 - } 1667 - }, 1668 - }, { 1669 - Name: "J1", 1670 - Params: []kind{numKind}, 1671 - Result: numKind, 1672 - Func: func(c *CallCtxt) { 1673 - x := c.Float64(0) 1674 - if c.Do() { 1675 - c.Ret = func() interface{} { 1676 - return math.J1(x) 1677 - }() 1678 - } 1679 - }, 1680 - }, { 1681 - Name: "Y1", 1682 - Params: []kind{numKind}, 1683 - Result: numKind, 1684 - Func: func(c *CallCtxt) { 1685 - x := c.Float64(0) 1686 - if c.Do() { 1687 - c.Ret = func() interface{} { 1688 - return math.Y1(x) 1689 - }() 1690 - } 1691 - }, 1692 - }, { 1693 - Name: "Jn", 1694 - Params: []kind{intKind, numKind}, 1695 - Result: numKind, 1696 - Func: func(c *CallCtxt) { 1697 - n, x := c.Int(0), c.Float64(1) 1698 - if c.Do() { 1699 - c.Ret = func() interface{} { 1700 - return math.Jn(n, x) 1701 - }() 1702 - } 1703 - }, 1704 - }, { 1705 - Name: "Yn", 1706 - Params: []kind{intKind, numKind}, 1707 - Result: numKind, 1708 - Func: func(c *CallCtxt) { 1709 - n, x := c.Int(0), c.Float64(1) 1710 - if c.Do() { 1711 - c.Ret = func() interface{} { 1712 - return math.Yn(n, x) 1713 - }() 1714 - } 1715 - }, 1716 - }, { 1717 - Name: "Ldexp", 1718 - Params: []kind{numKind, intKind}, 1719 - Result: numKind, 1720 - Func: func(c *CallCtxt) { 1721 - frac, exp := c.Float64(0), c.Int(1) 1722 - if c.Do() { 1723 - c.Ret = func() interface{} { 1724 - return math.Ldexp(frac, exp) 1725 - }() 1726 - } 1727 - }, 1728 - }, { 1729 - Name: "Log", 1730 - Params: []kind{numKind}, 1731 - Result: numKind, 1732 - Func: func(c *CallCtxt) { 1733 - x := c.Decimal(0) 1734 - if c.Do() { 1735 - c.Ret, c.Err = func() (interface{}, error) { 1736 - var d internal.Decimal 1737 - _, err := apdContext.Ln(&d, x) 1738 - return &d, err 1739 - }() 1740 - } 1741 - }, 1742 - }, { 1743 - Name: "Log10", 1744 - Params: []kind{numKind}, 1745 - Result: numKind, 1746 - Func: func(c *CallCtxt) { 1747 - x := c.Decimal(0) 1748 - if c.Do() { 1749 - c.Ret, c.Err = func() (interface{}, error) { 1750 - var d internal.Decimal 1751 - _, err := apdContext.Log10(&d, x) 1752 - return &d, err 1753 - }() 1754 - } 1755 - }, 1756 - }, { 1757 - Name: "Log2", 1758 - Params: []kind{numKind}, 1759 - Result: numKind, 1760 - Func: func(c *CallCtxt) { 1761 - x := c.Decimal(0) 1762 - if c.Do() { 1763 - c.Ret, c.Err = func() (interface{}, error) { 1764 - var d, ln2 internal.Decimal 1765 - _, _ = apdContext.Ln(&ln2, two) 1766 - _, err := apdContext.Ln(&d, x) 1767 - if err != nil { 1768 - return &d, err 1769 - } 1770 - _, err = apdContext.Quo(&d, &d, &ln2) 1771 - return &d, nil 1772 - }() 1773 - } 1774 - }, 1775 - }, { 1776 - Name: "Log1p", 1777 - Params: []kind{numKind}, 1778 - Result: numKind, 1779 - Func: func(c *CallCtxt) { 1780 - x := c.Float64(0) 1781 - if c.Do() { 1782 - c.Ret = func() interface{} { 1783 - return math.Log1p(x) 1784 - }() 1785 - } 1786 - }, 1787 - }, { 1788 - Name: "Logb", 1789 - Params: []kind{numKind}, 1790 - Result: numKind, 1791 - Func: func(c *CallCtxt) { 1792 - x := c.Float64(0) 1793 - if c.Do() { 1794 - c.Ret = func() interface{} { 1795 - return math.Logb(x) 1796 - }() 1797 - } 1798 - }, 1799 - }, { 1800 - Name: "Ilogb", 1801 - Params: []kind{numKind}, 1802 - Result: intKind, 1803 - Func: func(c *CallCtxt) { 1804 - x := c.Float64(0) 1805 - if c.Do() { 1806 - c.Ret = func() interface{} { 1807 - return math.Ilogb(x) 1808 - }() 1809 - } 1810 - }, 1811 - }, { 1812 - Name: "Mod", 1813 - Params: []kind{numKind, numKind}, 1814 - Result: numKind, 1815 - Func: func(c *CallCtxt) { 1816 - x, y := c.Float64(0), c.Float64(1) 1817 - if c.Do() { 1818 - c.Ret = func() interface{} { 1819 - return math.Mod(x, y) 1820 - }() 1821 - } 1822 - }, 1823 - }, { 1824 - Name: "Pow", 1825 - Params: []kind{numKind, numKind}, 1826 - Result: numKind, 1827 - Func: func(c *CallCtxt) { 1828 - x, y := c.Decimal(0), c.Decimal(1) 1829 - if c.Do() { 1830 - c.Ret, c.Err = func() (interface{}, error) { 1831 - var d internal.Decimal 1832 - _, err := apdContext.Pow(&d, x, y) 1833 - return &d, err 1834 - }() 1835 - } 1836 - }, 1837 - }, { 1838 - Name: "Pow10", 1839 - Params: []kind{intKind}, 1840 - Result: numKind, 1841 - Func: func(c *CallCtxt) { 1842 - n := c.Int32(0) 1843 - if c.Do() { 1844 - c.Ret = func() interface{} { 1845 - return apd.New(1, n) 1846 - }() 1847 - } 1848 - }, 1849 - }, { 1850 - Name: "Remainder", 1851 - Params: []kind{numKind, numKind}, 1852 - Result: numKind, 1853 - Func: func(c *CallCtxt) { 1854 - x, y := c.Float64(0), c.Float64(1) 1855 - if c.Do() { 1856 - c.Ret = func() interface{} { 1857 - return math.Remainder(x, y) 1858 - }() 1859 - } 1860 - }, 1861 - }, { 1862 - Name: "Signbit", 1863 - Params: []kind{numKind}, 1864 - Result: boolKind, 1865 - Func: func(c *CallCtxt) { 1866 - x := c.Decimal(0) 1867 - if c.Do() { 1868 - c.Ret = func() interface{} { 1869 - return x.Negative 1870 - }() 1871 - } 1872 - }, 1873 - }, { 1874 - Name: "Cos", 1875 - Params: []kind{numKind}, 1876 - Result: numKind, 1877 - Func: func(c *CallCtxt) { 1878 - x := c.Float64(0) 1879 - if c.Do() { 1880 - c.Ret = func() interface{} { 1881 - return math.Cos(x) 1882 - }() 1883 - } 1884 - }, 1885 - }, { 1886 - Name: "Sin", 1887 - Params: []kind{numKind}, 1888 - Result: numKind, 1889 - Func: func(c *CallCtxt) { 1890 - x := c.Float64(0) 1891 - if c.Do() { 1892 - c.Ret = func() interface{} { 1893 - return math.Sin(x) 1894 - }() 1895 - } 1896 - }, 1897 - }, { 1898 - Name: "Sinh", 1899 - Params: []kind{numKind}, 1900 - Result: numKind, 1901 - Func: func(c *CallCtxt) { 1902 - x := c.Float64(0) 1903 - if c.Do() { 1904 - c.Ret = func() interface{} { 1905 - return math.Sinh(x) 1906 - }() 1907 - } 1908 - }, 1909 - }, { 1910 - Name: "Cosh", 1911 - Params: []kind{numKind}, 1912 - Result: numKind, 1913 - Func: func(c *CallCtxt) { 1914 - x := c.Float64(0) 1915 - if c.Do() { 1916 - c.Ret = func() interface{} { 1917 - return math.Cosh(x) 1918 - }() 1919 - } 1920 - }, 1921 - }, { 1922 - Name: "Sqrt", 1923 - Params: []kind{numKind}, 1924 - Result: numKind, 1925 - Func: func(c *CallCtxt) { 1926 - x := c.Float64(0) 1927 - if c.Do() { 1928 - c.Ret = func() interface{} { 1929 - return math.Sqrt(x) 1930 - }() 1931 - } 1932 - }, 1933 - }, { 1934 - Name: "Tan", 1935 - Params: []kind{numKind}, 1936 - Result: numKind, 1937 - Func: func(c *CallCtxt) { 1938 - x := c.Float64(0) 1939 - if c.Do() { 1940 - c.Ret = func() interface{} { 1941 - return math.Tan(x) 1942 - }() 1943 - } 1944 - }, 1945 - }, { 1946 - Name: "Tanh", 1947 - Params: []kind{numKind}, 1948 - Result: numKind, 1949 - Func: func(c *CallCtxt) { 1950 - x := c.Float64(0) 1951 - if c.Do() { 1952 - c.Ret = func() interface{} { 1953 - return math.Tanh(x) 1954 - }() 1955 - } 1956 - }, 1957 - }}, 1958 - }, 1959 - "math/bits": { 1960 - Native: []*Builtin{{ 1961 - Name: "Lsh", 1962 - Params: []kind{intKind, intKind}, 1963 - Result: intKind, 1964 - Func: func(c *CallCtxt) { 1965 - x, n := c.BigInt(0), c.Uint(1) 1966 - if c.Do() { 1967 - c.Ret = func() interface{} { 1968 - var z big.Int 1969 - z.Lsh(x, n) 1970 - return &z 1971 - }() 1972 - } 1973 - }, 1974 - }, { 1975 - Name: "Rsh", 1976 - Params: []kind{intKind, intKind}, 1977 - Result: intKind, 1978 - Func: func(c *CallCtxt) { 1979 - x, n := c.BigInt(0), c.Uint(1) 1980 - if c.Do() { 1981 - c.Ret = func() interface{} { 1982 - var z big.Int 1983 - z.Rsh(x, n) 1984 - return &z 1985 - }() 1986 - } 1987 - }, 1988 - }, { 1989 - Name: "At", 1990 - Params: []kind{intKind, intKind}, 1991 - Result: intKind, 1992 - Func: func(c *CallCtxt) { 1993 - x, i := c.BigInt(0), c.Uint(1) 1994 - if c.Do() { 1995 - c.Ret, c.Err = func() (interface{}, error) { 1996 - if i > math.MaxInt32 { 1997 - return 0, fmt.Errorf("bit index too large") 1998 - } 1999 - return x.Bit(int(i)), nil 2000 - }() 2001 - } 2002 - }, 2003 - }, { 2004 - Name: "Set", 2005 - Params: []kind{intKind, intKind, intKind}, 2006 - Result: intKind, 2007 - Func: func(c *CallCtxt) { 2008 - x, i, bit := c.BigInt(0), c.Int(1), c.Uint(2) 2009 - if c.Do() { 2010 - c.Ret = func() interface{} { 2011 - var z big.Int 2012 - z.SetBit(x, i, bit) 2013 - return &z 2014 - }() 2015 - } 2016 - }, 2017 - }, { 2018 - Name: "And", 2019 - Params: []kind{intKind, intKind}, 2020 - Result: intKind, 2021 - Func: func(c *CallCtxt) { 2022 - a, b := c.BigInt(0), c.BigInt(1) 2023 - if c.Do() { 2024 - c.Ret = func() interface{} { 2025 - var z big.Int 2026 - z.And(a, b) 2027 - return &z 2028 - }() 2029 - } 2030 - }, 2031 - }, { 2032 - Name: "Or", 2033 - Params: []kind{intKind, intKind}, 2034 - Result: intKind, 2035 - Func: func(c *CallCtxt) { 2036 - a, b := c.BigInt(0), c.BigInt(1) 2037 - if c.Do() { 2038 - c.Ret = func() interface{} { 2039 - var z big.Int 2040 - z.Or(a, b) 2041 - return &z 2042 - }() 2043 - } 2044 - }, 2045 - }, { 2046 - Name: "Xor", 2047 - Params: []kind{intKind, intKind}, 2048 - Result: intKind, 2049 - Func: func(c *CallCtxt) { 2050 - a, b := c.BigInt(0), c.BigInt(1) 2051 - if c.Do() { 2052 - c.Ret = func() interface{} { 2053 - var z big.Int 2054 - z.Xor(a, b) 2055 - return &z 2056 - }() 2057 - } 2058 - }, 2059 - }, { 2060 - Name: "Clear", 2061 - Params: []kind{intKind, intKind}, 2062 - Result: intKind, 2063 - Func: func(c *CallCtxt) { 2064 - a, b := c.BigInt(0), c.BigInt(1) 2065 - if c.Do() { 2066 - c.Ret = func() interface{} { 2067 - var z big.Int 2068 - z.AndNot(a, b) 2069 - return &z 2070 - }() 2071 - } 2072 - }, 2073 - }, { 2074 - Name: "OnesCount", 2075 - Params: []kind{intKind}, 2076 - Result: intKind, 2077 - Func: func(c *CallCtxt) { 2078 - x := c.BigInt(0) 2079 - if c.Do() { 2080 - c.Ret = func() interface{} { 2081 - var count int 2082 - for _, w := range x.Bits() { 2083 - count += bits.OnesCount64(uint64(w)) 2084 - } 2085 - return count 2086 - }() 2087 - } 2088 - }, 2089 - }, { 2090 - Name: "Len", 2091 - Params: []kind{intKind}, 2092 - Result: intKind, 2093 - Func: func(c *CallCtxt) { 2094 - x := c.BigInt(0) 2095 - if c.Do() { 2096 - c.Ret = func() interface{} { 2097 - return x.BitLen() 2098 - }() 2099 - } 2100 - }, 2101 - }}, 2102 - }, 2103 - "net": { 2104 - Native: []*Builtin{{ 2105 - Name: "SplitHostPort", 2106 - Params: []kind{stringKind}, 2107 - Result: listKind, 2108 - Func: func(c *CallCtxt) { 2109 - s := c.String(0) 2110 - if c.Do() { 2111 - c.Ret, c.Err = func() (interface{}, error) { 2112 - host, port, err := net.SplitHostPort(s) 2113 - if err != nil { 2114 - return nil, err 2115 - } 2116 - return []string{host, port}, nil 2117 - }() 2118 - } 2119 - }, 2120 - }, { 2121 - Name: "JoinHostPort", 2122 - Params: []kind{topKind, topKind}, 2123 - Result: stringKind, 2124 - Func: func(c *CallCtxt) { 2125 - host, port := c.Value(0), c.Value(1) 2126 - if c.Do() { 2127 - c.Ret, c.Err = func() (interface{}, error) { 2128 - var err error 2129 - hostStr := "" 2130 - switch host.Kind() { 2131 - case ListKind: 2132 - ipdata := netGetIP(host) 2133 - if len(ipdata) != 4 && len(ipdata) != 16 { 2134 - err = fmt.Errorf("invalid host %q", host) 2135 - } 2136 - hostStr = ipdata.String() 2137 - case BytesKind: 2138 - var b []byte 2139 - b, err = host.Bytes() 2140 - hostStr = string(b) 2141 - default: 2142 - hostStr, err = host.String() 2143 - } 2144 - if err != nil { 2145 - return "", err 2146 - } 2147 - 2148 - portStr := "" 2149 - switch port.Kind() { 2150 - case StringKind: 2151 - portStr, err = port.String() 2152 - case BytesKind: 2153 - var b []byte 2154 - b, err = port.Bytes() 2155 - portStr = string(b) 2156 - default: 2157 - var i int64 2158 - i, err = port.Int64() 2159 - portStr = strconv.Itoa(int(i)) 2160 - } 2161 - if err != nil { 2162 - return "", err 2163 - } 2164 - 2165 - return net.JoinHostPort(hostStr, portStr), nil 2166 - }() 2167 - } 2168 - }, 2169 - }, { 2170 - Name: "FQDN", 2171 - Params: []kind{stringKind}, 2172 - Result: boolKind, 2173 - Func: func(c *CallCtxt) { 2174 - s := c.String(0) 2175 - if c.Do() { 2176 - c.Ret = func() interface{} { 2177 - for i := 0; i < len(s); i++ { 2178 - if s[i] >= utf8.RuneSelf { 2179 - return false 2180 - } 2181 - } 2182 - _, err := idnaProfile.ToASCII(s) 2183 - return err == nil 2184 - }() 2185 - } 2186 - }, 2187 - }, { 2188 - Name: "IPv4len", 2189 - Const: "4", 2190 - }, { 2191 - Name: "IPv6len", 2192 - Const: "16", 2193 - }, { 2194 - Name: "ParseIP", 2195 - Params: []kind{stringKind}, 2196 - Result: listKind, 2197 - Func: func(c *CallCtxt) { 2198 - s := c.String(0) 2199 - if c.Do() { 2200 - c.Ret, c.Err = func() (interface{}, error) { 2201 - goip := net.ParseIP(s) 2202 - if goip == nil { 2203 - return nil, fmt.Errorf("invalid IP address %q", s) 2204 - } 2205 - return netToList(goip), nil 2206 - }() 2207 - } 2208 - }, 2209 - }, { 2210 - Name: "IPv4", 2211 - Params: []kind{topKind}, 2212 - Result: boolKind, 2213 - Func: func(c *CallCtxt) { 2214 - ip := c.Value(0) 2215 - if c.Do() { 2216 - c.Ret = func() interface{} { 2217 - 2218 - return netGetIP(ip).To4() != nil 2219 - }() 2220 - } 2221 - }, 2222 - }, { 2223 - Name: "IP", 2224 - Params: []kind{topKind}, 2225 - Result: boolKind, 2226 - Func: func(c *CallCtxt) { 2227 - ip := c.Value(0) 2228 - if c.Do() { 2229 - c.Ret = func() interface{} { 2230 - 2231 - return netGetIP(ip) != nil 2232 - }() 2233 - } 2234 - }, 2235 - }, { 2236 - Name: "LoopbackIP", 2237 - Params: []kind{topKind}, 2238 - Result: boolKind, 2239 - Func: func(c *CallCtxt) { 2240 - ip := c.Value(0) 2241 - if c.Do() { 2242 - c.Ret = func() interface{} { 2243 - return netGetIP(ip).IsLoopback() 2244 - }() 2245 - } 2246 - }, 2247 - }, { 2248 - Name: "MulticastIP", 2249 - Params: []kind{topKind}, 2250 - Result: boolKind, 2251 - Func: func(c *CallCtxt) { 2252 - ip := c.Value(0) 2253 - if c.Do() { 2254 - c.Ret = func() interface{} { 2255 - return netGetIP(ip).IsMulticast() 2256 - }() 2257 - } 2258 - }, 2259 - }, { 2260 - Name: "InterfaceLocalMulticastIP", 2261 - Params: []kind{topKind}, 2262 - Result: boolKind, 2263 - Func: func(c *CallCtxt) { 2264 - ip := c.Value(0) 2265 - if c.Do() { 2266 - c.Ret = func() interface{} { 2267 - return netGetIP(ip).IsInterfaceLocalMulticast() 2268 - }() 2269 - } 2270 - }, 2271 - }, { 2272 - Name: "LinkLocalMulticastIP", 2273 - Params: []kind{topKind}, 2274 - Result: boolKind, 2275 - Func: func(c *CallCtxt) { 2276 - ip := c.Value(0) 2277 - if c.Do() { 2278 - c.Ret = func() interface{} { 2279 - return netGetIP(ip).IsLinkLocalMulticast() 2280 - }() 2281 - } 2282 - }, 2283 - }, { 2284 - Name: "LinkLocalUnicastIP", 2285 - Params: []kind{topKind}, 2286 - Result: boolKind, 2287 - Func: func(c *CallCtxt) { 2288 - ip := c.Value(0) 2289 - if c.Do() { 2290 - c.Ret = func() interface{} { 2291 - return netGetIP(ip).IsLinkLocalUnicast() 2292 - }() 2293 - } 2294 - }, 2295 - }, { 2296 - Name: "GlobalUnicastIP", 2297 - Params: []kind{topKind}, 2298 - Result: boolKind, 2299 - Func: func(c *CallCtxt) { 2300 - ip := c.Value(0) 2301 - if c.Do() { 2302 - c.Ret = func() interface{} { 2303 - return netGetIP(ip).IsGlobalUnicast() 2304 - }() 2305 - } 2306 - }, 2307 - }, { 2308 - Name: "UnspecifiedIP", 2309 - Params: []kind{topKind}, 2310 - Result: boolKind, 2311 - Func: func(c *CallCtxt) { 2312 - ip := c.Value(0) 2313 - if c.Do() { 2314 - c.Ret = func() interface{} { 2315 - return netGetIP(ip).IsUnspecified() 2316 - }() 2317 - } 2318 - }, 2319 - }, { 2320 - Name: "ToIP4", 2321 - Params: []kind{topKind}, 2322 - Result: listKind, 2323 - Func: func(c *CallCtxt) { 2324 - ip := c.Value(0) 2325 - if c.Do() { 2326 - c.Ret, c.Err = func() (interface{}, error) { 2327 - ipdata := netGetIP(ip) 2328 - if ipdata == nil { 2329 - return nil, fmt.Errorf("invalid IP %q", ip) 2330 - } 2331 - ipv4 := ipdata.To4() 2332 - if ipv4 == nil { 2333 - return nil, fmt.Errorf("cannot convert %q to IPv4", ipdata) 2334 - } 2335 - return netToList(ipv4), nil 2336 - }() 2337 - } 2338 - }, 2339 - }, { 2340 - Name: "ToIP16", 2341 - Params: []kind{topKind}, 2342 - Result: listKind, 2343 - Func: func(c *CallCtxt) { 2344 - ip := c.Value(0) 2345 - if c.Do() { 2346 - c.Ret, c.Err = func() (interface{}, error) { 2347 - ipdata := netGetIP(ip) 2348 - if ipdata == nil { 2349 - return nil, fmt.Errorf("invalid IP %q", ip) 2350 - } 2351 - return netToList(ipdata), nil 2352 - }() 2353 - } 2354 - }, 2355 - }, { 2356 - Name: "IPString", 2357 - Params: []kind{topKind}, 2358 - Result: stringKind, 2359 - Func: func(c *CallCtxt) { 2360 - ip := c.Value(0) 2361 - if c.Do() { 2362 - c.Ret, c.Err = func() (interface{}, error) { 2363 - ipdata := netGetIP(ip) 2364 - if ipdata == nil { 2365 - return "", fmt.Errorf("invalid IP %q", ip) 2366 - } 2367 - return ipdata.String(), nil 2368 - }() 2369 - } 2370 - }, 2371 - }}, 2372 - }, 2373 - "path": { 2374 - Native: []*Builtin{{ 2375 - Name: "Split", 2376 - Params: []kind{stringKind}, 2377 - Result: listKind, 2378 - Func: func(c *CallCtxt) { 2379 - path := c.String(0) 2380 - if c.Do() { 2381 - c.Ret = func() interface{} { 2382 - file, dir := split(path) 2383 - return []string{file, dir} 2384 - }() 2385 - } 2386 - }, 2387 - }, { 2388 - Name: "Match", 2389 - Params: []kind{stringKind, stringKind}, 2390 - Result: boolKind, 2391 - Func: func(c *CallCtxt) { 2392 - pattern, name := c.String(0), c.String(1) 2393 - if c.Do() { 2394 - c.Ret, c.Err = func() (interface{}, error) { 2395 - return path.Match(pattern, name) 2396 - }() 2397 - } 2398 - }, 2399 - }, { 2400 - Name: "Clean", 2401 - Params: []kind{stringKind}, 2402 - Result: stringKind, 2403 - Func: func(c *CallCtxt) { 2404 - path := c.String(0) 2405 - if c.Do() { 2406 - c.Ret = func() interface{} { 2407 - return pathClean(path) 2408 - }() 2409 - } 2410 - }, 2411 - }, { 2412 - Name: "Ext", 2413 - Params: []kind{stringKind}, 2414 - Result: stringKind, 2415 - Func: func(c *CallCtxt) { 2416 - path := c.String(0) 2417 - if c.Do() { 2418 - c.Ret = func() interface{} { 2419 - return pathExt(path) 2420 - }() 2421 - } 2422 - }, 2423 - }, { 2424 - Name: "Base", 2425 - Params: []kind{stringKind}, 2426 - Result: stringKind, 2427 - Func: func(c *CallCtxt) { 2428 - path := c.String(0) 2429 - if c.Do() { 2430 - c.Ret = func() interface{} { 2431 - return pathBase(path) 2432 - }() 2433 - } 2434 - }, 2435 - }, { 2436 - Name: "IsAbs", 2437 - Params: []kind{stringKind}, 2438 - Result: boolKind, 2439 - Func: func(c *CallCtxt) { 2440 - path := c.String(0) 2441 - if c.Do() { 2442 - c.Ret = func() interface{} { 2443 - return pathIsAbs(path) 2444 - }() 2445 - } 2446 - }, 2447 - }, { 2448 - Name: "Dir", 2449 - Params: []kind{stringKind}, 2450 - Result: stringKind, 2451 - Func: func(c *CallCtxt) { 2452 - path := c.String(0) 2453 - if c.Do() { 2454 - c.Ret = func() interface{} { 2455 - return pathDir(path) 2456 - }() 2457 - } 2458 - }, 2459 - }}, 2460 - }, 2461 - "regexp": { 2462 - Native: []*Builtin{{ 2463 - Name: "Valid", 2464 - Params: []kind{stringKind}, 2465 - Result: boolKind, 2466 - Func: func(c *CallCtxt) { 2467 - pattern := c.String(0) 2468 - if c.Do() { 2469 - c.Ret, c.Err = func() (interface{}, error) { 2470 - _, err := regexp.Compile(pattern) 2471 - return err == nil, err 2472 - }() 2473 - } 2474 - }, 2475 - }, { 2476 - Name: "Find", 2477 - Params: []kind{stringKind, stringKind}, 2478 - Result: stringKind, 2479 - Func: func(c *CallCtxt) { 2480 - pattern, s := c.String(0), c.String(1) 2481 - if c.Do() { 2482 - c.Ret, c.Err = func() (interface{}, error) { 2483 - re, err := regexp.Compile(pattern) 2484 - if err != nil { 2485 - return "", err 2486 - } 2487 - m := re.FindStringIndex(s) 2488 - if m == nil { 2489 - return "", errNoMatch 2490 - } 2491 - return s[m[0]:m[1]], nil 2492 - }() 2493 - } 2494 - }, 2495 - }, { 2496 - Name: "FindAll", 2497 - Params: []kind{stringKind, stringKind, intKind}, 2498 - Result: listKind, 2499 - Func: func(c *CallCtxt) { 2500 - pattern, s, n := c.String(0), c.String(1), c.Int(2) 2501 - if c.Do() { 2502 - c.Ret, c.Err = func() (interface{}, error) { 2503 - re, err := regexp.Compile(pattern) 2504 - if err != nil { 2505 - return nil, err 2506 - } 2507 - m := re.FindAllString(s, n) 2508 - if m == nil { 2509 - return nil, errNoMatch 2510 - } 2511 - return m, nil 2512 - }() 2513 - } 2514 - }, 2515 - }, { 2516 - Name: "FindSubmatch", 2517 - Params: []kind{stringKind, stringKind}, 2518 - Result: listKind, 2519 - Func: func(c *CallCtxt) { 2520 - pattern, s := c.String(0), c.String(1) 2521 - if c.Do() { 2522 - c.Ret, c.Err = func() (interface{}, error) { 2523 - re, err := regexp.Compile(pattern) 2524 - if err != nil { 2525 - return nil, err 2526 - } 2527 - m := re.FindStringSubmatch(s) 2528 - if m == nil { 2529 - return nil, errNoMatch 2530 - } 2531 - return m, nil 2532 - }() 2533 - } 2534 - }, 2535 - }, { 2536 - Name: "FindAllSubmatch", 2537 - Params: []kind{stringKind, stringKind, intKind}, 2538 - Result: listKind, 2539 - Func: func(c *CallCtxt) { 2540 - pattern, s, n := c.String(0), c.String(1), c.Int(2) 2541 - if c.Do() { 2542 - c.Ret, c.Err = func() (interface{}, error) { 2543 - re, err := regexp.Compile(pattern) 2544 - if err != nil { 2545 - return nil, err 2546 - } 2547 - m := re.FindAllStringSubmatch(s, n) 2548 - if m == nil { 2549 - return nil, errNoMatch 2550 - } 2551 - return m, nil 2552 - }() 2553 - } 2554 - }, 2555 - }, { 2556 - Name: "FindNamedSubmatch", 2557 - Params: []kind{stringKind, stringKind}, 2558 - Result: structKind, 2559 - Func: func(c *CallCtxt) { 2560 - pattern, s := c.String(0), c.String(1) 2561 - if c.Do() { 2562 - c.Ret, c.Err = func() (interface{}, error) { 2563 - re, err := regexp.Compile(pattern) 2564 - if err != nil { 2565 - return nil, err 2566 - } 2567 - names := re.SubexpNames() 2568 - if len(names) == 0 { 2569 - return nil, errNoNamedGroup 2570 - } 2571 - m := re.FindStringSubmatch(s) 2572 - if m == nil { 2573 - return nil, errNoMatch 2574 - } 2575 - r := make(map[string]string, len(names)-1) 2576 - for k, name := range names { 2577 - if name != "" { 2578 - r[name] = m[k] 2579 - } 2580 - } 2581 - return r, nil 2582 - }() 2583 - } 2584 - }, 2585 - }, { 2586 - Name: "FindAllNamedSubmatch", 2587 - Params: []kind{stringKind, stringKind, intKind}, 2588 - Result: listKind, 2589 - Func: func(c *CallCtxt) { 2590 - pattern, s, n := c.String(0), c.String(1), c.Int(2) 2591 - if c.Do() { 2592 - c.Ret, c.Err = func() (interface{}, error) { 2593 - re, err := regexp.Compile(pattern) 2594 - if err != nil { 2595 - return nil, err 2596 - } 2597 - names := re.SubexpNames() 2598 - if len(names) == 0 { 2599 - return nil, errNoNamedGroup 2600 - } 2601 - m := re.FindAllStringSubmatch(s, n) 2602 - if m == nil { 2603 - return nil, errNoMatch 2604 - } 2605 - result := make([]map[string]string, len(m)) 2606 - for i, m := range m { 2607 - r := make(map[string]string, len(names)-1) 2608 - for k, name := range names { 2609 - if name != "" { 2610 - r[name] = m[k] 2611 - } 2612 - } 2613 - result[i] = r 2614 - } 2615 - return result, nil 2616 - }() 2617 - } 2618 - }, 2619 - }, { 2620 - Name: "Match", 2621 - Params: []kind{stringKind, stringKind}, 2622 - Result: boolKind, 2623 - Func: func(c *CallCtxt) { 2624 - pattern, s := c.String(0), c.String(1) 2625 - if c.Do() { 2626 - c.Ret, c.Err = func() (interface{}, error) { 2627 - return regexp.MatchString(pattern, s) 2628 - }() 2629 - } 2630 - }, 2631 - }, { 2632 - Name: "QuoteMeta", 2633 - Params: []kind{stringKind}, 2634 - Result: stringKind, 2635 - Func: func(c *CallCtxt) { 2636 - s := c.String(0) 2637 - if c.Do() { 2638 - c.Ret = func() interface{} { 2639 - return regexp.QuoteMeta(s) 2640 - }() 2641 - } 2642 - }, 2643 - }}, 2644 - }, 2645 - "strconv": { 2646 - Native: []*Builtin{{ 2647 - Name: "Unquote", 2648 - Params: []kind{stringKind}, 2649 - Result: stringKind, 2650 - Func: func(c *CallCtxt) { 2651 - s := c.String(0) 2652 - if c.Do() { 2653 - c.Ret, c.Err = func() (interface{}, error) { 2654 - return literal.Unquote(s) 2655 - }() 2656 - } 2657 - }, 2658 - }, { 2659 - Name: "ParseBool", 2660 - Params: []kind{stringKind}, 2661 - Result: boolKind, 2662 - Func: func(c *CallCtxt) { 2663 - str := c.String(0) 2664 - if c.Do() { 2665 - c.Ret, c.Err = func() (interface{}, error) { 2666 - return strconv.ParseBool(str) 2667 - }() 2668 - } 2669 - }, 2670 - }, { 2671 - Name: "FormatBool", 2672 - Params: []kind{boolKind}, 2673 - Result: stringKind, 2674 - Func: func(c *CallCtxt) { 2675 - b := c.Bool(0) 2676 - if c.Do() { 2677 - c.Ret = func() interface{} { 2678 - return strconv.FormatBool(b) 2679 - }() 2680 - } 2681 - }, 2682 - }, { 2683 - Name: "ParseFloat", 2684 - Params: []kind{stringKind, intKind}, 2685 - Result: numKind, 2686 - Func: func(c *CallCtxt) { 2687 - s, bitSize := c.String(0), c.Int(1) 2688 - if c.Do() { 2689 - c.Ret, c.Err = func() (interface{}, error) { 2690 - return strconv.ParseFloat(s, bitSize) 2691 - }() 2692 - } 2693 - }, 2694 - }, { 2695 - Name: "IntSize", 2696 - Const: "64", 2697 - }, { 2698 - Name: "ParseUint", 2699 - Params: []kind{stringKind, intKind, intKind}, 2700 - Result: intKind, 2701 - Func: func(c *CallCtxt) { 2702 - s, base, bitSize := c.String(0), c.Int(1), c.Int(2) 2703 - if c.Do() { 2704 - c.Ret, c.Err = func() (interface{}, error) { 2705 - return strconv.ParseUint(s, base, bitSize) 2706 - }() 2707 - } 2708 - }, 2709 - }, { 2710 - Name: "ParseInt", 2711 - Params: []kind{stringKind, intKind, intKind}, 2712 - Result: intKind, 2713 - Func: func(c *CallCtxt) { 2714 - s, base, bitSize := c.String(0), c.Int(1), c.Int(2) 2715 - if c.Do() { 2716 - c.Ret, c.Err = func() (interface{}, error) { 2717 - return strconv.ParseInt(s, base, bitSize) 2718 - }() 2719 - } 2720 - }, 2721 - }, { 2722 - Name: "Atoi", 2723 - Params: []kind{stringKind}, 2724 - Result: intKind, 2725 - Func: func(c *CallCtxt) { 2726 - s := c.String(0) 2727 - if c.Do() { 2728 - c.Ret, c.Err = func() (interface{}, error) { 2729 - return strconv.Atoi(s) 2730 - }() 2731 - } 2732 - }, 2733 - }, { 2734 - Name: "FormatFloat", 2735 - Params: []kind{numKind, intKind, intKind, intKind}, 2736 - Result: stringKind, 2737 - Func: func(c *CallCtxt) { 2738 - f, fmt, prec, bitSize := c.Float64(0), c.Byte(1), c.Int(2), c.Int(3) 2739 - if c.Do() { 2740 - c.Ret = func() interface{} { 2741 - return strconv.FormatFloat(f, fmt, prec, bitSize) 2742 - }() 2743 - } 2744 - }, 2745 - }, { 2746 - Name: "FormatUint", 2747 - Params: []kind{intKind, intKind}, 2748 - Result: stringKind, 2749 - Func: func(c *CallCtxt) { 2750 - i, base := c.Uint64(0), c.Int(1) 2751 - if c.Do() { 2752 - c.Ret = func() interface{} { 2753 - return strconv.FormatUint(i, base) 2754 - }() 2755 - } 2756 - }, 2757 - }, { 2758 - Name: "FormatInt", 2759 - Params: []kind{intKind, intKind}, 2760 - Result: stringKind, 2761 - Func: func(c *CallCtxt) { 2762 - i, base := c.Int64(0), c.Int(1) 2763 - if c.Do() { 2764 - c.Ret = func() interface{} { 2765 - return strconv.FormatInt(i, base) 2766 - }() 2767 - } 2768 - }, 2769 - }, { 2770 - Name: "Quote", 2771 - Params: []kind{stringKind}, 2772 - Result: stringKind, 2773 - Func: func(c *CallCtxt) { 2774 - s := c.String(0) 2775 - if c.Do() { 2776 - c.Ret = func() interface{} { 2777 - return strconv.Quote(s) 2778 - }() 2779 - } 2780 - }, 2781 - }, { 2782 - Name: "QuoteToASCII", 2783 - Params: []kind{stringKind}, 2784 - Result: stringKind, 2785 - Func: func(c *CallCtxt) { 2786 - s := c.String(0) 2787 - if c.Do() { 2788 - c.Ret = func() interface{} { 2789 - return strconv.QuoteToASCII(s) 2790 - }() 2791 - } 2792 - }, 2793 - }, { 2794 - Name: "QuoteToGraphic", 2795 - Params: []kind{stringKind}, 2796 - Result: stringKind, 2797 - Func: func(c *CallCtxt) { 2798 - s := c.String(0) 2799 - if c.Do() { 2800 - c.Ret = func() interface{} { 2801 - return strconv.QuoteToGraphic(s) 2802 - }() 2803 - } 2804 - }, 2805 - }, { 2806 - Name: "QuoteRune", 2807 - Params: []kind{intKind}, 2808 - Result: stringKind, 2809 - Func: func(c *CallCtxt) { 2810 - r := c.Rune(0) 2811 - if c.Do() { 2812 - c.Ret = func() interface{} { 2813 - return strconv.QuoteRune(r) 2814 - }() 2815 - } 2816 - }, 2817 - }, { 2818 - Name: "QuoteRuneToASCII", 2819 - Params: []kind{intKind}, 2820 - Result: stringKind, 2821 - Func: func(c *CallCtxt) { 2822 - r := c.Rune(0) 2823 - if c.Do() { 2824 - c.Ret = func() interface{} { 2825 - return strconv.QuoteRuneToASCII(r) 2826 - }() 2827 - } 2828 - }, 2829 - }, { 2830 - Name: "QuoteRuneToGraphic", 2831 - Params: []kind{intKind}, 2832 - Result: stringKind, 2833 - Func: func(c *CallCtxt) { 2834 - r := c.Rune(0) 2835 - if c.Do() { 2836 - c.Ret = func() interface{} { 2837 - return strconv.QuoteRuneToGraphic(r) 2838 - }() 2839 - } 2840 - }, 2841 - }, { 2842 - Name: "IsPrint", 2843 - Params: []kind{intKind}, 2844 - Result: boolKind, 2845 - Func: func(c *CallCtxt) { 2846 - r := c.Rune(0) 2847 - if c.Do() { 2848 - c.Ret = func() interface{} { 2849 - return strconv.IsPrint(r) 2850 - }() 2851 - } 2852 - }, 2853 - }, { 2854 - Name: "IsGraphic", 2855 - Params: []kind{intKind}, 2856 - Result: boolKind, 2857 - Func: func(c *CallCtxt) { 2858 - r := c.Rune(0) 2859 - if c.Do() { 2860 - c.Ret = func() interface{} { 2861 - return strconv.IsGraphic(r) 2862 - }() 2863 - } 2864 - }, 2865 - }}, 2866 - }, 2867 - "strings": { 2868 - Native: []*Builtin{{ 2869 - Name: "ByteAt", 2870 - Params: []kind{bytesKind | stringKind, intKind}, 2871 - Result: intKind, 2872 - Func: func(c *CallCtxt) { 2873 - b, i := c.Bytes(0), c.Int(1) 2874 - if c.Do() { 2875 - c.Ret, c.Err = func() (interface{}, error) { 2876 - if i < 0 || i >= len(b) { 2877 - return 0, fmt.Errorf("index out of range") 2878 - } 2879 - return b[i], nil 2880 - }() 2881 - } 2882 - }, 2883 - }, { 2884 - Name: "ByteSlice", 2885 - Params: []kind{bytesKind | stringKind, intKind, intKind}, 2886 - Result: bytesKind | stringKind, 2887 - Func: func(c *CallCtxt) { 2888 - b, start, end := c.Bytes(0), c.Int(1), c.Int(2) 2889 - if c.Do() { 2890 - c.Ret, c.Err = func() (interface{}, error) { 2891 - if start < 0 || start > end || end > len(b) { 2892 - return nil, fmt.Errorf("index out of range") 2893 - } 2894 - return b[start:end], nil 2895 - }() 2896 - } 2897 - }, 2898 - }, { 2899 - Name: "Runes", 2900 - Params: []kind{stringKind}, 2901 - Result: listKind, 2902 - Func: func(c *CallCtxt) { 2903 - s := c.String(0) 2904 - if c.Do() { 2905 - c.Ret = func() interface{} { 2906 - return []rune(s) 2907 - }() 2908 - } 2909 - }, 2910 - }, { 2911 - Name: "MinRunes", 2912 - Params: []kind{stringKind, intKind}, 2913 - Result: boolKind, 2914 - Func: func(c *CallCtxt) { 2915 - s, min := c.String(0), c.Int(1) 2916 - if c.Do() { 2917 - c.Ret = func() interface{} { 2918 - 2919 - return len([]rune(s)) >= min 2920 - }() 2921 - } 2922 - }, 2923 - }, { 2924 - Name: "MaxRunes", 2925 - Params: []kind{stringKind, intKind}, 2926 - Result: boolKind, 2927 - Func: func(c *CallCtxt) { 2928 - s, max := c.String(0), c.Int(1) 2929 - if c.Do() { 2930 - c.Ret = func() interface{} { 2931 - 2932 - return len([]rune(s)) <= max 2933 - }() 2934 - } 2935 - }, 2936 - }, { 2937 - Name: "ToTitle", 2938 - Params: []kind{stringKind}, 2939 - Result: stringKind, 2940 - Func: func(c *CallCtxt) { 2941 - s := c.String(0) 2942 - if c.Do() { 2943 - c.Ret = func() interface{} { 2944 - 2945 - prev := ' ' 2946 - return strings.Map( 2947 - func(r rune) rune { 2948 - if unicode.IsSpace(prev) { 2949 - prev = r 2950 - return unicode.ToTitle(r) 2951 - } 2952 - prev = r 2953 - return r 2954 - }, 2955 - s) 2956 - }() 2957 - } 2958 - }, 2959 - }, { 2960 - Name: "ToCamel", 2961 - Params: []kind{stringKind}, 2962 - Result: stringKind, 2963 - Func: func(c *CallCtxt) { 2964 - s := c.String(0) 2965 - if c.Do() { 2966 - c.Ret = func() interface{} { 2967 - 2968 - prev := ' ' 2969 - return strings.Map( 2970 - func(r rune) rune { 2971 - if unicode.IsSpace(prev) { 2972 - prev = r 2973 - return unicode.ToLower(r) 2974 - } 2975 - prev = r 2976 - return r 2977 - }, 2978 - s) 2979 - }() 2980 - } 2981 - }, 2982 - }, { 2983 - Name: "SliceRunes", 2984 - Params: []kind{stringKind, intKind, intKind}, 2985 - Result: stringKind, 2986 - Func: func(c *CallCtxt) { 2987 - s, start, end := c.String(0), c.Int(1), c.Int(2) 2988 - if c.Do() { 2989 - c.Ret, c.Err = func() (interface{}, error) { 2990 - runes := []rune(s) 2991 - if start < 0 || start > end || end > len(runes) { 2992 - return "", fmt.Errorf("index out of range") 2993 - } 2994 - return string(runes[start:end]), nil 2995 - }() 2996 - } 2997 - }, 2998 - }, { 2999 - Name: "Compare", 3000 - Params: []kind{stringKind, stringKind}, 3001 - Result: intKind, 3002 - Func: func(c *CallCtxt) { 3003 - a, b := c.String(0), c.String(1) 3004 - if c.Do() { 3005 - c.Ret = func() interface{} { 3006 - return strings.Compare(a, b) 3007 - }() 3008 - } 3009 - }, 3010 - }, { 3011 - Name: "Count", 3012 - Params: []kind{stringKind, stringKind}, 3013 - Result: intKind, 3014 - Func: func(c *CallCtxt) { 3015 - s, substr := c.String(0), c.String(1) 3016 - if c.Do() { 3017 - c.Ret = func() interface{} { 3018 - return strings.Count(s, substr) 3019 - }() 3020 - } 3021 - }, 3022 - }, { 3023 - Name: "Contains", 3024 - Params: []kind{stringKind, stringKind}, 3025 - Result: boolKind, 3026 - Func: func(c *CallCtxt) { 3027 - s, substr := c.String(0), c.String(1) 3028 - if c.Do() { 3029 - c.Ret = func() interface{} { 3030 - return strings.Contains(s, substr) 3031 - }() 3032 - } 3033 - }, 3034 - }, { 3035 - Name: "ContainsAny", 3036 - Params: []kind{stringKind, stringKind}, 3037 - Result: boolKind, 3038 - Func: func(c *CallCtxt) { 3039 - s, chars := c.String(0), c.String(1) 3040 - if c.Do() { 3041 - c.Ret = func() interface{} { 3042 - return strings.ContainsAny(s, chars) 3043 - }() 3044 - } 3045 - }, 3046 - }, { 3047 - Name: "LastIndex", 3048 - Params: []kind{stringKind, stringKind}, 3049 - Result: intKind, 3050 - Func: func(c *CallCtxt) { 3051 - s, substr := c.String(0), c.String(1) 3052 - if c.Do() { 3053 - c.Ret = func() interface{} { 3054 - return strings.LastIndex(s, substr) 3055 - }() 3056 - } 3057 - }, 3058 - }, { 3059 - Name: "IndexAny", 3060 - Params: []kind{stringKind, stringKind}, 3061 - Result: intKind, 3062 - Func: func(c *CallCtxt) { 3063 - s, chars := c.String(0), c.String(1) 3064 - if c.Do() { 3065 - c.Ret = func() interface{} { 3066 - return strings.IndexAny(s, chars) 3067 - }() 3068 - } 3069 - }, 3070 - }, { 3071 - Name: "LastIndexAny", 3072 - Params: []kind{stringKind, stringKind}, 3073 - Result: intKind, 3074 - Func: func(c *CallCtxt) { 3075 - s, chars := c.String(0), c.String(1) 3076 - if c.Do() { 3077 - c.Ret = func() interface{} { 3078 - return strings.LastIndexAny(s, chars) 3079 - }() 3080 - } 3081 - }, 3082 - }, { 3083 - Name: "SplitN", 3084 - Params: []kind{stringKind, stringKind, intKind}, 3085 - Result: listKind, 3086 - Func: func(c *CallCtxt) { 3087 - s, sep, n := c.String(0), c.String(1), c.Int(2) 3088 - if c.Do() { 3089 - c.Ret = func() interface{} { 3090 - return strings.SplitN(s, sep, n) 3091 - }() 3092 - } 3093 - }, 3094 - }, { 3095 - Name: "SplitAfterN", 3096 - Params: []kind{stringKind, stringKind, intKind}, 3097 - Result: listKind, 3098 - Func: func(c *CallCtxt) { 3099 - s, sep, n := c.String(0), c.String(1), c.Int(2) 3100 - if c.Do() { 3101 - c.Ret = func() interface{} { 3102 - return strings.SplitAfterN(s, sep, n) 3103 - }() 3104 - } 3105 - }, 3106 - }, { 3107 - Name: "Split", 3108 - Params: []kind{stringKind, stringKind}, 3109 - Result: listKind, 3110 - Func: func(c *CallCtxt) { 3111 - s, sep := c.String(0), c.String(1) 3112 - if c.Do() { 3113 - c.Ret = func() interface{} { 3114 - return strings.Split(s, sep) 3115 - }() 3116 - } 3117 - }, 3118 - }, { 3119 - Name: "SplitAfter", 3120 - Params: []kind{stringKind, stringKind}, 3121 - Result: listKind, 3122 - Func: func(c *CallCtxt) { 3123 - s, sep := c.String(0), c.String(1) 3124 - if c.Do() { 3125 - c.Ret = func() interface{} { 3126 - return strings.SplitAfter(s, sep) 3127 - }() 3128 - } 3129 - }, 3130 - }, { 3131 - Name: "Fields", 3132 - Params: []kind{stringKind}, 3133 - Result: listKind, 3134 - Func: func(c *CallCtxt) { 3135 - s := c.String(0) 3136 - if c.Do() { 3137 - c.Ret = func() interface{} { 3138 - return strings.Fields(s) 3139 - }() 3140 - } 3141 - }, 3142 - }, { 3143 - Name: "Join", 3144 - Params: []kind{listKind, stringKind}, 3145 - Result: stringKind, 3146 - Func: func(c *CallCtxt) { 3147 - elems, sep := c.StringList(0), c.String(1) 3148 - if c.Do() { 3149 - c.Ret = func() interface{} { 3150 - return strings.Join(elems, sep) 3151 - }() 3152 - } 3153 - }, 3154 - }, { 3155 - Name: "HasPrefix", 3156 - Params: []kind{stringKind, stringKind}, 3157 - Result: boolKind, 3158 - Func: func(c *CallCtxt) { 3159 - s, prefix := c.String(0), c.String(1) 3160 - if c.Do() { 3161 - c.Ret = func() interface{} { 3162 - return strings.HasPrefix(s, prefix) 3163 - }() 3164 - } 3165 - }, 3166 - }, { 3167 - Name: "HasSuffix", 3168 - Params: []kind{stringKind, stringKind}, 3169 - Result: boolKind, 3170 - Func: func(c *CallCtxt) { 3171 - s, suffix := c.String(0), c.String(1) 3172 - if c.Do() { 3173 - c.Ret = func() interface{} { 3174 - return strings.HasSuffix(s, suffix) 3175 - }() 3176 - } 3177 - }, 3178 - }, { 3179 - Name: "Repeat", 3180 - Params: []kind{stringKind, intKind}, 3181 - Result: stringKind, 3182 - Func: func(c *CallCtxt) { 3183 - s, count := c.String(0), c.Int(1) 3184 - if c.Do() { 3185 - c.Ret = func() interface{} { 3186 - return strings.Repeat(s, count) 3187 - }() 3188 - } 3189 - }, 3190 - }, { 3191 - Name: "ToUpper", 3192 - Params: []kind{stringKind}, 3193 - Result: stringKind, 3194 - Func: func(c *CallCtxt) { 3195 - s := c.String(0) 3196 - if c.Do() { 3197 - c.Ret = func() interface{} { 3198 - return strings.ToUpper(s) 3199 - }() 3200 - } 3201 - }, 3202 - }, { 3203 - Name: "ToLower", 3204 - Params: []kind{stringKind}, 3205 - Result: stringKind, 3206 - Func: func(c *CallCtxt) { 3207 - s := c.String(0) 3208 - if c.Do() { 3209 - c.Ret = func() interface{} { 3210 - return strings.ToLower(s) 3211 - }() 3212 - } 3213 - }, 3214 - }, { 3215 - Name: "Trim", 3216 - Params: []kind{stringKind, stringKind}, 3217 - Result: stringKind, 3218 - Func: func(c *CallCtxt) { 3219 - s, cutset := c.String(0), c.String(1) 3220 - if c.Do() { 3221 - c.Ret = func() interface{} { 3222 - return strings.Trim(s, cutset) 3223 - }() 3224 - } 3225 - }, 3226 - }, { 3227 - Name: "TrimLeft", 3228 - Params: []kind{stringKind, stringKind}, 3229 - Result: stringKind, 3230 - Func: func(c *CallCtxt) { 3231 - s, cutset := c.String(0), c.String(1) 3232 - if c.Do() { 3233 - c.Ret = func() interface{} { 3234 - return strings.TrimLeft(s, cutset) 3235 - }() 3236 - } 3237 - }, 3238 - }, { 3239 - Name: "TrimRight", 3240 - Params: []kind{stringKind, stringKind}, 3241 - Result: stringKind, 3242 - Func: func(c *CallCtxt) { 3243 - s, cutset := c.String(0), c.String(1) 3244 - if c.Do() { 3245 - c.Ret = func() interface{} { 3246 - return strings.TrimRight(s, cutset) 3247 - }() 3248 - } 3249 - }, 3250 - }, { 3251 - Name: "TrimSpace", 3252 - Params: []kind{stringKind}, 3253 - Result: stringKind, 3254 - Func: func(c *CallCtxt) { 3255 - s := c.String(0) 3256 - if c.Do() { 3257 - c.Ret = func() interface{} { 3258 - return strings.TrimSpace(s) 3259 - }() 3260 - } 3261 - }, 3262 - }, { 3263 - Name: "TrimPrefix", 3264 - Params: []kind{stringKind, stringKind}, 3265 - Result: stringKind, 3266 - Func: func(c *CallCtxt) { 3267 - s, prefix := c.String(0), c.String(1) 3268 - if c.Do() { 3269 - c.Ret = func() interface{} { 3270 - return strings.TrimPrefix(s, prefix) 3271 - }() 3272 - } 3273 - }, 3274 - }, { 3275 - Name: "TrimSuffix", 3276 - Params: []kind{stringKind, stringKind}, 3277 - Result: stringKind, 3278 - Func: func(c *CallCtxt) { 3279 - s, suffix := c.String(0), c.String(1) 3280 - if c.Do() { 3281 - c.Ret = func() interface{} { 3282 - return strings.TrimSuffix(s, suffix) 3283 - }() 3284 - } 3285 - }, 3286 - }, { 3287 - Name: "Replace", 3288 - Params: []kind{stringKind, stringKind, stringKind, intKind}, 3289 - Result: stringKind, 3290 - Func: func(c *CallCtxt) { 3291 - s, old, new, n := c.String(0), c.String(1), c.String(2), c.Int(3) 3292 - if c.Do() { 3293 - c.Ret = func() interface{} { 3294 - return strings.Replace(s, old, new, n) 3295 - }() 3296 - } 3297 - }, 3298 - }, { 3299 - Name: "Index", 3300 - Params: []kind{stringKind, stringKind}, 3301 - Result: intKind, 3302 - Func: func(c *CallCtxt) { 3303 - s, substr := c.String(0), c.String(1) 3304 - if c.Do() { 3305 - c.Ret = func() interface{} { 3306 - return strings.Index(s, substr) 3307 - }() 3308 - } 3309 - }, 3310 - }}, 3311 - }, 3312 - "struct": { 3313 - Native: []*Builtin{{ 3314 - Name: "MinFields", 3315 - Params: []kind{structKind, intKind}, 3316 - Result: boolKind, 3317 - Func: func(c *CallCtxt) { 3318 - object, n := c.Struct(0), c.Int(1) 3319 - if c.Do() { 3320 - c.Ret, c.Err = func() (interface{}, error) { 3321 - iter := object.Fields(Hidden(false), Optional(false)) 3322 - count := 0 3323 - for iter.Next() { 3324 - count++ 3325 - } 3326 - return count >= n, nil 3327 - }() 3328 - } 3329 - }, 3330 - }, { 3331 - Name: "MaxFields", 3332 - Params: []kind{structKind, intKind}, 3333 - Result: boolKind, 3334 - Func: func(c *CallCtxt) { 3335 - object, n := c.Struct(0), c.Int(1) 3336 - if c.Do() { 3337 - c.Ret, c.Err = func() (interface{}, error) { 3338 - iter := object.Fields(Hidden(false), Optional(false)) 3339 - count := 0 3340 - for iter.Next() { 3341 - count++ 3342 - } 3343 - return count <= n, nil 3344 - }() 3345 - } 3346 - }, 3347 - }}, 3348 - }, 3349 - "text/tabwriter": { 3350 - Native: []*Builtin{{ 3351 - Name: "Write", 3352 - Params: []kind{topKind}, 3353 - Result: stringKind, 3354 - Func: func(c *CallCtxt) { 3355 - data := c.Value(0) 3356 - if c.Do() { 3357 - c.Ret, c.Err = func() (interface{}, error) { 3358 - buf := &bytes.Buffer{} 3359 - tw := tabwriter.NewWriter(buf, 0, 4, 1, ' ', 0) 3360 - 3361 - write := func(v Value) error { 3362 - b, err := v.Bytes() 3363 - if err != nil { 3364 - return err 3365 - } 3366 - _, err = tw.Write(b) 3367 - if err != nil { 3368 - return err 3369 - } 3370 - return nil 3371 - } 3372 - 3373 - switch data.Kind() { 3374 - case BytesKind, StringKind: 3375 - if err := write(data); err != nil { 3376 - return "", err 3377 - } 3378 - case ListKind: 3379 - for i, _ := data.List(); i.Next(); { 3380 - if err := write(i.Value()); err != nil { 3381 - return "", err 3382 - } 3383 - _, _ = tw.Write([]byte{'\n'}) 3384 - } 3385 - default: 3386 - return "", fmt.Errorf("tabwriter.Write: unsupported type %v", data.Kind()) 3387 - } 3388 - 3389 - err := tw.Flush() 3390 - return buf.String(), err 3391 - }() 3392 - } 3393 - }, 3394 - }}, 3395 - }, 3396 - "text/template": { 3397 - Native: []*Builtin{{ 3398 - Name: "Execute", 3399 - Params: []kind{stringKind, topKind}, 3400 - Result: stringKind, 3401 - Func: func(c *CallCtxt) { 3402 - templ, data := c.String(0), c.Value(1) 3403 - if c.Do() { 3404 - c.Ret, c.Err = func() (interface{}, error) { 3405 - t, err := template.New("").Parse(templ) 3406 - if err != nil { 3407 - return "", err 3408 - } 3409 - var x interface{} 3410 - if err := data.Decode(&x); err != nil { 3411 - return "", err 3412 - } 3413 - buf := &bytes.Buffer{} 3414 - if err := t.Execute(buf, x); err != nil { 3415 - return "", err 3416 - } 3417 - return buf.String(), nil 3418 - }() 3419 - } 3420 - }, 3421 - }, { 3422 - Name: "HTMLEscape", 3423 - Params: []kind{stringKind}, 3424 - Result: stringKind, 3425 - Func: func(c *CallCtxt) { 3426 - s := c.String(0) 3427 - if c.Do() { 3428 - c.Ret = func() interface{} { 3429 - return template.HTMLEscapeString(s) 3430 - }() 3431 - } 3432 - }, 3433 - }, { 3434 - Name: "JSEscape", 3435 - Params: []kind{stringKind}, 3436 - Result: stringKind, 3437 - Func: func(c *CallCtxt) { 3438 - s := c.String(0) 3439 - if c.Do() { 3440 - c.Ret = func() interface{} { 3441 - return template.JSEscapeString(s) 3442 - }() 3443 - } 3444 - }, 3445 - }}, 3446 - }, 3447 - "time": { 3448 - Native: []*Builtin{{ 3449 - Name: "Nanosecond", 3450 - Const: "1", 3451 - }, { 3452 - Name: "Microsecond", 3453 - Const: "1000", 3454 - }, { 3455 - Name: "Millisecond", 3456 - Const: "1000000", 3457 - }, { 3458 - Name: "Second", 3459 - Const: "1000000000", 3460 - }, { 3461 - Name: "Minute", 3462 - Const: "60000000000", 3463 - }, { 3464 - Name: "Hour", 3465 - Const: "3600000000000", 3466 - }, { 3467 - Name: "Duration", 3468 - Params: []kind{stringKind}, 3469 - Result: boolKind, 3470 - Func: func(c *CallCtxt) { 3471 - s := c.String(0) 3472 - if c.Do() { 3473 - c.Ret, c.Err = func() (interface{}, error) { 3474 - if _, err := time.ParseDuration(s); err != nil { 3475 - return false, err 3476 - } 3477 - return true, nil 3478 - }() 3479 - } 3480 - }, 3481 - }, { 3482 - Name: "ParseDuration", 3483 - Params: []kind{stringKind}, 3484 - Result: intKind, 3485 - Func: func(c *CallCtxt) { 3486 - s := c.String(0) 3487 - if c.Do() { 3488 - c.Ret, c.Err = func() (interface{}, error) { 3489 - d, err := time.ParseDuration(s) 3490 - if err != nil { 3491 - return 0, err 3492 - } 3493 - return int64(d), nil 3494 - }() 3495 - } 3496 - }, 3497 - }, { 3498 - Name: "ANSIC", 3499 - Const: "\"Mon Jan _2 15:04:05 2006\"", 3500 - }, { 3501 - Name: "UnixDate", 3502 - Const: "\"Mon Jan _2 15:04:05 MST 2006\"", 3503 - }, { 3504 - Name: "RubyDate", 3505 - Const: "\"Mon Jan 02 15:04:05 -0700 2006\"", 3506 - }, { 3507 - Name: "RFC822", 3508 - Const: "\"02 Jan 06 15:04 MST\"", 3509 - }, { 3510 - Name: "RFC822Z", 3511 - Const: "\"02 Jan 06 15:04 -0700\"", 3512 - }, { 3513 - Name: "RFC850", 3514 - Const: "\"Monday, 02-Jan-06 15:04:05 MST\"", 3515 - }, { 3516 - Name: "RFC1123", 3517 - Const: "\"Mon, 02 Jan 2006 15:04:05 MST\"", 3518 - }, { 3519 - Name: "RFC1123Z", 3520 - Const: "\"Mon, 02 Jan 2006 15:04:05 -0700\"", 3521 - }, { 3522 - Name: "RFC3339", 3523 - Const: "\"2006-01-02T15:04:05Z07:00\"", 3524 - }, { 3525 - Name: "RFC3339Nano", 3526 - Const: "\"2006-01-02T15:04:05.999999999Z07:00\"", 3527 - }, { 3528 - Name: "RFC3339Date", 3529 - Const: "\"2006-01-02\"", 3530 - }, { 3531 - Name: "Kitchen", 3532 - Const: "\"3:04PM\"", 3533 - }, { 3534 - Name: "Kitchen24", 3535 - Const: "\"15:04\"", 3536 - }, { 3537 - Name: "January", 3538 - Const: "1", 3539 - }, { 3540 - Name: "February", 3541 - Const: "2", 3542 - }, { 3543 - Name: "March", 3544 - Const: "3", 3545 - }, { 3546 - Name: "April", 3547 - Const: "4", 3548 - }, { 3549 - Name: "May", 3550 - Const: "5", 3551 - }, { 3552 - Name: "June", 3553 - Const: "6", 3554 - }, { 3555 - Name: "July", 3556 - Const: "7", 3557 - }, { 3558 - Name: "August", 3559 - Const: "8", 3560 - }, { 3561 - Name: "September", 3562 - Const: "9", 3563 - }, { 3564 - Name: "October", 3565 - Const: "10", 3566 - }, { 3567 - Name: "November", 3568 - Const: "11", 3569 - }, { 3570 - Name: "December", 3571 - Const: "12", 3572 - }, { 3573 - Name: "Sunday", 3574 - Const: "0", 3575 - }, { 3576 - Name: "Monday", 3577 - Const: "1", 3578 - }, { 3579 - Name: "Tuesday", 3580 - Const: "2", 3581 - }, { 3582 - Name: "Wednesday", 3583 - Const: "3", 3584 - }, { 3585 - Name: "Thursday", 3586 - Const: "4", 3587 - }, { 3588 - Name: "Friday", 3589 - Const: "5", 3590 - }, { 3591 - Name: "Saturday", 3592 - Const: "6", 3593 - }, { 3594 - Name: "Time", 3595 - Params: []kind{stringKind}, 3596 - Result: boolKind, 3597 - Func: func(c *CallCtxt) { 3598 - s := c.String(0) 3599 - if c.Do() { 3600 - c.Ret, c.Err = func() (interface{}, error) { 3601 - return timeFormat(s, time.RFC3339Nano) 3602 - }() 3603 - } 3604 - }, 3605 - }, { 3606 - Name: "Format", 3607 - Params: []kind{stringKind, stringKind}, 3608 - Result: boolKind, 3609 - Func: func(c *CallCtxt) { 3610 - value, layout := c.String(0), c.String(1) 3611 - if c.Do() { 3612 - c.Ret, c.Err = func() (interface{}, error) { 3613 - return timeFormat(value, layout) 3614 - }() 3615 - } 3616 - }, 3617 - }, { 3618 - Name: "Parse", 3619 - Params: []kind{stringKind, stringKind}, 3620 - Result: stringKind, 3621 - Func: func(c *CallCtxt) { 3622 - layout, value := c.String(0), c.String(1) 3623 - if c.Do() { 3624 - c.Ret, c.Err = func() (interface{}, error) { 3625 - t, err := time.Parse(layout, value) 3626 - if err != nil { 3627 - return "", err 3628 - } 3629 - return t.UTC().Format(time.RFC3339Nano), nil 3630 - }() 3631 - } 3632 - }, 3633 - }, { 3634 - Name: "Unix", 3635 - Params: []kind{intKind, intKind}, 3636 - Result: stringKind, 3637 - Func: func(c *CallCtxt) { 3638 - sec, nsec := c.Int64(0), c.Int64(1) 3639 - if c.Do() { 3640 - c.Ret = func() interface{} { 3641 - t := time.Unix(sec, nsec) 3642 - return t.UTC().Format(time.RFC3339Nano) 3643 - }() 3644 - } 3645 - }, 3646 - }}, 3647 - }, 3648 - "tool": { 3649 - Native: []*Builtin{}, 3650 - CUE: `{ 3651 - Command: { 3652 - $usage?: string 3653 - $short?: string 3654 - $long?: string 3655 - Tasks 3656 - } 3657 - Tasks: Task | { 3658 - [name=string]: Tasks 3659 - } 3660 - Task: { 3661 - $type: "tool.Task" 3662 - $id: =~"\\." 3663 - $after?: Task | [...Task] 3664 - } 3665 - Name: =~"^\\PL([-](\\PL|\\PN))*$" 3666 - }`, 3667 - }, 3668 - "tool/cli": { 3669 - Native: []*Builtin{}, 3670 - CUE: `{ 3671 - Print: { 3672 - $id: *"tool/cli.Print" | "print" 3673 - text: string 3674 - } 3675 - }`, 3676 - }, 3677 - "tool/exec": { 3678 - Native: []*Builtin{}, 3679 - CUE: `{ 3680 - Run: { 3681 - $id: *"tool/exec.Run" | "exec" 3682 - cmd: string | [string, ...string] 3683 - env: { 3684 - [string]: string | [...=~"="] 3685 - } 3686 - stdout: *null | string | bytes 3687 - stderr: *null | string | bytes 3688 - stdin: *null | string | bytes 3689 - success: bool 3690 - } 3691 - }`, 3692 - }, 3693 - "tool/file": { 3694 - Native: []*Builtin{}, 3695 - CUE: `{ 3696 - Read: { 3697 - $id: "tool/file.Read" 3698 - filename: !="" 3699 - contents: *bytes | string 3700 - } 3701 - Create: { 3702 - $id: "tool/file.Create" 3703 - filename: !="" 3704 - contents: bytes | string 3705 - permissions: int | *420 3706 - } 3707 - Append: { 3708 - $id: "tool/file.Append" 3709 - filename: !="" 3710 - contents: bytes | string 3711 - permissions: int | *420 3712 - } 3713 - Glob: { 3714 - $id: "tool/file.Glob" 3715 - glob: !="" 3716 - files: [...string] 3717 - } 3718 - }`, 3719 - }, 3720 - "tool/http": { 3721 - Native: []*Builtin{}, 3722 - CUE: `{ 3723 - Get: Do & { 3724 - method: "GET" 3725 - } 3726 - Do: { 3727 - $id: *"tool/http.Do" | "http" 3728 - method: string 3729 - response: { 3730 - body: *bytes | string 3731 - header: { 3732 - [string]: string | [...string] 3733 - } 3734 - trailer: { 3735 - [string]: string | [...string] 3736 - } 3737 - status: string 3738 - statusCode: int 3739 - } 3740 - url: string 3741 - request: { 3742 - body: *bytes | string 3743 - header: { 3744 - [string]: string | [...string] 3745 - } 3746 - trailer: { 3747 - [string]: string | [...string] 3748 - } 3749 - } 3750 - } 3751 - Post: Do & { 3752 - method: "POST" 3753 - } 3754 - Put: Do & { 3755 - method: "PUT" 3756 - } 3757 - Delete: Do & { 3758 - method: "DELETE" 3759 - } 3760 - }`, 3761 - }, 3762 - "tool/os": { 3763 - Native: []*Builtin{}, 3764 - CUE: `{ 3765 - Name: !="" & !~"^[$]" 3766 - Value: bool | number | *string | null 3767 - Setenv: { 3768 - $id: "tool/os.Setenv" 3769 - {[Name]: Value} 3770 - } 3771 - Getenv: { 3772 - $id: "tool/os.Getenv" 3773 - {[Name]: Value} 3774 - } 3775 - Environ: { 3776 - $id: "tool/os.Environ" 3777 - {[Name]: Value} 3778 - } 3779 - Clearenv: { 3780 - $id: "tool/os.Clearenv" 3781 - } 3782 - }`, 3783 - }, 3784 - }
+8 -1
cue/load/loader.go
··· 25 25 "strings" 26 26 "unicode" 27 27 28 + "golang.org/x/xerrors" 29 + 28 30 "cuelang.org/go/cue/build" 29 31 "cuelang.org/go/cue/errors" 30 32 "cuelang.org/go/cue/token" 31 33 "cuelang.org/go/internal/encoding" 32 34 "cuelang.org/go/internal/filetypes" 33 - "golang.org/x/xerrors" 35 + 36 + // Trigger the unconditional loading of all core builtin packages if load 37 + // is used. This was deemed the simplest way to avoid having to import 38 + // this line explicitly, and thus breaking existing code, for the majority 39 + // of cases, while not introducing an import cycle. 40 + _ "cuelang.org/go/pkg" 34 41 ) 35 42 36 43 // Instances returns the instances named by the command line arguments 'args'.
+20 -12
cue/types.go
··· 623 623 624 624 // MakeValue converts an adt.Value and given OpContext to a Value. The context 625 625 // must be directly or indirectly obtained from the NewRuntime defined in this 626 - // package and it will panic if this is not the case. This is for internal use 627 - // only. 626 + // package and it will panic if this is not the case. 627 + // 628 + // For internal use only. 628 629 func MakeValue(ctx *adt.OpContext, v adt.Value) Value { 629 630 runtime := ctx.Impl().(*runtime.Runtime) 630 631 index := runtime.Data.(*index) ··· 957 958 } 958 959 } 959 960 960 - if d := internal.Imports(f); len(d) == 0 { 961 - if len(f.Decls) == 1 { 962 - if e, ok := f.Decls[0].(*ast.EmbedDecl); ok { 963 - return e.Expr 964 - } 965 - } 966 - return &ast.StructLit{ 967 - Elts: f.Decls, 961 + outer: 962 + for _, d := range f.Decls { 963 + switch d.(type) { 964 + case *ast.Package, *ast.ImportDecl: 965 + return f 966 + case *ast.CommentGroup, *ast.Attribute: 967 + default: 968 + break outer 968 969 } 969 970 } 970 971 971 - return f 972 + if len(f.Decls) == 1 { 973 + if e, ok := f.Decls[0].(*ast.EmbedDecl); ok { 974 + return e.Expr 975 + } 976 + } 977 + return &ast.StructLit{ 978 + Elts: f.Decls, 979 + } 972 980 } 973 981 974 982 // Decode initializes x with Value v. If x is a struct, it will validate the ··· 1700 1708 case state.Flag('#'): 1701 1709 _, _ = io.WriteString(state, ctx.str(v.v)) 1702 1710 case state.Flag('+'): 1703 - _, _ = io.WriteString(state, debugStr(ctx, v.v)) 1711 + _, _ = io.WriteString(state, ctx.opCtx.Str(v.v)) 1704 1712 default: 1705 1713 n, _ := export.Raw.Expr(v.idx.Runtime, v.v) 1706 1714 b, _ := format.Node(n)
+1
encoding/gocode/generator_test.go
··· 28 28 "cuelang.org/go/cue" 29 29 "cuelang.org/go/cue/errors" 30 30 "cuelang.org/go/cue/load" 31 + _ "cuelang.org/go/pkg" 31 32 ) 32 33 33 34 var update = flag.Bool("update", false, "update test files")
+1
encoding/gocode/templates.go
··· 28 28 29 29 "cuelang.org/go/cue" 30 30 "cuelang.org/go/encoding/gocode/gocodec" 31 + _ "cuelang.org/go/pkg" 31 32 ) 32 33 33 34 `))
+1
encoding/gocode/testdata/pkg1/cue_gen.go
··· 7 7 8 8 "cuelang.org/go/cue" 9 9 "cuelang.org/go/encoding/gocode/gocodec" 10 + _ "cuelang.org/go/pkg" 10 11 ) 11 12 12 13 var cuegenvalMyStruct = cuegenMake("MyStruct", &MyStruct{})
+1
encoding/gocode/testdata/pkg2/cue_gen.go
··· 7 7 8 8 "cuelang.org/go/cue" 9 9 "cuelang.org/go/encoding/gocode/gocodec" 10 + _ "cuelang.org/go/pkg" 10 11 ) 11 12 12 13 var cuegenvalImportMe = cuegenMake("ImportMe", &ImportMe{})
+5 -3
encoding/jsonschema/decode_test.go
··· 24 24 "strings" 25 25 "testing" 26 26 27 + "github.com/google/go-cmp/cmp" 28 + "github.com/rogpeppe/go-internal/txtar" 29 + "github.com/stretchr/testify/assert" 30 + 27 31 "cuelang.org/go/cue" 28 32 "cuelang.org/go/cue/ast" 29 33 "cuelang.org/go/cue/errors" ··· 31 35 "cuelang.org/go/cue/token" 32 36 "cuelang.org/go/encoding/json" 33 37 "cuelang.org/go/encoding/yaml" 34 - "github.com/google/go-cmp/cmp" 35 - "github.com/stretchr/testify/assert" 36 - "golang.org/x/tools/txtar" 38 + _ "cuelang.org/go/pkg" 37 39 ) 38 40 39 41 var update = flag.Bool("update", false, "update the test files")
+1 -1
encoding/openapi/openapi_test.go
··· 160 160 t.Fatal(err) 161 161 } 162 162 163 - if d := diff.Diff(out.String(), string(b)); d != "" { 163 + if d := diff.Diff(string(b), out.String()); d != "" { 164 164 t.Errorf("files differ:\n%v", d) 165 165 } 166 166 })
+49
internal/builtin/registry.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package builtin 16 + 17 + import ( 18 + "sort" 19 + 20 + "cuelang.org/go/cue" 21 + "cuelang.org/go/internal/core/adt" 22 + ) 23 + 24 + type PackageFunc func(ctx *adt.OpContext) (*adt.Vertex, error) 25 + 26 + // Register registers a builtin, the value of which will be built 27 + // on first use. All builtins must be registered before first use of a runtime. 28 + // This restriction may be eliminated in the future. 29 + func Register(importPath string, f PackageFunc) { 30 + builtins[importPath] = f 31 + // TODO: remove at some point. 32 + cue.AddBuiltinPackage(importPath, f) 33 + } 34 + 35 + var builtins = map[string]PackageFunc{} 36 + 37 + func ImportPaths() (a []string) { 38 + for s := range builtins { 39 + a = append(a, s) 40 + } 41 + sort.Strings(a) 42 + return a 43 + } 44 + 45 + // Get return the builder for the package with the given path. 46 + // It will panic if the path does not exist. 47 + func Get(path string) PackageFunc { 48 + return builtins[path] 49 + }
+2
internal/core/adt/expr.go
··· 894 894 // Remove the path of the origin for arguments. This results in 895 895 // more sensible error messages: an error should refer to the call 896 896 // site, not the original location of the argument. 897 + // TODO: alternative, explicitly mark the argument number and use 898 + // that in error messages. 897 899 w := *v 898 900 w.Parent = nil 899 901 args = append(args, &w)
+1 -1
internal/core/compile/compile_test.go
··· 17 17 import ( 18 18 "flag" 19 19 "fmt" 20 + "strings" 20 21 "testing" 21 22 22 23 "cuelang.org/go/cue/errors" ··· 25 26 "cuelang.org/go/internal/core/debug" 26 27 "cuelang.org/go/internal/core/runtime" 27 28 "cuelang.org/go/internal/cuetxtar" 28 - "cuelang.org/go/pkg/strings" 29 29 ) 30 30 31 31 var (
+3 -1
internal/core/eval/eval_test.go
··· 20 20 "strings" 21 21 "testing" 22 22 23 + "github.com/rogpeppe/go-internal/txtar" 24 + 23 25 "cuelang.org/go/cue" 24 26 "cuelang.org/go/internal/core/debug" 25 27 "cuelang.org/go/internal/core/eval" 26 28 "cuelang.org/go/internal/core/validate" 27 29 "cuelang.org/go/internal/cuetxtar" 28 - "github.com/rogpeppe/go-internal/txtar" 30 + _ "cuelang.org/go/pkg" 29 31 ) 30 32 31 33 var (
+1
internal/filetypes/types.go
··· 7 7 8 8 "cuelang.org/go/cue" 9 9 "cuelang.org/go/encoding/gocode/gocodec" 10 + _ "cuelang.org/go/pkg" 10 11 ) 11 12 12 13 var cuegenCodec, cuegenInstance = func() (*gocodec.Codec, *cue.Instance) {
+37
pkg/crypto/md5/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package md5 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("crypto/md5", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Size", 22 + Const: "16", 23 + }, { 24 + Name: "BlockSize", 25 + Const: "64", 26 + }, { 27 + Name: "Sum", 28 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 29 + Result: adt.BytesKind | adt.StringKind, 30 + Func: func(c *internal.CallCtxt) { 31 + data := c.Bytes(0) 32 + if c.Do() { 33 + c.Ret = Sum(data) 34 + } 35 + }, 36 + }}, 37 + }
+37
pkg/crypto/sha1/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package sha1 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("crypto/sha1", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Size", 22 + Const: "20", 23 + }, { 24 + Name: "BlockSize", 25 + Const: "64", 26 + }, { 27 + Name: "Sum", 28 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 29 + Result: adt.BytesKind | adt.StringKind, 30 + Func: func(c *internal.CallCtxt) { 31 + data := c.Bytes(0) 32 + if c.Do() { 33 + c.Ret = Sum(data) 34 + } 35 + }, 36 + }}, 37 + }
+50
pkg/crypto/sha256/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package sha256 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("crypto/sha256", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Size", 22 + Const: "32", 23 + }, { 24 + Name: "Size224", 25 + Const: "28", 26 + }, { 27 + Name: "BlockSize", 28 + Const: "64", 29 + }, { 30 + Name: "Sum256", 31 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 32 + Result: adt.BytesKind | adt.StringKind, 33 + Func: func(c *internal.CallCtxt) { 34 + data := c.Bytes(0) 35 + if c.Do() { 36 + c.Ret = Sum256(data) 37 + } 38 + }, 39 + }, { 40 + Name: "Sum224", 41 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 42 + Result: adt.BytesKind | adt.StringKind, 43 + Func: func(c *internal.CallCtxt) { 44 + data := c.Bytes(0) 45 + if c.Do() { 46 + c.Ret = Sum224(data) 47 + } 48 + }, 49 + }}, 50 + }
+76
pkg/crypto/sha512/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package sha512 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("crypto/sha512", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Size", 22 + Const: "64", 23 + }, { 24 + Name: "Size224", 25 + Const: "28", 26 + }, { 27 + Name: "Size256", 28 + Const: "32", 29 + }, { 30 + Name: "Size384", 31 + Const: "48", 32 + }, { 33 + Name: "BlockSize", 34 + Const: "128", 35 + }, { 36 + Name: "Sum512", 37 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 38 + Result: adt.BytesKind | adt.StringKind, 39 + Func: func(c *internal.CallCtxt) { 40 + data := c.Bytes(0) 41 + if c.Do() { 42 + c.Ret = Sum512(data) 43 + } 44 + }, 45 + }, { 46 + Name: "Sum384", 47 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 48 + Result: adt.BytesKind | adt.StringKind, 49 + Func: func(c *internal.CallCtxt) { 50 + data := c.Bytes(0) 51 + if c.Do() { 52 + c.Ret = Sum384(data) 53 + } 54 + }, 55 + }, { 56 + Name: "Sum512_224", 57 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 58 + Result: adt.BytesKind | adt.StringKind, 59 + Func: func(c *internal.CallCtxt) { 60 + data := c.Bytes(0) 61 + if c.Do() { 62 + c.Ret = Sum512_224(data) 63 + } 64 + }, 65 + }, { 66 + Name: "Sum512_256", 67 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 68 + Result: adt.BytesKind | adt.StringKind, 69 + Func: func(c *internal.CallCtxt) { 70 + data := c.Bytes(0) 71 + if c.Do() { 72 + c.Ret = Sum512_256(data) 73 + } 74 + }, 75 + }}, 76 + }
+61
pkg/encoding/base64/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package base64 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("encoding/base64", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "EncodedLen", 22 + Params: []adt.Kind{adt.TopKind, adt.IntKind}, 23 + Result: adt.IntKind, 24 + Func: func(c *internal.CallCtxt) { 25 + encoding, n := c.Value(0), c.Int(1) 26 + if c.Do() { 27 + c.Ret, c.Err = EncodedLen(encoding, n) 28 + } 29 + }, 30 + }, { 31 + Name: "DecodedLen", 32 + Params: []adt.Kind{adt.TopKind, adt.IntKind}, 33 + Result: adt.IntKind, 34 + Func: func(c *internal.CallCtxt) { 35 + encoding, x := c.Value(0), c.Int(1) 36 + if c.Do() { 37 + c.Ret, c.Err = DecodedLen(encoding, x) 38 + } 39 + }, 40 + }, { 41 + Name: "Encode", 42 + Params: []adt.Kind{adt.TopKind, adt.BytesKind | adt.StringKind}, 43 + Result: adt.StringKind, 44 + Func: func(c *internal.CallCtxt) { 45 + encoding, src := c.Value(0), c.Bytes(1) 46 + if c.Do() { 47 + c.Ret, c.Err = Encode(encoding, src) 48 + } 49 + }, 50 + }, { 51 + Name: "Decode", 52 + Params: []adt.Kind{adt.TopKind, adt.StringKind}, 53 + Result: adt.BytesKind | adt.StringKind, 54 + Func: func(c *internal.CallCtxt) { 55 + encoding, s := c.Value(0), c.String(1) 56 + if c.Do() { 57 + c.Ret, c.Err = Decode(encoding, s) 58 + } 59 + }, 60 + }}, 61 + }
+41
pkg/encoding/csv/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package csv 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("encoding/csv", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Encode", 22 + Params: []adt.Kind{adt.TopKind}, 23 + Result: adt.StringKind, 24 + Func: func(c *internal.CallCtxt) { 25 + x := c.Value(0) 26 + if c.Do() { 27 + c.Ret, c.Err = Encode(x) 28 + } 29 + }, 30 + }, { 31 + Name: "Decode", 32 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 33 + Result: adt.ListKind, 34 + Func: func(c *internal.CallCtxt) { 35 + r := c.Reader(0) 36 + if c.Do() { 37 + c.Ret, c.Err = Decode(r) 38 + } 39 + }, 40 + }}, 41 + }
+71
pkg/encoding/hex/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package hex 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("encoding/hex", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "EncodedLen", 22 + Params: []adt.Kind{adt.IntKind}, 23 + Result: adt.IntKind, 24 + Func: func(c *internal.CallCtxt) { 25 + n := c.Int(0) 26 + if c.Do() { 27 + c.Ret = EncodedLen(n) 28 + } 29 + }, 30 + }, { 31 + Name: "DecodedLen", 32 + Params: []adt.Kind{adt.IntKind}, 33 + Result: adt.IntKind, 34 + Func: func(c *internal.CallCtxt) { 35 + x := c.Int(0) 36 + if c.Do() { 37 + c.Ret = DecodedLen(x) 38 + } 39 + }, 40 + }, { 41 + Name: "Decode", 42 + Params: []adt.Kind{adt.StringKind}, 43 + Result: adt.BytesKind | adt.StringKind, 44 + Func: func(c *internal.CallCtxt) { 45 + s := c.String(0) 46 + if c.Do() { 47 + c.Ret, c.Err = Decode(s) 48 + } 49 + }, 50 + }, { 51 + Name: "Dump", 52 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 53 + Result: adt.StringKind, 54 + Func: func(c *internal.CallCtxt) { 55 + data := c.Bytes(0) 56 + if c.Do() { 57 + c.Ret = Dump(data) 58 + } 59 + }, 60 + }, { 61 + Name: "Encode", 62 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 63 + Result: adt.StringKind, 64 + Func: func(c *internal.CallCtxt) { 65 + src := c.Bytes(0) 66 + if c.Do() { 67 + c.Ret = Encode(src) 68 + } 69 + }, 70 + }}, 71 + }
+101
pkg/encoding/json/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package json 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("encoding/json", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Valid", 22 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 23 + Result: adt.BoolKind, 24 + Func: func(c *internal.CallCtxt) { 25 + data := c.Bytes(0) 26 + if c.Do() { 27 + c.Ret = Valid(data) 28 + } 29 + }, 30 + }, { 31 + Name: "Compact", 32 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 33 + Result: adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + src := c.Bytes(0) 36 + if c.Do() { 37 + c.Ret, c.Err = Compact(src) 38 + } 39 + }, 40 + }, { 41 + Name: "Indent", 42 + Params: []adt.Kind{adt.BytesKind | adt.StringKind, adt.StringKind, adt.StringKind}, 43 + Result: adt.StringKind, 44 + Func: func(c *internal.CallCtxt) { 45 + src, prefix, indent := c.Bytes(0), c.String(1), c.String(2) 46 + if c.Do() { 47 + c.Ret, c.Err = Indent(src, prefix, indent) 48 + } 49 + }, 50 + }, { 51 + Name: "HTMLEscape", 52 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 53 + Result: adt.StringKind, 54 + Func: func(c *internal.CallCtxt) { 55 + src := c.Bytes(0) 56 + if c.Do() { 57 + c.Ret = HTMLEscape(src) 58 + } 59 + }, 60 + }, { 61 + Name: "Marshal", 62 + Params: []adt.Kind{adt.TopKind}, 63 + Result: adt.StringKind, 64 + Func: func(c *internal.CallCtxt) { 65 + v := c.Value(0) 66 + if c.Do() { 67 + c.Ret, c.Err = Marshal(v) 68 + } 69 + }, 70 + }, { 71 + Name: "MarshalStream", 72 + Params: []adt.Kind{adt.TopKind}, 73 + Result: adt.StringKind, 74 + Func: func(c *internal.CallCtxt) { 75 + v := c.Value(0) 76 + if c.Do() { 77 + c.Ret, c.Err = MarshalStream(v) 78 + } 79 + }, 80 + }, { 81 + Name: "Unmarshal", 82 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 83 + Result: adt.TopKind, 84 + Func: func(c *internal.CallCtxt) { 85 + b := c.Bytes(0) 86 + if c.Do() { 87 + c.Ret, c.Err = Unmarshal(b) 88 + } 89 + }, 90 + }, { 91 + Name: "Validate", 92 + Params: []adt.Kind{adt.BytesKind | adt.StringKind, adt.TopKind}, 93 + Result: adt.BoolKind, 94 + Func: func(c *internal.CallCtxt) { 95 + b, v := c.Bytes(0), c.Value(1) 96 + if c.Do() { 97 + c.Ret, c.Err = Validate(b, v) 98 + } 99 + }, 100 + }}, 101 + }
+71
pkg/encoding/yaml/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package yaml 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("encoding/yaml", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Marshal", 22 + Params: []adt.Kind{adt.TopKind}, 23 + Result: adt.StringKind, 24 + Func: func(c *internal.CallCtxt) { 25 + v := c.Value(0) 26 + if c.Do() { 27 + c.Ret, c.Err = Marshal(v) 28 + } 29 + }, 30 + }, { 31 + Name: "MarshalStream", 32 + Params: []adt.Kind{adt.TopKind}, 33 + Result: adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + v := c.Value(0) 36 + if c.Do() { 37 + c.Ret, c.Err = MarshalStream(v) 38 + } 39 + }, 40 + }, { 41 + Name: "Unmarshal", 42 + Params: []adt.Kind{adt.BytesKind | adt.StringKind}, 43 + Result: adt.TopKind, 44 + Func: func(c *internal.CallCtxt) { 45 + data := c.Bytes(0) 46 + if c.Do() { 47 + c.Ret, c.Err = Unmarshal(data) 48 + } 49 + }, 50 + }, { 51 + Name: "Validate", 52 + Params: []adt.Kind{adt.BytesKind | adt.StringKind, adt.TopKind}, 53 + Result: adt.BoolKind, 54 + Func: func(c *internal.CallCtxt) { 55 + b, v := c.Bytes(0), c.Value(1) 56 + if c.Do() { 57 + c.Ret, c.Err = Validate(b, v) 58 + } 59 + }, 60 + }, { 61 + Name: "ValidatePartial", 62 + Params: []adt.Kind{adt.BytesKind | adt.StringKind, adt.TopKind}, 63 + Result: adt.BoolKind, 64 + Func: func(c *internal.CallCtxt) { 65 + b, v := c.Bytes(0), c.Value(1) 66 + if c.Do() { 67 + c.Ret, c.Err = ValidatePartial(b, v) 68 + } 69 + }, 70 + }}, 71 + }
+412
pkg/gen/gen.go
··· 1 + // Copyright 2018 The CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + // Package gen is a command that can be used to bootstrap a new builtin package 16 + // directory. The directory has to reside in cuelang.org/go/pkg. 17 + // 18 + // To bootstrap a directory, run this command from within that direcory. 19 + // After that directory's files can be regenerated with go generate. 20 + // 21 + // Be sure to also update an entry in pkg/pkg.go, if so desired. 22 + package main 23 + 24 + import ( 25 + "bytes" 26 + "flag" 27 + "fmt" 28 + "go/ast" 29 + "go/constant" 30 + "go/format" 31 + "go/parser" 32 + "go/printer" 33 + "go/token" 34 + "io" 35 + "io/ioutil" 36 + "log" 37 + "math/big" 38 + "os" 39 + "path" 40 + "path/filepath" 41 + "strings" 42 + 43 + "cuelang.org/go/cue" 44 + "cuelang.org/go/cue/errors" 45 + cueformat "cuelang.org/go/cue/format" 46 + "cuelang.org/go/cue/load" 47 + "cuelang.org/go/internal" 48 + ) 49 + 50 + const genFile = "pkg.go" 51 + 52 + const prefix = "../pkg/" 53 + 54 + const header = `// Code generated by go generate. DO NOT EDIT. 55 + 56 + //go:generate rm %s 57 + //go:generate go run %sgen/gen.go 58 + 59 + package %s 60 + 61 + import ( 62 + "cuelang.org/go/internal/core/adt" 63 + "cuelang.org/go/pkg/internal" 64 + ) 65 + 66 + func init() { 67 + internal.Register(%q, pkg) 68 + } 69 + 70 + var _ = adt.TopKind // in case the adt package isn't used 71 + 72 + ` 73 + 74 + func main() { 75 + flag.Parse() 76 + log.SetFlags(log.Lshortfile) 77 + log.SetOutput(os.Stdout) 78 + 79 + g := generator{ 80 + w: &bytes.Buffer{}, 81 + decls: &bytes.Buffer{}, 82 + fset: token.NewFileSet(), 83 + } 84 + 85 + cwd, _ := os.Getwd() 86 + pkg := strings.Split(filepath.ToSlash(cwd), "/pkg/")[1] 87 + gopkg := path.Base(pkg) 88 + // TODO: rename list to lists and struct to structs. 89 + if gopkg == "struct" { 90 + gopkg = "structs" 91 + } 92 + dots := strings.Repeat("../", strings.Count(pkg, "/")+1) 93 + 94 + w := &bytes.Buffer{} 95 + fmt.Fprintf(w, header, genFile, dots, gopkg, pkg) 96 + g.processDir(pkg) 97 + 98 + io.Copy(w, g.decls) 99 + io.Copy(w, g.w) 100 + 101 + b, err := format.Source(w.Bytes()) 102 + if err != nil { 103 + b = w.Bytes() // write the unformatted source 104 + } 105 + 106 + b = bytes.Replace(b, []byte(".Builtin{{}}"), []byte(".Builtin{}"), -1) 107 + 108 + filename := filepath.Join(genFile) 109 + 110 + if err := ioutil.WriteFile(filename, b, 0644); err != nil { 111 + log.Fatal(err) 112 + } 113 + } 114 + 115 + type generator struct { 116 + w *bytes.Buffer 117 + decls *bytes.Buffer 118 + name string 119 + fset *token.FileSet 120 + defaultPkg string 121 + first bool 122 + iota int 123 + 124 + imports []*ast.ImportSpec 125 + } 126 + 127 + func (g *generator) processDir(pkg string) { 128 + goFiles, err := filepath.Glob("*.go") 129 + if err != nil { 130 + log.Fatal(err) 131 + } 132 + 133 + cueFiles, err := filepath.Glob("*.cue") 134 + if err != nil { 135 + log.Fatal(err) 136 + } 137 + 138 + if len(goFiles)+len(cueFiles) == 0 { 139 + return 140 + } 141 + 142 + fmt.Fprintf(g.w, "var pkg = &internal.Package{\nNative: []*internal.Builtin{{\n") 143 + g.first = true 144 + for _, filename := range goFiles { 145 + if filename == genFile { 146 + continue 147 + } 148 + g.processGo(filename) 149 + } 150 + fmt.Fprintf(g.w, "}},\n") 151 + g.processCUE(pkg) 152 + fmt.Fprintf(g.w, "}\n") 153 + } 154 + 155 + func (g *generator) sep() { 156 + if g.first { 157 + g.first = false 158 + return 159 + } 160 + fmt.Fprintln(g.w, "}, {") 161 + } 162 + 163 + // processCUE mixes in CUE definitions defined in the package directory. 164 + func (g *generator) processCUE(pkg string) { 165 + instances := cue.Build(load.Instances([]string{"."}, &load.Config{ 166 + StdRoot: ".", 167 + })) 168 + 169 + if err := instances[0].Err; err != nil { 170 + if !strings.Contains(err.Error(), "no CUE files") { 171 + errors.Print(os.Stderr, err, nil) 172 + log.Fatalf("error processing %s: %v", pkg, err) 173 + } 174 + return 175 + } 176 + 177 + v := instances[0].Value().Syntax(cue.Raw()) 178 + // fmt.Printf("%T\n", v) 179 + // fmt.Println(internal.DebugStr(v)) 180 + n := internal.ToExpr(v) 181 + b, err := cueformat.Node(n) 182 + if err != nil { 183 + log.Fatal(err) 184 + } 185 + b = bytes.ReplaceAll(b, []byte("\n\n"), []byte("\n")) 186 + // body = strings.ReplaceAll(body, "\t", "") 187 + // TODO: escape backtick 188 + fmt.Fprintf(g.w, "CUE: `%s`,\n", string(b)) 189 + } 190 + 191 + func (g *generator) processGo(filename string) { 192 + if strings.HasSuffix(filename, "_test.go") { 193 + return 194 + } 195 + f, err := parser.ParseFile(g.fset, filename, nil, parser.ParseComments) 196 + if err != nil { 197 + log.Fatal(err) 198 + } 199 + g.defaultPkg = "" 200 + g.name = f.Name.Name 201 + if g.name == "structs" { 202 + g.name = "struct" 203 + } 204 + 205 + for _, d := range f.Decls { 206 + switch x := d.(type) { 207 + case *ast.GenDecl: 208 + switch x.Tok { 209 + case token.CONST: 210 + for _, spec := range x.Specs { 211 + if !ast.IsExported(spec.(*ast.ValueSpec).Names[0].Name) { 212 + continue 213 + } 214 + g.genConst(spec.(*ast.ValueSpec)) 215 + } 216 + case token.VAR: 217 + continue 218 + case token.TYPE: 219 + // TODO: support type declarations. 220 + continue 221 + case token.IMPORT: 222 + continue 223 + default: 224 + log.Fatalf("gen %s: unexpected spec of type %s", filename, x.Tok) 225 + } 226 + case *ast.FuncDecl: 227 + g.genFun(x) 228 + } 229 + } 230 + } 231 + 232 + func (g *generator) genConst(spec *ast.ValueSpec) { 233 + name := spec.Names[0].Name 234 + value := "" 235 + switch v := g.toValue(spec.Values[0]); v.Kind() { 236 + case constant.Bool, constant.Int, constant.String: 237 + // TODO: convert octal numbers 238 + value = v.ExactString() 239 + case constant.Float: 240 + var rat big.Rat 241 + rat.SetString(v.ExactString()) 242 + var float big.Float 243 + float.SetRat(&rat) 244 + value = float.Text('g', -1) 245 + default: 246 + fmt.Printf("Dropped entry %s.%s (%T: %v)\n", g.defaultPkg, name, v.Kind(), v.ExactString()) 247 + return 248 + } 249 + g.sep() 250 + fmt.Fprintf(g.w, "Name: %q,\n Const: %q,\n", name, value) 251 + } 252 + 253 + func (g *generator) toValue(x ast.Expr) constant.Value { 254 + switch x := x.(type) { 255 + case *ast.BasicLit: 256 + return constant.MakeFromLiteral(x.Value, x.Kind, 0) 257 + case *ast.BinaryExpr: 258 + return constant.BinaryOp(g.toValue(x.X), x.Op, g.toValue(x.Y)) 259 + case *ast.UnaryExpr: 260 + return constant.UnaryOp(x.Op, g.toValue(x.X), 0) 261 + default: 262 + log.Fatalf("%s: unsupported expression type %T: %#v", g.defaultPkg, x, x) 263 + } 264 + return constant.MakeUnknown() 265 + } 266 + 267 + func (g *generator) genFun(x *ast.FuncDecl) { 268 + if x.Body == nil || !ast.IsExported(x.Name.Name) { 269 + return 270 + } 271 + types := []string{} 272 + if x.Type.Results != nil { 273 + for _, f := range x.Type.Results.List { 274 + if len(f.Names) > 0 { 275 + for range f.Names { 276 + types = append(types, g.goKind(f.Type)) 277 + } 278 + } else { 279 + types = append(types, g.goKind(f.Type)) 280 + } 281 + } 282 + } 283 + if n := len(types); n != 1 && (n != 2 || types[1] != "error") { 284 + fmt.Printf("Dropped func %s.%s: must have one return value or a value and an error %v\n", g.defaultPkg, x.Name.Name, types) 285 + return 286 + } 287 + 288 + if x.Recv != nil { 289 + // if strings.HasPrefix(x.Name.Name, g.name) { 290 + // printer.Fprint(g.decls, g.fset, x) 291 + // fmt.Fprint(g.decls, "\n\n") 292 + // } 293 + return 294 + } 295 + 296 + g.sep() 297 + fmt.Fprintf(g.w, "Name: %q,\n", x.Name.Name) 298 + 299 + args := []string{} 300 + vals := []string{} 301 + kind := []string{} 302 + for _, f := range x.Type.Params.List { 303 + for _, name := range f.Names { 304 + typ := strings.Title(g.goKind(f.Type)) 305 + argKind := g.goToCUE(f.Type) 306 + vals = append(vals, fmt.Sprintf("c.%s(%d)", typ, len(args))) 307 + args = append(args, name.Name) 308 + kind = append(kind, argKind) 309 + } 310 + } 311 + 312 + fmt.Fprintf(g.w, "Params: []adt.Kind{%s},\n", strings.Join(kind, ", ")) 313 + result := g.goToCUE(x.Type.Results.List[0].Type) 314 + fmt.Fprintf(g.w, "Result: %s,\n", result) 315 + argList := strings.Join(args, ", ") 316 + valList := strings.Join(vals, ", ") 317 + init := "" 318 + if len(args) > 0 { 319 + init = fmt.Sprintf("%s := %s", argList, valList) 320 + } 321 + 322 + fmt.Fprintf(g.w, "Func: func(c *internal.CallCtxt) {") 323 + defer fmt.Fprintln(g.w, "},") 324 + fmt.Fprintln(g.w) 325 + if init != "" { 326 + fmt.Fprintln(g.w, init) 327 + } 328 + fmt.Fprintln(g.w, "if c.Do() {") 329 + defer fmt.Fprintln(g.w, "}") 330 + if len(types) == 1 { 331 + fmt.Fprintf(g.w, "c.Ret = %s(%s)", x.Name.Name, argList) 332 + } else { 333 + fmt.Fprintf(g.w, "c.Ret, c.Err = %s(%s)", x.Name.Name, argList) 334 + } 335 + } 336 + 337 + func (g *generator) goKind(expr ast.Expr) string { 338 + if star, isStar := expr.(*ast.StarExpr); isStar { 339 + expr = star.X 340 + } 341 + w := &bytes.Buffer{} 342 + printer.Fprint(w, g.fset, expr) 343 + switch str := w.String(); str { 344 + case "big.Int": 345 + return "bigInt" 346 + case "big.Float": 347 + return "bigFloat" 348 + case "big.Rat": 349 + return "bigRat" 350 + case "internal.Decimal": 351 + return "decimal" 352 + case "[]*internal.Decimal": 353 + return "decimalList" 354 + case "cue.Struct": 355 + return "struct" 356 + case "cue.Value": 357 + return "value" 358 + case "cue.List": 359 + return "list" 360 + case "[]string": 361 + return "stringList" 362 + case "[]byte": 363 + return "bytes" 364 + case "[]cue.Value": 365 + return "list" 366 + case "io.Reader": 367 + return "reader" 368 + case "time.Time": 369 + return "string" 370 + default: 371 + return str 372 + } 373 + } 374 + 375 + func (g *generator) goToCUE(expr ast.Expr) (cueKind string) { 376 + // TODO: detect list and structs types for return values. 377 + switch k := g.goKind(expr); k { 378 + case "error": 379 + cueKind += "adt.BottomKind" 380 + case "bool": 381 + cueKind += "adt.BoolKind" 382 + case "bytes", "reader": 383 + cueKind += "adt.BytesKind|adt.StringKind" 384 + case "string": 385 + cueKind += "adt.StringKind" 386 + case "int", "int8", "int16", "int32", "rune", "int64", 387 + "uint", "byte", "uint8", "uint16", "uint32", "uint64", 388 + "bigInt": 389 + cueKind += "adt.IntKind" 390 + case "float64", "bigRat", "bigFloat", "decimal": 391 + cueKind += "adt.NumKind" 392 + case "list", "decimalList", "stringList": 393 + cueKind += "adt.ListKind" 394 + case "struct": 395 + cueKind += "adt.StructKind" 396 + case "value": 397 + // Must use callCtxt.value method for these types and resolve manually. 398 + cueKind += "adt.TopKind" // TODO: can be more precise 399 + default: 400 + switch { 401 + case strings.HasPrefix(k, "[]"): 402 + cueKind += "adt.ListKind" 403 + case strings.HasPrefix(k, "map["): 404 + cueKind += "adt.StructKind" 405 + default: 406 + // log.Println("Unknown type:", k) 407 + // Must use callCtxt.value method for these types and resolve manually. 408 + cueKind += "adt.TopKind" // TODO: can be more precise 409 + } 410 + } 411 + return cueKind 412 + }
+41
pkg/html/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package html 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("html", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Escape", 22 + Params: []adt.Kind{adt.StringKind}, 23 + Result: adt.StringKind, 24 + Func: func(c *internal.CallCtxt) { 25 + s := c.String(0) 26 + if c.Do() { 27 + c.Ret = Escape(s) 28 + } 29 + }, 30 + }, { 31 + Name: "Unescape", 32 + Params: []adt.Kind{adt.StringKind}, 33 + Result: adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + s := c.String(0) 36 + if c.Do() { 37 + c.Ret = Unescape(s) 38 + } 39 + }, 40 + }}, 41 + }
+27
pkg/internal/register.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package internal 16 + 17 + import ( 18 + "cuelang.org/go/internal/builtin" 19 + "cuelang.org/go/internal/core/adt" 20 + ) 21 + 22 + func Register(importPath string, p *Package) { 23 + f := func(ctx *adt.OpContext) (*adt.Vertex, error) { 24 + return p.MustCompile(ctx, importPath), nil 25 + } 26 + builtin.Register(importPath, f) 27 + }
+233
pkg/list/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package list 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("list", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Drop", 22 + Params: []adt.Kind{adt.ListKind, adt.IntKind}, 23 + Result: adt.ListKind, 24 + Func: func(c *internal.CallCtxt) { 25 + x, n := c.List(0), c.Int(1) 26 + if c.Do() { 27 + c.Ret, c.Err = Drop(x, n) 28 + } 29 + }, 30 + }, { 31 + Name: "FlattenN", 32 + Params: []adt.Kind{adt.TopKind, adt.IntKind}, 33 + Result: adt.ListKind, 34 + Func: func(c *internal.CallCtxt) { 35 + xs, depth := c.Value(0), c.Int(1) 36 + if c.Do() { 37 + c.Ret, c.Err = FlattenN(xs, depth) 38 + } 39 + }, 40 + }, { 41 + Name: "Take", 42 + Params: []adt.Kind{adt.ListKind, adt.IntKind}, 43 + Result: adt.ListKind, 44 + Func: func(c *internal.CallCtxt) { 45 + x, n := c.List(0), c.Int(1) 46 + if c.Do() { 47 + c.Ret, c.Err = Take(x, n) 48 + } 49 + }, 50 + }, { 51 + Name: "Slice", 52 + Params: []adt.Kind{adt.ListKind, adt.IntKind, adt.IntKind}, 53 + Result: adt.ListKind, 54 + Func: func(c *internal.CallCtxt) { 55 + x, i, j := c.List(0), c.Int(1), c.Int(2) 56 + if c.Do() { 57 + c.Ret, c.Err = Slice(x, i, j) 58 + } 59 + }, 60 + }, { 61 + Name: "MinItems", 62 + Params: []adt.Kind{adt.ListKind, adt.IntKind}, 63 + Result: adt.BoolKind, 64 + Func: func(c *internal.CallCtxt) { 65 + a, n := c.List(0), c.Int(1) 66 + if c.Do() { 67 + c.Ret = MinItems(a, n) 68 + } 69 + }, 70 + }, { 71 + Name: "MaxItems", 72 + Params: []adt.Kind{adt.ListKind, adt.IntKind}, 73 + Result: adt.BoolKind, 74 + Func: func(c *internal.CallCtxt) { 75 + a, n := c.List(0), c.Int(1) 76 + if c.Do() { 77 + c.Ret = MaxItems(a, n) 78 + } 79 + }, 80 + }, { 81 + Name: "UniqueItems", 82 + Params: []adt.Kind{adt.ListKind}, 83 + Result: adt.BoolKind, 84 + Func: func(c *internal.CallCtxt) { 85 + a := c.List(0) 86 + if c.Do() { 87 + c.Ret = UniqueItems(a) 88 + } 89 + }, 90 + }, { 91 + Name: "Contains", 92 + Params: []adt.Kind{adt.ListKind, adt.TopKind}, 93 + Result: adt.BoolKind, 94 + Func: func(c *internal.CallCtxt) { 95 + a, v := c.List(0), c.Value(1) 96 + if c.Do() { 97 + c.Ret = Contains(a, v) 98 + } 99 + }, 100 + }, { 101 + Name: "Avg", 102 + Params: []adt.Kind{adt.ListKind}, 103 + Result: adt.NumKind, 104 + Func: func(c *internal.CallCtxt) { 105 + xs := c.DecimalList(0) 106 + if c.Do() { 107 + c.Ret, c.Err = Avg(xs) 108 + } 109 + }, 110 + }, { 111 + Name: "Max", 112 + Params: []adt.Kind{adt.ListKind}, 113 + Result: adt.NumKind, 114 + Func: func(c *internal.CallCtxt) { 115 + xs := c.DecimalList(0) 116 + if c.Do() { 117 + c.Ret, c.Err = Max(xs) 118 + } 119 + }, 120 + }, { 121 + Name: "Min", 122 + Params: []adt.Kind{adt.ListKind}, 123 + Result: adt.NumKind, 124 + Func: func(c *internal.CallCtxt) { 125 + xs := c.DecimalList(0) 126 + if c.Do() { 127 + c.Ret, c.Err = Min(xs) 128 + } 129 + }, 130 + }, { 131 + Name: "Product", 132 + Params: []adt.Kind{adt.ListKind}, 133 + Result: adt.NumKind, 134 + Func: func(c *internal.CallCtxt) { 135 + xs := c.DecimalList(0) 136 + if c.Do() { 137 + c.Ret, c.Err = Product(xs) 138 + } 139 + }, 140 + }, { 141 + Name: "Range", 142 + Params: []adt.Kind{adt.NumKind, adt.NumKind, adt.NumKind}, 143 + Result: adt.ListKind, 144 + Func: func(c *internal.CallCtxt) { 145 + start, limit, step := c.Decimal(0), c.Decimal(1), c.Decimal(2) 146 + if c.Do() { 147 + c.Ret, c.Err = Range(start, limit, step) 148 + } 149 + }, 150 + }, { 151 + Name: "Sum", 152 + Params: []adt.Kind{adt.ListKind}, 153 + Result: adt.NumKind, 154 + Func: func(c *internal.CallCtxt) { 155 + xs := c.DecimalList(0) 156 + if c.Do() { 157 + c.Ret, c.Err = Sum(xs) 158 + } 159 + }, 160 + }, { 161 + Name: "Sort", 162 + Params: []adt.Kind{adt.ListKind, adt.TopKind}, 163 + Result: adt.ListKind, 164 + Func: func(c *internal.CallCtxt) { 165 + list, cmp := c.List(0), c.Value(1) 166 + if c.Do() { 167 + c.Ret, c.Err = Sort(list, cmp) 168 + } 169 + }, 170 + }, { 171 + Name: "SortStable", 172 + Params: []adt.Kind{adt.ListKind, adt.TopKind}, 173 + Result: adt.ListKind, 174 + Func: func(c *internal.CallCtxt) { 175 + list, cmp := c.List(0), c.Value(1) 176 + if c.Do() { 177 + c.Ret, c.Err = SortStable(list, cmp) 178 + } 179 + }, 180 + }, { 181 + Name: "SortStrings", 182 + Params: []adt.Kind{adt.ListKind}, 183 + Result: adt.ListKind, 184 + Func: func(c *internal.CallCtxt) { 185 + a := c.StringList(0) 186 + if c.Do() { 187 + c.Ret = SortStrings(a) 188 + } 189 + }, 190 + }, { 191 + Name: "IsSorted", 192 + Params: []adt.Kind{adt.ListKind, adt.TopKind}, 193 + Result: adt.BoolKind, 194 + Func: func(c *internal.CallCtxt) { 195 + list, cmp := c.List(0), c.Value(1) 196 + if c.Do() { 197 + c.Ret = IsSorted(list, cmp) 198 + } 199 + }, 200 + }, { 201 + Name: "IsSortedStrings", 202 + Params: []adt.Kind{adt.ListKind}, 203 + Result: adt.BoolKind, 204 + Func: func(c *internal.CallCtxt) { 205 + a := c.StringList(0) 206 + if c.Do() { 207 + c.Ret = IsSortedStrings(a) 208 + } 209 + }, 210 + }}, 211 + CUE: `{ 212 + Comparer: { 213 + T: _ 214 + x: T 215 + y: T 216 + less: bool 217 + } 218 + Ascending: { 219 + Comparer 220 + T: number | string 221 + x: T 222 + y: T 223 + less: true && x < y 224 + } 225 + Descending: { 226 + Comparer 227 + T: number | string 228 + x: T 229 + y: T 230 + less: x > y 231 + } 232 + }`, 233 + }
+17 -4
pkg/list/sort.go
··· 32 32 } 33 33 34 34 func (s *valueSorter) ret() ([]cue.Value, error) { 35 - panic("implemented in cue/builtinutil.go") 35 + if s.err != nil { 36 + return nil, s.err 37 + } 38 + // The input slice is already a copy and that we can modify it safely. 39 + return s.a, nil 36 40 } 37 41 38 - func (s *valueSorter) Len() int { panic("implemented in cue/builtinutil.go") } 39 - func (s *valueSorter) Swap(i, j int) { panic("implemented in cue/builtinutil.go") } 40 - func (s *valueSorter) Less(i, j int) bool { panic("implemented in cue/builtinutil.go") } 42 + func (s *valueSorter) Len() int { return len(s.a) } 43 + func (s *valueSorter) Swap(i, j int) { s.a[i], s.a[j] = s.a[j], s.a[i] } 44 + func (s *valueSorter) Less(i, j int) bool { 45 + v := s.cmp.Fill(s.a[i], "x") 46 + v = v.Fill(s.a[j], "y") 47 + isLess, err := v.Lookup("less").Bool() 48 + if err != nil && s.err == nil { 49 + s.err = err 50 + return true 51 + } 52 + return isLess 53 + } 41 54 42 55 // Sort sorts data. It does O(n*log(n)) comparisons. 43 56 // The sort is not guaranteed to be stable.
+121
pkg/math/bits/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package bits 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("math/bits", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Lsh", 22 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 23 + Result: adt.IntKind, 24 + Func: func(c *internal.CallCtxt) { 25 + x, n := c.BigInt(0), c.Uint(1) 26 + if c.Do() { 27 + c.Ret = Lsh(x, n) 28 + } 29 + }, 30 + }, { 31 + Name: "Rsh", 32 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 33 + Result: adt.IntKind, 34 + Func: func(c *internal.CallCtxt) { 35 + x, n := c.BigInt(0), c.Uint(1) 36 + if c.Do() { 37 + c.Ret = Rsh(x, n) 38 + } 39 + }, 40 + }, { 41 + Name: "At", 42 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 43 + Result: adt.IntKind, 44 + Func: func(c *internal.CallCtxt) { 45 + x, i := c.BigInt(0), c.Uint(1) 46 + if c.Do() { 47 + c.Ret, c.Err = At(x, i) 48 + } 49 + }, 50 + }, { 51 + Name: "Set", 52 + Params: []adt.Kind{adt.IntKind, adt.IntKind, adt.IntKind}, 53 + Result: adt.IntKind, 54 + Func: func(c *internal.CallCtxt) { 55 + x, i, bit := c.BigInt(0), c.Int(1), c.Uint(2) 56 + if c.Do() { 57 + c.Ret = Set(x, i, bit) 58 + } 59 + }, 60 + }, { 61 + Name: "And", 62 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 63 + Result: adt.IntKind, 64 + Func: func(c *internal.CallCtxt) { 65 + a, b := c.BigInt(0), c.BigInt(1) 66 + if c.Do() { 67 + c.Ret = And(a, b) 68 + } 69 + }, 70 + }, { 71 + Name: "Or", 72 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 73 + Result: adt.IntKind, 74 + Func: func(c *internal.CallCtxt) { 75 + a, b := c.BigInt(0), c.BigInt(1) 76 + if c.Do() { 77 + c.Ret = Or(a, b) 78 + } 79 + }, 80 + }, { 81 + Name: "Xor", 82 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 83 + Result: adt.IntKind, 84 + Func: func(c *internal.CallCtxt) { 85 + a, b := c.BigInt(0), c.BigInt(1) 86 + if c.Do() { 87 + c.Ret = Xor(a, b) 88 + } 89 + }, 90 + }, { 91 + Name: "Clear", 92 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 93 + Result: adt.IntKind, 94 + Func: func(c *internal.CallCtxt) { 95 + a, b := c.BigInt(0), c.BigInt(1) 96 + if c.Do() { 97 + c.Ret = Clear(a, b) 98 + } 99 + }, 100 + }, { 101 + Name: "OnesCount", 102 + Params: []adt.Kind{adt.IntKind}, 103 + Result: adt.IntKind, 104 + Func: func(c *internal.CallCtxt) { 105 + x := c.BigInt(0) 106 + if c.Do() { 107 + c.Ret = OnesCount(x) 108 + } 109 + }, 110 + }, { 111 + Name: "Len", 112 + Params: []adt.Kind{adt.IntKind}, 113 + Result: adt.IntKind, 114 + Func: func(c *internal.CallCtxt) { 115 + x := c.BigInt(0) 116 + if c.Do() { 117 + c.Ret = Len(x) 118 + } 119 + }, 120 + }}, 121 + }
+613
pkg/math/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package math 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("math", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "MaxExp", 22 + Const: "2147483647", 23 + }, { 24 + Name: "MinExp", 25 + Const: "-2147483648", 26 + }, { 27 + Name: "MaxPrec", 28 + Const: "4294967295", 29 + }, { 30 + Name: "ToNearestEven", 31 + Const: "0", 32 + }, { 33 + Name: "ToNearestAway", 34 + Const: "1", 35 + }, { 36 + Name: "ToZero", 37 + Const: "2", 38 + }, { 39 + Name: "AwayFromZero", 40 + Const: "3", 41 + }, { 42 + Name: "ToNegativeInf", 43 + Const: "4", 44 + }, { 45 + Name: "ToPositiveInf", 46 + Const: "5", 47 + }, { 48 + Name: "Below", 49 + Const: "-1", 50 + }, { 51 + Name: "Exact", 52 + Const: "0", 53 + }, { 54 + Name: "Above", 55 + Const: "1", 56 + }, { 57 + Name: "Jacobi", 58 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 59 + Result: adt.IntKind, 60 + Func: func(c *internal.CallCtxt) { 61 + x, y := c.BigInt(0), c.BigInt(1) 62 + if c.Do() { 63 + c.Ret = Jacobi(x, y) 64 + } 65 + }, 66 + }, { 67 + Name: "MaxBase", 68 + Const: "62", 69 + }, { 70 + Name: "Floor", 71 + Params: []adt.Kind{adt.NumKind}, 72 + Result: adt.NumKind, 73 + Func: func(c *internal.CallCtxt) { 74 + x := c.Decimal(0) 75 + if c.Do() { 76 + c.Ret, c.Err = Floor(x) 77 + } 78 + }, 79 + }, { 80 + Name: "Ceil", 81 + Params: []adt.Kind{adt.NumKind}, 82 + Result: adt.NumKind, 83 + Func: func(c *internal.CallCtxt) { 84 + x := c.Decimal(0) 85 + if c.Do() { 86 + c.Ret, c.Err = Ceil(x) 87 + } 88 + }, 89 + }, { 90 + Name: "Trunc", 91 + Params: []adt.Kind{adt.NumKind}, 92 + Result: adt.NumKind, 93 + Func: func(c *internal.CallCtxt) { 94 + x := c.Decimal(0) 95 + if c.Do() { 96 + c.Ret, c.Err = Trunc(x) 97 + } 98 + }, 99 + }, { 100 + Name: "Round", 101 + Params: []adt.Kind{adt.NumKind}, 102 + Result: adt.NumKind, 103 + Func: func(c *internal.CallCtxt) { 104 + x := c.Decimal(0) 105 + if c.Do() { 106 + c.Ret, c.Err = Round(x) 107 + } 108 + }, 109 + }, { 110 + Name: "RoundToEven", 111 + Params: []adt.Kind{adt.NumKind}, 112 + Result: adt.NumKind, 113 + Func: func(c *internal.CallCtxt) { 114 + x := c.Decimal(0) 115 + if c.Do() { 116 + c.Ret, c.Err = RoundToEven(x) 117 + } 118 + }, 119 + }, { 120 + Name: "MultipleOf", 121 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 122 + Result: adt.BoolKind, 123 + Func: func(c *internal.CallCtxt) { 124 + x, y := c.Decimal(0), c.Decimal(1) 125 + if c.Do() { 126 + c.Ret, c.Err = MultipleOf(x, y) 127 + } 128 + }, 129 + }, { 130 + Name: "Abs", 131 + Params: []adt.Kind{adt.NumKind}, 132 + Result: adt.NumKind, 133 + Func: func(c *internal.CallCtxt) { 134 + x := c.Decimal(0) 135 + if c.Do() { 136 + c.Ret, c.Err = Abs(x) 137 + } 138 + }, 139 + }, { 140 + Name: "Acosh", 141 + Params: []adt.Kind{adt.NumKind}, 142 + Result: adt.NumKind, 143 + Func: func(c *internal.CallCtxt) { 144 + x := c.Float64(0) 145 + if c.Do() { 146 + c.Ret = Acosh(x) 147 + } 148 + }, 149 + }, { 150 + Name: "Asin", 151 + Params: []adt.Kind{adt.NumKind}, 152 + Result: adt.NumKind, 153 + Func: func(c *internal.CallCtxt) { 154 + x := c.Float64(0) 155 + if c.Do() { 156 + c.Ret = Asin(x) 157 + } 158 + }, 159 + }, { 160 + Name: "Acos", 161 + Params: []adt.Kind{adt.NumKind}, 162 + Result: adt.NumKind, 163 + Func: func(c *internal.CallCtxt) { 164 + x := c.Float64(0) 165 + if c.Do() { 166 + c.Ret = Acos(x) 167 + } 168 + }, 169 + }, { 170 + Name: "Asinh", 171 + Params: []adt.Kind{adt.NumKind}, 172 + Result: adt.NumKind, 173 + Func: func(c *internal.CallCtxt) { 174 + x := c.Float64(0) 175 + if c.Do() { 176 + c.Ret = Asinh(x) 177 + } 178 + }, 179 + }, { 180 + Name: "Atan", 181 + Params: []adt.Kind{adt.NumKind}, 182 + Result: adt.NumKind, 183 + Func: func(c *internal.CallCtxt) { 184 + x := c.Float64(0) 185 + if c.Do() { 186 + c.Ret = Atan(x) 187 + } 188 + }, 189 + }, { 190 + Name: "Atan2", 191 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 192 + Result: adt.NumKind, 193 + Func: func(c *internal.CallCtxt) { 194 + y, x := c.Float64(0), c.Float64(1) 195 + if c.Do() { 196 + c.Ret = Atan2(y, x) 197 + } 198 + }, 199 + }, { 200 + Name: "Atanh", 201 + Params: []adt.Kind{adt.NumKind}, 202 + Result: adt.NumKind, 203 + Func: func(c *internal.CallCtxt) { 204 + x := c.Float64(0) 205 + if c.Do() { 206 + c.Ret = Atanh(x) 207 + } 208 + }, 209 + }, { 210 + Name: "Cbrt", 211 + Params: []adt.Kind{adt.NumKind}, 212 + Result: adt.NumKind, 213 + Func: func(c *internal.CallCtxt) { 214 + x := c.Decimal(0) 215 + if c.Do() { 216 + c.Ret, c.Err = Cbrt(x) 217 + } 218 + }, 219 + }, { 220 + Name: "E", 221 + Const: "2.71828182845904523536028747135266249775724709369995957496696763", 222 + }, { 223 + Name: "Pi", 224 + Const: "3.14159265358979323846264338327950288419716939937510582097494459", 225 + }, { 226 + Name: "Phi", 227 + Const: "1.61803398874989484820458683436563811772030917980576286213544861", 228 + }, { 229 + Name: "Sqrt2", 230 + Const: "1.41421356237309504880168872420969807856967187537694807317667974", 231 + }, { 232 + Name: "SqrtE", 233 + Const: "1.64872127070012814684865078781416357165377610071014801157507931", 234 + }, { 235 + Name: "SqrtPi", 236 + Const: "1.77245385090551602729816748334114518279754945612238712821380779", 237 + }, { 238 + Name: "SqrtPhi", 239 + Const: "1.27201964951406896425242246173749149171560804184009624861664038", 240 + }, { 241 + Name: "Ln2", 242 + Const: "0.693147180559945309417232121458176568075500134360255254120680009", 243 + }, { 244 + Name: "Log2E", 245 + Const: "1.442695040888963407359924681001892137426645954152985934135449408", 246 + }, { 247 + Name: "Ln10", 248 + Const: "2.3025850929940456840179914546843642076011014886287729760333278", 249 + }, { 250 + Name: "Log10E", 251 + Const: "0.43429448190325182765112891891660508229439700580366656611445378", 252 + }, { 253 + Name: "Copysign", 254 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 255 + Result: adt.NumKind, 256 + Func: func(c *internal.CallCtxt) { 257 + x, y := c.Decimal(0), c.Decimal(1) 258 + if c.Do() { 259 + c.Ret = Copysign(x, y) 260 + } 261 + }, 262 + }, { 263 + Name: "Dim", 264 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 265 + Result: adt.NumKind, 266 + Func: func(c *internal.CallCtxt) { 267 + x, y := c.Decimal(0), c.Decimal(1) 268 + if c.Do() { 269 + c.Ret, c.Err = Dim(x, y) 270 + } 271 + }, 272 + }, { 273 + Name: "Erf", 274 + Params: []adt.Kind{adt.NumKind}, 275 + Result: adt.NumKind, 276 + Func: func(c *internal.CallCtxt) { 277 + x := c.Float64(0) 278 + if c.Do() { 279 + c.Ret = Erf(x) 280 + } 281 + }, 282 + }, { 283 + Name: "Erfc", 284 + Params: []adt.Kind{adt.NumKind}, 285 + Result: adt.NumKind, 286 + Func: func(c *internal.CallCtxt) { 287 + x := c.Float64(0) 288 + if c.Do() { 289 + c.Ret = Erfc(x) 290 + } 291 + }, 292 + }, { 293 + Name: "Erfinv", 294 + Params: []adt.Kind{adt.NumKind}, 295 + Result: adt.NumKind, 296 + Func: func(c *internal.CallCtxt) { 297 + x := c.Float64(0) 298 + if c.Do() { 299 + c.Ret = Erfinv(x) 300 + } 301 + }, 302 + }, { 303 + Name: "Erfcinv", 304 + Params: []adt.Kind{adt.NumKind}, 305 + Result: adt.NumKind, 306 + Func: func(c *internal.CallCtxt) { 307 + x := c.Float64(0) 308 + if c.Do() { 309 + c.Ret = Erfcinv(x) 310 + } 311 + }, 312 + }, { 313 + Name: "Exp", 314 + Params: []adt.Kind{adt.NumKind}, 315 + Result: adt.NumKind, 316 + Func: func(c *internal.CallCtxt) { 317 + x := c.Decimal(0) 318 + if c.Do() { 319 + c.Ret, c.Err = Exp(x) 320 + } 321 + }, 322 + }, { 323 + Name: "Exp2", 324 + Params: []adt.Kind{adt.NumKind}, 325 + Result: adt.NumKind, 326 + Func: func(c *internal.CallCtxt) { 327 + x := c.Decimal(0) 328 + if c.Do() { 329 + c.Ret, c.Err = Exp2(x) 330 + } 331 + }, 332 + }, { 333 + Name: "Expm1", 334 + Params: []adt.Kind{adt.NumKind}, 335 + Result: adt.NumKind, 336 + Func: func(c *internal.CallCtxt) { 337 + x := c.Float64(0) 338 + if c.Do() { 339 + c.Ret = Expm1(x) 340 + } 341 + }, 342 + }, { 343 + Name: "Gamma", 344 + Params: []adt.Kind{adt.NumKind}, 345 + Result: adt.NumKind, 346 + Func: func(c *internal.CallCtxt) { 347 + x := c.Float64(0) 348 + if c.Do() { 349 + c.Ret = Gamma(x) 350 + } 351 + }, 352 + }, { 353 + Name: "Hypot", 354 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 355 + Result: adt.NumKind, 356 + Func: func(c *internal.CallCtxt) { 357 + p, q := c.Float64(0), c.Float64(1) 358 + if c.Do() { 359 + c.Ret = Hypot(p, q) 360 + } 361 + }, 362 + }, { 363 + Name: "J0", 364 + Params: []adt.Kind{adt.NumKind}, 365 + Result: adt.NumKind, 366 + Func: func(c *internal.CallCtxt) { 367 + x := c.Float64(0) 368 + if c.Do() { 369 + c.Ret = J0(x) 370 + } 371 + }, 372 + }, { 373 + Name: "Y0", 374 + Params: []adt.Kind{adt.NumKind}, 375 + Result: adt.NumKind, 376 + Func: func(c *internal.CallCtxt) { 377 + x := c.Float64(0) 378 + if c.Do() { 379 + c.Ret = Y0(x) 380 + } 381 + }, 382 + }, { 383 + Name: "J1", 384 + Params: []adt.Kind{adt.NumKind}, 385 + Result: adt.NumKind, 386 + Func: func(c *internal.CallCtxt) { 387 + x := c.Float64(0) 388 + if c.Do() { 389 + c.Ret = J1(x) 390 + } 391 + }, 392 + }, { 393 + Name: "Y1", 394 + Params: []adt.Kind{adt.NumKind}, 395 + Result: adt.NumKind, 396 + Func: func(c *internal.CallCtxt) { 397 + x := c.Float64(0) 398 + if c.Do() { 399 + c.Ret = Y1(x) 400 + } 401 + }, 402 + }, { 403 + Name: "Jn", 404 + Params: []adt.Kind{adt.IntKind, adt.NumKind}, 405 + Result: adt.NumKind, 406 + Func: func(c *internal.CallCtxt) { 407 + n, x := c.Int(0), c.Float64(1) 408 + if c.Do() { 409 + c.Ret = Jn(n, x) 410 + } 411 + }, 412 + }, { 413 + Name: "Yn", 414 + Params: []adt.Kind{adt.IntKind, adt.NumKind}, 415 + Result: adt.NumKind, 416 + Func: func(c *internal.CallCtxt) { 417 + n, x := c.Int(0), c.Float64(1) 418 + if c.Do() { 419 + c.Ret = Yn(n, x) 420 + } 421 + }, 422 + }, { 423 + Name: "Ldexp", 424 + Params: []adt.Kind{adt.NumKind, adt.IntKind}, 425 + Result: adt.NumKind, 426 + Func: func(c *internal.CallCtxt) { 427 + frac, exp := c.Float64(0), c.Int(1) 428 + if c.Do() { 429 + c.Ret = Ldexp(frac, exp) 430 + } 431 + }, 432 + }, { 433 + Name: "Log", 434 + Params: []adt.Kind{adt.NumKind}, 435 + Result: adt.NumKind, 436 + Func: func(c *internal.CallCtxt) { 437 + x := c.Decimal(0) 438 + if c.Do() { 439 + c.Ret, c.Err = Log(x) 440 + } 441 + }, 442 + }, { 443 + Name: "Log10", 444 + Params: []adt.Kind{adt.NumKind}, 445 + Result: adt.NumKind, 446 + Func: func(c *internal.CallCtxt) { 447 + x := c.Decimal(0) 448 + if c.Do() { 449 + c.Ret, c.Err = Log10(x) 450 + } 451 + }, 452 + }, { 453 + Name: "Log2", 454 + Params: []adt.Kind{adt.NumKind}, 455 + Result: adt.NumKind, 456 + Func: func(c *internal.CallCtxt) { 457 + x := c.Decimal(0) 458 + if c.Do() { 459 + c.Ret, c.Err = Log2(x) 460 + } 461 + }, 462 + }, { 463 + Name: "Log1p", 464 + Params: []adt.Kind{adt.NumKind}, 465 + Result: adt.NumKind, 466 + Func: func(c *internal.CallCtxt) { 467 + x := c.Float64(0) 468 + if c.Do() { 469 + c.Ret = Log1p(x) 470 + } 471 + }, 472 + }, { 473 + Name: "Logb", 474 + Params: []adt.Kind{adt.NumKind}, 475 + Result: adt.NumKind, 476 + Func: func(c *internal.CallCtxt) { 477 + x := c.Float64(0) 478 + if c.Do() { 479 + c.Ret = Logb(x) 480 + } 481 + }, 482 + }, { 483 + Name: "Ilogb", 484 + Params: []adt.Kind{adt.NumKind}, 485 + Result: adt.IntKind, 486 + Func: func(c *internal.CallCtxt) { 487 + x := c.Float64(0) 488 + if c.Do() { 489 + c.Ret = Ilogb(x) 490 + } 491 + }, 492 + }, { 493 + Name: "Mod", 494 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 495 + Result: adt.NumKind, 496 + Func: func(c *internal.CallCtxt) { 497 + x, y := c.Float64(0), c.Float64(1) 498 + if c.Do() { 499 + c.Ret = Mod(x, y) 500 + } 501 + }, 502 + }, { 503 + Name: "Pow", 504 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 505 + Result: adt.NumKind, 506 + Func: func(c *internal.CallCtxt) { 507 + x, y := c.Decimal(0), c.Decimal(1) 508 + if c.Do() { 509 + c.Ret, c.Err = Pow(x, y) 510 + } 511 + }, 512 + }, { 513 + Name: "Pow10", 514 + Params: []adt.Kind{adt.IntKind}, 515 + Result: adt.NumKind, 516 + Func: func(c *internal.CallCtxt) { 517 + n := c.Int32(0) 518 + if c.Do() { 519 + c.Ret = Pow10(n) 520 + } 521 + }, 522 + }, { 523 + Name: "Remainder", 524 + Params: []adt.Kind{adt.NumKind, adt.NumKind}, 525 + Result: adt.NumKind, 526 + Func: func(c *internal.CallCtxt) { 527 + x, y := c.Float64(0), c.Float64(1) 528 + if c.Do() { 529 + c.Ret = Remainder(x, y) 530 + } 531 + }, 532 + }, { 533 + Name: "Signbit", 534 + Params: []adt.Kind{adt.NumKind}, 535 + Result: adt.BoolKind, 536 + Func: func(c *internal.CallCtxt) { 537 + x := c.Decimal(0) 538 + if c.Do() { 539 + c.Ret = Signbit(x) 540 + } 541 + }, 542 + }, { 543 + Name: "Cos", 544 + Params: []adt.Kind{adt.NumKind}, 545 + Result: adt.NumKind, 546 + Func: func(c *internal.CallCtxt) { 547 + x := c.Float64(0) 548 + if c.Do() { 549 + c.Ret = Cos(x) 550 + } 551 + }, 552 + }, { 553 + Name: "Sin", 554 + Params: []adt.Kind{adt.NumKind}, 555 + Result: adt.NumKind, 556 + Func: func(c *internal.CallCtxt) { 557 + x := c.Float64(0) 558 + if c.Do() { 559 + c.Ret = Sin(x) 560 + } 561 + }, 562 + }, { 563 + Name: "Sinh", 564 + Params: []adt.Kind{adt.NumKind}, 565 + Result: adt.NumKind, 566 + Func: func(c *internal.CallCtxt) { 567 + x := c.Float64(0) 568 + if c.Do() { 569 + c.Ret = Sinh(x) 570 + } 571 + }, 572 + }, { 573 + Name: "Cosh", 574 + Params: []adt.Kind{adt.NumKind}, 575 + Result: adt.NumKind, 576 + Func: func(c *internal.CallCtxt) { 577 + x := c.Float64(0) 578 + if c.Do() { 579 + c.Ret = Cosh(x) 580 + } 581 + }, 582 + }, { 583 + Name: "Sqrt", 584 + Params: []adt.Kind{adt.NumKind}, 585 + Result: adt.NumKind, 586 + Func: func(c *internal.CallCtxt) { 587 + x := c.Float64(0) 588 + if c.Do() { 589 + c.Ret = Sqrt(x) 590 + } 591 + }, 592 + }, { 593 + Name: "Tan", 594 + Params: []adt.Kind{adt.NumKind}, 595 + Result: adt.NumKind, 596 + Func: func(c *internal.CallCtxt) { 597 + x := c.Float64(0) 598 + if c.Do() { 599 + c.Ret = Tan(x) 600 + } 601 + }, 602 + }, { 603 + Name: "Tanh", 604 + Params: []adt.Kind{adt.NumKind}, 605 + Result: adt.NumKind, 606 + Func: func(c *internal.CallCtxt) { 607 + x := c.Float64(0) 608 + if c.Do() { 609 + c.Ret = Tanh(x) 610 + } 611 + }, 612 + }}, 613 + }
+187
pkg/net/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package net 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("net", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "SplitHostPort", 22 + Params: []adt.Kind{adt.StringKind}, 23 + Result: adt.ListKind, 24 + Func: func(c *internal.CallCtxt) { 25 + s := c.String(0) 26 + if c.Do() { 27 + c.Ret, c.Err = SplitHostPort(s) 28 + } 29 + }, 30 + }, { 31 + Name: "JoinHostPort", 32 + Params: []adt.Kind{adt.TopKind, adt.TopKind}, 33 + Result: adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + host, port := c.Value(0), c.Value(1) 36 + if c.Do() { 37 + c.Ret, c.Err = JoinHostPort(host, port) 38 + } 39 + }, 40 + }, { 41 + Name: "FQDN", 42 + Params: []adt.Kind{adt.StringKind}, 43 + Result: adt.BoolKind, 44 + Func: func(c *internal.CallCtxt) { 45 + s := c.String(0) 46 + if c.Do() { 47 + c.Ret = FQDN(s) 48 + } 49 + }, 50 + }, { 51 + Name: "IPv4len", 52 + Const: "4", 53 + }, { 54 + Name: "IPv6len", 55 + Const: "16", 56 + }, { 57 + Name: "ParseIP", 58 + Params: []adt.Kind{adt.StringKind}, 59 + Result: adt.ListKind, 60 + Func: func(c *internal.CallCtxt) { 61 + s := c.String(0) 62 + if c.Do() { 63 + c.Ret, c.Err = ParseIP(s) 64 + } 65 + }, 66 + }, { 67 + Name: "IPv4", 68 + Params: []adt.Kind{adt.TopKind}, 69 + Result: adt.BoolKind, 70 + Func: func(c *internal.CallCtxt) { 71 + ip := c.Value(0) 72 + if c.Do() { 73 + c.Ret = IPv4(ip) 74 + } 75 + }, 76 + }, { 77 + Name: "IP", 78 + Params: []adt.Kind{adt.TopKind}, 79 + Result: adt.BoolKind, 80 + Func: func(c *internal.CallCtxt) { 81 + ip := c.Value(0) 82 + if c.Do() { 83 + c.Ret = IP(ip) 84 + } 85 + }, 86 + }, { 87 + Name: "LoopbackIP", 88 + Params: []adt.Kind{adt.TopKind}, 89 + Result: adt.BoolKind, 90 + Func: func(c *internal.CallCtxt) { 91 + ip := c.Value(0) 92 + if c.Do() { 93 + c.Ret = LoopbackIP(ip) 94 + } 95 + }, 96 + }, { 97 + Name: "MulticastIP", 98 + Params: []adt.Kind{adt.TopKind}, 99 + Result: adt.BoolKind, 100 + Func: func(c *internal.CallCtxt) { 101 + ip := c.Value(0) 102 + if c.Do() { 103 + c.Ret = MulticastIP(ip) 104 + } 105 + }, 106 + }, { 107 + Name: "InterfaceLocalMulticastIP", 108 + Params: []adt.Kind{adt.TopKind}, 109 + Result: adt.BoolKind, 110 + Func: func(c *internal.CallCtxt) { 111 + ip := c.Value(0) 112 + if c.Do() { 113 + c.Ret = InterfaceLocalMulticastIP(ip) 114 + } 115 + }, 116 + }, { 117 + Name: "LinkLocalMulticastIP", 118 + Params: []adt.Kind{adt.TopKind}, 119 + Result: adt.BoolKind, 120 + Func: func(c *internal.CallCtxt) { 121 + ip := c.Value(0) 122 + if c.Do() { 123 + c.Ret = LinkLocalMulticastIP(ip) 124 + } 125 + }, 126 + }, { 127 + Name: "LinkLocalUnicastIP", 128 + Params: []adt.Kind{adt.TopKind}, 129 + Result: adt.BoolKind, 130 + Func: func(c *internal.CallCtxt) { 131 + ip := c.Value(0) 132 + if c.Do() { 133 + c.Ret = LinkLocalUnicastIP(ip) 134 + } 135 + }, 136 + }, { 137 + Name: "GlobalUnicastIP", 138 + Params: []adt.Kind{adt.TopKind}, 139 + Result: adt.BoolKind, 140 + Func: func(c *internal.CallCtxt) { 141 + ip := c.Value(0) 142 + if c.Do() { 143 + c.Ret = GlobalUnicastIP(ip) 144 + } 145 + }, 146 + }, { 147 + Name: "UnspecifiedIP", 148 + Params: []adt.Kind{adt.TopKind}, 149 + Result: adt.BoolKind, 150 + Func: func(c *internal.CallCtxt) { 151 + ip := c.Value(0) 152 + if c.Do() { 153 + c.Ret = UnspecifiedIP(ip) 154 + } 155 + }, 156 + }, { 157 + Name: "ToIP4", 158 + Params: []adt.Kind{adt.TopKind}, 159 + Result: adt.ListKind, 160 + Func: func(c *internal.CallCtxt) { 161 + ip := c.Value(0) 162 + if c.Do() { 163 + c.Ret, c.Err = ToIP4(ip) 164 + } 165 + }, 166 + }, { 167 + Name: "ToIP16", 168 + Params: []adt.Kind{adt.TopKind}, 169 + Result: adt.ListKind, 170 + Func: func(c *internal.CallCtxt) { 171 + ip := c.Value(0) 172 + if c.Do() { 173 + c.Ret, c.Err = ToIP16(ip) 174 + } 175 + }, 176 + }, { 177 + Name: "IPString", 178 + Params: []adt.Kind{adt.TopKind}, 179 + Result: adt.StringKind, 180 + Func: func(c *internal.CallCtxt) { 181 + ip := c.Value(0) 182 + if c.Do() { 183 + c.Ret, c.Err = IPString(ip) 184 + } 185 + }, 186 + }}, 187 + }
+91
pkg/path/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package path 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("path", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Split", 22 + Params: []adt.Kind{adt.StringKind}, 23 + Result: adt.ListKind, 24 + Func: func(c *internal.CallCtxt) { 25 + path := c.String(0) 26 + if c.Do() { 27 + c.Ret = Split(path) 28 + } 29 + }, 30 + }, { 31 + Name: "Match", 32 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 33 + Result: adt.BoolKind, 34 + Func: func(c *internal.CallCtxt) { 35 + pattern, name := c.String(0), c.String(1) 36 + if c.Do() { 37 + c.Ret, c.Err = Match(pattern, name) 38 + } 39 + }, 40 + }, { 41 + Name: "Clean", 42 + Params: []adt.Kind{adt.StringKind}, 43 + Result: adt.StringKind, 44 + Func: func(c *internal.CallCtxt) { 45 + path := c.String(0) 46 + if c.Do() { 47 + c.Ret = Clean(path) 48 + } 49 + }, 50 + }, { 51 + Name: "Ext", 52 + Params: []adt.Kind{adt.StringKind}, 53 + Result: adt.StringKind, 54 + Func: func(c *internal.CallCtxt) { 55 + path := c.String(0) 56 + if c.Do() { 57 + c.Ret = Ext(path) 58 + } 59 + }, 60 + }, { 61 + Name: "Base", 62 + Params: []adt.Kind{adt.StringKind}, 63 + Result: adt.StringKind, 64 + Func: func(c *internal.CallCtxt) { 65 + path := c.String(0) 66 + if c.Do() { 67 + c.Ret = Base(path) 68 + } 69 + }, 70 + }, { 71 + Name: "IsAbs", 72 + Params: []adt.Kind{adt.StringKind}, 73 + Result: adt.BoolKind, 74 + Func: func(c *internal.CallCtxt) { 75 + path := c.String(0) 76 + if c.Do() { 77 + c.Ret = IsAbs(path) 78 + } 79 + }, 80 + }, { 81 + Name: "Dir", 82 + Params: []adt.Kind{adt.StringKind}, 83 + Result: adt.StringKind, 84 + Func: func(c *internal.CallCtxt) { 85 + path := c.String(0) 86 + if c.Do() { 87 + c.Ret = Dir(path) 88 + } 89 + }, 90 + }}, 91 + }
+111
pkg/regexp/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package regexp 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("regexp", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Valid", 22 + Params: []adt.Kind{adt.StringKind}, 23 + Result: adt.BoolKind, 24 + Func: func(c *internal.CallCtxt) { 25 + pattern := c.String(0) 26 + if c.Do() { 27 + c.Ret, c.Err = Valid(pattern) 28 + } 29 + }, 30 + }, { 31 + Name: "Find", 32 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 33 + Result: adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + pattern, s := c.String(0), c.String(1) 36 + if c.Do() { 37 + c.Ret, c.Err = Find(pattern, s) 38 + } 39 + }, 40 + }, { 41 + Name: "FindAll", 42 + Params: []adt.Kind{adt.StringKind, adt.StringKind, adt.IntKind}, 43 + Result: adt.ListKind, 44 + Func: func(c *internal.CallCtxt) { 45 + pattern, s, n := c.String(0), c.String(1), c.Int(2) 46 + if c.Do() { 47 + c.Ret, c.Err = FindAll(pattern, s, n) 48 + } 49 + }, 50 + }, { 51 + Name: "FindSubmatch", 52 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 53 + Result: adt.ListKind, 54 + Func: func(c *internal.CallCtxt) { 55 + pattern, s := c.String(0), c.String(1) 56 + if c.Do() { 57 + c.Ret, c.Err = FindSubmatch(pattern, s) 58 + } 59 + }, 60 + }, { 61 + Name: "FindAllSubmatch", 62 + Params: []adt.Kind{adt.StringKind, adt.StringKind, adt.IntKind}, 63 + Result: adt.ListKind, 64 + Func: func(c *internal.CallCtxt) { 65 + pattern, s, n := c.String(0), c.String(1), c.Int(2) 66 + if c.Do() { 67 + c.Ret, c.Err = FindAllSubmatch(pattern, s, n) 68 + } 69 + }, 70 + }, { 71 + Name: "FindNamedSubmatch", 72 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 73 + Result: adt.StructKind, 74 + Func: func(c *internal.CallCtxt) { 75 + pattern, s := c.String(0), c.String(1) 76 + if c.Do() { 77 + c.Ret, c.Err = FindNamedSubmatch(pattern, s) 78 + } 79 + }, 80 + }, { 81 + Name: "FindAllNamedSubmatch", 82 + Params: []adt.Kind{adt.StringKind, adt.StringKind, adt.IntKind}, 83 + Result: adt.ListKind, 84 + Func: func(c *internal.CallCtxt) { 85 + pattern, s, n := c.String(0), c.String(1), c.Int(2) 86 + if c.Do() { 87 + c.Ret, c.Err = FindAllNamedSubmatch(pattern, s, n) 88 + } 89 + }, 90 + }, { 91 + Name: "Match", 92 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 93 + Result: adt.BoolKind, 94 + Func: func(c *internal.CallCtxt) { 95 + pattern, s := c.String(0), c.String(1) 96 + if c.Do() { 97 + c.Ret, c.Err = Match(pattern, s) 98 + } 99 + }, 100 + }, { 101 + Name: "QuoteMeta", 102 + Params: []adt.Kind{adt.StringKind}, 103 + Result: adt.StringKind, 104 + Func: func(c *internal.CallCtxt) { 105 + s := c.String(0) 106 + if c.Do() { 107 + c.Ret = QuoteMeta(s) 108 + } 109 + }, 110 + }}, 111 + }
+47
pkg/register.go
··· 1 + // Copyright 2020 CUE Authors 2 + // 3 + // Licensed under the Apache License, Version 2.0 (the "License"); 4 + // you may not use this file except in compliance with the License. 5 + // You may obtain a copy of the License at 6 + // 7 + // http://www.apache.org/licenses/LICENSE-2.0 8 + // 9 + // Unless required by applicable law or agreed to in writing, software 10 + // distributed under the License is distributed on an "AS IS" BASIS, 11 + // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 + // See the License for the specific language governing permissions and 13 + // limitations under the License. 14 + 15 + package pkg 16 + 17 + import ( 18 + _ "cuelang.org/go/pkg/crypto/md5" 19 + _ "cuelang.org/go/pkg/crypto/sha1" 20 + _ "cuelang.org/go/pkg/crypto/sha256" 21 + _ "cuelang.org/go/pkg/crypto/sha512" 22 + _ "cuelang.org/go/pkg/encoding/base64" 23 + _ "cuelang.org/go/pkg/encoding/csv" 24 + _ "cuelang.org/go/pkg/encoding/hex" 25 + _ "cuelang.org/go/pkg/encoding/json" 26 + _ "cuelang.org/go/pkg/encoding/yaml" 27 + _ "cuelang.org/go/pkg/html" 28 + 29 + _ "cuelang.org/go/pkg/list" 30 + _ "cuelang.org/go/pkg/math" 31 + _ "cuelang.org/go/pkg/math/bits" 32 + _ "cuelang.org/go/pkg/net" 33 + _ "cuelang.org/go/pkg/path" 34 + _ "cuelang.org/go/pkg/regexp" 35 + _ "cuelang.org/go/pkg/strconv" 36 + _ "cuelang.org/go/pkg/strings" 37 + _ "cuelang.org/go/pkg/struct" 38 + _ "cuelang.org/go/pkg/text/tabwriter" 39 + _ "cuelang.org/go/pkg/text/template" 40 + _ "cuelang.org/go/pkg/time" 41 + _ "cuelang.org/go/pkg/tool" 42 + _ "cuelang.org/go/pkg/tool/cli" 43 + _ "cuelang.org/go/pkg/tool/exec" 44 + _ "cuelang.org/go/pkg/tool/file" 45 + _ "cuelang.org/go/pkg/tool/http" 46 + _ "cuelang.org/go/pkg/tool/os" 47 + )
+204
pkg/strconv/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package strconv 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("strconv", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Unquote", 22 + Params: []adt.Kind{adt.StringKind}, 23 + Result: adt.StringKind, 24 + Func: func(c *internal.CallCtxt) { 25 + s := c.String(0) 26 + if c.Do() { 27 + c.Ret, c.Err = Unquote(s) 28 + } 29 + }, 30 + }, { 31 + Name: "ParseBool", 32 + Params: []adt.Kind{adt.StringKind}, 33 + Result: adt.BoolKind, 34 + Func: func(c *internal.CallCtxt) { 35 + str := c.String(0) 36 + if c.Do() { 37 + c.Ret, c.Err = ParseBool(str) 38 + } 39 + }, 40 + }, { 41 + Name: "FormatBool", 42 + Params: []adt.Kind{adt.BoolKind}, 43 + Result: adt.StringKind, 44 + Func: func(c *internal.CallCtxt) { 45 + b := c.Bool(0) 46 + if c.Do() { 47 + c.Ret = FormatBool(b) 48 + } 49 + }, 50 + }, { 51 + Name: "ParseFloat", 52 + Params: []adt.Kind{adt.StringKind, adt.IntKind}, 53 + Result: adt.NumKind, 54 + Func: func(c *internal.CallCtxt) { 55 + s, bitSize := c.String(0), c.Int(1) 56 + if c.Do() { 57 + c.Ret, c.Err = ParseFloat(s, bitSize) 58 + } 59 + }, 60 + }, { 61 + Name: "IntSize", 62 + Const: "64", 63 + }, { 64 + Name: "ParseUint", 65 + Params: []adt.Kind{adt.StringKind, adt.IntKind, adt.IntKind}, 66 + Result: adt.IntKind, 67 + Func: func(c *internal.CallCtxt) { 68 + s, base, bitSize := c.String(0), c.Int(1), c.Int(2) 69 + if c.Do() { 70 + c.Ret, c.Err = ParseUint(s, base, bitSize) 71 + } 72 + }, 73 + }, { 74 + Name: "ParseInt", 75 + Params: []adt.Kind{adt.StringKind, adt.IntKind, adt.IntKind}, 76 + Result: adt.IntKind, 77 + Func: func(c *internal.CallCtxt) { 78 + s, base, bitSize := c.String(0), c.Int(1), c.Int(2) 79 + if c.Do() { 80 + c.Ret, c.Err = ParseInt(s, base, bitSize) 81 + } 82 + }, 83 + }, { 84 + Name: "Atoi", 85 + Params: []adt.Kind{adt.StringKind}, 86 + Result: adt.IntKind, 87 + Func: func(c *internal.CallCtxt) { 88 + s := c.String(0) 89 + if c.Do() { 90 + c.Ret, c.Err = Atoi(s) 91 + } 92 + }, 93 + }, { 94 + Name: "FormatFloat", 95 + Params: []adt.Kind{adt.NumKind, adt.IntKind, adt.IntKind, adt.IntKind}, 96 + Result: adt.StringKind, 97 + Func: func(c *internal.CallCtxt) { 98 + f, fmt, prec, bitSize := c.Float64(0), c.Byte(1), c.Int(2), c.Int(3) 99 + if c.Do() { 100 + c.Ret = FormatFloat(f, fmt, prec, bitSize) 101 + } 102 + }, 103 + }, { 104 + Name: "FormatUint", 105 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 106 + Result: adt.StringKind, 107 + Func: func(c *internal.CallCtxt) { 108 + i, base := c.Uint64(0), c.Int(1) 109 + if c.Do() { 110 + c.Ret = FormatUint(i, base) 111 + } 112 + }, 113 + }, { 114 + Name: "FormatInt", 115 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 116 + Result: adt.StringKind, 117 + Func: func(c *internal.CallCtxt) { 118 + i, base := c.Int64(0), c.Int(1) 119 + if c.Do() { 120 + c.Ret = FormatInt(i, base) 121 + } 122 + }, 123 + }, { 124 + Name: "Quote", 125 + Params: []adt.Kind{adt.StringKind}, 126 + Result: adt.StringKind, 127 + Func: func(c *internal.CallCtxt) { 128 + s := c.String(0) 129 + if c.Do() { 130 + c.Ret = Quote(s) 131 + } 132 + }, 133 + }, { 134 + Name: "QuoteToASCII", 135 + Params: []adt.Kind{adt.StringKind}, 136 + Result: adt.StringKind, 137 + Func: func(c *internal.CallCtxt) { 138 + s := c.String(0) 139 + if c.Do() { 140 + c.Ret = QuoteToASCII(s) 141 + } 142 + }, 143 + }, { 144 + Name: "QuoteToGraphic", 145 + Params: []adt.Kind{adt.StringKind}, 146 + Result: adt.StringKind, 147 + Func: func(c *internal.CallCtxt) { 148 + s := c.String(0) 149 + if c.Do() { 150 + c.Ret = QuoteToGraphic(s) 151 + } 152 + }, 153 + }, { 154 + Name: "QuoteRune", 155 + Params: []adt.Kind{adt.IntKind}, 156 + Result: adt.StringKind, 157 + Func: func(c *internal.CallCtxt) { 158 + r := c.Rune(0) 159 + if c.Do() { 160 + c.Ret = QuoteRune(r) 161 + } 162 + }, 163 + }, { 164 + Name: "QuoteRuneToASCII", 165 + Params: []adt.Kind{adt.IntKind}, 166 + Result: adt.StringKind, 167 + Func: func(c *internal.CallCtxt) { 168 + r := c.Rune(0) 169 + if c.Do() { 170 + c.Ret = QuoteRuneToASCII(r) 171 + } 172 + }, 173 + }, { 174 + Name: "QuoteRuneToGraphic", 175 + Params: []adt.Kind{adt.IntKind}, 176 + Result: adt.StringKind, 177 + Func: func(c *internal.CallCtxt) { 178 + r := c.Rune(0) 179 + if c.Do() { 180 + c.Ret = QuoteRuneToGraphic(r) 181 + } 182 + }, 183 + }, { 184 + Name: "IsPrint", 185 + Params: []adt.Kind{adt.IntKind}, 186 + Result: adt.BoolKind, 187 + Func: func(c *internal.CallCtxt) { 188 + r := c.Rune(0) 189 + if c.Do() { 190 + c.Ret = IsPrint(r) 191 + } 192 + }, 193 + }, { 194 + Name: "IsGraphic", 195 + Params: []adt.Kind{adt.IntKind}, 196 + Result: adt.BoolKind, 197 + Func: func(c *internal.CallCtxt) { 198 + r := c.Rune(0) 199 + if c.Do() { 200 + c.Ret = IsGraphic(r) 201 + } 202 + }, 203 + }}, 204 + }
+361
pkg/strings/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package strings 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("strings", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "ByteAt", 22 + Params: []adt.Kind{adt.BytesKind | adt.StringKind, adt.IntKind}, 23 + Result: adt.IntKind, 24 + Func: func(c *internal.CallCtxt) { 25 + b, i := c.Bytes(0), c.Int(1) 26 + if c.Do() { 27 + c.Ret, c.Err = ByteAt(b, i) 28 + } 29 + }, 30 + }, { 31 + Name: "ByteSlice", 32 + Params: []adt.Kind{adt.BytesKind | adt.StringKind, adt.IntKind, adt.IntKind}, 33 + Result: adt.BytesKind | adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + b, start, end := c.Bytes(0), c.Int(1), c.Int(2) 36 + if c.Do() { 37 + c.Ret, c.Err = ByteSlice(b, start, end) 38 + } 39 + }, 40 + }, { 41 + Name: "Runes", 42 + Params: []adt.Kind{adt.StringKind}, 43 + Result: adt.ListKind, 44 + Func: func(c *internal.CallCtxt) { 45 + s := c.String(0) 46 + if c.Do() { 47 + c.Ret = Runes(s) 48 + } 49 + }, 50 + }, { 51 + Name: "MinRunes", 52 + Params: []adt.Kind{adt.StringKind, adt.IntKind}, 53 + Result: adt.BoolKind, 54 + Func: func(c *internal.CallCtxt) { 55 + s, min := c.String(0), c.Int(1) 56 + if c.Do() { 57 + c.Ret = MinRunes(s, min) 58 + } 59 + }, 60 + }, { 61 + Name: "MaxRunes", 62 + Params: []adt.Kind{adt.StringKind, adt.IntKind}, 63 + Result: adt.BoolKind, 64 + Func: func(c *internal.CallCtxt) { 65 + s, max := c.String(0), c.Int(1) 66 + if c.Do() { 67 + c.Ret = MaxRunes(s, max) 68 + } 69 + }, 70 + }, { 71 + Name: "ToTitle", 72 + Params: []adt.Kind{adt.StringKind}, 73 + Result: adt.StringKind, 74 + Func: func(c *internal.CallCtxt) { 75 + s := c.String(0) 76 + if c.Do() { 77 + c.Ret = ToTitle(s) 78 + } 79 + }, 80 + }, { 81 + Name: "ToCamel", 82 + Params: []adt.Kind{adt.StringKind}, 83 + Result: adt.StringKind, 84 + Func: func(c *internal.CallCtxt) { 85 + s := c.String(0) 86 + if c.Do() { 87 + c.Ret = ToCamel(s) 88 + } 89 + }, 90 + }, { 91 + Name: "SliceRunes", 92 + Params: []adt.Kind{adt.StringKind, adt.IntKind, adt.IntKind}, 93 + Result: adt.StringKind, 94 + Func: func(c *internal.CallCtxt) { 95 + s, start, end := c.String(0), c.Int(1), c.Int(2) 96 + if c.Do() { 97 + c.Ret, c.Err = SliceRunes(s, start, end) 98 + } 99 + }, 100 + }, { 101 + Name: "Compare", 102 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 103 + Result: adt.IntKind, 104 + Func: func(c *internal.CallCtxt) { 105 + a, b := c.String(0), c.String(1) 106 + if c.Do() { 107 + c.Ret = Compare(a, b) 108 + } 109 + }, 110 + }, { 111 + Name: "Count", 112 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 113 + Result: adt.IntKind, 114 + Func: func(c *internal.CallCtxt) { 115 + s, substr := c.String(0), c.String(1) 116 + if c.Do() { 117 + c.Ret = Count(s, substr) 118 + } 119 + }, 120 + }, { 121 + Name: "Contains", 122 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 123 + Result: adt.BoolKind, 124 + Func: func(c *internal.CallCtxt) { 125 + s, substr := c.String(0), c.String(1) 126 + if c.Do() { 127 + c.Ret = Contains(s, substr) 128 + } 129 + }, 130 + }, { 131 + Name: "ContainsAny", 132 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 133 + Result: adt.BoolKind, 134 + Func: func(c *internal.CallCtxt) { 135 + s, chars := c.String(0), c.String(1) 136 + if c.Do() { 137 + c.Ret = ContainsAny(s, chars) 138 + } 139 + }, 140 + }, { 141 + Name: "LastIndex", 142 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 143 + Result: adt.IntKind, 144 + Func: func(c *internal.CallCtxt) { 145 + s, substr := c.String(0), c.String(1) 146 + if c.Do() { 147 + c.Ret = LastIndex(s, substr) 148 + } 149 + }, 150 + }, { 151 + Name: "IndexAny", 152 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 153 + Result: adt.IntKind, 154 + Func: func(c *internal.CallCtxt) { 155 + s, chars := c.String(0), c.String(1) 156 + if c.Do() { 157 + c.Ret = IndexAny(s, chars) 158 + } 159 + }, 160 + }, { 161 + Name: "LastIndexAny", 162 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 163 + Result: adt.IntKind, 164 + Func: func(c *internal.CallCtxt) { 165 + s, chars := c.String(0), c.String(1) 166 + if c.Do() { 167 + c.Ret = LastIndexAny(s, chars) 168 + } 169 + }, 170 + }, { 171 + Name: "SplitN", 172 + Params: []adt.Kind{adt.StringKind, adt.StringKind, adt.IntKind}, 173 + Result: adt.ListKind, 174 + Func: func(c *internal.CallCtxt) { 175 + s, sep, n := c.String(0), c.String(1), c.Int(2) 176 + if c.Do() { 177 + c.Ret = SplitN(s, sep, n) 178 + } 179 + }, 180 + }, { 181 + Name: "SplitAfterN", 182 + Params: []adt.Kind{adt.StringKind, adt.StringKind, adt.IntKind}, 183 + Result: adt.ListKind, 184 + Func: func(c *internal.CallCtxt) { 185 + s, sep, n := c.String(0), c.String(1), c.Int(2) 186 + if c.Do() { 187 + c.Ret = SplitAfterN(s, sep, n) 188 + } 189 + }, 190 + }, { 191 + Name: "Split", 192 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 193 + Result: adt.ListKind, 194 + Func: func(c *internal.CallCtxt) { 195 + s, sep := c.String(0), c.String(1) 196 + if c.Do() { 197 + c.Ret = Split(s, sep) 198 + } 199 + }, 200 + }, { 201 + Name: "SplitAfter", 202 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 203 + Result: adt.ListKind, 204 + Func: func(c *internal.CallCtxt) { 205 + s, sep := c.String(0), c.String(1) 206 + if c.Do() { 207 + c.Ret = SplitAfter(s, sep) 208 + } 209 + }, 210 + }, { 211 + Name: "Fields", 212 + Params: []adt.Kind{adt.StringKind}, 213 + Result: adt.ListKind, 214 + Func: func(c *internal.CallCtxt) { 215 + s := c.String(0) 216 + if c.Do() { 217 + c.Ret = Fields(s) 218 + } 219 + }, 220 + }, { 221 + Name: "Join", 222 + Params: []adt.Kind{adt.ListKind, adt.StringKind}, 223 + Result: adt.StringKind, 224 + Func: func(c *internal.CallCtxt) { 225 + elems, sep := c.StringList(0), c.String(1) 226 + if c.Do() { 227 + c.Ret = Join(elems, sep) 228 + } 229 + }, 230 + }, { 231 + Name: "HasPrefix", 232 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 233 + Result: adt.BoolKind, 234 + Func: func(c *internal.CallCtxt) { 235 + s, prefix := c.String(0), c.String(1) 236 + if c.Do() { 237 + c.Ret = HasPrefix(s, prefix) 238 + } 239 + }, 240 + }, { 241 + Name: "HasSuffix", 242 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 243 + Result: adt.BoolKind, 244 + Func: func(c *internal.CallCtxt) { 245 + s, suffix := c.String(0), c.String(1) 246 + if c.Do() { 247 + c.Ret = HasSuffix(s, suffix) 248 + } 249 + }, 250 + }, { 251 + Name: "Repeat", 252 + Params: []adt.Kind{adt.StringKind, adt.IntKind}, 253 + Result: adt.StringKind, 254 + Func: func(c *internal.CallCtxt) { 255 + s, count := c.String(0), c.Int(1) 256 + if c.Do() { 257 + c.Ret = Repeat(s, count) 258 + } 259 + }, 260 + }, { 261 + Name: "ToUpper", 262 + Params: []adt.Kind{adt.StringKind}, 263 + Result: adt.StringKind, 264 + Func: func(c *internal.CallCtxt) { 265 + s := c.String(0) 266 + if c.Do() { 267 + c.Ret = ToUpper(s) 268 + } 269 + }, 270 + }, { 271 + Name: "ToLower", 272 + Params: []adt.Kind{adt.StringKind}, 273 + Result: adt.StringKind, 274 + Func: func(c *internal.CallCtxt) { 275 + s := c.String(0) 276 + if c.Do() { 277 + c.Ret = ToLower(s) 278 + } 279 + }, 280 + }, { 281 + Name: "Trim", 282 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 283 + Result: adt.StringKind, 284 + Func: func(c *internal.CallCtxt) { 285 + s, cutset := c.String(0), c.String(1) 286 + if c.Do() { 287 + c.Ret = Trim(s, cutset) 288 + } 289 + }, 290 + }, { 291 + Name: "TrimLeft", 292 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 293 + Result: adt.StringKind, 294 + Func: func(c *internal.CallCtxt) { 295 + s, cutset := c.String(0), c.String(1) 296 + if c.Do() { 297 + c.Ret = TrimLeft(s, cutset) 298 + } 299 + }, 300 + }, { 301 + Name: "TrimRight", 302 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 303 + Result: adt.StringKind, 304 + Func: func(c *internal.CallCtxt) { 305 + s, cutset := c.String(0), c.String(1) 306 + if c.Do() { 307 + c.Ret = TrimRight(s, cutset) 308 + } 309 + }, 310 + }, { 311 + Name: "TrimSpace", 312 + Params: []adt.Kind{adt.StringKind}, 313 + Result: adt.StringKind, 314 + Func: func(c *internal.CallCtxt) { 315 + s := c.String(0) 316 + if c.Do() { 317 + c.Ret = TrimSpace(s) 318 + } 319 + }, 320 + }, { 321 + Name: "TrimPrefix", 322 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 323 + Result: adt.StringKind, 324 + Func: func(c *internal.CallCtxt) { 325 + s, prefix := c.String(0), c.String(1) 326 + if c.Do() { 327 + c.Ret = TrimPrefix(s, prefix) 328 + } 329 + }, 330 + }, { 331 + Name: "TrimSuffix", 332 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 333 + Result: adt.StringKind, 334 + Func: func(c *internal.CallCtxt) { 335 + s, suffix := c.String(0), c.String(1) 336 + if c.Do() { 337 + c.Ret = TrimSuffix(s, suffix) 338 + } 339 + }, 340 + }, { 341 + Name: "Replace", 342 + Params: []adt.Kind{adt.StringKind, adt.StringKind, adt.StringKind, adt.IntKind}, 343 + Result: adt.StringKind, 344 + Func: func(c *internal.CallCtxt) { 345 + s, old, new, n := c.String(0), c.String(1), c.String(2), c.Int(3) 346 + if c.Do() { 347 + c.Ret = Replace(s, old, new, n) 348 + } 349 + }, 350 + }, { 351 + Name: "Index", 352 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 353 + Result: adt.IntKind, 354 + Func: func(c *internal.CallCtxt) { 355 + s, substr := c.String(0), c.String(1) 356 + if c.Do() { 357 + c.Ret = Index(s, substr) 358 + } 359 + }, 360 + }}, 361 + }
+41
pkg/struct/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package structs 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("struct", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "MinFields", 22 + Params: []adt.Kind{adt.StructKind, adt.IntKind}, 23 + Result: adt.BoolKind, 24 + Func: func(c *internal.CallCtxt) { 25 + object, n := c.Struct(0), c.Int(1) 26 + if c.Do() { 27 + c.Ret, c.Err = MinFields(object, n) 28 + } 29 + }, 30 + }, { 31 + Name: "MaxFields", 32 + Params: []adt.Kind{adt.StructKind, adt.IntKind}, 33 + Result: adt.BoolKind, 34 + Func: func(c *internal.CallCtxt) { 35 + object, n := c.Struct(0), c.Int(1) 36 + if c.Do() { 37 + c.Ret, c.Err = MaxFields(object, n) 38 + } 39 + }, 40 + }}, 41 + }
+31
pkg/text/tabwriter/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package tabwriter 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("text/tabwriter", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Write", 22 + Params: []adt.Kind{adt.TopKind}, 23 + Result: adt.StringKind, 24 + Func: func(c *internal.CallCtxt) { 25 + data := c.Value(0) 26 + if c.Do() { 27 + c.Ret, c.Err = Write(data) 28 + } 29 + }, 30 + }}, 31 + }
+51
pkg/text/template/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package template 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("text/template", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Execute", 22 + Params: []adt.Kind{adt.StringKind, adt.TopKind}, 23 + Result: adt.StringKind, 24 + Func: func(c *internal.CallCtxt) { 25 + templ, data := c.String(0), c.Value(1) 26 + if c.Do() { 27 + c.Ret, c.Err = Execute(templ, data) 28 + } 29 + }, 30 + }, { 31 + Name: "HTMLEscape", 32 + Params: []adt.Kind{adt.StringKind}, 33 + Result: adt.StringKind, 34 + Func: func(c *internal.CallCtxt) { 35 + s := c.String(0) 36 + if c.Do() { 37 + c.Ret = HTMLEscape(s) 38 + } 39 + }, 40 + }, { 41 + Name: "JSEscape", 42 + Params: []adt.Kind{adt.StringKind}, 43 + Result: adt.StringKind, 44 + Func: func(c *internal.CallCtxt) { 45 + s := c.String(0) 46 + if c.Do() { 47 + c.Ret = JSEscape(s) 48 + } 49 + }, 50 + }}, 51 + }
+195
pkg/time/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../gen/gen.go 5 + 6 + package time 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("time", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{{ 21 + Name: "Nanosecond", 22 + Const: "1", 23 + }, { 24 + Name: "Microsecond", 25 + Const: "1000", 26 + }, { 27 + Name: "Millisecond", 28 + Const: "1000000", 29 + }, { 30 + Name: "Second", 31 + Const: "1000000000", 32 + }, { 33 + Name: "Minute", 34 + Const: "60000000000", 35 + }, { 36 + Name: "Hour", 37 + Const: "3600000000000", 38 + }, { 39 + Name: "Duration", 40 + Params: []adt.Kind{adt.StringKind}, 41 + Result: adt.BoolKind, 42 + Func: func(c *internal.CallCtxt) { 43 + s := c.String(0) 44 + if c.Do() { 45 + c.Ret, c.Err = Duration(s) 46 + } 47 + }, 48 + }, { 49 + Name: "ParseDuration", 50 + Params: []adt.Kind{adt.StringKind}, 51 + Result: adt.IntKind, 52 + Func: func(c *internal.CallCtxt) { 53 + s := c.String(0) 54 + if c.Do() { 55 + c.Ret, c.Err = ParseDuration(s) 56 + } 57 + }, 58 + }, { 59 + Name: "ANSIC", 60 + Const: "\"Mon Jan _2 15:04:05 2006\"", 61 + }, { 62 + Name: "UnixDate", 63 + Const: "\"Mon Jan _2 15:04:05 MST 2006\"", 64 + }, { 65 + Name: "RubyDate", 66 + Const: "\"Mon Jan 02 15:04:05 -0700 2006\"", 67 + }, { 68 + Name: "RFC822", 69 + Const: "\"02 Jan 06 15:04 MST\"", 70 + }, { 71 + Name: "RFC822Z", 72 + Const: "\"02 Jan 06 15:04 -0700\"", 73 + }, { 74 + Name: "RFC850", 75 + Const: "\"Monday, 02-Jan-06 15:04:05 MST\"", 76 + }, { 77 + Name: "RFC1123", 78 + Const: "\"Mon, 02 Jan 2006 15:04:05 MST\"", 79 + }, { 80 + Name: "RFC1123Z", 81 + Const: "\"Mon, 02 Jan 2006 15:04:05 -0700\"", 82 + }, { 83 + Name: "RFC3339", 84 + Const: "\"2006-01-02T15:04:05Z07:00\"", 85 + }, { 86 + Name: "RFC3339Nano", 87 + Const: "\"2006-01-02T15:04:05.999999999Z07:00\"", 88 + }, { 89 + Name: "RFC3339Date", 90 + Const: "\"2006-01-02\"", 91 + }, { 92 + Name: "Kitchen", 93 + Const: "\"3:04PM\"", 94 + }, { 95 + Name: "Kitchen24", 96 + Const: "\"15:04\"", 97 + }, { 98 + Name: "January", 99 + Const: "1", 100 + }, { 101 + Name: "February", 102 + Const: "2", 103 + }, { 104 + Name: "March", 105 + Const: "3", 106 + }, { 107 + Name: "April", 108 + Const: "4", 109 + }, { 110 + Name: "May", 111 + Const: "5", 112 + }, { 113 + Name: "June", 114 + Const: "6", 115 + }, { 116 + Name: "July", 117 + Const: "7", 118 + }, { 119 + Name: "August", 120 + Const: "8", 121 + }, { 122 + Name: "September", 123 + Const: "9", 124 + }, { 125 + Name: "October", 126 + Const: "10", 127 + }, { 128 + Name: "November", 129 + Const: "11", 130 + }, { 131 + Name: "December", 132 + Const: "12", 133 + }, { 134 + Name: "Sunday", 135 + Const: "0", 136 + }, { 137 + Name: "Monday", 138 + Const: "1", 139 + }, { 140 + Name: "Tuesday", 141 + Const: "2", 142 + }, { 143 + Name: "Wednesday", 144 + Const: "3", 145 + }, { 146 + Name: "Thursday", 147 + Const: "4", 148 + }, { 149 + Name: "Friday", 150 + Const: "5", 151 + }, { 152 + Name: "Saturday", 153 + Const: "6", 154 + }, { 155 + Name: "Time", 156 + Params: []adt.Kind{adt.StringKind}, 157 + Result: adt.BoolKind, 158 + Func: func(c *internal.CallCtxt) { 159 + s := c.String(0) 160 + if c.Do() { 161 + c.Ret, c.Err = Time(s) 162 + } 163 + }, 164 + }, { 165 + Name: "Format", 166 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 167 + Result: adt.BoolKind, 168 + Func: func(c *internal.CallCtxt) { 169 + value, layout := c.String(0), c.String(1) 170 + if c.Do() { 171 + c.Ret, c.Err = Format(value, layout) 172 + } 173 + }, 174 + }, { 175 + Name: "Parse", 176 + Params: []adt.Kind{adt.StringKind, adt.StringKind}, 177 + Result: adt.StringKind, 178 + Func: func(c *internal.CallCtxt) { 179 + layout, value := c.String(0), c.String(1) 180 + if c.Do() { 181 + c.Ret, c.Err = Parse(layout, value) 182 + } 183 + }, 184 + }, { 185 + Name: "Unix", 186 + Params: []adt.Kind{adt.IntKind, adt.IntKind}, 187 + Result: adt.StringKind, 188 + Func: func(c *internal.CallCtxt) { 189 + sec, nsec := c.Int64(0), c.Int64(1) 190 + if c.Do() { 191 + c.Ret = Unix(sec, nsec) 192 + } 193 + }, 194 + }}, 195 + }
+27
pkg/tool/cli/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package cli 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("tool/cli", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{}, 21 + CUE: `{ 22 + Print: { 23 + $id: *"tool/cli.Print" | "print" 24 + text: string 25 + } 26 + }`, 27 + }
+34
pkg/tool/exec/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package exec 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("tool/exec", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{}, 21 + CUE: `{ 22 + Run: { 23 + $id: *"tool/exec.Run" | "exec" 24 + cmd: string | [string, ...string] 25 + env: { 26 + [string]: string | [...=~"="] 27 + } 28 + stdout: *null | string | bytes 29 + stderr: *null | string | bytes 30 + stdin: *null | string | bytes 31 + success: bool 32 + } 33 + }`, 34 + }
+45
pkg/tool/file/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package file 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("tool/file", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{}, 21 + CUE: `{ 22 + Read: { 23 + $id: "tool/file.Read" 24 + filename: !="" 25 + contents: *bytes | string 26 + } 27 + Append: { 28 + $id: "tool/file.Append" 29 + filename: !="" 30 + permissions: int | *420 31 + contents: bytes | string 32 + } 33 + Create: { 34 + $id: "tool/file.Create" 35 + filename: !="" 36 + permissions: int | *420 37 + contents: bytes | string 38 + } 39 + Glob: { 40 + $id: "tool/file.Glob" 41 + glob: !="" 42 + files: [...string] 43 + } 44 + }`, 45 + }
+64
pkg/tool/http/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package http 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("tool/http", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{}, 21 + CUE: `{ 22 + Get: { 23 + Do 24 + method: "GET" 25 + } 26 + Post: { 27 + Do 28 + method: "POST" 29 + } 30 + Put: { 31 + Do 32 + method: "PUT" 33 + } 34 + Delete: { 35 + Do 36 + method: "DELETE" 37 + } 38 + Do: { 39 + $id: *"tool/http.Do" | "http" 40 + method: string 41 + url: string 42 + request: { 43 + body: *bytes | string 44 + header: { 45 + [string]: string | [...string] 46 + } 47 + trailer: { 48 + [string]: string | [...string] 49 + } 50 + } 51 + response: { 52 + status: string 53 + statusCode: int 54 + body: *bytes | string 55 + header: { 56 + [string]: string | [...string] 57 + } 58 + trailer: { 59 + [string]: string | [...string] 60 + } 61 + } 62 + } 63 + }`, 64 + }
+46
pkg/tool/os/pkg.go
··· 1 + // Code generated by go generate. DO NOT EDIT. 2 + 3 + //go:generate rm pkg.go 4 + //go:generate go run ../../gen/gen.go 5 + 6 + package os 7 + 8 + import ( 9 + "cuelang.org/go/internal/core/adt" 10 + "cuelang.org/go/pkg/internal" 11 + ) 12 + 13 + func init() { 14 + internal.Register("tool/os", pkg) 15 + } 16 + 17 + var _ = adt.TopKind // in case the adt package isn't used 18 + 19 + var pkg = &internal.Package{ 20 + Native: []*internal.Builtin{}, 21 + CUE: `{ 22 + Value: bool | number | *string | null 23 + Name: !="" & !~"^[$]" 24 + Setenv: { 25 + { 26 + [Name]: Value 27 + } 28 + $id: "tool/os.Setenv" 29 + } 30 + Getenv: { 31 + { 32 + [Name]: Value 33 + } 34 + $id: "tool/os.Getenv" 35 + } 36 + Environ: { 37 + { 38 + [Name]: Value 39 + } 40 + $id: "tool/os.Environ" 41 + } 42 + Clearenv: { 43 + $id: "tool/os.Clearenv" 44 + } 45 + }`, 46 + }