// Public methos public IoObject getType(IoState state, string typeName) { Type t = null; foreach (string s in this.usingNamespaces.Keys) { IoCLRAssembly asm = this.usingNamespaces[s] as IoCLRAssembly; t = asm.assembly.GetType(s + "." + typeName); if (t != null) { IoCLRObject obj = IoCLRObject.createObject(state) as IoCLRObject; obj.clrType = t; obj.clrInstance = null; return(obj); } } if (t == null) { foreach (string s in this.loadedAssemblies.Keys) { IoCLRAssembly asm = this.loadedAssemblies[s] as IoCLRAssembly; t = asm.assembly.GetType(typeName); if (t != null) { IoCLRObject obj = IoCLRObject.createObject(state) as IoCLRObject; obj.clrType = t; obj.clrInstance = null; return(obj); } } } return(null); }
// Published Slots public static IoObject slotUsing(IoObject target, IoObject locals, IoObject message) { IoCLR self = target as IoCLR; IoMessage m = message as IoMessage; IoSeq nameSpace = m.localsSymbolArgAt(locals, 0); bool validNamespace = false; IoCLRAssembly foundInAssembly = null; foreach (IoCLRAssembly asm in self.loadedAssemblies.Values) { if (asm.assemblyNamespaces[nameSpace.value] != null) { validNamespace = true; foundInAssembly = asm; break; } } if (!validNamespace) { Console.WriteLine("Namespace '{0}' is not valid.", nameSpace.value); return(self); } if (self.usingNamespaces[nameSpace.value] == null) { self.usingNamespaces[nameSpace.value] = foundInAssembly; } return(self); }
// published slots public static IoObject slotNamespaces(IoObject target, IoObject locals, IoObject message) { IoCLRAssembly self = target as IoCLRAssembly; IoMessage m = message as IoMessage; foreach (string s in self.assemblyNamespaces.Keys) { Console.Write(s + " "); } Console.WriteLine(); return(self); }
public static IoObject slotLoadAssembly(IoObject target, IoObject locals, IoObject message) { IoCLR self = target as IoCLR; IoMessage m = message as IoMessage; IoSeq assemblyName = m.localsSymbolArgAt(locals, 0); IoCLRAssembly asm = self.loadedAssemblies[assemblyName.value] as IoCLRAssembly; if (asm != null) { return(asm); } asm = IoCLRAssembly.createObject(target.state); asm.assembly = Assembly.LoadWithPartialName(assemblyName.value); if (asm.assembly == null) { return(self); } self.loadedAssemblies[assemblyName.value] = asm; asm.assemblyTypes = asm.assembly.GetTypes(); asm.assemblyNamespaces = new Hashtable(); foreach (Type t in asm.assemblyTypes) { string theNameSpace = t.FullName.LastIndexOf(".") == -1 ? "-" : t.FullName.Substring(0, t.FullName.LastIndexOf(".")); string theClass = t.FullName.LastIndexOf(".") == -1 ? t.FullName : t.FullName.Substring(t.FullName.LastIndexOf(".") + 1); if (theClass.Equals("Form")) { int i = 0; } if (asm.assemblyNamespaces.ContainsKey(theNameSpace)) { Hashtable a = asm.assemblyNamespaces[theNameSpace] as Hashtable; a[theClass] = t; } else { Hashtable classes = new Hashtable(); classes[theClass] = t; asm.assemblyNamespaces[theNameSpace] = classes; } } return(asm); }
public IoCLRObject getType(string typeName) { Type t = null; foreach (string s in this.usingNamespaces.Keys) { IoCLRAssembly asm = this.usingNamespaces[s] as IoCLRAssembly; t = asm.assembly.GetType(s + typeName); if (t != null) { IoCLRObject obj = new IoCLRObject(); obj.clrType = t; obj.clrInstance = null; } } return(null); }
public override IoObject proto(IoState state) { IoCLRAssembly pro = new IoCLRAssembly(); pro.state = state; pro.uniqueId = 0; pro.createSlots(); pro.createProtos(); pro.isActivatable = true; state.registerProtoWithFunc(pro.name, new IoStateProto(pro.name, pro, new IoStateProtoFunc(pro.proto))); //pro.protos.Add(state.protoWithInitFunc("Object")); IoCFunction[] methodTable = new IoCFunction[] { new IoCFunction("namespaces", new IoMethodFunc(IoCLRAssembly.slotNamespaces)), }; pro.addTaglessMethodTable(state, methodTable); return pro; }
public override IoObject proto(IoState state) { IoCLRAssembly pro = new IoCLRAssembly(); pro.state = state; pro.uniqueId = 0; pro.createSlots(); pro.createProtos(); pro.isActivatable = true; state.registerProtoWithFunc(pro.name, new IoStateProto(pro.name, pro, new IoStateProtoFunc(pro.proto))); //pro.protos.Add(state.protoWithInitFunc("Object")); IoCFunction[] methodTable = new IoCFunction[] { new IoCFunction("namespaces", new IoMethodFunc(IoCLRAssembly.slotNamespaces)), }; pro.addTaglessMethodTable(state, methodTable); return(pro); }
public new static IoCLRAssembly createObject(IoState state) { IoCLRAssembly cf = new IoCLRAssembly(); return(cf.proto(state).clone(state) as IoCLRAssembly); }
public new static IoCLRAssembly createProto(IoState state) { IoCLRAssembly cf = new IoCLRAssembly(); return(cf.proto(state) as IoCLRAssembly); }
public IoState() { objectProto = IoObject.createProto(this); core = objectProto.clone(this); lobby = objectProto.clone(this); IoSeq seqProto = IoSeq.createProto(this); setupSingletons(); setupSymbols(); objectProto.protoFinish(this); IoMessage messageProto = IoMessage.createProto(this); nilMessage = IoMessage.createObject(this) as IoMessage; nilMessage.cachedResult = ioNil; nilMessage.messageName = IOSYMBOL("nil"); IoMap mapProto = IoMap.createProto(this); IoNumber numProto = IoNumber.createProto(this); IoCFunction cfProto = IoCFunction.createProto(this); IoBlock blockProto = IoBlock.createProto(this); //IoCoroutine coroProto = IoCoroutine.createProto(this); //mainCoroutine = coroProto; //currentCoroutine = coroProto; IoCall callProto = IoCall.createProto(this); IoList listProto = IoList.createProto(this); clrProto = IoCLR.createProto(this); IoCLRAssembly asmProto = IoCLRAssembly.createProto(this); IoCLRObject clrObjProto = IoCLRObject.createProto(this); IoObject protos = objectProto.clone(this); protos.slots["Core"] = core; protos.slots["Addons"] = null; lobby.slots["Lobby"] = lobby; lobby.slots["Protos"] = protos; core.slots["Object"] = objectProto; core.slots["Map"] = mapProto; // core.slots["Coroutine"] = coroProto; core.slots["Message"] = messageProto; core.slots["CFunction"] = cfProto; core.slots["Number"] = numProto; core.slots["Block"] = blockProto; core.slots["Call"] = callProto; core.slots["Locals"] = localsProto = objectProto.localsProto(this); core.slots["List"] = listProto; core.slots["Sequence"] = seqProto; core.slots["CLR"] = clrProto; core.slots["CLRAssembly"] = asmProto; core.slots["CLRObject"] = clrObjProto; objectProto.protos.Add(lobby); lobby.protos.Add(protos); protos.protos.Add(core); localsUpdateSlotCFunc = new IoCFunction(this, "localsUpdate", IoObject.localsUpdateSlot); initMessage = IoMessage.newWithName(this, IOSYMBOL("init")); forwardMessage = IoMessage.newWithName(this, IOSYMBOL("forward")); activateMessage = IoMessage.newWithName(this, IOSYMBOL("activate")); selfMessage = IoMessage.newWithName(this, IOSYMBOL("self")); opShuffleMessage = IoMessage.newWithName(this, IOSYMBOL("opShuffle")); mainMessage = IoMessage.newWithName(this, IOSYMBOL("main")); typeMessage = IoMessage.newWithName(this, IOSYMBOL("type")); }
public static new IoCLRAssembly createProto(IoState state) { IoCLRAssembly cf = new IoCLRAssembly(); return cf.proto(state) as IoCLRAssembly; }
public static new IoCLRAssembly createObject(IoState state) { IoCLRAssembly cf = new IoCLRAssembly(); return cf.proto(state).clone(state) as IoCLRAssembly; }
public static IoObject slotLoadAssembly(IoObject target, IoObject locals, IoObject message) { IoCLR self = target as IoCLR; IoMessage m = message as IoMessage; IoSeq assemblyName = m.localsSymbolArgAt(locals, 0); IoCLRAssembly asm = null; if (self.loadedAssemblies.ContainsKey(assemblyName.value)) { asm = self.loadedAssemblies[assemblyName.value]; if (asm != null) { return(asm); } } asm = IoCLRAssembly.createObject(target.state); var name = new AssemblyName(assemblyName.value); try { asm.assembly = Assembly.Load(name); Console.WriteLine("载入{0} ....成功!", name.Name); } catch (FileNotFoundException ex) { Console.WriteLine("载入{0} ....失败!", name.Name); } if (asm.assembly == null) { return(self); } self.loadedAssemblies[assemblyName.value] = asm; asm.assemblyTypes = asm.assembly.GetTypes(); asm.assemblyNamespaces = new Dictionary <string, Dictionary <string, Type> >(); foreach (Type t in asm.assemblyTypes) { string theNameSpace = t.FullName.LastIndexOf(".") == -1 ? "-" : t.FullName.Substring(0, t.FullName.LastIndexOf(".")); string theClass = t.FullName.LastIndexOf(".") == -1 ? t.FullName : t.FullName.Substring(t.FullName.LastIndexOf(".") + 1); if (theClass.Equals("Form")) { //~//int i = 0; } if (asm.assemblyNamespaces.ContainsKey(theNameSpace)) { Dictionary <string, Type> a = asm.assemblyNamespaces[theNameSpace]; a[theClass] = t; } else { Dictionary <string, Type> classes = new Dictionary <string, Type>(); classes[theClass] = t; asm.assemblyNamespaces[theNameSpace] = classes; } } return(asm); }