Пример #1
0
        public static IoNumber newWithDouble(IoState state, double n)
        {
            IoNumber fab = new IoNumber();
            IoNumber num = state.protoWithInitFunc(fab.name) as IoNumber;

            num             = num.clone(state) as IoNumber;
            num.isInteger   = false;
            num.doubleValue = n;

            if (Double.Equals(n, 0) ||
                (!Double.IsInfinity(n) && !Double.IsNaN(n) &&
                 !n.ToString(CultureInfo.InvariantCulture).Contains(".") &&
                 !n.ToString(CultureInfo.InvariantCulture).Contains("E") &&
                 !n.ToString(CultureInfo.InvariantCulture).Contains("e")
                )
                )
            {
                try
                {
                    num.longValue = Convert.ToInt32(n);
                    num.isInteger = true;
                }
                catch (OverflowException oe)
                {
                }
            }
            return(num);
        }
Пример #2
0
        public static IoNumber newWithDouble(IoState state, double n)
        {
            IoNumber fab = new IoNumber();
            IoNumber num = state.protoWithInitFunc(fab.name) as IoNumber;
            num = num.clone(state) as IoNumber;
            num.isInteger = false;
            num.doubleValue = n;

            if (Double.Equals(n, 0) ||
                (!Double.IsInfinity(n) && !Double.IsNaN(n) &&
                !n.ToString(CultureInfo.InvariantCulture).Contains(".") &&
                !n.ToString(CultureInfo.InvariantCulture).Contains("E") &&
                !n.ToString(CultureInfo.InvariantCulture).Contains("e")
                )
            )
            {
                try
                {
                    num.longValue = Convert.ToInt32(n);
                    num.isInteger = true;
                }
                catch (OverflowException oe)
                {

                }
            }
            return num;
        }
Пример #3
0
        public static IoObject slotSubstract(IoObject self, IoObject locals, IoObject message)
        {
            IoMessage m = message as IoMessage;
            IoNumber  o = m.localsNumberArgAt(locals, 0);

            return(IoNumber.newWithDouble(self.state, -o.asDouble()));
        }
Пример #4
0
        private static IEnumerator Recurse2(IoCoroutine f)
        {
            //yield return null; // just create and quit // 1

            //f.fiber.Yield(f);

            IoCoroutine ccc = IoCoroutine.createObject(IoCLI.state);

            ccc.fiber             = new Fiber();
            ccc.fiber.currentCoro = ccc;
            //yield return
            ccc.fiber.currentRoutine = new FiberProc(IoCLI.Recurse3 /*(ccc)*/);
            if (coro.fiber.State == 4)
            {
                Console.WriteLine("Creation Error. Fiber Exceeds on Recurse 2 " + f.uniqueId);
                IoCLI.yieldingCoros.Remove(f);
                return(null);
            }
            ccc.rawSetResult(IoNumber.newWithDouble(IoCLI.state, 42));
            ccc.rawSetRunLocals(IoCLI.state.core);
            ccc.rawSetRunMessage(IoCLI.state.nilMessage);
            ccc.rawSetRunTarget(ccc);
            IoCLI.yieldingCoros.Add(ccc);

            //Console.WriteLine("Coro2 " + f.uniqueId + " creates Coro3 + " + ccc.uniqueId);

            IoCLI.yieldingCoros.Remove(f);
            //yield return null; // 2

            return(null);
        }
