Ejemplo n.º 1
0
 public Symbol <float> CType(MetaSymbol a, MetaSymbol b)
 {
     if (a.Type == b.Type)
     {
         return(new Symbol <float>(Tokens.NUM, 0));
     }
     return(new Symbol <float>(Tokens.NUM, -1));
 }
Ejemplo n.º 2
0
        public void Jmp(Symbol <int> ptr, MetaSymbol arg)
        {
            var    fun = mini.GetAddress <Instruction>(ptr.Value, Tokens.LBL, Tokens.FUN).Value;
            object o   = mini.FindObject(fun.ObjectIdentifier, noerror: true);

            o = o ?? mini;

            fun.Call(new MetaSymbol[] { arg }, o);
            Ret();
        }
Ejemplo n.º 3
0
        public void Push(Symbol <int> ptr, MetaSymbol value)
        {
            var list = mini.GetRegister <List <MetaSymbol> >(ptr.Value, Tokens.LIST).Value;

            if (list.Count > 0 && list[0].Type != value.Type)
            {
                throw new SyntaxError(list[0].Type, value.Type);
            }

            list.Add(value);
        }
Ejemplo n.º 4
0
        public void Loop(Symbol <int> ptr)
        {
            var fun = mini.GetAddress <Instruction>(ptr.Value, Tokens.LBL).Value;

            int itreg = ptr.Value;
            var args  = new MetaSymbol[0];

            while (mini.GetRegister <float>(1, Tokens.NUM).Value != 0)
            {
                fun.Call(args, mini);
            }
        }
Ejemplo n.º 5
0
        void CheckReturnType(MetaSymbol ax)
        {
            if (returnType == Tokens.NIL)
            {
                return;
            }

            if (ax.Type != returnType)
            {
                throw new TypeError("return", returnType, ax.Type);
            }
        }
