示例#1
0
        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
        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
        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
        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
        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
        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
        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"));
        }
        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;"));
        }
        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', '');"));
        }
        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']();"));
        }