Diff
Modified: trunk/Tools/ChangeLog (221441 => 221442)
--- trunk/Tools/ChangeLog 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/ChangeLog 2017-08-31 20:57:45 UTC (rev 221442)
@@ -1,3 +1,36 @@
+2017-08-31 Filip Pizlo <fpi...@apple.com>
+
+ WSL should handle variable assignments and variable declarations
+ https://bugs.webkit.org/show_bug.cgi?id=176180
+
+ Reviewed by Saam Barati.
+
+ Just fills in VariableDecl and Assignment logic so that we can test variables.
+
+ * WebGPUShadingLanguageRI/Checker.js:
+ (Checker.prototype.visitProtocolDecl.set throw):
+ * WebGPUShadingLanguageRI/EBufferBuilder.js:
+ (EBufferBuilder.prototype._createEPtrForNode):
+ (EBufferBuilder.prototype.visitFuncParameter):
+ (EBufferBuilder.prototype.visitVariableDecl):
+ (EBufferBuilder):
+ * WebGPUShadingLanguageRI/Evaluator.js:
+ (Evaluator.prototype.visitVariableDecl):
+ (Evaluator.prototype.visitAssignment):
+ * WebGPUShadingLanguageRI/NameResolver.js:
+ (NameResolver.prototype.visitVariableDecl):
+ * WebGPUShadingLanguageRI/Rewriter.js:
+ (Rewriter.prototype.visitFuncParameter):
+ (Rewriter.prototype.visitVariableDecl):
+ * WebGPUShadingLanguageRI/Test.js:
+ (makeInt):
+ (TEST_add1):
+ (TEST_simpleGeneric):
+ (TEST_simpleAssignment):
+ (TEST_simpleDefault):
+ * WebGPUShadingLanguageRI/Visitor.js:
+ (Visitor.prototype.visitVariableDecl):
+
2017-08-31 Chris Dumez <cdu...@apple.com>
getFileMetadata() does not work as expected for symbolic links
Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -110,6 +110,17 @@
throw new WTypeError(node.origin.originString, "Array length must be constexpr");
}
+ visitVariableDecl(node)
+ {
+ node.type.visit(this);
+ if (node.initializer) {
+ let lhsType = node.type;
+ let rhsType = node.initializer.visit(this);
+ if (!lhsType.equals(rhsType))
+ throw new WTypeError(node.origin.originString, "Type mismatch in variable initialization: " + lhsType + " versus " + rhsType);
+ }
+ }
+
visitAssignment(node)
{
// FIXME: We need to check that the lhs is assignable.
Modified: trunk/Tools/WebGPUShadingLanguageRI/EBufferBuilder.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/EBufferBuilder.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/EBufferBuilder.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -39,11 +39,21 @@
return new EPtr(new PtrType(null, "thread", type), buffer, 0);
}
- visitFuncParameter(node)
+ _createEPtrForNode(node)
{
if (!node.type)
- throw new Error("Func parameter has no type: " + node);
+ throw new Error("node has no type: " + node);
node.ePtr = this._createEPtr(node.type);
}
+
+ visitFuncParameter(node)
+ {
+ this._createEPtrForNode(node);
+ }
+
+ visitVariableDecl(node)
+ {
+ this._createEPtrForNode(node);
+ }
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -60,6 +60,20 @@
throw new ReturnException(node.value ? node.value.visit(this) : null);
}
+ visitVariableDecl(node)
+ {
+ node.type.populateDefaultValue(node.ePtr.buffer, node.ePtr.offset);
+ if (node.initializer)
+ node.ePtr.copyFrom(node.initializer.visit(this));
+ }
+
+ visitAssignment(node)
+ {
+ let result = node.lhs.visit(this);
+ result.copyFrom(node.rhs.visit(this));
+ return result;
+ }
+
visitCommaExpression(node)
{
let result;
Modified: trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/NameResolver.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -176,6 +176,14 @@
node.elementType.visit(new NameResolver(nameContext));
}
+ visitVariableDecl(node)
+ {
+ this._nameContext.add(node);
+ node.type.visit(this);
+ if (node.initializer)
+ node.initializer.visit(this);
+ }
+
visitVariableRef(node)
{
let result = this._nameContext.get(Value, node.name);
Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -56,10 +56,21 @@
{
let result = new FuncParameter(node.origin, node.name, node.type.visit(this));
this._mapNode(node, result);
- result.lValue = node.lValue;
+ result.ePtr = node.ePtr;
return result;
}
+ visitVariableDecl(node)
+ {
+ let result = new VariableDecl(
+ node.origin, node.name,
+ node.type.visit(this),
+ node.initializer ? node.initializer.visit(this) : null);
+ this._mapNode(node, result);
+ result.ePtr = node.ePtr;
+ return result;
+ }
+
visitBlock(node)
{
let result = new Block(node.origin);
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -31,6 +31,11 @@
return prepare("<test>", 0, code);
}
+function makeInt(program, value)
+{
+ return new EInt(program.intrinsics.int32, value);
+}
+
function checkInt(result, expected)
{
if (!(result instanceof EInt))
@@ -55,14 +60,14 @@
function TEST_add1() {
let program = doPrep("int foo(int x) { return x + 1; }");
- checkInt(callFunction(program, "foo", [], [new EInt(program.intrinsics.int32, 42)]), 43);
+ checkInt(callFunction(program, "foo", [], [makeInt(program, 42)]), 43);
}
function TEST_simpleGeneric() {
- let program = doPrep(
- `T id<T>(T x) { return x; }
- int foo(int x) { return id(x) + 1; }`);
- checkInt(callFunction(program, "foo", [], [new EInt(program.intrinsics.int32, 42)]), 43);
+ let program = doPrep(`
+ T id<T>(T x) { return x; }
+ int foo(int x) { return id(x) + 1; }`);
+ checkInt(callFunction(program, "foo", [], [makeInt(program, 42)]), 43);
}
function TEST_nameResolutionFailure()
@@ -72,6 +77,40 @@
(e) => e instanceof WTypeError && e.message.indexOf("<test>:1") != -1);
}
+function TEST_simpleVariable()
+{
+ let program = doPrep(`
+ int foo(int p)
+ {
+ int result = p;
+ return result;
+ }`);
+ checkInt(callFunction(program, "foo", [], [makeInt(program, 42)]), 42);
+}
+
+function TEST_simpleAssignment()
+{
+ let program = doPrep(`
+ int foo(int p)
+ {
+ int result;
+ result = p;
+ return result;
+ }`);
+ checkInt(callFunction(program, "foo", [], [makeInt(program, 42)]), 42);
+}
+
+function TEST_simpleDefault()
+{
+ let program = doPrep(`
+ int foo()
+ {
+ int result;
+ return result;
+ }`);
+ checkInt(callFunction(program, "foo", [], []), 0);
+}
+
let before = preciseTime();
let filter = /.*/; // run everything by default
Modified: trunk/Tools/WebGPUShadingLanguageRI/Visitor.js (221441 => 221442)
--- trunk/Tools/WebGPUShadingLanguageRI/Visitor.js 2017-08-31 20:53:38 UTC (rev 221441)
+++ trunk/Tools/WebGPUShadingLanguageRI/Visitor.js 2017-08-31 20:57:45 UTC (rev 221442)
@@ -140,6 +140,13 @@
node.numElements.visit(this);
}
+ visitVariableDecl(node)
+ {
+ node.type.visit(this);
+ if (node.initializer)
+ node.initializer.visit(this);
+ }
+
visitAssignment(node)
{
node.lhs.visit(this);