Exemple #1
0
 public Object GetRealObject(StreamingContext context)
 {
     return(PrimitiveCombination0.Make(this.procedure));
 }
Exemple #2
0
        internal object ReadObject(uint location)
        {
            object probe = null;

            if (this.sharingTable.TryGetValue(location, out probe) == true)
            {
                return(probe);
            }

            EncodedObject encoded =
                heapSection.Contains(location) ? heapSection [location]
                : constSection.Contains(location) ? constSection [location]
                : new EncodedObject(0);
            // Console.WriteLine ("{0}", encoded.TypeCode);
            object first = null;

            switch (encoded.TypeCode)
            {
            case TC.ACCESS:
                return(Access.Make(ReadObject(encoded.Datum),
                                   (Symbol)ReadObject(encoded.Datum + 4)));

            case TC.ASSIGNMENT:
                return(ReadAssignment(encoded.Datum));

            case TC.BIG_FIXNUM:
                return(ReadBignum(encoded.Datum));

            case TC.BIG_FLONUM:
                return(ReadBigFlonum(encoded.Datum));

            case TC.CHARACTER:
                return((char)(encoded.Datum));

            case TC.CHARACTER_STRING:
                return(heapSection.ReadString(encoded.Datum));

            case TC.COMBINATION:
                return(Combination.Make(ReadVector(encoded.Datum)));

            case TC.COMBINATION_1:
                return(Combination1.Make(ReadObject(encoded.Datum),
                                         ReadObject(encoded.Datum + 4)));

            case TC.COMBINATION_2:
                return(Combination2.Make(ReadObject(encoded.Datum),
                                         ReadObject(encoded.Datum + 4),
                                         ReadObject(encoded.Datum + 8)));

            case TC.COMMENT:
                return(Comment.Make(ReadObject(encoded.Datum),
                                    ReadObject(encoded.Datum + 4)));

            case TC.COMPLEX:
                return(new Complex(ReadObject(encoded.Datum),
                                   ReadObject(encoded.Datum + 4)));

            case TC.CONDITIONAL:
                return(Conditional.Make(ReadObject(encoded.Datum),
                                        ReadObject(encoded.Datum + 4),
                                        ReadObject(encoded.Datum + 8)));

            case TC.CONSTANT:
                return(Constant.Decode(encoded.Datum));

            case TC.DEFINITION:
                return(Definition.Make((Symbol)ReadObject(encoded.Datum),
                                       ReadObject(encoded.Datum + 4)));

            case TC.DELAY:
                return(Delay.Make(ReadObject(encoded.Datum)));

            case TC.DISJUNCTION:
                return(Disjunction.Make(ReadObject(encoded.Datum),
                                        ReadObject(encoded.Datum + 4)));

            case TC.EXTENDED_LAMBDA:
                return(ReadExtendedLambda(encoded.Datum));

            case TC.FIXNUM:
                return(encoded.Datum > 0x02000000
                           ? (int)-(0x04000000 - encoded.Datum)
                           : (int)encoded.Datum);

            case TC.INTERNED_SYMBOL:
                return(Symbol.Make(new String((char [])ReadObject(encoded.Datum))));

            case TC.LAMBDA:
                Symbol    name;
                Symbol [] formals;
                ReadFormals(encoded.Datum + 4, out name, out formals);
                return(Lambda.Make(name, formals, SCode.EnsureSCode(ReadObject(encoded.Datum))));

            case TC.LIST:
                object second = ReadObject(encoded.Datum + 4);
                return(new Cons(ReadObject(encoded.Datum),
                                second == sharpF ? null : second));

            case TC.NULL:
                if (encoded.Datum != 0)
                {
                    throw new NotImplementedException();
                }
                return(sharpF);

            case TC.PCOMB0:
                return(PrimitiveCombination0.Make((Primitive0)primSection[encoded.Datum]));

            case TC.PCOMB1:
                return(PrimitiveCombination1.Make((Primitive1)ReadObject(encoded.Datum),
                                                  ReadObject(encoded.Datum + 4)));

            case TC.PCOMB2:
                return(PrimitiveCombination2.Make((Primitive2)ReadObject(encoded.Datum),
                                                  ReadObject(encoded.Datum + 4),
                                                  ReadObject(encoded.Datum + 8)));

            case TC.PCOMB3:
                return(PrimitiveCombination3.Make((Primitive3)ReadObject(encoded.Datum + 4),
                                                  ReadObject(encoded.Datum + 8),
                                                  ReadObject(encoded.Datum + 12),
                                                  ReadObject(encoded.Datum + 16)));

            case TC.PRIMITIVE:
                return(primSection [encoded.Datum]);

            case TC.REFERENCE_TRAP:
                if (encoded.Datum == 0)
                {
                    return(ReferenceTrap.Unassigned);
                }
                else
                {
                    throw new NotImplementedException();
                }
            // return ReferenceTrap.Make (encoded.Datum);

            case TC.RATNUM:
                return(new Ratnum(ReadObject(encoded.Datum),
                                  ReadObject(encoded.Datum + 4)));

            case TC.RETURN_CODE:
                return((ReturnCode)(encoded.Datum));

            case TC.SEQUENCE_2:
                return(Sequence2.Make(ReadObject(encoded.Datum),
                                      ReadObject(encoded.Datum + 4)));

            case TC.SEQUENCE_3:
                // Chains of sequence_3 can be arbitrarily long.
                // Unfortunately, the CLR puts a strict limit on
                // the stack, so we have to do this funky thing.
                Cons sequenceStack = null;
                while (true)
                {
                    // read the first two elements
                    object s1 = ReadObject(encoded.Datum);
                    sequenceStack = new Cons(s1, sequenceStack);
                    object s2 = ReadObject(encoded.Datum + 4);
                    sequenceStack = new Cons(s2, sequenceStack);

                    // peek at the third

                    EncodedObject sencoded =
                        heapSection.Contains(encoded.Datum + 8) ? heapSection [encoded.Datum + 8]
                           : constSection.Contains(encoded.Datum + 8) ? constSection [encoded.Datum + 8]
                           : new EncodedObject(0);

                    if (sencoded.TypeCode == TC.SEQUENCE_3)
                    {
                        encoded = sencoded;
                    }
                    else
                    {
                        // found the end of the chain!
                        object tail = ReadObject(encoded.Datum + 8);
                        while (sequenceStack != null)
                        {
                            object ob2 = sequenceStack.Car;
                            sequenceStack = (Cons)sequenceStack.Cdr;
                            object ob1 = sequenceStack.Car;
                            sequenceStack = (Cons)sequenceStack.Cdr;
                            tail          = Sequence3.Make(ob1, ob2, tail);
                        }
                        return(tail);
                    }
                }


            case TC.THE_ENVIRONMENT:
                return(TheEnvironment.Make());

            case TC.UNINTERNED_SYMBOL:
                // KLUDGE!!  Make sure that all uninterned strings within a file
                // keep their identity when read.
                // Also, postpend a unique number so we can tell these apart.
                first = ReadObject(encoded.Datum);
                if (first is Symbol)
                {
                    return(first);
                }
                else
                {
                    Symbol result = Symbol.MakeUninterned("#:" + new String((char [])first) + "-" + (gensymCounter++).ToString(CultureInfo.InvariantCulture));
                    this.sharingTable.Add(encoded.Datum, result);
                    return(result);
                }

            case TC.VARIABLE:
                return(Variable.Make((Symbol)ReadObject(encoded.Datum)));

            case TC.VECTOR:
                return(ReadVector(encoded.Datum));

            default:
                throw new NotImplementedException();
            }
        }
