builtins.go raw
1 package loader
2
3 import (
4 "fmt"
5 "go/ast"
6 "go/parser"
7 "go/token"
8 )
9
10 // injectMoxieByteBuiltins parses __moxie_concat, __moxie_eq, __moxie_lt
11 // declarations for the given package name. Called during the rewrite phase
12 // to make these functions available in any package that uses []byte ops.
13 func injectMoxieByteBuiltins(fset *token.FileSet, pkgName string) *ast.File {
14 src := fmt.Sprintf(`package %s
15
16 func __moxie_concat(a, b []byte) []byte {
17 panic("__moxie_concat: compiler failed to intercept")
18 }
19
20 func __moxie_eq(a, b []byte) bool {
21 panic("__moxie_eq: compiler failed to intercept")
22 }
23
24 func __moxie_lt(a, b []byte) bool {
25 panic("__moxie_lt: compiler failed to intercept")
26 }
27 `, pkgName)
28 f, err := parser.ParseFile(fset, "<moxie:builtins>", src, 0)
29 if err != nil {
30 return nil
31 }
32 return f
33 }
34