blob: e435b18938d262c282bc8eaafa9d3bfa0181cda1 [file] [log] [blame]
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +01001// Code generated by go generate. DO NOT EDIT.
2
3package cue
4
5import (
6 "bytes"
7 "crypto/md5"
8 "crypto/sha1"
9 "crypto/sha256"
10 "crypto/sha512"
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +010011 "encoding/csv"
12 "encoding/hex"
13 "encoding/json"
14 "fmt"
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +010015 "html"
16 "io"
17 "math"
18 "math/big"
19 "math/bits"
20 "path"
21 "regexp"
22 "strconv"
23 "strings"
24 "text/tabwriter"
25 "text/template"
26 "unicode"
Marcel van Lohuizen76b92b52018-12-16 10:47:03 +010027
Marcel van Lohuizen6ceb6012019-02-18 18:30:38 +010028 "cuelang.org/go/cue/literal"
Marcel van Lohuizen76b92b52018-12-16 10:47:03 +010029 "cuelang.org/go/cue/parser"
30 "cuelang.org/go/cue/token"
31 "cuelang.org/go/internal/third_party/yaml"
32 goyaml "github.com/ghodss/yaml"
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +010033)
34
35func init() {
36 initBuiltins(builtinPackages)
37}
38
39var _ io.Reader
40
41var split = path.Split
42
43var pathClean = path.Clean
44
45var pathExt = path.Ext
46
47var pathBase = path.Base
48
49var pathIsAbs = path.IsAbs
50
51var pathDir = path.Dir
52
Marcel van Lohuizen57333362019-04-01 14:35:09 +020053var builtinPackages = map[string]*builtinPkg{
54 "": &builtinPkg{
55 native: []*builtin{{}},
56 },
57 "crypto/md5": &builtinPkg{
58 native: []*builtin{{
59 Name: "Size",
60 Const: "16",
61 }, {
62 Name: "BlockSize",
63 Const: "64",
64 }, {
65 Name: "Sum",
66 Params: []kind{stringKind},
67 Result: topKind,
68 Func: func(c *callCtxt) {
69 data := c.bytes(0)
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +010070 c.ret = func() interface{} {
Marcel van Lohuizen57333362019-04-01 14:35:09 +020071 return md5.Sum(data)
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +010072 }()
Marcel van Lohuizen57333362019-04-01 14:35:09 +020073 },
74 }},
75 },
76 "crypto/sha1": &builtinPkg{
77 native: []*builtin{{
78 Name: "Size",
79 Const: "20",
80 }, {
81 Name: "BlockSize",
82 Const: "64",
83 }, {
84 Name: "Sum",
85 Params: []kind{stringKind},
86 Result: topKind,
87 Func: func(c *callCtxt) {
88 data := c.bytes(0)
89 c.ret = func() interface{} {
90 return sha1.Sum(data)
91 }()
92 },
93 }},
94 },
95 "crypto/sha256": &builtinPkg{
96 native: []*builtin{{
97 Name: "Size",
98 Const: "32",
99 }, {
100 Name: "Size224",
101 Const: "28",
102 }, {
103 Name: "BlockSize",
104 Const: "64",
105 }, {
106 Name: "Sum256",
107 Params: []kind{stringKind},
108 Result: topKind,
109 Func: func(c *callCtxt) {
110 data := c.bytes(0)
111 c.ret = func() interface{} {
112 return sha256.Sum256(data)
113 }()
114 },
115 }, {
116 Name: "Sum224",
117 Params: []kind{stringKind},
118 Result: topKind,
119 Func: func(c *callCtxt) {
120 data := c.bytes(0)
121 c.ret = func() interface{} {
122 return sha256.Sum224(data)
123 }()
124 },
125 }},
126 },
127 "crypto/sha512": &builtinPkg{
128 native: []*builtin{{
129 Name: "Size",
130 Const: "64",
131 }, {
132 Name: "Size224",
133 Const: "28",
134 }, {
135 Name: "Size256",
136 Const: "32",
137 }, {
138 Name: "Size384",
139 Const: "48",
140 }, {
141 Name: "BlockSize",
142 Const: "128",
143 }, {
144 Name: "Sum512",
145 Params: []kind{stringKind},
146 Result: topKind,
147 Func: func(c *callCtxt) {
148 data := c.bytes(0)
149 c.ret = func() interface{} {
150 return sha512.Sum512(data)
151 }()
152 },
153 }, {
154 Name: "Sum384",
155 Params: []kind{stringKind},
156 Result: topKind,
157 Func: func(c *callCtxt) {
158 data := c.bytes(0)
159 c.ret = func() interface{} {
160 return sha512.Sum384(data)
161 }()
162 },
163 }, {
164 Name: "Sum512_224",
165 Params: []kind{stringKind},
166 Result: topKind,
167 Func: func(c *callCtxt) {
168 data := c.bytes(0)
169 c.ret = func() interface{} {
170 return sha512.Sum512_224(data)
171 }()
172 },
173 }, {
174 Name: "Sum512_256",
175 Params: []kind{stringKind},
176 Result: topKind,
177 Func: func(c *callCtxt) {
178 data := c.bytes(0)
179 c.ret = func() interface{} {
180 return sha512.Sum512_256(data)
181 }()
182 },
183 }},
184 },
185 "encoding/csv": &builtinPkg{
186 native: []*builtin{{
187 Name: "Encode",
188 Params: []kind{topKind},
189 Result: stringKind,
190 Func: func(c *callCtxt) {
191 x := c.value(0)
192 c.ret, c.err = func() (interface{}, error) {
193 buf := &bytes.Buffer{}
194 w := csv.NewWriter(buf)
195 iter, err := x.List()
196 if err != nil {
197 return "", err
198 }
199 for iter.Next() {
200 row, err := iter.Value().List()
201 if err != nil {
202 return "", err
203 }
204 a := []string{}
205 for row.Next() {
206 col := row.Value()
207 if str, err := col.String(); err == nil {
208 a = append(a, str)
209 } else {
210 b, err := col.MarshalJSON()
211 if err != nil {
212 return "", err
213 }
214 a = append(a, string(b))
215 }
216 }
217 w.Write(a)
218 }
219 w.Flush()
220 return buf.String(), nil
221 }()
222 },
223 }, {
224 Name: "Decode",
225 Params: []kind{stringKind},
226 Result: listKind,
227 Func: func(c *callCtxt) {
228 r := c.reader(0)
229 c.ret, c.err = func() (interface{}, error) {
230 return csv.NewReader(r).ReadAll()
231 }()
232 },
233 }},
234 },
235 "encoding/hex": &builtinPkg{
236 native: []*builtin{{
237 Name: "EncodedLen",
238 Params: []kind{intKind},
239 Result: intKind,
240 Func: func(c *callCtxt) {
241 n := c.int(0)
242 c.ret = func() interface{} {
243 return hex.EncodedLen(n)
244 }()
245 },
246 }, {
247 Name: "DecodedLen",
248 Params: []kind{intKind},
249 Result: intKind,
250 Func: func(c *callCtxt) {
251 x := c.int(0)
252 c.ret = func() interface{} {
253 return hex.DecodedLen(x)
254 }()
255 },
256 }, {
257 Name: "Decode",
258 Params: []kind{stringKind},
259 Result: stringKind,
260 Func: func(c *callCtxt) {
261 s := c.string(0)
262 c.ret, c.err = func() (interface{}, error) {
263 return hex.DecodeString(s)
264 }()
265 },
266 }, {
267 Name: "Dump",
268 Params: []kind{stringKind},
269 Result: stringKind,
270 Func: func(c *callCtxt) {
271 data := c.bytes(0)
272 c.ret = func() interface{} {
273 return hex.Dump(data)
274 }()
275 },
276 }, {
277 Name: "Encode",
278 Params: []kind{stringKind},
279 Result: stringKind,
280 Func: func(c *callCtxt) {
281 src := c.bytes(0)
282 c.ret = func() interface{} {
283 return hex.EncodeToString(src)
284 }()
285 },
286 }},
287 },
288 "encoding/json": &builtinPkg{
289 native: []*builtin{{
290 Name: "Valid",
291 Params: []kind{stringKind},
292 Result: boolKind,
293 Func: func(c *callCtxt) {
294 data := c.bytes(0)
295 c.ret = func() interface{} {
296 return json.Valid(data)
297 }()
298 },
299 }, {
300 Name: "Compact",
301 Params: []kind{stringKind},
302 Result: stringKind,
303 Func: func(c *callCtxt) {
304 src := c.bytes(0)
305 c.ret, c.err = func() (interface{}, error) {
306 dst := bytes.Buffer{}
307 if err := json.Compact(&dst, src); err != nil {
308 return "", err
309 }
310 return dst.String(), nil
311 }()
312 },
313 }, {
314 Name: "Indent",
315 Params: []kind{stringKind, stringKind, stringKind},
316 Result: stringKind,
317 Func: func(c *callCtxt) {
318 src, prefix, indent := c.bytes(0), c.string(1), c.string(2)
319 c.ret, c.err = func() (interface{}, error) {
320 dst := bytes.Buffer{}
321 if err := json.Indent(&dst, src, prefix, indent); err != nil {
322 return "", err
323 }
324 return dst.String(), nil
325 }()
326 },
327 }, {
328 Name: "HTMLEscape",
329 Params: []kind{stringKind},
330 Result: stringKind,
331 Func: func(c *callCtxt) {
332 src := c.bytes(0)
333 c.ret = func() interface{} {
334 dst := &bytes.Buffer{}
335 json.HTMLEscape(dst, src)
336 return dst.String()
337 }()
338 },
339 }, {
340 Name: "Marshal",
341 Params: []kind{topKind},
342 Result: stringKind,
343 Func: func(c *callCtxt) {
344 v := c.value(0)
345 c.ret, c.err = func() (interface{}, error) {
346 b, err := json.Marshal(v)
347 return string(b), err
348 }()
349 },
350 }, {
351 Name: "MarshalStream",
352 Params: []kind{topKind},
353 Result: stringKind,
354 Func: func(c *callCtxt) {
355 v := c.value(0)
356 c.ret, c.err = func() (interface{}, error) {
357
358 iter, err := v.List()
359 if err != nil {
360 return "", err
361 }
362 buf := &bytes.Buffer{}
363 for iter.Next() {
364 b, err := json.Marshal(iter.Value())
365 if err != nil {
366 return "", err
367 }
368 buf.Write(b)
369 buf.WriteByte('\n')
370 }
371 return buf.String(), nil
372 }()
373 },
374 }, {
375 Name: "Unmarshal",
376 Params: []kind{stringKind},
377 Result: topKind,
378 Func: func(c *callCtxt) {
379 b := c.bytes(0)
380 c.ret, c.err = func() (interface{}, error) {
381 if !json.Valid(b) {
382 return nil, fmt.Errorf("json: invalid JSON")
383 }
384 fset := token.NewFileSet()
385 expr, err := parser.ParseExpr(fset, "json", b)
386 if err != nil {
387
388 return nil, fmt.Errorf("json: could not parse JSON: %v", err)
389 }
390 return expr, nil
391 }()
392 },
393 }},
394 },
395 "encoding/yaml": &builtinPkg{
396 native: []*builtin{{
397 Name: "Marshal",
398 Params: []kind{topKind},
399 Result: stringKind,
400 Func: func(c *callCtxt) {
401 v := c.value(0)
402 c.ret, c.err = func() (interface{}, error) {
403 b, err := goyaml.Marshal(v)
404 return string(b), err
405 }()
406 },
407 }, {
408 Name: "MarshalStream",
409 Params: []kind{topKind},
410 Result: stringKind,
411 Func: func(c *callCtxt) {
412 v := c.value(0)
413 c.ret, c.err = func() (interface{}, error) {
414
415 iter, err := v.List()
416 if err != nil {
417 return "", err
418 }
419 buf := &bytes.Buffer{}
420 for i := 0; iter.Next(); i++ {
421 if i > 0 {
422 buf.WriteString("---\n")
423 }
424 b, err := goyaml.Marshal(iter.Value())
425 if err != nil {
426 return "", err
427 }
428 buf.Write(b)
429 }
430 return buf.String(), nil
431 }()
432 },
433 }, {
434 Name: "Unmarshal",
435 Params: []kind{stringKind},
436 Result: topKind,
437 Func: func(c *callCtxt) {
438 data := c.bytes(0)
439 c.ret, c.err = func() (interface{}, error) {
440 fset := token.NewFileSet()
441 return yaml.Unmarshal(fset, "", data)
442 }()
443 },
444 }},
445 },
446 "html": &builtinPkg{
447 native: []*builtin{{
448 Name: "Escape",
449 Params: []kind{stringKind},
450 Result: stringKind,
451 Func: func(c *callCtxt) {
452 s := c.string(0)
453 c.ret = func() interface{} {
454 return html.EscapeString(s)
455 }()
456 },
457 }, {
458 Name: "Unescape",
459 Params: []kind{stringKind},
460 Result: stringKind,
461 Func: func(c *callCtxt) {
462 s := c.string(0)
463 c.ret = func() interface{} {
464 return html.UnescapeString(s)
465 }()
466 },
467 }},
468 },
Marcel van Lohuizen57333362019-04-01 14:35:09 +0200469 "math": &builtinPkg{
470 native: []*builtin{{
471 Name: "MaxExp",
472 Const: "2147483647",
473 }, {
474 Name: "MinExp",
475 Const: "-2147483648",
476 }, {
477 Name: "MaxPrec",
478 Const: "4294967295",
479 }, {
480 Name: "ToNearestEven",
481 Const: "0",
482 }, {
483 Name: "ToNearestAway",
484 Const: "1",
485 }, {
486 Name: "ToZero",
487 Const: "2",
488 }, {
489 Name: "AwayFromZero",
490 Const: "3",
491 }, {
492 Name: "ToNegativeInf",
493 Const: "4",
494 }, {
495 Name: "ToPositiveInf",
496 Const: "5",
497 }, {
498 Name: "Below",
499 Const: "-1",
500 }, {
501 Name: "Exact",
502 Const: "0",
503 }, {
504 Name: "Above",
505 Const: "1",
506 }, {
507 Name: "Jacobi",
508 Params: []kind{intKind, intKind},
509 Result: intKind,
510 Func: func(c *callCtxt) {
511 x, y := c.bigInt(0), c.bigInt(1)
512 c.ret = func() interface{} {
513 return big.Jacobi(x, y)
514 }()
515 },
516 }, {
517 Name: "MaxBase",
518 Const: "62",
519 }, {
520 Name: "Floor",
521 Params: []kind{numKind},
522 Result: numKind,
523 Func: func(c *callCtxt) {
524 x := c.float64(0)
525 c.ret = func() interface{} {
526 return math.Floor(x)
527 }()
528 },
529 }, {
530 Name: "Ceil",
531 Params: []kind{numKind},
532 Result: numKind,
533 Func: func(c *callCtxt) {
534 x := c.float64(0)
535 c.ret = func() interface{} {
536 return math.Ceil(x)
537 }()
538 },
539 }, {
540 Name: "Trunc",
541 Params: []kind{numKind},
542 Result: numKind,
543 Func: func(c *callCtxt) {
544 x := c.float64(0)
545 c.ret = func() interface{} {
546 return math.Trunc(x)
547 }()
548 },
549 }, {
550 Name: "Round",
551 Params: []kind{numKind},
552 Result: numKind,
553 Func: func(c *callCtxt) {
554 x := c.float64(0)
555 c.ret = func() interface{} {
556 return math.Round(x)
557 }()
558 },
559 }, {
560 Name: "RoundToEven",
561 Params: []kind{numKind},
562 Result: numKind,
563 Func: func(c *callCtxt) {
564 x := c.float64(0)
565 c.ret = func() interface{} {
566 return math.RoundToEven(x)
567 }()
568 },
569 }, {
570 Name: "Abs",
571 Params: []kind{numKind},
572 Result: numKind,
573 Func: func(c *callCtxt) {
574 x := c.float64(0)
575 c.ret = func() interface{} {
576 return math.Abs(x)
577 }()
578 },
579 }, {
580 Name: "Acosh",
581 Params: []kind{numKind},
582 Result: numKind,
583 Func: func(c *callCtxt) {
584 x := c.float64(0)
585 c.ret = func() interface{} {
586 return math.Acosh(x)
587 }()
588 },
589 }, {
590 Name: "Asin",
591 Params: []kind{numKind},
592 Result: numKind,
593 Func: func(c *callCtxt) {
594 x := c.float64(0)
595 c.ret = func() interface{} {
596 return math.Asin(x)
597 }()
598 },
599 }, {
600 Name: "Acos",
601 Params: []kind{numKind},
602 Result: numKind,
603 Func: func(c *callCtxt) {
604 x := c.float64(0)
605 c.ret = func() interface{} {
606 return math.Acos(x)
607 }()
608 },
609 }, {
610 Name: "Asinh",
611 Params: []kind{numKind},
612 Result: numKind,
613 Func: func(c *callCtxt) {
614 x := c.float64(0)
615 c.ret = func() interface{} {
616 return math.Asinh(x)
617 }()
618 },
619 }, {
620 Name: "Atan",
621 Params: []kind{numKind},
622 Result: numKind,
623 Func: func(c *callCtxt) {
624 x := c.float64(0)
625 c.ret = func() interface{} {
626 return math.Atan(x)
627 }()
628 },
629 }, {
630 Name: "Atan2",
631 Params: []kind{numKind, numKind},
632 Result: numKind,
633 Func: func(c *callCtxt) {
634 y, x := c.float64(0), c.float64(1)
635 c.ret = func() interface{} {
636 return math.Atan2(y, x)
637 }()
638 },
639 }, {
640 Name: "Atanh",
641 Params: []kind{numKind},
642 Result: numKind,
643 Func: func(c *callCtxt) {
644 x := c.float64(0)
645 c.ret = func() interface{} {
646 return math.Atanh(x)
647 }()
648 },
649 }, {
650 Name: "Cbrt",
651 Params: []kind{numKind},
652 Result: numKind,
653 Func: func(c *callCtxt) {
654 x := c.float64(0)
655 c.ret = func() interface{} {
656 return math.Cbrt(x)
657 }()
658 },
659 }, {
660 Name: "E",
661 Const: "2.71828182845904523536028747135266249775724709369995957496696763",
662 }, {
663 Name: "Pi",
664 Const: "3.14159265358979323846264338327950288419716939937510582097494459",
665 }, {
666 Name: "Phi",
667 Const: "1.61803398874989484820458683436563811772030917980576286213544861",
668 }, {
669 Name: "Sqrt2",
670 Const: "1.41421356237309504880168872420969807856967187537694807317667974",
671 }, {
672 Name: "SqrtE",
673 Const: "1.64872127070012814684865078781416357165377610071014801157507931",
674 }, {
675 Name: "SqrtPi",
676 Const: "1.77245385090551602729816748334114518279754945612238712821380779",
677 }, {
678 Name: "SqrtPhi",
679 Const: "1.27201964951406896425242246173749149171560804184009624861664038",
680 }, {
681 Name: "Ln2",
682 Const: "0.693147180559945309417232121458176568075500134360255254120680009",
683 }, {
684 Name: "Log2E",
685 Const: "1.442695040888963407359924681001892137426645954152985934135449408",
686 }, {
687 Name: "Ln10",
688 Const: "2.3025850929940456840179914546843642076011014886287729760333278",
689 }, {
690 Name: "Log10E",
691 Const: "0.43429448190325182765112891891660508229439700580366656611445378",
692 }, {
693 Name: "Copysign",
694 Params: []kind{numKind, numKind},
695 Result: numKind,
696 Func: func(c *callCtxt) {
697 x, y := c.float64(0), c.float64(1)
698 c.ret = func() interface{} {
699 return math.Copysign(x, y)
700 }()
701 },
702 }, {
703 Name: "Dim",
704 Params: []kind{numKind, numKind},
705 Result: numKind,
706 Func: func(c *callCtxt) {
707 x, y := c.float64(0), c.float64(1)
708 c.ret = func() interface{} {
709 return math.Dim(x, y)
710 }()
711 },
712 }, {
713 Name: "Erf",
714 Params: []kind{numKind},
715 Result: numKind,
716 Func: func(c *callCtxt) {
717 x := c.float64(0)
718 c.ret = func() interface{} {
719 return math.Erf(x)
720 }()
721 },
722 }, {
723 Name: "Erfc",
724 Params: []kind{numKind},
725 Result: numKind,
726 Func: func(c *callCtxt) {
727 x := c.float64(0)
728 c.ret = func() interface{} {
729 return math.Erfc(x)
730 }()
731 },
732 }, {
733 Name: "Erfinv",
734 Params: []kind{numKind},
735 Result: numKind,
736 Func: func(c *callCtxt) {
737 x := c.float64(0)
738 c.ret = func() interface{} {
739 return math.Erfinv(x)
740 }()
741 },
742 }, {
743 Name: "Erfcinv",
744 Params: []kind{numKind},
745 Result: numKind,
746 Func: func(c *callCtxt) {
747 x := c.float64(0)
748 c.ret = func() interface{} {
749 return math.Erfcinv(x)
750 }()
751 },
752 }, {
753 Name: "Exp",
754 Params: []kind{numKind},
755 Result: numKind,
756 Func: func(c *callCtxt) {
757 x := c.float64(0)
758 c.ret = func() interface{} {
759 return math.Exp(x)
760 }()
761 },
762 }, {
763 Name: "Exp2",
764 Params: []kind{numKind},
765 Result: numKind,
766 Func: func(c *callCtxt) {
767 x := c.float64(0)
768 c.ret = func() interface{} {
769 return math.Exp2(x)
770 }()
771 },
772 }, {
773 Name: "Expm1",
774 Params: []kind{numKind},
775 Result: numKind,
776 Func: func(c *callCtxt) {
777 x := c.float64(0)
778 c.ret = func() interface{} {
779 return math.Expm1(x)
780 }()
781 },
782 }, {
783 Name: "Gamma",
784 Params: []kind{numKind},
785 Result: numKind,
786 Func: func(c *callCtxt) {
787 x := c.float64(0)
788 c.ret = func() interface{} {
789 return math.Gamma(x)
790 }()
791 },
792 }, {
793 Name: "Hypot",
794 Params: []kind{numKind, numKind},
795 Result: numKind,
796 Func: func(c *callCtxt) {
797 p, q := c.float64(0), c.float64(1)
798 c.ret = func() interface{} {
799 return math.Hypot(p, q)
800 }()
801 },
802 }, {
803 Name: "J0",
804 Params: []kind{numKind},
805 Result: numKind,
806 Func: func(c *callCtxt) {
807 x := c.float64(0)
808 c.ret = func() interface{} {
809 return math.J0(x)
810 }()
811 },
812 }, {
813 Name: "Y0",
814 Params: []kind{numKind},
815 Result: numKind,
816 Func: func(c *callCtxt) {
817 x := c.float64(0)
818 c.ret = func() interface{} {
819 return math.Y0(x)
820 }()
821 },
822 }, {
823 Name: "J1",
824 Params: []kind{numKind},
825 Result: numKind,
826 Func: func(c *callCtxt) {
827 x := c.float64(0)
828 c.ret = func() interface{} {
829 return math.J1(x)
830 }()
831 },
832 }, {
833 Name: "Y1",
834 Params: []kind{numKind},
835 Result: numKind,
836 Func: func(c *callCtxt) {
837 x := c.float64(0)
838 c.ret = func() interface{} {
839 return math.Y1(x)
840 }()
841 },
842 }, {
843 Name: "Jn",
844 Params: []kind{intKind, numKind},
845 Result: numKind,
846 Func: func(c *callCtxt) {
847 n, x := c.int(0), c.float64(1)
848 c.ret = func() interface{} {
849 return math.Jn(n, x)
850 }()
851 },
852 }, {
853 Name: "Yn",
854 Params: []kind{intKind, numKind},
855 Result: numKind,
856 Func: func(c *callCtxt) {
857 n, x := c.int(0), c.float64(1)
858 c.ret = func() interface{} {
859 return math.Yn(n, x)
860 }()
861 },
862 }, {
863 Name: "Ldexp",
864 Params: []kind{numKind, intKind},
865 Result: numKind,
866 Func: func(c *callCtxt) {
867 frac, exp := c.float64(0), c.int(1)
868 c.ret = func() interface{} {
869 return math.Ldexp(frac, exp)
870 }()
871 },
872 }, {
873 Name: "Log",
874 Params: []kind{numKind},
875 Result: numKind,
876 Func: func(c *callCtxt) {
877 x := c.float64(0)
878 c.ret = func() interface{} {
879 return math.Log(x)
880 }()
881 },
882 }, {
883 Name: "Log10",
884 Params: []kind{numKind},
885 Result: numKind,
886 Func: func(c *callCtxt) {
887 x := c.float64(0)
888 c.ret = func() interface{} {
889 return math.Log10(x)
890 }()
891 },
892 }, {
893 Name: "Log2",
894 Params: []kind{numKind},
895 Result: numKind,
896 Func: func(c *callCtxt) {
897 x := c.float64(0)
898 c.ret = func() interface{} {
899 return math.Log2(x)
900 }()
901 },
902 }, {
903 Name: "Log1p",
904 Params: []kind{numKind},
905 Result: numKind,
906 Func: func(c *callCtxt) {
907 x := c.float64(0)
908 c.ret = func() interface{} {
909 return math.Log1p(x)
910 }()
911 },
912 }, {
913 Name: "Logb",
914 Params: []kind{numKind},
915 Result: numKind,
916 Func: func(c *callCtxt) {
917 x := c.float64(0)
918 c.ret = func() interface{} {
919 return math.Logb(x)
920 }()
921 },
922 }, {
923 Name: "Ilogb",
924 Params: []kind{numKind},
925 Result: intKind,
926 Func: func(c *callCtxt) {
927 x := c.float64(0)
928 c.ret = func() interface{} {
929 return math.Ilogb(x)
930 }()
931 },
932 }, {
933 Name: "Mod",
934 Params: []kind{numKind, numKind},
935 Result: numKind,
936 Func: func(c *callCtxt) {
937 x, y := c.float64(0), c.float64(1)
938 c.ret = func() interface{} {
939 return math.Mod(x, y)
940 }()
941 },
942 }, {
943 Name: "Pow",
944 Params: []kind{numKind, numKind},
945 Result: numKind,
946 Func: func(c *callCtxt) {
947 x, y := c.float64(0), c.float64(1)
948 c.ret = func() interface{} {
949 return math.Pow(x, y)
950 }()
951 },
952 }, {
953 Name: "Pow10",
954 Params: []kind{intKind},
955 Result: numKind,
956 Func: func(c *callCtxt) {
957 n := c.int(0)
958 c.ret = func() interface{} {
959 return math.Pow10(n)
960 }()
961 },
962 }, {
963 Name: "Remainder",
964 Params: []kind{numKind, numKind},
965 Result: numKind,
966 Func: func(c *callCtxt) {
967 x, y := c.float64(0), c.float64(1)
968 c.ret = func() interface{} {
969 return math.Remainder(x, y)
970 }()
971 },
972 }, {
973 Name: "Signbit",
974 Params: []kind{numKind},
975 Result: boolKind,
976 Func: func(c *callCtxt) {
977 x := c.float64(0)
978 c.ret = func() interface{} {
979 return math.Signbit(x)
980 }()
981 },
982 }, {
983 Name: "Cos",
984 Params: []kind{numKind},
985 Result: numKind,
986 Func: func(c *callCtxt) {
987 x := c.float64(0)
988 c.ret = func() interface{} {
989 return math.Cos(x)
990 }()
991 },
992 }, {
993 Name: "Sin",
994 Params: []kind{numKind},
995 Result: numKind,
996 Func: func(c *callCtxt) {
997 x := c.float64(0)
998 c.ret = func() interface{} {
999 return math.Sin(x)
1000 }()
1001 },
1002 }, {
1003 Name: "Sinh",
1004 Params: []kind{numKind},
1005 Result: numKind,
1006 Func: func(c *callCtxt) {
1007 x := c.float64(0)
1008 c.ret = func() interface{} {
1009 return math.Sinh(x)
1010 }()
1011 },
1012 }, {
1013 Name: "Cosh",
1014 Params: []kind{numKind},
1015 Result: numKind,
1016 Func: func(c *callCtxt) {
1017 x := c.float64(0)
1018 c.ret = func() interface{} {
1019 return math.Cosh(x)
1020 }()
1021 },
1022 }, {
1023 Name: "Sqrt",
1024 Params: []kind{numKind},
1025 Result: numKind,
1026 Func: func(c *callCtxt) {
1027 x := c.float64(0)
1028 c.ret = func() interface{} {
1029 return math.Sqrt(x)
1030 }()
1031 },
1032 }, {
1033 Name: "Tan",
1034 Params: []kind{numKind},
1035 Result: numKind,
1036 Func: func(c *callCtxt) {
1037 x := c.float64(0)
1038 c.ret = func() interface{} {
1039 return math.Tan(x)
1040 }()
1041 },
1042 }, {
1043 Name: "Tanh",
1044 Params: []kind{numKind},
1045 Result: numKind,
1046 Func: func(c *callCtxt) {
1047 x := c.float64(0)
1048 c.ret = func() interface{} {
1049 return math.Tanh(x)
1050 }()
1051 },
1052 }},
1053 },
1054 "math/bits": &builtinPkg{
1055 native: []*builtin{{
1056 Name: "And",
1057 Params: []kind{intKind, intKind},
1058 Result: intKind,
1059 Func: func(c *callCtxt) {
1060 a, b := c.bigInt(0), c.bigInt(1)
1061 c.ret = func() interface{} {
1062 wa := a.Bits()
1063 wb := b.Bits()
1064 n := len(wa)
1065 if len(wb) < n {
1066 n = len(wb)
1067 }
1068 w := make([]big.Word, n)
1069 for i := range w {
1070 w[i] = wa[i] & wb[i]
1071 }
1072 i := &big.Int{}
1073 i.SetBits(w)
1074 return i
1075 }()
1076 },
1077 }, {
1078 Name: "Or",
1079 Params: []kind{intKind, intKind},
1080 Result: intKind,
1081 Func: func(c *callCtxt) {
1082 a, b := c.bigInt(0), c.bigInt(1)
1083 c.ret = func() interface{} {
1084 wa := a.Bits()
1085 wb := b.Bits()
1086 var w []big.Word
1087 n := len(wa)
1088 if len(wa) > len(wb) {
1089 w = append(w, wa...)
1090 n = len(wb)
1091 } else {
1092 w = append(w, wb...)
1093 }
1094 for i := 0; i < n; i++ {
1095 w[i] = wa[i] | wb[i]
1096 }
1097 i := &big.Int{}
1098 i.SetBits(w)
1099 return i
1100 }()
1101 },
1102 }, {
1103 Name: "Xor",
1104 Params: []kind{intKind, intKind},
1105 Result: intKind,
1106 Func: func(c *callCtxt) {
1107 a, b := c.bigInt(0), c.bigInt(1)
1108 c.ret = func() interface{} {
1109 wa := a.Bits()
1110 wb := b.Bits()
1111 var w []big.Word
1112 n := len(wa)
1113 if len(wa) > len(wb) {
1114 w = append(w, wa...)
1115 n = len(wb)
1116 } else {
1117 w = append(w, wb...)
1118 }
1119 for i := 0; i < n; i++ {
1120 w[i] = wa[i] ^ wb[i]
1121 }
1122 i := &big.Int{}
1123 i.SetBits(w)
1124 return i
1125 }()
1126 },
1127 }, {
1128 Name: "Clear",
1129 Params: []kind{intKind, intKind},
1130 Result: intKind,
1131 Func: func(c *callCtxt) {
1132 a, b := c.bigInt(0), c.bigInt(1)
1133 c.ret = func() interface{} {
1134 wa := a.Bits()
1135 wb := b.Bits()
1136 w := append([]big.Word(nil), wa...)
1137 for i, m := range wb {
1138 if i >= len(w) {
1139 break
1140 }
1141 w[i] = wa[i] &^ m
1142 }
1143 i := &big.Int{}
1144 i.SetBits(w)
1145 return i
1146 }()
1147 },
1148 }, {
1149 Name: "OnesCount",
1150 Params: []kind{intKind},
1151 Result: intKind,
1152 Func: func(c *callCtxt) {
1153 x := c.uint64(0)
1154 c.ret = func() interface{} {
1155 return bits.OnesCount64(x)
1156 }()
1157 },
1158 }, {
1159 Name: "RotateLeft",
1160 Params: []kind{intKind, intKind},
1161 Result: intKind,
1162 Func: func(c *callCtxt) {
1163 x, k := c.uint64(0), c.int(1)
1164 c.ret = func() interface{} {
1165 return bits.RotateLeft64(x, k)
1166 }()
1167 },
1168 }, {
1169 Name: "Reverse",
1170 Params: []kind{intKind},
1171 Result: intKind,
1172 Func: func(c *callCtxt) {
1173 x := c.uint64(0)
1174 c.ret = func() interface{} {
1175 return bits.Reverse64(x)
1176 }()
1177 },
1178 }, {
1179 Name: "ReverseBytes",
1180 Params: []kind{intKind},
1181 Result: intKind,
1182 Func: func(c *callCtxt) {
1183 x := c.uint64(0)
1184 c.ret = func() interface{} {
1185 return bits.ReverseBytes64(x)
1186 }()
1187 },
1188 }, {
1189 Name: "Len",
1190 Params: []kind{intKind},
1191 Result: intKind,
1192 Func: func(c *callCtxt) {
1193 x := c.uint64(0)
1194 c.ret = func() interface{} {
1195 return bits.Len64(x)
1196 }()
1197 },
1198 }},
1199 },
1200 "path": &builtinPkg{
1201 native: []*builtin{{
1202 Name: "Split",
1203 Params: []kind{stringKind},
1204 Result: listKind,
1205 Func: func(c *callCtxt) {
1206 path := c.string(0)
1207 c.ret = func() interface{} {
1208 file, dir := split(path)
1209 return []string{file, dir}
1210 }()
1211 },
1212 }, {
1213 Name: "Match",
1214 Params: []kind{stringKind, stringKind},
1215 Result: boolKind,
1216 Func: func(c *callCtxt) {
1217 pattern, name := c.string(0), c.string(1)
1218 c.ret, c.err = func() (interface{}, error) {
1219 return path.Match(pattern, name)
1220 }()
1221 },
1222 }, {
1223 Name: "Clean",
1224 Params: []kind{stringKind},
1225 Result: stringKind,
1226 Func: func(c *callCtxt) {
1227 path := c.string(0)
1228 c.ret = func() interface{} {
1229 return pathClean(path)
1230 }()
1231 },
1232 }, {
1233 Name: "Ext",
1234 Params: []kind{stringKind},
1235 Result: stringKind,
1236 Func: func(c *callCtxt) {
1237 path := c.string(0)
1238 c.ret = func() interface{} {
1239 return pathExt(path)
1240 }()
1241 },
1242 }, {
1243 Name: "Base",
1244 Params: []kind{stringKind},
1245 Result: stringKind,
1246 Func: func(c *callCtxt) {
1247 path := c.string(0)
1248 c.ret = func() interface{} {
1249 return pathBase(path)
1250 }()
1251 },
1252 }, {
1253 Name: "IsAbs",
1254 Params: []kind{stringKind},
1255 Result: boolKind,
1256 Func: func(c *callCtxt) {
1257 path := c.string(0)
1258 c.ret = func() interface{} {
1259 return pathIsAbs(path)
1260 }()
1261 },
1262 }, {
1263 Name: "Dir",
1264 Params: []kind{stringKind},
1265 Result: stringKind,
1266 Func: func(c *callCtxt) {
1267 path := c.string(0)
1268 c.ret = func() interface{} {
1269 return pathDir(path)
1270 }()
1271 },
1272 }},
1273 },
1274 "regexp": &builtinPkg{
1275 native: []*builtin{{
1276 Name: "Match",
1277 Params: []kind{stringKind, stringKind},
1278 Result: boolKind,
1279 Func: func(c *callCtxt) {
1280 pattern, s := c.string(0), c.string(1)
1281 c.ret, c.err = func() (interface{}, error) {
1282 return regexp.MatchString(pattern, s)
1283 }()
1284 },
1285 }, {
1286 Name: "QuoteMeta",
1287 Params: []kind{stringKind},
1288 Result: stringKind,
1289 Func: func(c *callCtxt) {
1290 s := c.string(0)
1291 c.ret = func() interface{} {
1292 return regexp.QuoteMeta(s)
1293 }()
1294 },
1295 }},
1296 },
Marcel van Lohuizen57333362019-04-01 14:35:09 +02001297 "strconv": &builtinPkg{
1298 native: []*builtin{{
1299 Name: "Unquote",
1300 Params: []kind{stringKind},
1301 Result: stringKind,
1302 Func: func(c *callCtxt) {
1303 s := c.string(0)
1304 c.ret, c.err = func() (interface{}, error) {
1305 return literal.Unquote(s)
1306 }()
1307 },
1308 }, {
1309 Name: "ParseBool",
1310 Params: []kind{stringKind},
1311 Result: boolKind,
1312 Func: func(c *callCtxt) {
1313 str := c.string(0)
1314 c.ret, c.err = func() (interface{}, error) {
1315 return strconv.ParseBool(str)
1316 }()
1317 },
1318 }, {
1319 Name: "FormatBool",
1320 Params: []kind{boolKind},
1321 Result: stringKind,
1322 Func: func(c *callCtxt) {
1323 b := c.bool(0)
1324 c.ret = func() interface{} {
1325 return strconv.FormatBool(b)
1326 }()
1327 },
1328 }, {
1329 Name: "ParseFloat",
1330 Params: []kind{stringKind, intKind},
1331 Result: numKind,
1332 Func: func(c *callCtxt) {
1333 s, bitSize := c.string(0), c.int(1)
1334 c.ret, c.err = func() (interface{}, error) {
1335 return strconv.ParseFloat(s, bitSize)
1336 }()
1337 },
1338 }, {
1339 Name: "IntSize",
1340 Const: "64",
1341 }, {
1342 Name: "ParseUint",
1343 Params: []kind{stringKind, intKind, intKind},
1344 Result: intKind,
1345 Func: func(c *callCtxt) {
1346 s, base, bitSize := c.string(0), c.int(1), c.int(2)
1347 c.ret, c.err = func() (interface{}, error) {
1348 return strconv.ParseUint(s, base, bitSize)
1349 }()
1350 },
1351 }, {
1352 Name: "ParseInt",
1353 Params: []kind{stringKind, intKind, intKind},
1354 Result: intKind,
1355 Func: func(c *callCtxt) {
1356 s, base, bitSize := c.string(0), c.int(1), c.int(2)
1357 c.ret, c.err = func() (interface{}, error) {
1358 return strconv.ParseInt(s, base, bitSize)
1359 }()
1360 },
1361 }, {
1362 Name: "Atoi",
1363 Params: []kind{stringKind},
1364 Result: intKind,
1365 Func: func(c *callCtxt) {
1366 s := c.string(0)
1367 c.ret, c.err = func() (interface{}, error) {
1368 return strconv.Atoi(s)
1369 }()
1370 },
1371 }, {
1372 Name: "FormatFloat",
1373 Params: []kind{numKind, intKind, intKind, intKind},
1374 Result: stringKind,
1375 Func: func(c *callCtxt) {
1376 f, fmt, prec, bitSize := c.float64(0), c.byte(1), c.int(2), c.int(3)
1377 c.ret = func() interface{} {
1378 return strconv.FormatFloat(f, fmt, prec, bitSize)
1379 }()
1380 },
1381 }, {
1382 Name: "FormatUint",
1383 Params: []kind{intKind, intKind},
1384 Result: stringKind,
1385 Func: func(c *callCtxt) {
1386 i, base := c.uint64(0), c.int(1)
1387 c.ret = func() interface{} {
1388 return strconv.FormatUint(i, base)
1389 }()
1390 },
1391 }, {
1392 Name: "FormatInt",
1393 Params: []kind{intKind, intKind},
1394 Result: stringKind,
1395 Func: func(c *callCtxt) {
1396 i, base := c.int64(0), c.int(1)
1397 c.ret = func() interface{} {
1398 return strconv.FormatInt(i, base)
1399 }()
1400 },
1401 }, {
1402 Name: "Quote",
1403 Params: []kind{stringKind},
1404 Result: stringKind,
1405 Func: func(c *callCtxt) {
1406 s := c.string(0)
1407 c.ret = func() interface{} {
1408 return strconv.Quote(s)
1409 }()
1410 },
1411 }, {
1412 Name: "QuoteToASCII",
1413 Params: []kind{stringKind},
1414 Result: stringKind,
1415 Func: func(c *callCtxt) {
1416 s := c.string(0)
1417 c.ret = func() interface{} {
1418 return strconv.QuoteToASCII(s)
1419 }()
1420 },
1421 }, {
1422 Name: "QuoteToGraphic",
1423 Params: []kind{stringKind},
1424 Result: stringKind,
1425 Func: func(c *callCtxt) {
1426 s := c.string(0)
1427 c.ret = func() interface{} {
1428 return strconv.QuoteToGraphic(s)
1429 }()
1430 },
1431 }, {
1432 Name: "QuoteRune",
1433 Params: []kind{intKind},
1434 Result: stringKind,
1435 Func: func(c *callCtxt) {
1436 r := c.rune(0)
1437 c.ret = func() interface{} {
1438 return strconv.QuoteRune(r)
1439 }()
1440 },
1441 }, {
1442 Name: "QuoteRuneToASCII",
1443 Params: []kind{intKind},
1444 Result: stringKind,
1445 Func: func(c *callCtxt) {
1446 r := c.rune(0)
1447 c.ret = func() interface{} {
1448 return strconv.QuoteRuneToASCII(r)
1449 }()
1450 },
1451 }, {
1452 Name: "QuoteRuneToGraphic",
1453 Params: []kind{intKind},
1454 Result: stringKind,
1455 Func: func(c *callCtxt) {
1456 r := c.rune(0)
1457 c.ret = func() interface{} {
1458 return strconv.QuoteRuneToGraphic(r)
1459 }()
1460 },
1461 }, {
1462 Name: "CanBackquote",
1463 Params: []kind{stringKind},
1464 Result: boolKind,
1465 Func: func(c *callCtxt) {
1466 s := c.string(0)
1467 c.ret = func() interface{} {
1468 return strconv.CanBackquote(s)
1469 }()
1470 },
1471 }, {
1472 Name: "IsPrint",
1473 Params: []kind{intKind},
1474 Result: boolKind,
1475 Func: func(c *callCtxt) {
1476 r := c.rune(0)
1477 c.ret = func() interface{} {
1478 return strconv.IsPrint(r)
1479 }()
1480 },
1481 }, {
1482 Name: "IsGraphic",
1483 Params: []kind{intKind},
1484 Result: boolKind,
1485 Func: func(c *callCtxt) {
1486 r := c.rune(0)
1487 c.ret = func() interface{} {
1488 return strconv.IsGraphic(r)
1489 }()
1490 },
1491 }},
1492 },
1493 "strings": &builtinPkg{
1494 native: []*builtin{{
1495 Name: "ToTitle",
1496 Params: []kind{stringKind},
1497 Result: stringKind,
1498 Func: func(c *callCtxt) {
1499 s := c.string(0)
1500 c.ret = func() interface{} {
1501
1502 prev := ' '
1503 return strings.Map(
1504 func(r rune) rune {
1505 if unicode.IsSpace(prev) {
1506 prev = r
1507 return unicode.ToTitle(r)
1508 }
1509 prev = r
1510 return r
1511 },
1512 s)
1513 }()
1514 },
1515 }, {
1516 Name: "ToCamel",
1517 Params: []kind{stringKind},
1518 Result: stringKind,
1519 Func: func(c *callCtxt) {
1520 s := c.string(0)
1521 c.ret = func() interface{} {
1522
1523 prev := ' '
1524 return strings.Map(
1525 func(r rune) rune {
1526 if unicode.IsSpace(prev) {
1527 prev = r
1528 return unicode.ToLower(r)
1529 }
1530 prev = r
1531 return r
1532 },
1533 s)
1534 }()
1535 },
1536 }, {
1537 Name: "Compare",
1538 Params: []kind{stringKind, stringKind},
1539 Result: intKind,
1540 Func: func(c *callCtxt) {
1541 a, b := c.string(0), c.string(1)
1542 c.ret = func() interface{} {
1543 return strings.Compare(a, b)
1544 }()
1545 },
1546 }, {
1547 Name: "Count",
1548 Params: []kind{stringKind, stringKind},
1549 Result: intKind,
1550 Func: func(c *callCtxt) {
1551 s, substr := c.string(0), c.string(1)
1552 c.ret = func() interface{} {
1553 return strings.Count(s, substr)
1554 }()
1555 },
1556 }, {
1557 Name: "Contains",
1558 Params: []kind{stringKind, stringKind},
1559 Result: boolKind,
1560 Func: func(c *callCtxt) {
1561 s, substr := c.string(0), c.string(1)
1562 c.ret = func() interface{} {
1563 return strings.Contains(s, substr)
1564 }()
1565 },
1566 }, {
1567 Name: "ContainsAny",
1568 Params: []kind{stringKind, stringKind},
1569 Result: boolKind,
1570 Func: func(c *callCtxt) {
1571 s, chars := c.string(0), c.string(1)
1572 c.ret = func() interface{} {
1573 return strings.ContainsAny(s, chars)
1574 }()
1575 },
1576 }, {
1577 Name: "LastIndex",
1578 Params: []kind{stringKind, stringKind},
1579 Result: intKind,
1580 Func: func(c *callCtxt) {
1581 s, substr := c.string(0), c.string(1)
1582 c.ret = func() interface{} {
1583 return strings.LastIndex(s, substr)
1584 }()
1585 },
1586 }, {
1587 Name: "IndexAny",
1588 Params: []kind{stringKind, stringKind},
1589 Result: intKind,
1590 Func: func(c *callCtxt) {
1591 s, chars := c.string(0), c.string(1)
1592 c.ret = func() interface{} {
1593 return strings.IndexAny(s, chars)
1594 }()
1595 },
1596 }, {
1597 Name: "LastIndexAny",
1598 Params: []kind{stringKind, stringKind},
1599 Result: intKind,
1600 Func: func(c *callCtxt) {
1601 s, chars := c.string(0), c.string(1)
1602 c.ret = func() interface{} {
1603 return strings.LastIndexAny(s, chars)
1604 }()
1605 },
1606 }, {
1607 Name: "SplitN",
1608 Params: []kind{stringKind, stringKind, intKind},
1609 Result: listKind,
1610 Func: func(c *callCtxt) {
1611 s, sep, n := c.string(0), c.string(1), c.int(2)
1612 c.ret = func() interface{} {
1613 return strings.SplitN(s, sep, n)
1614 }()
1615 },
1616 }, {
1617 Name: "SplitAfterN",
1618 Params: []kind{stringKind, stringKind, intKind},
1619 Result: listKind,
1620 Func: func(c *callCtxt) {
1621 s, sep, n := c.string(0), c.string(1), c.int(2)
1622 c.ret = func() interface{} {
1623 return strings.SplitAfterN(s, sep, n)
1624 }()
1625 },
1626 }, {
1627 Name: "Split",
1628 Params: []kind{stringKind, stringKind},
1629 Result: listKind,
1630 Func: func(c *callCtxt) {
1631 s, sep := c.string(0), c.string(1)
1632 c.ret = func() interface{} {
1633 return strings.Split(s, sep)
1634 }()
1635 },
1636 }, {
1637 Name: "SplitAfter",
1638 Params: []kind{stringKind, stringKind},
1639 Result: listKind,
1640 Func: func(c *callCtxt) {
1641 s, sep := c.string(0), c.string(1)
1642 c.ret = func() interface{} {
1643 return strings.SplitAfter(s, sep)
1644 }()
1645 },
1646 }, {
1647 Name: "Fields",
1648 Params: []kind{stringKind},
1649 Result: listKind,
1650 Func: func(c *callCtxt) {
1651 s := c.string(0)
1652 c.ret = func() interface{} {
1653 return strings.Fields(s)
1654 }()
1655 },
1656 }, {
1657 Name: "Join",
1658 Params: []kind{listKind, stringKind},
1659 Result: stringKind,
1660 Func: func(c *callCtxt) {
1661 a, sep := c.strList(0), c.string(1)
1662 if c.do() {
1663 c.ret = func() interface{} {
1664 return strings.Join(a, sep)
1665 }()
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +01001666 }
Marcel van Lohuizen57333362019-04-01 14:35:09 +02001667 },
1668 }, {
1669 Name: "HasPrefix",
1670 Params: []kind{stringKind, stringKind},
1671 Result: boolKind,
1672 Func: func(c *callCtxt) {
1673 s, prefix := c.string(0), c.string(1)
1674 c.ret = func() interface{} {
1675 return strings.HasPrefix(s, prefix)
1676 }()
1677 },
1678 }, {
1679 Name: "HasSuffix",
1680 Params: []kind{stringKind, stringKind},
1681 Result: boolKind,
1682 Func: func(c *callCtxt) {
1683 s, suffix := c.string(0), c.string(1)
1684 c.ret = func() interface{} {
1685 return strings.HasSuffix(s, suffix)
1686 }()
1687 },
1688 }, {
1689 Name: "Repeat",
1690 Params: []kind{stringKind, intKind},
1691 Result: stringKind,
1692 Func: func(c *callCtxt) {
1693 s, count := c.string(0), c.int(1)
1694 c.ret = func() interface{} {
1695 return strings.Repeat(s, count)
1696 }()
1697 },
1698 }, {
1699 Name: "ToUpper",
1700 Params: []kind{stringKind},
1701 Result: stringKind,
1702 Func: func(c *callCtxt) {
1703 s := c.string(0)
1704 c.ret = func() interface{} {
1705 return strings.ToUpper(s)
1706 }()
1707 },
1708 }, {
1709 Name: "ToLower",
1710 Params: []kind{stringKind},
1711 Result: stringKind,
1712 Func: func(c *callCtxt) {
1713 s := c.string(0)
1714 c.ret = func() interface{} {
1715 return strings.ToLower(s)
1716 }()
1717 },
1718 }, {
1719 Name: "Trim",
1720 Params: []kind{stringKind, stringKind},
1721 Result: stringKind,
1722 Func: func(c *callCtxt) {
1723 s, cutset := c.string(0), c.string(1)
1724 c.ret = func() interface{} {
1725 return strings.Trim(s, cutset)
1726 }()
1727 },
1728 }, {
1729 Name: "TrimLeft",
1730 Params: []kind{stringKind, stringKind},
1731 Result: stringKind,
1732 Func: func(c *callCtxt) {
1733 s, cutset := c.string(0), c.string(1)
1734 c.ret = func() interface{} {
1735 return strings.TrimLeft(s, cutset)
1736 }()
1737 },
1738 }, {
1739 Name: "TrimRight",
1740 Params: []kind{stringKind, stringKind},
1741 Result: stringKind,
1742 Func: func(c *callCtxt) {
1743 s, cutset := c.string(0), c.string(1)
1744 c.ret = func() interface{} {
1745 return strings.TrimRight(s, cutset)
1746 }()
1747 },
1748 }, {
1749 Name: "TrimSpace",
1750 Params: []kind{stringKind},
1751 Result: stringKind,
1752 Func: func(c *callCtxt) {
1753 s := c.string(0)
1754 c.ret = func() interface{} {
1755 return strings.TrimSpace(s)
1756 }()
1757 },
1758 }, {
1759 Name: "TrimPrefix",
1760 Params: []kind{stringKind, stringKind},
1761 Result: stringKind,
1762 Func: func(c *callCtxt) {
1763 s, prefix := c.string(0), c.string(1)
1764 c.ret = func() interface{} {
1765 return strings.TrimPrefix(s, prefix)
1766 }()
1767 },
1768 }, {
1769 Name: "TrimSuffix",
1770 Params: []kind{stringKind, stringKind},
1771 Result: stringKind,
1772 Func: func(c *callCtxt) {
1773 s, suffix := c.string(0), c.string(1)
1774 c.ret = func() interface{} {
1775 return strings.TrimSuffix(s, suffix)
1776 }()
1777 },
1778 }, {
1779 Name: "Replace",
1780 Params: []kind{stringKind, stringKind, stringKind, intKind},
1781 Result: stringKind,
1782 Func: func(c *callCtxt) {
1783 s, old, new, n := c.string(0), c.string(1), c.string(2), c.int(3)
1784 c.ret = func() interface{} {
1785 return strings.Replace(s, old, new, n)
1786 }()
1787 },
1788 }, {
1789 Name: "Index",
1790 Params: []kind{stringKind, stringKind},
1791 Result: intKind,
1792 Func: func(c *callCtxt) {
1793 s, substr := c.string(0), c.string(1)
1794 c.ret = func() interface{} {
1795 return strings.Index(s, substr)
1796 }()
1797 },
1798 }},
1799 },
1800 "text/tabwriter": &builtinPkg{
1801 native: []*builtin{{
1802 Name: "Write",
1803 Params: []kind{topKind},
1804 Result: stringKind,
1805 Func: func(c *callCtxt) {
1806 data := c.value(0)
1807 c.ret, c.err = func() (interface{}, error) {
1808 buf := &bytes.Buffer{}
1809 tw := tabwriter.NewWriter(buf, 0, 4, 1, ' ', 0)
Marcel van Lohuizenad10d9d2019-04-28 00:22:44 +02001810
1811 write := func(v Value) error {
1812 b, err := v.Bytes()
1813 if err != nil {
1814 return err
1815 }
1816 _, err = tw.Write(b)
1817 if err != nil {
1818 return err
1819 }
1820 return nil
Marcel van Lohuizen57333362019-04-01 14:35:09 +02001821 }
Marcel van Lohuizenad10d9d2019-04-28 00:22:44 +02001822
1823 switch data.Kind() {
1824 case BytesKind, StringKind:
1825 if err := write(data); err != nil {
1826 return "", err
1827 }
1828 case ListKind:
1829 for i, _ := data.List(); i.Next(); {
1830 if err := write(i.Value()); err != nil {
1831 return "", err
1832 }
1833 tw.Write([]byte{'\n'})
1834 }
1835 default:
1836 return "", fmt.Errorf("tabwriter.Write: unsupported type %v", data.Kind())
Marcel van Lohuizen57333362019-04-01 14:35:09 +02001837 }
Marcel van Lohuizenad10d9d2019-04-28 00:22:44 +02001838
1839 err := tw.Flush()
Marcel van Lohuizen57333362019-04-01 14:35:09 +02001840 return buf.String(), err
1841 }()
1842 },
1843 }},
1844 },
1845 "text/template": &builtinPkg{
1846 native: []*builtin{{
1847 Name: "Execute",
1848 Params: []kind{stringKind, topKind},
1849 Result: stringKind,
1850 Func: func(c *callCtxt) {
1851 templ, data := c.string(0), c.value(1)
1852 c.ret, c.err = func() (interface{}, error) {
1853 t, err := template.New("").Parse(templ)
1854 if err != nil {
1855 return "", err
1856 }
1857 buf := &bytes.Buffer{}
1858 if err := t.Execute(buf, data); err != nil {
1859 return "", err
1860 }
1861 return buf.String(), nil
1862 }()
1863 },
1864 }, {
1865 Name: "HTMLEscape",
1866 Params: []kind{stringKind},
1867 Result: stringKind,
1868 Func: func(c *callCtxt) {
1869 s := c.string(0)
1870 c.ret = func() interface{} {
1871 return template.HTMLEscapeString(s)
1872 }()
1873 },
1874 }, {
1875 Name: "JSEscape",
1876 Params: []kind{stringKind},
1877 Result: stringKind,
1878 Func: func(c *callCtxt) {
1879 s := c.string(0)
1880 c.ret = func() interface{} {
1881 return template.JSEscapeString(s)
1882 }()
1883 },
1884 }},
1885 },
1886 "time": &builtinPkg{
1887 native: []*builtin{{}},
1888 cue: `{
1889 Time: null | =~"^\("\\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2]\\d|3[0-1])")T\("([0-1]\\d|2[0-3]):[0-5]\\d:[0-5]\\d")\("(.\\d{1,10})?")\("(Z|(-|\\+)\\d\\d:\\d\\d)")$"
1890}`,
1891 },
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001892 "tool": &builtinPkg{
1893 native: []*builtin{{}},
1894 cue: `{
1895 Command: {
1896 usage?: string
1897 short?: string
1898 long?: string
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001899 tasks <name>: Task
1900 }
Marcel van Lohuizen928bfa32019-04-26 12:16:18 +02001901 Task kind: =~"\\."
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001902}`,
1903 },
1904 "tool/cli": &builtinPkg{
1905 native: []*builtin{{}},
1906 cue: `{
1907 Print: {
Marcel van Lohuizen928bfa32019-04-26 12:16:18 +02001908 kind: *"tool/cli.Print" | "print"
1909 text: string
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001910 }
1911}`,
1912 },
1913 "tool/exec": &builtinPkg{
1914 native: []*builtin{{}},
1915 cue: `{
1916 Run: {
Marcel van Lohuizen928bfa32019-04-26 12:16:18 +02001917 kind: *"tool/exec.Run" | "exec"
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001918 cmd: string | [string, ...string]
1919 install?: string | [string, ...string]
1920 env <Key>: string
1921 stdout: *null | string | bytes
1922 stderr: *null | string | bytes
1923 stdin?: string | bytes
1924 success: bool
1925 }
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001926}`,
1927 },
1928 "tool/file": &builtinPkg{
1929 native: []*builtin{{}},
1930 cue: `{
1931 Read: {
Marcel van Lohuizen83b33c02019-04-26 22:42:16 +02001932 kind: "tool/file.Read"
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001933 filename: !=""
1934 contents: *bytes | string
1935 }
1936 Create: {
Marcel van Lohuizen83b33c02019-04-26 22:42:16 +02001937 kind: "tool/file.Create"
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001938 filename: !=""
1939 contents: bytes | string
1940 permissions: int | *420
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001941 }
1942 Append: {
Marcel van Lohuizen83b33c02019-04-26 22:42:16 +02001943 kind: "tool/file.Append"
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001944 filename: !=""
1945 contents: bytes | string
1946 permissions: int | *420
1947 }
1948 Glob: {
Marcel van Lohuizen83b33c02019-04-26 22:42:16 +02001949 kind: "tool/file.Glob"
1950 glob: !=""
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001951 files: [...string]
1952 }
1953}`,
1954 },
1955 "tool/http": &builtinPkg{
1956 native: []*builtin{{}},
1957 cue: `{
1958 Get: Do & {
1959 method: "GET"
1960 }
1961 Do: {
Marcel van Lohuizen928bfa32019-04-26 12:16:18 +02001962 kind: *"tool/http.Do" | "http"
Marcel van Lohuizenf8132852019-04-26 12:16:18 +02001963 method: string
1964 response: {
1965 body: *bytes | string
1966 header <Name>: string | [...string]
1967 trailer <Name>: string | [...string]
1968 status: string
1969 statusCode: int
1970 }
1971 url: string
1972 request: {
1973 body: *bytes | string
1974 header <Name>: string | [...string]
1975 trailer <Name>: string | [...string]
1976 }
1977 }
1978 Post: Do & {
1979 method: "POST"
1980 }
1981 Put: Do & {
1982 method: "PUT"
1983 }
1984 Delete: Do & {
1985 method: "DELETE"
1986 }
1987}`,
1988 },
Marcel van Lohuizen7b5d2fd2018-12-11 16:34:56 +01001989}