static void RegisterPrimitiveProcedures() { var unaryArity = new Arity(1, Arity.Mode.Equal); var binaryArity = new Arity(2, Arity.Mode.Equal); var nonEmptyArity = new Arity(1, Arity.Mode.GreaterEqual); var arithContract = new Contract(nonEmptyArity, new List <Type> { typeof(Number) }); var binNumContract = new Contract(binaryArity, new List <Type> { typeof(Number), typeof(Number) }); var unaryIValueContract = new Contract(unaryArity, new List <Type> { typeof(IValue) }); var binaryIValueContract = new Contract(binaryArity, new List <Type> { typeof(IValue), typeof(IValue) }); var mpairContract = new Contract(unaryArity, new List <Type> { typeof(MPair) }); var listContract = new Contract(nonEmptyArity, new List <Type> { typeof(IValue) }); var ppTable = new (string, Contract, Func <IReadOnlyCollection <IValue>, IValue>)[]
public Contract(Arity arity, IList <Type> paramTypes) { if (!arity.Verify(paramTypes.Count)) { // The Contract class is designed to be used by the primitive procedures only, // which means that I should take care of getting their contracts & implementation right. // If compound procedures are also allowed to specify their contracts, then // this exception should be replaced with an interpreter-handled exception. throw new ArgumentException("The given parameter types does not match the specified arity."); } if (paramTypes.Where((t) => !Utils.IsIValueType(t)).Count() != 0) { throw new ArgumentException("The given parameter types contain a non-IValue type."); } this.arity = arity; this.paramTypes = paramTypes; }