Beispiel #1
0
 public override void FromJson(JObject o)
 {
     name             = Token.FromJson(o["Name"]);
     block            = JsonParam.FromJson <Block>(o["Block"]);
     parents          = JsonParam.FromJsonArray <Types>((JArray)o["Parents"]);
     this.assingBlock = block;
 }
Beispiel #2
0
 public override void FromJson(JObject o)
 {
     left  = JsonParam.FromJson <Types>(o["Left"]);
     right = JsonParam.FromJson <Types>(o["Right"]);
     op    = Token.FromJson(o["Op"]);
     rtok  = Token.FromJson(o["RightToken"]);
 }
Beispiel #3
0
        public static Dictionary <T1, T2> FromJsonDictionary <T1, T2>(object obj) where T1 : Types where T2 : Types
        {
            var dict = new Dictionary <T1, T2>();

            if (obj is JValue jValue)
            {
                if (jValue.Value is string jString)
                {
                    var jSomething = JsonConvert.DeserializeObject <object>(jString);
                    if (jSomething is JArray jArray)
                    {
                        if (jArray.Count > 0)
                        {
                            var x = JsonParam.FromJsonArrayBase <KeyValuePair <JObject, JObject> >(jArray);
                            foreach (var keyValuePair in x)
                            {
                                dict.Add((T1)FromJson(keyValuePair.Key), (T2)FromJson(keyValuePair.Value));
                            }
                        }
                    }
                    else if (jSomething is JObject jObject)
                    {
                        if (jObject.Count > 0)
                        {
                            var x = 0;
                        }
                    }
                }
            }
            else
            {
                var x = 1;
            }
            return(dict);
        }
Beispiel #4
0
 public override void FromJson(JObject o)
 {
     name             = Token.FromJson(o["RealName"]);
     genericArguments = JsonParam.FromJsonArrayBase <string>((JArray)o["GenericArguments"]);
     paraml           = JsonParam.FromJson <ParameterList>(o["ParameterList"]);
     returnt          = Token.FromJson(o["Returnt"]);
     _cacheName       = o["CacheName"].ToString();
 }
Beispiel #5
0
 public override void FromJson(JObject o)
 {
     name             = JsonParam.FromJson <Variable>(o["Variable"]);
     expresion        = JsonParam.FromJson <Types>(o["Exrpesion"]);
     plist            = JsonParam.FromJson <ParameterList>(o["ParameterList"]);
     isInArgumentList = (bool)o["IsInArgumentList"];
     isCallInArgument = (bool)o["IsCallInArgument"];
     isNormalLambda   = (bool)o["IsNormalLambda"];
 }
Beispiel #6
0
 public override void FromJson(JObject o)
 {
     name             = Token.FromJson(o["Name"]);
     genericArguments = JsonParam.FromJsonArrayBase <string>((JArray)o["GenericArguments"]);
     paraml           = JsonParam.FromJson <ParameterList>(o["ParameterList"]);
     returnt          = Token.FromJson(o["Returnt"]);
     block            = JsonParam.FromJson <Block>(o["Block"]);
     assingBlock      = block;
     extendingClass   = o["ExtendingClass"].ToString();
     isConstructor    = (bool)o["IsConstructor"];
     _cacheName       = o["CacheName"].ToString();
 }
Beispiel #7
0
        public override void FromJson(JObject o)
        {
            parameters        = JsonParam.FromJsonArray <Types>((JArray)o["Parameters"]);
            allowMultipel     = (bool)o["AllowMultipel"];
            allowMultipelName = Token.FromJson(o["AllowMultipelName"]);
            var dfcstm = JsonParam.FromJsonDictionaryKeyBase <string, Types>(o["DefaulCustom"]);

            if (dfcstm.Count > 0)
            {
                Debugger.Break();
            }
        }
Beispiel #8
0
 public override void FromJson(JObject o)
 {
     conditions = JsonParam.FromJsonDictionary <Types, Block>(o["Conditions"]);
 }
Beispiel #9
0
 public override void FromJson(JObject o)
 {
     variable   = JsonParam.FromJson <Variable>(o["Variable"]);
     isIterable = (bool)o["IsIterable"];
     className  = o["ClassName"].ToString();
 }
