Exemplo n.º 1
0
        public static string JsonSchemaFaker(JsonSchema4 schema, List <object> ReferenceStack, bool UseXMlNames = false)
        {
            if (ReferenceStack == null)
            {
                ReferenceStack = new List <object>();
            }
            ReferenceStack.Add(schema);
            if (CachedValues.ContainsKey(schema))
            {
                object returnValue;
                CachedValues.TryGetValue(schema, out returnValue);
                return((string)returnValue);
            }



            if (schema.HasReference)
            {
                if (ReferenceStack.Contains(schema.Reference))
                {
                    return(string.Empty);
                }
                else
                {
                    return(JsonSchemaFaker(schema.Reference, ReferenceStack, UseXMlNames));
                }
            }



            Dictionary <string, object> JsonBody = new Dictionary <string, object>();

            foreach (KeyValuePair <string, JsonProperty> jkp in schema.ActualProperties)
            {
                //code
                string key = jkp.Key;
                if (UseXMlNames && jkp.Value.Xml != null)
                {
                    key = jkp.Value.Xml.Name;
                }
                if (jkp.Value.HasReference && !ReferenceStack.Contains(jkp.Value.Reference))
                {
                    if (jkp.Value.Reference.HasReference == false && jkp.Value.Reference.Properties.Count == 0)
                    {
                        object o1 = GenerateJsonObjectFromJsonSchema4(jkp.Value, ReferenceStack, UseXMlNames);
                        JsonBody.Add(key, o1);
                    }
                    else
                    {
                        if (!jkp.Value.Reference.Equals(jkp.Value))
                        {
                            string property = JsonSchemaFaker(jkp.Value.Reference, ReferenceStack, UseXMlNames);
                            object o        = JsonConvert.DeserializeObject(property);
                            JsonBody.Add(key, o);
                        }
                    }
                }
                else
                {
                    object o = GenerateJsonObjectFromJsonSchema4(jkp.Value, ReferenceStack, UseXMlNames);
                    JsonBody.Add(key, o);
                }
            }

            ReferenceStack.Remove(schema);

            string output = JsonConvert.SerializeObject(JsonBody);

            CachedValues.Add(schema, output);
            return(output);
        }