Пример #5
0
        public override IoObject proto(IoState state)
        {
            IoNumber pro = new IoNumber();

            pro.state = state;
            pro.createSlots();
            pro.createProtos();
            pro.doubleValue = 0;
            pro.longValue   = 0;
            pro.isInteger   = true;
            state.registerProtoWithFunc(name, new IoStateProto(pro.name, pro, new IoStateProtoFunc(pro.proto)));
            pro.protos.Add(state.protoWithInitFunc("Object"));

            IoCFunction[] methodTable = new IoCFunction[] {
                new IoCFunction("asNumber", new IoMethodFunc(IoNumber.slotAsNumber)),
                new IoCFunction("+", new IoMethodFunc(IoNumber.slotAdd)),
                new IoCFunction("-", new IoMethodFunc(IoNumber.slotSubstract)),
                new IoCFunction("*", new IoMethodFunc(IoNumber.slotMultiply)),
                new IoCFunction("/", new IoMethodFunc(IoNumber.slotDivide)),
                new IoCFunction("log10", new IoMethodFunc(IoNumber.slotLog10)),
                new IoCFunction("log2", new IoMethodFunc(IoNumber.slotLog2)),
                new IoCFunction("log", new IoMethodFunc(IoNumber.slotLog)),
                new IoCFunction("pow", new IoMethodFunc(IoNumber.slotPow)),
                new IoCFunction("pi", new IoMethodFunc(IoNumber.slotPi)),
                new IoCFunction("e", new IoMethodFunc(IoNumber.slotE)),
                new IoCFunction("minPositive", new IoMethodFunc(IoNumber.slotMinPositive)),
                new IoCFunction("exp", new IoMethodFunc(IoNumber.slotExp)),
                new IoCFunction("round", new IoMethodFunc(IoNumber.slotRound)),
//                new IoCFunction("asString", new IoMethodFunc(this.asString))
            };

            pro.addTaglessMethodTable(state, methodTable);
            return(pro);
        }
Пример #6
0
        // Published Slots

        public static IoObject slotCompare(IoObject self, IoObject locals, IoObject message)
        {
            IoMessage m = message as IoMessage;
            IoObject  o = m.localsValueArgAt(locals, 0);

            return(IoNumber.newWithDouble(self.state, Convert.ToDouble(self.compare(o))));
        }
Пример #7
0
        // setSlot("A", 32.45 + (20*(5836 log10)) + (20*(8.5 log10)))
        // !link-budget 22 0 13 126.3606841787141377 8 0

        public static IoObject slotLog2(IoObject target, IoObject locals, IoObject message)
        {
            // IoNumber other = (message as IoMessage).localsNumberArgAt(locals, 0);
            IoNumber self = target as IoNumber;

            return(IoNumber.newWithDouble(target.state,
                                          Math.Log(self.isInteger ? self.longValue : self.doubleValue, 2)));
        }
Пример #8
0
        public static IoObject slotRound(IoObject target, IoObject locals, IoObject message)
        {
            IoNumber self = target as IoNumber;

            return(IoNumber.newWithDouble(target.state,
                                          Math.Round(self.isInteger ? self.longValue : self.doubleValue)
                                          ));
        }
Пример #9
0
Файл: IoList.cs Проект: ypyf/io
        public static IoObject slotAt(IoObject target, IoObject locals, IoObject message)
        {
            IoMessage m   = message as IoMessage;
            IoNumber  ind = m.localsNumberArgAt(locals, 0);
            IoList    o   = target as IoList;
            IoObject  v   = o.list[ind.asInt()] as IoObject;

            return(v == null ? target.state.ioNil : v);
        }
Пример #10
0
        public static IoObject slotDivide(IoObject target, IoObject locals, IoObject message)
        {
            IoNumber other = (message as IoMessage).localsNumberArgAt(locals, 0);
            IoNumber self  = target as IoNumber;

            return(IoNumber.newWithDouble(target.state,
                                          (self.isInteger ? self.longValue : self.doubleValue) /
                                          (other.isInteger ? other.longValue : other.doubleValue)));
        }
Пример #11
0
        public static IoObject slotSize(IoObject target, IoObject locals, IoObject m)
        {
            IoMap dict = target as IoMap;

            if (dict.map != null)
            {
                return(IoNumber.newWithDouble(dict.tag.state, dict.map.Count));
            }
            return(dict.tag.state.ioNil);
        }