Beispiel #10
0
        public override string Compile(int tabs = 0)
        {
            if (!found || _ihaveit != null)
            {
                return("");
            }

            //Console.WriteLine(">" +import.Value + ": " + DateTime.Now.ToShortTimeString());
            string compiled = block.Compile();

            /*!!! CACHING !!!*/
            var hash = _code.GetHashCode();
            var path = import.Value.Replace('.', '\\');
            var dir  = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);

            var _compiled = true;

            Interpreter.CurrentStaticInterpreter = interpret;
            if (File.Exists(dir + "\\" + Program.projectFolder + @"\" + path + ".p.h"))
            {
                var     fcache  = File.ReadAllText(dir + "\\" + Program.projectFolder + @"\" + path + ".p.h");
                JObject jobject = JsonConvert.DeserializeObject <JObject>(fcache);
                if (!Interpreter._RECOMPILE && (int)jobject["hash"] == hash)
                {
                    _compiled = false;
                    //It's same soo we alerady cached it OwO
                    //TODO:
                    //var cachecode = (JObject)jobject["content"];
                    //var builded = JsonParam.FromJson(cachecode);
                }
            }

            if (_compiled)
            {
                var     json  = JsonParam.ToJson(block);
                var     fname = dir + "\\" + Program.projectFolder + @"\" + path + ".p";
                var     rdir  = new FileInfo(fname).Directory.FullName;
                JObject fl    = new JObject();
                fl["hash"]    = hash;
                fl["content"] = json;
                File.WriteAllText(rdir + "\\" + GetModule() + ".p.h", fl.ToString());
                var regex      = new Regex(@"\/\/(.*)}\(typeof(.*)\,[ ]this\);", RegexOptions.Multiline | RegexOptions.Singleline);
                var newcompile = regex.Replace(compiled, "");
                File.WriteAllText(rdir + "\\" + GetModule() + ".p.c", newcompile.Trim());
            }

            string atttab = "";

            for (var i = 0; i < 5 - (import.Value.Length / 5); i++)
            {
                atttab += "\t";
            }

            var now = DateTime.Now;

            Console.Write((now.Hour < 10 ? "0": "") + now.ToShortTimeString() + ": " + import.Value + atttab + " -> [");
            Console.ForegroundColor = ConsoleColor.White;
            if (_compiled)
            {
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.Write("Compiled");
            }
            else
            {
                Console.BackgroundColor = ConsoleColor.DarkGreen;
                Console.Write(" Cached ");
            }
            Console.ResetColor();
            Console.Write("] ");
            if (interpret.stopwatch.Elapsed.Seconds > 0)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
            }
            else if (interpret.stopwatch.Elapsed.Milliseconds > 400)
            {
                Console.ForegroundColor = ConsoleColor.DarkYellow;
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
            }
            Console.WriteLine(interpret.stopwatch.Elapsed.Seconds + "." + interpret.stopwatch.Elapsed.Milliseconds.ToString("D3") + " sec");
            Console.ResetColor();
            compiled = compiled.Replace("\n", "\n  ");

            string n   = GetName();
            string tbs = DoTabs(tabs);

            var outcom = new StringBuilder();

            if (n == "")
            {
                outcom.Append("\n" + tbs + "//Imported " + GetModule() + "\n");
                outcom.Append(compiled.Substring(0, compiled.Length) + "\n");
            }
            else
            {
                outcom.Append("\n" + tbs + "//Imported " + import.Value + "\n");
                //if (n.Count(c => c == '.') > 0)
                //    outcom.Append(tbs + n + " = function (_, __){\n  'use strict';\n");
                //else
                //    outcom.Append(tbs + "var " + n + " = function (_, __){\n  'use strict';\n");
                outcom.Append(compiled.Substring(0, compiled.Length) + "\n");

                /*
                 * List<string> exposed = new List<string>();
                 * foreach (KeyValuePair<string, Types> t in block.SymbolTable.Table)
                 * {
                 *  if (t.Value == null || t.Key.Trim() == "") continue;
                 *  if (block.SymbolTable.TableIsCopy.ContainsKey(t.Key) && block.SymbolTable.TableIsCopy[t.Key])
                 *      continue;
                 *  if (t.Key == "int" || t.Key == "string" || t.Key == "null")
                 *      continue;
                 *  if (t.Value is Function && (((Function)t.Value).isExternal || ((Function)t.Value).isExtending))
                 *      continue;
                 *  if (t.Value is Class && ((Class)t.Value).isExternal)
                 *      continue;
                 *  if (t.Value is Interface && ((Interface)t.Value).isExternal)
                 *      continue;
                 *  if (t.Value is Delegate)
                 *      continue;
                 *  if (t.Value is Generic)
                 *      continue;
                 *  if (t.Value is Function tf)
                 *  {
                 *      //outcom.Append("  _." + tf.Name + " = " + tf.Name + ";\n");
                 *      //if (Interpreter._DEBUG)
                 *      //    outcom.Append("  _." + tf.Name + "$META = " + tf.Name + "$META;\n");
                 *  }
                 *  else if (t.Value is Class tc)
                 *  {
                 *      if (!tc.isForImport)
                 *      {
                 *          //outcom.Append("  _." + tc.getName() + " = " + tc.getName() + ";\n");
                 *          //if (Interpreter._DEBUG)
                 *          //    outcom.Append("  _." + tc.getName() + "$META = " + tc.getName() + "$META;\n");
                 *      }
                 *      if (tc.isForImport)
                 *      {
                 *          outcom.Append(Program.DrawClassInside(tc, tc.getName(), exposed, import.Value));
                 *      }
                 *  }
                 *  else if (t.Value is Interface ti)
                 *  {
                 *      //outcom.Append("  _." + ti.getName() + " = " + ti.getName() + ";\n");
                 *      //if (Interpreter._DEBUG)
                 *      //    outcom.Append("  _." + ti.getName() + "$META = " + ti.getName() + "$META;\n");
                 *  }
                 *  else if (t.Value is Import im)
                 *  {
                 *      var split = im.GetName().Split('.');
                 *      var namem = string.Join(".", split.Take(split.Length - 1));
                 *      if (namem == "") namem = split[0];
                 *      if(namem == import.Value)
                 *          continue;
                 *
                 *      if (t.Key.Contains("."))
                 *      {
                 *          var skl = "";
                 *          foreach (string p in t.Key.Split('.').Take(t.Key.Split('.').Length - 1))
                 *          {
                 *              skl += (skl == "" ? "" : ".") + p;
                 *              if (!Program.importClass.Contains(skl))
                 *              {
                 *                  Program.importClass.Add(skl);
                 *                  //outcom.Append("  _." + skl + " = {};\n");
                 *              }
                 *          }
                 *      }
                 *      if (im.GetName() == "")
                 *      {
                 *          //outcom.Append("  _." + t.Key + " = " + im.GetModule() + ";\n");
                 *          //if (im.As != "")
                 *          //    outcom.Append("  var " + t.Key + " = " + im.GetModule() + ";\n");
                 *      }
                 *      else
                 *      {
                 *          var name = "";
                 *          if (im.GetName().Replace('.', '_') != im.GetModule())
                 *          {
                 *              //name = "module_" + im.GetName().Replace('.', '_') + "_" + im.GetModule();
                 *              //outcom.Append("  var " + name + " = GetModule(\"" + im.GetName() + "." + im.GetModule() + "\");\n");
                 *          }
                 *          else
                 *          {
                 *              //name = "module_" + im.GetName().Replace('.', '_');
                 *              //outcom.Append("  var " + name + " = GetModule(\"" + im.GetName() + "\");\n");
                 *          }
                 *
                 *          //outcom += "  _." + t.Key + " = " + name + ";\n";
                 *          //if (im.As != "")
                 *          //    outcom.Append("  var " + t.Key + " = " + name + ";\n");
                 *      }
                 *      if(!exposed.Contains(t.Key))
                 *          exposed.Add(t.Key);
                 *      foreach (KeyValuePair<string, Types> qq in im.Block.SymbolTable.Table)
                 *      {
                 *          if (qq.Value is Class && !exposed.Contains(qq.Key) && !((Class)qq.Value).isExternal)
                 *          {
                 *              if (im.GetName() != "")
                 *              {
                 *                  //outcom.Append("  var " + qq.Key + " = " + im.GetName() + "." + ((Class)qq.Value).getName() + ";\n");
                 *                  exposed.Add(qq.Key);
                 *              }
                 *          }
                 *      }
                 *  }
                 *  //else
                 *  //    outcom.Append(tbs + "  _." + t.Key + " = " + t.Key + ";\n");
                 * }
                 *
                 * if(import.Value.Contains("."))
                 *  outcom.Append("\n"+tbs+"  DefineModule('"+GetName()+"."+GetModule()+"', _);\n");
                 * else
                 *  outcom.Append("\n"+tbs+"  DefineModule('"+GetModule()+"', _);\n");
                 *
                 * outcom.Append(tbs + "\n  return _;\n");
                 * outcom.Append(tbs + "}(typeof " + n + " === 'undefined' ? {} : " + n + ", this);\n");
                 */
            }
            return(outcom.ToString());
        }