Exemplo n.º 2
0
        private static object GenerateJsonObjectFromJsonSchema4(JsonProperty value, List <object> ReferenceStack, bool UseXMlNames)
        {
            if (CachedValues.ContainsKey(value))
            {
                object returnValue;
                CachedValues.TryGetValue(value, out returnValue);
                return(returnValue);
            }
            if (ReferenceStack == null)
            {
                ReferenceStack = new List <object>();
            }

            List <object> PrivateStack = new List <object>();
            object        output       = "";

            switch (value.Type)
            {
            case JsonObjectType.Object:

                Dictionary <string, object> JsonBody = new Dictionary <string, object>();
                foreach (KeyValuePair <string, JsonProperty> jkp in value.ActualProperties)
                {
                    string key = jkp.Key;
                    if (UseXMlNames && jkp.Value.Xml != null)
                    {
                        key = jkp.Value.Xml.Name;
                    }
                    ReferenceStack.Add(jkp.Value);
                    PrivateStack.Add(jkp.Value);
                    object JObject = GenerateJsonObjectFromJsonSchema4(jkp.Value, ReferenceStack, UseXMlNames);
                    JsonBody.Add(key, JsonConvert.SerializeObject(JObject));
                }
                output = JsonBody;
                break;

            case JsonObjectType.Array:



                JObject jb = new JObject();
                foreach (var item in value.Item.ActualProperties)
                {
                    string key = item.Key;
                    if (UseXMlNames && item.Value.Xml != null)
                    {
                        key = item.Value.Xml.Name;
                    }
                    ReferenceStack.Add(item.Value);
                    PrivateStack.Add(item.Value);
                    object JsonObject = GenerateJsonObjectFromJsonSchema4(item.Value, ReferenceStack, UseXMlNames);
                    jb.Add(key, JsonConvert.SerializeObject(JsonObject));
                }
                if (value.Item.HasReference)
                {
                    if (!ReferenceStack.Contains(value.Item.Reference))
                    {
                        foreach (var item in value.Item.Reference.ActualProperties)
                        {
                            if (item.Value.Equals(value))
                            {
                                jb.Add(item.Key, "");
                            }
                            else
                            {
                                string key = item.Key;
                                if (UseXMlNames && item.Value.Xml != null)
                                {
                                    key = item.Value.Xml.Name;
                                }

                                object o = GenerateJsonObjectFromJsonSchema4(item.Value, ReferenceStack, UseXMlNames);

                                jb.Add(key, (JToken)o);
                            }
                        }
                    }
                }

                JArray ja = new JArray();
                ja.Add(jb);


                output = ja;
                if (UseXMlNames)
                {
                    Dictionary <string, object> jsb = new Dictionary <string, object>();
                    jsb.Add(value.Xml.Name, ja);
                    output = jsb;
                }
                break;

            case JsonObjectType.String:
                output = new JValue("sample");
                break;

            case JsonObjectType.Number:
                output = new JValue(1);
                break;

            case JsonObjectType.Integer:
                output = new JValue(1);
                break;

            case JsonObjectType.Boolean:
                output = new JValue(false);
                break;

            case JsonObjectType.Null:
                output = JValue.CreateNull();
                break;

            default:
                output = new JValue("");;
                break;
            }

            foreach (object obj in PrivateStack)
            {
                ReferenceStack.Remove(obj);
            }
            CachedValues.Add(value, output);
            return(output);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 現在の状態で、現在のコードの実行を再開します。
        /// </summary>
        /// <returns></returns>
        public bool Resume()
        {
            KecaknoahObject         v1, v2;
            KecaknoahReference      rfr;
            Stack <KecaknoahObject> args;

            while (ProgramCounter < Codes.Count)
            {
                var c = Codes[ProgramCounter];
                switch (c.Type)
                {
                //基本--------------------------------------------------------------------
                case KecaknoahILCodeType.Nop:
                    break;

                case KecaknoahILCodeType.Label:
                    break;

                case KecaknoahILCodeType.PushInteger:
                    ReferenceStack.Push(KecaknoahReference.Right(c.IntegerValue));
                    break;

                case KecaknoahILCodeType.PushString:
                    ReferenceStack.Push(KecaknoahReference.Right(c.StringValue));
                    break;

                case KecaknoahILCodeType.PushDouble:
                    ReferenceStack.Push(KecaknoahReference.Right(c.FloatValue));
                    break;

                case KecaknoahILCodeType.PushBoolean:
                    ReferenceStack.Push(KecaknoahReference.Right(c.BooleanValue));
                    break;

                case KecaknoahILCodeType.PushNil:
                    ReferenceStack.Push(KecaknoahNil.Reference);
                    break;

                case KecaknoahILCodeType.Pop:
                    ReferenceStack.Pop();
                    break;

                //二項演算子--------------------------------------------------------------
                case KecaknoahILCodeType.Plus:
                case KecaknoahILCodeType.Minus:
                case KecaknoahILCodeType.Multiply:
                case KecaknoahILCodeType.Divide:
                case KecaknoahILCodeType.Modular:
                case KecaknoahILCodeType.And:
                case KecaknoahILCodeType.Or:
                case KecaknoahILCodeType.Xor:
                case KecaknoahILCodeType.AndAlso:
                case KecaknoahILCodeType.OrElse:
                case KecaknoahILCodeType.LeftBitShift:
                case KecaknoahILCodeType.RightBitShift:
                case KecaknoahILCodeType.Equal:
                case KecaknoahILCodeType.NotEqual:
                case KecaknoahILCodeType.Greater:
                case KecaknoahILCodeType.Lesser:
                case KecaknoahILCodeType.GreaterEqual:
                case KecaknoahILCodeType.LesserEqual:
                    v2 = ReferenceStack.Pop().RawObject;
                    v1 = ReferenceStack.Pop().RawObject;
                    ReferenceStack.Push(KecaknoahReference.Right(v1.ExpressionOperation(c.Type, v2)));
                    break;

                case KecaknoahILCodeType.Not:
                case KecaknoahILCodeType.Negative:
                    v1 = ReferenceStack.Pop().RawObject;
                    ReferenceStack.Push(KecaknoahReference.Right(v1.ExpressionOperation(c.Type, null)));
                    break;

                //代入など--------------------------------------------------------------
                case KecaknoahILCodeType.Assign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    rfr.RawObject = v1;
                    ReferenceStack.Push(KecaknoahReference.Right(v1));
                    break;

                case KecaknoahILCodeType.PlusAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Plus, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.MinusAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Minus, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.MultiplyAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Multiply, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.DivideAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Divide, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.AndAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.And, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.OrAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Or, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.XorAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Xor, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.ModularAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.Modular, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.LeftBitShiftAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.LeftBitShift, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.RightBitShiftAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.RightBitShift, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                case KecaknoahILCodeType.NilAssign:
                    v1            = ReferenceStack.Pop().RawObject;
                    rfr           = ReferenceStack.Pop();
                    v2            = rfr.RawObject.ExpressionOperation(KecaknoahILCodeType.NilAssign, v1);
                    rfr.RawObject = v2;
                    ReferenceStack.Push(KecaknoahReference.Right(v2));
                    break;

                //特殊----------------------------------------------------------------------------
                case KecaknoahILCodeType.StartCoroutine:
                    args = new Stack <KecaknoahObject>();
                    for (int i = 0; i < c.IntegerValue; i++)
                    {
                        args.Push(ReferenceStack.Pop().RawObject.AsByValValue());
                    }
                    var ct  = ReferenceStack.Peek().RawObject as KecaknoahScriptFunction;
                    var ict = ReferenceStack.Peek().RawObject as KecaknoahInteropFunction;
                    ReferenceStack.Pop();
                    if (ct == null && ict == null)
                    {
                        throw new InvalidOperationException("スクリプト上のメソッド以外はコルーチン化出来ません");
                    }
                    if (!ct.Equals(null))
                    {
                        cors[c.StringValue] = new KecaknoahScriptCoroutineFrame(RunningContext, ct, args.ToArray());
                    }
                    else
                    {
                        cors[c.StringValue] = new KecaknoahInteropCoroutineFrame(RunningContext, ict, args.ToArray());
                    }
                    break;

                case KecaknoahILCodeType.ResumeCoroutine:
                    var cobj = cors[c.StringValue];
                    if (cobj == null)
                    {
                        if (c.BooleanValue)
                        {
                            ReferenceStack.Pop();
                        }
                        ReferenceStack.Push(KecaknoahNil.Reference);
                        break;
                    }
                    var cr = cobj.Resume();
                    if (c.BooleanValue)
                    {
                        //2引数
                        var vas = ReferenceStack.Pop();
                        vas.RawObject = cr.ReturningObject;
                        ReferenceStack.Push(KecaknoahReference.Right(cr.CanResume.AsKecaknoahBoolean()));
                    }
                    else
                    {
                        //1引数
                        ReferenceStack.Push(KecaknoahReference.Right(cr.ReturningObject));
                    }
                    if (!cr.CanResume)
                    {
                        cors[c.StringValue] = null;
                    }
                    break;

                case KecaknoahILCodeType.MakeArray:
                    var ars = new Stack <KecaknoahObject>();
                    for (int i = 0; i < c.IntegerValue; i++)
                    {
                        ars.Push(ReferenceStack.Pop().RawObject);
                    }
                    var arr = new KecaknoahArray(new[] { (int)c.IntegerValue });
                    for (int i = 0; i < c.IntegerValue; i++)
                    {
                        arr.array[i] = new KecaknoahReference {
                            IsLeftValue = true, RawObject = ars.Pop()
                        }
                    }
                    ;
                    ReferenceStack.Push(KecaknoahReference.Right(arr));
                    break;

                case KecaknoahILCodeType.Jump:
                    ProgramCounter = (int)c.IntegerValue;
                    continue;

                case KecaknoahILCodeType.TrueJump:
                    v1 = ReferenceStack.Pop().RawObject;
                    if (v1.ToBoolean())
                    {
                        ProgramCounter = (int)c.IntegerValue;
                        continue;
                    }
                    break;

                case KecaknoahILCodeType.FalseJump:
                    v1 = ReferenceStack.Pop().RawObject;
                    if (!v1.ToBoolean())
                    {
                        ProgramCounter = (int)c.IntegerValue;
                        continue;
                    }
                    break;

                case KecaknoahILCodeType.Return:
                    ReturningObject = ReferenceStack.Pop().RawObject;
                    return(false);

                case KecaknoahILCodeType.Yield:
                    ReturningObject = ReferenceStack.Pop().RawObject;
                    ProgramCounter++;
                    return(true);

                case KecaknoahILCodeType.Call:
                    args = new Stack <KecaknoahObject>();
                    for (int i = 0; i < c.IntegerValue; i++)
                    {
                        args.Push(ReferenceStack.Pop().RawObject);
                    }
                    v1 = ReferenceStack.Pop().RawObject.AsByValValue();
                    ReferenceStack.Push(KecaknoahReference.Right(v1.Call(RunningContext, args.ToArray()).ReturningObject));
                    break;

                case KecaknoahILCodeType.IndexerCall:
                    args = new Stack <KecaknoahObject>();
                    for (int i = 0; i < c.IntegerValue; i++)
                    {
                        args.Push(ReferenceStack.Pop().RawObject);
                    }
                    v1 = ReferenceStack.Pop().RawObject.AsByValValue();
                    ReferenceStack.Push(v1.GetIndexerReference(args.ToArray()));
                    break;

                case KecaknoahILCodeType.PushArgument:
                    ReferenceStack.Push(KecaknoahReference.Right(Arguments[(int)c.IntegerValue]));
                    break;

                case KecaknoahILCodeType.LoadObject:
                    string refname = c.StringValue;
                    ReferenceStack.Push(GetReference(refname));
                    break;

                case KecaknoahILCodeType.LoadMember:
                    var or = ReferenceStack.Pop();
                    ReferenceStack.Push(or.GetMemberReference(c.StringValue));
                    break;

                case KecaknoahILCodeType.LoadVarg:
                    args = new Stack <KecaknoahObject>();
                    for (int i = 0; i < c.IntegerValue; i++)
                    {
                        args.Push(ReferenceStack.Pop().RawObject);
                    }
                    ReferenceStack.Push(KecaknoahReference.Right(VariableArguments[(int)args.Pop().ToInt64()]));
                    break;

                case KecaknoahILCodeType.AsValue:
                    ReferenceStack.Push(KecaknoahReference.Right(ReferenceStack.Pop().RawObject.AsByValValue()));
                    break;
                }
                ProgramCounter++;
            }
            if (ReferenceStack.Count == 0)
            {
                ReferenceStack.Push(KecaknoahNil.Reference);
            }
            ReturningObject = ReferenceStack.Pop().RawObject;
            return(false);
        }
Exemplo n.º 4
0
 public void Init()
 {
     this.stack = new ReferenceStack <double>();
 }
Exemplo n.º 5
0
 public void Init()
 {
     this.stack      = new ReferenceStack <double>();
     this.calculator = new Calculator(stack);
 }
Exemplo n.º 6
0
        public static string JsonSchemaFaker(JsonSchema4 schema, List <object> ReferenceStack, bool UseXMlNames = false)
        {
            if (ReferenceStack == null)
            {
                ReferenceStack = new List <object>();
            }
            ReferenceStack.Add(schema);
            if (CachedValues.ContainsKey(schema))
            {
                object returnValue;
                CachedValues.TryGetValue(schema, out returnValue);
                return((string)returnValue);
            }

            if (schema.HasReference)
            {
                if (ReferenceStack.Contains(schema.Reference))
                {
                    return(string.Empty);
                }
                else
                {
                    return(JsonSchemaFaker(schema.Reference, ReferenceStack, UseXMlNames));
                }
            }

            Dictionary <string, object> JsonBody = new Dictionary <string, object>();

            if (schema.AllOf.Count == 0)
            {
                foreach (KeyValuePair <string, JsonProperty> jkp in schema.ActualProperties)
                {
                    //code
                    string key = jkp.Key;
                    if (UseXMlNames && jkp.Value.Xml != null)
                    {
                        key = jkp.Value.Xml.Name;
                    }
                    if (jkp.Value.HasReference && !ReferenceStack.Contains(jkp.Value.Reference))
                    {
                        if (jkp.Value.Reference.HasReference == false && jkp.Value.Reference.Properties.Count == 0)
                        {
                            object o1 = GenerateJsonObjectFromJsonSchema4(jkp.Value, ReferenceStack, UseXMlNames);
                            JsonBody.Add(key, o1);
                        }
                        else
                        {
                            if (!jkp.Value.Reference.Equals(jkp.Value))
                            {
                                string property = JsonSchemaFaker(jkp.Value.Reference, ReferenceStack, UseXMlNames);
                                object o        = JsonConvert.DeserializeObject(property);
                                JsonBody.Add(key, o);
                            }
                        }
                    }
                    else
                    {
                        object o = GenerateJsonObjectFromJsonSchema4(jkp.Value, ReferenceStack, UseXMlNames);
                        JsonBody.Add(key, o);
                    }
                }
            }
            else
            {
                System.Text.StringBuilder property = new System.Text.StringBuilder();
                foreach (var schemaObject in schema.AllOf)
                {
                    if (string.IsNullOrEmpty(property.ToString()))
                    {
                        property.Append(JsonSchemaFaker(schemaObject, ReferenceStack, UseXMlNames));
                    }
                    else
                    {
                        property.Remove(property.Length - 1, 1);
                        var result = JsonSchemaFaker(schemaObject, ReferenceStack, UseXMlNames);
                        property.Append(string.Format(",{0}", result.Substring(1, result.Length - 1)));
                    }
                }
                return(property.ToString());
            }

            ReferenceStack.Remove(schema);

            string output = JsonConvert.SerializeObject(JsonBody);

            CachedValues.Add(schema, output);
            return(output);
        }