示例#1
0
        internal bool GetType(out object value)
        {
            if (this.trapOnReference)
            {
                switch (ReferenceTrap.GetTrapKind(this.val))
                {
                case TrapKind.TRAP_UNBOUND:
                    value = 0;
                    break;

                case TrapKind.TRAP_UNASSIGNED:
                    value = 1;
                    break;

                case TrapKind.TRAP_MACRO:
                    value = 3;
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            else
            {
                value = 2; // NORMAL
            }
            return(false);
        }
示例#2
0
        public static TrapKind GetTrapKind(object value)
        {
            ReferenceTrap reftrap = value as ReferenceTrap;

            if (reftrap == null)
            {
                return(TrapKind.NON_TRAP_KIND);
            }
            else if (reftrap == expensive)
            {
                return(TrapKind.TRAP_EXPENSIVE);
            }
            else if (reftrap == unassigned)
            {
                return(TrapKind.TRAP_UNASSIGNED);
            }
            else if (reftrap == unbound)
            {
                return(TrapKind.TRAP_UNBOUND);
            }
            else
            {
                return((TrapKind)(reftrap.contents.Car));
            }
        }
示例#3
0
        public static bool PrimitiveObjectRef(ref object answer, object arg0, object arg1)
        {
            ReferenceTrap reftrap = arg0 as ReferenceTrap;

            if (reftrap != null)
            {
                int idx = (int)arg1;
                if (idx == 0)
                {
                    answer = (((Cons)(reftrap.Contents)).Car);
                }
                else if (idx == 1)
                {
                    answer = (((Cons)(reftrap.Contents)).Cdr);
                }
                else
                {
                    throw new NotImplementedException();
                }
            }
            else
            {
                throw new NotImplementedException();
            }
            return(false);
        }
示例#4
0
        public static bool PrimitiveObjectSetType(out object answer, object arg0, object arg1)
        {
            TC newType = (TC)(int)arg0;

            switch (newType)
            {
            case TC.CONSTANT:
                answer = Constant.Decode((uint)(int)arg1);
                break;

            case TC.FIXNUM:
                answer = (arg1 == null) ? 9
                        : (arg1 is SchemeObject) ? (int)((SchemeObject)arg1).GetHashCode()
                        : arg1.GetHashCode();
                break;

            case TC.MANIFEST_NM_VECTOR:
                answer = arg1;
                break;

            case TC.MANIFEST_SPECIAL_NM_VECTOR:
                answer = new ManifestSpecialNMVector((int)arg1);
                break;

            case TC.NON_MARKED_VECTOR:
                answer = new NonMarkedVector(arg1);
                break;

            case TC.REFERENCE_TRAP:
                answer = ReferenceTrap.Make(arg1);
                break;

            case TC.VECTOR:
                answer = ((NonMarkedVector)arg1).contents;
                break;

            default:
                throw new NotImplementedException();
            }
            return(false);
        }
示例#5
0
        internal bool SafeGetValue(out object value)
        {
            if (this.trapOnReference)
            {
                switch (ReferenceTrap.GetTrapKind(this.val))
                {
                case TrapKind.TRAP_MACRO:
                    value = this.val;
                    break;

                default:
                    throw new NotImplementedException();
                }
                return(false);
            }
            else
            {
                value = this.val;
                return(false);
            }
        }
示例#6
0
        public static bool ObjectDatum(out object answer, object arg)
        {
            Primitive prim = arg as Primitive;

            // make.scm does this song and dance with a primitive to find
            // if it exists.  We just sidestep by hacking object-datum to
            // return the primitive itself!
            if (prim != null)
            {
                answer = prim;
            }

            else if (arg is bool && (bool)arg == false)
            {
                answer = 0;
            }
            else if (arg == null)
            {
                answer = 9;
            }
            else if (arg is Int32)
            {
                answer = arg;
            }
            else if (arg is long)
            {
                answer = arg;
            }

            ////else {
            ////    int probe;
            ////    if (objectDatumDictionary.TryGetValue (arg, out probe)) {
            ////        return probe);
            ////    }
            ////    int datum = objectDatumCounter;
            ////    objectDatumDictionary.Add (arg, datum);
            ////    datumObjectDictionary.Add (datum, arg);
            ////    objectDatumCounter += 1;
            ////    return datum);
            else if (arg is ReferenceTrap)
            {
                ReferenceTrap rarg = (ReferenceTrap)arg;
                TrapKind      kind = ReferenceTrap.GetTrapKind(rarg);
                if (kind == TrapKind.TRAP_UNASSIGNED ||
                    kind == TrapKind.TRAP_UNBOUND ||
                    kind == TrapKind.TRAP_EXPENSIVE)
                {
                    answer = (int)kind;
                }
                else
                {
                    answer = arg.GetHashCode();
                }
            }
            else
            {
                answer = arg.GetHashCode();
            }
            if (answer is int && (int)answer < 0)
            {
                Debugger.Break();
            }
            return(false);
        }