コード例 #1
0
ファイル: CompilerTests.cs プロジェクト: Szune/eilang
            public void ShouldBeAppliedIfFunctionDoesNotEndWithReturn()
            {
                const string name    = "test";
                var          funcAst = new AstExtensionFunction(name, name, new List <Parameter>(), new Position(0, 0));

                funcAst.Expressions.Add(
                    new AstFunctionCall("println", new List <AstExpression>
                {
                    new AstBinaryMathOperation(BinaryMath.Plus,
                                               new AstIntegerConstant(5, null),
                                               new AstIntegerConstant(5, null),
                                               null)
                }, null));
                funcAst.Expressions.Add(
                    new AstFunctionCall("println", new List <AstExpression>
                {
                    new AstStringConstant("hello world", null)
                }, null)
                    );
                var env = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory());

                Compiler.Compile(env,
                                 new AstRoot(new Position(0, 0))
                {
                    Functions = { funcAst }
                });
                Assert.Equal(typeof(Return), env.ExtensionFunctions[$"{GetGlobalName(name)}->{name}"].Code.Last().Op.GetType());
            }
コード例 #2
0
ファイル: CompilerTests.cs プロジェクト: Szune/eilang
            public void ShouldBeAppliedIfFunctionIsEmpty()
            {
                const string name    = "test";
                var          funcAst = new AstExtensionFunction(name, name, new List <Parameter>(), new Position(0, 0));
                var          env     = new ScriptEnvironment(new OperationCodeFactory(), new ValueFactory());

                Compiler.Compile(env,
                                 new AstRoot(new Position(0, 0))
                {
                    Functions = { funcAst }
                });
                Assert.Equal(typeof(Return), env.ExtensionFunctions[$"{GetGlobalName(name)}->{name}"].Code.Last().Op.GetType());
            }