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