Example #1
0
 public element(Value m = default, Value k = default, types.Type t = default, token.Pos pos = default)
 {
     this.m   = m;
     this.k   = k;
     this.t   = t;
     this.pos = pos;
 }
 public selectionKey(types.SelectionKind kind = default, types.Type recv = default, types.Object obj = default, @string index = default, bool indirect = default)
 {
     this.kind     = kind;
     this.recv     = recv;
     this.obj      = obj;
     this.index    = index;
     this.indirect = indirect;
 }
Example #3
0
File: value.cs Project: zjmit/go2cs
                            // hashType returns a hash for t such that
                            // types.Identical(x, y) => hashType(x) == hashType(y).
                            private static long hashType(types.Type t)
                            {
                                mu.Lock();
                                var h = int(hasher.Hash(t));

                                mu.Unlock();
                                return(h);
                            }
Example #4
0
File: value.cs Project: zjmit/go2cs
                            // nil-tolerant variant of types.Identical.
                            private static bool sameType(types.Type x, types.Type y)
                            {
                                if (x == null)
                                {
                                    return(y == null);
                                }

                                return(y != null && types.Identical(x, y));
                            }
Example #5
0
 public FreeVar(@string name = default, types.Type typ = default, token.Pos pos = default, ref ptr <Function> parent = default, slice <Instruction> referrers = default, Value outer = default)
 {
     this.name      = name;
     this.typ       = typ;
     this.pos       = pos;
     this.parent    = parent;
     this.referrers = referrers;
     this.outer     = outer;
 }
Example #6
0
File: value.cs Project: zjmit/go2cs
                            private static long hash(this array x, types.Type t)
                            {
                                long h = 0L;
                                ptr <types.Array> tElt = t.Underlying()._ <ptr <types.Array> >().Elem();

                                foreach (var(_, xi) in x)
                                {
                                    h += hash(tElt, xi);
                                }
                                return(h);
                            }
Example #7
0
File: value.cs Project: zjmit/go2cs
                            private static bool eq(this array x, types.Type t, object _y)
                            {
                                array             y    = _y._ <array>();
                                ptr <types.Array> tElt = t.Underlying()._ <ptr <types.Array> >().Elem();

                                foreach (var(i, xi) in x)
                                {
                                    if (!equals(tElt, xi, y[i]))
                                    {
                                        return(false);
                                    }
                                }
                                return(true);
                            }
Example #8
0
File: value.cs Project: zjmit/go2cs
                            private static long hash(this structure x, types.Type t)
                            {
                                ptr <types.Struct> tStruct = t.Underlying()._ <ptr <types.Struct> >();
                                long h = 0L;

                                for (long i = 0L;
                                     var n = tStruct.NumFields(); i < n; i++)
                                {
                                    {
                                        var f = tStruct.Field(i);

                                        if (!f.Anonymous())
                                        {
                                            h += hash(f.Type(), x[i]);
                                        }
                                    }
                                }

                                return(h);
                            }
Example #9
0
File: value.cs Project: zjmit/go2cs
                            // usesBuiltinMap returns true if the built-in hash function and
                            // equivalence relation for type t are consistent with those of the
                            // interpreter's representation of type t.  Such types are: all basic
                            // types (bool, numbers, string), pointers and channels.
                            //
                            // usesBuiltinMap returns false for types that require a custom map
                            // implementation: interfaces, arrays and structs.
                            //
                            // Panic ensues if t is an invalid map key type: function, map or slice.
                            private static bool usesBuiltinMap(types.Type t) => func((_, panic, __) =>
                            {
                                switch (t.type())
                                {
                                case ptr <types.Basic> t:
                                    return(true);

                                    break;

                                case ptr <types.Chan> t:
                                    return(true);

                                    break;

                                case ptr <types.Pointer> t:
                                    return(true);

                                    break;

                                case ptr <types.Named> t:
                                    return(usesBuiltinMap(t.Underlying()));

                                    break;

                                case ptr <types.Interface> t:
                                    return(false);

                                    break;

                                case ptr <types.Array> t:
                                    return(false);

                                    break;

                                case ptr <types.Struct> t:
                                    return(false);

                                    break;
                                }
                                panic(fmt.Sprintf("invalid map key type: %T", t));
                            });
Example #10
0
File: value.cs Project: zjmit/go2cs
                            private static bool eq(this structure x, types.Type t, object _y)
                            {
                                structure          y       = _y._ <structure>();
                                ptr <types.Struct> tStruct = t.Underlying()._ <ptr <types.Struct> >();

                                for (long i = 0L;
                                     var n = tStruct.NumFields(); i < n; i++)
                                {
                                    {
                                        var f = tStruct.Field(i);

                                        if (!f.Anonymous())
                                        {
                                            if (!equals(f.Type(), x[i], y[i]))
                                            {
                                                return(false);
                                            }
                                        }
                                    }
                                }

                                return(true);
                            }
Example #11
0
File: value.cs Project: zjmit/go2cs
 private static long hash(this rtype x, types.Type _)
 {
     return(hashType(x.t));
 }
Example #12
0
File: value.cs Project: zjmit/go2cs
 private static long hash(this iface x, types.Type _)
 {
     return(hashType(x.t) * 8581L + hash(x.t, x.v));
 }
Example #13
0
File: value.cs Project: zjmit/go2cs
                            private static bool eq(this iface x, types.Type t, object _y)
                            {
                                iface y = _y._ <iface>();

                                return(sameType(x.t, y.t) && (x.t == null || equals(x.t, x.v, y.v)));
                            }
