public void ReduceListTest() { // (list 1 2 3) Cons list = new Cons { Head = 1, Tail = new Cons { Head = 2, Tail = new Cons { Head = 3, Tail = Cons.Nil } } }; // (reduce #'+ list :initial-value 0) Assert.That(ConsAux.Reduce(list, (x, rhs) => (int)x + rhs, 0), Is.EqualTo(6)); }
public void ObjEqualtyTest() { String testStr = "Test"; var strCons = new Cons { Head = testStr, Tail = testStr }; Assert.That(strCons.Head, Is.EqualTo(testStr)); Assert.That(strCons.Tail, Is.EqualTo(testStr)); }
private void CompileProgn(Cons formList, LexicalScope lexScope) { if(formList.Head != Cons.Nil) { while (formList.Tail != Cons.Nil) { CompileForm(formList.Head, lexScope); _gen.Emit(OpCodes.Pop); Assert.TypeIs(formList.Tail, typeof(Cons)); formList = formList.Tail as Cons; } CompileForm(formList.Head, lexScope); } else { var fldInfo = typeof(Cons).GetField("Nil", BindingFlags.Public | BindingFlags.Static); _gen.Emit(OpCodes.Ldsfld, fldInfo); } }
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 void ReduceMalformedTest() { Cons malformedList = new Cons { Head = new Object(), Tail = new Object() }; ConsAux.Reduce(malformedList, (x, rhs) => rhs, new Object()); }
private void CompileSpecialForm(Cons form, LexicalScope lexScope) { Symbol formSym = form.Head as Symbol; switch(formSym.Name) { case "let": CompileLet(form.Tail as Cons, lexScope); return; case "progn": CompileProgn(form.Tail as Cons, lexScope); return; default: throw new CompilerError("Unknown special form {0}", formSym.Name); } }
public void DefaultTest() { var defCons = new Cons(); Assert.That(defCons.Head, Is.EqualTo(Cons.Nil)); Assert.That(defCons.Tail, Is.EqualTo(Cons.Nil)); }