public IErrorReporter ErrorSpawningMutables() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; var point_type = root_ns.AddBuilder(TypeBuilder.Create("Point") .SetModifier(EntityModifier.Mutable) .With(VariableDeclaration.CreateStatement("x", NameFactory.Int64NameReference(), null, EntityModifier.Public | env.Options.ReassignableModifier())) .With(FunctionBuilder.Create("empty", ExpressionReadMode.CannotBeRead, NameFactory.UnitNameReference(), Block.CreateStatement()) .Parameters(FunctionParameter.Create("p", NameFactory.PointerNameReference(NameReference.Create("Point")), Variadic.None, null, isNameRequired: false, usageMode: ExpressionReadMode.CannotBeRead)))); FunctionArgument mutable_arg = FunctionArgument.Create(NameReference.Create("r")); NameReference mutable_method = NameReference.Create("r", "empty"); var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("r", null, ExpressionFactory.HeapConstructor(NameReference.Create("Point"))), Spawn.Create(FunctionCall.Create(mutable_method, mutable_arg)), Return.Create(NameReference.Create("r", "x")) }))); resolver = NameResolver.Create(env); Assert.AreEqual(2, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.CannotSpawnWithMutableArgument, mutable_arg)); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.CannotSpawnOnMutableContext, mutable_method)); } return(resolver); }
public IInterpreter SingleMessage() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create( "sender", ExpressionReadMode.CannotBeRead, NameFactory.UnitNameReference(), Block.CreateStatement(new IExpression[] { ExpressionFactory.AssertTrue(FunctionCall.Create(NameReference.Create("ch", NameFactory.ChannelSend), FunctionArgument.Create(Int64Literal.Create("2")))), })) .Parameters(FunctionParameter.Create("ch", NameFactory.PointerNameReference(NameFactory.ChannelNameReference(NameFactory.Int64NameReference())), Variadic.None, null, isNameRequired: false))); root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("ch", null, ExpressionFactory.HeapConstructor(NameFactory.ChannelNameReference(NameFactory.Int64NameReference()))), Spawn.Create(FunctionCall.Create(NameReference.Create("sender"), FunctionArgument.Create(NameReference.Create("ch")))), VariableDeclaration.CreateStatement("r", null, FunctionCall.Create(NameReference.Create("ch", NameFactory.ChannelReceive))), ExpressionFactory.AssertOptionIsSome(NameReference.Create("r")), Return.Create(ExpressionFactory.GetOptionValue(NameReference.Create("r"))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
void CallFuncTest() { btn_text.text = "点击停止"; var action = Sequence.Create( CallFunc.Create(CallBackO, "延时0.5秒"), DelayTime.Create(0.5f), CallFunc.Create(CallBackO, "图片移动"), MoveTo.Create(1f, 200, 100).InitSubjectTransform(image.transform), MoveTo.Create(1f, 0, 0).InitSubjectTransform(image.transform), CallFunc.Create(CallBackO, "颜色渐变"), ColorTo.Create(0.5f, 1, 0, 0, 1f).InitSubjectComponent(image), ColorTo.Create(0.5f, 0, 1, 0, 1f).InitSubjectComponent(image), ColorTo.Create(0.5f, 0, 0, 1, 1f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "颜色reset"), ColorTo.Create(0.5f, 1, 1, 1, 1).InitSubjectComponent(image), CallFunc.Create(CallBackO, "渐隐"), FadeOut.Create(1f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "渐出"), FadeIn.Create(1f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "1秒闪烁5次"), Blink.Create(1f, 5), CallFunc.Create(CallBackO, "二阶贝塞尔曲线"), BezierTo.Create(2.0f, new Vector3(200, 100, 0), new Vector3(-100, 50, 0), new Vector3(100, 80, 0)).InitSubjectTransform(image.transform), CallFunc.Create(CallBackO, "移动回原点"), MoveTo.Create(1f, 0, 0).InitSubjectTransform(image.transform), CallFunc.Create(CallBackO, "边移动边放大"), Spawn.Create(MoveTo.Create(1.0f, 200, 100f), ScaleTo.Create(1.0f, 3.0f, 3.0f, 3.0f)), CallFunc.Create(CallBackO, "缩放位置回原位"), Spawn.Create(MoveTo.Create(1.0f, 0, 0), ScaleTo.Create(1.0f, 1f, 1f, 1f)), NumberBy.Create(2.0f, "数字跳跃,从100到200:{0:f2}", 100, 100).InitSubjectComponent(text), DelayTime.Create(0.5f), NumberTo.Create(2.0f, "数字跳跃,从200到0:{0:f2}", 200, 0).InitSubjectComponent(text), DelayTime.Create(0.5f), CallFunc.Create(CallBackO, "Image Filled"), FillAmountTo.Create(1.5f, 0f).InitSubjectComponent(image), FillAmountTo.Create(1.5f, 1.0f).InitSubjectComponent(image), CallFunc.Create(CallBackO, "reset"), CallFunc.Create(CallBackO, "旋转 放大2倍,复原。重复3次"), Repeat.Create(Spawn.Create( RotationBy.Create(1.0f, 0, 0, 360f), Sequence.Create( ScaleTo.Create(0.5f, 2.0f, 2.0f, 2.0f), ScaleTo.Create(0.5f, 1.0f, 1.0f, 1.0f))).InitSubjectTransform(image.transform), 3), ExtraAction.Create() ); float toX = 300f; var easeAction = Sequence.Create( CallFunc.Create(CallBackO, "变速运动演示,图一正常,图二是变速运动"), DelayTime.Create(1f), CallFunc.Create(CallBackO, "当前变速是EaseIn"), DelayTime.Create(0.5f), Spawn.Create( MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image.transform), EaseIn.Create(MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "复位"), Spawn.Create( MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image.transform), EaseIn.Create(MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "当前变速是EaseOut"), DelayTime.Create(0.5f), Spawn.Create( MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image.transform), EaseOut.Create(MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "复位"), Spawn.Create( MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image.transform), EaseOut.Create(MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "当前变速是EaseInOut"), DelayTime.Create(0.5f), Spawn.Create( MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image.transform), EaseInOut.Create(MoveBy.Create(1.0f, toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "复位"), Spawn.Create( MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image.transform), EaseInOut.Create(MoveBy.Create(1.0f, -toX, 0f, 0f).InitSubjectTransform(image2.transform), 3f)), CallFunc.Create(CallBackO, "变速运动未完待续"), DelayTime.Create(1f), ExtraAction.Create() ); CCActionManager.Instance.AddAction(Sequence.Create(action, easeAction, CallFunc.Create(CallBackEnd)), transform); }