WSL should use & for getting a ^ and @ for getting a []
authorfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Sep 2017 00:57:27 +0000 (00:57 +0000)
committerfpizlo@apple.com <fpizlo@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 2 Sep 2017 00:57:27 +0000 (00:57 +0000)
https://bugs.webkit.org/show_bug.cgi?id=176245

Reviewed by Myles Maxfield.

Using \ as an operator was a bad decision since that's an escape character in so many contexts.

Henceforth, & is for making pointers, for example:

thread int^ foo() { int x; return &x; }

And @ is for making array references, for example:

thread int[] foo() { int[42] x; return @x; }

Having separate operators makes it easy to have pointers to fixed-size arrays:

thread int[42]^ foo() { int[42] x; return &x; }

* WebGPUShadingLanguageRI/Intrinsics.js:
(Intrinsics):
* WebGPUShadingLanguageRI/Lexer.js:
(Lexer.prototype.next):
(Lexer):
* WebGPUShadingLanguageRI/MakePtrExpression.js:
(MakePtrExpression.prototype.toString):
(MakePtrExpression):
* WebGPUShadingLanguageRI/Parse.js:
(parsePossibleSuffix):
(parsePossiblePrefix):
(parseFuncName):
* WebGPUShadingLanguageRI/StandardLibrary.js:
* WebGPUShadingLanguageRI/Test.js:
(TEST_simpleMakePtr):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@221511 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/WebGPUShadingLanguageRI/Intrinsics.js
Tools/WebGPUShadingLanguageRI/Lexer.js
Tools/WebGPUShadingLanguageRI/MakePtrExpression.js
Tools/WebGPUShadingLanguageRI/Parse.js
Tools/WebGPUShadingLanguageRI/StandardLibrary.js
Tools/WebGPUShadingLanguageRI/Test.js

index 2d451a8..dff32e3 100644 (file)
@@ -1,3 +1,40 @@
+2017-09-01  Filip Pizlo  <fpizlo@apple.com>
+
+        WSL should use & for getting a ^ and @ for getting a []
+        https://bugs.webkit.org/show_bug.cgi?id=176245
+
+        Reviewed by Myles Maxfield.
+        
+        Using \ as an operator was a bad decision since that's an escape character in so many contexts.
+        
+        Henceforth, & is for making pointers, for example:
+        
+        thread int^ foo() { int x; return &x; }
+        
+        And @ is for making array references, for example:
+        
+        thread int[] foo() { int[42] x; return @x; }
+        
+        Having separate operators makes it easy to have pointers to fixed-size arrays:
+        
+        thread int[42]^ foo() { int[42] x; return &x; }
+
+        * WebGPUShadingLanguageRI/Intrinsics.js:
+        (Intrinsics):
+        * WebGPUShadingLanguageRI/Lexer.js:
+        (Lexer.prototype.next):
+        (Lexer):
+        * WebGPUShadingLanguageRI/MakePtrExpression.js:
+        (MakePtrExpression.prototype.toString):
+        (MakePtrExpression):
+        * WebGPUShadingLanguageRI/Parse.js:
+        (parsePossibleSuffix):
+        (parsePossiblePrefix):
+        (parseFuncName):
+        * WebGPUShadingLanguageRI/StandardLibrary.js:
+        * WebGPUShadingLanguageRI/Test.js:
+        (TEST_simpleMakePtr):
+
 2017-09-01  Myles C. Maxfield  <mmaxfield@apple.com>
 
         WSL's lexer will never emit keyword tokens
index fa94fdc..3251fbe 100644 (file)
@@ -88,16 +88,16 @@ class Intrinsics {
         };
         
         this._map.set(
-            "native thread T^ operator\\[]<T>(thread T[],uint)",
+            "native thread T^ operator&[]<T>(thread T[],uint)",
             arrayElementPtr);
         this._map.set(
-            "native threadgroup T^ operator\\[]<T:primitive>(threadgroup T[],uint)",
+            "native threadgroup T^ operator&[]<T:primitive>(threadgroup T[],uint)",
             arrayElementPtr);
         this._map.set(
-            "native device T^ operator\\[]<T:primitive>(device T[],uint)",
+            "native device T^ operator&[]<T:primitive>(device T[],uint)",
             arrayElementPtr);
         this._map.set(
-            "native constant T^ operator\\[]<T:primitive>(constant T[],uint)",
+            "native constant T^ operator&[]<T:primitive>(constant T[],uint)",
             arrayElementPtr);
     }
     
