public void VerifyISeqRestMaintainsMeta(ISeq s) { IPersistentMap meta = ((IMeta)s).meta(); for (; s.next() != null; s = s.next()) Expect(((IMeta)s.next()).meta(), EqualTo(meta)); }
/// <summary> /// Create a <see cref="PersistentHashSet">PersistentHashSet</see> initialized from an <see cref="ISeq">ISeq</see> of items. /// </summary> /// <param name="items">An <see cref="ISeq">ISeq</see> of items</param> /// <returns>A <see cref="PersistentHashSet">PersistentHashSet</see>.</returns> public static PersistentHashSet create(ISeq items) { PersistentHashSet ret = EMPTY; for (; items != null; items = items.next()) ret = (PersistentHashSet)ret.cons(items.first()); return ret; }
public static PersistentHashSet create(ISeq items) { ITransientSet ret = (ITransientSet)EMPTY.asTransient(); for (; items != null; items = items.next()) ret = (ITransientSet)ret.conj(items.first()); return (PersistentHashSet)ret.persistent(); }
public static Expr Parse(ISeq form) { Expr fexpr = Compiler.GenerateAST(form.first()); IPersistentVector args = PersistentVector.EMPTY; for ( ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(Compiler.GenerateAST(s.first())); return new InvokeExpr(Compiler.TagOf(form),fexpr,args); }
public static Expr Parse(ISeq form) { Expr fexpr = Compiler.GenerateAST(form.first(),false); IPersistentVector args = PersistentVector.EMPTY; for ( ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(Compiler.GenerateAST(s.first(),false)); return new InvokeExpr((string)Compiler.SOURCE.deref(),(int)Compiler.LINE.deref(),Compiler.TagOf(form),fexpr,args); }
public void VerifyISeqContents(ISeq s, IList<object> values) { int i=0; for (; s != null; s = s.next(), i++) Expect(s.first(), EqualTo(values[i])); Expect(i, EqualTo(values.Count)); }
/// <summary> /// Create a struct from a struct definition and values (in order) for the fixed keys. /// </summary> /// <param name="def">A struct definition</param> /// <param name="valseq">A sequence of values for the fixed keys (in definition order).</param> /// <returns>A <see cref="PersistentStructMap">PersistentStructMap</see>.</returns> public static PersistentStructMap construct(Def def, ISeq valseq) { object[] vals = new object[def.Keyslots.count()]; IPersistentMap ext = PersistentHashMap.EMPTY; for (int i = 0; i < vals.Length && valseq != null; valseq = valseq.next(), i++) { vals[i] = valseq.first(); } if (valseq != null) throw new ArgumentException("Too many arguments to struct constructor"); return new PersistentStructMap(null, def, vals, ext); }
public static Expr Parse(ParserContext pcon, IPersistentMap form) { ParserContext pconToUse = pcon.EvalOrExpr(); bool constant = true; IPersistentVector keyvals = PersistentVector.EMPTY; for (ISeq s = RT.seq(form); s != null; s = s.next()) { IMapEntry e = (IMapEntry)s.first(); Expr k = Compiler.Analyze(pconToUse, e.key()); Expr v = Compiler.Analyze(pconToUse, e.val()); keyvals = (IPersistentVector)keyvals.cons(k); keyvals = (IPersistentVector)keyvals.cons(v); if (!(k is LiteralExpr && v is LiteralExpr)) { constant = false; } } Expr ret = new MapExpr(keyvals); IObj iobjForm = form as IObj; if (iobjForm != null && iobjForm.meta() != null) { return(Compiler.OptionallyGenerateMetaInit(pcon, form, ret)); } else if (constant) { // This 'optimzation' works, mostly, unless you have nested map values. // The nested map values do not participate in the constants map, so you end up with the code to create the keys. // Result: huge duplication of keyword creation. 3X increase in init time to the REPL. //IPersistentMap m = PersistentHashMap.EMPTY; //for (int i = 0; i < keyvals.length(); i += 2) // m = m.assoc(((LiteralExpr)keyvals.nth(i)).Val, ((LiteralExpr)keyvals.nth(i + 1)).Val); //return new ConstantExpr(m); return(ret); } else { return(ret); } }
/// <summary> /// Determines whether the specified Object is equal to the current object. /// </summary> /// <param name="obj">The Object to compare to the current object.</param> /// <returns><c>true</c> if the specified Object is equal to the current object; otherwise <c>false</c></returns> /// <remarks>Equality is value-based, ie.e. depends on the sequence of items.</remarks> public override bool Equals(object obj) { if (!(obj is Sequential || obj is IList)) { return(false); } ISeq ms = RT.seq(obj); for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) { if (ms == null || !Util.equals(s.first(), ms.first())) { return(false); } } return(ms == null); // hit end of sequence on both sequences }
internal static Type[] CreateTypeArray(ISeq seq) { List <Type> types = new List <Type>(); for (ISeq s = seq == null ? null : seq.seq(); s != null; s = s.next()) { Object o = s.first(); Type oAsType = o as Type; if (oAsType != null) { types.Add(oAsType); } else if (o is ISeq) { object first = RT.first(o); Symbol firstAsSymbol = first as Symbol; if (firstAsSymbol == null || !firstAsSymbol.Equals(HostExpr.ByRefSym)) { throw new ArgumentException("First element of parameter definition is not by-ref"); } Type secondAsType = RT.second(o) as Type; if (secondAsType == null) { throw new ArgumentException("by-ref must be paired with a type"); } types.Add(secondAsType.MakeByRefType()); } else { throw new ArgumentException("Bad parameter definition"); } } if (types.Count == 0) { return(Type.EmptyTypes); } return(types.ToArray <Type>()); }
public static void pushThreadBindings(Associative bindings) { Frame f = CurrentFrame; Associative bmap = f.Bindings; for (ISeq bs = bindings.seq(); bs != null; bs = bs.next()) { IMapEntry e = (IMapEntry)bs.first(); Var v = (Var)e.key(); if (!v._dynamic) { throw new InvalidOperationException(String.Format("Can't dynamically bind non-dynamic var: {0}/{1}", v.Namespace, v.Symbol)); } v.Validate(e.val()); v._threadBound.set(true); bmap = bmap.assoc(v, new TBox(Thread.CurrentThread, e.val())); } CurrentFrame = new Frame(bmap, f); }
/// <summary> /// Determine if an object is equivalent to this (handles all collections). /// </summary> /// <param name="o">The object to compare.</param> /// <returns><c>true</c> if the object is equivalent; <c>false</c> otherwise.</returns> public bool equiv(object o) { if (!(o is Sequential || o is IList)) { return(false); } ISeq ms = RT.seq(o); for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) { if (ms == null || !Util.equiv(s.first(), ms.first())) { return(false); } } return(ms == null); // hit end of sequence on both sequences }
private ConstructorBuilder EmitConstructorForNonDefType(TypeBuilder fnTB, Type baseType) { ConstructorBuilder cb = fnTB.DefineConstructor(MethodAttributes.Public, CallingConventions.HasThis, CtorTypes()); CljILGen gen = new CljILGen(cb.GetILGenerator()); GenContext.EmitDebugInfo(gen, SpanMap); //Call base constructor ConstructorInfo baseCtorInfo = baseType.GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public, null, Type.EmptyTypes, null); if (baseCtorInfo == null) throw new InvalidOperationException("Unable to find default constructor for " + baseType.FullName); gen.EmitLoadArg(0); gen.Emit(OpCodes.Call, baseCtorInfo); // Store Meta if (SupportsMeta) { gen.EmitLoadArg(0); gen.EmitLoadArg(1); gen.Emit(OpCodes.Castclass, typeof(IPersistentMap)); gen.EmitFieldSet(MetaField); } // store closed-overs in their fields int a = 0; int offset = !SupportsMeta ? 1 : 2; for (ISeq s = RT.keys(Closes); s != null; s = s.next(), a++) { //LocalBinding lb = (LocalBinding)s.first(); FieldBuilder fb = ClosedOverFields[a]; bool isVolatile = IsVolatile(ClosedOverFieldsToBindingsMap[fb]); gen.EmitLoadArg(0); // gen.Emit(OpCodes.Ldarg_0); gen.EmitLoadArg(a + offset); // gen.Emit(OpCodes.Ldarg, a + 1); gen.MaybeEmitVolatileOp(isVolatile); gen.Emit(OpCodes.Stfld, fb); } gen.Emit(OpCodes.Ret); return cb; }
internal static List <HostArg> ParseArgs(ParserContext pcon, ISeq argSeq) { List <HostArg> args = new List <HostArg>(); for (ISeq s = argSeq; s != null; s = s.next()) { object arg = s.first(); HostArg.ParameterType paramType = HostArg.ParameterType.Standard; LocalBinding lb = null; ISeq argAsSeq = arg as ISeq; if (argAsSeq != null) { Symbol op = RT.first(argAsSeq) as Symbol; if (op != null && op.Equals(ByRefSym)) { if (RT.Length(argAsSeq) != 2) { throw new ArgumentException("Wrong number of arguments to {0}", op.Name); } object localArg = RT.second(argAsSeq); Symbol symLocalArg = localArg as Symbol; if (symLocalArg == null || (lb = Compiler.ReferenceLocal(symLocalArg)) == null) { throw new ArgumentException("Argument to {0} must be a local variable.", op.Name); } paramType = HostArg.ParameterType.ByRef; arg = localArg; } } Expr expr = Compiler.Analyze(pcon.EvalOrExpr(), arg); args.Add(new HostArg(paramType, expr, lb)); } return(args); }
void LightCompileMethods() { Dictionary <int, DynamicMethod> dict = new Dictionary <int, DynamicMethod>(); // Create a dynamic method that takes an array of closed-over values // and returns an instance of AFnImpl. for (ISeq s = RT.seq(_methods); s != null; s = s.next()) { FnMethod method = (FnMethod)s.first(); method.LightEmit(this, CompiledType); int key = GetMethodKey(method); //dict[key] = new WeakReference(method.DynMethod); dict[key] = method.DynMethod; } DynMethodMap[DynMethodMapKey] = dict; _dynMethodMap = dict; }
/// <summary> /// Add a new key/value pair. /// </summary> /// <param name="o">The key/value pair to add.</param> /// <returns>A new map with key+value pair added.</returns> public IPersistentMap cons(object o) { if (o is IMapEntry e) { return(assoc(e.key(), e.val())); } if (o is DictionaryEntry de) { return(assoc(de.Key, de.Value)); } if (o != null) { Type t = o.GetType(); if (t.IsGenericType && t.Name == "KeyValuePair`2") { object key = t.InvokeMember("Key", BindingFlags.GetProperty, null, o, null); object val = t.InvokeMember("Value", BindingFlags.GetProperty, null, o, null); return(assoc(key, val)); } } if (o is IPersistentVector v) { if (v.count() != 2) { throw new ArgumentException("Vector arg to map cons must be a pair"); } return(assoc(v.nth(0), v.nth(1))); } IPersistentMap ret = this; for (ISeq s = RT.seq(o); s != null; s = s.next()) { IMapEntry me = (IMapEntry)s.first(); ret = ret.assoc(me.key(), me.val()); } return(ret); }
public bool equiv(object o) { if (this == o) { return(true); } if (!(o is Sequential || o is IList)) { return(false); } ISeq ms = RT.seq(o); for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) { if (ms == null || !Util.equiv(s.first(), ms.first())) { return(false); } } return(ms == null); }
/// <summary> /// The creator method. /// </summary> /// <param name="args">A sequence of elements.</param> /// <returns>A new list.</returns> protected override object doInvoke(object args) { if (args is IArraySeq ias) { object[] argsarray = (object[])ias.ToArray(); IPersistentList ret = EMPTY; for (int i = argsarray.Length - 1; i >= ias.index(); i--) { ret = (IPersistentList)ret.cons(argsarray[i]); } return(ret); } List <object> list = new List <object>(); for (ISeq s = RT.seq(args); s != null; s = s.next()) { list.Add(s.first()); } return(create(list)); }
static List <Type> ParseGenericMethodTypeArgs(ISeq targs) { List <Type> types = new List <Type>(); for (ISeq s = targs; s != null; s = s.next()) { object arg = s.first(); if (!(arg is Symbol)) { throw new ArgumentException("Malformed generic method designator: type arg must be a Symbol"); } Type t = HostExpr.MaybeType(arg, false); if (t == null) { throw new ArgumentException("Malformed generic method designator: invalid type arg"); } types.Add(t); } return(types); }
public override bool Equals(object obj) { if (this == obj) { return(true); } if (!(obj is Sequential || obj is IList)) { return(false); } ISeq ms = RT.seq(obj); for (ISeq s = seq(); s != null; s = s.next(), ms = ms.next()) { if (ms == null || !Util.equiv(s.first(), ms.first())) { return(false); } } return(ms == null); }
static public object invokeStatic(ISeq args) { if (args is IArraySeq ias) { object[] argsarray = (object[])ias.ToArray(); IPersistentList ret = EMPTY; for (int i = argsarray.Length - 1; i >= 0; i--) { ret = (IPersistentList)ret.cons(argsarray[i]); } return(ret); } List <object> list = new List <object>(); for (ISeq s = RT.seq(args); s != null; s = s.next()) { list.Add(s.first()); } return(create(list)); }
/// <summary> /// Move to the next item. /// </summary> /// <returns><value>true</value> if there is a next item; /// <value>false</value> if the sequence is already at the end.</returns> public bool MoveNext() { if (_isAtEnd || _origSeq == null) { return(false); } if (_seq == null) { _seq = _origSeq; } else { _seq = _seq.next(); if (_seq == null) { _isAtEnd = true; } } return(!_isAtEnd); }
public static bool mapEquals(IPersistentMap m1, Object obj) { if (m1 == obj) { return(true); } //if(!(obj instanceof Map)) // return false; //Map m = (Map) obj; IDictionary d = obj as IDictionary; if (d == null) { return(false); } // Java had the following. // This works on other APersistentMap implementations, but not on // arbitrary dictionaries. //if (d.Count != m1.Count || d.GetHashCode() != m1.GetHashCode()) // return false; if (d.Count != m1.count()) { return(false); } for (ISeq s = m1.seq(); s != null; s = s.next()) { IMapEntry me = (IMapEntry)s.first(); bool found = d.Contains(me.key()); if (!found || !Util.equals(me.val(), d[me.key()])) { return(false); } } return(true); }
public ITransientMap conj(object val) { EnsureEditable(); { IMapEntry e = val as IMapEntry; if (e != null) { return(assoc(e.key(), e.val())); } } if (val is DictionaryEntry) { DictionaryEntry de = (DictionaryEntry)val; return(assoc(de.Key, de.Value)); } { IPersistentVector v = val as IPersistentVector; if (v != null) { if (v.count() != 2) { throw new ArgumentException("Vector arg to map conj must be a pair"); } return(assoc(v.nth(0), v.nth(1))); } } // TODO: also handle KeyValuePair? ITransientMap ret = this; for (ISeq es = RT.seq(val); es != null; es = es.next()) { IMapEntry e = (IMapEntry)es.first(); ret = ret.assoc(e.key(), e.val()); } return(ret); }
/// <summary> /// Determine if an object is equivalent to this (handles all collections). /// </summary> /// <param name="o">The object to compare.</param> /// <returns><c>true</c> if the object is equivalent; <c>false</c> otherwise.</returns> /// <remarks> /// In Java Rev 1215, Added equiv. Same as the definition in Equals, as in they took out the hashcode comparison. /// Different, as in Util.Equal above became Util.equals. and below it is Util.equiv. /// </remarks> public bool equiv(object o) { //if(!(obj instanceof Map)) // return false; //Map m = (Map) obj; if (o is IPersistentMap && !(o is MapEquivalence)) { return(false); } IDictionary d = o as IDictionary; if (d == null) { return(false); } // Java had the following. // This works on other APersistentMap implementations, but not on // arbitrary dictionaries. //if (d.Count != this.Count || d.GetHashCode() != this.GetHashCode()) // return false; if (d.Count != this.Count) { return(false); } for (ISeq s = seq(); s != null; s = s.next()) { IMapEntry me = (IMapEntry)s.first(); bool found = d.Contains(me.key()); if (!found || !Util.equiv(me.val(), d[me.key()])) { return(false); } } return(true); }
public static Expr Parse(ParserContext pcon, IPersistentSet form) { ParserContext pconToUse = pcon.EvalOrExpr(); bool constant = true; IPersistentVector keys = PersistentVector.EMPTY; for (ISeq s = RT.seq(form); s != null; s = s.next()) { object e = s.first(); Expr expr = Compiler.Analyze(pconToUse, e); keys = (IPersistentVector)keys.cons(expr); if (!(expr is LiteralExpr)) { constant = false; } } Expr ret = new SetExpr(keys); IObj iobjForm = form as IObj; if (iobjForm != null && iobjForm.meta() != null) { return(Compiler.OptionallyGenerateMetaInit(pcon, form, ret)); } else if (constant) { IPersistentSet set = PersistentHashSet.EMPTY; for (int i = 0; i < keys.count(); i++) { LiteralExpr ve = (LiteralExpr)keys.nth(i); set = (IPersistentSet)set.cons(ve.Val); } return(new ConstantExpr(set)); } else { return(ret); } }
public virtual void Emit(RHC rhc, ObjExpr objx, CljILGen ilg) { //emitting a Fn means constructing an instance, feeding closed-overs from enclosing scope, if any //objx arg is enclosing objx, not this if (IsDefType) { ilg.Emit(OpCodes.Ldnull); } else { if (SupportsMeta) { ilg.Emit(OpCodes.Ldnull); ilg.Emit(OpCodes.Castclass, typeof(IPersistentMap)); } for (ISeq s = RT.keys(Closes); s != null; s = s.next()) { LocalBinding lb = (LocalBinding)s.first(); if (lb.PrimitiveType != null) { objx.EmitUnboxedLocal(ilg, lb); } else { objx.EmitLocal(ilg, lb); } } ilg.Emit(OpCodes.Newobj, _ctorInfo); } if (rhc == RHC.Statement) { ilg.Emit(OpCodes.Pop); } }
public static Expr Parse(ParserContext pcon, IPersistentSet form) { ParserContext pconToUse = pcon.EvalOrExpr(); bool constant = true; IPersistentVector keys = PersistentVector.EMPTY; for (ISeq s = RT.seq(form); s != null; s = s.next()) { object e = s.first(); Expr expr = Compiler.Analyze(pconToUse, e); keys = (IPersistentVector)keys.cons(expr); if (!(expr is LiteralExpr)) { constant = false; } } Expr ret = new SetExpr(keys); if (form is IObj iobjForm && iobjForm.meta() != null) { return(Compiler.OptionallyGenerateMetaInit(pcon, form, ret)); }
protected override void GenerateMethods(GenContext context) { for (ISeq s = RT.seq(Methods); s != null; s = s.next()) { FnMethod method = (FnMethod)s.first(); method.GenerateCode(this, context); } if (IsVariadic) { GenerateGetRequiredArityMethod(TypeBuilder, _variadicMethod.RequiredArity); } List <int> supportedArities = new List <int>(); for (ISeq s = RT.seq(Methods); s != null; s = s.next()) { FnMethod method = (FnMethod)s.first(); supportedArities.Add(method.NumParams); } GenerateHasArityMethod(TypeBuilder, supportedArities, IsVariadic, IsVariadic ? _variadicMethod.RequiredArity : 0); }
private static void DefineMethod(TypeBuilder proxyTB, IPersistentVector sig) { Symbol mname = (Symbol)sig.nth(0); Type[] paramTypes = GenClass.CreateTypeArray((ISeq)sig.nth(1)); Type retType = (Type)sig.nth(2); ISeq pmetas = (ISeq)(sig.count() >= 4 ? sig.nth(3) : null); MethodBuilder mb = proxyTB.DefineMethod(mname.Name, MethodAttributes.Abstract | MethodAttributes.Public | MethodAttributes.Virtual, retType, paramTypes); SetCustomAttributes(mb, GenInterface.ExtractAttributes(RT.meta(mname))); int i = 1; for (ISeq s = pmetas; s != null; s = s.next(), i++) { IPersistentMap meta = GenInterface.ExtractAttributes((IPersistentMap)s.first()); if (meta != null && meta.count() > 0) { ParameterBuilder pb = mb.DefineParameter(i, ParameterAttributes.None, String.Format("p_{0}", i)); GenInterface.SetCustomAttributes(pb, meta); } } }
protected override void EmitMethods(TypeBuilder tb) { for (ISeq s = RT.seq(_methods); s != null; s = s.next()) { FnMethod method = (FnMethod)s.first(); method.Emit(this, tb); } if (IsVariadic) { EmitGetRequiredArityMethod(_typeBuilder, _variadicMethod.RequiredArity); } List <int> supportedArities = new List <int>(); for (ISeq s = RT.seq(_methods); s != null; s = s.next()) { FnMethod method = (FnMethod)s.first(); supportedArities.Add(method.NumParams); } EmitHasArityMethod(_typeBuilder, supportedArities, IsVariadic, IsVariadic ? _variadicMethod.RequiredArity : 0); }
Type Generate(Type superclass, ISeq interfaces, IPersistentMap attributes, string className) { // define the class List <Type> interfaceTypes = new List <Type> { typeof(IProxy) }; for (ISeq s = interfaces; s != null; s = s.next()) { interfaceTypes.Add((Type)s.first()); } TypeBuilder proxyTB = _context.ModuleBuilder.DefineType( className, TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed, superclass, interfaceTypes.ToArray()); GenInterface.SetCustomAttributes(proxyTB, attributes); DefineCtors(proxyTB, superclass); MaybeImplementISerializable(proxyTB, interfaceTypes); FieldBuilder mapField = AddIProxyMethods(proxyTB); HashSet <Type> allInterfaces = GetAllInterfaces(interfaces); HashSet <MethodBuilder> specialMethods = new HashSet <MethodBuilder>(); AddInterfaceMethods(proxyTB, mapField, superclass, allInterfaces, specialMethods); AddInterfaceProperties(proxyTB, superclass, allInterfaces, specialMethods); // Must follow AddInterfaceMethods Type t = proxyTB.CreateType(); //if (Compiler.IsCompiling) // SaveProxyContext(); return(t); }
public object this[int index] { get { if (index < 0) { throw new ArgumentOutOfRangeException("index", "Index must be non-negative."); } ISeq s = seq(); for (int i = 0; s != null; s = s.next(), i++) { if (i == index) { return(s.first()); } } throw new ArgumentOutOfRangeException("index", "Index past end of sequence."); } set { throw new InvalidOperationException(); } }
public object this[int index] { get { //Java has this: return RT.nth(this, index); // THis causes an infinite loop in my code. // When this was introduces, a change was made in RT.nth that changed the List test in its type dispatch to RandomAccess. // CLR does not have the equivalent notion, so I just left it at IList. BOOM! // So, I have to do a sequential search, duplicating some of the code in RT.nth. ISeq seq = this; for (int i = 0; i <= index && seq != null; ++i, seq = seq.next()) { if (i == index) { return(seq.first()); } } throw new ArgumentOutOfRangeException("index"); } set { throw new InvalidOperationException("Cannot modify an immutable sequence"); } }
protected override void EmitMethods(TypeBuilder tb) { HashSet <MethodInfo> implemented = new HashSet <MethodInfo>(); for (ISeq s = RT.seq(Methods); s != null; s = s.next()) { NewInstanceMethod method = (NewInstanceMethod)s.first(); method.Emit(this, tb); implemented.UnionWith(method.MethodInfos); } foreach (List <MethodInfo> ms in _methodMap.Values) { foreach (MethodInfo mi in ms) { if (NeedsDummy(mi, implemented)) { EmitDummyMethod(tb, mi, true); } } } EmitHasArityMethod(TypeBuilder, null, false, 0); }
private static Object process_output(Object o, int level) { if (o is IPersistentCollection) { o = ((IPersistentCollection)o).seq(); } if (o is ISeq) { ISeq r2 = (ISeq)o; object[] outArr = new object[r2.count()]; int i = 0; while (r2 != null) { outArr[i] = level == 1 ? process_output(r2.first(), 0) : cleanValue(r2.first()); i++; r2 = r2.next(); } return(level == 1 ? pack(outArr) : outArr); } else { return(level == 1 ? pack(cleanValue(o)) : cleanValue(o)); } }
protected override void GenerateMethods(GenContext context) { HashSet <MethodInfo> implemented = new HashSet <MethodInfo>(); for (ISeq s = RT.seq(Methods); s != null; s = s.next()) { NewInstanceMethod method = (NewInstanceMethod)s.first(); method.GenerateCode(this, context); implemented.UnionWith(method.MethodInfos); } foreach (List <MethodInfo> ms in _methodMap.Values) { foreach (MethodInfo mi in ms) { if (NeedsDummy(mi, implemented)) { GenerateDummyMethod(context, mi); } } } GenerateHasArityMethod(TypeBuilder, null, false, 0); }
static void GatherMethods( Type st, ISeq interfaces, out Dictionary<IPersistentVector, List<MethodInfo>> overrides) { Dictionary<IPersistentVector, List<MethodInfo>> allm = new Dictionary<IPersistentVector, List<MethodInfo>>(); GatherMethods(st, allm); for (; interfaces != null; interfaces = interfaces.next()) GatherMethods((Type)interfaces.first(), allm); overrides = allm; }
/// <summary> /// Create a <see cref="PersistentHashMap">PersistentHashMap</see> initialized from /// an <see cref="ISeq">ISeq</see> of alternating keys and values. /// </summary> /// <param name="items">An <see cref="ISeq">ISeq</see> of alternating keys and values.</param> /// <returns>A <see cref="PersistentHashMap">PersistentHashMap</see>.</returns> public static PersistentHashMap create(ISeq items) { ITransientMap ret = (ITransientMap)EMPTY.asTransient(); for (; items != null; items = items.next().next()) { if ( items.next() == null ) throw new ArgumentException(String.Format("No value supplied for key: {0}", items.first())); ret = ret.assoc(items.first(), RT.second(items) ); } return (PersistentHashMap)ret.persistent(); }
public static PersistentHashSet createWithCheck(ISeq items) { ITransientSet ret = (ITransientSet)EMPTY.asTransient(); for (int i = 0; items != null; items = items.next(), ++i) { ret = (ITransientSet)ret.conj(items.first()); if (ret.count() != i + 1) throw new ArgumentException("Duplicate key: " + items.first()); } return (PersistentHashSet)ret.persistent(); }
public static object ApplyToHelper(IFn fn, ISeq argList) { switch (RT.BoundedLength(argList, 20)) { case 0: argList = null; return fn.invoke(); case 1: return fn.invoke(Util.Ret1(argList.first(),argList=null)); case 2: return fn.invoke(argList.first() , Util.Ret1((argList = argList.next()).first(),argList = null) ); case 3: return fn.invoke(argList.first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 4: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 5: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 6: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 7: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 8: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 9: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 10: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 11: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 12: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 13: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 14: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 15: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 16: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 17: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 18: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 19: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); case 20: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , Util.Ret1((argList = argList.next()).first(), argList = null) ); default: return fn.invoke(argList.first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , (argList = argList.next()).first() , RT.SeqToArray<object>(Util.Ret1(argList.next(),argList=null))); } }
public static Expr Parse(ParserContext pcon, ISeq form) { pcon = pcon.EvEx(); // TODO: DO we need the recur context here and below? Expr fexpr = Compiler.Analyze(pcon,form.first()); if ( fexpr is VarExpr && ((VarExpr)fexpr).Var.Equals(Compiler.INSTANCE)) { if ( RT.second(form) is Symbol ) { Type t = HostExpr.MaybeType(RT.second(form),false); if ( t != null ) return new InstanceOfExpr((string)Compiler.SOURCE.deref(), (IPersistentMap)Compiler.SOURCE_SPAN.deref(), t, Compiler.Analyze(pcon,RT.third(form))); } } if (fexpr is VarExpr && pcon.Rhc != RHC.Eval) { Var v = ((VarExpr)fexpr).Var; object arglists = RT.get(RT.meta(v), Compiler.ARGLISTS_KEY); int arity = RT.count(form.next()); for (ISeq s = RT.seq(arglists); s != null; s = s.next()) { IPersistentVector sargs = (IPersistentVector)s.first(); if (sargs.count() == arity) { string primc = FnMethod.PrimInterface(sargs); if (primc != null) return Compiler.Analyze(pcon, RT.listStar(Symbol.intern(".invokePrim"), ((Symbol)form.first()).withMeta(RT.map(RT.TAG_KEY, Symbol.intern(primc))), form.next())); break; } } } if (fexpr is KeywordExpr && RT.count(form) == 2 && Compiler.KEYWORD_CALLSITES.isBound) { Expr target = Compiler.Analyze(pcon, RT.second(form)); return new KeywordInvokeExpr((string)Compiler.SOURCE.deref(), (IPersistentMap)Compiler.SOURCE_SPAN.deref(), Compiler.TagOf(form), (KeywordExpr)fexpr, target); } IPersistentVector args = PersistentVector.EMPTY; for ( ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(Compiler.Analyze(pcon,s.first())); //if (args.count() > Compiler.MAX_POSITIONAL_ARITY) // throw new ArgumentException(String.Format("No more than {0} args supported", Compiler.MAX_POSITIONAL_ARITY)); return new InvokeExpr((string)Compiler.SOURCE.deref(), (IPersistentMap)Compiler.SOURCE_SPAN.deref(), //Compiler.GetSourceSpanMap(form), Compiler.TagOf(form), fexpr, args); }
/// <summary> /// Create a struct from a struct definition and a sequence of alternating keys and values. /// </summary> /// <param name="def">The struct definition</param> /// <param name="keyvals">A sequence of alternating keys and values.</param> /// <returns>A <see cref="PersistentStructMap">PersistentStructMap</see>.</returns> public static PersistentStructMap create(Def def, ISeq keyvals) { object[] vals = new object[def.Keyslots.count()]; IPersistentMap ext = PersistentHashMap.EMPTY; for (; keyvals != null; keyvals = keyvals.next().next()) { if (keyvals.next() == null) throw new ArgumentException(String.Format("No value supplied for key: {0}", keyvals.first())); object k = keyvals.first(); object v = RT.second(keyvals); IMapEntry me = def.Keyslots.entryAt(k); if (me != null) vals[Util.ConvertToInt(me.val())] = v; else ext = ext.assoc(k, v); } return new PersistentStructMap(null, def, vals, ext); }
//static string[] InterfaceNames(IPersistentVector interfaces) //{ // int icnt = interfaces.count(); // string[] inames = icnt > 0 ? new string[icnt] : null; // for (int i = 0; i < icnt; i++) // inames[i] = SlashName((Type)interfaces.nth(i)); // return inames; //} //static string SlashName(Type t) //{ // return t.FullName.Replace(',', '/'); //} #endregion #region Method reflection static void GatherMethods( Type st, ISeq interfaces, out Dictionary<IPersistentVector, IList<MethodInfo>> overrides, out Dictionary<IPersistentVector, IList<MethodInfo>> explicits) { overrides = new Dictionary<IPersistentVector, IList<MethodInfo>>(); explicits = new Dictionary<IPersistentVector, IList<MethodInfo>>(); GatherMethods(st, overrides); for (; interfaces != null; interfaces = interfaces.next()) { GatherMethods((Type)interfaces.first(), overrides); GatherInterfaceExplicits((Type)interfaces.first(),explicits); } }
public static Expr Parse(ParserContext pcon, ISeq form) { pcon = pcon.EvalOrExpr(); Expr fexpr = Compiler.Analyze(pcon,form.first()); VarExpr varFexpr = fexpr as VarExpr; if (varFexpr != null && varFexpr.Var.Equals(Compiler.InstanceVar)) { if ( RT.second(form) is Symbol ) { Type t = HostExpr.MaybeType(RT.second(form),false); if ( t != null ) return new InstanceOfExpr((string)Compiler.SourceVar.deref(), (IPersistentMap)Compiler.SourceSpanVar.deref(), t, Compiler.Analyze(pcon,RT.third(form))); } } if (varFexpr != null && pcon.Rhc != RHC.Eval) { Var v = varFexpr.Var; object arglists = RT.get(RT.meta(v), Compiler.ArglistsKeyword); int arity = RT.count(form.next()); for (ISeq s = RT.seq(arglists); s != null; s = s.next()) { IPersistentVector sargs = (IPersistentVector)s.first(); if (sargs.count() == arity) { string primc = FnMethod.PrimInterface(sargs); if (primc != null) return Compiler.Analyze(pcon, RT.listStar(Symbol.intern(".invokePrim"), ((Symbol)form.first()).withMeta(RT.map(RT.TagKey, Symbol.intern(primc))), form.next())); break; } } } KeywordExpr kwFexpr = fexpr as KeywordExpr; if (kwFexpr != null && RT.count(form) == 2 && Compiler.KeywordCallsitesVar.isBound) { Expr target = Compiler.Analyze(pcon, RT.second(form)); return new KeywordInvokeExpr((string)Compiler.SourceVar.deref(), (IPersistentMap)Compiler.SourceSpanVar.deref(), Compiler.TagOf(form), kwFexpr, target); } IPersistentVector args = PersistentVector.EMPTY; for ( ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(Compiler.Analyze(pcon,s.first())); //if (args.count() > Compiler.MAX_POSITIONAL_ARITY) // throw new ArgumentException(String.Format("No more than {0} args supported", Compiler.MAX_POSITIONAL_ARITY)); return new InvokeExpr((string)Compiler.SourceVar.deref(), (IPersistentMap)Compiler.SourceSpanVar.deref(), //Compiler.GetSourceSpanMap(form), Compiler.TagOf(form), fexpr, args); }
public static PersistentVector create(ISeq items) { Object[] arr = new Object[32]; int i = 0; for (; items != null && i < 32; items = items.next()) arr[i++] = items.first(); if (items != null) { // >32, construct with array directly PersistentVector start = new PersistentVector(32, 5, EmptyNode, arr); TransientVector ret = (TransientVector)start.asTransient(); for (; items != null; items = items.next()) ret = (TransientVector)ret.conj(items.first()); return (PersistentVector)ret.persistent(); } else if (i == 32) { // exactly 32, skip copy return new PersistentVector(32, 5, EmptyNode, arr); } else { // <32, copy to minimum array and construct Object[] arr2 = new Object[i]; Array.Copy(arr, 0, arr2, 0, i); return new PersistentVector(i, 5, EmptyNode, arr2); } }
private static object MacroexpandSeq1(ISeq form) { object op = RT.first(form); if (IsSpecial(op)) return form; // macro expansion Var v = IsMacro(op); if (v != null) { try { return v.applyTo(RT.cons(form, RT.cons(LocalEnvVar.get(), form.next()))); } catch (ArityException e) { // hide the 2 extra params for a macro throw new ArityException(e.Actual - 2, e.Name); } } else { Symbol sym = op as Symbol; if (sym != null) { string sname = sym.Name; // (.substring s 2 5) => (. x substring 2 5) if (sname[0] == '.') { if (form.count() < 2) throw new ArgumentException("Malformed member expression, expecting (.member target ...)"); Symbol method = Symbol.intern(sname.Substring(1)); object target = RT.second(form); if (HostExpr.MaybeType(target, false) != null) target = ((IObj)RT.list(IdentitySym, target)).withMeta(RT.map(RT.TagKey, ClassSym)); // We need to make sure source information gets transferred return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(DotSym, target, method, form.next().next())), form); } else if (NamesStaticMember(sym)) { Symbol target = Symbol.intern(sym.Namespace); Type t = HostExpr.MaybeType(target, false); if (t != null) { Symbol method = Symbol.intern(sym.Name); // We need to make sure source information gets transferred return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(Compiler.DotSym, target, method, form.next())), form); } } else { // (x.substring 2 5) => (. x substring 2 5) // also (package.class.name ... ) (. package.class name ... ) int index = sname.LastIndexOf('.'); if (index == sname.Length - 1) // We need to make sure source information gets transferred return MaybeTransferSourceInfo(RT.listStar(Compiler.NewSym, Symbol.intern(sname.Substring(0, index)), form.next()), form); } } } return form; }
public void VerifyISeqRestTypes(ISeq s, Type type) { for ( ; s.next() != null; s = s.next()) Expect(s.next(), InstanceOf(type)); }
public static PersistentVector create(ISeq items) { ITransientCollection ret = EMPTY.asTransient(); for (; items != null; items = items.next()) ret = ret.conj(items.first()); return (PersistentVector)ret.persistent(); }
/// <summary> /// Create a <see cref="PersistentVector">PersistentVector</see> from an <see cref="ISeq">ISeq</see>. /// </summary> /// <param name="items">A sequence of items.</param> /// <returns>An initialized vector.</returns> public static PersistentVector create(ISeq items) { IPersistentVector ret = EMPTY; for (; items != null; items = items.next()) ret = ret.cons(items.first()); return (PersistentVector)ret; }
public override object applyTo(ISeq args) { int reqArity = getRequiredArity(); if (RT.BoundedLength(args, reqArity) <= reqArity) return AFn.ApplyToHelper(this, Util.Ret1(args, args = null)); switch (reqArity) { case 0: return doInvoke(Util.Ret1(args, args = null)); case 1: return doInvoke(args.first() , Util.Ret1(args.next(), args = null)); case 2: return doInvoke(args.first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 3: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 4: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 5: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 6: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 7: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 8: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 9: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 10: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 11: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 12: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 13: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 14: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 15: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 16: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 17: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 18: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 19: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); case 20: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , Util.Ret1(args.next(), args = null)); } throw WrongArityException(-1); }
private static ISeq sqExpandList(ISeq seq) { IPersistentVector ret = PersistentVector.EMPTY; for (; seq != null; seq = seq.next()) { Object item = seq.first(); //if (item is Unquote) // ret = ret.cons(RT.list(LIST, ((Unquote)item).Obj)); // REV 1184 if (isUnquote(item)) ret = ret.cons(RT.list(LIST, RT.second(item))); else if (isUnquoteSplicing(item)) ret = ret.cons(RT.second(item)); else ret = ret.cons(RT.list(LIST, syntaxQuote(item))); } return ret.seq(); }
private static object MacroexpandSeq1(ISeq form) { object op = RT.first(form); if (IsSpecial(op)) return form; // macro expansion Var v = IsMacro(op); if (v != null) { try { Var.pushThreadBindings(RT.map(RT.MACRO_META, RT.meta(form))); return v.applyTo(form.next()); } finally { Var.popThreadBindings(); } } else { if (op is Symbol) { Symbol sym = (Symbol)op; string sname = sym.Name; // (.substring s 2 5) => (. x substring 2 5) if (sname[0] == '.') { if (form.count() < 2) throw new ArgumentException("Malformed member expression, expecting (.member target ...)"); Symbol method = Symbol.intern(sname.Substring(1)); // TODO: Figure out why the following change made in Java Rev 1158 breaks ants.clj // Note on that revision: force instance member interpretation of (.method ClassName), e.g. (.getMethods String) works // However, when I do this, it makes ants.clj choke on: (def white-brush (new SolidBrush (.White Color))) object target = RT.second(form); if (MaybeType(target, false) != null) //target = RT.list(IDENTITY, target); target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(RT.TAG_KEY, CLASS)); return RT.listStar(DOT, target, method, form.next().next()); // safe substitute: return RT.listStar(Compiler.DOT, RT.second(form), method, form.next().next()); } else if (NamesStaticMember(sym)) { Symbol target = Symbol.intern(sym.Namespace); Type t = MaybeType(target, false); if (t != null) { Symbol method = Symbol.intern(sym.Name); return RT.listStar(Compiler.DOT, target, method, form.next()); } } else { // (x.substring 2 5) => (. s substring 2 5) int index = sname.LastIndexOf('.'); if (index == sname.Length - 1) return RT.listStar(Compiler.NEW, Symbol.intern(sname.Substring(0, index)), form.next()); } } } return form; }
public static Expr Parse(ParserContext pcon, ISeq form) { pcon = pcon.EvEx(); // TODO: DO we need the recur context here and below? Expr fexpr = Compiler.Analyze(pcon,form.first()); if ( fexpr is VarExpr && ((VarExpr)fexpr).Var.Equals(Compiler.INSTANCE)) { if ( RT.second(form) is Symbol ) { Type t = HostExpr.MaybeType(RT.second(form),false); if ( t != null ) return new InstanceOfExpr((string)Compiler.SOURCE.deref(), (IPersistentMap)Compiler.SOURCE_SPAN.deref(), t, Compiler.Analyze(pcon,RT.third(form))); } } if (fexpr is VarExpr && pcon.Rhc != RHC.Eval) { Var v = ((VarExpr)fexpr).Var; if (RT.booleanCast(RT.get(RT.meta(v), Compiler.STATIC_KEY))) return StaticInvokeExpr.Parse(v, RT.next(form), Compiler.TagOf(form)); } if (fexpr is KeywordExpr && RT.count(form) == 2 && Compiler.KEYWORD_CALLSITES.isBound) { Expr target = Compiler.Analyze(pcon, RT.second(form)); return new KeywordInvokeExpr((string)Compiler.SOURCE.deref(), (IPersistentMap)Compiler.SOURCE_SPAN.deref(), Compiler.TagOf(form), (KeywordExpr)fexpr, target); } IPersistentVector args = PersistentVector.EMPTY; for ( ISeq s = RT.seq(form.next()); s != null; s = s.next()) args = args.cons(Compiler.Analyze(pcon,s.first())); return new InvokeExpr((string)Compiler.SOURCE.deref(), (IPersistentMap)Compiler.SOURCE_SPAN.deref(), //Compiler.GetSourceSpanMap(form), Compiler.TagOf(form), fexpr, args); }
/// <summary> /// Create a <see cref="PersistentTreeMap">PersistentTreeMap</see> from a comparison method /// an <see cref="ISeq">ISeq</see> of alternating keys and values. /// </summary> /// <param name="comp">A comparison method.</param> /// <param name="items">The <see cref="ISeq">ISeq</see> of alternating keys and values.</param> /// <returns>A <see cref="PersistentTreeMap">PersistentTreeMap</see>.</returns> public static PersistentTreeMap create(IComparer comp, ISeq items) { IPersistentMap ret = new PersistentTreeMap(comp); for (; items != null; items = items.next().next()) { if (items.next() == null) throw new ArgumentException(string.Format("No value supplied for key: %s", items.first())); ret = ret.assoc(items.first(), RT.second(items)); } return (PersistentTreeMap)ret; }
private static object MacroexpandSeq1(ISeq form) { object op = RT.first(form); if (IsSpecial(op)) return form; // macro expansion Var v = IsMacro(op); if (v != null) { // TODO: Check this against current code return v.applyTo(RT.cons(form, RT.cons(LOCAL_ENV.get(), form.next()))); } else { if (op is Symbol) { Symbol sym = (Symbol)op; string sname = sym.Name; // (.substring s 2 5) => (. x substring 2 5) if (sname[0] == '.') { if (form.count() < 2) throw new ArgumentException("Malformed member expression, expecting (.member target ...)"); Symbol method = Symbol.intern(sname.Substring(1)); object target = RT.second(form); if (HostExpr.MaybeType(target, false) != null) target = ((IObj)RT.list(IDENTITY, target)).withMeta(RT.map(RT.TAG_KEY, CLASS)); // We need to make sure source information gets transferred return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(DOT, target, method, form.next().next())), form); } else if (NamesStaticMember(sym)) { Symbol target = Symbol.intern(sym.Namespace); Type t = HostExpr.MaybeType(target, false); if (t != null) { Symbol method = Symbol.intern(sym.Name); // We need to make sure source information gets transferred return MaybeTransferSourceInfo(PreserveTag(form, RT.listStar(Compiler.DOT, target, method, form.next())), form); } } else { // (x.substring 2 5) => (. x substring 2 5) // also (package.class.name ... ) (. package.class name ... ) int index = sname.LastIndexOf('.'); if (index == sname.Length - 1) // We need to make sure source information gets transferred return MaybeTransferSourceInfo(RT.listStar(Compiler.NEW, Symbol.intern(sname.Substring(0, index)), form.next()), form); } } } return form; }
public static PersistentHashMap createWithCheck(ISeq items) { ITransientMap ret = (ITransientMap)EMPTY.asTransient(); for (int i = 0; items != null; items = items.next().next(), ++i) { if (items.next() == null) throw new ArgumentException(String.Format("No value supplied for key: {0}", items.first())); ret = ret.assoc(items.first(), RT.second(items)); if (ret.count() != i + 1) throw new ArgumentException("Duplicate key: " + items.first()); } return (PersistentHashMap)ret.persistent(); }
// do we need this? protected static ISeq FindKey(object key, ISeq args) { while (args != null) { if (key == args.first()) return args.next(); args = RT.next(args); args = RT.next(args); } return null; }
public override object applyTo(ISeq args) { if (RT.BoundedLength(args, _reqArity) <= _reqArity) return base.applyTo(args); switch (_reqArity) { case 0: return doInvoke(args); case 1: return doInvoke(args.first() , args.next()); case 2: return doInvoke(args.first() , (args = args.next()).first() , args.next()); case 3: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 4: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 5: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 6: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 7: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 8: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 9: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 10: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 11: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 12: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 13: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 14: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 15: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 16: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 17: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 18: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 19: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); case 20: return doInvoke(args.first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , (args = args.next()).first() , args.next()); } throw WrongArityException(); }
private static Expression GenerateInvoke(ISeq form) { Expression fn = Generate(form.first()); fn = Expression.Convert(fn,typeof(IFn)); ISeq s = RT.seq(form.next()); int n = s == null ? 0 : s.count(); Expression[] args = new Expression[n]; for (int i = 0; s != null; s = s.next(), i++) args[i] = MaybeBox(Generate(s.first())); Type returnType = ComputeInvocationReturnType(form.first(), form); Expression call = GenerateInvocation(returnType, fn, args); return call; }