Example #14
0
File: types.cs Project: zjmit/go2cs
 // matchArgType reports an error if printf verb t is not appropriate
 // for operand arg.
 //
 // typ is used only for recursive calls; external callers must supply nil.
 //
 // (Recursion arises from the compound types {map,chan,slice} which
 // may be printed with %d etc. if that is appropriate for their element
 // types.)
 private static bool matchArgType(ptr <analysis.Pass> _addr_pass, printfArgType t, types.Type typ, ast.Expr arg)
 {
     ref analysis.Pass pass = ref _addr_pass.val;
Example #15
0
File: print.cs Project: zjmit/go2cs
 private static @string relType(types.Type t, ptr <types.Package> _addr_from)
 {
     ref types.Package from = ref _addr_from.val;
Example #16
0
 public dddSlice(types.Type elem = default)
 {
     this.elem = elem;
 }
Example #17
0
 public entry(types.Type key = default)
 {
     this.key = key;
 }
Example #18
0
 // nilConst returns a nil constant of the specified type, which may
 // be any reference type, including interfaces.
 //
 private static ptr <Const> nilConst(types.Type typ)
 {
     return(_addr_NewConst(null, typ) !);
 }
Example #19
0
 public interpreter(slice <value> osArgs = default, ref ptr <ssa.Program> prog = default, map <ssa.Value, ptr <value> > globals = default, Mode mode = default, ref ptr <ssa.Package> reflectPackage = default, methodSet errorMethods = default, methodSet rtypeMethods = default, types.Type runtimeErrorString = default, types.Sizes sizes = default, int goroutines = default)
 {
     this.osArgs             = osArgs;
     this.prog               = prog;
     this.globals            = globals;
     this.mode               = mode;
     this.reflectPackage     = reflectPackage;
     this.errorMethods       = errorMethods;
     this.rtypeMethods       = rtypeMethods;
     this.runtimeErrorString = runtimeErrorString;
     this.sizes              = sizes;
     this.goroutines         = goroutines;
 }
Example #20
0
 // MethodSet returns the method set of type T.  It is thread-safe.
 //
 // If cache is nil, this function is equivalent to types.NewMethodSet(T).
 // Utility functions can thus expose an optional *MethodSetCache
 // parameter to clients that care about performance.
 //
 private static ptr <types.MethodSet> MethodSet(this ptr <MethodSetCache> _addr_cache, types.Type T) => func((defer, _, __) =>
Example #21
0
File: emit.cs Project: zjmit/go2cs
 // emitNew emits to f a new (heap Alloc) instruction allocating an
 // object of type typ.  pos is the optional source location.
 //
 private static ptr<Alloc> emitNew(ptr<Function> _addr_f, types.Type typ, token.Pos pos)
 {
     ref Function f = ref _addr_f.val;
Example #22
0
 // IntuitiveMethodSet returns the intuitive method set of a type T,
 // which is the set of methods you can call on an addressable value of
 // that type.
 //
 // The result always contains MethodSet(T), and is exactly MethodSet(T)
 // for interface types and for pointer-to-concrete types.
 // For all other concrete types T, the result additionally
 // contains each method belonging to *T if there is no identically
 // named method on T itself.
 //
 // This corresponds to user intuition about method sets;
 // this function is intended only for user interfaces.
 //
 // The order of the result is as for types.MethodSet(T).
 //
 public static slice <ptr <types.Selection> > IntuitiveMethodSet(types.Type T, ptr <MethodSetCache> _addr_msets)
 {
     ref MethodSetCache msets = ref _addr_msets.val;
Example #23
0
 public Global(@string name = default, types.Object @object = default, types.Type typ = default, token.Pos pos = default, ref ptr <Package> Pkg = default)
 {
     this.name    = name;
     this.@object = @object;
     this.typ     = typ;
     this.pos     = pos;
     this.Pkg     = Pkg;
 }
Example #24
0
File: value.cs Project: zjmit/go2cs
 private static bool eq(this rtype x, types.Type _, object y)
 {
     return(types.Identical(x.t, y._ <rtype>().t));
 }
Example #25
0
File: value.cs Project: zjmit/go2cs
 // equals returns true iff x and y are equal according to Go's
 // linguistic equivalence relation for type t.
 // In a well-typed program, the dynamic types of x and y are
 // guaranteed equal.
 private static bool equals(types.Type t, value x, value y) => func((_, panic, __) =>
Example #26
0
 public register(anInstruction anInstruction = default, long num = default, types.Type typ = default, token.Pos pos = default, slice <Instruction> referrers = default)
 {
     this.m_anInstructionRef = new ptr <anInstruction>(anInstruction);
     this.num       = num;
     this.typ       = typ;
     this.pos       = pos;
     this.referrers = referrers;
 }
Example #27
0
 // zeroConst returns a new "zero" constant of the specified type,
 // which must not be an array or struct type: the zero values of
 // aggregates are well-defined but cannot be represented by Const.
 //
 private static ptr <Const> zeroConst(types.Type t) => func((_, panic, __) =>
Example #28
0
 public Parameter(@string name = default, types.Object @object = default, types.Type typ = default, token.Pos pos = default, ref ptr <Function> parent = default, slice <Instruction> referrers = default)
 {
     this.name      = name;
     this.@object   = @object;
     this.typ       = typ;
     this.pos       = pos;
     this.parent    = parent;
     this.referrers = referrers;
 }
Example #29
0
 // NewConst returns a new constant of the specified value and type.
 // val must be valid according to the specification of Const.Value.
 //
 public static ptr <Const> NewConst(constant.Value val, types.Type typ)
 {
     return(addr(new Const(typ, val)));
 }
Example #30
0
 public fixupRecord(ref ptr <types.Named> toUpdate = default, types.Type target = default)
 {
     this.toUpdate = toUpdate;
     this.target   = target;
 }