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); }
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]; }
private void GenLexSymValue(LexicalScope lexScope, Symbol varSym, String slot) { LocalBuilder lexVar = lexScope.Value(varSym, slot); _gen.Emit(OpCodes.Ldloc, lexVar); }
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); }
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); } }
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 }
public void CreationTest() { Symbol sym = new Symbol("testSymbol"); Assert.That(sym.Name, Is.EqualTo("testSymbol")); }
private bool IsSpecialForm(Symbol sym) { switch(sym.Name) { case "progn": return true; case "let": return true; default: return false; } }