Ejemplo n.º 1
0
 public void IterateFunction()
 {
     EmitFunction ef = (OneCallContext ctx) => 
     {
         return Result.Ok(ctx.Obj.ToString());
     };
     var actual = CallIterate(Enumerable.Range(1, 3), ",", ef);
     Assert.True(actual.IsSuccess);
     Assert.Equal("1,2,3", actual.Value);
 }
Ejemplo n.º 2
0
 public void EachFunction()
 {
     EmitFunction ef = (OneCallContext ctx) =>
     {
         return Result.Ok(ctx.Obj.ToString());
     };
     var obj = new { A = Enumerable.Range(1, 3) };
     var actual = CallEach(obj, "A", ",", ef);
     Assert.True(actual.IsSuccess);
     Assert.Equal("1,2,3", actual.Value);
 }
Ejemplo n.º 3
0
        public void IterateFunction()
        {
            EmitFunction ef = (SdmapCompilerContext ctx, object o) =>
            {
                return(Result.Ok(o.ToString()));
            };
            var actual = CallIterate(Enumerable.Range(1, 3), ",", ef);

            Assert.True(actual.IsSuccess);
            Assert.Equal("1,2,3", actual.Value);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="fxEvent"></param>
 /// <param name="spriteIndex"></param>
 /// <param name="delay"></param>
 /// <param name="period"></param>
 /// <param name="sleep"></param>
 /// <param name="count"></param>
 /// <param name="emit"></param>
 public ParticleStage( SfxInstance instance, int spriteIndex, float delay, float period, float sleep, int count, bool looped, EmitFunction emit )
     : base(instance)
 {
     this.looped			=	false;
     this.spriteIndex	=	spriteIndex	;
     this.delay			=	delay		;
     this.period			=	period		;
     this.sleep			=	sleep		;
     this.count			=	count		;
     this.emit			=	emit		;
     this.looped			=	looped;
 }
Ejemplo n.º 5
0
        public Result EnsureCompiled(SdmapCompilerContext context)
        {
            if (Emiter != null)
            {
                return(Result.Ok());
            }

            return(CompileInternal(context)
                   .OnSuccess(v =>
            {
                Emiter = v;
                _parseTree = null;
            }));
        }
Ejemplo n.º 6
0
        public Result Process(CoreSqlContext parseRule, string functionName)
        {
            var method = new DynamicMethod(functionName,
                                           typeof(Result <string>), new[] { typeof(SdmapCompilerContext), typeof(object) });

            _il = method.GetILGenerator();

            void returnBlock()
            {
                _il.Emit(OpCodes.Ldloc_0);                                        // sb
                var okMethod = typeof(Result)
                               .GetTypeInfo()
                               .GetMethods()
                               .Single(x => x.IsGenericMethod && x.Name == "Ok")
                               .MakeGenericMethod(typeof(string));

                _il.Emit(OpCodes.Call, typeof(StringBuilder)
                         .GetTypeInfo()
                         .GetMethod(nameof(StringBuilder.ToString), Type.EmptyTypes)); // str
                _il.Emit(OpCodes.Call, okMethod);                                      // result<str>

                _il.Emit(OpCodes.Ret);                                                 // [empty-returned]
                Function = (EmitFunction)method.CreateDelegate(typeof(EmitFunction));
            };

            if (parseRule == null)
            {
                returnBlock();
                return(Result.Ok());
            }

            _il.DeclareLocal(typeof(StringBuilder));
            _il.Emit(OpCodes.Newobj, typeof(StringBuilder)
                     .GetTypeInfo()
                     .GetConstructor(Type.EmptyTypes));                               // sb
            _il.Emit(OpCodes.Stloc_0);                                                // [empty]

            return(Visit(parseRule)
                   .OnSuccess(() =>                                                   // [must be empty]
            {
                returnBlock();
            }));
        }
Ejemplo n.º 7
0
 private Result<string> CallEach(object self, 
     string prop, string joiner, EmitFunction ef)
 {
     return DynamicRuntimeMacros.Each(OneCallContext.CreateEmpty(),
         "", self, new object[] { prop, joiner, ef });
 }
Ejemplo n.º 8
0
 private Result<string> CallIterate(object self, string joiner, EmitFunction ef)
 {
     return DynamicRuntimeMacros.Iterate(OneCallContext.CreateByObj(self), 
         "", self, new object[] { joiner, ef });
 }
Ejemplo n.º 9
0
 public static Result <string> ExecuteEmiter(EmitFunction ef, OneCallContext ctx)
 => ef(ctx.Dig(ctx.Obj));
Ejemplo n.º 10
0
Archivo: SqlDef.cs Proyecto: sdcb/sdmap
 public EmiterSegmentDef(string id, EmitFunction emiter) : base(id)
 {
     Emiter = emiter;
 }
Ejemplo n.º 11
0
 public static Result <string> ExecuteEmiter(EmitFunction ef, SdmapCompilerContext ctx, object obj)
 {
     return(ef(ctx, obj));
 }
Ejemplo n.º 12
0
 private Result <string> CallEach(object self,
                                  string prop, string joiner, EmitFunction ef)
 {
     return(CommonMacros.Each(SdmapCompilerContext.CreateEmpty(),
                              "", self, new object[] { prop, joiner, ef }));
 }
Ejemplo n.º 13
0
        public Result Process(CoreSqlContext parseRule, string functionName)
        {
            var method = new DynamicMethod(functionName,
                                           typeof(Result <string>), new[] { typeof(OneCallContext) });

            _il = method.GetILGenerator();

            void returnBlock()
            {
                bool isNamed = NameUtil.IsNamed(functionName);
                // root:
                //     combine deps
                // child-named:
                //     not combine
                // child-unnamed:
                //     combine strings

                Label defaultExit          = _il.DefineLabel();
                Label childNamedNotCombine = _il.DefineLabel();

                _il.Emit(OpCodes.Ldarg_0);                         // ctx
                _il.Emit(OpCodes.Call, OneCallContext.GetIsChild); // isChild
                _il.Emit(isNamed ?
                         OpCodes.Ldc_I4_1 : OpCodes.Ldc_I4_0);     // isNamed
                _il.Emit(OpCodes.And);                             // if (isChild && isNamed)
                _il.Emit(OpCodes.Brtrue_S, childNamedNotCombine);  //     goto notCombine

                _il.MarkLabel(defaultExit);
                {
                    string methodName = isNamed ?
                                        nameof(CoreSqlVisitorHelper.CombineDeps) :
                                        nameof(CoreSqlVisitorHelper.CombineStrings);
                    MethodInfo combineMethod = typeof(CoreSqlVisitorHelper).GetMethod(methodName);
                    _il.Emit(OpCodes.Ldarg_0);                                   // ctx
                    _il.Emit(OpCodes.Call, combineMethod);                       // result<str>
                    _il.Emit(OpCodes.Ret);                                       //
                }
                _il.MarkLabel(childNamedNotCombine);
                {
                    MethodInfo ok = typeof(Result).GetMethods()
                                    .Single(x => x.IsGenericMethod && x.Name == nameof(Result.Ok))
                                    .MakeGenericMethod(typeof(string));
                    _il.Emit(OpCodes.Ldstr, "");                                  // [empty]
                    _il.Emit(OpCodes.Call, ok);                                   // result<empty>
                    _il.Emit(OpCodes.Ret);                                        //
                }

                Function = (EmitFunction)method.CreateDelegate(typeof(EmitFunction));
            };

            if (parseRule == null)
            {
                returnBlock();
                return(Result.Ok());
            }

            _il.DeclareLocal(typeof(List <object>));
            _il.Emit(OpCodes.Ldarg_0);                                                // ctx
            _il.Emit(OpCodes.Call, OneCallContext.GetTempStore);                      // sb
            _il.Emit(OpCodes.Stloc_0);                                                // [empty]

            return(Visit(parseRule)
                   .OnSuccess(() =>                                                   // [must be empty]
            {
                returnBlock();
            }));
        }
Ejemplo n.º 14
0
 private extern void SetEmitFunction(EmitFunction value);
Ejemplo n.º 15
0
 private extern void GetEmitFunction(ref EmitFunction value);
Ejemplo n.º 16
0
 /*-----------------------------------------------------------------------------------------
  *
  *	Stage creation functions :
  *
 -----------------------------------------------------------------------------------------*/
 /// <summary>
 /// 
 /// </summary>
 /// <param name="spriteName"></param>
 /// <param name="delay"></param>
 /// <param name="period"></param>
 /// <param name="sleep"></param>
 /// <param name="count"></param>
 /// <param name="emit"></param>
 protected void AddParticleStage( string spriteName, float delay, float period, float sleep, int count, bool looped, EmitFunction emit )
 {
     if (count==0) {
         return;
     }
     var spriteIndex		=	sfxSystem.GetSpriteIndex( spriteName );
     var stage			=	new ParticleStage( this, spriteIndex, delay, period, sleep, count, looped, emit );
     stages.Add( stage );
 }