public StaticMapping (Symbol [] names, int [] offsets)
        {
            int [] mapping = offsets;
            
#if DEBUG
            bool found = false;
            foreach (int [] knownMapping in knownMappings) {
               if (SameMapping(knownMapping, offsets)) {
                   mapping = knownMapping;
                   found = true;
                   break;
               }
            }
            if (!found)
                knownMappings.Add(mapping);
#endif
            this.names = names;
            this.offsets = mapping;
            foreach (int offset in offsets)
            {
                if (offset > 30)
                {
                    this.offsetCode = -1;
                    break;
                }
                this.offsetCode += 1 << offset;
            }
        }
Beispiel #2
0
        protected LambdaBase(Symbol name, Symbol [] formals, SCode body, ICollection<Symbol> freeVariables, StaticMapping staticMapping)
        {
            this.lambdaName = name;
            this.lambdaFormals = formals;
            this.lambdaBody = body;
            this.lambdaFreeVariables = freeVariables;
            this.staticMapping = staticMapping;
            #if DEBUG
            // Paranoia:  check for duplicate maps
            if (name != Dummy)
                for (int i = 0; i < formals.Length - 1; i++)
                    if (formals [i] != null)
                        for (int j = i + 1; j < formals.Length; j++)
                            if (formals [i] == formals [j])
                                Debugger.Break ();

            // //Check for eta-reducible primitive lambdas.  There seem to be
            // //too many of these.
            // Bug found and fixed.
            //if (body is PrimitiveCombination0 &&
            //    formals.Length == 0 )
            //    Debugger.Break ();

            //if (body is PrimitiveCombination1 &&
            //    formals.Length == 1 &&
            //    ((PrimitiveCombination1) body).Operand is Variable &&
            //    ((Variable) ((PrimitiveCombination1) body).Operand).Name == formals [0])
            //    Debugger.Break ();

            //if (body is PrimitiveCombination2 &&
            //    formals.Length == 2 &&
            //    ((PrimitiveCombination2) body).Operand0 is Variable &&
            //    ((PrimitiveCombination2) body).Operand1 is Variable &&
            //    ((Variable) ((PrimitiveCombination2) body).Operand0).Name == formals [0] &&
            //    ((Variable) ((PrimitiveCombination2) body).Operand1).Name == formals [1]) {
            //    Debugger.Break ();
            //}

            //if (body is PrimitiveCombination3 &&
            //    formals.Length == 3 &&
            //    ((PrimitiveCombination3) body).Operand0 is Variable &&
            //    ((PrimitiveCombination3) body).Operand1 is Variable &&
            //    ((PrimitiveCombination3) body).Operand2 is Variable &&
            //    ((Variable) ((PrimitiveCombination3) body).Operand0).Name == formals [0] &&
            //    ((Variable) ((PrimitiveCombination3) body).Operand1).Name == formals [1] &&
            //    ((Variable) ((PrimitiveCombination3) body).Operand2).Name == formals [2])
            //    Debugger.Break ();
            #endif
        }
Beispiel #3
0
 protected PCondIsNullA0XS(PrimitiveIsNullA0 predicate, SCode consequent, StaticVariable alternative)
     : base(predicate, consequent, alternative)
 {
     this.alternativeName = alternative.Name;
     this.alternativeOffset = alternative.Offset;
 }
 protected PrimitiveStringSetS(StaticVariable arg0, SCode arg1, SCode arg2)
     : base(arg0, arg1, arg2)
 {
     this.rand0Name = arg0.Name;
     this.rand0Offset = arg0.Offset;
 }
Beispiel #5
0
        public void ReadFormals(uint location, out Symbol name, out Symbol [] formals)
        {
            object [] names = (object []) ReadObject (location);
            for (int i = 0; i < names.Length - 1; i++)
                for (int j = i + 1; j < names.Length; j++)
                    if (names [i] == names [j])
                        Debugger.Break ();

            name = (Symbol) names [0];
            formals = new Symbol [names.Length-1];
            for (int i = 1; i < names.Length; i++)
                formals [i - 1] = (names [i] is Symbol) ? (Symbol) names [i] : Symbol.MakeUninterned ((string) names [i]);
            return;
        }
 protected PrimitiveGreaterThanFixnumS(Primitive2 rator, StaticVariable rand0, SCode rand1)
     : base(rator, rand0, rand1)
 {
     this.rand0Name = rand0.Name;
     this.rand0Offset = rand0.Offset;
 }
 protected PCondLessThanFixnumS(PrimitiveLessThanFixnumS predicate, SCode consequent, SCode alternative)
     : base(predicate, consequent, alternative)
 {
     this.rand0Name = predicate.rand0Name;
     this.rand0Offset = predicate.rand0Offset;
 }
