本文整理汇总了Golang中e8vm/io/e8vm/g8/tast.NewRef函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRef函数的具体用法?Golang NewRef怎么用?Golang NewRef使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewRef函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildIdent
func buildIdent(b *builder, ident *lex8.Token) tast.Expr {
s := b.scope.Query(ident.Lit)
if s == nil {
b.Errorf(ident.Pos, "undefined identifier %s", ident.Lit)
return nil
}
b.refSym(s, ident.Pos)
t := s.ObjType.(types.T)
switch s.Type {
case tast.SymVar, tast.SymField:
ref := tast.NewAddressableRef(t)
return &tast.Ident{ident, ref, s}
case tast.SymConst, tast.SymStruct, tast.SymType, tast.SymImport:
ref := tast.NewRef(t)
return &tast.Ident{ident, ref, s}
case tast.SymFunc:
if t, ok := t.(*types.Func); ok {
if t.MethodFunc == nil {
return &tast.Ident{ident, tast.NewRef(t), s}
}
if b.this == nil {
panic("this missing")
}
ref := &tast.Ref{T: t.MethodFunc, Recv: b.this}
return &tast.Ident{ident, ref, s}
}
return &tast.Ident{ident, tast.NewRef(t), s}
default:
b.Errorf(ident.Pos, "todo: token type: %s", tast.SymStr(s.Type))
return nil
}
}
示例2: buildPkgSym
func buildPkgSym(
b *builder, m *ast.MemberExpr, pkg *types.Pkg,
) (*tast.Ref, *sym8.Symbol) {
sym := findPackageSym(b, m.Sub, pkg)
if sym == nil {
return nil, nil
}
if pkg.Lang == "asm8" {
switch sym.Type {
case asm8.SymVar:
return tast.NewRef(types.Uint), sym
case asm8.SymFunc:
return tast.NewRef(types.VoidFunc), sym
}
b.Errorf(m.Sub.Pos, "invalid symbol %s in %s: %s",
m.Sub.Lit, pkg, asm8.SymStr(sym.Type),
)
return nil, nil
}
t := sym.ObjType.(types.T)
switch sym.Type {
case tast.SymConst, tast.SymStruct, tast.SymFunc:
return tast.NewRef(t), sym
case tast.SymVar:
return tast.NewAddressableRef(t), sym
}
b.Errorf(m.Sub.Pos, "bug: invalid symbol %s in %s: %s",
m.Sub.Lit, pkg, tast.SymStr(sym.Type),
)
return nil, nil
}
示例3: binaryOpInt
func binaryOpInt(
b *builder, opTok *lex8.Token, A, B tast.Expr, t types.T,
) tast.Expr {
op := opTok.Lit
switch op {
case "+", "-", "*", "&", "|", "^", "%", "/":
r := tast.NewRef(t)
return &tast.OpExpr{A, opTok, B, r}
case "==", "!=", ">", "<", ">=", "<=":
r := tast.NewRef(types.Bool)
return &tast.OpExpr{A, opTok, B, r}
}
b.Errorf(opTok.Pos, "%q on ints", op)
return nil
}
示例4: buildSlicing
func buildSlicing(
b *builder, expr *ast.IndexExpr, array tast.Expr,
) tast.Expr {
t := array.R().T
et := elementType(t)
if et == nil {
b.Errorf(expr.Lbrack.Pos, "slicing on neither array nor slice")
return nil
}
var indexStart, indexEnd tast.Expr
if expr.Index != nil {
indexStart = buildArrayIndex(b, expr.Index, expr.Lbrack.Pos)
if indexStart == nil {
return nil
}
}
if expr.IndexEnd != nil {
indexEnd = buildArrayIndex(b, expr.IndexEnd, expr.Colon.Pos)
if indexEnd == nil {
return nil
}
}
ref := tast.NewRef(&types.Slice{et})
return &tast.IndexExpr{
Array: array,
Index: indexStart,
IndexEnd: indexEnd,
HasColon: true,
Ref: ref,
}
}
示例5: unaryOpConst
func unaryOpConst(b *builder, opTok *lex8.Token, B tast.Expr) tast.Expr {
op := opTok.Lit
bref := B.R()
if !bref.IsSingle() {
b.Errorf(opTok.Pos, "invalid operation: %q on %s", op, bref)
return nil
}
v, ok := types.NumConst(bref.T)
if !ok {
// TODO: support type const
b.Errorf(opTok.Pos, "typed const operation not implemented")
return nil
}
switch op {
case "+":
return B // just shortcut this
case "-":
return &tast.Const{tast.NewRef(types.NewNumber(-v))}
}
b.Errorf(opTok.Pos, "invalid operation: %q on %s", op, B)
return nil
}
示例6: buildConstMember
func buildConstMember(b *builder, m *ast.MemberExpr) tast.Expr {
obj := b.buildConstExpr(m.Expr)
if obj == nil {
return nil
}
ref := obj.R()
if !ref.IsSingle() {
b.Errorf(m.Dot.Pos, "%s does not have any member", ref)
return nil
}
if pkg, ok := ref.T.(*types.Pkg); ok {
s := findPackageSym(b, m.Sub, pkg)
if s == nil {
return nil
}
if s.Type != tast.SymConst {
b.Errorf(m.Sub.Pos, "%s.%s is not a const", pkg, m.Sub.Lit)
return nil
}
return &tast.Const{tast.NewRef(s.ObjType.(types.T))}
}
b.Errorf(m.Dot.Pos, "expect const expression")
return nil
}
示例7: binaryOpSlice
func binaryOpSlice(b *builder, opTok *lex8.Token, A, B tast.Expr) tast.Expr {
op := opTok.Lit
switch op {
case "==", "!=":
return &tast.OpExpr{A, opTok, B, tast.NewRef(types.Bool)}
}
b.Errorf(opTok.Pos, "%q on slices", op)
return nil
}
示例8: unaryOpBool
func unaryOpBool(b *builder, opTok *lex8.Token, B tast.Expr) tast.Expr {
op := opTok.Lit
if op == "!" {
t := B.R().T
return &tast.OpExpr{nil, opTok, B, tast.NewRef(t)}
}
b.Errorf(opTok.Pos, "invalid operation: %q on boolean", op)
return nil
}
示例9: binaryOpBool
func binaryOpBool(b *builder, opTok *lex8.Token, A, B tast.Expr) tast.Expr {
op := opTok.Lit
switch op {
case "==", "!=", "&&", "||":
r := tast.NewRef(types.Bool)
return &tast.OpExpr{A, opTok, B, r}
}
b.Errorf(opTok.Pos, "%q on bools", op)
return nil
}
示例10: buildMethod
func buildMethod(b *builder, f *pkgFunc) *tast.Func {
this := f.recv.pt
b.thisType = this
if f.f.Recv != nil { // go-like, explicit receiver
b.this = tast.NewAddressableRef(this)
} else { // inlined
b.this = tast.NewRef(this)
b.scope.PushTable(f.recv.t.Syms)
defer b.scope.Pop()
}
return buildFunc(b, f)
}
示例11: unaryOpInt
func unaryOpInt(b *builder, opTok *lex8.Token, B tast.Expr) tast.Expr {
op := opTok.Lit
switch op {
case "+":
return B
case "-", "^":
t := B.R().T
return &tast.OpExpr{nil, opTok, B, tast.NewRef(t)}
}
b.Errorf(opTok.Pos, "invalid operation: %q on %s", op, B)
return nil
}
示例12: buildCallLen
func buildCallLen(b *builder, expr *ast.CallExpr, f tast.Expr) tast.Expr {
args := buildExprList(b, expr.Args)
if args == nil {
return nil
}
ref := args.R()
if !ref.IsSingle() {
b.Errorf(expr.Lparen.Pos, "len() takes one argument")
return nil
}
t := ref.T
switch t.(type) {
case *types.Slice:
return &tast.CallExpr{f, args, tast.NewRef(types.Int)}
case *types.Array:
return &tast.CallExpr{f, args, tast.NewRef(types.Int)}
}
b.Errorf(expr.Lparen.Pos, "len() does not take %s", t)
return nil
}
示例13: buildConstIdent
func buildConstIdent(b *builder, ident *lex8.Token) tast.Expr {
s := b.scope.Query(ident.Lit)
if s == nil {
b.Errorf(ident.Pos, "undefined identifier %s", ident.Lit)
return nil
}
b.refSym(s, ident.Pos)
t := s.ObjType.(types.T)
switch s.Type {
case tast.SymConst:
ref := tast.NewRef(t)
return &tast.Const{ref}
case tast.SymStruct, tast.SymType, tast.SymImport:
ref := tast.NewRef(t)
return &tast.Ident{ident, ref, s}
}
b.Errorf(ident.Pos, "%s is a %s; expect a const",
ident.Lit, tast.SymStr(s.Type),
)
return nil
}
示例14: refAddress
func refAddress(b *builder, opTok *lex8.Token, B tast.Expr) tast.Expr {
op := opTok.Lit
opPos := opTok.Pos
bref := B.R()
if types.IsType(bref.T) || !bref.IsSingle() {
b.Errorf(opPos, "%q on %s", op, bref)
return nil
} else if !bref.Addressable {
b.Errorf(opPos, "reading address of non-addressable")
return nil
}
r := tast.NewRef(&types.Pointer{bref.T})
return &tast.OpExpr{nil, opTok, B, r}
}
示例15: binaryOpPtr
func binaryOpPtr(b *builder, opTok *lex8.Token, A, B tast.Expr) tast.Expr {
op := opTok.Lit
atyp := A.R().T
btyp := B.R().T
switch op {
case "==", "!=":
if types.IsNil(atyp) {
A = tast.NewCast(A, btyp)
} else if types.IsNil(btyp) {
B = tast.NewCast(B, atyp)
}
return &tast.OpExpr{A, opTok, B, tast.NewRef(types.Bool)}
}
b.Errorf(opTok.Pos, "%q on pointers", op)
return nil
}