Process() public method

public Process ( CodeModel model ) : void
model CodeModel
return void
コード例 #1
0
ファイル: NodeCompilerTests.cs プロジェクト: ajlopez/AjTalk
        public void CompilePharoCorePointForNodeJs()
        {
            ChunkReader chunkCoreReader = new ChunkReader(@"PharoCoreKernelObjects.st");
            CodeReader coreReader = new CodeReader(chunkCoreReader);
            ChunkReader chunkReader = new ChunkReader(@"PharoCorePoint.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            coreReader.Process(model);
            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            Assert.IsTrue(ContainsLine(output, "var base = require('./js/ajtalk-base.js');"));
            Assert.IsTrue(ContainsLine(output, "var send = base.send;"));
            Assert.IsTrue(ContainsLine(output, "var sendSuper = base.sendSuper;"));
            Assert.IsTrue(ContainsLine(output, "var primitives = require('./js/ajtalk-primitives.js');"));

            Assert.IsTrue(ContainsLine(output, "function Point()"));
            Assert.IsTrue(ContainsLine(output, "PointClass.__super = ObjectClass;"));
            Assert.IsTrue(ContainsLine(output, "Point.__super = Object;"));
            Assert.IsTrue(ContainsLine(output, "PointClass.prototype.__proto__ = ObjectClass.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Point.prototype.__proto__ = Object.prototype;"));
            Assert.IsTrue(ContainsLine(output, "exports.Point = Point;"));
            Assert.IsTrue(ContainsLine(output, "Point.prototype.$x = null;"));
            Assert.IsTrue(ContainsLine(output, "Point.prototype.$y = null;"));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ajlopez/AjTalk
        public static void Main(string[] args)
        {
            StreamWriter swriter = new StreamWriter(GetOutputFileName(args));
            SourceWriter writer = new SourceWriter(swriter);
            CodeModel model = new CodeModel();
            Compilers.Javascript.Compiler compiler = null;

            string target = GetTarget(args);

            if (target == "node")
                compiler = new NodeCompiler(writer);
            else if (target == "browser")
                compiler = new BrowserCompiler(writer);
            else if (target == "vm")
                compiler = new VirtualMachineCompiler(writer);
            else
                throw new ArgumentException("Invalid target");

            foreach (string filename in GetFileNames(args))
            {
                ChunkReader chunkReader = new ChunkReader(filename);
                CodeReader reader = new CodeReader(chunkReader);

                reader.Process(model);
            }

            compiler.Visit(model);

            swriter.Close();
        }
コード例 #3
0
ファイル: NodeCompilerTests.cs プロジェクト: ajlopez/AjTalk
        public void CompilePharoCoreKernelObjectsForNodeJs()
        {
            ChunkReader chunkReader = new ChunkReader(@"PharoCoreKernelObjects.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "function Object()"));
            Assert.IsTrue(ContainsLine(output, "ObjectClass.__super = ProtoObjectClass;"));
            Assert.IsTrue(ContainsLine(output, "Object.__super = ProtoObject;"));
            Assert.IsTrue(ContainsLine(output, "ObjectClass.prototype.__proto__ = ProtoObjectClass.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Object.prototype.__proto__ = ProtoObject.prototype;"));
            Assert.IsTrue(ContainsLine(output, "BooleanClass.prototype.__proto__ = ObjectClass.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Boolean.prototype.__proto__ = Object.prototype;"));
            Assert.IsTrue(ContainsLine(output, "function Boolean()"));
            Assert.IsTrue(ContainsLine(output, "exports.Object = Object;"));
            Assert.IsTrue(ContainsLine(output, "exports.Boolean = Boolean;"));
            Assert.IsTrue(ContainsLine(output, "exports.ProtoObject = ProtoObject;"));
        }
コード例 #4
0
        public void CompilePharoCorePointForBrowser()
        {
            ChunkReader chunkCoreReader = new ChunkReader(@"PharoCoreKernelObjects.st");
            CodeReader coreReader = new CodeReader(chunkCoreReader);
            ChunkReader chunkReader = new ChunkReader(@"PharoCorePoint.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            coreReader.Process(model);
            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            Assert.IsTrue(ContainsLine(output, "AjTalk = function() {"));
            Assert.IsTrue(ContainsLine(output, "var send = base.send;"));
            Assert.IsTrue(ContainsLine(output, "var sendSuper = base.sendSuper;"));

            Assert.IsTrue(ContainsLine(output, "function Point()"));
            Assert.IsTrue(ContainsLine(output, "PointClass.__super = ObjectClass;"));
            Assert.IsTrue(ContainsLine(output, "Point.__super = Object;"));
            Assert.IsTrue(ContainsLine(output, "PointClass.prototype.__proto__ = ObjectClass.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Point.prototype.__proto__ = Object.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Point.prototype.$x = null;"));
            Assert.IsTrue(ContainsLine(output, "Point.prototype.$y = null;"));

            Assert.IsTrue(ContainsLine(output, "Point : Point"));
        }
コード例 #5
0
ファイル: CodeReaderTests.cs プロジェクト: ajlopez/AjTalk
        public void ProcessFileOut01()
        {
            ChunkReader chunkReader = new ChunkReader(@"FileOut01.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            Assert.IsNotNull(model.GetClass("Object"));
            Assert.AreEqual(3, model.Elements.Count());

            Assert.IsInstanceOfType(model.Elements.First(), typeof(ClassModel));
            Assert.IsInstanceOfType(model.Elements.Skip(1).First(), typeof(MethodModel));
            Assert.IsInstanceOfType(model.Elements.Skip(2).First(), typeof(MethodModel));
        }
コード例 #6
0
ファイル: NodeCompilerTests.cs プロジェクト: ajlopez/AjTalk
        public void CompileSqueakKernelObjectsForNodeJs()
        {
            ChunkReader chunkReader = new ChunkReader(@"SqueakKernelObjects.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "function Object()"));
            Assert.IsTrue(ContainsLine(output, "function Boolean()"));
            Assert.IsTrue(ContainsLine(output, "exports.Object = Object;"));
            Assert.IsTrue(ContainsLine(output, "exports.Boolean = Boolean;"));

            // Class variables in Object
            Assert.IsTrue(ContainsLine(output, "ObjectClass.$DependentsFields = null;"));
        }
コード例 #7
0
ファイル: NodeCompilerTests.cs プロジェクト: ajlopez/AjTalk
        public void CompileSqueakObjectForNodeJs()
        {
            ChunkReader chunkReader = new ChunkReader(@"SqueakObject.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "var base = require('./js/ajtalk-base.js');"));
            Assert.IsTrue(ContainsLine(output, "var send = base.send;"));
            Assert.IsTrue(ContainsLine(output, "var sendSuper = base.sendSuper;"));
            Assert.IsTrue(ContainsLine(output, "var primitives = require('./js/ajtalk-primitives.js');"));

            Assert.IsTrue(ContainsLine(output, "function Object()"));

            Assert.IsTrue(ContainsLine(output, "exports.Object = Object;"));
        }
コード例 #8
0
        internal static void CompileFile(string filename)
        {
            ChunkReader chunkReader = new ChunkReader(filename);
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            foreach (var element in model.Elements)
            {
                Block block = new Block();
                BytecodeCompiler compiler = new BytecodeCompiler(block);
                element.Visit(compiler);
                if (element is MethodModel && ((MethodModel)element).Body == null)
                    continue;
                Assert.IsNotNull(block.ByteCodes);
            }
        }
コード例 #9
0
        public void CompilePharoCoreRectangle()
        {
            ChunkReader chunkCoreReader = new ChunkReader(@"PharoCoreKernelObjects.st");
            CodeReader coreReader = new CodeReader(chunkCoreReader);
            ChunkReader chunkReader = new ChunkReader(@"PharoCoreRectangle.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            coreReader.Process(model);
            reader.Process(model);

            foreach (var element in model.Elements)
            {
                Block block = new Block();
                BytecodeCompiler compiler = new BytecodeCompiler(block);
                element.Visit(compiler);

                if (element is MethodModel && ((MethodModel)element).Body == null)
                    continue;

                Assert.IsNotNull(block.ByteCodes);
            }
        }
コード例 #10
0
ファイル: CompilerTests.cs プロジェクト: ajlopez/AjTalk
        public void CompileFileOut01()
        {
            ChunkReader chunkReader = new ChunkReader(@"FileOut01.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "function Object()"));
        }
コード例 #11
0
ファイル: CompilerTests.cs プロジェクト: ajlopez/AjTalk
        public void CompilePharoCoreRectangle()
        {
            ChunkReader chunkCoreReader = new ChunkReader(@"PharoCoreKernelObjects.st");
            CodeReader coreReader = new CodeReader(chunkCoreReader);
            ChunkReader chunkReader = new ChunkReader(@"PharoCoreRectangle.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            coreReader.Process(model);
            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "function Rectangle()"));
            Assert.IsTrue(ContainsLine(output, "RectangleClass.__super = ObjectClass;"));
            Assert.IsTrue(ContainsLine(output, "Rectangle.__super = Object;"));
            Assert.IsTrue(ContainsLine(output, "RectangleClass.prototype.__proto__ = ObjectClass.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Rectangle.prototype.__proto__ = Object.prototype;"));
            Assert.IsTrue(ContainsLine(output, "Rectangle.prototype.$origin = null;"));
            Assert.IsTrue(ContainsLine(output, "Rectangle.prototype.$corner = null;"));
        }
コード例 #12
0
        public void CompileSqueakObjectForBrowser()
        {
            ChunkReader chunkReader = new ChunkReader(@"SqueakObject.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "AjTalk = function() {"));
            Assert.IsTrue(ContainsLine(output, "var send = base.send;"));
            Assert.IsTrue(ContainsLine(output, "var sendSuper = base.sendSuper;"));

            Assert.IsTrue(ContainsLine(output, "function Object()"));

            Assert.IsTrue(ContainsLine(output, "Object : Object"));
        }
コード例 #13
0
        public void CompileSqueakObject()
        {
            ChunkReader chunkReader = new ChunkReader(@"SqueakObject.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "var ajtalk;"));
            Assert.IsTrue(ContainsLine(output, "var Smalltalk;"));
        }
コード例 #14
0
        public void CompileSqueakKernelObjects()
        {
            ChunkReader chunkReader = new ChunkReader(@"SqueakKernelObjects.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "Smalltalk.Object.subclass_instanceVariableNames_classVariableNames_('MessageSend', 'receiver selector arguments', '');"));
        }
コード例 #15
0
        public void CompilePharoCorePoint()
        {
            ChunkReader chunkReader = new ChunkReader(@"PharoCorePoint.st");
            CodeReader reader = new CodeReader(chunkReader);
            CodeModel model = new CodeModel();

            reader.Process(model);

            this.compiler.Visit(model);
            this.writer.Close();
            string output = this.writer.ToString();

            // TODO more tests
            Assert.IsTrue(ContainsLine(output, "Smalltalk.Object.subclass_instanceVariableNames_classVariableNames_('Point', 'x y', '');"));
            Assert.IsTrue(ContainsLine(output, "factor = 3['reciprocal']();"));
        }