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")); }
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;")); }
public override void Visit(CodeModel model) { // TODO Review browser dependent preface code this.WriteLine("AjTalk = function() {"); this.WriteLine("var send = base.send;"); this.WriteLine("var sendSuper = base.sendSuper;"); base.Visit(model); this.WriteLine(); int n = 0; this.WriteLineStart("return {"); foreach (var element in model.Elements) { if (!(element is ClassModel)) continue; if (n > 0) this.WriteLine(","); this.Write(string.Format("{0} : {0}", ((ClassModel)element).Name)); n++; } this.WriteLine(string.Empty); this.WriteLineEnd("}"); this.WriteLine("}();"); }
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;")); }
public void Process(CodeModel model) { for (string chunk = this.reader.GetChunk(); chunk != null; chunk = this.reader.GetChunk()) { bool isreader = false; if (chunk.StartsWith("!")) { chunk = chunk.Substring(1); isreader = true; } ModelParser parser = new ModelParser(chunk); IExpression expression = parser.ParseExpression(); if (isreader) { if (expression is MessageExpression && ((MessageExpression)expression).Selector.Contains("methodsFor:")) this.ProcessMethods(model, (MessageExpression)expression); else if (expression is MessageExpression && ((MessageExpression)expression).Selector.Contains("commentStamp:")) this.ProcessComment(model, (MessageExpression)expression); else this.ProcessReader(); } else { if (expression is MessageExpression) this.ProcessMessageExpression(model, (MessageExpression)expression); } } }
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(); }
public void CompileEmptyModel() { CodeModel model = new CodeModel(); this.compiler.Visit(model); this.writer.Close(); string output = this.writer.ToString(); Assert.IsTrue(ContainsLine(output, "var ajtalk;")); Assert.IsTrue(ContainsLine(output, "var Smalltalk;")); Assert.IsTrue(ContainsLine(output, "if (typeof(ajtalk) === 'undefined')")); Assert.IsTrue(ContainsLine(output, "ajtalk = require('ajtalk.js');")); Assert.IsTrue(ContainsLine(output, "if (typeof(Smalltalk) === 'undefined')")); Assert.IsTrue(ContainsLine(output, "Smalltalk = ajtalk.Smalltalk;")); }
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)); }
public override void Visit(CodeModel model) { this.WriteLine("var ajtalk;"); this.WriteLine("var Smalltalk;"); this.WriteLine(); this.WriteLineStart("if (typeof(ajtalk) === 'undefined')"); this.WriteLine("ajtalk = require('ajtalk.js');"); this.WriteLineEnd(string.Empty); this.WriteLineStart("if (typeof(Smalltalk) === 'undefined')"); this.WriteLine("Smalltalk = ajtalk.Smalltalk;"); this.WriteLineEnd(string.Empty); base.Visit(model); }
public override void Visit(CodeModel model) { // TODO Review Node.js dependent preface code this.WriteLine("var base = require('./js/ajtalk-base.js');"); this.WriteLine("var send = base.send;"); this.WriteLine("var sendSuper = base.sendSuper;"); this.WriteLine("var primitives = require('./js/ajtalk-primitives.js');"); base.Visit(model); this.WriteLine(); foreach (var element in model.Elements) { if (!(element is ClassModel)) continue; // TODO Node.js module dependent this.WriteLine(string.Format("exports.{0} = {0};", ((ClassModel)element).Name)); } }
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 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;")); }
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;")); }
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 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); } }
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); } }
public override void Visit(CodeModel model) { foreach (var element in model.Elements) element.Visit(this); }
public abstract void Visit(CodeModel expression);
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;")); }
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()")); }
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 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']();")); }
private void ProcessComment(CodeModel model, MessageExpression expression) { this.reader.GetChunk(); }
private void ProcessMethods(CodeModel model, MessageExpression expression) { string className = expression.Target.AsString(); ClassModel @class = model.GetClass(className); for (string chunk = this.reader.GetChunk(); chunk != null; chunk = this.reader.GetChunk()) { if (string.IsNullOrEmpty(chunk.Trim())) break; ModelParser parser = new ModelParser(chunk); MethodModel method = parser.ParseMethod(@class, false); model.AddElement(method); } }
private void ProcessMessageExpression(CodeModel model, MessageExpression expression) { // TODO implements weakSubclass if (expression.Selector.StartsWith("subclass:") || expression.Selector.StartsWith("weakSubclass:") || expression.Selector.StartsWith("variableSubclass:")) { bool isvariable = expression.Selector.StartsWith("variableSubclass:"); SymbolExpression symbol = (SymbolExpression)expression.Arguments.First(); VariableExpression variable = (VariableExpression)expression.Target; ClassModel super = null; if (variable.Name != null && variable.Name != symbol.Symbol) //// TODO review quick hack if class is not defined yet if (model.HasClass(variable.Name)) super = model.GetClass(variable.Name); ClassModel @class; if (super != null || variable.Name == null) @class = new ClassModel(symbol.Symbol, super, GetInstanceVariableNames(expression), GetClassVariableNames(expression), isvariable, GetPoolDictionariesNames(expression), GetCategory(expression)); else @class = new ClassModel(symbol.Symbol, variable.Name, GetInstanceVariableNames(expression), GetClassVariableNames(expression), isvariable, GetPoolDictionariesNames(expression), GetCategory(expression)); model.AddElement(@class); } }