diff --git a/examples/raytracer.sk b/examples/raytracer.sk index ad5ad6cb..87fd3e60 100644 --- a/examples/raytracer.sk +++ b/examples/raytracer.sk @@ -27,8 +27,7 @@ def render(width int, height int, pixels Int32Array) { var screenY = (y * 2.0 + 1 - height) / width for x in 0..width { var screenX = (x * 2.0 + 1 - width) / width - pixels[i] = scene.trace2D(screenX, -screenY).pack - i++ + pixels[i++] = scene.trace2D(screenX, -screenY).pack } } } diff --git a/skewc.js b/skewc.js index bd2a9f36..b03c31a7 100644 --- a/skewc.js +++ b/skewc.js @@ -116,8 +116,7 @@ return -1; } - var a = this.value.charCodeAt(this.index); - this.index = this.index + 1 | 0; + var a = this.value.charCodeAt((this.index = this.index + 1 | 0) + -1 | 0); if (a < 55296 || a >= 56320) { return a; @@ -127,8 +126,7 @@ return -1; } - var b = this.value.charCodeAt(this.index); - this.index = this.index + 1 | 0; + var b = this.value.charCodeAt((this.index = this.index + 1 | 0) + -1 | 0); return ((a << 10) + b | 0) + ((65536 - (55296 << 10) | 0) - 56320 | 0) | 0; }; @@ -454,8 +452,7 @@ } // Compress tokens to eliminate unused null gaps - tokens[count] = token; - count = count + 1 | 0; + tokens[(count = count + 1 | 0) + -1 | 0] = token; // Tokens that start with a greater than may need to be split var tokenKind = token.kind; @@ -7114,7 +7111,7 @@ // Factory functions // Getters, most of which should be inlineable when asserts are skipped in release Skew.Node = function(kind) { - this.id = Skew.Node._createID(); + this.id = Skew.Node._nextID = Skew.Node._nextID + 1 | 0; this.kind = kind; this.flags = 0; this.range = null; @@ -7541,11 +7538,6 @@ } }; - Skew.Node._createID = function() { - Skew.Node._nextID = Skew.Node._nextID + 1 | 0; - return Skew.Node._nextID; - }; - Skew.Node._symbolsOrStringsLookTheSame = function(left, right) { return left.symbol != null && left.symbol == right.symbol || left.symbol == null && right.symbol == null && left.asString() == right.asString(); }; @@ -9807,16 +9799,14 @@ var i = 1; while ((i + 1 | 0) < text.length) { - var c = text.charCodeAt(i); - i = i + 1 | 0; + var c = text.charCodeAt((i = i + 1 | 0) + -1 | 0); if (c == 92) { var escape = i - 1 | 0; builder.append(text.slice(start, escape)); if ((i + 1 | 0) < text.length) { - c = text.charCodeAt(i); - i = i + 1 | 0; + c = text.charCodeAt((i = i + 1 | 0) + -1 | 0); if (c == 110) { builder.append('\n'); @@ -9850,12 +9840,10 @@ else if (c == 120) { if ((i + 1 | 0) < text.length) { - var c0 = Skew.Parsing.parseHexCharacter(text.charCodeAt(i)); - i = i + 1 | 0; + var c0 = Skew.Parsing.parseHexCharacter(text.charCodeAt((i = i + 1 | 0) + -1 | 0)); if ((i + 1 | 0) < text.length) { - var c1 = Skew.Parsing.parseHexCharacter(text.charCodeAt(i)); - i = i + 1 | 0; + var c1 = Skew.Parsing.parseHexCharacter(text.charCodeAt((i = i + 1 | 0) + -1 | 0)); if (c0 != -1 && c1 != -1) { builder.append(String.fromCharCode(c0 << 4 | c1)); @@ -10281,7 +10269,7 @@ }; Skew.Symbol = function(kind, name) { - this.id = Skew.Symbol._createID(); + this.id = Skew.Symbol._nextID = Skew.Symbol._nextID + 1 | 0; this.kind = kind; this.name = name; this.rename = null; @@ -10485,11 +10473,6 @@ } }; - Skew.Symbol._createID = function() { - Skew.Symbol._nextID = Skew.Symbol._nextID + 1 | 0; - return Skew.Symbol._nextID; - }; - Skew.Symbol._substituteSymbols = function(node, symbols) { if (node.symbol != null) { node.symbol = in_IntMap.get(symbols, node.symbol.id, node.symbol); @@ -15449,8 +15432,7 @@ var variable = list2[i3]; if (variable.kind == Skew.SymbolKind.VARIABLE_ENUM) { - variable.value = new Skew.Node(Skew.NodeKind.CONSTANT).withContent(new Skew.IntContent(nextEnumValue)).withType(symbol.resolvedType).withRange(variable.range); - nextEnumValue = nextEnumValue + 1 | 0; + variable.value = new Skew.Node(Skew.NodeKind.CONSTANT).withContent(new Skew.IntContent((nextEnumValue = nextEnumValue + 1 | 0) + -1 | 0)).withType(symbol.resolvedType).withRange(variable.range); } } @@ -18946,8 +18928,7 @@ var name = prefix; while (this.isNameUsed(name)) { - count = count + 1 | 0; - name = prefix + count.toString(); + name = prefix + (count = count + 1 | 0).toString(); } this.reserveName(name, null); @@ -19351,7 +19332,7 @@ }; Skew.Type = function(kind, symbol) { - this.id = Skew.Type._createID(); + this.id = Skew.Type._nextID = Skew.Type._nextID + 1 | 0; this.kind = kind; this.symbol = symbol; this.environment = null; @@ -19449,23 +19430,13 @@ } }; - Skew.Type._createID = function() { - Skew.Type._nextID = Skew.Type._nextID + 1 | 0; - return Skew.Type._nextID; - }; - Skew.Environment = function(parameters, substitutions) { - this.id = Skew.Environment._createID(); + this.id = Skew.Environment._nextID = Skew.Environment._nextID + 1 | 0; this.parameters = parameters; this.substitutions = substitutions; this.mergeCache = null; }; - Skew.Environment._createID = function() { - Skew.Environment._nextID = Skew.Environment._nextID + 1 | 0; - return Skew.Environment._nextID; - }; - Skew.TypeCache = function() { this.boolType = null; this.boxType = null; @@ -20783,7 +20754,7 @@ Skew.NATIVE_LIBRARY_CPP = '\nclass bool {\n def toString string {\n return self ? "true" : "false"\n }\n}\n\nclass int {\n def toString string {\n return dynamic.intToString(self)\n }\n}\n\nclass double {\n def toString string {\n return dynamic.doubleToString(self)\n }\n\n def isNaN bool {\n return self != self\n }\n}\n'; Skew.NATIVE_LIBRARY_CS = '\n@using("System.Diagnostics")\ndef assert(truth bool) {\n dynamic.Debug.Assert(truth)\n}\n\n@using("System")\nvar __random dynamic.Random = null\n\n@using("System")\n@import\nnamespace Math {\n @rename("Abs") if TARGET == .CSHARP\n def abs(x double) double\n @rename("Abs") if TARGET == .CSHARP\n def abs(x int) int\n\n @rename("Acos") if TARGET == .CSHARP\n def acos(x double) double\n @rename("Asin") if TARGET == .CSHARP\n def asin(x double) double\n @rename("Atan") if TARGET == .CSHARP\n def atan(x double) double\n @rename("Atan2") if TARGET == .CSHARP\n def atan2(x double, y double) double\n\n @rename("Sin") if TARGET == .CSHARP\n def sin(x double) double\n @rename("Cos") if TARGET == .CSHARP\n def cos(x double) double\n @rename("Tan") if TARGET == .CSHARP\n def tan(x double) double\n\n @rename("Floor") if TARGET == .CSHARP\n def floor(x double) double\n @rename("Ceiling") if TARGET == .CSHARP\n def ceil(x double) double\n @rename("Round") if TARGET == .CSHARP\n def round(x double) double\n\n @rename("Exp") if TARGET == .CSHARP\n def exp(x double) double\n @rename("Log") if TARGET == .CSHARP\n def log(x double) double\n @rename("Pow") if TARGET == .CSHARP\n def pow(x double, y double) double\n @rename("Sqrt") if TARGET == .CSHARP\n def sqrt(x double) double\n\n @rename("Max") if TARGET == .CSHARP\n def max(x double, y double) double\n @rename("Max") if TARGET == .CSHARP\n def max(x int, y int) int\n\n @rename("Min") if TARGET == .CSHARP\n def min(x double, y double) double\n @rename("Min") if TARGET == .CSHARP\n def min(x int, y int) int\n\n def random double {\n if __random == null { __random = dynamic.Random.new() }\n return __random.NextDouble()\n }\n}\n\nclass double {\n def isFinite bool {\n return !isNaN && !dynamic.double.IsInfinity(self)\n }\n\n def isNaN bool {\n return dynamic.double.IsNaN(self)\n }\n}\n\n@using("System.Text")\n@import\nclass StringBuilder {\n @rename("Append")\n def append(x string)\n\n @rename("ToString")\n def toString string\n}\n\nclass bool {\n @rename("ToString")\n def toString string {\n return self ? "true" : "false"\n }\n}\n\nclass int {\n @rename("ToString")\n def toString string\n\n def >>>(x int) int {\n return dynamic.unchecked(self as dynamic.uint >> x) as int\n }\n}\n\nclass double {\n @rename("ToString")\n def toString string\n}\n\nclass string {\n @rename("CompareTo")\n def <=>(x string) int\n\n @rename("StartsWith")\n def startsWith(x string) bool\n\n @rename("EndsWith")\n def endsWith(x string) bool\n\n @rename("Contains")\n def in(x string) bool\n\n @rename("IndexOf")\n def indexOf(x string) int\n\n @rename("LastIndexOf")\n def lastIndexOf(x string) int\n\n @rename("Replace")\n def replaceAll(before string, after string) string\n\n @rename("Substring") {\n def slice(start int) string\n def slice(start int, end int) string\n }\n\n @rename("ToLower")\n def toLowerCase string\n\n @rename("ToUpper")\n def toUpperCase string\n\n def count int {\n return (self as dynamic).Length\n }\n\n def get(index int) string {\n return fromCodeUnit(self[index])\n }\n\n def repeat(times int) string {\n var result = ""\n for i in 0..times {\n result += self\n }\n return result\n }\n\n @using("System.Linq")\n @using("System")\n def split(separator string) List {\n var separators = [separator]\n return dynamic.Enumerable.ToList((self as dynamic).Split(dynamic.Enumerable.ToArray(separators as dynamic), dynamic.StringSplitOptions.None))\n }\n\n def join(parts List) string {\n return dynamic.string.Join(self, parts)\n }\n\n def slice(start int, end int) string {\n return (self as dynamic).Substring(start, end - start)\n }\n\n def codeUnits List {\n var result List = []\n for i in 0..count {\n result.append(self[i])\n }\n return result\n }\n}\n\nnamespace string {\n def fromCodeUnit(codeUnit int) string {\n return dynamic.string.new(codeUnit as dynamic.char, 1)\n }\n\n def fromCodeUnits(codeUnits List) string {\n var builder = StringBuilder.new\n for codeUnit in codeUnits {\n builder.append(codeUnit as dynamic.char)\n }\n return builder.toString\n }\n}\n\n@using("System.Collections.Generic")\nclass List {\n @rename("Contains")\n def in(x T) bool\n\n @rename("Add")\n def append(value T)\n\n @rename("AddRange")\n def append(value List)\n\n @rename("Sort")\n def sort(x fn(T, T) int)\n\n @rename("Reverse")\n def reverse\n\n @rename("RemoveAll")\n def removeIf(x fn(T) bool)\n\n @rename("RemoveAt")\n def removeAt(x int)\n\n @rename("Remove")\n def removeOne(x T)\n\n @rename("TrueForAll")\n def all(x fn(T) bool) bool\n\n @rename("ForEach")\n def each(x fn(T))\n\n @rename("FindAll")\n def filter(x fn(T) bool) List\n\n @rename("ConvertAll")\n def map(x fn(T) R) List\n\n @rename("IndexOf")\n def indexOf(x T) int\n\n @rename("LastIndexOf")\n def lastIndexOf(x T) int\n\n @rename("Insert")\n def insert(x int, value T)\n\n @rename("InsertRange")\n def insert(x int, value List)\n\n def appendOne(x T) {\n if !(x in self) {\n append(x)\n }\n }\n\n def removeRange(start int, end int) {\n (self as dynamic).RemoveRange(start, end - start)\n }\n\n @using("System.Linq") {\n @rename("SequenceEqual")\n def equals(x List) bool\n\n @rename("First")\n def first T\n\n @rename("Last")\n def last T\n }\n\n def any(callback fn(T) bool) bool {\n return !all(x => !callback(x))\n }\n\n def isEmpty bool {\n return count == 0\n }\n\n def count int {\n return (self as dynamic).Count\n }\n\n def prepend(value T) {\n insert(0, value)\n }\n\n def prepend(values List) {\n var count = values.count\n for i in 0..count {\n prepend(values[count - i - 1])\n }\n }\n\n def removeFirst {\n removeAt(0)\n }\n\n def removeLast {\n removeAt(count - 1)\n }\n\n def takeFirst T {\n var value = first\n removeFirst\n return value\n }\n\n def takeLast T {\n var value = last\n removeLast\n return value\n }\n\n def takeAt(x int) T {\n var value = self[x]\n removeAt(x)\n return value\n }\n\n def takeRange(start int, end int) List {\n var value = slice(start, end)\n removeRange(start, end)\n return value\n }\n\n def slice(start int) List {\n return slice(start, count)\n }\n\n def slice(start int, end int) List {\n return (self as dynamic).GetRange(start, end - start)\n }\n\n def clone List {\n var clone = new\n clone.append(self)\n return clone\n }\n}\n\n@using("System.Collections.Generic")\n@rename("Dictionary")\nclass StringMap {\n @rename("Count")\n def count int\n\n @rename("ContainsKey")\n def in(key string) bool\n\n @rename("Remove")\n def remove(key string)\n\n def isEmpty bool {\n return count == 0\n }\n\n def {...}(key string, value T) StringMap {\n (self as dynamic).Add(key, value)\n return self\n }\n\n def get(key string, value T) T {\n return key in self ? self[key] : value\n }\n\n def keys List {\n return dynamic.System.Linq.Enumerable.ToList((self as dynamic).Keys)\n }\n\n def values List {\n return dynamic.System.Linq.Enumerable.ToList((self as dynamic).Values)\n }\n\n def clone StringMap {\n var clone = new\n for key in keys {\n clone[key] = self[key]\n }\n return clone\n }\n\n def each(x fn(string, T)) {\n for pair in self as dynamic {\n x(pair.Key, pair.Value)\n }\n }\n}\n\n@using("System.Collections.Generic")\n@rename("Dictionary")\nclass IntMap {\n @rename("Count")\n def count int\n\n @rename("ContainsKey")\n def in(key int) bool\n\n @rename("Remove")\n def remove(key int)\n\n def isEmpty bool {\n return count == 0\n }\n\n def {...}(key int, value T) IntMap {\n (self as dynamic).Add(key, value)\n return self\n }\n\n def get(key int, value T) T {\n return key in self ? self[key] : value\n }\n\n def keys List {\n return dynamic.System.Linq.Enumerable.ToList((self as dynamic).Keys)\n }\n\n def values List {\n return dynamic.System.Linq.Enumerable.ToList((self as dynamic).Values)\n }\n\n def clone IntMap {\n var clone = new\n for key in keys {\n clone[key] = self[key]\n }\n return clone\n }\n\n def each(x fn(int, T)) {\n for pair in self as dynamic {\n x(pair.Key, pair.Value)\n }\n }\n}\n'; Skew.NATIVE_LIBRARY_JS = '\nconst __extends = (derived dynamic, base dynamic) => {\n derived.prototype = dynamic.Object.create(base.prototype)\n derived.prototype.constructor = derived\n}\n\nconst __imul fn(int, int) int = dynamic.Math.imul ? dynamic.Math.imul : (a, b) => {\n const ah dynamic = (a >> 16) & 65535\n const bh dynamic = (b >> 16) & 65535\n const al dynamic = a & 65535\n const bl dynamic = b & 65535\n return al * bl + ((ah * bl + al * bh) << 16) | 0\n}\n\nconst __isInt = (value dynamic) => value == (value | 0)\nconst __isBool = (value dynamic) => value == !!value\nconst __isDouble = (value dynamic) => value == +value || dynamic.isNaN(value)\nconst __isString = (value dynamic) => dynamic.typeof(value) == "string"\n\ndef assert(truth bool) {\n if !truth {\n throw dynamic.Error("Assertion failed")\n }\n}\n\n@import\nnamespace Math {}\n\nclass double {\n def isFinite bool {\n return dynamic.isFinite(self)\n }\n\n def isNaN bool {\n return dynamic.isNaN(self)\n }\n}\n\nclass string {\n def <=>(x string) int {\n return ((x as dynamic < self) as int) - ((x as dynamic > self) as int)\n }\n\n def startsWith(text string) bool {\n return count >= text.count && slice(0, text.count) == text\n }\n\n def endsWith(text string) bool {\n return count >= text.count && slice(count - text.count) == text\n }\n\n def replaceAll(before string, after string) string {\n return after.join(self.split(before))\n }\n\n def in(value string) bool {\n return indexOf(value) != -1\n }\n\n def count int {\n return (self as dynamic).length\n }\n\n def [](index int) int {\n return (self as dynamic).charCodeAt(index)\n }\n\n def get(index int) string {\n return (self as dynamic)[index]\n }\n\n def repeat(times int) string {\n var result = ""\n for i in 0..times {\n result += self\n }\n return result\n }\n\n def join(parts List) string {\n return (parts as dynamic).join(self)\n }\n\n def codeUnits List {\n var result List = []\n for i in 0..count {\n result.append(self[i])\n }\n return result\n }\n}\n\nnamespace string {\n def fromCodeUnit(codeUnit int) string {\n return dynamic.String.fromCharCode(codeUnit)\n }\n\n def fromCodeUnits(codeUnits List) string {\n var result = ""\n for codeUnit in codeUnits {\n result += string.fromCodeUnit(codeUnit)\n }\n return result\n }\n}\n\nclass StringBuilder {\n var buffer = ""\n\n def new {\n }\n\n def append(x string) {\n buffer += x\n }\n\n def toString string {\n return buffer\n }\n}\n\n@rename("Array")\nclass List {\n @rename("shift") {\n def removeFirst\n def takeFirst T\n }\n\n @rename("pop") {\n def removeLast\n def takeLast T\n }\n\n @rename("unshift")\n def prepend(x T)\n\n @rename("push")\n def append(x T)\n\n @rename("every") if TARGET == .JAVASCRIPT\n def all(x fn(T) bool) bool\n\n @rename("some") if TARGET == .JAVASCRIPT\n def any(x fn(T) bool) bool\n\n @rename("slice") if TARGET == .JAVASCRIPT\n def clone List\n\n @rename("forEach") if TARGET == .JAVASCRIPT\n def each(x fn(T))\n\n def in(value T) bool {\n return indexOf(value) != -1\n }\n\n def isEmpty bool {\n return count == 0\n }\n\n def count int {\n return (self as dynamic).length\n }\n\n def first T {\n return self[0]\n }\n\n def last T {\n return self[count - 1]\n }\n\n def prepend(values List) {\n var count = values.count\n for i in 0..count {\n prepend(values[count - i - 1])\n }\n }\n\n def append(values List) {\n for value in values {\n append(value)\n }\n }\n\n def insert(index int, values List) {\n for value in values {\n insert(index, value)\n index++\n }\n }\n\n def insert(index int, value T) {\n (self as dynamic).splice(index, 0, value)\n }\n\n def removeAt(x int) {\n (self as dynamic).splice(x, 1)\n }\n\n def takeAt(x int) T {\n return (self as dynamic).splice(x, 1)[0]\n }\n\n def takeRange(start int, end int) List {\n return (self as dynamic).splice(start, end - start)\n }\n\n def appendOne(value T) {\n if !(value in self) {\n append(value)\n }\n }\n\n def removeOne(value T) {\n var index = indexOf(value)\n if index >= 0 {\n removeAt(index)\n }\n }\n\n def removeRange(start int, end int) {\n (self as dynamic).splice(start, end - start)\n }\n\n def removeIf(callback fn(T) bool) {\n var index = 0\n\n # Remove elements in place\n for i in 0..count {\n if !callback(self[i]) {\n if index < i {\n self[index] = self[i]\n }\n index++\n }\n }\n\n # Shrink the array to the correct size\n while index < count {\n removeLast\n }\n }\n\n def equals(other List) bool {\n if count != other.count {\n return false\n }\n for i in 0..count {\n if self[i] != other[i] {\n return false\n }\n }\n return true\n }\n}\n\nnamespace List {\n def new List {\n return [] as dynamic\n }\n}\n\nnamespace StringMap {\n def new StringMap {\n return dynamic.Object.create(null)\n }\n}\n\nclass StringMap {\n def {...}(key string, value T) StringMap {\n self[key] = value\n return self\n }\n\n def count int {\n return keys.count\n }\n\n def isEmpty bool {\n for key in self as dynamic {\n return false\n }\n return true\n }\n\n def get(key string, defaultValue T) T {\n var value = self[key]\n return value != dynamic.void(0) ? value : defaultValue # Compare against undefined so the key is only hashed once for speed\n }\n\n def keys List {\n return dynamic.Object.keys(self)\n }\n\n def values List {\n var values List = []\n for key in self as dynamic {\n values.append(self[key])\n }\n return values\n }\n\n def clone StringMap {\n var clone = new\n for key in keys {\n clone[key] = self[key]\n }\n return clone\n }\n\n def remove(key string) {\n dynamic.delete(self[key])\n }\n\n def each(x fn(string, T)) {\n for key in self as dynamic {\n x(key, self[key])\n }\n }\n}\n\nnamespace IntMap {\n def new IntMap {\n return {} as dynamic\n }\n}\n\nclass IntMap {\n def {...}(key int, value T) IntMap {\n self[key] = value\n return self\n }\n\n def count int {\n return values.count\n }\n\n def isEmpty bool {\n for key in self as dynamic {\n return false\n }\n return true\n }\n\n def get(key int, defaultValue T) T {\n var value = self[key]\n return value != dynamic.void(0) ? value : defaultValue # Compare against undefined so the key is only hashed once for speed\n }\n\n def keys List {\n var keys List = []\n for key in self as dynamic {\n keys.append(key as int)\n }\n return keys\n }\n\n def values List {\n var values List = []\n for key in self as dynamic {\n values.append(self[key])\n }\n return values\n }\n\n def clone IntMap {\n var clone = new\n for key in keys {\n clone[key] = self[key]\n }\n return clone\n }\n\n def remove(key int) {\n dynamic.delete(self[key])\n }\n\n def each(x fn(int, T)) {\n for key in self as dynamic {\n x(key as int, self[key])\n }\n }\n}\n'; - Skew.UNICODE_LIBRARY = '\nnamespace Unicode {\n enum Encoding {\n UTF8\n UTF16\n UTF32\n }\n\n const STRING_ENCODING Encoding =\n TARGET == .CSHARP || TARGET == .JAVASCRIPT ? .UTF16 :\n .UTF32\n\n class StringIterator {\n var value = ""\n var index = 0\n var stop = 0\n\n def reset(text string, start int) StringIterator {\n value = text\n index = start\n stop = text.count\n return self\n }\n\n def countCodePointsUntil(stop int) int {\n var count = 0\n while index < stop && nextCodePoint >= 0 {\n count++\n }\n return count\n }\n\n if STRING_ENCODING == .UTF8 {\n def nextCodePoint int {\n if index >= stop { return -1 }\n var a = value[index]\n index++\n if a < 0xC0 { return a }\n if index >= stop { return -1 }\n var b = value[index]\n index++\n if a < 0xE0 { return ((a & 0x1F) << 6) | (b & 0x3F) }\n if index >= stop { return -1 }\n var c = value[index]\n index++\n if a < 0xF0 { return ((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F) }\n if index >= stop { return -1 }\n var d = value[index]\n index++\n return ((a & 0x07) << 18) | ((b & 0x3F) << 12) | ((c & 0x3F) << 6) | (d & 0x3F)\n }\n }\n\n else if STRING_ENCODING == .UTF16 {\n def nextCodePoint int {\n if index >= stop { return -1 }\n var a = value[index]\n index++\n if a < 0xD800 || a >= 0xDC00 { return a }\n if index >= stop { return -1 }\n var b = value[index]\n index++\n return (a << 10) + b + (0x10000 - (0xD800 << 10) - 0xDC00)\n }\n }\n\n else {\n def nextCodePoint int {\n if index >= stop { return -1 }\n var c = value[index]\n index++\n return c\n }\n }\n }\n\n namespace StringIterator {\n const INSTANCE = StringIterator.new\n }\n\n def codeUnitCountForCodePoints(codePoints List, encoding Encoding) int {\n var count = 0\n\n switch encoding {\n case .UTF8 {\n for codePoint in codePoints {\n if codePoint < 0x80 { count++ }\n else if codePoint < 0x800 { count += 2 }\n else if codePoint < 0x10000 { count += 3 }\n else { count += 4 }\n }\n }\n\n case .UTF16 {\n for codePoint in codePoints {\n if codePoint < 0x10000 { count++ }\n else { count += 2 }\n }\n }\n\n case .UTF32 {\n count = codePoints.count\n }\n }\n\n return count\n }\n}\n\nclass string {\n if Unicode.STRING_ENCODING == .UTF32 {\n def codePoints List {\n return codeUnits\n }\n }\n\n else {\n def codePoints List {\n var codePoints List = []\n var instance = Unicode.StringIterator.INSTANCE\n instance.reset(self, 0)\n\n while true {\n var codePoint = instance.nextCodePoint\n if codePoint < 0 {\n return codePoints\n }\n codePoints.append(codePoint)\n }\n }\n }\n}\n\nnamespace string {\n def fromCodePoints(codePoints List) string {\n var builder = StringBuilder.new\n for codePoint in codePoints {\n builder.append(fromCodePoint(codePoint))\n }\n return builder.toString\n }\n\n if Unicode.STRING_ENCODING == .UTF8 {\n def fromCodePoint(codePoint int) string {\n return\n codePoint < 0x80 ? fromCodeUnit(codePoint) : (\n codePoint < 0x800 ? fromCodeUnit(((codePoint >> 6) & 0x1F) | 0xC0) : (\n codePoint < 0x10000 ? fromCodeUnit(((codePoint >> 12) & 0x0F) | 0xE0) : (\n fromCodeUnit(((codePoint >> 18) & 0x07) | 0xF0)\n ) + fromCodeUnit(((codePoint >> 12) & 0x3F) | 0x80)\n ) + fromCodeUnit(((codePoint >> 6) & 0x3F) | 0x80)\n ) + fromCodeUnit((codePoint & 0x3F) | 0x80)\n }\n }\n\n else if Unicode.STRING_ENCODING == .UTF16 {\n def fromCodePoint(codePoint int) string {\n return codePoint < 0x10000 ? fromCodeUnit(codePoint) :\n fromCodeUnit(((codePoint - 0x10000) >> 10) + 0xD800) +\n fromCodeUnit(((codePoint - 0x10000) & ((1 << 10) - 1)) + 0xDC00)\n }\n }\n\n else {\n def fromCodePoint(codePoint int) string {\n return fromCodeUnit(codePoint)\n }\n }\n}\n'; + Skew.UNICODE_LIBRARY = '\nnamespace Unicode {\n enum Encoding {\n UTF8\n UTF16\n UTF32\n }\n\n const STRING_ENCODING Encoding =\n TARGET == .CSHARP || TARGET == .JAVASCRIPT ? .UTF16 :\n .UTF32\n\n class StringIterator {\n var value = ""\n var index = 0\n var stop = 0\n\n def reset(text string, start int) StringIterator {\n value = text\n index = start\n stop = text.count\n return self\n }\n\n def countCodePointsUntil(stop int) int {\n var count = 0\n while index < stop && nextCodePoint >= 0 {\n count++\n }\n return count\n }\n\n if STRING_ENCODING == .UTF8 {\n def nextCodePoint int {\n if index >= stop { return -1 }\n var a = value[index++]\n if a < 0xC0 { return a }\n if index >= stop { return -1 }\n var b = value[index++]\n if a < 0xE0 { return ((a & 0x1F) << 6) | (b & 0x3F) }\n if index >= stop { return -1 }\n var c = value[index++]\n if a < 0xF0 { return ((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F) }\n if index >= stop { return -1 }\n var d = value[index++]\n return ((a & 0x07) << 18) | ((b & 0x3F) << 12) | ((c & 0x3F) << 6) | (d & 0x3F)\n }\n }\n\n else if STRING_ENCODING == .UTF16 {\n def nextCodePoint int {\n if index >= stop { return -1 }\n var a = value[index++]\n if a < 0xD800 || a >= 0xDC00 { return a }\n if index >= stop { return -1 }\n var b = value[index++]\n return (a << 10) + b + (0x10000 - (0xD800 << 10) - 0xDC00)\n }\n }\n\n else {\n def nextCodePoint int {\n if index >= stop { return -1 }\n return value[index++]\n }\n }\n }\n\n namespace StringIterator {\n const INSTANCE = StringIterator.new\n }\n\n def codeUnitCountForCodePoints(codePoints List, encoding Encoding) int {\n var count = 0\n\n switch encoding {\n case .UTF8 {\n for codePoint in codePoints {\n if codePoint < 0x80 { count++ }\n else if codePoint < 0x800 { count += 2 }\n else if codePoint < 0x10000 { count += 3 }\n else { count += 4 }\n }\n }\n\n case .UTF16 {\n for codePoint in codePoints {\n if codePoint < 0x10000 { count++ }\n else { count += 2 }\n }\n }\n\n case .UTF32 {\n count = codePoints.count\n }\n }\n\n return count\n }\n}\n\nclass string {\n if Unicode.STRING_ENCODING == .UTF32 {\n def codePoints List {\n return codeUnits\n }\n }\n\n else {\n def codePoints List {\n var codePoints List = []\n var instance = Unicode.StringIterator.INSTANCE\n instance.reset(self, 0)\n\n while true {\n var codePoint = instance.nextCodePoint\n if codePoint < 0 {\n return codePoints\n }\n codePoints.append(codePoint)\n }\n }\n }\n}\n\nnamespace string {\n def fromCodePoints(codePoints List) string {\n var builder = StringBuilder.new\n for codePoint in codePoints {\n builder.append(fromCodePoint(codePoint))\n }\n return builder.toString\n }\n\n if Unicode.STRING_ENCODING == .UTF8 {\n def fromCodePoint(codePoint int) string {\n return\n codePoint < 0x80 ? fromCodeUnit(codePoint) : (\n codePoint < 0x800 ? fromCodeUnit(((codePoint >> 6) & 0x1F) | 0xC0) : (\n codePoint < 0x10000 ? fromCodeUnit(((codePoint >> 12) & 0x0F) | 0xE0) : (\n fromCodeUnit(((codePoint >> 18) & 0x07) | 0xF0)\n ) + fromCodeUnit(((codePoint >> 12) & 0x3F) | 0x80)\n ) + fromCodeUnit(((codePoint >> 6) & 0x3F) | 0x80)\n ) + fromCodeUnit((codePoint & 0x3F) | 0x80)\n }\n }\n\n else if Unicode.STRING_ENCODING == .UTF16 {\n def fromCodePoint(codePoint int) string {\n return codePoint < 0x10000 ? fromCodeUnit(codePoint) :\n fromCodeUnit(((codePoint - 0x10000) >> 10) + 0xD800) +\n fromCodeUnit(((codePoint - 0x10000) & ((1 << 10) - 1)) + 0xDC00)\n }\n }\n\n else {\n def fromCodePoint(codePoint int) string {\n return fromCodeUnit(codePoint)\n }\n }\n}\n'; Skew.DEFAULT_MESSAGE_LIMIT = 10; Skew.VALID_TARGETS = in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(Object.create(null), 'cpp', new Skew.CPlusPlusTarget()), 'cs', new Skew.CSharpTarget()), 'js', new Skew.JavaScriptTarget()), 'lisp-tree', new Skew.LispTreeTarget()); Skew.CSharpEmitter._isKeyword = in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(in_StringMap.insert(Object.create(null), 'abstract', 0), 'as', 0), 'base', 0), 'bool', 0), 'break', 0), 'byte', 0), 'case', 0), 'catch', 0), 'char', 0), 'checked', 0), 'class', 0), 'const', 0), 'continue', 0), 'decimal', 0), 'default', 0), 'delegate', 0), 'do', 0), 'double', 0), 'else', 0), 'enum', 0), 'event', 0), 'explicit', 0), 'extern', 0), 'false', 0), 'finally', 0), 'fixed', 0), 'float', 0), 'for', 0), 'foreach', 0), 'goto', 0), 'if', 0), 'implicit', 0), 'in', 0), 'int', 0), 'interface', 0), 'internal', 0), 'is', 0), 'lock', 0), 'long', 0), 'namespace', 0), 'new', 0), 'null', 0), 'object', 0), 'operator', 0), 'out', 0), 'override', 0), 'params', 0), 'private', 0), 'protected', 0), 'public', 0), 'readonly', 0), 'ref', 0), 'return', 0), 'sbyte', 0), 'sealed', 0), 'short', 0), 'sizeof', 0), 'stackalloc', 0), 'static', 0), 'string', 0), 'struct', 0), 'switch', 0), 'this', 0), 'throw', 0), 'true', 0), 'try', 0), 'typeof', 0), 'uint', 0), 'ulong', 0), 'unchecked', 0), 'unsafe', 0), 'ushort', 0), 'using', 0), 'virtual', 0), 'void', 0), 'volatile', 0), 'while', 0); diff --git a/src/core/node.sk b/src/core/node.sk index 9ed4e7d2..5c9d68e4 100644 --- a/src/core/node.sk +++ b/src/core/node.sk @@ -576,8 +576,7 @@ namespace Skew { namespace Node { def _createID int { - _nextID++ - return _nextID + return ++_nextID } var _nextID = 0 diff --git a/src/core/symbol.sk b/src/core/symbol.sk index d8e1f165..eab3cf6e 100644 --- a/src/core/symbol.sk +++ b/src/core/symbol.sk @@ -250,8 +250,7 @@ namespace Skew { var _nextID = 0 def _createID int { - _nextID++ - return _nextID + return ++_nextID } def _substituteSymbols(node Node, symbols IntMap) { diff --git a/src/frontend/parser.sk b/src/frontend/parser.sk index e910c393..9b54f102 100644 --- a/src/frontend/parser.sk +++ b/src/frontend/parser.sk @@ -1100,14 +1100,12 @@ namespace Skew.Parsing { var start = 1 # Append long runs of unescaped characters using a single slice for speed var i = 1 while i + 1 < text.count { - var c = text[i] - i++ + var c = text[i++] if c == '\\' { var escape = i - 1 builder.append(text.slice(start, escape)) if i + 1 < text.count { - c = text[i] - i++ + c = text[i++] if c == 'n' { builder.append("\n") start = i @@ -1134,11 +1132,9 @@ namespace Skew.Parsing { } else if c == 'x' { if i + 1 < text.count { - var c0 = parseHexCharacter(text[i]) - i++ + var c0 = parseHexCharacter(text[i++]) if i + 1 < text.count { - var c1 = parseHexCharacter(text[i]) - i++ + var c1 = parseHexCharacter(text[i++]) if c0 != -1 && c1 != -1 { builder.append(string.fromCodeUnit(c0 << 4 | c1)) start = i diff --git a/src/frontend/token.sk b/src/frontend/token.sk index b62b4a42..6a2aed97 100644 --- a/src/frontend/token.sk +++ b/src/frontend/token.sk @@ -68,8 +68,7 @@ namespace Skew { } # Compress tokens to eliminate unused null gaps - tokens[count] = token - count++ + tokens[count++] = token # Tokens that start with a greater than may need to be split var tokenKind = token.kind diff --git a/src/middle/resolving.sk b/src/middle/resolving.sk index fe770532..bb580e7f 100644 --- a/src/middle/resolving.sk +++ b/src/middle/resolving.sk @@ -352,8 +352,7 @@ namespace Skew.Resolving { var nextEnumValue = 0 for variable in symbol.variables { if variable.kind == .VARIABLE_ENUM { - variable.value = Node.createInt(nextEnumValue).withType(symbol.resolvedType).withRange(variable.range) - nextEnumValue++ + variable.value = Node.createInt(nextEnumValue++).withType(symbol.resolvedType).withRange(variable.range) } } symbol.flags |= Symbol.IS_VALUE_TYPE diff --git a/src/middle/scope.sk b/src/middle/scope.sk index 3e9dbe78..f7d81aa1 100644 --- a/src/middle/scope.sk +++ b/src/middle/scope.sk @@ -102,8 +102,7 @@ namespace Skew { var count = 0 var name = prefix while isNameUsed(name) { - count++ - name = prefix + count.toString + name = prefix + (++count).toString } reserveName(name, null) return name diff --git a/src/middle/type.sk b/src/middle/type.sk index dc6110e8..4ea5cbad 100644 --- a/src/middle/type.sk +++ b/src/middle/type.sk @@ -105,8 +105,7 @@ namespace Skew { } def _createID int { - _nextID++ - return _nextID + return ++_nextID } var _nextID = 0 @@ -133,8 +132,7 @@ namespace Skew { namespace Environment { def _createID int { - _nextID++ - return _nextID + return ++_nextID } var _nextID = 0 diff --git a/src/middle/unicode.sk b/src/middle/unicode.sk index 941a5e5c..6f2cbfcd 100644 --- a/src/middle/unicode.sk +++ b/src/middle/unicode.sk @@ -34,20 +34,16 @@ namespace Unicode { if STRING_ENCODING == .UTF8 { def nextCodePoint int { if index >= stop { return -1 } - var a = value[index] - index++ + var a = value[index++] if a < 0xC0 { return a } if index >= stop { return -1 } - var b = value[index] - index++ + var b = value[index++] if a < 0xE0 { return ((a & 0x1F) << 6) | (b & 0x3F) } if index >= stop { return -1 } - var c = value[index] - index++ + var c = value[index++] if a < 0xF0 { return ((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F) } if index >= stop { return -1 } - var d = value[index] - index++ + var d = value[index++] return ((a & 0x07) << 18) | ((b & 0x3F) << 12) | ((c & 0x3F) << 6) | (d & 0x3F) } } @@ -55,12 +51,10 @@ namespace Unicode { else if STRING_ENCODING == .UTF16 { def nextCodePoint int { if index >= stop { return -1 } - var a = value[index] - index++ + var a = value[index++] if a < 0xD800 || a >= 0xDC00 { return a } if index >= stop { return -1 } - var b = value[index] - index++ + var b = value[index++] return (a << 10) + b + (0x10000 - (0xD800 << 10) - 0xDC00) } } @@ -68,9 +62,7 @@ namespace Unicode { else { def nextCodePoint int { if index >= stop { return -1 } - var c = value[index] - index++ - return c + return value[index++] } } }