Beispiel #8
0
        internal override SCode LookupVariableUncached(Symbol variable,
            Func<int, int, SCode> ifLexicalVariable,
            Func<int, int, SCode> ifShadowableLexicalVariable,
            Func<StandardEnvironment, SCode> ifAuxVariable,
            Func<StandardEnvironment, SCode> ifShadowableAuxVariable,
            Func<StandardEnvironment, SCode> ifFreeVariable,
            Func<StandardEnvironment, SCode> ifShadowableFreeVariable,
            Func<GlobalEnvironment, ValueCell, SCode> ifGlobalVariable,
            Func<GlobalEnvironment, ValueCell, SCode> ifShadowableGlobalVariable)
        {
            throw new NotImplementedException ();
            //    this.environment.LocateVariable<SCode> (variable,
            //        delegate () { throw new NotImplementedException (); },
            //        delegate (ValueCell cell) { throw new NotImplementedException (); },
            //        delegate (LexicalEnvironment env, int depth, int o) {
            //            if (depth == 0) {
            //                return ifLexicalVariable (depth, o);
            //            }
            //            else {
            //                return ifShadowableLexicalVariable (depth, o);
            //            }
            //        },
            //        delegate (StandardEnvironment env, int depth) {
            //            if (depth == 0) {
            //                return ifAuxVariable (env);
            //            }
            //            else {
            //                return ifShadowableAuxVariable (env);
            //            }
            //        });

            //    int offset = this.environment.SearchFormals (variable);
            //    if (offset == -1) {
            //        ValueCell cell = this.environment.SearchIncrementals(variable);
            //        if (cell == null)
            //            return ifFreeVariable (this.environment);
            //        return ifAuxVariable (this.environment);
            //    }
            //    return ifLexicalVariable (0, offset);
        }
 internal PrimitiveIsEqSS(Primitive2 rator, StaticVariable rand0, StaticVariable rand1)
     : base(rator, rand0, rand1)
 {
     #if DEBUG
     if (rand0.Offset == rand1.Offset) Debugger.Break ();
     #endif
     this.rand1Name = rand1.Name;
     this.rand1Offset = rand1.Offset;
 }
 protected PrimitiveIsEqS(Primitive2 rator, StaticVariable rand0, SCode rand1)
     : base(rator, rand0, rand1)
 {
     this.rand0Name = rand0.Name;
     this.rand0Offset = rand0.Offset;
 }
 protected PrimitiveIsEqCarXS(Primitive2 rator, PrimitiveCar rand0, StaticVariable rand1)
     : base(rator, rand0, rand1)
 {
     this.rand1Name = rand1.Name;
     this.rand1Offset = rand1.Offset;
 }
 protected PrimitiveIsEqCarS(Primitive2 rator, PrimitiveCarS rand0, SCode rand1)
     : base(rator, rand0, rand1)
 {
     this.rand0ArgOffset = rand0.offset;
     this.rand0ArgName = rand0.name;
 }
 internal PrimitiveIsEqCarAS(Primitive2 rator, PrimitiveCarA rand0, StaticVariable rand1)
     : base(rator, rand0, rand1)
 {
     this.rand1Name = rand1.Name;
     this.rand1Offset = rand1.Offset;
 }
 protected PrimitiveIsEqCarA0CarS(Primitive2 rator, PrimitiveCarA0 rand0, PrimitiveCarS rand1)
     : base(rator, rand0, rand1)
 {
     this.rand1Name = rand1.name;
     this.rand1Offset = rand1.offset;
 }
Beispiel #15
0
 public UnboundVariableError(Symbol name)
     : base(1)
 {
     this.name = name;
 }
Beispiel #16
0
 internal SCode LookupVariable(Symbol variable,
     Func<int, int, SCode> ifLexicalVariable,
     Func<int, int, SCode> ifShadowableLexicalVariable,
     Func<StandardEnvironment, SCode> ifAuxVariable,
     Func<StandardEnvironment, SCode> ifShadowableAuxVariable,
     Func<StandardEnvironment, SCode> ifFreeVariable,
     Func<StandardEnvironment, SCode> ifShadowableFreeVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifGlobalVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifShadowableGlobalVariable)
 {
     SCode answer;
     if (this.cache.TryGetValue (variable, out answer))
         return answer;
     answer = LookupVariableUncached (variable,
         ifLexicalVariable,
         ifShadowableLexicalVariable,
         ifAuxVariable,
         ifShadowableAuxVariable,
         ifFreeVariable,
         ifShadowableFreeVariable,
         ifGlobalVariable,
         ifShadowableGlobalVariable);
     cache.Add (variable, answer);
     return answer;
 }
Beispiel #17
0
 internal abstract SCode LookupVariableUncached(Symbol variable,
     Func<int, int, SCode> ifLexicalVariable,
     Func<int, int, SCode> ifShadowableLexicalVariable,
     Func<StandardEnvironment, SCode> ifAuxVariable,
     Func<StandardEnvironment, SCode> ifShadowableAuxVariable,
     Func<StandardEnvironment, SCode> ifFreeVariable,
     Func<StandardEnvironment, SCode> ifShadowableFreeVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifGlobalVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifShadowableGlobalVariable);
 protected PrimitiveIsIntEqQS(Primitive2 rator, Quotation rand0, StaticVariable rand1)
     : base(rator, rand0, rand1)
 {
     this.rand1Name = rand1.Name;
     this.rand1Offset = rand1.Offset;
 }
