Title: [222139] trunk/Tools
Revision
222139
Author
mmaxfi...@apple.com
Date
2017-09-17 20:39:19 -0700 (Sun, 17 Sep 2017)

Log Message

WSL needs to understand && and ||
https://bugs.webkit.org/show_bug.cgi?id=177062

Reviewed by Filip Pizlo.

Very similar to LogicalNot.

* WebGPUShadingLanguageRI/All.js:
* WebGPUShadingLanguageRI/Checker.js:
* WebGPUShadingLanguageRI/EBufferBuilder.js:
(EBufferBuilder.prototype.visitLogicalExpression):
* WebGPUShadingLanguageRI/Evaluator.js:
(Evaluator.prototype.visitLogicalExpression):
* WebGPUShadingLanguageRI/Lexer.js:
(Lexer.prototype.next):
(Lexer):
* WebGPUShadingLanguageRI/LogicalExpression.js: Added.
(LogicalExpression):
(LogicalExpression.prototype.get text):
(LogicalExpression.prototype.get left):
(LogicalExpression.prototype.get right):
(LogicalExpression.prototype.toString):
* WebGPUShadingLanguageRI/Parse.js:
(parseLeftLogicalExpression):
* WebGPUShadingLanguageRI/Rewriter.js:
(Rewriter.prototype.visitLogicalExpression):
* WebGPUShadingLanguageRI/Test.html:
* WebGPUShadingLanguageRI/Test.js:
* WebGPUShadingLanguageRI/Visitor.js:
(Visitor.prototype.visitProtocolDecl):

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (222138 => 222139)


--- trunk/Tools/ChangeLog	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/ChangeLog	2017-09-18 03:39:19 UTC (rev 222139)
@@ -1,5 +1,38 @@
 2017-09-17  Myles C. Maxfield  <mmaxfi...@apple.com>
 
+        WSL needs to understand && and ||
+        https://bugs.webkit.org/show_bug.cgi?id=177062
+
+        Reviewed by Filip Pizlo.
+
+        Very similar to LogicalNot.
+
+        * WebGPUShadingLanguageRI/All.js:
+        * WebGPUShadingLanguageRI/Checker.js:
+        * WebGPUShadingLanguageRI/EBufferBuilder.js:
+        (EBufferBuilder.prototype.visitLogicalExpression):
+        * WebGPUShadingLanguageRI/Evaluator.js:
+        (Evaluator.prototype.visitLogicalExpression):
+        * WebGPUShadingLanguageRI/Lexer.js:
+        (Lexer.prototype.next):
+        (Lexer):
+        * WebGPUShadingLanguageRI/LogicalExpression.js: Added.
+        (LogicalExpression):
+        (LogicalExpression.prototype.get text):
+        (LogicalExpression.prototype.get left):
+        (LogicalExpression.prototype.get right):
+        (LogicalExpression.prototype.toString):
+        * WebGPUShadingLanguageRI/Parse.js:
+        (parseLeftLogicalExpression):
+        * WebGPUShadingLanguageRI/Rewriter.js:
+        (Rewriter.prototype.visitLogicalExpression):
+        * WebGPUShadingLanguageRI/Test.html:
+        * WebGPUShadingLanguageRI/Test.js:
+        * WebGPUShadingLanguageRI/Visitor.js:
+        (Visitor.prototype.visitProtocolDecl):
+
+2017-09-17  Myles C. Maxfield  <mmaxfi...@apple.com>
+
         WSL needs float and double support
         https://bugs.webkit.org/show_bug.cgi?id=177058
 

Modified: trunk/Tools/WebGPUShadingLanguageRI/All.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/All.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/All.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -92,6 +92,7 @@
 load("Lexer.js");
 load("LexerToken.js");
 load("LiteralTypeChecker.js");
+load("LogicalExpression.js");
 load("LogicalNot.js");
 load("LoopChecker.js");
 load("MakeArrayRefExpression.js");

Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -257,23 +257,31 @@
         return this._program.intrinsics.bool;
     }
 
+    _requireBool(_expression_)
+    {
+        let type = _expression_.visit(this);
+        if (!type)
+            throw new Error("_expression_ has no type, but should be bool: " + _expression_);
+        if (!type.equals(this._program.intrinsics.bool))
+            throw new WError("_expression_ isn't a bool: " + _expression_);
+    }
+
     visitLogicalNot(node)
     {
-        let resultType = node.operand.visit(this);
-        if (!resultType)
-            throw new Error("Trying to negate something with no type: " + node.operand);
-        if (!resultType.equals(this._program.intrinsics.bool))
-            throw new WError("Trying to negate something that isn't a bool: " + node.operand);
+        this._requireBool(node.operand);
         return this._program.intrinsics.bool;
     }
 