Пример #12
0
        public static IoObject slotAt(IoObject target, IoObject locals, IoObject message)
        {
            IoMessage m   = message as IoMessage;
            IoSeq     o   = target as IoSeq;
            IoSeq     res = IoSeq.createObject(target.state);
            IoNumber  arg = m.localsNumberArgAt(locals, 0);

            res.value += o.value.Substring(arg.asInt(), 1);
            return(res);
        }
Пример #13
0
Файл: IoList.cs Проект: ypyf/io
        // Published Slots

        public static IoObject slotIndexOf(IoObject target, IoObject locals, IoObject m)
        {
            IoList   o     = target as IoList;
            IoObject value = (m as IoMessage).localsValueArgAt(locals, 1);

            try
            {
                return(IoNumber.newWithDouble(target.state, o.list.IndexOf(value)));
            }
            catch (ArgumentOutOfRangeException aoore)
            {
                object ex = aoore;
                return(target.state.ioNil);
            }
        }
Пример #14
0
        private static IEnumerator Recurse3(IoCoroutine f)
        {
            IoCoroutine ccc = IoCoroutine.createObject(IoCLI.state);

            ccc.fiber                = new Fiber();
            ccc.fiber.currentCoro    = ccc;
            ccc.fiber.currentRoutine = IoCLI.Recurse4(ccc);
            ccc.rawSetResult(IoNumber.newWithDouble(IoCLI.state, 42));
            ccc.rawSetRunLocals(IoCLI.state.core);
            ccc.rawSetRunMessage(IoCLI.state.nilMessage);
            ccc.rawSetRunTarget(ccc);
            IoCLI.yieldingCoros.Add(ccc);

            Console.WriteLine("Recurse3+" + i++);

            yield return(ccc);
        }
Пример #15
0
        private static IEnumerator Recurse2(IoCoroutine f)
        {
            yield return(null); // just create and quit

            IoCoroutine ccc = IoCoroutine.createObject(IoCLI.state);

            ccc.fiber                = new Fiber();
            ccc.fiber.currentCoro    = ccc;
            ccc.fiber.currentRoutine = IoCLI.Recurse3(ccc);
            ccc.rawSetResult(IoNumber.newWithDouble(IoCLI.state, 42));
            ccc.rawSetRunLocals(IoCLI.state.core);
            ccc.rawSetRunMessage(IoCLI.state.nilMessage);
            ccc.rawSetRunTarget(ccc);
            IoCLI.yieldingCoros.Add(ccc);

            yield return(ccc);
        }
Пример #16
0
Файл: IoList.cs Проект: ypyf/io
        public static IoObject slotRemoveAt(IoObject target, IoObject locals, IoObject message)
        {
            IoMessage m   = message as IoMessage;
            IoNumber  ind = m.localsNumberArgAt(locals, 0);
            IoList    o   = target as IoList;

            try
            {
                o.list.RemoveAt(ind.asInt());
                return(target);
            }
            catch (ArgumentOutOfRangeException aoore)
            {
                object ex = aoore;
                return(target.state.ioNil);
            }
        }
Пример #17
0
        public override int compare(IoObject v)
        {
            IoNumber o = this as IoNumber;

            if (v is IoNumber)
            {
                if (Convert.ToDouble((v as IoNumber).value) == Convert.ToDouble(o.value))
                {
                    return(0);
                }
                double d         = (v as IoNumber).isInteger ? (v as IoNumber).longValue : (v as IoNumber).doubleValue;
                double thisValue = o.isInteger ? o.longValue : o.doubleValue;

                return(thisValue < d ? -1 : 1);
            }
            return(base.compare(v));
        }
