Inheritance: IoObject
Exemple #1
0
        // 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);
        }
Exemple #2
0
        public static IoObject slotGetType(IoObject target, IoObject locals, IoObject message)
        {
            IoCLR     self     = target as IoCLR;
            IoMessage m        = message as IoMessage;
            IoSeq     typeName = m.localsSymbolArgAt(locals, 0);
            IoObject  obj      = self.getType(target.state, typeName.value);

            return(obj == null ? target.state.ioNil : obj);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public override IoObject proto(IoState state)
        {
            IoCLR pro = new IoCLR();

            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("loadAssembly", new IoMethodFunc(IoCLR.slotLoadAssembly)),
                new IoCFunction("using", new IoMethodFunc(IoCLR.slotUsing)),
                new IoCFunction("getType", new IoMethodFunc(IoCLR.slotGetType)),
            };

            pro.addTaglessMethodTable(state, methodTable);
            return(pro);
        }
Exemple #5
0
        public new static IoCLR createObject(IoState state)
        {
            IoCLR cf = new IoCLR();

            return(cf.proto(state).clone(state) as IoCLR);
        }
Exemple #6
0
        public new static IoCLR createProto(IoState state)
        {
            IoCLR cf = new IoCLR();

            return(cf.proto(state) as IoCLR);
        }
Exemple #7
0
        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"));
        }
Exemple #8
0
 public static new IoCLR createProto(IoState state)
 {
     IoCLR cf = new IoCLR();
     return cf.proto(state) as IoCLR;
 }
Exemple #9
0
 public static new IoCLR createObject(IoState state)
 {
     IoCLR cf = new IoCLR();
     return cf.proto(state).clone(state) as IoCLR;
 }
Exemple #10
0
        public override IoObject proto(IoState state)
        {
            IoCLR pro = new IoCLR();
            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("loadAssembly", new IoMethodFunc(IoCLR.slotLoadAssembly)),
                new IoCFunction("using", new IoMethodFunc(IoCLR.slotUsing)),
                new IoCFunction("getType", new IoMethodFunc(IoCLR.slotGetType)),
            };

            pro.addTaglessMethodTable(state, methodTable);
            return pro;
        }
Exemple #11
0
        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"));
        }
Exemple #12
0
        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);
        }