+    visitLogicalExpression(node)
+    {
+        this._requireBool(node.left);
+        this._requireBool(node.right);
+        return this._program.intrinsics.bool;
+    }
+
     visitIfStatement(node)
     {
-        let conditionalResultType = node.conditional.visit(this);
-        if (!conditionalResultType)
-            throw new Error("Trying to negate something with no type: " + node.conditional);
-        if (!conditionalResultType.equals(this._program.intrinsics.bool))
-            throw new WError("Trying to negate something that isn't a bool: " + node.conditional);
+        this._requireBool(node.conditional);
         node.body.visit(this);
         if (node.elseBody)
             node.elseBody.visit(this);
@@ -281,11 +289,7 @@
 
     visitWhileLoop(node)
     {
-        let conditionalResultType = node.conditional.visit(this);
-        if (!conditionalResultType)
-            throw new Error("While loop conditional has no type: " + node.conditional);
-        if (!conditionalResultType.equals(this._program.intrinsics.bool))
-            throw new WError("While loop conditional isn't a bool: " + node.conditional);
+        this._requireBool(node.conditional);
         node.body.visit(this);
     }
 
@@ -292,11 +296,7 @@
     visitDoWhileLoop(node)
     {
         node.body.visit(this);
-        let conditionalResultType = node.conditional.visit(this);
-        if (!conditionalResultType)
-            throw new Error("Do-While loop conditional has no type: " + node.conditional);
-        if (!conditionalResultType.equals(this._program.intrinsics.bool))
-            throw new WError("Do-While loop conditional isn't a bool: " + node.conditional);
+        this._requireBool(node.conditional);
     }
 
     visitForLoop(node)
@@ -303,13 +303,8 @@
     {
         if (node.initialization)
             node.initialization.visit(this);
-        if (node.condition) {
-            let conditionResultType = node.condition.visit(this);
-            if (!conditionResultType)
-                throw new Error("For loop conditional has no type: " + node.conditional);
-            if (!conditionResultType.equals(this._program.intrinsics.bool))
-                throw new WError("For loop conditional isn't a bool: " + node.conditional);
-        }
+        if (node.condition)
+            this._requireBool(node.condition);
         if (node.increment)
             node.increment.visit(this);
         node.body.visit(this);

Modified: trunk/Tools/WebGPUShadingLanguageRI/EBufferBuilder.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/EBufferBuilder.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/EBufferBuilder.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -104,6 +104,12 @@
         super.visitLogicalNot(node);
     }
     
+    visitLogicalExpression(node)
+    {
+        node.ePtr = EPtr.box();
+        super.visitLogicalExpression(node);
+    }
+    
     visitLetExpression(node)
     {
         this._createEPtrForNode(node);

Modified: trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -166,6 +166,24 @@
         return node.ePtr.box(result);
     }
 
+    visitLogicalExpression(node)
+    {
+        let lhs = node.left.visit(this).loadValue();
+        let rhs = node.right.visit(this).loadValue();
+        let result;
+        switch (node.text) {
+        case "&&":
+            result = lhs && rhs;
+            break;
+        case "||":
+            result = lhs || rhs;
+            break;
+        default:
+            throw new Error("Unknown type of logical _expression_");
+        }
+        return node.ePtr.box(result);
+    }
+
     visitIfStatement(node)
     {
         if (node.conditional.visit(this).loadValue())

Modified: trunk/Tools/WebGPUShadingLanguageRI/Lexer.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Lexer.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Lexer.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -123,7 +123,7 @@
         if (/^[0-9]+/.test(relevantText))
             return result("intLiteral");
         
-        if (/^->|>=|<=|==|!=|\+=|-=|\*=|\/=|%=|^=|\|=|&=|\+\+|--|([{}()\[\]?:=+*\/,.%!~^&|<>@;-])/.test(relevantText))
+        if (/^->|>=|<=|==|!=|\+=|-=|\*=|\/=|%=|^=|\|=|&=|\+\+|--|&&|\|\||([{}()\[\]?:=+*\/,.%!~^&|<>@;-])/.test(relevantText))
             return result("punctuation");
         
         let remaining = relevantText.substring(0, 20).split(/\s/)[0];

Added: trunk/Tools/WebGPUShadingLanguageRI/LogicalExpression.js (0 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/LogicalExpression.js	                        (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/LogicalExpression.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+"use strict";
+
+class LogicalExpression extends _expression_ {
+    constructor(origin, text, left, right)
+    {
+        super(origin);
+        this._text = text;
+        this._left = left;
+        this._right = right;
+    }
+    
+    get text() { return this._text; }
+    get left() { return this._left; }
+    get right() { return this._right; }
+    
+    toString()
+    {
+        return "(" + this.left + " " + this.text + " " + this.right + ")";
+    }
+}
+

Modified: trunk/Tools/WebGPUShadingLanguageRI/Parse.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Parse.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Parse.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -507,7 +507,7 @@
     {
         return genericParseLeft(
             texts, nextParser,
-            (token, left, right) => new LogicalExpression(token, token.text, left, right));
+            (token, left, right) => new LogicalExpression(token, token.text, new CallExpression(left.origin, "bool", [], [left]), new CallExpression(right.origin, "bool", [], [right])));
     }
     
     function parsePossibleLogicalAnd()

Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -313,6 +313,13 @@
         result.ePtr = node.ePtr;
         return result;
     }
+    
+    visitLogicalExpression(node)
+    {
+        let result = new LogicalExpression(node.origin, node.text, node.left.visit(this), node.right.visit(this));
+        result.ePtr = node.ePtr;
+        return result;
+    }
 
     visitIfStatement(node)
     {

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.html (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.html	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.html	2017-09-18 03:39:19 UTC (rev 222139)
@@ -69,6 +69,7 @@
 <script src=""
 <script src=""
 <script src=""
+<script src=""
 <script src=""
 <script src=""
 <script src=""

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -527,8 +527,8 @@
 
 function TEST_lexerKeyword()
 {
-    let result = doLex("ident for while 123 123u { } {asd asd{ 1a3 1.2 + 3.4 + 1. + .2 1.2d 0.d .3d");
-    if (result.length != 23)
+    let result = doLex("ident for while 123 123u { } {asd asd{ 1a3 1.2 + 3.4 + 1. + .2 1.2d 0.d .3d && ||");
+    if (result.length != 25)
         throw new Error("Lexer emitted an incorrect number of tokens (expected 23): " + result.length);
     checkLexerToken(result[0],  0,  "identifier",    "ident");
     checkLexerToken(result[1],  6,  "keyword",       "for");
@@ -553,6 +553,8 @@
     checkLexerToken(result[20], 63, "floatLiteral",  "1.2d");
     checkLexerToken(result[21], 68, "floatLiteral",  "0.d");
     checkLexerToken(result[22], 72, "floatLiteral",  ".3d");
+    checkLexerToken(result[23], 76, "punctuation",   "&&");
+    checkLexerToken(result[24], 79, "punctuation",   "||");
 }
 
 function TEST_simpleNoReturn()
@@ -2790,6 +2792,52 @@
         (e) => e instanceof WTypeError);
 }
 
+function TEST_booleanMath()
+{
+    let program = doPrep(`
+        bool foo()
+        {
+            return true && true;
+        }
+        bool foo2()
+        {
+            return true && false;
+        }
+        bool foo3()
+        {
+            return false && true;
+        }
+        bool foo4()
+        {
+            return false && false;
+        }
+        bool foo5()
+        {
+            return true || true;
+        }
+        bool foo6()
+        {
+            return true || false;
+        }
+        bool foo7()
+        {
+            return false || true;
+        }
+        bool foo8()
+        {
+            return false || false;
+        }
+    `);
+    checkBool(program, callFunction(program, "foo", [], []), true);
+    checkBool(program, callFunction(program, "foo2", [], []), false);
+    checkBool(program, callFunction(program, "foo3", [], []), false);
+    checkBool(program, callFunction(program, "foo4", [], []), false);
+    checkBool(program, callFunction(program, "foo5", [], []), true);
+    checkBool(program, callFunction(program, "foo6", [], []), true);
+    checkBool(program, callFunction(program, "foo7", [], []), true);
+    checkBool(program, callFunction(program, "foo8", [], []), false);
+}
+
 let filter = /.*/; // run everything by default
 if (this["arguments"]) {
     for (let i = 0; i < arguments.length; i++) {

Modified: trunk/Tools/WebGPUShadingLanguageRI/Visitor.js (222138 => 222139)


--- trunk/Tools/WebGPUShadingLanguageRI/Visitor.js	2017-09-18 00:31:53 UTC (rev 222138)
+++ trunk/Tools/WebGPUShadingLanguageRI/Visitor.js	2017-09-18 03:39:19 UTC (rev 222139)
@@ -314,6 +314,12 @@
         node.operand.visit(this);
     }
     
+    visitLogicalExpression(node)
+    {
+        node.left.visit(this);
+        node.right.visit(this);
+    }
+    
     visitFunctionLikeBlock(node)
     {
         if (node.returnType)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to