コード例 #1
0
ファイル: IoCLR.cs プロジェクト: MilkTool/io-clr
        // 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);
        }
コード例 #2
0
ファイル: IoCLR.cs プロジェクト: MilkTool/io-clr
        // 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);
        }
コード例 #3
0
        // 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);
        }
コード例 #4
0
ファイル: IoCLR.cs プロジェクト: MilkTool/io-clr
        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);
        }
コード例 #5
0
ファイル: IoCLR.cs プロジェクト: MilkTool/io-clr
        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);
        }
コード例 #6
0
ファイル: IoCLRAssembly.cs プロジェクト: stangelandcl/io-clr
        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;
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        public new static IoCLRAssembly createObject(IoState state)
        {
            IoCLRAssembly cf = new IoCLRAssembly();

            return(cf.proto(state).clone(state) as IoCLRAssembly);
        }
コード例 #9
0
        public new static IoCLRAssembly createProto(IoState state)
        {
            IoCLRAssembly cf = new IoCLRAssembly();

            return(cf.proto(state) as IoCLRAssembly);
        }
コード例 #10
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"));
        }
コード例 #11
0
ファイル: IoCLRAssembly.cs プロジェクト: stangelandcl/io-clr
 public static new IoCLRAssembly createProto(IoState state)
 {
     IoCLRAssembly cf = new IoCLRAssembly();
     return cf.proto(state) as IoCLRAssembly;
 }
コード例 #12
0
ファイル: IoCLRAssembly.cs プロジェクト: stangelandcl/io-clr
 public static new IoCLRAssembly createObject(IoState state)
 {
     IoCLRAssembly cf = new IoCLRAssembly();
     return cf.proto(state).clone(state) as IoCLRAssembly;
 }
コード例 #13
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);
        }