public static object DefineMacro(Symbol sym, LambdaClosure value, string doc) { EraseVariable(sym); sym.MacroValue = value; sym.CompilerDocumentation = doc; return(sym); }
public static LambdaClosure MakeLambdaClosure(LambdaDefinition def, IRuntimeVariables hoistValues) { var closure = new LambdaClosure { Definition = def, HoistFrame = new Frame(def.HoistNames, hoistValues) }; return(closure); }
public static object DefineCompilerMacro(Symbol sym, LambdaClosure value, string doc) { if (!Functionp(sym.Value)) { ThrowError("Cannot define compiler macro for non-function {0}", sym); } sym.CompilerMacroValue = value; sym.CompilerDocumentation = doc; return(sym); }
public static LambdaClosure MakeLambdaClosure(LambdaDefinition def) { var closure = new LambdaClosure { Definition = def, Frame = Runtime.CurrentThreadContext.Frame }; return(closure); }
public static LambdaClosure DefineMethod(Symbol sym, LambdaClosure lambda) { var container = sym.Value as MultiMethod; if (container == null) { container = DefineMultiMethod(sym, lambda.Definition.Signature, null); } else if (container.RequiredArgsCount != 0 && lambda.Definition.Signature.RequiredArgsCount != container.RequiredArgsCount) { throw new LispException("Number of parameters of {0} and its multimethod are not the same", ToPrintString(lambda)); } container.Add(lambda); return(lambda); }
public object ApplyNext(LambdaClosure current, object[] args) { foreach (var lambda in Lambdas) { if (current != null) { if (lambda == current) { current = null; } } else if (lambda.Definition.Signature.ParametersMatchArguments(args)) { return(((IApply)lambda).Apply(args)); } } return(null); }
public void Add(LambdaClosure method) { method.Owner = this; var comparer = new LambdaSignatureComparer(); for (var i = 0; i < Lambdas.Count; ++i) { int result = comparer.Compare(method.Definition.Signature, Lambdas[i].Definition.Signature); if (result == -1) { Lambdas.Insert(i, method); return; } else if (result == 0) { Lambdas[i] = method; return; } } Lambdas.Add(method); }
public static BindingRestrictions GetGenericRestrictions(LambdaClosure method, DynamicMetaObject[] args) { var methodList = method.Generic.Lambdas; var restrictions = BindingRestrictions.Empty; // // Restrictions for this method // for (var i = 0; i < method.Definition.Signature.RequiredArgsCount; ++i) { var par = method.Definition.Signature.Parameters[i]; if (par.Specializer != null) { var restr = BindingRestrictions.GetExpressionRestriction(Expression.Call(Runtime.IsInstanceOfMethod, args[i].Expression, Expression.Constant(par.Specializer))); restrictions = restrictions.Merge(restr); } } // // Additional NOT restrictions for lambdas that come before the method and fully subtype the method. // foreach (LambdaClosure lambda in methodList) { if (lambda == method) { break; } bool lambdaSubtypesMethod = true; for (var i = 0; i < method.Definition.Signature.RequiredArgsCount; ++i) { var par = method.Definition.Signature.Parameters[i]; var par2 = lambda.Definition.Signature.Parameters[i]; if (!Runtime.IsSubtype(par2.Specializer, par.Specializer, false)) { lambdaSubtypesMethod = false; break; } } if (!lambdaSubtypesMethod) { continue; } Expression tests = null; for (var i = 0; i < method.Definition.Signature.RequiredArgsCount; ++i) { var par = method.Definition.Signature.Parameters[i]; var par2 = lambda.Definition.Signature.Parameters[i]; if (Runtime.IsSubtype(par2.Specializer, par.Specializer, true)) { var test = Expression.Not(Expression.Call(Runtime.IsInstanceOfMethod, args[i].Expression, Expression.Constant(par2.Specializer))); if (tests == null) { tests = test; } else { tests = Expression.Or(tests, test); } } } if (tests != null) { var restr = BindingRestrictions.GetExpressionRestriction(tests); restrictions = restrictions.Merge(restr); } } return(restrictions); }
public LambdaApplyMetaObject(Expression objParam, LambdaClosure lambda) : base(objParam, BindingRestrictions.Empty, lambda) { this.lambda = lambda; }