diff --git a/README.md b/README.md index 654be48..4a983e9 100644 --- a/README.md +++ b/README.md @@ -37,16 +37,16 @@ Check out the [documentation](https://kyleect.github.io/locks/#/docs) the start fn fizzBuzz(n) { for (let i = 1; i <= n; i = i + 1) { if (i % 15 == 0) { - print "FizzBuzz"; + println("FizzBuzz"); } else if (i % 3 == 0) { - print "Fizz"; + println("Fizz"); } else if (i % 5 == 0) { - print "Buzz"; + println("Buzz"); } else { - print i; + println(i); } } } @@ -75,7 +75,7 @@ $ locks run file.locks #### Execute locks code as an argument ```shell -$ locks exec 'print "Hello";' # Hello +$ locks exec 'println("Hello");' # Hello ``` #### Execute locks code from stdin @@ -90,9 +90,9 @@ $ cat res/benchmarks/fib.locks | locks exec // example.locks let value; -print value; // out: nil +println(value); // out: nil value = 42; -print value; // out: 42; +println(value); // out: 42 ``` ```shell @@ -172,16 +172,16 @@ Program { fn fizzBuzz(n) { for (let i = 1; i <= n; i = i + 1) { if (i % 15 == 0) { - print "FizzBuzz"; + println("FizzBuzz"); } else if (i % 3 == 0) { - print "Fizz"; + println("Fizz"); } else if (i % 5 == 0) { - print "Buzz"; + println("Buzz"); } else { - print i; + println(i); } } } @@ -327,6 +327,7 @@ With the syntax and implementation changes so far the Locks language has divered - Class inheritence: `class Child : Parent {}` -> `class Child extends Parent {}` - Lists: `[1, 2, 3]`, `arr[0]`, `arr[0] = 123` - Add the `len` native function for lists and strings + - Change `print` from a statement to a function: `print`, `println` - Bug Fixes - Add `#[repr(C)]` to `ObjectNative`. This fixes a segfault that occurred when there were multiple entries in the `Native` enum. - [Dockerize](Dockerfile) the Locks binary executable diff --git a/playground/src/pages/docs.tsx b/playground/src/pages/docs.tsx index 02608ab..4965a98 100644 --- a/playground/src/pages/docs.tsx +++ b/playground/src/pages/docs.tsx @@ -169,16 +169,16 @@ const Docs: React.FC = () => ( 'fn fizzBuzz(n) {', ' for (let i = 1; i <= n; i = i + 1) {', ' if (i % 15 == 0) {', - ' print "FizzBuzz";', + ' println("FizzBuzz");', ' }', ' else if (i % 3 == 0) {', - ' print "Fizz";', + ' println("Fizz");', ' }', ' else if (i % 5 == 0) {', - ' print "Buzz";', + ' println("Buzz");', ' }', ' else {', - ' print i;', + ' println(i);', ' }', ' }', '}', @@ -214,9 +214,9 @@ const Docs: React.FC = () => ( anchor="variables" code={[ 'let value;', - 'print value; // out: nil', + 'println(value); // out: nil', 'value = 42;', - 'print value; // out: 42;', + 'println(value); // out: 42;', ]} height="75px" > @@ -231,10 +231,10 @@ const Docs: React.FC = () => ( anchor="nil" code={[ 'let value = nil;', - 'print nil; // out: nil', + 'println(nil); // out: nil', '', 'fn noReturn() {}', - 'print noReturn(); // out: nil', + 'println(noReturn()); // out: nil', ]} height="110px" > @@ -245,16 +245,16 @@ const Docs: React.FC = () => ( title="Numbers" anchor="numbers" code={[ - 'print 123; // out: 123', - 'print 123.45; // out: 123.45', - 'print -123; // out: -123', - 'print -123.45; // out: -123.45', - 'print (5 + 7) * 2.5; // out: 30;', - 'print 5 % 1; // out: 0', - 'print 5 % 2; // out: 1', - 'print 5 % 3; // out: 2', - 'print 5 % 4; // out: 1', - 'print 5 % 5; // out: 0', + 'println(123); // out: 123', + 'println(123.45); // out: 123.45', + 'println(-123); // out: -123', + 'println(-123.45); // out: -123.45', + 'println((5 + 7) * 2.5); // out: 30;', + 'println(5 % 1); // out: 0', + 'println(5 % 2); // out: 1', + 'println(5 % 3); // out: 2', + 'println(5 % 4); // out: 1', + 'println(5 % 5); // out: 0', ]} height="300px" > @@ -264,10 +264,10 @@ const Docs: React.FC = () => ( title="Booleans" anchor="booleans" code={[ - 'print true; // out: true', - 'print true and false; // out: false', - 'print true or false; // out: true', - 'print !true; // out: false', + 'println(true); // out: true', + 'println(true and false); // out: false', + 'println(true or false); // out: true', + 'println(!true); // out: false', ]} height="100px" > @@ -282,7 +282,7 @@ const Docs: React.FC = () => ( 'let isTrue = true;', '', 'if (isTrue) {', - ' print "Was true!";', + ' println("Was true!");', '}', '', '// out: Was true!', @@ -296,9 +296,9 @@ const Docs: React.FC = () => ( 'let isTrue = true;', '', 'if (isTrue) {', - ' print "Was true!";', + ' println("Was true!");', '} else {', - ' print "Was false!";', + ' println("Was false!");', '}', '', '// out: Was true!', @@ -309,8 +309,8 @@ const Docs: React.FC = () => ( title="Strings" anchor="strings" code={[ - 'print "Hello World"; // out: Hello World', - 'print len("Hello World"); // out: 11', + 'println("Hello World"); // out: Hello World', + 'println(len("Hello World")); // out: 11', ]} height="50px" > @@ -319,7 +319,7 @@ const Docs: React.FC = () => ( Strings can be concatenated together using the +{' '} @@ -333,7 +333,7 @@ const Docs: React.FC = () => ( ' return a + b;', '}', '', - 'print sum(60, 40); // out: 100', + 'println(sum(60, 40)); // out: 100', ]} height="100px" /> @@ -343,7 +343,7 @@ const Docs: React.FC = () => ( code={[ 'fn sum (a, b) => a + b;', '', - 'print sum(60, 40); // out: 100', + 'println(sum(60, 40)); // out: 100', ]} height="100px" /> @@ -357,7 +357,7 @@ const Docs: React.FC = () => ( '', 'let add = sum;', '', - 'print add(70, 20); // out: 90', + 'println(add(70, 20)); // out: 90', ]} height="150px" > @@ -376,7 +376,7 @@ const Docs: React.FC = () => ( ' return person;', '}', '', - 'print greet("Hello")("World"); // out: Hello World', + 'println(greet("Hello")("World")); // out: Hello World', ]} height="200px" > @@ -386,8 +386,8 @@ const Docs: React.FC = () => ( title="For Loops" anchor="for-loops" code={[ - 'for (let i = 0; i < 10; i = i + 1) {', - ' print i;', + 'for (var i = 0; i < 10; i = i + 1) {', + ' println(i);', '}', '', '// out: 0', @@ -409,7 +409,7 @@ const Docs: React.FC = () => ( code={[ 'let a = 1;', 'while (a < 10) {', - ' print a;', + ' println(a);', ' a = a + 1;', '}', '', @@ -444,7 +444,7 @@ const Docs: React.FC = () => ( '', 'let greeter = Greeter("Hello");', '', - 'print greeter.greet("World"); // out: Hello World!!!', + 'println(greeter.greet("World")); // out: Hello World!!!', ]} height="325px" /> @@ -473,7 +473,7 @@ const Docs: React.FC = () => ( '', 'let greeter = HelloGreeter();', '', - 'print greeter.greet("World"); // out: Hello World!!!', + 'println(greeter.greet("World")); // out: Hello World!!!', ]} height="425px" /> @@ -496,7 +496,7 @@ const Docs: React.FC = () => ( '', 'let box = Box(123);', '', - 'print box.get(); // out: 123', + 'println(box.get()); // out: 123', ]} height="300px" /> @@ -517,11 +517,11 @@ const Docs: React.FC = () => ( '', 'let box = Box("Hello");', '', - 'print box.get(); // out: Hello', + 'println(box.get()); // out: Hello', '', 'box.value = "World";', '', - 'print box.get(); // out: World', + 'println(box.get()); // out: World', ]} height="350px" /> @@ -531,11 +531,11 @@ const Docs: React.FC = () => ( anchor="lists" code={[ 'let list = [10, 20, 30];', - 'print len(list); // out: 3', + 'println(len(list)); // out: 3', 'let last = list[2];', - 'print last; // out: 30', + 'println(last); // out: 30', 'list[1] = list[1] * 2;', - 'print list[1]; // out: 40', + 'println(list[1]); // out: 40', ]} height="125px" > @@ -1010,7 +1010,7 @@ const Docs: React.FC = () => (

Run Input

-
$ locks exec &squo;print "Hello";&squo;
+
$ locks exec &squo;println("Hello";&squo);
$ cat res/benchmarks/fib.locks | locks exec
diff --git a/playground/vendor/lz-string/tests/lib/jasmine-1.3.1/jasmine.js b/playground/vendor/lz-string/tests/lib/jasmine-1.3.1/jasmine.js index 6b3459b..e2a4ff5 100644 --- a/playground/vendor/lz-string/tests/lib/jasmine-1.3.1/jasmine.js +++ b/playground/vendor/lz-string/tests/lib/jasmine-1.3.1/jasmine.js @@ -1,4 +1,4 @@ -var isCommonJS = typeof window == "undefined" && typeof exports == "object"; +var isCommonJS = typeof window == 'undefined' && typeof exports == 'object'; /** * Top level namespace for Jasmine, a lightweight JavaScript BDD/spec/testing framework. @@ -10,8 +10,8 @@ if (isCommonJS) exports.jasmine = jasmine; /** * @private */ -jasmine.unimplementedMethod_ = function() { - throw new Error("unimplemented method"); +jasmine.unimplementedMethod_ = function () { + throw new Error('unimplemented method'); }; /** @@ -37,7 +37,7 @@ jasmine.DEFAULT_UPDATE_INTERVAL = 250; /** * Maximum levels of nesting that will be included when an object is pretty-printed */ -jasmine.MAX_PRETTY_PRINT_DEPTH = 40; +jasmine.MAX_PRETTY_print_DEPTH = 40; /** * Default timeout interval in milliseconds for waitsFor() blocks. @@ -51,7 +51,7 @@ jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000; */ jasmine.CATCH_EXCEPTIONS = true; -jasmine.getGlobal = function() { +jasmine.getGlobal = function () { function getGlobal() { return this; } @@ -67,10 +67,10 @@ jasmine.getGlobal = function() { * @param base {Object} bound 'this' for the function * @param name {Function} function to find */ -jasmine.bindOriginal_ = function(base, name) { +jasmine.bindOriginal_ = function (base, name) { var original = base[name]; if (original.apply) { - return function() { + return function () { return original.apply(base, arguments); }; } else { @@ -80,20 +80,26 @@ jasmine.bindOriginal_ = function(base, name) { }; jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout'); -jasmine.clearTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearTimeout'); +jasmine.clearTimeout = jasmine.bindOriginal_( + jasmine.getGlobal(), + 'clearTimeout', +); jasmine.setInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'setInterval'); -jasmine.clearInterval = jasmine.bindOriginal_(jasmine.getGlobal(), 'clearInterval'); +jasmine.clearInterval = jasmine.bindOriginal_( + jasmine.getGlobal(), + 'clearInterval', +); -jasmine.MessageResult = function(values) { +jasmine.MessageResult = function (values) { this.type = 'log'; this.values = values; this.trace = new Error(); // todo: test better }; -jasmine.MessageResult.prototype.toString = function() { - var text = ""; +jasmine.MessageResult.prototype.toString = function () { + var text = ''; for (var i = 0; i < this.values.length; i++) { - if (i > 0) text += " "; + if (i > 0) text += ' '; if (jasmine.isString_(this.values[i])) { text += this.values[i]; } else { @@ -103,7 +109,7 @@ jasmine.MessageResult.prototype.toString = function() { return text; }; -jasmine.ExpectationResult = function(params) { +jasmine.ExpectationResult = function (params) { this.type = 'expect'; this.matcherName = params.matcherName; this.passed_ = params.passed; @@ -111,7 +117,7 @@ jasmine.ExpectationResult = function(params) { this.actual = params.actual; this.message = this.passed_ ? 'Passed.' : params.message; - var trace = (params.trace || new Error(this.message)); + var trace = params.trace || new Error(this.message); this.trace = this.passed_ ? '' : trace; }; @@ -126,8 +132,8 @@ jasmine.ExpectationResult.prototype.passed = function () { /** * Getter for the Jasmine environment. Ensures one gets created */ -jasmine.getEnv = function() { - var env = jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env(); +jasmine.getEnv = function () { + var env = (jasmine.currentEnv_ = jasmine.currentEnv_ || new jasmine.Env()); return env; }; @@ -137,8 +143,8 @@ jasmine.getEnv = function() { * @param value * @returns {Boolean} */ -jasmine.isArray_ = function(value) { - return jasmine.isA_("Array", value); +jasmine.isArray_ = function (value) { + return jasmine.isA_('Array', value); }; /** @@ -147,8 +153,8 @@ jasmine.isArray_ = function(value) { * @param value * @returns {Boolean} */ -jasmine.isString_ = function(value) { - return jasmine.isA_("String", value); +jasmine.isString_ = function (value) { + return jasmine.isA_('String', value); }; /** @@ -157,8 +163,8 @@ jasmine.isString_ = function(value) { * @param value * @returns {Boolean} */ -jasmine.isNumber_ = function(value) { - return jasmine.isA_("Number", value); +jasmine.isNumber_ = function (value) { + return jasmine.isA_('Number', value); }; /** @@ -168,7 +174,7 @@ jasmine.isNumber_ = function(value) { * @param value * @returns {Boolean} */ -jasmine.isA_ = function(typeName, value) { +jasmine.isA_ = function (typeName, value) { return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; }; @@ -178,10 +184,10 @@ jasmine.isA_ = function(typeName, value) { * @param value {Object} an object to be outputted * @returns {String} */ -jasmine.pp = function(value) { - var stringPrettyPrinter = new jasmine.StringPrettyPrinter(); - stringPrettyPrinter.format(value); - return stringPrettyPrinter.string; +jasmine.pp = function (value) { + var stringPrettyprinter = new jasmine.StringPrettyPrinter(); + stringPrettyprinter.format(value); + return stringPrettyprinter.string; }; /** @@ -190,7 +196,7 @@ jasmine.pp = function(value) { * @param {Object} obj object to check * @returns {Boolean} */ -jasmine.isDomNode = function(obj) { +jasmine.isDomNode = function (obj) { return obj.nodeType > 0; }; @@ -204,7 +210,7 @@ jasmine.isDomNode = function(obj) { * @param {Class} clazz * @returns matchable object of the type clazz */ -jasmine.any = function(clazz) { +jasmine.any = function (clazz) { return new jasmine.Matchers.Any(clazz); }; @@ -220,7 +226,7 @@ jasmine.any = function(clazz) { * @returns matchable object for the sample */ jasmine.objectContaining = function (sample) { - return new jasmine.Matchers.ObjectContaining(sample); + return new jasmine.Matchers.ObjectContaining(sample); }; /** @@ -267,7 +273,7 @@ jasmine.objectContaining = function (sample) { * @see spyOn, jasmine.createSpy, jasmine.createSpyObj * @param {String} name */ -jasmine.Spy = function(name) { +jasmine.Spy = function (name) { /** * The name of the spy, if provided. */ @@ -279,8 +285,7 @@ jasmine.Spy = function(name) { /** * The actual function this spy stubs. */ - this.plan = function() { - }; + this.plan = function () {}; /** * Tracking of the most recent call to the spy. * @example @@ -315,7 +320,7 @@ jasmine.Spy = function(name) { * // defining a spy on an existing property: foo.bar * spyOn(foo, 'bar').andCallThrough(); */ -jasmine.Spy.prototype.andCallThrough = function() { +jasmine.Spy.prototype.andCallThrough = function () { this.plan = this.originalValue; return this; }; @@ -332,8 +337,8 @@ jasmine.Spy.prototype.andCallThrough = function() { * * @param {Object} value */ -jasmine.Spy.prototype.andReturn = function(value) { - this.plan = function() { +jasmine.Spy.prototype.andReturn = function (value) { + this.plan = function () { return value; }; return this; @@ -351,8 +356,8 @@ jasmine.Spy.prototype.andReturn = function(value) { * * @param {String} exceptionMsg */ -jasmine.Spy.prototype.andThrow = function(exceptionMsg) { - this.plan = function() { +jasmine.Spy.prototype.andThrow = function (exceptionMsg) { + this.plan = function () { throw exceptionMsg; }; return this; @@ -373,7 +378,7 @@ jasmine.Spy.prototype.andThrow = function(exceptionMsg) { * * @param {Function} fakeFunc */ -jasmine.Spy.prototype.andCallFake = function(fakeFunc) { +jasmine.Spy.prototype.andCallFake = function (fakeFunc) { this.plan = fakeFunc; return this; }; @@ -392,7 +397,7 @@ jasmine.Spy.prototype.andCallFake = function(fakeFunc) { * * expect(foo.bar.callCount).toEqual(0); */ -jasmine.Spy.prototype.reset = function() { +jasmine.Spy.prototype.reset = function () { this.wasCalled = false; this.callCount = 0; this.argsForCall = []; @@ -400,16 +405,15 @@ jasmine.Spy.prototype.reset = function() { this.mostRecentCall = {}; }; -jasmine.createSpy = function(name) { - - var spyObj = function() { +jasmine.createSpy = function (name) { + var spyObj = function () { spyObj.wasCalled = true; spyObj.callCount++; var args = jasmine.util.argsToArray(arguments); spyObj.mostRecentCall.object = this; spyObj.mostRecentCall.args = args; spyObj.argsForCall.push(args); - spyObj.calls.push({object: this, args: args}); + spyObj.calls.push({ object: this, args: args }); return spyObj.plan.apply(this, arguments); }; @@ -430,7 +434,7 @@ jasmine.createSpy = function(name) { * @param {jasmine.Spy|Object} putativeSpy * @returns {Boolean} */ -jasmine.isSpy = function(putativeSpy) { +jasmine.isSpy = function (putativeSpy) { return putativeSpy && putativeSpy.isSpy; }; @@ -441,9 +445,11 @@ jasmine.isSpy = function(putativeSpy) { * @param {String} baseName name of spy class * @param {Array} methodNames array of names of methods to make spies */ -jasmine.createSpyObj = function(baseName, methodNames) { +jasmine.createSpyObj = function (baseName, methodNames) { if (!jasmine.isArray_(methodNames) || methodNames.length === 0) { - throw new Error('createSpyObj requires a non-empty array of method names to create spies for'); + throw new Error( + 'createSpyObj requires a non-empty array of method names to create spies for', + ); } var obj = {}; for (var i = 0; i < methodNames.length; i++) { @@ -457,7 +463,7 @@ jasmine.createSpyObj = function(baseName, methodNames) { * * Be careful not to leave calls to jasmine.log in production code. */ -jasmine.log = function() { +jasmine.log = function () { var spec = jasmine.getEnv().currentSpec; spec.log.apply(spec, arguments); }; @@ -477,7 +483,7 @@ jasmine.log = function() { * @param methodName * @return {jasmine.Spy} a Jasmine spy that can be chained with all spy methods */ -var spyOn = function(obj, methodName) { +var spyOn = function (obj, methodName) { return jasmine.getEnv().currentSpec.spyOn(obj, methodName); }; if (isCommonJS) exports.spyOn = spyOn; @@ -495,7 +501,7 @@ if (isCommonJS) exports.spyOn = spyOn; * @param {String} desc description of this specification * @param {Function} func defines the preconditions and expectations of the spec */ -var it = function(desc, func) { +var it = function (desc, func) { return jasmine.getEnv().it(desc, func); }; if (isCommonJS) exports.it = it; @@ -508,7 +514,7 @@ if (isCommonJS) exports.it = it; * @param {String} desc description of this specification * @param {Function} func defines the preconditions and expectations of the spec */ -var xit = function(desc, func) { +var xit = function (desc, func) { return jasmine.getEnv().xit(desc, func); }; if (isCommonJS) exports.xit = xit; @@ -522,7 +528,7 @@ if (isCommonJS) exports.xit = xit; * @param {Object} actual Actual value to test against and expected value * @return {jasmine.Matchers} */ -var expect = function(actual) { +var expect = function (actual) { return jasmine.getEnv().currentSpec.expect(actual); }; if (isCommonJS) exports.expect = expect; @@ -532,7 +538,7 @@ if (isCommonJS) exports.expect = expect; * * @param {Function} func Function that defines part of a jasmine spec. */ -var runs = function(func) { +var runs = function (func) { jasmine.getEnv().currentSpec.runs(func); }; if (isCommonJS) exports.runs = runs; @@ -543,7 +549,7 @@ if (isCommonJS) exports.runs = runs; * @deprecated Use waitsFor() instead * @param {Number} timeout milliseconds to wait */ -var waits = function(timeout) { +var waits = function (timeout) { jasmine.getEnv().currentSpec.waits(timeout); }; if (isCommonJS) exports.waits = waits; @@ -555,8 +561,14 @@ if (isCommonJS) exports.waits = waits; * @param {String} optional_timeoutMessage * @param {Number} optional_timeout */ -var waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { - jasmine.getEnv().currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments); +var waitsFor = function ( + latchFunction, + optional_timeoutMessage, + optional_timeout, +) { + jasmine + .getEnv() + .currentSpec.waitsFor.apply(jasmine.getEnv().currentSpec, arguments); }; if (isCommonJS) exports.waitsFor = waitsFor; @@ -567,7 +579,7 @@ if (isCommonJS) exports.waitsFor = waitsFor; * * @param {Function} beforeEachFunction */ -var beforeEach = function(beforeEachFunction) { +var beforeEach = function (beforeEachFunction) { jasmine.getEnv().beforeEach(beforeEachFunction); }; if (isCommonJS) exports.beforeEach = beforeEach; @@ -579,7 +591,7 @@ if (isCommonJS) exports.beforeEach = beforeEach; * * @param {Function} afterEachFunction */ -var afterEach = function(afterEachFunction) { +var afterEach = function (afterEachFunction) { jasmine.getEnv().afterEach(afterEachFunction); }; if (isCommonJS) exports.afterEach = afterEach; @@ -599,7 +611,7 @@ if (isCommonJS) exports.afterEach = afterEach; * @param {String} description A string, usually the class under test. * @param {Function} specDefinitions function that defines several specs. */ -var describe = function(description, specDefinitions) { +var describe = function (description, specDefinitions) { return jasmine.getEnv().describe(description, specDefinitions); }; if (isCommonJS) exports.describe = describe; @@ -610,39 +622,42 @@ if (isCommonJS) exports.describe = describe; * @param {String} description A string, usually the class under test. * @param {Function} specDefinitions function that defines several specs. */ -var xdescribe = function(description, specDefinitions) { +var xdescribe = function (description, specDefinitions) { return jasmine.getEnv().xdescribe(description, specDefinitions); }; if (isCommonJS) exports.xdescribe = xdescribe; - // Provide the XMLHttpRequest class for IE 5.x-6.x: -jasmine.XmlHttpRequest = (typeof XMLHttpRequest == "undefined") ? function() { - function tryIt(f) { - try { - return f(); - } catch(e) { - } - return null; - } - - var xhr = tryIt(function() { - return new ActiveXObject("Msxml2.XMLHTTP.6.0"); - }) || - tryIt(function() { - return new ActiveXObject("Msxml2.XMLHTTP.3.0"); - }) || - tryIt(function() { - return new ActiveXObject("Msxml2.XMLHTTP"); - }) || - tryIt(function() { - return new ActiveXObject("Microsoft.XMLHTTP"); - }); - - if (!xhr) throw new Error("This browser does not support XMLHttpRequest."); +jasmine.XmlHttpRequest = + typeof XMLHttpRequest == 'undefined' + ? function () { + function tryIt(f) { + try { + return f(); + } catch (e) {} + return null; + } - return xhr; -} : XMLHttpRequest; + var xhr = + tryIt(function () { + return new ActiveXObject('Msxml2.XMLHTTP.6.0'); + }) || + tryIt(function () { + return new ActiveXObject('Msxml2.XMLHTTP.3.0'); + }) || + tryIt(function () { + return new ActiveXObject('Msxml2.XMLHTTP'); + }) || + tryIt(function () { + return new ActiveXObject('Microsoft.XMLHTTP'); + }); + + if (!xhr) + throw new Error('This browser does not support XMLHttpRequest.'); + + return xhr; + } + : XMLHttpRequest; /** * @namespace */ @@ -655,22 +670,20 @@ jasmine.util = {}; * @param {Function} childClass * @param {Function} parentClass */ -jasmine.util.inherit = function(childClass, parentClass) { +jasmine.util.inherit = function (childClass, parentClass) { /** * @private */ - var subclass = function() { - }; + var subclass = function () {}; subclass.prototype = parentClass.prototype; childClass.prototype = new subclass(); }; -jasmine.util.formatException = function(e) { +jasmine.util.formatException = function (e) { var lineNumber; if (e.line) { lineNumber = e.line; - } - else if (e.lineNumber) { + } else if (e.lineNumber) { lineNumber = e.lineNumber; } @@ -678,12 +691,11 @@ jasmine.util.formatException = function(e) { if (e.sourceURL) { file = e.sourceURL; - } - else if (e.fileName) { + } else if (e.fileName) { file = e.fileName; } - var message = (e.name && e.message) ? (e.name + ': ' + e.message) : e.toString(); + var message = e.name && e.message ? e.name + ': ' + e.message : e.toString(); if (file && lineNumber) { message += ' in ' + file + ' (line ' + lineNumber + ')'; @@ -692,20 +704,18 @@ jasmine.util.formatException = function(e) { return message; }; -jasmine.util.htmlEscape = function(str) { +jasmine.util.htmlEscape = function (str) { if (!str) return str; - return str.replace(/&/g, '&') - .replace(//g, '>'); + return str.replace(/&/g, '&').replace(//g, '>'); }; -jasmine.util.argsToArray = function(args) { +jasmine.util.argsToArray = function (args) { var arrayOfArgs = []; for (var i = 0; i < args.length; i++) arrayOfArgs.push(args[i]); return arrayOfArgs; }; -jasmine.util.extend = function(destination, source) { +jasmine.util.extend = function (destination, source) { for (var property in source) destination[property] = source[property]; return destination; }; @@ -715,7 +725,7 @@ jasmine.util.extend = function(destination, source) { * * @constructor */ -jasmine.Env = function() { +jasmine.Env = function () { this.currentSpec = null; this.currentSuite = null; this.currentRunner_ = new jasmine.Runner(this); @@ -725,7 +735,7 @@ jasmine.Env = function() { this.updateInterval = jasmine.DEFAULT_UPDATE_INTERVAL; this.defaultTimeoutInterval = jasmine.DEFAULT_TIMEOUT_INTERVAL; this.lastUpdate = 0; - this.specFilter = function() { + this.specFilter = function () { return true; }; @@ -734,7 +744,7 @@ jasmine.Env = function() { this.equalityTesters_ = []; // wrap matchers - this.matchersClass = function() { + this.matchersClass = function () { jasmine.Matchers.apply(this, arguments); }; jasmine.util.inherit(this.matchersClass, jasmine.Matchers); @@ -742,7 +752,6 @@ jasmine.Env = function() { jasmine.Matchers.wrapInto_(jasmine.Matchers.prototype, this.matchersClass); }; - jasmine.Env.prototype.setTimeout = jasmine.setTimeout; jasmine.Env.prototype.clearTimeout = jasmine.clearTimeout; jasmine.Env.prototype.setInterval = jasmine.setInterval; @@ -762,17 +771,17 @@ jasmine.Env.prototype.version = function () { /** * @returns string containing jasmine version build info, if set. */ -jasmine.Env.prototype.versionString = function() { +jasmine.Env.prototype.versionString = function () { if (!jasmine.version_) { - return "version unknown"; + return 'version unknown'; } var version = this.version(); - var versionString = version.major + "." + version.minor + "." + version.build; + var versionString = version.major + '.' + version.minor + '.' + version.build; if (version.release_candidate) { - versionString += ".rc" + version.release_candidate; + versionString += '.rc' + version.release_candidate; } - versionString += " revision " + version.revision; + versionString += ' revision ' + version.revision; return versionString; }; @@ -794,16 +803,21 @@ jasmine.Env.prototype.nextSuiteId = function () { * Register a reporter to receive status updates from Jasmine. * @param {jasmine.Reporter} reporter An object which will receive status updates. */ -jasmine.Env.prototype.addReporter = function(reporter) { +jasmine.Env.prototype.addReporter = function (reporter) { this.reporter.addReporter(reporter); }; -jasmine.Env.prototype.execute = function() { +jasmine.Env.prototype.execute = function () { this.currentRunner_.execute(); }; -jasmine.Env.prototype.describe = function(description, specDefinitions) { - var suite = new jasmine.Suite(this, description, specDefinitions, this.currentSuite); +jasmine.Env.prototype.describe = function (description, specDefinitions) { + var suite = new jasmine.Suite( + this, + description, + specDefinitions, + this.currentSuite, + ); var parentSuite = this.currentSuite; if (parentSuite) { @@ -817,12 +831,12 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) { var declarationError = null; try { specDefinitions.call(suite); - } catch(e) { + } catch (e) { declarationError = e; } if (declarationError) { - this.it("encountered a declaration exception", function() { + this.it('encountered a declaration exception', function () { throw declarationError; }); } @@ -832,7 +846,7 @@ jasmine.Env.prototype.describe = function(description, specDefinitions) { return suite; }; -jasmine.Env.prototype.beforeEach = function(beforeEachFunction) { +jasmine.Env.prototype.beforeEach = function (beforeEachFunction) { if (this.currentSuite) { this.currentSuite.beforeEach(beforeEachFunction); } else { @@ -844,23 +858,21 @@ jasmine.Env.prototype.currentRunner = function () { return this.currentRunner_; }; -jasmine.Env.prototype.afterEach = function(afterEachFunction) { +jasmine.Env.prototype.afterEach = function (afterEachFunction) { if (this.currentSuite) { this.currentSuite.afterEach(afterEachFunction); } else { this.currentRunner_.afterEach(afterEachFunction); } - }; -jasmine.Env.prototype.xdescribe = function(desc, specDefinitions) { +jasmine.Env.prototype.xdescribe = function (desc, specDefinitions) { return { - execute: function() { - } + execute: function () {}, }; }; -jasmine.Env.prototype.it = function(description, func) { +jasmine.Env.prototype.it = function (description, func) { var spec = new jasmine.Spec(this, this.currentSuite, description); this.currentSuite.add(spec); this.currentSpec = spec; @@ -872,72 +884,122 @@ jasmine.Env.prototype.it = function(description, func) { return spec; }; -jasmine.Env.prototype.xit = function(desc, func) { +jasmine.Env.prototype.xit = function (desc, func) { return { id: this.nextSpecId(), - runs: function() { - } + runs: function () {}, }; }; -jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchValues) { +jasmine.Env.prototype.compareRegExps_ = function ( + a, + b, + mismatchKeys, + mismatchValues, +) { if (a.source != b.source) - mismatchValues.push("expected pattern /" + b.source + "/ is not equal to the pattern /" + a.source + "/"); + mismatchValues.push( + 'expected pattern /' + + b.source + + '/ is not equal to the pattern /' + + a.source + + '/', + ); if (a.ignoreCase != b.ignoreCase) - mismatchValues.push("expected modifier i was" + (b.ignoreCase ? " " : " not ") + "set and does not equal the origin modifier"); + mismatchValues.push( + 'expected modifier i was' + + (b.ignoreCase ? ' ' : ' not ') + + 'set and does not equal the origin modifier', + ); if (a.global != b.global) - mismatchValues.push("expected modifier g was" + (b.global ? " " : " not ") + "set and does not equal the origin modifier"); + mismatchValues.push( + 'expected modifier g was' + + (b.global ? ' ' : ' not ') + + 'set and does not equal the origin modifier', + ); if (a.multiline != b.multiline) - mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier"); + mismatchValues.push( + 'expected modifier m was' + + (b.multiline ? ' ' : ' not ') + + 'set and does not equal the origin modifier', + ); if (a.sticky != b.sticky) - mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier"); - - return (mismatchValues.length === 0); -}; - -jasmine.Env.prototype.compareObjects_ = function(a, b, mismatchKeys, mismatchValues) { - if (a.__Jasmine_been_here_before__ === b && b.__Jasmine_been_here_before__ === a) { + mismatchValues.push( + 'expected modifier y was' + + (b.sticky ? ' ' : ' not ') + + 'set and does not equal the origin modifier', + ); + + return mismatchValues.length === 0; +}; + +jasmine.Env.prototype.compareObjects_ = function ( + a, + b, + mismatchKeys, + mismatchValues, +) { + if ( + a.__Jasmine_been_here_before__ === b && + b.__Jasmine_been_here_before__ === a + ) { return true; } a.__Jasmine_been_here_before__ = b; b.__Jasmine_been_here_before__ = a; - var hasKey = function(obj, keyName) { + var hasKey = function (obj, keyName) { return obj !== null && obj[keyName] !== jasmine.undefined; }; for (var property in b) { if (!hasKey(a, property) && hasKey(b, property)) { - mismatchKeys.push("expected has key '" + property + "', but missing from actual."); + mismatchKeys.push( + "expected has key '" + property + "', but missing from actual.", + ); } } for (property in a) { if (!hasKey(b, property) && hasKey(a, property)) { - mismatchKeys.push("expected missing key '" + property + "', but present in actual."); + mismatchKeys.push( + "expected missing key '" + property + "', but present in actual.", + ); } } for (property in b) { if (property == '__Jasmine_been_here_before__') continue; if (!this.equals_(a[property], b[property], mismatchKeys, mismatchValues)) { - mismatchValues.push("'" + property + "' was '" + (b[property] ? jasmine.util.htmlEscape(b[property].toString()) : b[property]) + "' in expected, but was '" + (a[property] ? jasmine.util.htmlEscape(a[property].toString()) : a[property]) + "' in actual."); + mismatchValues.push( + "'" + + property + + "' was '" + + (b[property] + ? jasmine.util.htmlEscape(b[property].toString()) + : b[property]) + + "' in expected, but was '" + + (a[property] + ? jasmine.util.htmlEscape(a[property].toString()) + : a[property]) + + "' in actual.", + ); } } if (jasmine.isArray_(a) && jasmine.isArray_(b) && a.length != b.length) { - mismatchValues.push("arrays were not the same length"); + mismatchValues.push('arrays were not the same length'); } delete a.__Jasmine_been_here_before__; delete b.__Jasmine_been_here_before__; - return (mismatchKeys.length === 0 && mismatchValues.length === 0); + return mismatchKeys.length === 0 && mismatchValues.length === 0; }; -jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { +jasmine.Env.prototype.equals_ = function (a, b, mismatchKeys, mismatchValues) { mismatchKeys = mismatchKeys || []; mismatchValues = mismatchValues || []; @@ -949,8 +1011,13 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { if (a === b) return true; - if (a === jasmine.undefined || a === null || b === jasmine.undefined || b === null) { - return (a == jasmine.undefined && b == jasmine.undefined); + if ( + a === jasmine.undefined || + a === null || + b === jasmine.undefined || + b === null + ) { + return a == jasmine.undefined && b == jasmine.undefined; } if (jasmine.isDomNode(a) && jasmine.isDomNode(b)) { @@ -978,26 +1045,26 @@ jasmine.Env.prototype.equals_ = function(a, b, mismatchKeys, mismatchValues) { } if (jasmine.isString_(a) && jasmine.isString_(b)) { - return (a == b); + return a == b; } if (jasmine.isNumber_(a) && jasmine.isNumber_(b)) { - return (a == b); + return a == b; } if (a instanceof RegExp && b instanceof RegExp) { return this.compareRegExps_(a, b, mismatchKeys, mismatchValues); } - if (typeof a === "object" && typeof b === "object") { + if (typeof a === 'object' && typeof b === 'object') { return this.compareObjects_(a, b, mismatchKeys, mismatchValues); } //Straight check - return (a === b); + return a === b; }; -jasmine.Env.prototype.contains_ = function(haystack, needle) { +jasmine.Env.prototype.contains_ = function (haystack, needle) { if (jasmine.isArray_(haystack)) { for (var i = 0; i < haystack.length; i++) { if (this.equals_(haystack[i], needle)) return true; @@ -1007,39 +1074,32 @@ jasmine.Env.prototype.contains_ = function(haystack, needle) { return haystack.indexOf(needle) >= 0; }; -jasmine.Env.prototype.addEqualityTester = function(equalityTester) { +jasmine.Env.prototype.addEqualityTester = function (equalityTester) { this.equalityTesters_.push(equalityTester); }; /** No-op base class for Jasmine reporters. * * @constructor */ -jasmine.Reporter = function() { -}; +jasmine.Reporter = function () {}; //noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportRunnerStarting = function(runner) { -}; +jasmine.Reporter.prototype.reportRunnerStarting = function (runner) {}; //noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportRunnerResults = function(runner) { -}; +jasmine.Reporter.prototype.reportRunnerResults = function (runner) {}; //noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportSuiteResults = function(suite) { -}; +jasmine.Reporter.prototype.reportSuiteResults = function (suite) {}; //noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportSpecStarting = function(spec) { -}; +jasmine.Reporter.prototype.reportSpecStarting = function (spec) {}; //noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.reportSpecResults = function(spec) { -}; +jasmine.Reporter.prototype.reportSpecResults = function (spec) {}; //noinspection JSUnusedLocalSymbols -jasmine.Reporter.prototype.log = function(str) { -}; +jasmine.Reporter.prototype.log = function (str) {}; /** * Blocks are functions with executable code that make up a spec. @@ -1049,17 +1109,16 @@ jasmine.Reporter.prototype.log = function(str) { * @param {Function} func * @param {jasmine.Spec} spec */ -jasmine.Block = function(env, func, spec) { +jasmine.Block = function (env, func, spec) { this.env = env; this.func = func; this.spec = spec; }; -jasmine.Block.prototype.execute = function(onComplete) { +jasmine.Block.prototype.execute = function (onComplete) { if (!jasmine.CATCH_EXCEPTIONS) { this.func.apply(this.spec); - } - else { + } else { try { this.func.apply(this.spec); } catch (e) { @@ -1072,14 +1131,14 @@ jasmine.Block.prototype.execute = function(onComplete) { * * @constructor */ -jasmine.JsApiReporter = function() { +jasmine.JsApiReporter = function () { this.started = false; this.finished = false; this.suites_ = []; this.results_ = {}; }; -jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { +jasmine.JsApiReporter.prototype.reportRunnerStarting = function (runner) { this.started = true; var suites = runner.topLevelSuites(); for (var i = 0; i < suites.length; i++) { @@ -1088,19 +1147,19 @@ jasmine.JsApiReporter.prototype.reportRunnerStarting = function(runner) { } }; -jasmine.JsApiReporter.prototype.suites = function() { +jasmine.JsApiReporter.prototype.suites = function () { return this.suites_; }; -jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { +jasmine.JsApiReporter.prototype.summarize_ = function (suiteOrSpec) { var isSuite = suiteOrSpec instanceof jasmine.Suite; var summary = { id: suiteOrSpec.id, name: suiteOrSpec.description, type: isSuite ? 'suite' : 'spec', - children: [] + children: [], }; - + if (isSuite) { var children = suiteOrSpec.children(); for (var i = 0; i < children.length; i++) { @@ -1110,36 +1169,34 @@ jasmine.JsApiReporter.prototype.summarize_ = function(suiteOrSpec) { return summary; }; -jasmine.JsApiReporter.prototype.results = function() { +jasmine.JsApiReporter.prototype.results = function () { return this.results_; }; -jasmine.JsApiReporter.prototype.resultsForSpec = function(specId) { +jasmine.JsApiReporter.prototype.resultsForSpec = function (specId) { return this.results_[specId]; }; //noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.reportRunnerResults = function(runner) { +jasmine.JsApiReporter.prototype.reportRunnerResults = function (runner) { this.finished = true; }; //noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.reportSuiteResults = function(suite) { -}; +jasmine.JsApiReporter.prototype.reportSuiteResults = function (suite) {}; //noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.reportSpecResults = function(spec) { +jasmine.JsApiReporter.prototype.reportSpecResults = function (spec) { this.results_[spec.id] = { messages: spec.results().getItems(), - result: spec.results().failedCount > 0 ? "failed" : "passed" + result: spec.results().failedCount > 0 ? 'failed' : 'passed', }; }; //noinspection JSUnusedLocalSymbols -jasmine.JsApiReporter.prototype.log = function(str) { -}; +jasmine.JsApiReporter.prototype.log = function (str) {}; -jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ +jasmine.JsApiReporter.prototype.resultsForSpecs = function (specIds) { var results = {}; for (var i = 0; i < specIds.length; i++) { var specId = specIds[i]; @@ -1148,25 +1205,31 @@ jasmine.JsApiReporter.prototype.resultsForSpecs = function(specIds){ return results; }; -jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ +jasmine.JsApiReporter.prototype.summarizeResult_ = function (result) { var summaryMessages = []; var messagesLength = result.messages.length; for (var messageIndex = 0; messageIndex < messagesLength; messageIndex++) { var resultMessage = result.messages[messageIndex]; summaryMessages.push({ - text: resultMessage.type == 'log' ? resultMessage.toString() : jasmine.undefined, + text: + resultMessage.type == 'log' + ? resultMessage.toString() + : jasmine.undefined, passed: resultMessage.passed ? resultMessage.passed() : true, type: resultMessage.type, message: resultMessage.message, trace: { - stack: resultMessage.passed && !resultMessage.passed() ? resultMessage.trace.stack : jasmine.undefined - } + stack: + resultMessage.passed && !resultMessage.passed() + ? resultMessage.trace.stack + : jasmine.undefined, + }, }); } return { - result : result.result, - messages : summaryMessages + result: result.result, + messages: summaryMessages, }; }; @@ -1176,7 +1239,7 @@ jasmine.JsApiReporter.prototype.summarizeResult_ = function(result){ * @param actual * @param {jasmine.Spec} spec */ -jasmine.Matchers = function(env, actual, spec, opt_isNot) { +jasmine.Matchers = function (env, actual, spec, opt_isNot) { this.env = env; this.actual = actual; this.spec = spec; @@ -1185,25 +1248,36 @@ jasmine.Matchers = function(env, actual, spec, opt_isNot) { }; // todo: @deprecated as of Jasmine 0.11, remove soon [xw] -jasmine.Matchers.pp = function(str) { - throw new Error("jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!"); +jasmine.Matchers.pp = function (str) { + throw new Error( + 'jasmine.Matchers.pp() is no longer supported, please use jasmine.pp() instead!', + ); }; // todo: @deprecated Deprecated as of Jasmine 0.10. Rewrite your custom matchers to return true or false. [xw] -jasmine.Matchers.prototype.report = function(result, failing_message, details) { - throw new Error("As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs"); +jasmine.Matchers.prototype.report = function ( + result, + failing_message, + details, +) { + throw new Error( + 'As of jasmine 0.11, custom matchers must be implemented differently -- please see jasmine docs', + ); }; -jasmine.Matchers.wrapInto_ = function(prototype, matchersClass) { +jasmine.Matchers.wrapInto_ = function (prototype, matchersClass) { for (var methodName in prototype) { if (methodName == 'report') continue; var orig = prototype[methodName]; - matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_(methodName, orig); + matchersClass.prototype[methodName] = jasmine.Matchers.matcherFn_( + methodName, + orig, + ); } }; -jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { - return function() { +jasmine.Matchers.matcherFn_ = function (matcherName, matcherFunction) { + return function () { var matcherArgs = jasmine.util.argsToArray(arguments); var result = matcherFunction.apply(this, arguments); @@ -1221,15 +1295,21 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { message = message[this.isNot ? 1 : 0]; } } else { - var englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); - message = "Expected " + jasmine.pp(this.actual) + (this.isNot ? " not " : " ") + englishyPredicate; + var englishyPredicate = matcherName.replace(/[A-Z]/g, function (s) { + return ' ' + s.toLowerCase(); + }); + message = + 'Expected ' + + jasmine.pp(this.actual) + + (this.isNot ? ' not ' : ' ') + + englishyPredicate; if (matcherArgs.length > 0) { for (var i = 0; i < matcherArgs.length; i++) { - if (i > 0) message += ","; - message += " " + jasmine.pp(matcherArgs[i]); + if (i > 0) message += ','; + message += ' ' + jasmine.pp(matcherArgs[i]); } } - message += "."; + message += '.'; } } var expectationResult = new jasmine.ExpectationResult({ @@ -1237,21 +1317,18 @@ jasmine.Matchers.matcherFn_ = function(matcherName, matcherFunction) { passed: result, expected: matcherArgs.length > 1 ? matcherArgs : matcherArgs[0], actual: this.actual, - message: message + message: message, }); this.spec.addMatcherResult(expectationResult); return jasmine.undefined; }; }; - - - /** * toBe: compares the actual to the expected using === * @param expected */ -jasmine.Matchers.prototype.toBe = function(expected) { +jasmine.Matchers.prototype.toBe = function (expected) { return this.actual === expected; }; @@ -1260,7 +1337,7 @@ jasmine.Matchers.prototype.toBe = function(expected) { * @param expected * @deprecated as of 1.0. Use not.toBe() instead. */ -jasmine.Matchers.prototype.toNotBe = function(expected) { +jasmine.Matchers.prototype.toNotBe = function (expected) { return this.actual !== expected; }; @@ -1269,7 +1346,7 @@ jasmine.Matchers.prototype.toNotBe = function(expected) { * * @param expected */ -jasmine.Matchers.prototype.toEqual = function(expected) { +jasmine.Matchers.prototype.toEqual = function (expected) { return this.env.equals_(this.actual, expected); }; @@ -1278,7 +1355,7 @@ jasmine.Matchers.prototype.toEqual = function(expected) { * @param expected * @deprecated as of 1.0. Use not.toEqual() instead. */ -jasmine.Matchers.prototype.toNotEqual = function(expected) { +jasmine.Matchers.prototype.toNotEqual = function (expected) { return !this.env.equals_(this.actual, expected); }; @@ -1288,7 +1365,7 @@ jasmine.Matchers.prototype.toNotEqual = function(expected) { * * @param expected */ -jasmine.Matchers.prototype.toMatch = function(expected) { +jasmine.Matchers.prototype.toMatch = function (expected) { return new RegExp(expected).test(this.actual); }; @@ -1297,74 +1374,74 @@ jasmine.Matchers.prototype.toMatch = function(expected) { * @param expected * @deprecated as of 1.0. Use not.toMatch() instead. */ -jasmine.Matchers.prototype.toNotMatch = function(expected) { - return !(new RegExp(expected).test(this.actual)); +jasmine.Matchers.prototype.toNotMatch = function (expected) { + return !new RegExp(expected).test(this.actual); }; /** * Matcher that compares the actual to jasmine.undefined. */ -jasmine.Matchers.prototype.toBeDefined = function() { - return (this.actual !== jasmine.undefined); +jasmine.Matchers.prototype.toBeDefined = function () { + return this.actual !== jasmine.undefined; }; /** * Matcher that compares the actual to jasmine.undefined. */ -jasmine.Matchers.prototype.toBeUndefined = function() { - return (this.actual === jasmine.undefined); +jasmine.Matchers.prototype.toBeUndefined = function () { + return this.actual === jasmine.undefined; }; /** * Matcher that compares the actual to null. */ -jasmine.Matchers.prototype.toBeNull = function() { - return (this.actual === null); +jasmine.Matchers.prototype.toBeNull = function () { + return this.actual === null; }; /** * Matcher that compares the actual to NaN. */ -jasmine.Matchers.prototype.toBeNaN = function() { - this.message = function() { - return [ "Expected " + jasmine.pp(this.actual) + " to be NaN." ]; - }; +jasmine.Matchers.prototype.toBeNaN = function () { + this.message = function () { + return ['Expected ' + jasmine.pp(this.actual) + ' to be NaN.']; + }; - return (this.actual !== this.actual); + return this.actual !== this.actual; }; /** * Matcher that boolean not-nots the actual. */ -jasmine.Matchers.prototype.toBeTruthy = function() { +jasmine.Matchers.prototype.toBeTruthy = function () { return !!this.actual; }; - /** * Matcher that boolean nots the actual. */ -jasmine.Matchers.prototype.toBeFalsy = function() { +jasmine.Matchers.prototype.toBeFalsy = function () { return !this.actual; }; - /** * Matcher that checks to see if the actual, a Jasmine spy, was called. */ -jasmine.Matchers.prototype.toHaveBeenCalled = function() { +jasmine.Matchers.prototype.toHaveBeenCalled = function () { if (arguments.length > 0) { - throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); + throw new Error( + 'toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith', + ); } if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } - this.message = function() { + this.message = function () { return [ - "Expected spy " + this.actual.identity + " to have been called.", - "Expected spy " + this.actual.identity + " not to have been called." + 'Expected spy ' + this.actual.identity + ' to have been called.', + 'Expected spy ' + this.actual.identity + ' not to have been called.', ]; }; @@ -1372,14 +1449,15 @@ jasmine.Matchers.prototype.toHaveBeenCalled = function() { }; /** @deprecated Use expect(xxx).toHaveBeenCalled() instead */ -jasmine.Matchers.prototype.wasCalled = jasmine.Matchers.prototype.toHaveBeenCalled; +jasmine.Matchers.prototype.wasCalled = + jasmine.Matchers.prototype.toHaveBeenCalled; /** * Matcher that checks to see if the actual, a Jasmine spy, was not called. * * @deprecated Use expect(xxx).not.toHaveBeenCalled() instead */ -jasmine.Matchers.prototype.wasNotCalled = function() { +jasmine.Matchers.prototype.wasNotCalled = function () { if (arguments.length > 0) { throw new Error('wasNotCalled does not take arguments'); } @@ -1388,10 +1466,10 @@ jasmine.Matchers.prototype.wasNotCalled = function() { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } - this.message = function() { + this.message = function () { return [ - "Expected spy " + this.actual.identity + " to not have been called.", - "Expected spy " + this.actual.identity + " to have been called." + 'Expected spy ' + this.actual.identity + ' to not have been called.', + 'Expected spy ' + this.actual.identity + ' to have been called.', ]; }; @@ -1404,18 +1482,34 @@ jasmine.Matchers.prototype.wasNotCalled = function() { * @example * */ -jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { +jasmine.Matchers.prototype.toHaveBeenCalledWith = function () { var expectedArgs = jasmine.util.argsToArray(arguments); if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } - this.message = function() { - var invertedMessage = "Expected spy " + this.actual.identity + " not to have been called with " + jasmine.pp(expectedArgs) + " but it was."; - var positiveMessage = ""; + this.message = function () { + var invertedMessage = + 'Expected spy ' + + this.actual.identity + + ' not to have been called with ' + + jasmine.pp(expectedArgs) + + ' but it was.'; + var positiveMessage = ''; if (this.actual.callCount === 0) { - positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but it was never called."; + positiveMessage = + 'Expected spy ' + + this.actual.identity + + ' to have been called with ' + + jasmine.pp(expectedArgs) + + ' but it was never called.'; } else { - positiveMessage = "Expected spy " + this.actual.identity + " to have been called with " + jasmine.pp(expectedArgs) + " but actual calls were " + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, '') + positiveMessage = + 'Expected spy ' + + this.actual.identity + + ' to have been called with ' + + jasmine.pp(expectedArgs) + + ' but actual calls were ' + + jasmine.pp(this.actual.argsForCall).replace(/^\[ | \]$/g, ''); } return [positiveMessage, invertedMessage]; }; @@ -1424,19 +1518,24 @@ jasmine.Matchers.prototype.toHaveBeenCalledWith = function() { }; /** @deprecated Use expect(xxx).toHaveBeenCalledWith() instead */ -jasmine.Matchers.prototype.wasCalledWith = jasmine.Matchers.prototype.toHaveBeenCalledWith; +jasmine.Matchers.prototype.wasCalledWith = + jasmine.Matchers.prototype.toHaveBeenCalledWith; /** @deprecated Use expect(xxx).not.toHaveBeenCalledWith() instead */ -jasmine.Matchers.prototype.wasNotCalledWith = function() { +jasmine.Matchers.prototype.wasNotCalledWith = function () { var expectedArgs = jasmine.util.argsToArray(arguments); if (!jasmine.isSpy(this.actual)) { throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); } - this.message = function() { + this.message = function () { return [ - "Expected spy not to have been called with " + jasmine.pp(expectedArgs) + " but it was", - "Expected spy to have been called with " + jasmine.pp(expectedArgs) + " but it was" + 'Expected spy not to have been called with ' + + jasmine.pp(expectedArgs) + + ' but it was', + 'Expected spy to have been called with ' + + jasmine.pp(expectedArgs) + + ' but it was', ]; }; @@ -1448,7 +1547,7 @@ jasmine.Matchers.prototype.wasNotCalledWith = function() { * * @param {Object} expected */ -jasmine.Matchers.prototype.toContain = function(expected) { +jasmine.Matchers.prototype.toContain = function (expected) { return this.env.contains_(this.actual, expected); }; @@ -1458,15 +1557,15 @@ jasmine.Matchers.prototype.toContain = function(expected) { * @param {Object} expected * @deprecated as of 1.0. Use not.toContain() instead. */ -jasmine.Matchers.prototype.toNotContain = function(expected) { +jasmine.Matchers.prototype.toNotContain = function (expected) { return !this.env.contains_(this.actual, expected); }; -jasmine.Matchers.prototype.toBeLessThan = function(expected) { +jasmine.Matchers.prototype.toBeLessThan = function (expected) { return this.actual < expected; }; -jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { +jasmine.Matchers.prototype.toBeGreaterThan = function (expected) { return this.actual > expected; }; @@ -1477,11 +1576,11 @@ jasmine.Matchers.prototype.toBeGreaterThan = function(expected) { * @param {Number} expected * @param {Number} precision, as number of decimal places */ -jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) { +jasmine.Matchers.prototype.toBeCloseTo = function (expected, precision) { if (!(precision === 0)) { precision = precision || 2; } - return Math.abs(expected - this.actual) < (Math.pow(10, -precision) / 2); + return Math.abs(expected - this.actual) < Math.pow(10, -precision) / 2; }; /** @@ -1489,7 +1588,7 @@ jasmine.Matchers.prototype.toBeCloseTo = function(expected, precision) { * * @param {String} [expected] */ -jasmine.Matchers.prototype.toThrow = function(expected) { +jasmine.Matchers.prototype.toThrow = function (expected) { var result = false; var exception; if (typeof this.actual != 'function') { @@ -1501,27 +1600,44 @@ jasmine.Matchers.prototype.toThrow = function(expected) { exception = e; } if (exception) { - result = (expected === jasmine.undefined || this.env.equals_(exception.message || exception, expected.message || expected)); - } - - var not = this.isNot ? "not " : ""; - - this.message = function() { - if (exception && (expected === jasmine.undefined || !this.env.equals_(exception.message || exception, expected.message || expected))) { - return ["Expected function " + not + "to throw", expected ? expected.message || expected : "an exception", ", but it threw", exception.message || exception].join(' '); + result = + expected === jasmine.undefined || + this.env.equals_( + exception.message || exception, + expected.message || expected, + ); + } + + var not = this.isNot ? 'not ' : ''; + + this.message = function () { + if ( + exception && + (expected === jasmine.undefined || + !this.env.equals_( + exception.message || exception, + expected.message || expected, + )) + ) { + return [ + 'Expected function ' + not + 'to throw', + expected ? expected.message || expected : 'an exception', + ', but it threw', + exception.message || exception, + ].join(' '); } else { - return "Expected function to throw an exception."; + return 'Expected function to throw an exception.'; } }; return result; }; -jasmine.Matchers.Any = function(expectedClass) { +jasmine.Matchers.Any = function (expectedClass) { this.expectedClass = expectedClass; }; -jasmine.Matchers.Any.prototype.jasmineMatches = function(other) { +jasmine.Matchers.Any.prototype.jasmineMatches = function (other) { if (this.expectedClass == String) { return typeof other == 'string' || other instanceof String; } @@ -1541,7 +1657,7 @@ jasmine.Matchers.Any.prototype.jasmineMatches = function(other) { return other instanceof this.expectedClass; }; -jasmine.Matchers.Any.prototype.jasmineToString = function() { +jasmine.Matchers.Any.prototype.jasmineToString = function () { return ''; }; @@ -1549,88 +1665,116 @@ jasmine.Matchers.ObjectContaining = function (sample) { this.sample = sample; }; -jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) { +jasmine.Matchers.ObjectContaining.prototype.jasmineMatches = function ( + other, + mismatchKeys, + mismatchValues, +) { mismatchKeys = mismatchKeys || []; mismatchValues = mismatchValues || []; var env = jasmine.getEnv(); - var hasKey = function(obj, keyName) { + var hasKey = function (obj, keyName) { return obj != null && obj[keyName] !== jasmine.undefined; }; for (var property in this.sample) { if (!hasKey(other, property) && hasKey(this.sample, property)) { - mismatchKeys.push("expected has key '" + property + "', but missing from actual."); - } - else if (!env.equals_(this.sample[property], other[property], mismatchKeys, mismatchValues)) { - mismatchValues.push("'" + property + "' was '" + (other[property] ? jasmine.util.htmlEscape(other[property].toString()) : other[property]) + "' in expected, but was '" + (this.sample[property] ? jasmine.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + "' in actual."); + mismatchKeys.push( + "expected has key '" + property + "', but missing from actual.", + ); + } else if ( + !env.equals_( + this.sample[property], + other[property], + mismatchKeys, + mismatchValues, + ) + ) { + mismatchValues.push( + "'" + + property + + "' was '" + + (other[property] + ? jasmine.util.htmlEscape(other[property].toString()) + : other[property]) + + "' in expected, but was '" + + (this.sample[property] + ? jasmine.util.htmlEscape(this.sample[property].toString()) + : this.sample[property]) + + "' in actual.", + ); } } - return (mismatchKeys.length === 0 && mismatchValues.length === 0); + return mismatchKeys.length === 0 && mismatchValues.length === 0; }; jasmine.Matchers.ObjectContaining.prototype.jasmineToString = function () { - return ""; + return ''; }; // Mock setTimeout, clearTimeout // Contributed by Pivotal Computer Systems, www.pivotalsf.com -jasmine.FakeTimer = function() { +jasmine.FakeTimer = function () { this.reset(); var self = this; - self.setTimeout = function(funcToCall, millis) { + self.setTimeout = function (funcToCall, millis) { self.timeoutsMade++; self.scheduleFunction(self.timeoutsMade, funcToCall, millis, false); return self.timeoutsMade; }; - self.setInterval = function(funcToCall, millis) { + self.setInterval = function (funcToCall, millis) { self.timeoutsMade++; self.scheduleFunction(self.timeoutsMade, funcToCall, millis, true); return self.timeoutsMade; }; - self.clearTimeout = function(timeoutKey) { + self.clearTimeout = function (timeoutKey) { self.scheduledFunctions[timeoutKey] = jasmine.undefined; }; - self.clearInterval = function(timeoutKey) { + self.clearInterval = function (timeoutKey) { self.scheduledFunctions[timeoutKey] = jasmine.undefined; }; - }; -jasmine.FakeTimer.prototype.reset = function() { +jasmine.FakeTimer.prototype.reset = function () { this.timeoutsMade = 0; this.scheduledFunctions = {}; this.nowMillis = 0; }; -jasmine.FakeTimer.prototype.tick = function(millis) { +jasmine.FakeTimer.prototype.tick = function (millis) { var oldMillis = this.nowMillis; var newMillis = oldMillis + millis; this.runFunctionsWithinRange(oldMillis, newMillis); this.nowMillis = newMillis; }; -jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMillis) { +jasmine.FakeTimer.prototype.runFunctionsWithinRange = function ( + oldMillis, + nowMillis, +) { var scheduledFunc; var funcsToRun = []; for (var timeoutKey in this.scheduledFunctions) { scheduledFunc = this.scheduledFunctions[timeoutKey]; - if (scheduledFunc != jasmine.undefined && - scheduledFunc.runAtMillis >= oldMillis && - scheduledFunc.runAtMillis <= nowMillis) { + if ( + scheduledFunc != jasmine.undefined && + scheduledFunc.runAtMillis >= oldMillis && + scheduledFunc.runAtMillis <= nowMillis + ) { funcsToRun.push(scheduledFunc); this.scheduledFunctions[timeoutKey] = jasmine.undefined; } } if (funcsToRun.length > 0) { - funcsToRun.sort(function(a, b) { + funcsToRun.sort(function (a, b) { return a.runAtMillis - b.runAtMillis; }); for (var i = 0; i < funcsToRun.length; ++i) { @@ -1639,25 +1783,31 @@ jasmine.FakeTimer.prototype.runFunctionsWithinRange = function(oldMillis, nowMil this.nowMillis = funcToRun.runAtMillis; funcToRun.funcToCall(); if (funcToRun.recurring) { - this.scheduleFunction(funcToRun.timeoutKey, - funcToRun.funcToCall, - funcToRun.millis, - true); + this.scheduleFunction( + funcToRun.timeoutKey, + funcToRun.funcToCall, + funcToRun.millis, + true, + ); } - } catch(e) { - } + } catch (e) {} } this.runFunctionsWithinRange(oldMillis, nowMillis); } }; -jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, millis, recurring) { +jasmine.FakeTimer.prototype.scheduleFunction = function ( + timeoutKey, + funcToCall, + millis, + recurring, +) { this.scheduledFunctions[timeoutKey] = { runAtMillis: this.nowMillis + millis, funcToCall: funcToCall, recurring: recurring, timeoutKey: timeoutKey, - millis: millis + millis: millis, }; }; @@ -1667,25 +1817,33 @@ jasmine.FakeTimer.prototype.scheduleFunction = function(timeoutKey, funcToCall, jasmine.Clock = { defaultFakeTimer: new jasmine.FakeTimer(), - reset: function() { + reset: function () { jasmine.Clock.assertInstalled(); jasmine.Clock.defaultFakeTimer.reset(); }, - tick: function(millis) { + tick: function (millis) { jasmine.Clock.assertInstalled(); jasmine.Clock.defaultFakeTimer.tick(millis); }, - runFunctionsWithinRange: function(oldMillis, nowMillis) { - jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange(oldMillis, nowMillis); + runFunctionsWithinRange: function (oldMillis, nowMillis) { + jasmine.Clock.defaultFakeTimer.runFunctionsWithinRange( + oldMillis, + nowMillis, + ); }, - scheduleFunction: function(timeoutKey, funcToCall, millis, recurring) { - jasmine.Clock.defaultFakeTimer.scheduleFunction(timeoutKey, funcToCall, millis, recurring); + scheduleFunction: function (timeoutKey, funcToCall, millis, recurring) { + jasmine.Clock.defaultFakeTimer.scheduleFunction( + timeoutKey, + funcToCall, + millis, + recurring, + ); }, - useMock: function() { + useMock: function () { if (!jasmine.Clock.isInstalled()) { var spec = jasmine.getEnv().currentSpec; spec.after(jasmine.Clock.uninstallMock); @@ -1694,11 +1852,11 @@ jasmine.Clock = { } }, - installMock: function() { + installMock: function () { jasmine.Clock.installed = jasmine.Clock.defaultFakeTimer; }, - uninstallMock: function() { + uninstallMock: function () { jasmine.Clock.assertInstalled(); jasmine.Clock.installed = jasmine.Clock.real; }, @@ -1707,25 +1865,27 @@ jasmine.Clock = { setTimeout: jasmine.getGlobal().setTimeout, clearTimeout: jasmine.getGlobal().clearTimeout, setInterval: jasmine.getGlobal().setInterval, - clearInterval: jasmine.getGlobal().clearInterval + clearInterval: jasmine.getGlobal().clearInterval, }, - assertInstalled: function() { + assertInstalled: function () { if (!jasmine.Clock.isInstalled()) { - throw new Error("Mock clock is not installed, use jasmine.Clock.useMock()"); + throw new Error( + 'Mock clock is not installed, use jasmine.Clock.useMock()', + ); } }, - isInstalled: function() { + isInstalled: function () { return jasmine.Clock.installed == jasmine.Clock.defaultFakeTimer; }, - installed: null + installed: null, }; jasmine.Clock.installed = jasmine.Clock.real; //else for IE support -jasmine.getGlobal().setTimeout = function(funcToCall, millis) { +jasmine.getGlobal().setTimeout = function (funcToCall, millis) { if (jasmine.Clock.installed.setTimeout.apply) { return jasmine.Clock.installed.setTimeout.apply(this, arguments); } else { @@ -1733,7 +1893,7 @@ jasmine.getGlobal().setTimeout = function(funcToCall, millis) { } }; -jasmine.getGlobal().setInterval = function(funcToCall, millis) { +jasmine.getGlobal().setInterval = function (funcToCall, millis) { if (jasmine.Clock.installed.setInterval.apply) { return jasmine.Clock.installed.setInterval.apply(this, arguments); } else { @@ -1741,7 +1901,7 @@ jasmine.getGlobal().setInterval = function(funcToCall, millis) { } }; -jasmine.getGlobal().clearTimeout = function(timeoutKey) { +jasmine.getGlobal().clearTimeout = function (timeoutKey) { if (jasmine.Clock.installed.clearTimeout.apply) { return jasmine.Clock.installed.clearTimeout.apply(this, arguments); } else { @@ -1749,7 +1909,7 @@ jasmine.getGlobal().clearTimeout = function(timeoutKey) { } }; -jasmine.getGlobal().clearInterval = function(timeoutKey) { +jasmine.getGlobal().clearInterval = function (timeoutKey) { if (jasmine.Clock.installed.clearTimeout.apply) { return jasmine.Clock.installed.clearInterval.apply(this, arguments); } else { @@ -1760,28 +1920,28 @@ jasmine.getGlobal().clearInterval = function(timeoutKey) { /** * @constructor */ -jasmine.MultiReporter = function() { +jasmine.MultiReporter = function () { this.subReporters_ = []; }; jasmine.util.inherit(jasmine.MultiReporter, jasmine.Reporter); -jasmine.MultiReporter.prototype.addReporter = function(reporter) { +jasmine.MultiReporter.prototype.addReporter = function (reporter) { this.subReporters_.push(reporter); }; -(function() { +(function () { var functionNames = [ - "reportRunnerStarting", - "reportRunnerResults", - "reportSuiteResults", - "reportSpecStarting", - "reportSpecResults", - "log" + 'reportRunnerStarting', + 'reportRunnerResults', + 'reportSuiteResults', + 'reportSpecStarting', + 'reportSpecResults', + 'log', ]; for (var i = 0; i < functionNames.length; i++) { var functionName = functionNames[i]; - jasmine.MultiReporter.prototype[functionName] = (function(functionName) { - return function() { + jasmine.MultiReporter.prototype[functionName] = (function (functionName) { + return function () { for (var j = 0; j < this.subReporters_.length; j++) { var subReporter = this.subReporters_[j]; if (subReporter[functionName]) { @@ -1797,7 +1957,7 @@ jasmine.MultiReporter.prototype.addReporter = function(reporter) { * * @constructor */ -jasmine.NestedResults = function() { +jasmine.NestedResults = function () { /** * The total count of results */ @@ -1825,7 +1985,7 @@ jasmine.NestedResults = function() { * * @param result */ -jasmine.NestedResults.prototype.rollupCounts = function(result) { +jasmine.NestedResults.prototype.rollupCounts = function (result) { this.totalCount += result.totalCount; this.passedCount += result.passedCount; this.failedCount += result.failedCount; @@ -1835,14 +1995,14 @@ jasmine.NestedResults.prototype.rollupCounts = function(result) { * Adds a log message. * @param values Array of message parts which will be concatenated later. */ -jasmine.NestedResults.prototype.log = function(values) { +jasmine.NestedResults.prototype.log = function (values) { this.items_.push(new jasmine.MessageResult(values)); }; /** * Getter for the results: message & results. */ -jasmine.NestedResults.prototype.getItems = function() { +jasmine.NestedResults.prototype.getItems = function () { return this.items_; }; @@ -1850,7 +2010,7 @@ jasmine.NestedResults.prototype.getItems = function() { * Adds a result, tracking counts (total, passed, & failed) * @param {jasmine.ExpectationResult|jasmine.NestedResults} result */ -jasmine.NestedResults.prototype.addResult = function(result) { +jasmine.NestedResults.prototype.addResult = function (result) { if (result.type != 'log') { if (result.items_) { this.rollupCounts(result); @@ -1869,13 +2029,13 @@ jasmine.NestedResults.prototype.addResult = function(result) { /** * @returns {Boolean} True if everything below passed */ -jasmine.NestedResults.prototype.passed = function() { +jasmine.NestedResults.prototype.passed = function () { return this.passedCount === this.totalCount; }; /** * Base class for pretty printing for expectation results. */ -jasmine.PrettyPrinter = function() { +jasmine.PrettyPrinter = function () { this.ppNestLevel_ = 0; }; @@ -1884,7 +2044,7 @@ jasmine.PrettyPrinter = function() { * * @param value */ -jasmine.PrettyPrinter.prototype.format = function(value) { +jasmine.PrettyPrinter.prototype.format = function (value) { this.ppNestLevel_++; try { if (value === jasmine.undefined) { @@ -1898,7 +2058,7 @@ jasmine.PrettyPrinter.prototype.format = function(value) { } else if (typeof value === 'string') { this.emitString(value); } else if (jasmine.isSpy(value)) { - this.emitScalar("spy on " + value.identity); + this.emitScalar('spy on ' + value.identity); } else if (value instanceof RegExp) { this.emitScalar(value.toString()); } else if (typeof value === 'function') { @@ -1908,7 +2068,11 @@ jasmine.PrettyPrinter.prototype.format = function(value) { } else if (value instanceof Date) { this.emitScalar('Date(' + value + ')'); } else if (value.__Jasmine_been_here_before__) { - this.emitScalar(''); + this.emitScalar( + '', + ); } else if (jasmine.isArray_(value) || typeof value == 'object') { value.__Jasmine_been_here_before__ = true; if (jasmine.isArray_(value)) { @@ -1925,38 +2089,43 @@ jasmine.PrettyPrinter.prototype.format = function(value) { } }; -jasmine.PrettyPrinter.prototype.iterateObject = function(obj, fn) { +jasmine.PrettyPrinter.prototype.iterateObject = function (obj, fn) { for (var property in obj) { if (!obj.hasOwnProperty(property)) continue; if (property == '__Jasmine_been_here_before__') continue; - fn(property, obj.__lookupGetter__ ? (obj.__lookupGetter__(property) !== jasmine.undefined && - obj.__lookupGetter__(property) !== null) : false); + fn( + property, + obj.__lookupGetter__ + ? obj.__lookupGetter__(property) !== jasmine.undefined && + obj.__lookupGetter__(property) !== null + : false, + ); } }; -jasmine.PrettyPrinter.prototype.emitArray = jasmine.unimplementedMethod_; -jasmine.PrettyPrinter.prototype.emitObject = jasmine.unimplementedMethod_; -jasmine.PrettyPrinter.prototype.emitScalar = jasmine.unimplementedMethod_; -jasmine.PrettyPrinter.prototype.emitString = jasmine.unimplementedMethod_; +jasmine.Prettyprinter.prototype.emitArray = jasmine.unimplementedMethod_; +jasmine.Prettyprinter.prototype.emitObject = jasmine.unimplementedMethod_; +jasmine.Prettyprinter.prototype.emitScalar = jasmine.unimplementedMethod_; +jasmine.Prettyprinter.prototype.emitString = jasmine.unimplementedMethod_; -jasmine.StringPrettyPrinter = function() { - jasmine.PrettyPrinter.call(this); +jasmine.StringPrettyPrinter = function () { + jasmine.Prettyprinter.call(this); this.string = ''; }; -jasmine.util.inherit(jasmine.StringPrettyPrinter, jasmine.PrettyPrinter); +jasmine.util.inherit(jasmine.StringPrettyprinter, jasmine.PrettyPrinter); -jasmine.StringPrettyPrinter.prototype.emitScalar = function(value) { +jasmine.StringPrettyPrinter.prototype.emitScalar = function (value) { this.append(value); }; -jasmine.StringPrettyPrinter.prototype.emitString = function(value) { +jasmine.StringPrettyPrinter.prototype.emitString = function (value) { this.append("'" + value + "'"); }; -jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { +jasmine.StringPrettyPrinter.prototype.emitArray = function (array) { if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) { - this.append("Array"); + this.append('Array'); return; } @@ -1970,9 +2139,9 @@ jasmine.StringPrettyPrinter.prototype.emitArray = function(array) { this.append(' ]'); }; -jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { +jasmine.StringPrettyPrinter.prototype.emitObject = function (obj) { if (this.ppNestLevel_ > jasmine.MAX_PRETTY_PRINT_DEPTH) { - this.append("Object"); + this.append('Object'); return; } @@ -1980,7 +2149,7 @@ jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { this.append('{ '); var first = true; - this.iterateObject(obj, function(property, isGetter) { + this.iterateObject(obj, function (property, isGetter) { if (first) { first = false; } else { @@ -1999,10 +2168,10 @@ jasmine.StringPrettyPrinter.prototype.emitObject = function(obj) { this.append(' }'); }; -jasmine.StringPrettyPrinter.prototype.append = function(value) { +jasmine.StringPrettyPrinter.prototype.append = function (value) { this.string += value; }; -jasmine.Queue = function(env) { +jasmine.Queue = function (env) { this.env = env; // parallel to blocks. each true value in this array means the block will @@ -2015,7 +2184,7 @@ jasmine.Queue = function(env) { this.abort = false; }; -jasmine.Queue.prototype.addBefore = function(block, ensure) { +jasmine.Queue.prototype.addBefore = function (block, ensure) { if (ensure === jasmine.undefined) { ensure = false; } @@ -2024,7 +2193,7 @@ jasmine.Queue.prototype.addBefore = function(block, ensure) { this.ensured.unshift(ensure); }; -jasmine.Queue.prototype.add = function(block, ensure) { +jasmine.Queue.prototype.add = function (block, ensure) { if (ensure === jasmine.undefined) { ensure = false; } @@ -2033,36 +2202,39 @@ jasmine.Queue.prototype.add = function(block, ensure) { this.ensured.push(ensure); }; -jasmine.Queue.prototype.insertNext = function(block, ensure) { +jasmine.Queue.prototype.insertNext = function (block, ensure) { if (ensure === jasmine.undefined) { ensure = false; } - this.ensured.splice((this.index + this.offset + 1), 0, ensure); - this.blocks.splice((this.index + this.offset + 1), 0, block); + this.ensured.splice(this.index + this.offset + 1, 0, ensure); + this.blocks.splice(this.index + this.offset + 1, 0, block); this.offset++; }; -jasmine.Queue.prototype.start = function(onComplete) { +jasmine.Queue.prototype.start = function (onComplete) { this.running = true; this.onComplete = onComplete; this.next_(); }; -jasmine.Queue.prototype.isRunning = function() { +jasmine.Queue.prototype.isRunning = function () { return this.running; }; jasmine.Queue.LOOP_DONT_RECURSE = true; -jasmine.Queue.prototype.next_ = function() { +jasmine.Queue.prototype.next_ = function () { var self = this; var goAgain = true; while (goAgain) { goAgain = false; - - if (self.index < self.blocks.length && !(this.abort && !this.ensured[self.index])) { + + if ( + self.index < self.blocks.length && + !(this.abort && !this.ensured[self.index]) + ) { var calledSynchronously = true; var completedSynchronously = false; @@ -2080,9 +2252,12 @@ jasmine.Queue.prototype.next_ = function() { self.index++; var now = new Date().getTime(); - if (self.env.updateInterval && now - self.env.lastUpdate > self.env.updateInterval) { + if ( + self.env.updateInterval && + now - self.env.lastUpdate > self.env.updateInterval + ) { self.env.lastUpdate = now; - self.env.setTimeout(function() { + self.env.setTimeout(function () { self.next_(); }, 0); } else { @@ -2099,7 +2274,6 @@ jasmine.Queue.prototype.next_ = function() { if (completedSynchronously) { onComplete(); } - } else { self.running = false; if (self.onComplete) { @@ -2109,7 +2283,7 @@ jasmine.Queue.prototype.next_ = function() { } }; -jasmine.Queue.prototype.results = function() { +jasmine.Queue.prototype.results = function () { var results = new jasmine.NestedResults(); for (var i = 0; i < this.blocks.length; i++) { if (this.blocks[i].results) { @@ -2119,14 +2293,13 @@ jasmine.Queue.prototype.results = function() { return results; }; - /** * Runner * * @constructor * @param {jasmine.Env} env */ -jasmine.Runner = function(env) { +jasmine.Runner = function (env) { var self = this; self.env = env; self.queue = new jasmine.Queue(env); @@ -2135,7 +2308,7 @@ jasmine.Runner = function(env) { self.suites_ = []; }; -jasmine.Runner.prototype.execute = function() { +jasmine.Runner.prototype.execute = function () { var self = this; if (self.env.reporter.reportRunnerStarting) { self.env.reporter.reportRunnerStarting(this); @@ -2145,26 +2318,25 @@ jasmine.Runner.prototype.execute = function() { }); }; -jasmine.Runner.prototype.beforeEach = function(beforeEachFunction) { +jasmine.Runner.prototype.beforeEach = function (beforeEachFunction) { beforeEachFunction.typeName = 'beforeEach'; - this.before_.splice(0,0,beforeEachFunction); + this.before_.splice(0, 0, beforeEachFunction); }; -jasmine.Runner.prototype.afterEach = function(afterEachFunction) { +jasmine.Runner.prototype.afterEach = function (afterEachFunction) { afterEachFunction.typeName = 'afterEach'; - this.after_.splice(0,0,afterEachFunction); + this.after_.splice(0, 0, afterEachFunction); }; - -jasmine.Runner.prototype.finishCallback = function() { +jasmine.Runner.prototype.finishCallback = function () { this.env.reporter.reportRunnerResults(this); }; -jasmine.Runner.prototype.addSuite = function(suite) { +jasmine.Runner.prototype.addSuite = function (suite) { this.suites_.push(suite); }; -jasmine.Runner.prototype.add = function(block) { +jasmine.Runner.prototype.add = function (block) { if (block instanceof jasmine.Suite) { this.addSuite(block); } @@ -2180,11 +2352,11 @@ jasmine.Runner.prototype.specs = function () { return specs; }; -jasmine.Runner.prototype.suites = function() { +jasmine.Runner.prototype.suites = function () { return this.suites_; }; -jasmine.Runner.prototype.topLevelSuites = function() { +jasmine.Runner.prototype.topLevelSuites = function () { var topLevelSuites = []; for (var i = 0; i < this.suites_.length; i++) { if (!this.suites_[i].parentSuite) { @@ -2194,7 +2366,7 @@ jasmine.Runner.prototype.topLevelSuites = function() { return topLevelSuites; }; -jasmine.Runner.prototype.results = function() { +jasmine.Runner.prototype.results = function () { return this.queue.results(); }; /** @@ -2205,7 +2377,7 @@ jasmine.Runner.prototype.results = function() { * @param {jasmine.Suite} suite * @param {String} description */ -jasmine.Spec = function(env, suite, description) { +jasmine.Spec = function (env, suite, description) { if (!env) { throw new Error('jasmine.Env() required'); } @@ -2227,12 +2399,11 @@ jasmine.Spec = function(env, suite, description) { spec.matchersClass = null; }; -jasmine.Spec.prototype.getFullName = function() { +jasmine.Spec.prototype.getFullName = function () { return this.suite.getFullName() + ' ' + this.description + '.'; }; - -jasmine.Spec.prototype.results = function() { +jasmine.Spec.prototype.results = function () { return this.results_; }; @@ -2241,7 +2412,7 @@ jasmine.Spec.prototype.results = function() { * * Be careful not to leave calls to jasmine.log in production code. */ -jasmine.Spec.prototype.log = function() { +jasmine.Spec.prototype.log = function () { return this.results_.log(arguments); }; @@ -2262,11 +2433,11 @@ jasmine.Spec.prototype.addToQueue = function (block) { /** * @param {jasmine.ExpectationResult} result */ -jasmine.Spec.prototype.addMatcherResult = function(result) { +jasmine.Spec.prototype.addMatcherResult = function (result) { this.results_.addResult(result); }; -jasmine.Spec.prototype.expect = function(actual) { +jasmine.Spec.prototype.expect = function (actual) { var positive = new (this.getMatchersClass_())(this.env, actual, this); positive.not = new (this.getMatchersClass_())(this.env, actual, this, true); return positive; @@ -2278,7 +2449,7 @@ jasmine.Spec.prototype.expect = function(actual) { * @deprecated Use waitsFor() instead * @param {Number} timeout milliseconds to wait */ -jasmine.Spec.prototype.waits = function(timeout) { +jasmine.Spec.prototype.waits = function (timeout) { var waitsFunc = new jasmine.WaitsBlock(this.env, timeout, this); this.addToQueue(waitsFunc); return this; @@ -2291,7 +2462,11 @@ jasmine.Spec.prototype.waits = function(timeout) { * @param {String} optional_timeoutMessage * @param {Number} optional_timeout */ -jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessage, optional_timeout) { +jasmine.Spec.prototype.waitsFor = function ( + latchFunction, + optional_timeoutMessage, + optional_timeout, +) { var latchFunction_ = null; var optional_timeoutMessage_ = null; var optional_timeout_ = null; @@ -2311,7 +2486,13 @@ jasmine.Spec.prototype.waitsFor = function(latchFunction, optional_timeoutMessag } } - var waitsForFunc = new jasmine.WaitsForBlock(this.env, optional_timeout_, latchFunction_, optional_timeoutMessage_, this); + var waitsForFunc = new jasmine.WaitsForBlock( + this.env, + optional_timeout_, + latchFunction_, + optional_timeoutMessage_, + this, + ); this.addToQueue(waitsForFunc); return this; }; @@ -2320,18 +2501,18 @@ jasmine.Spec.prototype.fail = function (e) { var expectationResult = new jasmine.ExpectationResult({ passed: false, message: e ? jasmine.util.formatException(e) : 'Exception', - trace: { stack: e.stack } + trace: { stack: e.stack }, }); this.results_.addResult(expectationResult); }; -jasmine.Spec.prototype.getMatchersClass_ = function() { +jasmine.Spec.prototype.getMatchersClass_ = function () { return this.matchersClass || this.env.matchersClass; }; -jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { +jasmine.Spec.prototype.addMatchers = function (matchersPrototype) { var parent = this.getMatchersClass_(); - var newMatchersClass = function() { + var newMatchersClass = function () { parent.apply(this, arguments); }; jasmine.util.inherit(newMatchersClass, parent); @@ -2339,11 +2520,11 @@ jasmine.Spec.prototype.addMatchers = function(matchersPrototype) { this.matchersClass = newMatchersClass; }; -jasmine.Spec.prototype.finishCallback = function() { +jasmine.Spec.prototype.finishCallback = function () { this.env.reporter.reportSpecResults(this); }; -jasmine.Spec.prototype.finish = function(onComplete) { +jasmine.Spec.prototype.finish = function (onComplete) { this.removeAllSpies(); this.finishCallback(); if (onComplete) { @@ -2351,7 +2532,7 @@ jasmine.Spec.prototype.finish = function(onComplete) { } }; -jasmine.Spec.prototype.after = function(doAfter) { +jasmine.Spec.prototype.after = function (doAfter) { if (this.queue.isRunning()) { this.queue.add(new jasmine.Block(this.env, doAfter, this), true); } else { @@ -2359,7 +2540,7 @@ jasmine.Spec.prototype.after = function(doAfter) { } }; -jasmine.Spec.prototype.execute = function(onComplete) { +jasmine.Spec.prototype.execute = function (onComplete) { var spec = this; if (!spec.env.specFilter(spec)) { spec.results_.skipped = true; @@ -2378,7 +2559,7 @@ jasmine.Spec.prototype.execute = function(onComplete) { }); }; -jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { +jasmine.Spec.prototype.addBeforesAndAftersToQueue = function () { var runner = this.env.currentRunner(); var i; @@ -2391,7 +2572,10 @@ jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { this.queue.addBefore(new jasmine.Block(this.env, runner.before_[i], this)); } for (i = 0; i < this.afterCallbacks.length; i++) { - this.queue.add(new jasmine.Block(this.env, this.afterCallbacks[i], this), true); + this.queue.add( + new jasmine.Block(this.env, this.afterCallbacks[i], this), + true, + ); } for (suite = this.suite; suite; suite = suite.parentSuite) { for (i = 0; i < suite.after_.length; i++) { @@ -2403,13 +2587,17 @@ jasmine.Spec.prototype.addBeforesAndAftersToQueue = function() { } }; -jasmine.Spec.prototype.explodes = function() { +jasmine.Spec.prototype.explodes = function () { throw 'explodes function should not have been called'; }; -jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist) { +jasmine.Spec.prototype.spyOn = function ( + obj, + methodName, + ignoreMethodDoesntExist, +) { if (obj == jasmine.undefined) { - throw "spyOn could not find an object to spy upon for " + methodName + "()"; + throw 'spyOn could not find an object to spy upon for ' + methodName + '()'; } if (!ignoreMethodDoesntExist && obj[methodName] === jasmine.undefined) { @@ -2432,7 +2620,7 @@ jasmine.Spec.prototype.spyOn = function(obj, methodName, ignoreMethodDoesntExist return spyObj; }; -jasmine.Spec.prototype.removeAllSpies = function() { +jasmine.Spec.prototype.removeAllSpies = function () { for (var i = 0; i < this.spies_.length; i++) { var spy = this.spies_[i]; spy.baseObj[spy.methodName] = spy.originalValue; @@ -2449,7 +2637,7 @@ jasmine.Spec.prototype.removeAllSpies = function() { * @param {Function} specDefinitions * @param {jasmine.Suite} parentSuite */ -jasmine.Suite = function(env, description, specDefinitions, parentSuite) { +jasmine.Suite = function (env, description, specDefinitions, parentSuite) { var self = this; self.id = env.nextSuiteId ? env.nextSuiteId() : null; self.description = description; @@ -2463,37 +2651,41 @@ jasmine.Suite = function(env, description, specDefinitions, parentSuite) { self.specs_ = []; }; -jasmine.Suite.prototype.getFullName = function() { +jasmine.Suite.prototype.getFullName = function () { var fullName = this.description; - for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { + for ( + var parentSuite = this.parentSuite; + parentSuite; + parentSuite = parentSuite.parentSuite + ) { fullName = parentSuite.description + ' ' + fullName; } return fullName; }; -jasmine.Suite.prototype.finish = function(onComplete) { +jasmine.Suite.prototype.finish = function (onComplete) { this.env.reporter.reportSuiteResults(this); this.finished = true; - if (typeof(onComplete) == 'function') { + if (typeof onComplete == 'function') { onComplete(); } }; -jasmine.Suite.prototype.beforeEach = function(beforeEachFunction) { +jasmine.Suite.prototype.beforeEach = function (beforeEachFunction) { beforeEachFunction.typeName = 'beforeEach'; this.before_.unshift(beforeEachFunction); }; -jasmine.Suite.prototype.afterEach = function(afterEachFunction) { +jasmine.Suite.prototype.afterEach = function (afterEachFunction) { afterEachFunction.typeName = 'afterEach'; this.after_.unshift(afterEachFunction); }; -jasmine.Suite.prototype.results = function() { +jasmine.Suite.prototype.results = function () { return this.queue.results(); }; -jasmine.Suite.prototype.add = function(suiteOrSpec) { +jasmine.Suite.prototype.add = function (suiteOrSpec) { this.children_.push(suiteOrSpec); if (suiteOrSpec instanceof jasmine.Suite) { this.suites_.push(suiteOrSpec); @@ -2504,25 +2696,25 @@ jasmine.Suite.prototype.add = function(suiteOrSpec) { this.queue.add(suiteOrSpec); }; -jasmine.Suite.prototype.specs = function() { +jasmine.Suite.prototype.specs = function () { return this.specs_; }; -jasmine.Suite.prototype.suites = function() { +jasmine.Suite.prototype.suites = function () { return this.suites_; }; -jasmine.Suite.prototype.children = function() { +jasmine.Suite.prototype.children = function () { return this.children_; }; -jasmine.Suite.prototype.execute = function(onComplete) { +jasmine.Suite.prototype.execute = function (onComplete) { var self = this; this.queue.start(function () { self.finish(onComplete); }); }; -jasmine.WaitsBlock = function(env, timeout, spec) { +jasmine.WaitsBlock = function (env, timeout, spec) { this.timeout = timeout; jasmine.Block.call(this, env, null, spec); }; @@ -2548,7 +2740,7 @@ jasmine.WaitsBlock.prototype.execute = function (onComplete) { * @param {String} message The message to display if the desired condition hasn't been met within the given time period. * @param {jasmine.Spec} spec The Jasmine spec. */ -jasmine.WaitsForBlock = function(env, timeout, latchFunction, message, spec) { +jasmine.WaitsForBlock = function (env, timeout, latchFunction, message, spec) { this.timeout = timeout || env.defaultTimeoutInterval; this.latchFunction = latchFunction; this.message = message; @@ -2559,9 +2751,11 @@ jasmine.util.inherit(jasmine.WaitsForBlock, jasmine.Block); jasmine.WaitsForBlock.TIMEOUT_INCREMENT = 10; -jasmine.WaitsForBlock.prototype.execute = function(onComplete) { +jasmine.WaitsForBlock.prototype.execute = function (onComplete) { if (jasmine.VERBOSE) { - this.env.reporter.log('>> Jasmine waiting for ' + (this.message || 'something to happen')); + this.env.reporter.log( + '>> Jasmine waiting for ' + (this.message || 'something to happen'), + ); } var latchFunctionResult; try { @@ -2575,26 +2769,31 @@ jasmine.WaitsForBlock.prototype.execute = function(onComplete) { if (latchFunctionResult) { onComplete(); } else if (this.totalTimeSpentWaitingForLatch >= this.timeout) { - var message = 'timed out after ' + this.timeout + ' msec waiting for ' + (this.message || 'something to happen'); + var message = + 'timed out after ' + + this.timeout + + ' msec waiting for ' + + (this.message || 'something to happen'); this.spec.fail({ name: 'timeout', - message: message + message: message, }); this.abort = true; onComplete(); } else { - this.totalTimeSpentWaitingForLatch += jasmine.WaitsForBlock.TIMEOUT_INCREMENT; + this.totalTimeSpentWaitingForLatch += + jasmine.WaitsForBlock.TIMEOUT_INCREMENT; var self = this; - this.env.setTimeout(function() { + this.env.setTimeout(function () { self.execute(onComplete); }, jasmine.WaitsForBlock.TIMEOUT_INCREMENT); } }; -jasmine.version_= { - "major": 1, - "minor": 3, - "build": 1, - "revision": 1354556913 +jasmine.version_ = { + major: 1, + minor: 3, + build: 1, + revision: 1354556913, }; diff --git a/res/benchmarks/binary_trees.locks b/res/benchmarks/binary_trees.locks index 2d31455..a1e643e 100644 --- a/res/benchmarks/binary_trees.locks +++ b/res/benchmarks/binary_trees.locks @@ -28,10 +28,10 @@ let stretchDepth = maxDepth + 1; let start = clock(); -print "stretch tree of depth:"; -print stretchDepth; -print "check:"; -print Tree(0, stretchDepth).check(); +println("stretch tree of depth:"); +println(stretchDepth); +println("check:"); +println(Tree(0, stretchDepth).check()); let longLivedTree = Tree(0, maxDepth); @@ -52,20 +52,20 @@ while (depth < stretchDepth) { i = i + 1; } - print "num trees:"; - print iterations * 2; - print "depth:"; - print depth; - print "check:"; - print check; + println("num trees:"); + println(iterations * 2); + println("depth:"); + println(depth); + println("check:"); + println(check); iterations = iterations / 4; depth = depth + 2; } -print "long lived tree of depth:"; -print maxDepth; -print "check:"; -print longLivedTree.check(); -print "elapsed:"; -print clock() - start; +println("long lived tree of depth:"); +println(maxDepth); +println("check:"); +println(longLivedTree.check()); +println("elapsed:"); +println(clock() - start); diff --git a/res/benchmarks/equality.locks b/res/benchmarks/equality.locks index 97db316..2592236 100644 --- a/res/benchmarks/equality.locks +++ b/res/benchmarks/equality.locks @@ -26,9 +26,9 @@ while (i < 50000000) { } let elapsed = clock() - start; -print "loop"; -print loopTime; -print "elapsed"; -print elapsed; -print "equals"; -print elapsed - loopTime; +println("loop"); +println(loopTime); +println("elapsed"); +println(elapsed); +println("equals"); +println(elapsed - loopTime); diff --git a/res/benchmarks/fib.locks b/res/benchmarks/fib.locks index 573ab08..e9e4303 100644 --- a/res/benchmarks/fib.locks +++ b/res/benchmarks/fib.locks @@ -4,5 +4,5 @@ fn fib(n) { } let start = clock(); -print fib(39) == 63245986; -print clock() - start; +println(fib(39) == 63245986); +println(clock() - start); diff --git a/res/benchmarks/instantiation.locks b/res/benchmarks/instantiation.locks index d54fa13..7066925 100644 --- a/res/benchmarks/instantiation.locks +++ b/res/benchmarks/instantiation.locks @@ -40,4 +40,4 @@ while (i < 8000000) { i = i + 1; } -print clock() - start; +println(clock() - start); diff --git a/res/benchmarks/invocation.locks b/res/benchmarks/invocation.locks index 596727e..a5cf12b 100644 --- a/res/benchmarks/invocation.locks +++ b/res/benchmarks/invocation.locks @@ -70,4 +70,4 @@ while (i < 9000000) { i = i + 1; } -print clock() - start; +println(clock() - start); diff --git a/res/benchmarks/method_call.locks b/res/benchmarks/method_call.locks index 304dde8..f0e63b7 100644 --- a/res/benchmarks/method_call.locks +++ b/res/benchmarks/method_call.locks @@ -47,7 +47,7 @@ for (let i = 0; i < n; i = i + 1) { val = toggle.activate().value(); } -print toggle.value(); +println(toggle.value()); val = true; let ntoggle = NthToggle(val, 3); @@ -65,5 +65,5 @@ for (let i = 0; i < n; i = i + 1) { val = ntoggle.activate().value(); } -print ntoggle.value(); -print clock() - start; +println(ntoggle.value()); +println(clock() - start); diff --git a/res/benchmarks/properties.locks b/res/benchmarks/properties.locks index 3eba8de..a47f351 100644 --- a/res/benchmarks/properties.locks +++ b/res/benchmarks/properties.locks @@ -103,4 +103,4 @@ while (i < 7000000) { i = i + 1; } -print clock() - start; +println(clock() - start); diff --git a/res/benchmarks/string_equality.locks b/res/benchmarks/string_equality.locks index 5cfaecf..2405f7a 100644 --- a/res/benchmarks/string_equality.locks +++ b/res/benchmarks/string_equality.locks @@ -47,9 +47,9 @@ let start = clock(); equality(); let elapsed = clock() - start; -print "loop"; -print loopTime; -print "elapsed"; -print elapsed; -print "equals"; -print elapsed - loopTime; +println("loop"); +println(loopTime); +println("elapsed"); +println(elapsed); +println("equals"); +println(elapsed - loopTime); diff --git a/res/benchmarks/trees.locks b/res/benchmarks/trees.locks index 5264e19..d82c4b4 100644 --- a/res/benchmarks/trees.locks +++ b/res/benchmarks/trees.locks @@ -24,6 +24,6 @@ class Tree { let tree = Tree(8); let start = clock(); for (let i = 0; i < 300; i = i + 1) { - if (tree.walk() != 122068) print "Error"; + if (tree.walk() != 122068) println("Error"); } -print clock() - start; +println(clock() - start); diff --git a/res/benchmarks/zoo.locks b/res/benchmarks/zoo.locks index 654d3af..bf8cf3c 100644 --- a/res/benchmarks/zoo.locks +++ b/res/benchmarks/zoo.locks @@ -27,5 +27,5 @@ while (sum < 200000000) { + zoo.mouse(); } -print sum; -print clock() - start; +println(sum); +println(clock() - start); diff --git a/res/benchmarks/zoo_batch.locks b/res/benchmarks/zoo_batch.locks index b6ee79b..fb704eb 100644 --- a/res/benchmarks/zoo_batch.locks +++ b/res/benchmarks/zoo_batch.locks @@ -31,6 +31,6 @@ while (clock() - start < 10) { batch = batch + 1; } -print sum; -print batch; -print clock() - start; +println(sum); +println(batch); +println(clock() - start); diff --git a/res/examples/assignment/associativity.locks b/res/examples/assignment/associativity.locks index 1c2e238..64ec4cc 100644 --- a/res/examples/assignment/associativity.locks +++ b/res/examples/assignment/associativity.locks @@ -4,6 +4,6 @@ let c = "c"; // Assignment is right-associative. a = b = c; -print a; // out: c -print b; // out: c -print c; // out: c +println(a); // out: c +println(b); // out: c +println(c); // out: c diff --git a/res/examples/assignment/global.locks b/res/examples/assignment/global.locks index 97546d0..49e5972 100644 --- a/res/examples/assignment/global.locks +++ b/res/examples/assignment/global.locks @@ -1,8 +1,6 @@ let a = "before"; -print a; // out: before +println(a); // out: before a = "after"; -print a; // out: after +println(a); // out: after -print a = "arg"; // out: arg -print a; // out: arg diff --git a/res/examples/assignment/local.locks b/res/examples/assignment/local.locks index e24cf6c..1aa5cbd 100644 --- a/res/examples/assignment/local.locks +++ b/res/examples/assignment/local.locks @@ -1,10 +1,8 @@ { let a = "before"; - print a; // out: before + println(a); // out: before a = "after"; - print a; // out: after + println(a); // out: after - print a = "arg"; // out: arg - print a; // out: arg } diff --git a/res/examples/assignment/syntax.locks b/res/examples/assignment/syntax.locks index 44b7a36..ec2bd41 100644 --- a/res/examples/assignment/syntax.locks +++ b/res/examples/assignment/syntax.locks @@ -1,5 +1,5 @@ // Assignment on RHS of variable. let a = "before"; let c = a = "var"; -print a; // out: var -print c; // out: var +println(a); // out: var +println(c); // out: var diff --git a/res/examples/block/empty.locks b/res/examples/block/empty.locks index 30115d0..d13e7b6 100644 --- a/res/examples/block/empty.locks +++ b/res/examples/block/empty.locks @@ -4,4 +4,4 @@ if (true) {} if (false) {} else {} -print "ok"; // out: ok +println("ok"); // out: ok diff --git a/res/examples/block/scope.locks b/res/examples/block/scope.locks index 7412a49..ac85220 100644 --- a/res/examples/block/scope.locks +++ b/res/examples/block/scope.locks @@ -2,7 +2,7 @@ let a = "outer"; { let a = "inner"; - print a; // out: inner + println(a); // out: inner } -print a; // out: outer +println(a); // out: outer diff --git a/res/examples/bool/equality.locks b/res/examples/bool/equality.locks index cf64f5f..d873c4f 100644 --- a/res/examples/bool/equality.locks +++ b/res/examples/bool/equality.locks @@ -1,23 +1,23 @@ -print true == true; // out: true -print true == false; // out: false -print false == true; // out: false -print false == false; // out: true +println(true == true); // out: true +println(true == false); // out: false +println(false == true); // out: false +println(false == false); // out: true // Not equal to other types. -print true == 1; // out: false -print false == 0; // out: false -print true == "true"; // out: false -print false == "false"; // out: false -print false == ""; // out: false +println(true == 1); // out: false +println(false == 0); // out: false +println(true == "true"); // out: false +println(false == "false"); // out: false +println(false == ""); // out: false -print true != true; // out: false -print true != false; // out: true -print false != true; // out: true -print false != false; // out: false +println(true != true); // out: false +println(true != false); // out: true +println(false != true); // out: true +println(false != false); // out: false // Not equal to other types. -print true != 1; // out: true -print false != 0; // out: true -print true != "true"; // out: true -print false != "false"; // out: true -print false != ""; // out: true +println(true != 1); // out: true +println(false != 0); // out: true +println(true != "true"); // out: true +println(false != "false"); // out: true +println(false != ""); // out: true diff --git a/res/examples/bool/false_length.locks b/res/examples/bool/false_length.locks index 5d62c83..0068fa9 100644 --- a/res/examples/bool/false_length.locks +++ b/res/examples/bool/false_length.locks @@ -1 +1 @@ -print len(false); // out: TypeError: "false" object has no length +println(len(false)); // out: TypeError: "false" object has no length diff --git a/res/examples/bool/not.locks b/res/examples/bool/not.locks index ae217e1..795828b 100644 --- a/res/examples/bool/not.locks +++ b/res/examples/bool/not.locks @@ -1,3 +1,3 @@ -print !true; // out: false -print !false; // out: true -print !!true; // out: true +println(!true); // out: false +println(!false); // out: true +println(!!true); // out: true diff --git a/res/examples/bool/true_length.locks b/res/examples/bool/true_length.locks index 48f84c8..343dadf 100644 --- a/res/examples/bool/true_length.locks +++ b/res/examples/bool/true_length.locks @@ -1 +1 @@ -print len(true); // out: TypeError: "true" object has no length +println(len(true)); // out: TypeError: "true" object has no length diff --git a/res/examples/class/empty.locks b/res/examples/class/empty.locks index 3d75c34..875bf9d 100644 --- a/res/examples/class/empty.locks +++ b/res/examples/class/empty.locks @@ -1,3 +1,3 @@ class Foo {} -print Foo; // out: +println(Foo); // out: diff --git a/res/examples/class/inherited_method.locks b/res/examples/class/inherited_method.locks index d85683d..8ca6426 100644 --- a/res/examples/class/inherited_method.locks +++ b/res/examples/class/inherited_method.locks @@ -1,18 +1,18 @@ class Foo { fn inFoo() { - print "in foo"; + println("in foo"); } } class Bar extends Foo { fn inBar() { - print "in bar"; + println("in bar"); } } class Baz extends Bar { fn inBaz() { - print "in baz"; + println("in baz"); } } diff --git a/res/examples/class/instance_length.locks b/res/examples/class/instance_length.locks index 695175e..584fd3e 100644 --- a/res/examples/class/instance_length.locks +++ b/res/examples/class/instance_length.locks @@ -2,4 +2,4 @@ class Class {} let test = Class(); -print len(test); // out: TypeError: "instance" object has no length +println(len(test)); // out: TypeError: "instance" object has no length diff --git a/res/examples/class/length.locks b/res/examples/class/length.locks index d9e1e67..604dbe1 100644 --- a/res/examples/class/length.locks +++ b/res/examples/class/length.locks @@ -2,4 +2,4 @@ class Class { } -print len(Class); // out: TypeError: "class" object has no length +println(len(Class)); // out: TypeError: "class" object has no length diff --git a/res/examples/class/local_inherit_other.locks b/res/examples/class/local_inherit_other.locks index 59f027f..f611a8b 100644 --- a/res/examples/class/local_inherit_other.locks +++ b/res/examples/class/local_inherit_other.locks @@ -5,4 +5,4 @@ fn f() { return B; } -print f(); // out: +println(f()); // out: diff --git a/res/examples/class/local_reference_self.locks b/res/examples/class/local_reference_self.locks index 7b4cf91..dd572c6 100644 --- a/res/examples/class/local_reference_self.locks +++ b/res/examples/class/local_reference_self.locks @@ -5,5 +5,5 @@ } } - print Foo().returnSelf(); // out: + println(Foo().returnSelf()); // out: } diff --git a/res/examples/class/reference_self.locks b/res/examples/class/reference_self.locks index 24927c9..04bb85e 100644 --- a/res/examples/class/reference_self.locks +++ b/res/examples/class/reference_self.locks @@ -4,4 +4,4 @@ class Foo { } } -print Foo().returnSelf(); // out: +println(Foo().returnSelf()); // out: diff --git a/res/examples/closure/assign_in_block.locks b/res/examples/closure/assign_in_block.locks index 528a0be..f7e1515 100644 --- a/res/examples/closure/assign_in_block.locks +++ b/res/examples/closure/assign_in_block.locks @@ -10,4 +10,4 @@ let function; function = sum; } -print function(5, 8); // out: 23 +println(function(5, 8)); // out: 23 diff --git a/res/examples/closure/assign_to_closure.locks b/res/examples/closure/assign_to_closure.locks index e565d32..e793f31 100644 --- a/res/examples/closure/assign_to_closure.locks +++ b/res/examples/closure/assign_to_closure.locks @@ -4,16 +4,16 @@ let g; { let local = "local"; fn f_() { - print local; + println(local); local = "after f"; - print local; + println(local); } f = f_; fn g_() { - print local; + println(local); local = "after g"; - print local; + println(local); } g = g_; } diff --git a/res/examples/closure/assign_to_shadowed_later.locks b/res/examples/closure/assign_to_shadowed_later.locks index 220ca43..3f69d5a 100644 --- a/res/examples/closure/assign_to_shadowed_later.locks +++ b/res/examples/closure/assign_to_shadowed_later.locks @@ -7,7 +7,7 @@ let a = "global"; let a = "inner"; assign(); - print a; // out: inner + println(a); // out: inner } -print a; // out: assigned +println(a); // out: assigned diff --git a/res/examples/closure/close_over_function_parameter.locks b/res/examples/closure/close_over_function_parameter.locks index a96881c..000e33f 100644 --- a/res/examples/closure/close_over_function_parameter.locks +++ b/res/examples/closure/close_over_function_parameter.locks @@ -2,7 +2,7 @@ let f; fn foo(param) { fn f_() { - print param; + println(param); } f = f_; } diff --git a/res/examples/closure/close_over_later_variable.locks b/res/examples/closure/close_over_later_variable.locks index 7e43a81..566e956 100644 --- a/res/examples/closure/close_over_later_variable.locks +++ b/res/examples/closure/close_over_later_variable.locks @@ -7,8 +7,8 @@ fn f() { let a = "a"; let b = "b"; fn g() { - print b; // out: b - print a; // out: a + println(b); // out: b + println(a); // out: a } g(); } diff --git a/res/examples/closure/close_over_method_parameter.locks b/res/examples/closure/close_over_method_parameter.locks index df4c3ce..6fb4331 100644 --- a/res/examples/closure/close_over_method_parameter.locks +++ b/res/examples/closure/close_over_method_parameter.locks @@ -3,7 +3,7 @@ let f; class Foo { fn method(param) { fn f_() { - print param; + println(param); } f = f_; } diff --git a/res/examples/closure/closed_closure_in_function.locks b/res/examples/closure/closed_closure_in_function.locks index 57c7f14..75a8ca4 100644 --- a/res/examples/closure/closed_closure_in_function.locks +++ b/res/examples/closure/closed_closure_in_function.locks @@ -3,7 +3,7 @@ let f; { let local = "local"; fn f_() { - print local; + println(local); } f = f_; } diff --git a/res/examples/closure/nested_closure.locks b/res/examples/closure/nested_closure.locks index 3bb30d1..6b4bd26 100644 --- a/res/examples/closure/nested_closure.locks +++ b/res/examples/closure/nested_closure.locks @@ -7,9 +7,9 @@ fn f1() { fn f3() { let c = "c"; fn f4() { - print a; - print b; - print c; + println(a); + println(b); + println(c); } f = f4; } diff --git a/res/examples/closure/open_closure_in_function.locks b/res/examples/closure/open_closure_in_function.locks index ab9cc58..ea221b7 100644 --- a/res/examples/closure/open_closure_in_function.locks +++ b/res/examples/closure/open_closure_in_function.locks @@ -1,7 +1,7 @@ { let local = "local"; fn f() { - print local; // out: local + println(local); // out: local } f(); } diff --git a/res/examples/closure/reference_closure_multiple_times.locks b/res/examples/closure/reference_closure_multiple_times.locks index 8765acf..8c75fd0 100644 --- a/res/examples/closure/reference_closure_multiple_times.locks +++ b/res/examples/closure/reference_closure_multiple_times.locks @@ -3,8 +3,8 @@ let f; { let a = "a"; fn f_() { - print a; - print a; + println(a); + println(a); } f = f_; } diff --git a/res/examples/closure/reuse_closure_slot.locks b/res/examples/closure/reuse_closure_slot.locks index 02ece59..6a7b2aa 100644 --- a/res/examples/closure/reuse_closure_slot.locks +++ b/res/examples/closure/reuse_closure_slot.locks @@ -3,7 +3,7 @@ { let a = "a"; - fn f_() { print a; } + fn f_() { println(a); } f = f_; } diff --git a/res/examples/closure/shadow_closure_with_local.locks b/res/examples/closure/shadow_closure_with_local.locks index 4dc2db9..37ef311 100644 --- a/res/examples/closure/shadow_closure_with_local.locks +++ b/res/examples/closure/shadow_closure_with_local.locks @@ -2,11 +2,11 @@ let foo = "closure"; fn f() { { - print foo; // out: closure + println(foo); // out: closure let foo = "shadow"; - print foo; // out: shadow + println(foo); // out: shadow } - print foo; // out: closure + println(foo); // out: closure } f(); } diff --git a/res/examples/closure/unused_closure.locks b/res/examples/closure/unused_closure.locks index 17fe1a6..962cdbe 100644 --- a/res/examples/closure/unused_closure.locks +++ b/res/examples/closure/unused_closure.locks @@ -10,4 +10,4 @@ } // If we get here, we didn't segfault when a went out of scope. -print "ok"; // out: ok +println("ok"); // out: ok diff --git a/res/examples/closure/unused_later_closure.locks b/res/examples/closure/unused_later_closure.locks index dc89023..0997455 100644 --- a/res/examples/closure/unused_later_closure.locks +++ b/res/examples/closure/unused_later_closure.locks @@ -24,5 +24,5 @@ let closure; } } - print closure(); // out: a + println(closure()); // out: a } diff --git a/res/examples/comments/line_at_eof.locks b/res/examples/comments/line_at_eof.locks index f2f5f02..1e3b7f0 100644 --- a/res/examples/comments/line_at_eof.locks +++ b/res/examples/comments/line_at_eof.locks @@ -1,2 +1,2 @@ -print "ok"; // out: ok +println("ok"); // out: ok // comment diff --git a/res/examples/comments/unicode.locks b/res/examples/comments/unicode.locks index 6343a35..7ca1eb6 100644 --- a/res/examples/comments/unicode.locks +++ b/res/examples/comments/unicode.locks @@ -6,4 +6,4 @@ // Other stuff: ឃᢆ᯽₪ℜ↩⊗┺░ // Emoji: ☃☺♣ -print "ok"; // out: ok +println("ok"); // out: ok diff --git a/res/examples/constructor/arguments.locks b/res/examples/constructor/arguments.locks index e139a85..ae14f6e 100644 --- a/res/examples/constructor/arguments.locks +++ b/res/examples/constructor/arguments.locks @@ -1,14 +1,10 @@ class Foo { let a; - let b; - fn init(a, b) { - print "init"; // out: init + fn init(a) { this.a = a; - this.b = b; } } -let foo = Foo(1, 2); -print foo.a; // out: 1 -print foo.b; // out: 2 +let foo = Foo(1); +println(foo.a); // out: 1 diff --git a/res/examples/constructor/call_init_early_return.locks b/res/examples/constructor/call_init_early_return.locks index 9e40484..b21a885 100644 --- a/res/examples/constructor/call_init_early_return.locks +++ b/res/examples/constructor/call_init_early_return.locks @@ -1,11 +1,11 @@ class Foo { fn init() { - print "init"; + println("init"); return; - print "nope"; + println("nope"); } } let foo = Foo(); // out: init -print foo.init(); // out: init +println(foo.init()); // out: init // out: diff --git a/res/examples/constructor/call_init_explicitly.locks b/res/examples/constructor/call_init_explicitly.locks index 383f6a1..9a8cde5 100644 --- a/res/examples/constructor/call_init_explicitly.locks +++ b/res/examples/constructor/call_init_explicitly.locks @@ -2,7 +2,7 @@ class Foo { let field; fn init(arg) { - print "Foo.init(" + arg + ")"; + println("Foo.init(" + arg + ")"); this.field = "init"; } } @@ -11,7 +11,7 @@ let foo = Foo("one"); // out: Foo.init(one) foo.field = "field"; let foo2 = foo.init("two"); // out: Foo.init(two) -print foo2; // out: +println(foo2); // out: // Make sure init() doesn't create a fresh instance. -print foo.field; // out: init +println(foo.field); // out: init diff --git a/res/examples/constructor/default.locks b/res/examples/constructor/default.locks index 3d232c9..618c62c 100644 --- a/res/examples/constructor/default.locks +++ b/res/examples/constructor/default.locks @@ -1,4 +1,4 @@ class Foo {} let foo = Foo(); -print foo; // out: +println(foo); // out: diff --git a/res/examples/constructor/early_return.locks b/res/examples/constructor/early_return.locks index bbea118..fad7f99 100644 --- a/res/examples/constructor/early_return.locks +++ b/res/examples/constructor/early_return.locks @@ -1,10 +1,10 @@ class Foo { fn init() { - print "init"; + println("init"); return; - print "nope"; + println("nope"); } } let foo = Foo(); // out: init -print foo; // out: +println(foo); // out: diff --git a/res/examples/constructor/init_not_method.locks b/res/examples/constructor/init_not_method.locks index c783c12..7ead0f2 100644 --- a/res/examples/constructor/init_not_method.locks +++ b/res/examples/constructor/init_not_method.locks @@ -1,12 +1,12 @@ class Foo { fn init(arg) { - print "Foo.init(" + arg + ")"; + println("Foo.init(" + arg + ")"); this.field = "init"; } } fn init() { - print "not initializer"; + println("not initializer"); } init(); // out: not initializer diff --git a/res/examples/constructor/return_in_nested_function.locks b/res/examples/constructor/return_in_nested_function.locks index 3b0d7b7..ab86644 100644 --- a/res/examples/constructor/return_in_nested_function.locks +++ b/res/examples/constructor/return_in_nested_function.locks @@ -3,8 +3,8 @@ class Foo { fn init() { return "bar"; } - print init(); // out: bar + println(init()); // out: bar } } -print Foo(); // out: +println(Foo()); // out: diff --git a/res/examples/expressions/evaluate.locks b/res/examples/expressions/evaluate.locks index 03ed78b..8d41b61 100644 --- a/res/examples/expressions/evaluate.locks +++ b/res/examples/expressions/evaluate.locks @@ -1,2 +1,2 @@ // out: 2 -print (5 - (3 - 1)) + -1; +println((5 - (3 - 1)) + -1); diff --git a/res/examples/expressions/parse.locks b/res/examples/expressions/parse.locks index 064be7a..675fa96 100644 --- a/res/examples/expressions/parse.locks +++ b/res/examples/expressions/parse.locks @@ -1,2 +1,2 @@ // out: 2 -print (5 - (3 - 1)) + -1; \ No newline at end of file +println((5 - (3 - 1)) + -1); \ No newline at end of file diff --git a/res/examples/field/call_function_field.locks b/res/examples/field/call_function_field.locks index 52c0748..2cb7ff2 100644 --- a/res/examples/field/call_function_field.locks +++ b/res/examples/field/call_function_field.locks @@ -3,9 +3,9 @@ class Foo { } fn bar(a, b) { - print "bar"; - print a; - print b; + println("bar"); + println(a); + println(b); } let foo = Foo(); diff --git a/res/examples/field/default_value.locks b/res/examples/field/default_value.locks index 850f4d0..1765553 100644 --- a/res/examples/field/default_value.locks +++ b/res/examples/field/default_value.locks @@ -4,4 +4,4 @@ class Test { let test = Test(); -print test.value; // out: 123 +println(test.value); // out: 123 diff --git a/res/examples/field/define_field_on_class.locks b/res/examples/field/define_field_on_class.locks index 869bb26..bea2df5 100644 --- a/res/examples/field/define_field_on_class.locks +++ b/res/examples/field/define_field_on_class.locks @@ -12,4 +12,4 @@ class Greeter { let greeter = Greeter("Hello"); -print greeter.greet("World"); // out: Hello World +println(greeter.greet("World")); // out: Hello World diff --git a/res/examples/field/get_and_set_method.locks b/res/examples/field/get_and_set_method.locks index ed8724c..6176b33 100644 --- a/res/examples/field/get_and_set_method.locks +++ b/res/examples/field/get_and_set_method.locks @@ -1,12 +1,12 @@ // Bound methods have identity equality. class Foo { fn method(a) { - print "method"; - print a; + println("method"); + println(a); } fn other(a) { - print "other"; - print a; + println("other"); + println(a); } } diff --git a/res/examples/field/index_access_get_method_on_instance.locks b/res/examples/field/index_access_get_method_on_instance.locks index 06378d5..510f880 100644 --- a/res/examples/field/index_access_get_method_on_instance.locks +++ b/res/examples/field/index_access_get_method_on_instance.locks @@ -12,4 +12,4 @@ class Box { let box = Box(123); -print box["get"](); // out: 123 +println(box["get"]()); // out: 123 diff --git a/res/examples/field/index_access_get_nested.locks b/res/examples/field/index_access_get_nested.locks index aa1fcc1..062d86b 100644 --- a/res/examples/field/index_access_get_nested.locks +++ b/res/examples/field/index_access_get_nested.locks @@ -20,4 +20,4 @@ class Box { let obj = Object(123); -print obj["box"]["get"](); // out: 123 +println(obj["box"]["get"]()); // out: 123 diff --git a/res/examples/field/index_access_get_set_on_super.locks b/res/examples/field/index_access_get_set_on_super.locks index c9e3c71..693f424 100644 --- a/res/examples/field/index_access_get_set_on_super.locks +++ b/res/examples/field/index_access_get_set_on_super.locks @@ -22,4 +22,4 @@ class Child extends Parent { let child = Child(123); -print child.get(); // out: 123 +println(child.get()); // out: 123 diff --git a/res/examples/field/index_access_get_set_on_this.locks b/res/examples/field/index_access_get_set_on_this.locks index d20fa46..9933120 100644 --- a/res/examples/field/index_access_get_set_on_this.locks +++ b/res/examples/field/index_access_get_set_on_this.locks @@ -12,4 +12,4 @@ class Box { let box = Box(123); -print box.get(); // out: 123 +println(box.get()); // out: 123 diff --git a/res/examples/field/index_access_get_undefined.locks b/res/examples/field/index_access_get_undefined.locks index 63fe391..3747a7f 100644 --- a/res/examples/field/index_access_get_undefined.locks +++ b/res/examples/field/index_access_get_undefined.locks @@ -3,4 +3,4 @@ class Object { let obj = Object(); -print obj["key"]; // out: AttributeError: "Object" object has no attribute "key" +println(obj["key"]); // out: AttributeError: "Object" object has no attribute "key" diff --git a/res/examples/field/index_access_with_expr.locks b/res/examples/field/index_access_with_expr.locks index c84f293..0b74313 100644 --- a/res/examples/field/index_access_with_expr.locks +++ b/res/examples/field/index_access_with_expr.locks @@ -5,8 +5,8 @@ class Record { let key = "key"; let record = Record(); -print record[key]; // out: value +println(record[key]); // out: value record[key] = "new value"; -print record[key]; // out: new value +println(record[key]); // out: new value diff --git a/res/examples/field/index_access_with_string.locks b/res/examples/field/index_access_with_string.locks index af20249..310627c 100644 --- a/res/examples/field/index_access_with_string.locks +++ b/res/examples/field/index_access_with_string.locks @@ -4,8 +4,8 @@ class Record { let record = Record(); -print record["key"]; // out: value +println(record["key"]); // out: value record["key"] = "new value"; -print record["key"]; // out: new value +println(record["key"]); // out: new value diff --git a/res/examples/field/local_variable_shadowing_field.locks b/res/examples/field/local_variable_shadowing_field.locks index 98c3be2..c074b41 100644 --- a/res/examples/field/local_variable_shadowing_field.locks +++ b/res/examples/field/local_variable_shadowing_field.locks @@ -3,9 +3,9 @@ class Foo { fn call() { let value = 100; - print value; // out: 100 + println(value); // out: 100 - print this.value; // out: 123 + println(this.value); // out: 123 } } diff --git a/res/examples/field/many.locks b/res/examples/field/many.locks index 3c4eef8..ec3e1b3 100644 --- a/res/examples/field/many.locks +++ b/res/examples/field/many.locks @@ -166,85 +166,85 @@ fn setFields() { setFields(); fn printFields() { - print foo.apple; // out: apple - print foo.apricot; // out: apricot - print foo.avocado; // out: avocado - print foo.banana; // out: banana - print foo.bilberry; // out: bilberry - print foo.blackberry; // out: blackberry - print foo.blackcurrant; // out: blackcurrant - print foo.blueberry; // out: blueberry - print foo.boysenberry; // out: boysenberry - print foo.cantaloupe; // out: cantaloupe - print foo.cherimoya; // out: cherimoya - print foo.cherry; // out: cherry - print foo.clementine; // out: clementine - print foo.cloudberry; // out: cloudberry - print foo.coconut; // out: coconut - print foo.cranberry; // out: cranberry - print foo.currant; // out: currant - print foo.damson; // out: damson - print foo.date; // out: date - print foo.dragonfruit; // out: dragonfruit - print foo.durian; // out: durian - print foo.elderberry; // out: elderberry - print foo.feijoa; // out: feijoa - print foo.fig; // out: fig - print foo.gooseberry; // out: gooseberry - print foo.grape; // out: grape - print foo.grapefruit; // out: grapefruit - print foo.guava; // out: guava - print foo.honeydew; // out: honeydew - print foo.huckleberry; // out: huckleberry - print foo.jabuticaba; // out: jabuticaba - print foo.jackfruit; // out: jackfruit - print foo.jambul; // out: jambul - print foo.jujube; // out: jujube - print foo.juniper; // out: juniper - print foo.kiwifruit; // out: kiwifruit - print foo.kumquat; // out: kumquat - print foo.lemon; // out: lemon - print foo.lime; // out: lime - print foo.longan; // out: longan - print foo.loquat; // out: loquat - print foo.lychee; // out: lychee - print foo.mandarine; // out: mandarine - print foo.mango; // out: mango - print foo.marionberry; // out: marionberry - print foo.melon; // out: melon - print foo.miracle; // out: miracle - print foo.mulberry; // out: mulberry - print foo.nance; // out: nance - print foo.nectarine; // out: nectarine - print foo.olive; // out: olive - print foo.orange; // out: orange - print foo.papaya; // out: papaya - print foo.passionfruit; // out: passionfruit - print foo.peach; // out: peach - print foo.pear; // out: pear - print foo.persimmon; // out: persimmon - print foo.physalis; // out: physalis - print foo.pineapple; // out: pineapple - print foo.plantain; // out: plantain - print foo.plum; // out: plum - print foo.plumcot; // out: plumcot - print foo.pomegranate; // out: pomegranate - print foo.pomelo; // out: pomelo - print foo.quince; // out: quince - print foo.raisin; // out: raisin - print foo.rambutan; // out: rambutan - print foo.raspberry; // out: raspberry - print foo.redcurrant; // out: redcurrant - print foo.salak; // out: salak - print foo.salmonberry; // out: salmonberry - print foo.satsuma; // out: satsuma - print foo.strawberry; // out: strawberry - print foo.tamarillo; // out: tamarillo - print foo.tamarind; // out: tamarind - print foo.tangerine; // out: tangerine - print foo.tomato; // out: tomato - print foo.watermelon; // out: watermelon - print foo.yuzu; // out: yuzu + println(foo.apple); // out: apple + println(foo.apricot); // out: apricot + println(foo.avocado); // out: avocado + println(foo.banana); // out: banana + println(foo.bilberry); // out: bilberry + println(foo.blackberry); // out: blackberry + println(foo.blackcurrant); // out: blackcurrant + println(foo.blueberry); // out: blueberry + println(foo.boysenberry); // out: boysenberry + println(foo.cantaloupe); // out: cantaloupe + println(foo.cherimoya); // out: cherimoya + println(foo.cherry); // out: cherry + println(foo.clementine); // out: clementine + println(foo.cloudberry); // out: cloudberry + println(foo.coconut); // out: coconut + println(foo.cranberry); // out: cranberry + println(foo.currant); // out: currant + println(foo.damson); // out: damson + println(foo.date); // out: date + println(foo.dragonfruit); // out: dragonfruit + println(foo.durian); // out: durian + println(foo.elderberry); // out: elderberry + println(foo.feijoa); // out: feijoa + println(foo.fig); // out: fig + println(foo.gooseberry); // out: gooseberry + println(foo.grape); // out: grape + println(foo.grapefruit); // out: grapefruit + println(foo.guava); // out: guava + println(foo.honeydew); // out: honeydew + println(foo.huckleberry); // out: huckleberry + println(foo.jabuticaba); // out: jabuticaba + println(foo.jackfruit); // out: jackfruit + println(foo.jambul); // out: jambul + println(foo.jujube); // out: jujube + println(foo.juniper); // out: juniper + println(foo.kiwifruit); // out: kiwifruit + println(foo.kumquat); // out: kumquat + println(foo.lemon); // out: lemon + println(foo.lime); // out: lime + println(foo.longan); // out: longan + println(foo.loquat); // out: loquat + println(foo.lychee); // out: lychee + println(foo.mandarine); // out: mandarine + println(foo.mango); // out: mango + println(foo.marionberry); // out: marionberry + println(foo.melon); // out: melon + println(foo.miracle); // out: miracle + println(foo.mulberry); // out: mulberry + println(foo.nance); // out: nance + println(foo.nectarine); // out: nectarine + println(foo.olive); // out: olive + println(foo.orange); // out: orange + println(foo.papaya); // out: papaya + println(foo.passionfruit); // out: passionfruit + println(foo.peach); // out: peach + println(foo.pear); // out: pear + println(foo.persimmon); // out: persimmon + println(foo.physalis); // out: physalis + println(foo.pineapple); // out: pineapple + println(foo.plantain); // out: plantain + println(foo.plum); // out: plum + println(foo.plumcot); // out: plumcot + println(foo.pomegranate); // out: pomegranate + println(foo.pomelo); // out: pomelo + println(foo.quince); // out: quince + println(foo.raisin); // out: raisin + println(foo.rambutan); // out: rambutan + println(foo.raspberry); // out: raspberry + println(foo.redcurrant); // out: redcurrant + println(foo.salak); // out: salak + println(foo.salmonberry); // out: salmonberry + println(foo.satsuma); // out: satsuma + println(foo.strawberry); // out: strawberry + println(foo.tamarillo); // out: tamarillo + println(foo.tamarind); // out: tamarind + println(foo.tangerine); // out: tangerine + println(foo.tomato); // out: tomato + println(foo.watermelon); // out: watermelon + println(foo.yuzu); // out: yuzu } printFields(); diff --git a/res/examples/field/method.locks b/res/examples/field/method.locks index e513569..37e9d4c 100644 --- a/res/examples/field/method.locks +++ b/res/examples/field/method.locks @@ -1,9 +1,9 @@ class Foo { fn bar(arg) { - print arg; + println(arg); } } let bar = Foo().bar; -print "got method"; // out: got method +println("got method"); // out: got method bar("arg"); // out: arg diff --git a/res/examples/field/method_binds_this.locks b/res/examples/field/method_binds_this.locks index 387c982..9b0e2fb 100644 --- a/res/examples/field/method_binds_this.locks +++ b/res/examples/field/method_binds_this.locks @@ -3,8 +3,8 @@ class Foo { let fun; fn sayName(a) { - print this.name; - print a; + println(this.name); + println(a); } } diff --git a/res/examples/field/on_instance.locks b/res/examples/field/on_instance.locks index db37791..a1edd76 100644 --- a/res/examples/field/on_instance.locks +++ b/res/examples/field/on_instance.locks @@ -5,8 +5,8 @@ class Foo { let foo = Foo(); -print foo.bar = "bar value"; // out: bar value -print foo.baz = "baz value"; // out: baz value +println(foo.bar = "bar value"); // out: bar value +println(foo.baz = "baz value"); // out: baz value -print foo.bar; // out: bar value -print foo.baz; // out: baz value +println(foo.bar); // out: bar value +println(foo.baz); // out: baz value diff --git a/res/examples/for/closure_in_body.locks b/res/examples/for/closure_in_body.locks index 4fd3d81..70a5495 100644 --- a/res/examples/for/closure_in_body.locks +++ b/res/examples/for/closure_in_body.locks @@ -5,8 +5,8 @@ let f3; for (let i = 1; i < 4; i = i + 1) { let j = i; fn f() { - print i; - print j; + println(i); + println(j); } if (j == 1) f1 = f; diff --git a/res/examples/for/return_closure.locks b/res/examples/for/return_closure.locks index 6157d0f..fe7160b 100644 --- a/res/examples/for/return_closure.locks +++ b/res/examples/for/return_closure.locks @@ -1,7 +1,7 @@ fn f() { for (;;) { let i = "i"; - fn g() { print i; } + fn g() { println(i); } return g; } } diff --git a/res/examples/for/return_inside.locks b/res/examples/for/return_inside.locks index 42cfe33..e45e980 100644 --- a/res/examples/for/return_inside.locks +++ b/res/examples/for/return_inside.locks @@ -5,4 +5,4 @@ fn f() { } } -print f(); // out: i +println(f()); // out: i diff --git a/res/examples/for/scope.locks b/res/examples/for/scope.locks index efa28cf..476dec7 100644 --- a/res/examples/for/scope.locks +++ b/res/examples/for/scope.locks @@ -3,11 +3,11 @@ // New variable is in inner scope. for (let i = 0; i < 1; i = i + 1) { - print i; // out: 0 + println(i); // out: 0 // Loop body is in second inner scope. let i = -1; - print i; // out: -1 + println(i); // out: -1 } } @@ -17,10 +17,10 @@ // Goes out of scope after loop. let i = "after"; - print i; // out: after + println(i); // out: after // Can reuse an existing variable. for (i = 0; i < 1; i = i + 1) { - print i; // out: 0 + println(i); // out: 0 } } diff --git a/res/examples/for/syntax.locks b/res/examples/for/syntax.locks index 52c31ff..516560e 100644 --- a/res/examples/for/syntax.locks +++ b/res/examples/for/syntax.locks @@ -4,7 +4,7 @@ // out: 2 // out: 3 // -for (let c = 0; c < 3;) print c = c + 1; +for (let c = 0; c < 3;) println(c = c + 1); // Block body. // @@ -13,7 +13,7 @@ for (let c = 0; c < 3;) print c = c + 1; // out: 2 // for (let a = 0; a < 3; a = a + 1) { - print a; + println(a); } // No clauses. @@ -23,7 +23,7 @@ for (let a = 0; a < 3; a = a + 1) { fn foo() { for (;;) return "done"; } -print foo(); +println(foo()); // No variable. // @@ -31,7 +31,7 @@ print foo(); // out: 1 // let i = 0; -for (; i < 2; i = i + 1) print i; +for (; i < 2; i = i + 1) println(i); // No condition. // @@ -41,7 +41,7 @@ for (; i < 2; i = i + 1) print i; // fn bar() { for (let i = 0;; i = i + 1) { - print i; + println(i); if (i >= 2) return; } } @@ -54,7 +54,7 @@ bar(); // out: 1 // for (let i = 0; i < 2;) { - print i; + println(i); i = i + 1; } diff --git a/res/examples/function/assign_to_var.locks b/res/examples/function/assign_to_var.locks index 83b9caa..52c531d 100644 --- a/res/examples/function/assign_to_var.locks +++ b/res/examples/function/assign_to_var.locks @@ -1,5 +1,5 @@ fn f() { - print("Test"); + println("Test"); } let fun = f; diff --git a/res/examples/function/empty_body.locks b/res/examples/function/empty_body.locks index 598f5a7..0c6729a 100644 --- a/res/examples/function/empty_body.locks +++ b/res/examples/function/empty_body.locks @@ -1,2 +1,2 @@ fn f() {} -print f(); // out: nil +println(f()); // out: nil diff --git a/res/examples/function/expr_stmt_body.locks b/res/examples/function/expr_stmt_body.locks index 3f522d8..36325a1 100644 --- a/res/examples/function/expr_stmt_body.locks +++ b/res/examples/function/expr_stmt_body.locks @@ -8,7 +8,7 @@ fn both(a, b) => fn identity(value) => value; -print sum(10, 10); // out: 20 -print sum(10, -3); // out: 7 +println(sum(10, 10)); // out: 20 +println(sum(10, -3)); // out: 7 -print both(10, 5); // out: 3 +println(both(10, 5)); // out: 3 diff --git a/res/examples/function/extra_arguments.locks b/res/examples/function/extra_arguments.locks index cc60c6b..c7af8c2 100644 --- a/res/examples/function/extra_arguments.locks +++ b/res/examples/function/extra_arguments.locks @@ -1,6 +1,6 @@ fn f(a, b) { - print a; - print b; + println(a); + println(b); } // out: TypeError: f() takes 2 arguments but 4 were given diff --git a/res/examples/function/length.locks b/res/examples/function/length.locks index 880add4..d6a2ff1 100644 --- a/res/examples/function/length.locks +++ b/res/examples/function/length.locks @@ -1,3 +1,3 @@ fn sum (a, b) => a + b; -print len(sum); // out: TypeError: "function" object has no length +println(len(sum)); // out: TypeError: "function" object has no length diff --git a/res/examples/function/local_recursion.locks b/res/examples/function/local_recursion.locks index 49e72cd..fb08d95 100644 --- a/res/examples/function/local_recursion.locks +++ b/res/examples/function/local_recursion.locks @@ -4,5 +4,5 @@ return fib(n - 1) + fib(n - 2); } - print fib(8); // out: 21 + println(fib(8)); // out: 21 } diff --git a/res/examples/function/mutual_recursion.locks b/res/examples/function/mutual_recursion.locks index 231a41d..4546799 100644 --- a/res/examples/function/mutual_recursion.locks +++ b/res/examples/function/mutual_recursion.locks @@ -8,5 +8,5 @@ fn isOdd(n) { return isEven(n - 1); } -print isEven(4); // out: true -print isOdd(3); // out: true +println(isEven(4)); // out: true +println(isOdd(3)); // out: true diff --git a/res/examples/function/nested_call_with_arguments.locks b/res/examples/function/nested_call_with_arguments.locks index 51deaa7..2faef6b 100644 --- a/res/examples/function/nested_call_with_arguments.locks +++ b/res/examples/function/nested_call_with_arguments.locks @@ -7,7 +7,7 @@ fn returnFunCallWithArg(func, arg) { } fn printArg(arg) { - print arg; + println(arg); } returnFunCallWithArg(printArg, "hello world"); // out: hello world diff --git a/res/examples/function/parameters.locks b/res/examples/function/parameters.locks index b46d5ea..6286176 100644 --- a/res/examples/function/parameters.locks +++ b/res/examples/function/parameters.locks @@ -1,26 +1,26 @@ fn f0() { return 0; } -print f0(); // out: 0 +println(f0()); // out: 0 fn f1(a) { return a; } -print f1(1); // out: 1 +println(f1(1)); // out: 1 fn f2(a, b) { return a + b; } -print f2(1, 2); // out: 3 +println(f2(1, 2)); // out: 3 fn f3(a, b, c) { return a + b + c; } -print f3(1, 2, 3); // out: 6 +println(f3(1, 2, 3)); // out: 6 fn f4(a, b, c, d) { return a + b + c + d; } -print f4(1, 2, 3, 4); // out: 10 +println(f4(1, 2, 3, 4)); // out: 10 fn f5(a, b, c, d, e) { return a + b + c + d + e; } -print f5(1, 2, 3, 4, 5); // out: 15 +println(f5(1, 2, 3, 4, 5)); // out: 15 fn f6(a, b, c, d, e, f) { return a + b + c + d + e + f; } -print f6(1, 2, 3, 4, 5, 6); // out: 21 +println(f6(1, 2, 3, 4, 5, 6)); // out: 21 fn f7(a, b, c, d, e, f, g) { return a + b + c + d + e + f + g; } -print f7(1, 2, 3, 4, 5, 6, 7); // out: 28 +println(f7(1, 2, 3, 4, 5, 6, 7)); // out: 28 fn f8(a, b, c, d, e, f, g, h) { return a + b + c + d + e + f + g + h; } -print f8(1, 2, 3, 4, 5, 6, 7, 8); // out: 36 +println(f8(1, 2, 3, 4, 5, 6, 7, 8)); // out: 36 diff --git a/res/examples/function/print.locks b/res/examples/function/print.locks index d163da5..c88c330 100644 --- a/res/examples/function/print.locks +++ b/res/examples/function/print.locks @@ -1,4 +1,4 @@ fn foo() {} -print foo; // out: +println(foo); // out: -print clock; // out: +println(clock); // out: diff --git a/res/examples/function/recursion.locks b/res/examples/function/recursion.locks index 604fae9..627542d 100644 --- a/res/examples/function/recursion.locks +++ b/res/examples/function/recursion.locks @@ -3,4 +3,4 @@ fn fib(n) { return fib(n - 1) + fib(n - 2); } -print fib(8); // out: 21 +println(fib(8)); // out: 21 diff --git a/res/examples/if/dangling_else.locks b/res/examples/if/dangling_else.locks index 67fdf82..b4244f2 100644 --- a/res/examples/if/dangling_else.locks +++ b/res/examples/if/dangling_else.locks @@ -1,3 +1,3 @@ // A dangling else binds to the right-most if. -if (true) if (false) print "bad"; else print "good"; // out: good -if (false) if (true) print "bad"; else print "bad"; +if (true) if (false) println("bad"); else println("good"); // out: good +if (false) if (true) println("bad"); else println("bad"); diff --git a/res/examples/if/else.locks b/res/examples/if/else.locks index 6dd0349..b3da26e 100644 --- a/res/examples/if/else.locks +++ b/res/examples/if/else.locks @@ -1,6 +1,6 @@ // Evaluate the 'else' expression if the condition is false. -if (true) print "good"; else print "bad"; // out: good -if (false) print "bad"; else print "good"; // out: good +if (true) println("good"); else println("bad"); // out: good +if (false) println("bad"); else println("good"); // out: good // Allow block body. -if (false) nil; else { print "block"; } // out: block +if (false) nil; else { println("block"); } // out: block diff --git a/res/examples/if/if.locks b/res/examples/if/if.locks index da82792..4e805fc 100644 --- a/res/examples/if/if.locks +++ b/res/examples/if/if.locks @@ -1,10 +1,10 @@ // Evaluate the 'then' expression if the condition is true. -if (true) print "good"; // out: good -if (false) print "bad"; +if (true) println("good"); // out: good +if (false) println("bad"); // Allow block body. -if (true) { print "block"; } // out: block +if (true) { println("block"); } // out: block // Assignment in if condition. let a = false; -if (a = true) print a; // out: true +if (a = true) println(a); // out: true diff --git a/res/examples/if/truth.locks b/res/examples/if/truth.locks index 923e7c1..340392b 100644 --- a/res/examples/if/truth.locks +++ b/res/examples/if/truth.locks @@ -1,8 +1,8 @@ // False and nil are false. -if (false) print "bad"; else print "false"; // out: false -if (nil) print "bad"; else print "nil"; // out: nil +if (false) println("bad"); else println("false"); // out: false +if (nil) println("bad"); else println("nil"); // out: nil // Everything else is true. -if (true) print true; // out: true -if (0) print 0; // out: 0 -if ("") print "empty"; // out: empty +if (true) println(true); // out: true +if (0) println(0); // out: 0 +if ("") println("empty"); // out: empty diff --git a/res/examples/inheritance/constructor.locks b/res/examples/inheritance/constructor.locks index 734825a..245f3fb 100644 --- a/res/examples/inheritance/constructor.locks +++ b/res/examples/inheritance/constructor.locks @@ -6,7 +6,7 @@ class A { } fn test() { - print this.field; + println(this.field); } } diff --git a/res/examples/inheritance/inherit_methods.locks b/res/examples/inheritance/inherit_methods.locks index a25d091..c6e2f00 100644 --- a/res/examples/inheritance/inherit_methods.locks +++ b/res/examples/inheritance/inherit_methods.locks @@ -1,11 +1,11 @@ class Foo { - fn methodOnFoo() { print "foo"; } - fn override() { print "foo"; } + fn methodOnFoo() { println("foo"); } + fn override() { println("foo"); } } class Bar extends Foo { - fn methodOnBar() { print "bar"; } - fn override() { print "bar"; } + fn methodOnBar() { println("bar"); } + fn override() { println("bar"); } } let bar = Bar(); diff --git a/res/examples/inheritance/set_fields_from_base_class.locks b/res/examples/inheritance/set_fields_from_base_class.locks index a7142b1..241b3ed 100644 --- a/res/examples/inheritance/set_fields_from_base_class.locks +++ b/res/examples/inheritance/set_fields_from_base_class.locks @@ -7,9 +7,9 @@ class Foo { this.field2 = b; } - fn fooPrint() { - print this.field1; - print this.field2; + fn fooprintln() { + println(this.field1); + println(this.field2); } } @@ -19,23 +19,23 @@ class Bar extends Foo { this.field2 = b; } - fn barPrint() { - print this.field1; - print this.field2; + fn barprintln() { + println(this.field1); + println(this.field2); } } let bar = Bar(); bar.foo("foo 1", "foo 2"); -bar.fooPrint(); +bar.fooprintln(); // out: foo 1 // out: foo 2 bar.bar("bar 1", "bar 2"); -bar.barPrint(); +bar.barprintln(); // out: bar 1 // out: bar 2 -bar.fooPrint(); +bar.fooprintln(); // out: bar 1 // out: bar 2 diff --git a/res/examples/list/expression_statements.locks b/res/examples/list/expression_statements.locks index 361473f..94062e0 100644 --- a/res/examples/list/expression_statements.locks +++ b/res/examples/list/expression_statements.locks @@ -1,3 +1,3 @@ -print [1, 2, 5]; // out: [1, 2, 5] -print []; // out: [] -print [100, 200, 300][0]; // out: 100 +println([1, 2, 5]); // out: [1, 2, 5] +println([]); // out: [] +println([100, 200, 300][0]); // out: 100 diff --git a/res/examples/list/get_index.locks b/res/examples/list/get_index.locks index 8bab615..4d980d3 100644 --- a/res/examples/list/get_index.locks +++ b/res/examples/list/get_index.locks @@ -1,10 +1,10 @@ let a = ["a", "b"]; -print a[1]; // out: b +println(a[1]); // out: b let list = [100, 200, 300]; -print list[0]; // out: 100 -print list[1]; // out: 200 -print list[2]; // out: 300 -print list[3]; // out: IndexError: the length is 3 but the index is 3 (out of bounds) +println(list[0]); // out: 100 +println(list[1]); // out: 200 +println(list[2]); // out: 300 +println(list[3]); // out: IndexError: the length is 3 but the index is 3 (out of bounds) diff --git a/res/examples/list/get_index_on_bool.locks b/res/examples/list/get_index_on_bool.locks index 5d32767..cd7ed2e 100644 --- a/res/examples/list/get_index_on_bool.locks +++ b/res/examples/list/get_index_on_bool.locks @@ -1 +1 @@ -print true[0]; // out: TypeError: "bool" is not indexable +println(true[0]); // out: TypeError: "bool" is not indexable diff --git a/res/examples/list/get_index_on_class.locks b/res/examples/list/get_index_on_class.locks index c0f6cc4..34c283b 100644 --- a/res/examples/list/get_index_on_class.locks +++ b/res/examples/list/get_index_on_class.locks @@ -2,4 +2,4 @@ class Class { } -print Class[0]; // out: TypeError: "class" is not indexable +println(Class[0]); // out: TypeError: "class" is not indexable diff --git a/res/examples/list/get_index_on_class_instanitate_expression.locks b/res/examples/list/get_index_on_class_instanitate_expression.locks index b437943..ecd96e0 100644 --- a/res/examples/list/get_index_on_class_instanitate_expression.locks +++ b/res/examples/list/get_index_on_class_instanitate_expression.locks @@ -1,3 +1,3 @@ class Class {} -print Class()[0]; // out: TypeError: "instance" is not indexable +println(Class()[0]); // out: TypeError: "instance" is not indexable diff --git a/res/examples/list/get_index_on_instance.locks b/res/examples/list/get_index_on_instance.locks index 7a0820f..028126e 100644 --- a/res/examples/list/get_index_on_instance.locks +++ b/res/examples/list/get_index_on_instance.locks @@ -2,4 +2,4 @@ class Class {} let c = Class(); -print c[0]; // out: TypeError: "instance" is not indexable +println(c[0]); // out: TypeError: "instance" is not indexable diff --git a/res/examples/list/get_index_on_instance_list_field.locks b/res/examples/list/get_index_on_instance_list_field.locks index ce23289..3dde595 100644 --- a/res/examples/list/get_index_on_instance_list_field.locks +++ b/res/examples/list/get_index_on_instance_list_field.locks @@ -6,4 +6,4 @@ class Class { } } -print Class().values[0]; // out: 10 +println(Class().values[0]); // out: 10 diff --git a/res/examples/list/get_index_on_list_returned_from_function.locks b/res/examples/list/get_index_on_list_returned_from_function.locks index e0e4825..03df7d1 100644 --- a/res/examples/list/get_index_on_list_returned_from_function.locks +++ b/res/examples/list/get_index_on_list_returned_from_function.locks @@ -2,4 +2,4 @@ fn function() { return [4, 5 ,6]; } -print function()[0]; // out: 4 +println(function()[0]); // out: 4 diff --git a/res/examples/list/get_index_on_nil copy.locks b/res/examples/list/get_index_on_nil copy.locks index a78151d..d195034 100644 --- a/res/examples/list/get_index_on_nil copy.locks +++ b/res/examples/list/get_index_on_nil copy.locks @@ -1 +1 @@ -print nil[0]; // out: TypeError: "nil" is not indexable +println(nil[0]); // out: TypeError: "nil" is not indexable diff --git a/res/examples/list/get_index_on_nil.locks b/res/examples/list/get_index_on_nil.locks index a78151d..d195034 100644 --- a/res/examples/list/get_index_on_nil.locks +++ b/res/examples/list/get_index_on_nil.locks @@ -1 +1 @@ -print nil[0]; // out: TypeError: "nil" is not indexable +println(nil[0]); // out: TypeError: "nil" is not indexable diff --git a/res/examples/list/get_index_on_number.locks b/res/examples/list/get_index_on_number.locks index 0dfef77..79b483b 100644 --- a/res/examples/list/get_index_on_number.locks +++ b/res/examples/list/get_index_on_number.locks @@ -1 +1 @@ -print 0[0]; // out: TypeError: "number" is not indexable +println(0[0]); // out: TypeError: "number" is not indexable diff --git a/res/examples/list/get_index_on_string.locks b/res/examples/list/get_index_on_string.locks index 15d8466..84cb034 100644 --- a/res/examples/list/get_index_on_string.locks +++ b/res/examples/list/get_index_on_string.locks @@ -1,3 +1,3 @@ let string = "foo"; -print string[0]; // out: TypeError: "string" is not indexable +println(string[0]); // out: TypeError: "string" is not indexable diff --git a/res/examples/list/get_index_with_empty_index.locks b/res/examples/list/get_index_with_empty_index.locks index 783f01c..80a55df 100644 --- a/res/examples/list/get_index_with_empty_index.locks +++ b/res/examples/list/get_index_with_empty_index.locks @@ -1 +1 @@ -print [10, 20, 30][]; // out: SyntaxError: unexpected "]" +println([10, 20, 30][]); // out: SyntaxError: unexpected "]" diff --git a/res/examples/list/get_index_with_non_number_index.locks b/res/examples/list/get_index_with_non_number_index.locks index e7cd2ac..19957b0 100644 --- a/res/examples/list/get_index_with_non_number_index.locks +++ b/res/examples/list/get_index_with_non_number_index.locks @@ -1,3 +1,3 @@ let list = [1, 2]; -print list["b"]; // out: AttributeError: "list" object has no attribute "b" +println(list["b"]); // out: AttributeError: "list" object has no attribute "b" diff --git a/res/examples/list/length.locks b/res/examples/list/length.locks index daa1d8b..f617e62 100644 --- a/res/examples/list/length.locks +++ b/res/examples/list/length.locks @@ -2,4 +2,4 @@ let list = [1, 2, 3]; let length = len(list); -print length; // out: 3 +println(length); // out: 3 diff --git a/res/examples/list/mixed_types.locks b/res/examples/list/mixed_types.locks index fa2ad5a..ce985a0 100644 --- a/res/examples/list/mixed_types.locks +++ b/res/examples/list/mixed_types.locks @@ -7,4 +7,4 @@ fn example() { let list = [[1, 2, 3], Class, "test", 123, example]; -print list; // out: [[1, 2, 3], , "test", 123, ] +println(list); // out: [[1, 2, 3], , "test", 123, ] diff --git a/res/examples/list/nested_lists.locks b/res/examples/list/nested_lists.locks index 866f998..f8852ec 100644 --- a/res/examples/list/nested_lists.locks +++ b/res/examples/list/nested_lists.locks @@ -1,3 +1,3 @@ let list = [10, 20, [30]]; let last = list[2][0]; -print last; // out: 30 \ No newline at end of file +println(last); // out: 30 \ No newline at end of file diff --git a/res/examples/list/set_index.locks b/res/examples/list/set_index.locks index 8393c52..698f10d 100644 --- a/res/examples/list/set_index.locks +++ b/res/examples/list/set_index.locks @@ -1,13 +1,13 @@ let list = [100, 200, 300]; -print list[0]; // out: 100 -print list[1]; // out: 200 -print list[2]; // out: 300 +println(list[0]); // out: 100 +println(list[1]); // out: 200 +println(list[2]); // out: 300 list[1] = 400; -print list[0]; // out: 100 -print list[1]; // out: 400 -print list[2]; // out: 300 +println(list[0]); // out: 100 +println(list[1]); // out: 400 +println(list[2]); // out: 300 list[3] = 1000; // out: IndexError: the length is 3 but the index is 3 (out of bounds) diff --git a/res/examples/logical_operator/and.locks b/res/examples/logical_operator/and.locks index c668484..ddcaf57 100644 --- a/res/examples/logical_operator/and.locks +++ b/res/examples/logical_operator/and.locks @@ -1,13 +1,13 @@ // Note: These tests implicitly depend on ints being truthy. // Return the first non-true argument. -print false and 1; // out: false -print true and 1; // out: 1 -print 1 and 2 and false; // out: false +println(false and 1); // out: false +println(true and 1); // out: 1 +println(1 and 2 and false); // out: false // Return the last argument if all are true. -print 1 and true; // out: true -print 1 and 2 and 3; // out: 3 +println(1 and true); // out: true +println(1 and 2 and 3); // out: 3 // Short-circuit at the first false argument. let a = "before"; @@ -15,5 +15,5 @@ let b = "before"; (a = true) and (b = false) and (a = "bad"); -print a; // out: true -print b; // out: false +println(a); // out: true +println(b); // out: false diff --git a/res/examples/logical_operator/and_truth.locks b/res/examples/logical_operator/and_truth.locks index 190d56c..248b9f0 100644 --- a/res/examples/logical_operator/and_truth.locks +++ b/res/examples/logical_operator/and_truth.locks @@ -1,8 +1,8 @@ // False and nil are false. -print false and "bad"; // out: false -print nil and "bad"; // out: nil +println(false and "bad"); // out: false +println(nil and "bad"); // out: nil // Everything else is true. -print true and "ok"; // out: ok -print 0 and "ok"; // out: ok -print "" and "ok"; // out: ok +println(true and "ok"); // out: ok +println(0 and "ok"); // out: ok +println("" and "ok"); // out: ok diff --git a/res/examples/logical_operator/or.locks b/res/examples/logical_operator/or.locks index c5ea491..0c97f57 100644 --- a/res/examples/logical_operator/or.locks +++ b/res/examples/logical_operator/or.locks @@ -1,13 +1,13 @@ // Note: These tests implicitly depend on ints being truthy. // Return the first true argument. -print 1 or true; // out: 1 -print false or 1; // out: 1 -print false or false or true; // out: true +println(1 or true); // out: 1 +println(false or 1); // out: 1 +println(false or false or true); // out: true // Return the last argument if all are false. -print false or false; // out: false -print false or false or false; // out: false +println(false or false); // out: false +println(false or false or false); // out: false // Short-circuit at the first true argument. let a = "before"; @@ -15,5 +15,5 @@ let b = "before"; (a = false) or (b = true) or (a = "bad"); -print a; // out: false -print b; // out: true +println(a); // out: false +println(b); // out: true diff --git a/res/examples/logical_operator/or_truth.locks b/res/examples/logical_operator/or_truth.locks index 345f8ce..4f47679 100644 --- a/res/examples/logical_operator/or_truth.locks +++ b/res/examples/logical_operator/or_truth.locks @@ -1,8 +1,8 @@ // False and nil are false. -print false or "ok"; // out: ok -print nil or "ok"; // out: ok +println(false or "ok"); // out: ok +println(nil or "ok"); // out: ok // Everything else is true. -print true or "ok"; // out: true -print 0 or "ok"; // out: 0 -print "s" or "ok"; // out: s +println(true or "ok"); // out: true +println(0 or "ok"); // out: 0 +println("s" or "ok"); // out: s diff --git a/res/examples/method/arity.locks b/res/examples/method/arity.locks index cbba660..101399f 100644 --- a/res/examples/method/arity.locks +++ b/res/examples/method/arity.locks @@ -11,12 +11,12 @@ class Foo { } let foo = Foo(); -print foo.method0(); // out: no args -print foo.method1(1); // out: 1 -print foo.method2(1, 2); // out: 3 -print foo.method3(1, 2, 3); // out: 6 -print foo.method4(1, 2, 3, 4); // out: 10 -print foo.method5(1, 2, 3, 4, 5); // out: 15 -print foo.method6(1, 2, 3, 4, 5, 6); // out: 21 -print foo.method7(1, 2, 3, 4, 5, 6, 7); // out: 28 -print foo.method8(1, 2, 3, 4, 5, 6, 7, 8); // out: 36 +println(foo.method0()); // out: no args +println(foo.method1(1)); // out: 1 +println(foo.method2(1, 2)); // out: 3 +println(foo.method3(1, 2, 3)); // out: 6 +println(foo.method4(1, 2, 3, 4)); // out: 10 +println(foo.method5(1, 2, 3, 4, 5)); // out: 15 +println(foo.method6(1, 2, 3, 4, 5, 6)); // out: 21 +println(foo.method7(1, 2, 3, 4, 5, 6, 7)); // out: 28 +println(foo.method8(1, 2, 3, 4, 5, 6, 7, 8)); // out: 36 diff --git a/res/examples/method/empty_block.locks b/res/examples/method/empty_block.locks index 8bc3d77..b9cadfb 100644 --- a/res/examples/method/empty_block.locks +++ b/res/examples/method/empty_block.locks @@ -2,4 +2,4 @@ class Foo { fn bar() {} } -print Foo().bar(); // out: nil +println(Foo().bar()); // out: nil diff --git a/res/examples/method/expr_stmt_body.locks b/res/examples/method/expr_stmt_body.locks index 949846c..1d6ec33 100644 --- a/res/examples/method/expr_stmt_body.locks +++ b/res/examples/method/expr_stmt_body.locks @@ -11,8 +11,8 @@ class Box { let box = Box("Hello"); -print box.get(); // out: Hello +println(box.get()); // out: Hello box.value = "World"; -print box.get(); // out: World +println(box.get()); // out: World diff --git a/res/examples/method/extra_arguments.locks b/res/examples/method/extra_arguments.locks index 9296395..55f6449 100644 --- a/res/examples/method/extra_arguments.locks +++ b/res/examples/method/extra_arguments.locks @@ -1,7 +1,7 @@ class Foo { fn method(a, b) { - print a; - print b; + println(a); + println(b); } } diff --git a/res/examples/method/print_bound_method.locks b/res/examples/method/print_bound_method.locks index a7734b2..ffac7c5 100644 --- a/res/examples/method/print_bound_method.locks +++ b/res/examples/method/print_bound_method.locks @@ -1,5 +1,8 @@ class Foo { - fn method() { } + fn method() {} } + let foo = Foo(); -print foo.method; // out: +let method = foo.method; + +println(method); // out: diff --git a/res/examples/method/refer_to_name.locks b/res/examples/method/refer_to_name.locks index 6fef7ab..24836d3 100644 --- a/res/examples/method/refer_to_name.locks +++ b/res/examples/method/refer_to_name.locks @@ -1,6 +1,6 @@ class Foo { fn method() { - print method; // out: NameError: name "method" is not defined + println(method); // out: NameError: name "method" is not defined } } diff --git a/res/examples/nil/length.locks b/res/examples/nil/length.locks index ec0002f..b2030da 100644 --- a/res/examples/nil/length.locks +++ b/res/examples/nil/length.locks @@ -1 +1 @@ -print len(nil); // out: TypeError: "nil" object has no length +println(len(nil)); // out: TypeError: "nil" object has no length diff --git a/res/examples/nil/literal.locks b/res/examples/nil/literal.locks index 6f89e58..fb61a34 100644 --- a/res/examples/nil/literal.locks +++ b/res/examples/nil/literal.locks @@ -1 +1 @@ -print nil; // out: nil +println(nil); // out: nil diff --git a/res/examples/number/fizzbuzz.locks b/res/examples/number/fizzbuzz.locks index 69e1056..401f157 100644 --- a/res/examples/number/fizzbuzz.locks +++ b/res/examples/number/fizzbuzz.locks @@ -1,16 +1,16 @@ fn fizzBuzz(n) { for (let i = 1; i <= n; i = i + 1) { if (i % 15 == 0) { - print "FizzBuzz"; + println("FizzBuzz"); } else if (i % 3 == 0) { - print "Fizz"; + println("Fizz"); } else if (i % 5 == 0) { - print "Buzz"; + println("Buzz"); } else { - print i; + println(i); } } } diff --git a/res/examples/number/length.locks b/res/examples/number/length.locks index 86d98a9..ff17f00 100644 --- a/res/examples/number/length.locks +++ b/res/examples/number/length.locks @@ -1 +1 @@ -print len(100); // out: TypeError: "100" object has no length +println(len(100)); // out: TypeError: "100" object has no length diff --git a/res/examples/number/literals.locks b/res/examples/number/literals.locks index aaa0e5a..39d3698 100644 --- a/res/examples/number/literals.locks +++ b/res/examples/number/literals.locks @@ -1,7 +1,7 @@ -print 123; // out: 123 -print 987654; // out: 987654 -print 0; // out: 0 -print -0; // out: -0 +println(123); // out: 123 +println(987654); // out: 987654 +println(0); // out: 0 +println(-0); // out: -0 -print 123.456; // out: 123.456 -print -0.001; // out: -0.001 +println(123.456); // out: 123.456 +println(-0.001); // out: -0.001 diff --git a/res/examples/number/nan_equality.locks b/res/examples/number/nan_equality.locks index fb7eec7..d9efcb8 100644 --- a/res/examples/number/nan_equality.locks +++ b/res/examples/number/nan_equality.locks @@ -1,8 +1,8 @@ let nan = 0/0; -print nan == 0; // out: false -print nan != 1; // out: true +println(nan == 0); // out: false +println(nan != 1); // out: true // NaN is not equal to self. -// print nan == nan; // expected: false -// print nan != nan; // expected: true +// println(nan == nan); // expected: false +// println(nan != nan); // expected: true diff --git a/res/examples/operator/add.locks b/res/examples/operator/add.locks index adbb034..c187ac9 100644 --- a/res/examples/operator/add.locks +++ b/res/examples/operator/add.locks @@ -1,2 +1,2 @@ -print 123 + 456; // out: 579 -print "str" + "ing"; // out: string +println(123 + 456); // out: 579 +println("str" + "ing"); // out: string diff --git a/res/examples/operator/comparison.locks b/res/examples/operator/comparison.locks index 25e8856..f339f0c 100644 --- a/res/examples/operator/comparison.locks +++ b/res/examples/operator/comparison.locks @@ -1,25 +1,25 @@ -print 1 < 2; // out: true -print 2 < 2; // out: false -print 2 < 1; // out: false +println(1 < 2); // out: true +println(2 < 2); // out: false +println(2 < 1); // out: false -print 1 <= 2; // out: true -print 2 <= 2; // out: true -print 2 <= 1; // out: false +println(1 <= 2); // out: true +println(2 <= 2); // out: true +println(2 <= 1); // out: false -print 1 > 2; // out: false -print 2 > 2; // out: false -print 2 > 1; // out: true +println(1 > 2); // out: false +println(2 > 2); // out: false +println(2 > 1); // out: true -print 1 >= 2; // out: false -print 2 >= 2; // out: true -print 2 >= 1; // out: true +println(1 >= 2); // out: false +println(2 >= 2); // out: true +println(2 >= 1); // out: true // Zero and negative zero compare the same. -print 0 < -0; // out: false -print -0 < 0; // out: false -print 0 > -0; // out: false -print -0 > 0; // out: false -print 0 <= -0; // out: true -print -0 <= 0; // out: true -print 0 >= -0; // out: true -print -0 >= 0; // out: true +println(0 < -0); // out: false +println(-0 < 0); // out: false +println(0 > -0); // out: false +println(-0 > 0); // out: false +println(0 <= -0); // out: true +println(-0 <= 0); // out: true +println(0 >= -0); // out: true +println(-0 >= 0); // out: true diff --git a/res/examples/operator/divide.locks b/res/examples/operator/divide.locks index 49a598d..7c445a0 100644 --- a/res/examples/operator/divide.locks +++ b/res/examples/operator/divide.locks @@ -1,2 +1,2 @@ -print 8 / 2; // out: 4 -print 12.34 / 12.34; // out: 1 +println(8 / 2); // out: 4 +println(12.34 / 12.34); // out: 1 diff --git a/res/examples/operator/equals.locks b/res/examples/operator/equals.locks index 19a5dab..17b703a 100644 --- a/res/examples/operator/equals.locks +++ b/res/examples/operator/equals.locks @@ -1,14 +1,14 @@ -print nil == nil; // out: true +println(nil == nil); // out: true -print true == true; // out: true -print true == false; // out: false +println(true == true); // out: true +println(true == false); // out: false -print 1 == 1; // out: true -print 1 == 2; // out: false +println(1 == 1); // out: true +println(1 == 2); // out: false -print "str" == "str"; // out: true -print "str" == "ing"; // out: false +println("str" == "str"); // out: true +println("str" == "ing"); // out: false -print nil == false; // out: false -print false == 0; // out: false -print 0 == "0"; // out: false +println(nil == false); // out: false +println(false == 0); // out: false +println(0 == "0"); // out: false diff --git a/res/examples/operator/equals_class.locks b/res/examples/operator/equals_class.locks index 0502c49..0342e9f 100644 --- a/res/examples/operator/equals_class.locks +++ b/res/examples/operator/equals_class.locks @@ -2,12 +2,12 @@ class Foo {} class Bar {} -print Foo == Foo; // out: true -print Foo == Bar; // out: false -print Bar == Foo; // out: false -print Bar == Bar; // out: true +println(Foo == Foo); // out: true +println(Foo == Bar); // out: false +println(Bar == Foo); // out: false +println(Bar == Bar); // out: true -print Foo == "Foo"; // out: false -print Foo == nil; // out: false -print Foo == 123; // out: false -print Foo == true; // out: false +println(Foo == "Foo"); // out: false +println(Foo == nil); // out: false +println(Foo == 123); // out: false +println(Foo == true); // out: false diff --git a/res/examples/operator/equals_method.locks b/res/examples/operator/equals_method.locks index 96eb6c3..3e4c401 100644 --- a/res/examples/operator/equals_method.locks +++ b/res/examples/operator/equals_method.locks @@ -7,7 +7,7 @@ let foo = Foo(); let fooMethod = foo.method; // Same bound method. -print fooMethod == fooMethod; // out: true +println(fooMethod == fooMethod); // out: true // Different closurizations. -print foo.method == foo.method; // out: false +println(foo.method == foo.method); // out: false diff --git a/res/examples/operator/modulus.locks b/res/examples/operator/modulus.locks index 391b325..f452d47 100644 --- a/res/examples/operator/modulus.locks +++ b/res/examples/operator/modulus.locks @@ -1,6 +1,6 @@ -print 10 % 2; // out: 0 -print 5 % 1; // out: 0 -print 5 % 2; // out: 1 -print 5 % 3; // out: 2 -print 5 % 4; // out: 1 -print 5 % 5; // out: 0 +println(10 % 2); // out: 0 +println(5 % 1); // out: 0 +println(5 % 2); // out: 1 +println(5 % 3); // out: 2 +println(5 % 4); // out: 1 +println(5 % 5); // out: 0 diff --git a/res/examples/operator/multiply.locks b/res/examples/operator/multiply.locks index a1d25f4..f0e664c 100644 --- a/res/examples/operator/multiply.locks +++ b/res/examples/operator/multiply.locks @@ -1,2 +1,2 @@ -print 5 * 3; // out: 15 -print 12.34 * 0.3; // out: 3.702 +println(5 * 3); // out: 15 +println(12.34 * 0.3); // out: 3.702 diff --git a/res/examples/operator/negate.locks b/res/examples/operator/negate.locks index 5d359c3..84ed431 100644 --- a/res/examples/operator/negate.locks +++ b/res/examples/operator/negate.locks @@ -1,3 +1,3 @@ -print -(3); // out: -3 -print --(3); // out: 3 -print ---(3); // out: -3 +println(-(3)); // out: -3 +println(--(3)); // out: 3 +println(---(3)); // out: -3 diff --git a/res/examples/operator/not.locks b/res/examples/operator/not.locks index 723ad18..f43c3ea 100644 --- a/res/examples/operator/not.locks +++ b/res/examples/operator/not.locks @@ -1,13 +1,13 @@ -print !true; // out: false -print !false; // out: true -print !!true; // out: true +println(!true); // out: false +println(!false); // out: true +println(!!true); // out: true -print !123; // out: false -print !0; // out: false +println(!123); // out: false +println(!0); // out: false -print !nil; // out: true +println(!nil); // out: true -print !""; // out: false +println(!""); // out: false fn foo() {} -print !foo; // out: false +println(!foo); // out: false diff --git a/res/examples/operator/not_class.locks b/res/examples/operator/not_class.locks index 8a10a15..d71814c 100644 --- a/res/examples/operator/not_class.locks +++ b/res/examples/operator/not_class.locks @@ -1,3 +1,3 @@ class Bar {} -print !Bar; // out: false -print !Bar(); // out: false +println(!Bar); // out: false +println(!Bar()); // out: false diff --git a/res/examples/operator/not_equals.locks b/res/examples/operator/not_equals.locks index d43ffd8..9a451af 100644 --- a/res/examples/operator/not_equals.locks +++ b/res/examples/operator/not_equals.locks @@ -1,14 +1,14 @@ -print nil != nil; // out: false +println(nil != nil); // out: false -print true != true; // out: false -print true != false; // out: true +println(true != true); // out: false +println(true != false); // out: true -print 1 != 1; // out: false -print 1 != 2; // out: true +println(1 != 1); // out: false +println(1 != 2); // out: true -print "str" != "str"; // out: false -print "str" != "ing"; // out: true +println("str" != "str"); // out: false +println("str" != "ing"); // out: true -print nil != false; // out: true -print false != 0; // out: true -print 0 != "0"; // out: true +println(nil != false); // out: true +println(false != 0); // out: true +println(0 != "0"); // out: true diff --git a/res/examples/operator/subtract.locks b/res/examples/operator/subtract.locks index ed72884..b14e9ca 100644 --- a/res/examples/operator/subtract.locks +++ b/res/examples/operator/subtract.locks @@ -1,2 +1,2 @@ -print 4 - 3; // out: 1 -print 1.2 - 1.2; // out: 0 +println(4 - 3); // out: 1 +println(1.2 - 1.2); // out: 0 diff --git a/res/examples/precedence.locks b/res/examples/precedence.locks index 35be8e6..87193c4 100644 --- a/res/examples/precedence.locks +++ b/res/examples/precedence.locks @@ -1,32 +1,32 @@ // * has higher precedence than +. -print 2 + 3 * 4; // out: 14 +println(2 + 3 * 4); // out: 14 // * has higher precedence than -. -print 20 - 3 * 4; // out: 8 +println(20 - 3 * 4); // out: 8 // / has higher precedence than +. -print 2 + 6 / 3; // out: 4 +println(2 + 6 / 3); // out: 4 // / has higher precedence than -. -print 2 - 6 / 3; // out: 0 +println(2 - 6 / 3); // out: 0 // < has higher precedence than ==. -print false == 2 < 1; // out: true +println(false == 2 < 1); // out: true // > has higher precedence than ==. -print false == 1 > 2; // out: true +println(false == 1 > 2); // out: true // <= has higher precedence than ==. -print false == 2 <= 1; // out: true +println(false == 2 <= 1); // out: true // >= has higher precedence than ==. -print false == 1 >= 2; // out: true +println(false == 1 >= 2); // out: true // 1 - 1 is not space-sensitive. -print 1 - 1; // out: 0 -print 1 -1; // out: 0 -print 1- 1; // out: 0 -print 1-1; // out: 0 +println(1 - 1); // out: 0 +println(1 -1); // out: 0 +println(1- 1); // out: 0 +println(1-1); // out: 0 // Using () for grouping. -print (2 * (6 - (2 + 2))); // out: 4 +println((2 * (6 - (2 + 2)))); // out: 4 diff --git a/res/examples/print/missing_argument.locks b/res/examples/print/missing_argument.locks index c4d22cb..195e504 100644 --- a/res/examples/print/missing_argument.locks +++ b/res/examples/print/missing_argument.locks @@ -1,2 +1 @@ -// out: SyntaxError: unexpected ";" -print; +println(); // out: TypeError: println() takes 1 arguments but 0 were given diff --git a/res/examples/regression/394.locks b/res/examples/regression/394.locks index 7eff974..a34d837 100644 --- a/res/examples/regression/394.locks +++ b/res/examples/regression/394.locks @@ -1,5 +1,5 @@ { class A {} class B extends A {} - print B; // out: + println(B); // out: } diff --git a/res/examples/regression/40.locks b/res/examples/regression/40.locks index 007db5d..715fd30 100644 --- a/res/examples/regression/40.locks +++ b/res/examples/regression/40.locks @@ -1,7 +1,7 @@ fn caller(g) { g(); // g should be a function, not nil. - print g == nil; // out: false + println(g == nil); // out: false } fn callCaller() { diff --git a/res/examples/return/after_else.locks b/res/examples/return/after_else.locks index 3542395..3689d1f 100644 --- a/res/examples/return/after_else.locks +++ b/res/examples/return/after_else.locks @@ -2,4 +2,4 @@ fn f() { if (false) "no"; else return "ok"; } -print f(); // out: ok +println(f()); // out: ok diff --git a/res/examples/return/after_if.locks b/res/examples/return/after_if.locks index c6a5397..f30e7c2 100644 --- a/res/examples/return/after_if.locks +++ b/res/examples/return/after_if.locks @@ -2,4 +2,4 @@ fn f() { if (true) return "ok"; } -print f(); // out: ok +println(f()); // out: ok diff --git a/res/examples/return/after_while.locks b/res/examples/return/after_while.locks index 8a940ae..736f279 100644 --- a/res/examples/return/after_while.locks +++ b/res/examples/return/after_while.locks @@ -2,4 +2,4 @@ fn f() { while (true) return "ok"; } -print f(); // out: ok +println(f()); // out: ok diff --git a/res/examples/return/in_function.locks b/res/examples/return/in_function.locks index 741c538..1a843d5 100644 --- a/res/examples/return/in_function.locks +++ b/res/examples/return/in_function.locks @@ -1,6 +1,6 @@ fn f() { return "ok"; - print "bad"; + println("bad"); } -print f(); // out: ok +println(f()); // out: ok diff --git a/res/examples/return/in_method.locks b/res/examples/return/in_method.locks index 30889a2..a9bda2e 100644 --- a/res/examples/return/in_method.locks +++ b/res/examples/return/in_method.locks @@ -1,8 +1,8 @@ class Foo { fn method() { return "ok"; - print "bad"; + println("bad"); } } -print Foo().method(); // out: ok +println(Foo().method()); // out: ok diff --git a/res/examples/return/return_nil_if_no_value.locks b/res/examples/return/return_nil_if_no_value.locks index 2de8966..c68cd6b 100644 --- a/res/examples/return/return_nil_if_no_value.locks +++ b/res/examples/return/return_nil_if_no_value.locks @@ -1,6 +1,6 @@ fn f() { return; - print "bad"; + println("bad"); } -print f(); // out: nil +println(f()); // out: nil diff --git a/res/examples/string/length.locks b/res/examples/string/length.locks index 07acaef..ef949bf 100644 --- a/res/examples/string/length.locks +++ b/res/examples/string/length.locks @@ -1,2 +1,2 @@ -print len(""); // out: 0 -print len("Hello"); // out: 5 +println(len("")); // out: 0 +println(len("Hello")); // out: 5 diff --git a/res/examples/string/literals.locks b/res/examples/string/literals.locks index 410f381..186d2f4 100644 --- a/res/examples/string/literals.locks +++ b/res/examples/string/literals.locks @@ -1,5 +1,5 @@ -print "(" + "" + ")"; // out: () -print "a string"; // out: a string +println("(" + "" + ")"); // out: () +println("a string"); // out: a string // Non-ASCII. -print "A~¶Þॐஃ"; // out: A~¶Þॐஃ +println("A~¶Þॐஃ"); // out: A~¶Þॐஃ diff --git a/res/examples/string/multiline.locks b/res/examples/string/multiline.locks index 0cdf57e..8cb9712 100644 --- a/res/examples/string/multiline.locks +++ b/res/examples/string/multiline.locks @@ -4,4 +4,4 @@ let a = "1 2 3"; -print a; +println(a); diff --git a/res/examples/super/bound_method.locks b/res/examples/super/bound_method.locks index fc9018e..e508229 100644 --- a/res/examples/super/bound_method.locks +++ b/res/examples/super/bound_method.locks @@ -1,6 +1,6 @@ class A { fn method(arg) { - print "A.method(" + arg + ")"; + println("A.method(" + arg + ")"); } } @@ -10,7 +10,7 @@ class B extends A { } fn method(arg) { - print "B.method(" + arg + ")"; + println("B.method(" + arg + ")"); } } diff --git a/res/examples/super/call_other_method.locks b/res/examples/super/call_other_method.locks index 41d7fea..99f4e77 100644 --- a/res/examples/super/call_other_method.locks +++ b/res/examples/super/call_other_method.locks @@ -1,12 +1,12 @@ class Base { fn foo() { - print "Base.foo()"; + println("Base.foo()"); } } class Derived extends Base { fn bar() { - print "Derived.bar()"; + println("Derived.bar()"); super.foo(); } } diff --git a/res/examples/super/call_same_method.locks b/res/examples/super/call_same_method.locks index fb09f4a..8c3cef2 100644 --- a/res/examples/super/call_same_method.locks +++ b/res/examples/super/call_same_method.locks @@ -1,12 +1,12 @@ class Base { fn foo() { - print "Base.foo()"; + println("Base.foo()"); } } class Derived extends Base { fn foo() { - print "Derived.foo()"; + println("Derived.foo()"); super.foo(); } } diff --git a/res/examples/super/closure.locks b/res/examples/super/closure.locks index 44c59c9..682335c 100644 --- a/res/examples/super/closure.locks +++ b/res/examples/super/closure.locks @@ -14,4 +14,4 @@ class Derived extends Base { } let closure = Derived().getClosure(); -print closure(); // out: Base +println(closure()); // out: Base diff --git a/res/examples/super/constructor.locks b/res/examples/super/constructor.locks index a0b3b22..979b691 100644 --- a/res/examples/super/constructor.locks +++ b/res/examples/super/constructor.locks @@ -1,12 +1,12 @@ class Base { fn init(a, b) { - print "Base.init(" + a + ", " + b + ")"; + println("Base.init(" + a + ", " + b + ")"); } } class Derived extends Base { fn init() { - print "Derived.init()"; + println("Derived.init()"); super.init("a", "b"); } } diff --git a/res/examples/super/extra_arguments.locks b/res/examples/super/extra_arguments.locks index 5d01a32..8f21c54 100644 --- a/res/examples/super/extra_arguments.locks +++ b/res/examples/super/extra_arguments.locks @@ -1,12 +1,12 @@ class Base { fn foo(a, b) { - print "Base.foo(" + a + ", " + b + ")"; + println("Base.foo(" + a + ", " + b + ")"); } } class Derived extends Base { fn foo() { - print "Derived.foo()"; // out: Derived.foo() + println("Derived.foo()"); // out: Derived.foo() super.foo("a", "b", "c", "d"); // out: TypeError: foo() takes 2 arguments but 4 were given } } diff --git a/res/examples/super/indirectly_inherited.locks b/res/examples/super/indirectly_inherited.locks index 77cecb8..23ec1d2 100644 --- a/res/examples/super/indirectly_inherited.locks +++ b/res/examples/super/indirectly_inherited.locks @@ -1,6 +1,6 @@ class A { fn foo() { - print "A.foo()"; + println("A.foo()"); } } @@ -8,7 +8,7 @@ class B extends A {} class C extends B { fn foo() { - print "C.foo()"; + println("C.foo()"); super.foo(); } } diff --git a/res/examples/super/missing_arguments.locks b/res/examples/super/missing_arguments.locks index 65bc53b..314b01d 100644 --- a/res/examples/super/missing_arguments.locks +++ b/res/examples/super/missing_arguments.locks @@ -1,6 +1,6 @@ class Base { fn foo(a, b) { - print "Base.foo(" + a + ", " + b + ")"; + println("Base.foo(" + a + ", " + b + ")"); } } diff --git a/res/examples/super/reassign_superclass.locks b/res/examples/super/reassign_superclass.locks index fd463ef..8d93a9f 100644 --- a/res/examples/super/reassign_superclass.locks +++ b/res/examples/super/reassign_superclass.locks @@ -1,6 +1,6 @@ class Base { fn method() { - print "Base.method()"; + println("Base.method()"); } } @@ -12,7 +12,7 @@ class Derived extends Base { class OtherBase { fn method() { - print "OtherBase.method()"; + println("OtherBase.method()"); } } diff --git a/res/examples/super/super_in_closure_in_inherited_method.locks b/res/examples/super/super_in_closure_in_inherited_method.locks index 1c26fbb..8c0e436 100644 --- a/res/examples/super/super_in_closure_in_inherited_method.locks +++ b/res/examples/super/super_in_closure_in_inherited_method.locks @@ -1,6 +1,6 @@ class A { fn say() { - print "A"; + println("A"); } } @@ -13,13 +13,13 @@ class B extends A { } fn say() { - print "B"; + println("B"); } } class C extends B { fn say() { - print "C"; + println("C"); } } diff --git a/res/examples/super/super_in_inherited_method.locks b/res/examples/super/super_in_inherited_method.locks index cf8a7e4..8e67284 100644 --- a/res/examples/super/super_in_inherited_method.locks +++ b/res/examples/super/super_in_inherited_method.locks @@ -1,6 +1,6 @@ class A { fn say() { - print "A"; + println("A"); } } @@ -10,13 +10,13 @@ class B extends A { } fn say() { - print "B"; + println("B"); } } class C extends B { fn say() { - print "C"; + println("C"); } } diff --git a/res/examples/super/this_in_superclass_method.locks b/res/examples/super/this_in_superclass_method.locks index 2337b66..5ac4153 100644 --- a/res/examples/super/this_in_superclass_method.locks +++ b/res/examples/super/this_in_superclass_method.locks @@ -14,5 +14,5 @@ class Derived extends Base { } let derived = Derived("a", "b"); -print derived.a; // out: a -print derived.b; // out: b +println(derived.a); // out: a +println(derived.b); // out: b diff --git a/res/examples/test.locks b/res/examples/test.locks new file mode 100644 index 0000000..bb2cb7d --- /dev/null +++ b/res/examples/test.locks @@ -0,0 +1,11 @@ +class Class { + fn method() {} +} + +fn test(value) { + return value; +} + +let instance = Class(); + +println(test(instance.method)); // out: diff --git a/res/examples/this/closure.locks b/res/examples/this/closure.locks index 072fcc4..4407aff 100644 --- a/res/examples/this/closure.locks +++ b/res/examples/this/closure.locks @@ -10,4 +10,4 @@ class Foo { } let closure = Foo().getClosure(); -print closure(); // out: Foo +println(closure()); // out: Foo diff --git a/res/examples/this/nested_class.locks b/res/examples/this/nested_class.locks index 6b6176e..915d7da 100644 --- a/res/examples/this/nested_class.locks +++ b/res/examples/this/nested_class.locks @@ -1,13 +1,13 @@ class Outer { fn method() { - print this; // out: + println(this); // out: fn f() { - print this; // out: + println(this); // out: class Inner { fn method() { - print this; // out: + println(this); // out: } } diff --git a/res/examples/this/nested_closure.locks b/res/examples/this/nested_closure.locks index b058c5e..0bd5df1 100644 --- a/res/examples/this/nested_closure.locks +++ b/res/examples/this/nested_closure.locks @@ -16,4 +16,4 @@ class Foo { } let closure = Foo().getClosure(); -print closure()()(); // out: Foo +println(closure()()()); // out: Foo diff --git a/res/examples/this/this_in_method.locks b/res/examples/this/this_in_method.locks index abd8c79..445bc36 100644 --- a/res/examples/this/this_in_method.locks +++ b/res/examples/this/this_in_method.locks @@ -3,4 +3,4 @@ class Foo { fn baz() { return "baz"; } } -print Foo().bar().baz(); // out: baz +println(Foo().bar().baz()); // out: baz diff --git a/res/examples/variable/early_bound.locks b/res/examples/variable/early_bound.locks index 8c584c7..6b0a95e 100644 --- a/res/examples/variable/early_bound.locks +++ b/res/examples/variable/early_bound.locks @@ -1,7 +1,7 @@ let a = "outer"; { fn foo() { - print a; + println(a); } foo(); // out: outer diff --git a/res/examples/variable/in_middle_of_block.locks b/res/examples/variable/in_middle_of_block.locks index 802a220..738b290 100644 --- a/res/examples/variable/in_middle_of_block.locks +++ b/res/examples/variable/in_middle_of_block.locks @@ -1,10 +1,10 @@ { let a = "a"; - print a; // out: a + println(a); // out: a let b = a + " b"; - print b; // out: a b + println(b); // out: a b let c = a + " c"; - print c; // out: a c + println(c); // out: a c let d = b + " d"; - print d; // out: a b d + println(d); // out: a b d } diff --git a/res/examples/variable/in_nested_block.locks b/res/examples/variable/in_nested_block.locks index d8feb9e..d88d7d8 100644 --- a/res/examples/variable/in_nested_block.locks +++ b/res/examples/variable/in_nested_block.locks @@ -1,6 +1,6 @@ { let a = "outer"; { - print a; // out: outer + println(a); // out: outer } } diff --git a/res/examples/variable/local_from_method.locks b/res/examples/variable/local_from_method.locks index b82464e..689dc79 100644 --- a/res/examples/variable/local_from_method.locks +++ b/res/examples/variable/local_from_method.locks @@ -2,7 +2,7 @@ let foo = "variable"; class Foo { fn method() { - print foo; + println(foo); } } diff --git a/res/examples/variable/scope_reuse_in_different_blocks.locks b/res/examples/variable/scope_reuse_in_different_blocks.locks index b889530..c554d3d 100644 --- a/res/examples/variable/scope_reuse_in_different_blocks.locks +++ b/res/examples/variable/scope_reuse_in_different_blocks.locks @@ -1,9 +1,9 @@ { let a = "first"; - print a; // out: first + println(a); // out: first } { let a = "second"; - print a; // out: second + println(a); // out: second } diff --git a/res/examples/variable/shadow_and_local.locks b/res/examples/variable/shadow_and_local.locks index dfc85ad..9278666 100644 --- a/res/examples/variable/shadow_and_local.locks +++ b/res/examples/variable/shadow_and_local.locks @@ -1,8 +1,8 @@ { let a = "outer"; { - print a; // out: outer + println(a); // out: outer let a = "inner"; - print a; // out: inner + println(a); // out: inner } } diff --git a/res/examples/variable/shadow_global.locks b/res/examples/variable/shadow_global.locks index 5b29daa..1119204 100644 --- a/res/examples/variable/shadow_global.locks +++ b/res/examples/variable/shadow_global.locks @@ -1,6 +1,6 @@ let a = "global"; { let a = "shadow"; - print a; // out: shadow + println(a); // out: shadow } -print a; // out: global +println(a); // out: global diff --git a/res/examples/variable/shadow_local.locks b/res/examples/variable/shadow_local.locks index 2d33ee6..328f128 100644 --- a/res/examples/variable/shadow_local.locks +++ b/res/examples/variable/shadow_local.locks @@ -2,7 +2,7 @@ let a = "local"; { let a = "shadow"; - print a; // out: shadow + println(a); // out: shadow } - print a; // out: local + println(a); // out: local } diff --git a/res/examples/variable/undefined_global.locks b/res/examples/variable/undefined_global.locks index 932ea22..9f86db7 100644 --- a/res/examples/variable/undefined_global.locks +++ b/res/examples/variable/undefined_global.locks @@ -1,2 +1,2 @@ // out: NameError: name "notDefined" is not defined -print notDefined; +println(notDefined); diff --git a/res/examples/variable/undefined_local.locks b/res/examples/variable/undefined_local.locks index a6a8d21..73fbda0 100644 --- a/res/examples/variable/undefined_local.locks +++ b/res/examples/variable/undefined_local.locks @@ -1,4 +1,4 @@ { // out: NameError: name "notDefined" is not defined - print notDefined; + println(notDefined); } diff --git a/res/examples/variable/uninitialized.locks b/res/examples/variable/uninitialized.locks index 9de1cf0..bddfaa7 100644 --- a/res/examples/variable/uninitialized.locks +++ b/res/examples/variable/uninitialized.locks @@ -1,2 +1,2 @@ let a; -print a; // out: nil +println(a); // out: nil diff --git a/res/examples/variable/unreached_undefined.locks b/res/examples/variable/unreached_undefined.locks index cdf4d0a..0f57b9e 100644 --- a/res/examples/variable/unreached_undefined.locks +++ b/res/examples/variable/unreached_undefined.locks @@ -1,6 +1,6 @@ if (false) { - print notDefined; + println(notDefined); } // out: ok -print "ok"; +println("ok"); diff --git a/res/examples/variable/use_global_in_initializer.locks b/res/examples/variable/use_global_in_initializer.locks index 3cbeb30..102542e 100644 --- a/res/examples/variable/use_global_in_initializer.locks +++ b/res/examples/variable/use_global_in_initializer.locks @@ -1,3 +1,3 @@ let a = "value"; let a = a; // out: NameError: name "a" is already defined -print a; +println(a); diff --git a/res/examples/while/closure_in_body.locks b/res/examples/while/closure_in_body.locks index 0cd54c8..f81c68a 100644 --- a/res/examples/while/closure_in_body.locks +++ b/res/examples/while/closure_in_body.locks @@ -3,9 +3,13 @@ let f2; let f3; let i = 1; + while (i < 4) { let j = i; - fn f() { print j; } + + fn f() { + println(j); + } if (j == 1) f1 = f; else if (j == 2) f2 = f; diff --git a/res/examples/while/return_closure.locks b/res/examples/while/return_closure.locks index 042e35d..524095b 100644 --- a/res/examples/while/return_closure.locks +++ b/res/examples/while/return_closure.locks @@ -1,7 +1,7 @@ fn f() { while (true) { let i = "i"; - fn g() { print i; } + fn g() { println(i); } return g; } } diff --git a/res/examples/while/return_inside.locks b/res/examples/while/return_inside.locks index 590f69c..3ff7ac1 100644 --- a/res/examples/while/return_inside.locks +++ b/res/examples/while/return_inside.locks @@ -5,4 +5,4 @@ fn f() { } } -print f(); // out: i +println(f()); // out: i diff --git a/res/examples/while/syntax.locks b/res/examples/while/syntax.locks index 0b07eb9..55b1ac6 100644 --- a/res/examples/while/syntax.locks +++ b/res/examples/while/syntax.locks @@ -5,7 +5,7 @@ // out: 3 // let c = 0; -while (c < 3) print c = c + 1; +while (c < 3) println(c = c + 1); // Block body. // @@ -15,7 +15,7 @@ while (c < 3) print c = c + 1; // let a = 0; while (a < 3) { - print a; + println(a); a = a + 1; } diff --git a/res/grammar.lalrpop b/res/grammar.lalrpop index 2cff464..d188c04 100644 --- a/res/grammar.lalrpop +++ b/res/grammar.lalrpop @@ -123,7 +123,6 @@ ForIncr = ; StmtSimple = { StmtBlock, StmtExpr, - StmtPrint, StmtReturn, } @@ -135,9 +134,6 @@ StmtBlockInternal: ast::StmtBlock = "{" *> "}" => StmtExpr: ast::Stmt = ";" => ast::Stmt::Expr(ast::StmtExpr { <> }); -StmtPrint: ast::Stmt = "print" ";" => - ast::Stmt::Print(ast::StmtPrint { <> }); - StmtReturn: ast::Stmt = "return" ";" => ast::Stmt::Return(ast::StmtReturn { <> }); @@ -360,7 +356,6 @@ extern { "if" => lexer::Token::If, "nil" => lexer::Token::Nil, "or" => lexer::Token::Or, - "print" => lexer::Token::Print, "return" => lexer::Token::Return, "super" => lexer::Token::Super, "this" => lexer::Token::This, diff --git a/src/syntax/ast.rs b/src/syntax/ast.rs index ecd41be..785b2b9 100644 --- a/src/syntax/ast.rs +++ b/src/syntax/ast.rs @@ -18,7 +18,6 @@ pub enum Stmt { For(Box), Fn(StmtFn), If(Box), - Print(StmtPrint), Return(StmtReturn), Assign(StmtAssign), While(Box), @@ -34,7 +33,6 @@ impl Debug for Stmt { Self::For(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), Self::Fn(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), Self::If(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), - Self::Print(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), Self::Return(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), Self::Assign(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), Self::While(arg0) => f.write_fmt(format_args!("{:#?}", arg0)), @@ -84,11 +82,6 @@ pub struct StmtIf { pub else_: Option, } -#[derive(Clone, Debug, PartialEq)] -pub struct StmtPrint { - pub value: ExprS, -} - #[derive(Clone, Debug, PartialEq)] pub struct StmtReturn { pub value: Option, diff --git a/src/syntax/lexer.rs b/src/syntax/lexer.rs index b9c6b87..3757d1e 100644 --- a/src/syntax/lexer.rs +++ b/src/syntax/lexer.rs @@ -138,8 +138,6 @@ pub enum Token { Nil, #[token("or")] Or, - #[token("print")] - Print, #[token("return")] Return, #[token("super")] diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index 9aa3120..03e694b 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -49,7 +49,7 @@ pub fn parse(source: &str, offset: usize) -> Result> { } ParseError::UnrecognizedToken { token: (start, _, end), expected } => ( Error::SyntaxError(SyntaxError::UnrecognizedToken { - token: source[start..end].to_string(), + token: source[start - offset..end - offset].to_string(), expected, }), start..end, diff --git a/src/vm/compiler.rs b/src/vm/compiler.rs index f06b9cc..28914e1 100644 --- a/src/vm/compiler.rs +++ b/src/vm/compiler.rs @@ -251,10 +251,6 @@ impl Compiler { // END: self.patch_jump(jump_to_end, span)?; } - Stmt::Print(print) => { - self.compile_expr(&print.value, gc)?; - self.emit_u8(op::PRINT, span); - } Stmt::Return(return_) => { match self.ctx.type_ { FunctionType::Script => { @@ -400,7 +396,6 @@ impl Compiler { let ops = unsafe { &mut (*self.ctx.function).chunk.ops }; match ops.len().checked_sub(2) { - Some(idx) if ops[idx] == op::GET_PROPERTY => ops[idx] = op::INVOKE, Some(idx) if ops[idx] == op::GET_SUPER => ops[idx] = op::SUPER_INVOKE, Some(_) | None => self.emit_u8(op::CALL, span), } @@ -519,7 +514,11 @@ impl Compiler { }; } Expr::Literal(literal) => match literal { - ExprLiteral::Bool(true) => self.emit_u8(op::TRUE, span), + ExprLiteral::Bool(true) => { + println!("emitting true bool"); + + self.emit_u8(op::TRUE, span) + } ExprLiteral::Bool(false) => self.emit_u8(op::FALSE, span), ExprLiteral::Nil => self.emit_u8(op::NIL, span), ExprLiteral::Number(number) => { diff --git a/src/vm/disassembler.rs b/src/vm/disassembler.rs index e82361f..19f2e30 100644 --- a/src/vm/disassembler.rs +++ b/src/vm/disassembler.rs @@ -78,7 +78,6 @@ impl<'a> Disassembler<'a> { op::MODULUS => self.disassemble_op_simple("OP_MODULUS"), op::NOT => self.disassemble_op_simple("OP_NOT"), op::NEGATE => self.disassemble_op_simple("OP_NEGATE"), - op::PRINT => self.disassemble_op_simple("OP_PRINT"), op::JUMP => self.disassemble_op_jump("OP_JUMP", op_idx, true), op::JUMP_IF_FALSE => self.disassemble_op_jump("OP_JUMP_IF_FALSE", op_idx, true), op::LOOP => self.disassemble_op_jump("OP_LOOP", op_idx, false), @@ -292,22 +291,20 @@ mod tests { "\ let a = 123;\n\ let b = -a;\n\ - let c = a + b;\n\ - print c;", - "\ - 0000 OP_CONSTANT 0 == '123'\n\ - 0002 OP_DEFINE_GLOBAL 1 == 'a'\n\ - 0004 OP_GET_GLOBAL 1 == 'a'\n\ - 0006 OP_NEGATE\n\ - 0007 OP_DEFINE_GLOBAL 2 == 'b'\n\ - 0009 OP_GET_GLOBAL 1 == 'a'\n\ - 0011 OP_GET_GLOBAL 2 == 'b'\n\ - 0013 OP_ADD\n\ - 0014 OP_DEFINE_GLOBAL 3 == 'c'\n\ - 0016 OP_GET_GLOBAL 3 == 'c'\n\ - 0018 OP_PRINT\n\ - 0019 OP_NIL\n\ - 0020 OP_RETURN\n" + let c = a + b;", + concat!( + "0000 OP_CONSTANT 0 == '123'\n", + "0002 OP_DEFINE_GLOBAL 1 == 'a'\n", + "0004 OP_GET_GLOBAL 1 == 'a'\n", + "0006 OP_NEGATE\n", + "0007 OP_DEFINE_GLOBAL 2 == 'b'\n", + "0009 OP_GET_GLOBAL 1 == 'a'\n", + "0011 OP_GET_GLOBAL 2 == 'b'\n", + "0013 OP_ADD\n", + "0014 OP_DEFINE_GLOBAL 3 == 'c'\n", + "0016 OP_NIL\n", + "0017 OP_RETURN\n" + ) ), fn_define_empty: ( "fn sum (a, b) { }", @@ -367,22 +364,27 @@ mod tests { jump_to_false: ( "\ if (false) { - print 1; + println(1); } else { - print 2; + println(2); }", - "\ - 0000 OP_FALSE\n\ - 0001 OP_JUMP_IF_FALSE 1 -> 11\n\ - 0004 OP_POP\n\ - 0005 OP_CONSTANT 0 == '1'\n\ - 0007 OP_PRINT\n\ - 0008 OP_JUMP 8 -> 15\n\ - 0011 OP_POP\n\ - 0012 OP_CONSTANT 1 == '2'\n\ - 0014 OP_PRINT\n\ - 0015 OP_NIL\n\ - 0016 OP_RETURN\n" + concat!( + "0000 OP_FALSE\n", + "0001 OP_JUMP_IF_FALSE 1 -> 15\n", + "0004 OP_POP\n", + "0005 OP_GET_GLOBAL 0 == 'println'\n", + "0007 OP_CONSTANT 1 == '1'\n", + "0009 OP_CALL 1\n", + "0011 OP_POP\n", + "0012 OP_JUMP 12 -> 23\n", + "0015 OP_POP\n", + "0016 OP_GET_GLOBAL 0 == 'println'\n", + "0018 OP_CONSTANT 2 == '2'\n", + "0020 OP_CALL 1\n", + "0022 OP_POP\n", + "0023 OP_NIL\n", + "0024 OP_RETURN\n" + ) ), closure: ( r#" @@ -390,7 +392,7 @@ mod tests { fn foo(param) { fn f_() { - print param; + return param; } f = f_; @@ -407,9 +409,7 @@ mod tests { "| 0000 OP_CLOSURE 0 == ''\n", "| 0001 CAPTURE [local -> 1]\n", " | 0000 OP_GET_UPVALUE 0\n", - " | 0002 OP_PRINT\n", - " | 0003 OP_NIL\n", - " | 0004 OP_RETURN\n", + " | 0002 OP_RETURN\n", "| 0004 OP_GET_LOCAL 2\n", "| 0006 OP_SET_GLOBAL 1 == 'f'\n", "| 0008 OP_POP\n", @@ -443,7 +443,7 @@ mod tests { let greeter = Greeter(\"Hello\"); - print greeter.greet(\"World\"); // out: Hello World", + println(greeter.greet(\"World\")); // out: Hello World", concat!( "0000 OP_CLASS 0 == 'Greeter'\n", "0002 OP_DEFINE_GLOBAL 0 == 'Greeter'\n", @@ -456,7 +456,8 @@ mod tests { "| 0000 OP_GET_LOCAL 1\n", "| 0002 OP_GET_LOCAL 0\n", "| 0004 OP_SET_PROPERTY 0 == 'greeting'\n", - "| 0006 OP_POP\n| 0007 OP_GET_LOCAL 0\n", + "| 0006 OP_POP\n", + "| 0007 OP_GET_LOCAL 0\n", "| 0009 OP_RETURN\n", "0014 OP_METHOD 3 == 'init'\n", "0016 OP_CLOSURE 4 == ''\n", @@ -473,13 +474,15 @@ mod tests { "0023 OP_CONSTANT 6 == 'Hello'\n", "0025 OP_CALL 1\n", "0027 OP_DEFINE_GLOBAL 7 == 'greeter'\n", - "0029 OP_GET_GLOBAL 7 == 'greeter'\n", - "0031 OP_GET_PROPERTY 5 == 'greet'\n", - "0033 OP_CONSTANT 8 == 'World'\n", - "0035 OP_CALL 1\n", - "0037 OP_PRINT\n", - "0038 OP_NIL\n", - "0039 OP_RETURN\n" + "0029 OP_GET_GLOBAL 8 == 'println'\n", + "0031 OP_GET_GLOBAL 7 == 'greeter'\n", + "0033 OP_GET_PROPERTY 5 == 'greet'\n", + "0035 OP_CONSTANT 9 == 'World'\n", + "0037 OP_CALL 1\n", + "0039 OP_CALL 1\n", + "0041 OP_POP\n", + "0042 OP_NIL\n", + "0043 OP_RETURN\n", ) ), } diff --git a/src/vm/mod.rs b/src/vm/mod.rs index 70a8009..a255bc8 100644 --- a/src/vm/mod.rs +++ b/src/vm/mod.rs @@ -165,12 +165,11 @@ impl VM { op::MODULUS => self.op_modulus(), op::NOT => self.op_not(), op::NEGATE => self.op_negate(), - op::PRINT => self.op_print(stdout), op::JUMP => self.op_jump(), op::JUMP_IF_FALSE => self.op_jump_if_false(), op::LOOP => self.op_loop(), - op::CALL => self.op_call(), - op::INVOKE => self.op_invoke(), + op::CALL => self.op_call(stdout), + op::INVOKE => self.op_invoke(stdout), op::SUPER_INVOKE => self.op_super_invoke(), op::CLOSURE => self.op_closure(), op::CLOSE_UPVALUE => self.op_close_upvalue(), @@ -591,12 +590,6 @@ impl VM { } } - fn op_print(&mut self, stdout: &mut impl Write) -> Result<()> { - let value = self.pop(); - writeln!(stdout, "{value}") - .or_else(|_| self.err(IoError::WriteError { file: "stdout".to_string() })) - } - fn op_jump(&mut self) -> Result<()> { let offset = self.read_u16() as usize; self.frame.ip = unsafe { self.frame.ip.add(offset) }; @@ -630,19 +623,19 @@ impl VM { /// Will return [`Err(TypeError::NotCallable)`] otherwise. /// /// This consumes 1 byte op for the `arg_count` - fn op_call(&mut self) -> Result<()> { + fn op_call(&mut self, stdout: &mut impl Write) -> Result<()> { let arg_count = self.read_u8() as usize; let callee = unsafe { *self.peek(arg_count) }; - self.call_value(callee, arg_count) + self.call_value(callee, arg_count, stdout) } - fn op_invoke(&mut self) -> Result<()> { + fn op_invoke(&mut self, stdout: &mut impl Write) -> Result<()> { let name = unsafe { self.read_value().as_object().string }; let arg_count = self.read_u8() as usize; let instance = unsafe { (*self.peek(arg_count)).as_object().instance }; match unsafe { (*instance).fields.get(&name) } { - Some(&value) => self.call_value(value, arg_count), + Some(&value) => self.call_value(value, arg_count, stdout), None => match unsafe { (*(*instance).class).methods.get(&name) } { Some(&method) => self.call_closure(method, arg_count), None => self.err(AttributeError::NoSuchAttribute { @@ -830,7 +823,12 @@ impl VM { /// - [`ObjectType::Native`] /// /// Will return [`Err(TypeError::NotCallable)`] otherwise. - fn call_value(&mut self, value: Value, arg_count: usize) -> Result<()> { + fn call_value( + &mut self, + value: Value, + arg_count: usize, + stdout: &mut impl Write, + ) -> Result<()> { if value.is_object() { let object = value.as_object(); match object.type_() { @@ -839,7 +837,7 @@ impl VM { } ObjectType::Class => self.call_class(unsafe { object.class }, arg_count), ObjectType::Closure => self.call_closure(unsafe { object.closure }, arg_count), - ObjectType::Native => self.call_native(unsafe { object.native }, arg_count), + ObjectType::Native => self.call_native(unsafe { object.native }, arg_count, stdout), _ => self.err(TypeError::NotCallable { type_: value.type_().to_string() }), } } else { @@ -921,7 +919,12 @@ impl VM { /// Call [`ObjectNative`] function /// /// These are functions provided by the language runtime and not written in the language - fn call_native(&mut self, native: *mut ObjectNative, arg_count: usize) -> Result<()> { + fn call_native( + &mut self, + native: *mut ObjectNative, + arg_count: usize, + stdout: &mut impl Write, + ) -> Result<()> { let value = match { unsafe { (*native).native } } { Native::Clock => { self.pop(); @@ -971,6 +974,48 @@ impl VM { } } } + Native::Print => { + if arg_count != 1 { + return self.err(TypeError::ArityMismatch { + name: "print".to_string(), + exp_args: 1, + got_args: arg_count, + }); + } + + let arg = self.pop(); + self.pop(); + + match write!(stdout, "{arg}") + .or_else(|_| self.err(IoError::WriteError { file: "stdout".to_string() })) + { + Ok(_) => Value::NIL, + Err(x) => { + return Err(x); + } + } + } + Native::PrintLn => { + if arg_count != 1 { + return self.err(TypeError::ArityMismatch { + name: "println".to_string(), + exp_args: 1, + got_args: arg_count, + }); + } + + let arg = self.pop(); + self.pop(); + + match writeln!(stdout, "{arg}") + .or_else(|_| self.err(IoError::WriteError { file: "stdout".to_string() })) + { + Ok(_) => Value::NIL, + Err(x) => { + return Err(x); + } + } + } }; self.push(value); @@ -1097,13 +1142,20 @@ impl Default for VM { let mut gc = Gc::default(); let mut globals = HashMap::with_capacity_and_hasher(256, BuildHasherDefault::default()); - let clock_string = gc.alloc("clock"); - let clock_native = Value::from(gc.alloc(ObjectNative::new(Native::Clock))); - globals.insert(clock_string, clock_native); - let len_string = gc.alloc("len"); - let len_native = Value::from(gc.alloc(ObjectNative::new(Native::Length))); - globals.insert(len_string, len_native); + globals.insert(gc.alloc("clock"), Value::from(gc.alloc(ObjectNative::new(Native::Clock)))); + globals.insert(gc.alloc("len"), Value::from(gc.alloc(ObjectNative::new(Native::Length)))); + globals.insert(gc.alloc("print"), Value::from(gc.alloc(ObjectNative::new(Native::Print)))); + globals + .insert(gc.alloc("println"), Value::from(gc.alloc(ObjectNative::new(Native::PrintLn)))); + + let print_string = gc.alloc("print"); + let print_native = Value::from(gc.alloc(ObjectNative::new(Native::Print))); + globals.insert(print_string, print_native); + + let println_string = gc.alloc("println"); + let println_native = Value::from(gc.alloc(ObjectNative::new(Native::PrintLn))); + globals.insert(println_string, println_native); let init_string = gc.alloc("init"); diff --git a/src/vm/object.rs b/src/vm/object.rs index 3628444..7f7d675 100644 --- a/src/vm/object.rs +++ b/src/vm/object.rs @@ -315,6 +315,8 @@ impl ObjectNative { pub enum Native { Clock, Length, + Print, + PrintLn, } impl Display for Native { @@ -322,6 +324,8 @@ impl Display for Native { match self { Native::Clock => write!(f, "clock"), Native::Length => write!(f, "len"), + Native::Print => write!(f, "print"), + Native::PrintLn => write!(f, "println"), } } } diff --git a/src/vm/op.rs b/src/vm/op.rs index 77fb56c..be2e582 100644 --- a/src/vm/op.rs +++ b/src/vm/op.rs @@ -64,8 +64,6 @@ iota! { // Pops a number from the stack, negates it, and pushes the result onto the // stack. NEGATE, - // Pops a value from the stack and prints it. - PRINT, // Reads a 2-byte offset, and increments the instruction pointer by that // offset. JUMP, diff --git a/vsc/snippets.json b/vsc/snippets.json index 849da7d..edb1b23 100644 --- a/vsc/snippets.json +++ b/vsc/snippets.json @@ -51,9 +51,14 @@ }, "Print": { "prefix": "print", - "body": ["print $1;$0"], + "body": ["print($1);$0"], "description": "Print value" }, + "PrintLn": { + "prefix": "println", + "body": ["println($1);$0"], + "description": "Print value with a newline" + }, "While": { "prefix": "while", "body": ["while ($1) {", " $2", "}$0"],