Ejemplo n.º 6
0
        public void Mov(Symbol <int> ptr, Symbol <float> index, MetaSymbol value)
        {
            var list = mini.GetRegister <List <MetaSymbol> >(ptr.Value, Tokens.LIST).Value;

            if (list.Count > 0 && list[0].Type != value.Type)
            {
                throw new SyntaxError(list[0].Type, value.Type);
            }

            int i = (int)index.Value;

            i       = i < 0 ? list.Count + i : i;
            list[i] = value;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Invokes a method in C#
        /// </summary>
        public override MetaSymbol Call(MetaSymbol[] args, object csobj)
        {
            SignatureMatch(args);
            Type type = csobj.GetType();

            knownObj = type.ToString();

            var        info   = type.GetMethod(methodName, internalSign);
            MetaSymbol result = (MetaSymbol)info.Invoke(csobj, args);

            calls++;

            return(result ?? MetaSymbol.Nil);
        }
Ejemplo n.º 8
0
        public void For(Symbol <int> ptr, Symbol <List <MetaSymbol> > list, Symbol <int> label)
        {
            var fun = mini.GetAddress <Instruction>(label.Value, Tokens.LBL, Tokens.FUN).Value;

            object o = mini.FindObject(fun.ObjectIdentifier, noerror: true);

            o = o ?? mini;

            int itreg = ptr.Value;
            var args  = new MetaSymbol[0];

            foreach (var item in list.Value)
            {
                mini.SetAddress(itreg, item);
                fun.Call(args, o);
            }
        }
Ejemplo n.º 9
0
        public void For(Symbol <int> ptr, Symbol <float> max, Symbol <int> label)
        {
            var fun = mini.GetAddress <Instruction>(label.Value, Tokens.LBL, Tokens.FUN).Value;

            object o = mini.FindObject(fun.ObjectIdentifier, noerror: true);

            o = o ?? mini;

            int itreg = ptr.Value;
            var args  = new MetaSymbol[0];

            for (int i = 0; i < max.Value; i++)
            {
                mini.SetAddress(itreg, new Symbol <float>(Tokens.NUM, i));
                fun.Call(args, o);
            }
        }
Ejemplo n.º 10
0
        bool GreaterThan(MetaSymbol a, MetaSymbol b)
        {
            if (a.Type != b.Type)
            {
                return(false);
            }

            switch (a.Type)
            {
            case Tokens.NUM:
                return(MetaSymbol.Cast <float>(Tokens.NUM, a).Value > MetaSymbol.Cast <float>(Tokens.NUM, b).Value);

            case Tokens.INT:
                return(MetaSymbol.Cast <int>(Tokens.INT, a).Value < MetaSymbol.Cast <int>(Tokens.INT, b).Value);

            default:
                throw new SyntaxError("<num>|<int>", a.Type);
            }
        }
Ejemplo n.º 11
0
        public Symbol <float> Cmp(MetaSymbol a, MetaSymbol b)
        {
            if (Equal(a, b))
            {
                return(new Symbol <float>(Tokens.NUM, 0));
            }

            if (a.Type == b.Type && (a.Type == Tokens.NUM || a.Type == Tokens.INT))
            {
                // must be int or num to compare greater than
                if (GreaterThan(a, b))
                {
                    return(new Symbol <float>(Tokens.NUM, 1));
                }
            }

            // not equal or less than
            return(new Symbol <float>(Tokens.NUM, -1));
        }
Ejemplo n.º 12
0
        public ActionResult RefreshAll()
        {
            try
            {
                List <object> mss = (List <object>)MainService.GetObjects(EntitiesEnum.MetaSymbol);
                foreach (var m in mss)
                {
                    MetaSymbol ms      = (MetaSymbol)m;
                    SignalInfo signalC = MainService.CreateSignal(SignalFlags.Cluster, ms.Id, EnumSignals.SIGNAL_ACTIVE_ORDERS);
                    MainService.PostSignalTo(signalC);
                }

                return(Ok(HttpStatusCode.OK));
            }
            catch (Exception e)
            {
                log.Error(e.ToString());
                return(Problem(e.ToString(), "Error", StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 13
0
        bool Equal(MetaSymbol a, MetaSymbol b)
        {
            if (a.Type != b.Type)
            {
                return(false);
            }

            switch (a.Type)
            {
            case Tokens.NUM:
                return(MetaSymbol.Cast <float>(Tokens.NUM, a).Value == MetaSymbol.Cast <float>(Tokens.NUM, b).Value);

            case Tokens.STR:
                return(MetaSymbol.Cast <string>(Tokens.STR, a).Value == MetaSymbol.Cast <string>(Tokens.STR, b).Value);

            case Tokens.INT:
                return(MetaSymbol.Cast <int>(Tokens.INT, a).Value == MetaSymbol.Cast <int>(Tokens.INT, b).Value);

            default:
                throw new SyntaxError("<num>|<str>|<int>", a.Type);
            }
        }
Ejemplo n.º 14
0
        public void For(Symbol <int> ptr, Symbol <Vector3> max, Symbol <int> label)
        {
            var calladdr = mini.GetAddress <Instruction>(label.Value, Tokens.LBL, Tokens.FUN).Value;

            object o = mini.FindObject(calladdr.ObjectIdentifier, noerror: true);

            o = o ?? mini;

            int itreg = ptr.Value;
            var args  = new MetaSymbol[0];

            for (int x = 0; x < max.Value.x; x++)
            {
                for (int y = 0; y < max.Value.y; y++)
                {
                    for (int z = 0; z < max.Value.z; z++)
                    {
                        mini.SetAddress(itreg, new Symbol <Vector3>(Tokens.VEC, new Vector3(x, y, z)));
                        calladdr.Call(args, o);
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public MetaValue(MetaSymbol symbol)
 {
     Symbol = symbol ?? throw new ArgumentNullException(nameof(symbol));
 }
Ejemplo n.º 16
0
 public MetaSymbol Ret(MetaSymbol value)
 {
     Ret();
     return(value);
 }
Ejemplo n.º 17
0
 public MetadataReference(MetaSymbol symbol)
 {
     this.symbol = symbol;
 }
Ejemplo n.º 18
0
 public void Mov(Symbol <int> ptr, MetaSymbol value)
 {
     mini.SetAddress(ptr.Value, value);
 }
Ejemplo n.º 19
0
 public MetaSymbol Mov(MetaSymbol value)
 {
     return(value);
 }