Beispiel #19
0
 internal override SCode LookupVariableUncached(Symbol variable,  
     Func<int, int, SCode> ifLexicalVariable,
     Func<int, int, SCode> ifShadowableLexicalVariable,
     Func<StandardEnvironment, SCode> ifAuxVariable,
     Func<StandardEnvironment, SCode> ifShadowableAuxVariable,
     Func<StandardEnvironment, SCode> ifFreeVariable,
     Func<StandardEnvironment, SCode> ifShadowableFreeVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifGlobalVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifShadowableGlobalVariable)
 {
     int offset = this.lambda.LexicalOffset (variable);
     return
         (offset == -1) ? this.parent.LookupVariableUncached (variable,
              delegate (int depth, int o) { return ifLexicalVariable (depth + 1, o); },
              delegate (int depth, int o) { return ifShadowableLexicalVariable (depth+1, o); },
              ifAuxVariable,
              ifShadowableAuxVariable,
              ifFreeVariable,
              ifShadowableFreeVariable,
              ifGlobalVariable,
              ifShadowableGlobalVariable
              ) :
              ifLexicalVariable (0, offset);
 }
 protected PrimitiveIsEqAS(Primitive2 rator, Argument rand0, StaticVariable rand1)
     : base(rator, rand0, rand1)
 {
     this.rand1Name = rand1.Name;
     this.rand1Offset = rand1.Offset;
 }
 PrimitiveGreaterThanFixnumA0S(Primitive2 rator, Argument0 rand0, StaticVariable rand1)
     : base(rator, rand0, rand1)
 {
     this.rand1Name = rand1.Name;
     this.rand1Offset = rand1.Offset;
 }
Beispiel #22
0
 protected PCond1S(PrimitiveCombination1 predicate, SCode consequent, SCode alternative)
     : base(predicate, consequent, alternative)
 {
     this.predicateRandName = ((StaticVariable) predicate.Operand).Name;
     this.predicateRandOffset = ((StaticVariable) predicate.Operand).Offset;
 }
Beispiel #23
0
 public Symbol[] ReadFormals(uint location)
 {
     object [] formals = (object []) ReadObject (location);
     Symbol [] result = new Symbol [formals.Length];
     for (int i = 0; i < formals.Length; i++)
         result [i] = (Symbol) formals [i];
     return result;
 }
Beispiel #24
0
 protected PCond1XXS(PrimitiveCombination1 predicate, SCode consequent, StaticVariable alternative)
     : base(predicate, consequent, alternative)
 {
     this.alternativeName = alternative.Name;
     this.alternativeOffset = alternative.Offset;
 }
 internal PrimitiveRecordSetSQS(StaticVariable arg0, Quotation arg1, StaticVariable arg2)
     : base(arg0, arg1, arg2)
 {
     this.rand2Name = arg2.Name;
     this.rand2Offset = arg2.Offset;
 }
Beispiel #26
0
 protected PCond1A0S(PrimitiveCombination1 predicate, StaticVariable consequent, SCode alternative)
     : base(predicate, consequent, alternative)
 {
     this.consequentName = consequent.Name;
     this.consequentOffset = consequent.Offset;
 }
Beispiel #27
0
 protected PCondIsNullS(PrimitiveIsNullS predicate, SCode consequent, SCode alternative)
     : base(predicate, consequent, alternative)
 {
     this.predicateRandName = predicate.rand0Name;
     this.predicateRandOffset = predicate.rand0Offset;
 }
Beispiel #28
0
 protected PCondIsEqCarA0S(PrimitiveCombination2 predicate, SCode consequent, SCode alternative)
     : base(predicate, consequent, alternative)
 {
     this.rand1Name = ((StaticVariable) predicate.Operand1).Name;
     this.rand1Offset = ((StaticVariable) predicate.Operand1).Offset;
 }
Beispiel #29
0
 protected PCondIsNullAS(PrimitiveIsNullA predicate, StaticVariable consequent, SCode alternative)
     : base(predicate, consequent, alternative)
 {
     this.consequentName = consequent.Name;
     this.consequentOffset = consequent.Offset;
 }
Beispiel #30
0
 internal override SCode LookupVariableUncached(Symbol variable,  
     Func<int, int, SCode> ifLexicalVariable,
     Func<int, int, SCode> ifShadowableLexicalVariable,
     Func<StandardEnvironment, SCode> ifAuxVariable,
     Func<StandardEnvironment, SCode> ifShadowableAuxVariable,
     Func<StandardEnvironment, SCode> ifFreeVariable,
     Func<StandardEnvironment, SCode> ifShadowableFreeVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifGlobalVariable,
     Func<GlobalEnvironment, ValueCell, SCode> ifShadowableGlobalVariable)
 {
     throw new NotImplementedException ();
     //return this.environment.LocateVariable<SCode> (variable,
     //    delegate () { return ifGlobalVariable (this.environment, null); },
     //    delegate (ValueCell cell) { return ifGlobalVariable (this.environment, cell); },
     //    delegate (LexicalEnvironment env, int depth, int o) { throw new NotImplementedException (); },
     //    delegate (StandardEnvironment env, int depth) { throw new NotImplementedException (); });
 }