Exemple #3
0
        public static bool ObjectSetType(out object answer, object arg0, object arg1)
        {
            TC newType = (TC)(int)arg0;

            // kludge!!!!
            if ((int)arg0 == 0 && (int)arg1 == 1)
            {
                answer = new NullEnvironment();
            }
            else
            {
                switch (newType)
                {
                case TC.COMBINATION_2:
                    answer = Combination2.Make((Hunk3)arg1);
                    break;

                case TC.CONDITIONAL:
                    answer = Conditional.Make((Hunk3)arg1);
                    break;

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

                case TC.HUNK3_A:
                    // Probably someone trying to mark a history object.
                    answer = arg1;
                    break;

                case TC.HUNK3_B:
                    answer = arg1;
                    break;

                case TC.ENVIRONMENT:
                    object []       args       = (object[])arg1;
                    StandardClosure closure    = (StandardClosure)args [0];
                    object []       actualArgs = new object [args.Length - 1];
                    for (int i = 0; i < actualArgs.Length; i++)
                    {
                        actualArgs [i] = args [i + 1];
                    }
                    answer = new StandardEnvironment <StandardLambda, StandardClosure> (closure, actualArgs);
                    break;

                // throw new NotImplementedException ();
                //            // answer = (new InterpreterEnvironment ((object []) arg1));

                case TC.EXTENDED_LAMBDA:
                    answer = ExtendedLambda.Make((Hunk3)arg1);
                    break;

                case TC.PCOMB0:
                    answer = PrimitiveCombination0.Make((Primitive0)arg1);
                    break;

                case TC.PCOMB2:
                    answer = PrimitiveCombination2.Make((Hunk3)arg1);
                    break;

                case TC.PRIMITIVE:
                    if (!(arg1 is PrimitiveCombination0))
                    {
                        throw new NotImplementedException("Object-set-type on primitive");
                    }
                    answer = ((PrimitiveCombination0)arg1).Operator;
                    break;

                case TC.RECORD:
                    answer = new Record((object [])arg1);
                    return(false);

                case TC.SEQUENCE_3:
                    answer = new Sequence3((Hunk3)arg1);
                    break;

                case TC.THE_ENVIRONMENT:
                    answer = TheEnvironment.Make();
                    break;

                case TC.VARIABLE:
                    answer = Variable.Make((Hunk3)arg1);
                    break;

                case TC.VECTOR:
                    // Someone wants to see what endian we are!
                    char []   source = (char [])arg1;
                    object [] result = new object [source.Length / 4];
                    result [1] = ((((((byte)source [3]) * 256)
                                    + ((byte)source [2])) * 256)
                                  + ((byte)source [1])) * 256
                                 + ((byte)source [0]);
                    result [0] = ((((((byte)source [7]) * 256)
                                    + ((byte)source [6])) * 256)
                                  + ((byte)source [5])) * 256
                                 + ((byte)source [4]);
                    answer = result;
                    break;

                case TC.WEAK_CONS:
                    answer = new WeakCons(((Cons)arg1).Car, ((Cons)arg1).Cdr);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            return(false);
        }