index 6988b3f..2763070 100644 (file)
@@ -118,7 +118,7 @@ class Lexer {
         if (/^([0-9]*\.[0-9]+)|([0-9]+\.[0-9]*)/.test(relevantText))
             return result("doubleLiteral");
         
-        if (/^([{}()\[\]?:=+*\/,.%!~^&|<>\\;-]|->|=>|<=|==|!=|\+=|-=|\*=|\/=|%=|^=|\|=|&=)/.test(relevantText))
+        if (/^([{}()\[\]?:=+*\/,.%!~^&|<>@;-]|->|=>|<=|==|!=|\+=|-=|\*=|\/=|%=|^=|\|=|&=)/.test(relevantText))
             return result("punctuation");
         
         let remaining = relevantText.substring(0, 20).split(/\s/)[0];
index 5c3fdf1..13026d4 100644 (file)
@@ -35,6 +35,6 @@ class MakePtrExpression extends Expression {
     
     toString()
     {
-        return "\\(" + this.ptr + ")";
+        return "&(" + this.ptr + ")";
     }
 }
index a25fe46..eae859c 100644 (file)
@@ -382,7 +382,7 @@ function parse(program, origin, lineNumberOffset, text)
                 consume("]");
                 left = new DereferenceExpression(
                     token,
-                    new CallExpression(token, "operator\\[]", [], [left, index]));
+                    new CallExpression(token, "operator&[]", [], [left, index]));
                 break;
             }
             default:
@@ -399,9 +399,9 @@ function parse(program, origin, lineNumberOffset, text)
             return new CallAssignment(token, "operator" + token.text, parsePossiblePrefix());
         if (token = tryConsume("^"))
             return new DereferenceExpression(token, parsePossiblePrefix());
-        if (token = tryConsume("\\"))
-            return new MakePtrExpression(token, parsePossiblePrefix());
         if (token = tryConsume("&"))
+            return new MakePtrExpression(token, parsePossiblePrefix());
+        if (token = tryConsume("@"))
             return new MakeArrayRefExpression(token, parsePossiblePrefix());
         return parsePossibleSuffix();
     }
@@ -626,12 +626,11 @@ function parse(program, origin, lineNumberOffset, text)
     function parseFuncName()
     {
         if (tryConsume("operator")) {
-            let token = consume("+", "-", "*", "/", "%", "^", "&", "|", "<", ">", "<=", ">=", "!", "==", "++", "--", "\\");
-            if (token.text != "\\")
+            let token = consume("+", "-", "*", "/", "%", "^", "&", "|", "<", ">", "<=", ">=", "!", "==", "++", "--", "&");
+            if (token.text != "&" || !tryConsume("["))
                 return "operator" + token.text;
-            consume("[");
             consume("]");
-            return "operator\\[]";
+            return "operator&[]";
         }
         return consumeKind("identifier").text;
     }
index ebdb898..1bc08a7 100644 (file)
@@ -40,8 +40,8 @@ typedef uint = uint32;
 
 native int operator+(int, int);
 
-native thread T^ operator\\[]<T>(thread T[], uint);
-native threadgroup T^ operator\\[]<T:primitive>(threadgroup T[], uint);
-native device T^ operator\\[]<T:primitive>(device T[], uint);
-native constant T^ operator\\[]<T:primitive>(constant T[], uint);
+native thread T^ operator&[]<T>(thread T[], uint);
+native threadgroup T^ operator&[]<T:primitive>(threadgroup T[], uint);
+native device T^ operator&[]<T:primitive>(device T[], uint);
+native constant T^ operator&[]<T:primitive>(constant T[], uint);
 `;
index 97d3fcb..784e257 100644 (file)
@@ -171,7 +171,7 @@ function TEST_simpleMakePtr()
         thread int^ foo()
         {
             int x = 42;
-            return \\x;
+            return &x;
         }
     `);
     let result = callFunction(program, "foo", [], []);