Esempio n. 1
0
        private void CompileFuncall(Symbol fnSym, Cons paramList, LexicalScope lexScope)
        {
            if(lexScope.IsBound(fnSym, Symbol.FunctionSlot))
              {
            GenLexSymValue(lexScope, fnSym, Symbol.FunctionSlot);
              }
              else
              {
            FieldInfo functionSlotFld = typeof(Symbol).GetField("FunctionSlot");
            if(functionSlotFld == null)
            {
              throw new CompilerError("Unable to find VM.Types.Symbol.FunctionSlot field");
            }

            GenDynSymValue(fnSym, functionSlotFld);
              }

              MethodInfo invokeMethInfo = typeof(Function).GetMethod("Invoke");
              if(invokeMethInfo == null)
              {
            throw new CompilerError("Unable to find VM.Function.Invoke method");
              }

              var paramCount = ConsAux.Reduce(paramList, (x, counter) => counter + 1, 0);
              _gen.Emit(OpCodes.Newarr, paramCount);

              ConsAux.Reduce(paramList, (x, counter) =>
            {
              _gen.Emit(OpCodes.Dup);
              _gen.Emit(OpCodes.Ldc_I4, counter + 1);
              CompileForm(x, lexScope);
              _gen.Emit(OpCodes.Stelem_Ref);
              return counter + 1;
            }, 0);

              _gen.Emit(OpCodes.Call, invokeMethInfo);
        }
Esempio n. 2
0
        public Symbol InternSymbol(String name)
        {
            if(name == null)
              {
            throw new ArgumentException("Symbol's name can't be null!");
              }

              if(!_Symbols.ContainsKey(name))
              {
            _Symbols[name] = new Symbol(name);
              }

              return _Symbols[name];
        }
Esempio n. 3
0
 private void GenLexSymValue(LexicalScope lexScope, Symbol varSym, String slot)
 {
     LocalBuilder lexVar = lexScope.Value(varSym, slot);
       _gen.Emit(OpCodes.Ldloc, lexVar);
 }
Esempio n. 4
0
        private void GenDynSymValue(Symbol sym, FieldInfo slotDesignator)
        {
            PropertyInfo currentCtxProp = typeof(VM.Context).GetProperty("Current");
              if(currentCtxProp == null)
              {
            throw new CompilerError("Unable to find VM.Context.Current property");
              }

              MethodInfo curCtxGetter = currentCtxProp.GetGetMethod();
              if(curCtxGetter == null)
              {
            throw new CompilerError("Unable to find VM.Context.Current.get accessor");
              }

              PropertyInfo dynScopeProp = typeof(VM.Context).GetProperty("DynamicScope");
              if(dynScopeProp == null)
              {
            throw new CompilerError("Unable to find VM.Context.DynamicScope property");
              }

              MethodInfo dynScopeGetter = dynScopeProp.GetGetMethod();
              if(curCtxGetter == null)
              {
            throw new CompilerError("Unable to find VM.Context.DynamicScope.get accessor");
              }

              MethodInfo valueGetter = typeof(DynamicScope).GetMethod("Value");
              if(valueGetter == null)
              {
            throw new CompilerError("Unable to find VM.Scope.Value method");
              }

              _gen.Emit(OpCodes.Call, curCtxGetter);
              _gen.Emit(OpCodes.Call, dynScopeGetter);
              _gen.Emit(OpCodes.Ldstr, sym.Name);
              _gen.Emit(OpCodes.Ldstr, slotDesignator);
              _gen.Emit(OpCodes.Call, valueGetter);
        }
Esempio n. 5
0
        private void CompileVariable(Symbol sym, LexicalScope lexScope)
        {
            if(lexScope.IsBound(sym, Symbol.ValueSlot))
              {
            GenLexSymValue(lexScope, sym, Symbol.ValueSlot);
              }
              else
              {
            FieldInfo valueSlotFld = typeof(Symbol).GetField("ValueSlot");
            if(valueSlotFld == null)
            {
              throw new CompilerError("Unable to find VM.Types.Symbol.FunctionSlot field");
            }

            GenDynSymValue(sym, valueSlotFld);
              }
        }
Esempio n. 6
0
        public void EqualtyTest()
        {
            Symbol sym1 = new Symbol("test");
              Symbol sym2 = new Symbol("test");

              Assert.That(sym1, Is.EqualTo(sym1)); // self-equalty test
              Assert.That(sym1, Is.Not.EqualTo(sym2)); // objects non-equalty test
        }
Esempio n. 7
0
 public void CreationTest()
 {
     Symbol sym = new Symbol("testSymbol");
       Assert.That(sym.Name, Is.EqualTo("testSymbol"));
 }
Esempio n. 8
0
 private bool IsSpecialForm(Symbol sym)
 {
     switch(sym.Name)
       {
     case "progn":
       return true;
     case "let":
       return true;
     default:
       return false;
       }
 }