You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by er...@apache.org on 2017/12/19 13:05:29 UTC
[royale-compiler] 03/03: Baby steps toward actual AS -> WAT
transpiling
This is an automated email from the ASF dual-hosted git repository.
erikdebruin pushed a commit to branch feature/as2wasm
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git
commit bae45ccf1368b8e86f3002ae781182440e5c1054
Author: Erik de Bruin <er...@ixsoftware.nl>
AuthorDate: Tue Dec 19 14:05:19 2017 +0100
Baby steps toward actual AS -> WAT transpiling
Signed-off-by: Erik de Bruin <er...@ixsoftware.nl>
---
.../internal/codegen/wast/WASTEmitter.java | 102 ++++++++++++++++++++-
.../internal/codegen/wast/WASTEmitterTokens.java} | 27 +++---
.../internal/codegen/wast/TestWASTClass.java | 2 +-
.../codegen/wast/TestWASTMethodMember.java | 17 ++++
4 files changed, 130 insertions(+), 18 deletions(-)
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.java
index d40e835..46a924c 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitter.java
@@ -21,9 +21,18 @@ package org.apache.royale.compiler.internal.codegen.wast;
import java.io.FilterWriter;
+import org.apache.royale.compiler.codegen.IEmitterTokens;
+import org.apache.royale.compiler.definitions.IFunctionDefinition;
import org.apache.royale.compiler.definitions.IPackageDefinition;
import org.apache.royale.compiler.internal.codegen.as.ASEmitter;
+import org.apache.royale.compiler.internal.codegen.as.ASEmitterTokens;
+import org.apache.royale.compiler.internal.tree.as.FunctionNode;
+import org.apache.royale.compiler.tree.ASTNodeID;
+import org.apache.royale.compiler.tree.as.IAccessorNode;
import org.apache.royale.compiler.tree.as.IClassNode;
+import org.apache.royale.compiler.tree.as.IFunctionNode;
+import org.apache.royale.compiler.tree.as.IGetterNode;
+import org.apache.royale.compiler.tree.as.ISetterNode;
public class WASTEmitter extends ASEmitter {
@@ -33,11 +42,23 @@ public class WASTEmitter extends ASEmitter {
}
@Override
- public void emitClass(IClassNode node)
+ public void writeToken(IEmitterTokens value)
{
- //
+ writeToken(value, true);
}
+ public void writeToken(IEmitterTokens value, boolean insertSpace)
+ {
+ write(value.getToken());
+ if (insertSpace) {
+ write(ASEmitterTokens.SPACE);
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ // Package
+ //--------------------------------------------------------------------------
+
@Override
public void emitPackageFooter(IPackageDefinition definition)
{
@@ -56,4 +77,81 @@ public class WASTEmitter extends ASEmitter {
")");
}
+ //--------------------------------------------------------------------------
+ // Class
+ //--------------------------------------------------------------------------
+
+ @Override
+ public void emitClass(IClassNode node)
+ {
+ writeToken(ASEmitterTokens.PAREN_OPEN, false);
+ writeToken(WASTEmitterTokens.MODULE, false);
+ writeToken(ASEmitterTokens.NEW_LINE);
+ writeToken(ASEmitterTokens.NEW_LINE);
+ writeToken(ASEmitterTokens.PAREN_CLOSE, false);
+ }
+
+ //--------------------------------------------------------------------------
+ // Method
+ //--------------------------------------------------------------------------
+
+ @Override
+ public void emitMethod(IFunctionNode node)
+ {
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(getProblems());
+
+ IFunctionDefinition definition = node.getDefinition();
+
+ emitNamespaceIdentifier(node);
+ emitModifiers(definition);
+ emitMemberKeyword(node);
+
+ /*
+ // see below, this is temp, I don't want a bunch of duplicated code
+ // at them moment, subclasses can refine anyways, we are generalizing
+ if (node instanceof IGetterNode)
+ {
+ emitGetAccessorDocumentation((IGetterNode) node);
+ }
+ else if (node instanceof ISetterNode)
+ {
+ emitSetAccessorDocumentation((ISetterNode) node);
+ }
+ else
+ {
+ emitMethodDocumentation(node);
+ }
+
+ FunctionNode fn = (FunctionNode) node;
+ fn.parseFunctionBody(getProblems());
+
+ IFunctionDefinition definition = node.getDefinition();
+
+ emitNamespaceIdentifier(node);
+ emitModifiers(definition);
+ emitMemberKeyword(node);
+
+ // I'm cheating right here, I haven't "seen" the light
+ // on how to properly and efficiently deal with accessors since they are SO alike
+ // I don't want to lump them in with methods because implementations in the
+ // future need to know the difference without loopholes
+ if (node instanceof IAccessorNode)
+ {
+ emitAccessorKeyword(((IAccessorNode) node).getAccessorKeywordNode());
+ }
+
+ emitMemberName(node);
+ emitParameters(node.getParametersContainerNode());
+ emitType(node.getReturnTypeNode());
+ if (node.getParent().getParent().getNodeID() == ASTNodeID.ClassID)
+ {
+ emitMethodScope(node.getScopedNode());
+ }
+
+ // the client such as IASBlockWalker is responsible for the
+ // semi-colon and newline handling
+ */
+ }
+
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitterTokens.java
similarity index 63%
copy from compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
copy to compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitterTokens.java
index eab8957..1bb1f9c 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/wast/WASTEmitterTokens.java
@@ -16,26 +16,23 @@
* limitations under the License.
*
*/
-
package org.apache.royale.compiler.internal.codegen.wast;
-import org.apache.royale.compiler.internal.test.WASTTestBase;
-import org.apache.royale.compiler.tree.as.IClassNode;
-import org.junit.Test;
+import org.apache.royale.compiler.codegen.IEmitterTokens;
-/**
- * This class tests the production of WebAssembly Text Format code for Classes.
- *
- * @author Erik de Bruin
- */
-public class TestWASTClass extends WASTTestBase {
+public enum WASTEmitterTokens implements IEmitterTokens
+{
+ MODULE("module");
+
+ private String token;
- @Test
- public void testClassSimple()
+ private WASTEmitterTokens(String value)
{
- IClassNode node = (IClassNode) getNode("public class A{}", IClassNode.class, WRAP_LEVEL_PACKAGE);
- asBlockWalker.visitClass(node);
- assertOut("Hoi ");
+ token = value;
}
+ public String getToken()
+ {
+ return token;
+ }
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
index eab8957..8434e19 100644
--- a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTClass.java
@@ -35,7 +35,7 @@ public class TestWASTClass extends WASTTestBase {
{
IClassNode node = (IClassNode) getNode("public class A{}", IClassNode.class, WRAP_LEVEL_PACKAGE);
asBlockWalker.visitClass(node);
- assertOut("Hoi ");
+ assertOut("(module\n \n )");
}
}
diff --git a/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTMethodMember.java b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTMethodMember.java
new file mode 100644
index 0000000..0049821
--- /dev/null
+++ b/compiler-jx/src/test/java/org/apache/royale/compiler/internal/codegen/wast/TestWASTMethodMember.java
@@ -0,0 +1,17 @@
+package org.apache.royale.compiler.internal.codegen.wast;
+
+import org.apache.royale.compiler.internal.test.WASTTestBase;
+import org.apache.royale.compiler.tree.as.IFunctionNode;
+import org.junit.Test;
+
+public class TestWASTMethodMember extends WASTTestBase {
+
+ @Test
+ public void testMethod()
+ {
+ IFunctionNode node = getMethod("function foo(){}");
+ asBlockWalker.visitFunction(node);
+ assertOut("");
+ }
+
+}
--
To stop receiving notification emails like this one, please contact
"commits@royale.apache.org" <co...@royale.apache.org>.