internal CLSInstanceSymbol(String name, String memberName, Type type) : base(name) { globalValue = CLSMember.FindMember( memberName, type, false); }
internal CLSStaticSymbol(String name, String memberName, Type type) : base(name) { globalValue = member = CLSMember.FindMember( memberName, type, true); }
internal CLSStaticSymbol(String name, String memberName, Type type) : base(name) { globalValue = member = CLSMember.FindMember( memberName, type,true); }
public virtual CLSMember GetFound() { if (found == null) { if (_Type == null) { throw new Exception("No type!"); } found = FindMember0(name, _Type, _Static); } return(found); }
public override Object Invoke(params Object[] args) { // instance member gets target from first arg Object target = args[0]; if (target is Record) { Record rec = (Record)target; if (args.Length == 2) //set call { rec[name] = args[1]; return(args[1]); } else //get { Object ret = rec[name]; if (ret == null && !rec.Contains(name)) { throw new Exception("Record does not contain member: " + name); } return(ret); } } else { //get a real member to do the work //first check the cache Type targetType = target.GetType(); CLSMember member = (CLSMember)cache[targetType]; if (member == null) { //late-bound members are never static cache[targetType] = member = CLSMember.FindMember(name, targetType, false); } return(member.Invoke(args)); } }
internal Symbol intern(String name) { var table = this.table; Symbol result = (Symbol)table[name]; if (result == null) { var p = Parent; while (p != null) { Symbol result2 = p.table[name] as Symbol; if (result2 != null) { return(result2); } p = p.Parent; } } if (result == null) { if (name.StartsWith(":")) { table[name] = result = new Keyword(name); } else { int firstdot = name.IndexOf('.'); int lastdot = name.LastIndexOf('.'); int lastcolon = name.LastIndexOf(':'); int nameLength = name.Length; // .instance // .[namespace.]type:explicitinstance // [namespace.]type. // [namespace.]type:static // obj.member - transformed by reader if ((firstdot != -1 || lastcolon != -1) && nameLength > 1) { if (firstdot == 0) //instance { if (lastcolon > 0) //explicitly qualified { String memberName = name.Substring(lastcolon + 1, nameLength - (lastcolon + 1)); CLSMember innermember = CLSMember.FindMember( memberName, this, name.Substring(1, lastcolon - 1), false); table[name] = result = new CLSInstanceSymbol(name, innermember); } else { String memberName = name.Substring(1, nameLength - 1); table[name] = result = new CLSInstanceSymbol(name, memberName, null); } } else if (lastcolon > 0) //static { String memberName = name.Substring(lastcolon + 1, nameLength - (lastcolon + 1)); CLSMember innermember = CLSMember.FindMember( memberName, this, name.Substring(0, lastcolon), true); table[name] = result = new CLSStaticSymbol(name, innermember); } else if (lastdot == nameLength - 1) //type { Type type = findType(name.Substring(0, lastdot)); table[name] = result = new CLSTypeSymbol(name, type); } } else { table[name] = result = new Symbol(name); result.isDynamic = (name[0] == '*'); } } } return(result); }
internal CLSStaticSymbol(String name, CLSMember found) : base(name) { globalValue = member = found; }
internal CLSInstanceSymbol(String name, CLSMember found) : base(name) { globalValue = found; }
public virtual CLSMember GetFound() { if (found == null) { if (_Type == null) { throw new Exception("No type!"); } found = FindMember0(name, _Type, _Static); } return found; }
public static Object InvokeObject(Object f, params Object[] args) { Function func = f as Function; if (func != null) { return(func(args)); } IFunction ifunc = f as IFunction; if (ifunc != null) { return(ifunc.Invoke(args)); } else if (f is Type) { Type t = (Type)f; //try to support ctor-style init of Int32 etc. which don't have ctors //unfortunately, IntPtr IsPrimitive but has a ctor! if (t.IsPrimitive) { return(Convert.ChangeType(args[0], t)); } //CLSConstructor ctor = new CLSConstructor(t); return(CLSConstructor.Invoke(t, args)); } else if (args.Length == 1) { //treat as indexed get Array a = args[0] as Array; if (a != null) { if (f is Int32) { return(a.GetValue((Int32)f)); } else { return(a.GetValue((Int32[])f)); } } else //not an array, try default member { if (f is Array) { return(CLSMember.GetDefaultIndexedProperty(args[0], (Object[])f)); } else { return(CLSMember.GetDefaultIndexedProperty(args[0], new Object[] { f })); } } } else if (args.Length == 2) { //treat as indexed set Object val = args[1]; Object target = args[0]; Array a = target as Array; if (a != null) { if (f is Int32) { a.SetValue(val, (Int32)f); } else { a.SetValue(val, (Int32[])f); } } else //not an array, try default member { if (f is Array) { Array af = f as Array; Object[] subsandval = new Object[af.Length + 1]; Array.Copy(af, subsandval, af.Length); subsandval[af.Length] = args[1]; CLSMember.SetDefaultIndexedProperty(target, subsandval); } else { CLSMember.SetDefaultIndexedProperty(target, new Object[] { f, val }); } } return(args[1]); } //what should policy be on invoke nil? if (f == null) { return(null); } throw new Exception("Don't know how to invoke: " + f); //+ " with args: " + Primitives.strgf.Invoke((Object)args)); }