Пример #18
0
        void ifPossibleCacheToken(IoToken token)
        {
            IoSeq    method = this.messageName;
            IoObject r      = null;

            switch (token.type)
            {
            case IoTokenType.TRIQUOTE_TOKEN:
                break;

            case IoTokenType.MONOQUOTE_TOKEN:
                r = IoSeq.createSymbolInMachine(
                    method.state,
                    IoSeq.rawAsUnescapedSymbol(
                        IoSeq.rawAsUnquotedSymbol(
                            IoSeq.createObject(method.state, method.value)
                            )
                        ).value
                    );
                break;

            case IoTokenType.NUMBER_TOKEN:
                r = IoNumber.newWithDouble(this.state, Convert.ToDouble(method.value, CultureInfo.InvariantCulture));
                break;

            default:
                if (method.value.Equals("nil"))
                {
                    r = state.ioNil;
                }
                else if (method.value.Equals("true"))
                {
                    r = state.ioTrue;
                }
                else if (method.value.Equals("false"))
                {
                    r = state.ioFalse;
                }
                break;
            }
            this.cachedResult = r;
        }
Пример #19
0
        public static IoObject slotYield(IoObject target, IoObject locals, IoObject message)
        {
            IoState state = target.state;
            List <IEnumerator <IoObject> > toDeleteThread = new List <IEnumerator <IoObject> >();

            for (int i = 0; i < state.contextList.Count; i++)
            {
                IEnumerator <IoObject> e = state.contextList[i];
                bool end = e.MoveNext();
                if (!end)
                {
                    toDeleteThread.Add(e);
                }
            }
            foreach (var e in toDeleteThread)
            {
                state.contextList.Remove(e);
            }
            return(IoNumber.newWithDouble(state, state.contextList.Count));
        }
Пример #20
0
        private static IEnumerator Recurse3(IoCoroutine f)
        {
            int i = 0;

            IoCoroutine ccc = IoCoroutine.createObject(IoCLI.state);

            ccc.fiber             = new Fiber();
            ccc.fiber.currentCoro = ccc;
            //yield return
            ccc.fiber.currentRoutine = new FiberProc(IoCLI.Recurse4 /*(ccc)*/);
            if (coro.fiber.State == 4)
            {
                Console.WriteLine("Creation Error. Fiber Exceeds on Recurse 3 " + f.uniqueId);
                IoCLI.yieldingCoros.Remove(f);
                return(null);
            }
            ccc.rawSetResult(IoNumber.newWithDouble(IoCLI.state, 42));
            ccc.rawSetRunLocals(IoCLI.state.core);
            ccc.rawSetRunMessage(IoCLI.state.nilMessage);
            ccc.rawSetRunTarget(ccc);
            IoCLI.yieldingCoros.Add(ccc);

            IoCLI.yieldingCorosCount++;

            //Console.WriteLine("Coro3 " + f.uniqueId + " creates Coro4 + " + ccc.uniqueId);

            while (i < 2)
            {
                // f.fiber.Yield(f);
                //Console.WriteLine("Recurse3 Fiber: " + f.uniqueId + " Iteration: " + i++);
                //yield return null;
                i++;
            }

            IoCLI.yieldingCoros.Remove(f);

            return(null);
        }
Пример #21
0
 public static IoObject slotYieldingCoros(IoObject target, IoObject locals, IoObject message)
 {
     return(IoNumber.newWithDouble(target.state, target.state.contextList.Count));
 }
Пример #22
0
 public static new IoNumber createProto(IoState state)
 {
     IoNumber number = new IoNumber();
     return number.proto(state) as IoNumber;
 }
Пример #23
0
        public new static IoNumber createProto(IoState state)
        {
            IoNumber number = new IoNumber();

            return(number.proto(state) as IoNumber);
        }
Пример #24
0
        public static IoObject slotArgCount(IoObject target, IoObject locals, IoObject message)
        {
            IoMessage self = target as IoMessage;

            return(IoNumber.newWithDouble(target.state, Convert.ToDouble(self.args.Count)));
        }
Пример #25
0
        public static IoObject slotE(IoObject target, IoObject locals, IoObject message)
        {
            IoNumber self = target as IoNumber;

            return(IoNumber.newWithDouble(target.state, Math.E));
        }
Пример #26
0
        public static IoObject slotMinPositive(IoObject target, IoObject locals, IoObject message)
        {
            IoNumber self = target as IoNumber;

            return(IoNumber.newWithDouble(target.state, Double.Epsilon));
        }
