Пример #1
0
        private void InitializeCompiler()
        {
            _compiler = new MetaCodeCompiler();
            CompilerService = CompilerService.Instance;
            MacroInterpreter = new MacroInterpreter(CompilerService);
            CodeInterpreter = new CodeInterpreter(CompilerService);
            CodeGenerator = new CodeGenerator();
            SemanticParser = new SemanticParser(CompilerService);

            InitializeFunctions();
            WindowTitle = "MetaCode IDE";
        }
Пример #2
0
            public CachedMacro(NvGpuFifo PFifo, INvGpuEngine Engine, int Position)
            {
                this.Position = Position;

                Interpreter = new MacroInterpreter(PFifo, Engine);
            }
        public void MacroDeclarationTest()
        {
            // GIVEN
            var source = @"
                macro convertToWhile(tree : { * > foreach }) do
                   
                end;

                implicit macro inline(tree: { * > while[body] }) do
                    foreach (var t : any in tree) do
                       writeline(find(t, '{ if[condition] }'));
                    end;
                end;

                foreach (var i : Number in [1,2,3,4]) do
                    writeline(i);
                end;

                var i : number = 0;
                var n : number = 100;
                var sum : number = 0;

                while (i < n) do
                  sum := sum + 2 * i;
                  i := i + 1;
                end;

                while (false) do
                  var i : number = 1;
                end;

                if (24 > 42) 
                  skip;
                end;

                if (24 > 42) 
                  skip;
                end;

                if (24 > 42) 
                  skip;
                end;  
            ";

            var compilerService = new CompilerService();
            var analyzer = new MacroInterpreter(compilerService);

            // WHEN
            var node = ParseWithAbstractTreeVisitor(Compiler, source);
            analyzer.VisitChild(node as CompilationUnit);

            // THEN
        }
        public void SimpleMacroTest()
        {
            // GIVEN
            var source = @"
                implicit macro debugMacro(tree: { * > foreach[body][loop-variable =  str] > * }) do
                    writeline('Actual parameters of helloMacro');
                    writeline('-------------------');
                    var i : number = 1;
                    foreach (var str : string in convertToString(tree)) do
                        writeline(i + '. AST');
                        write(str);
                        writeline('-------------------');
                        i = i + 1;
                    end;
                end;                 

                function max(a: number, b: number) : number do
                    while (a < b) do
                        skip;
                    end;
                end;

                a.b.c;
                toString('Hello World', 10);
                (10 + 5) * b;
                foreach (var str : string in ['Hello', 'World']) do
                    if (a > 10) 
                      if (true) writeline(str); end;
                    else
                      skip;
                    end;
                    skip;
                end;

                foreach (var i : number in [1,2,3,4]) do
                    skip;
                end;

                object Person
                    name: string;
                    age: number;
                end;

                attribute @not-null(id: string, id2: number);

                var b : number = 100;
            ";

            var macroInterpreter = new MacroInterpreter(new CompilerService());
            var codeGenerator = new CodeGenerator();

            // WHEN
            var node = ParseWithAbstractTreeVisitor(Compiler, source);
            macroInterpreter.VisitChild(node as CompilationUnit);
            var result = codeGenerator.VisitChild(macroInterpreter.Root);

            // THEN
            Debug.WriteLine(result.ToString());
        }