Пример #27
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"));
        }
Пример #28
0
        public override IoObject activate(IoObject self, IoObject target, IoObject locals, IoMessage m, IoObject slotContext)
        {
            IoCLRFunction method = self as IoCLRFunction;
            IoCLRObject   obj    = target as IoCLRObject;
            object        result = null;

            object[] parameters = new object[method.evaluatedParameters.Count];
            for (int i = 0; i < method.evaluatedParameters.Count; i++)
            {
                IoObject ep = method.evaluatedParameters[i] as IoObject;
                switch (ep.name)
                {
                case "Object": parameters[i] = ep; break;

                case "Number":
                {
                    IoNumber num = ep as IoNumber;
                    if (num.isInteger)
                    {
                        parameters[i] = num.longValue;
                    }
                    else
                    {
                        parameters[i] = num.doubleValue;
                    }
                }
                break;

                case "Sequence": parameters[i] = (ep as IoSeq).value; break;

                case "CLRObject": parameters[i] = (ep as IoCLRObject).clrInstance; break;
                }
            }

            IoCLRObject clr = IoCLRObject.createObject(self.state);

            try
            {
                if (method.methodInfo is ConstructorInfo)
                {
                    ConstructorInfo ci = method.methodInfo as ConstructorInfo;
                    result = ci.Invoke(parameters);
                }
                else if (method.methodInfo is MethodInfo)
                {
                    MethodInfo mi = method.methodInfo as MethodInfo;
                    result = mi.Invoke(obj.clrInstance, parameters);
                }
                clr.clrType = result != null?result.GetType() : null;

                clr.clrInstance = result;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                clr.clrType     = null;
                clr.clrInstance = null;
            }

            return(clr);
        }
Пример #29
0
Файл: IoList.cs Проект: ypyf/io
        public static IoObject slotSize(IoObject target, IoObject locals, IoObject m)
        {
            IoList o = target as IoList;

            return(IoNumber.newWithDouble(target.state, o.list.Count));
        }
Пример #30
0
        public override IoObject proto(IoState state)
        {
            IoNumber pro = new IoNumber();
            pro.state = state;
            pro.createSlots();
            pro.createProtos();
            pro.doubleValue = 0;
            pro.longValue = 0;
            pro.isInteger = true;
            state.registerProtoWithFunc(name, new IoStateProto(pro.name, pro, new IoStateProtoFunc(pro.proto)));
            pro.protos.Add(state.protoWithInitFunc("Object"));

            IoCFunction[] methodTable = new IoCFunction[] {
                new IoCFunction("asNumber", new IoMethodFunc(IoNumber.slotAsNumber)),
                new IoCFunction("+", new IoMethodFunc(IoNumber.slotAdd)),
                new IoCFunction("-", new IoMethodFunc(IoNumber.slotSubstract)),
                new IoCFunction("*", new IoMethodFunc(IoNumber.slotMultiply)),
                new IoCFunction("/", new IoMethodFunc(IoNumber.slotDivide)),
                new IoCFunction("log10", new IoMethodFunc(IoNumber.slotLog10)),
                new IoCFunction("log2", new IoMethodFunc(IoNumber.slotLog2)),
                new IoCFunction("log", new IoMethodFunc(IoNumber.slotLog)),
                new IoCFunction("pow", new IoMethodFunc(IoNumber.slotPow)),
                new IoCFunction("pi", new IoMethodFunc(IoNumber.slotPi)),
                new IoCFunction("e", new IoMethodFunc(IoNumber.slotE)),
                new IoCFunction("minPositive", new IoMethodFunc(IoNumber.slotMinPositive)),
                new IoCFunction("exp", new IoMethodFunc(IoNumber.slotExp)),
                new IoCFunction("round", new IoMethodFunc(IoNumber.slotRound)),
            //                new IoCFunction("asString", new IoMethodFunc(this.asString))
            };

            pro.addTaglessMethodTable(state, methodTable);
            return pro;
        }