JWebAssembly
JWebAssembly copied to clipboard
Issue with JavaCC generate code: GOTO code without target loop/block.
I have a custom grammar in javacc and would like to convert it to wasm, but I get the error:
> GOTO code without target loop/block. Jump from 442 to 55 at gantt.cq.parser.CQParserTokenManager.getNextToken(CQParserTokenManager.java:2078)
The specific getNextToken
function is:
public Token getNextToken()
{
Token matchedToken;
int curPos = 0;
EOFLoop :
for (;;)
{
try
{
curChar = input_stream.BeginToken();
}
catch(Exception e)
{
jjmatchedKind = 0;
jjmatchedPos = -1;
matchedToken = jjFillToken();
return matchedToken;
}
image = jjimage;
image.setLength(0);
jjimageLen = 0;
for (;;)
{
switch(curLexState)
{
case 0:
try { input_stream.backup(0);
while (curChar <= 32 && (0x100003600L & (1L << curChar)) != 0L)
curChar = input_stream.BeginToken();
}
catch (java.io.IOException e1) { continue EOFLoop; }
jjmatchedKind = 0x7fffffff;
jjmatchedPos = 0;
curPos = jjMoveStringLiteralDfa0_0();
break;
case 1:
jjmatchedKind = 0x7fffffff;
jjmatchedPos = 0;
curPos = jjMoveStringLiteralDfa0_1();
if (jjmatchedPos == 0 && jjmatchedKind > 13)
{
jjmatchedKind = 13;
}
break;
case 2:
jjmatchedKind = 0x7fffffff;
jjmatchedPos = 0;
curPos = jjMoveStringLiteralDfa0_2();
if (jjmatchedPos == 0 && jjmatchedKind > 13)
{
jjmatchedKind = 13;
}
break;
}
if (jjmatchedKind != 0x7fffffff)
{
if (jjmatchedPos + 1 < curPos)
input_stream.backup(curPos - jjmatchedPos - 1);
if ((jjtoToken[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
{
matchedToken = jjFillToken();
if (jjnewLexState[jjmatchedKind] != -1)
curLexState = jjnewLexState[jjmatchedKind];
return matchedToken;
}
else if ((jjtoSkip[jjmatchedKind >> 6] & (1L << (jjmatchedKind & 077))) != 0L)
{
SkipLexicalActions(null);
if (jjnewLexState[jjmatchedKind] != -1)
curLexState = jjnewLexState[jjmatchedKind];
continue EOFLoop;
}
jjimageLen += jjmatchedPos + 1;
if (jjnewLexState[jjmatchedKind] != -1)
curLexState = jjnewLexState[jjmatchedKind];
curPos = 0;
jjmatchedKind = 0x7fffffff;
try {
curChar = input_stream.readChar();
continue;
}
catch (java.io.IOException e1) { }
}
int error_line = input_stream.getEndLine();
int error_column = input_stream.getEndColumn();
String error_after = null;
boolean EOFSeen = false;
try { input_stream.readChar(); input_stream.backup(1); }
catch (java.io.IOException e1) {
EOFSeen = true;
error_after = curPos <= 1 ? "" : input_stream.GetImage();
if (curChar == '\n' || curChar == '\r') {
error_line++;
error_column = 0;
}
else
error_column++;
}
if (!EOFSeen) {
input_stream.backup(1);
error_after = curPos <= 1 ? "" : input_stream.GetImage();
}
throw new TokenMgrError(EOFSeen, curLexState, error_line, error_column, error_after, curChar, TokenMgrError.LEXICAL_ERROR);
}
}
}
The line numbers do not match, but the referenced ´continue´ statement is in the last half of the code above:
try {
curChar = input_stream.readChar();
continue;
}
- Do you use the latest snapshot from Jitpack? if not then try it.
- Where can I find binaries for reproduction (maven artifact name)?
Created a project here to reproduce, but cant even get the basic example working, what am i doing wrong?
https://github.com/JWood48/JWebAssemblyTest
gradle wasm gives the following error:
$ gradle wasm
> Task :app:wasm FAILED
compiler: jwebassembly-master-SNAPSHOT.jar
> WASM compile failed with: Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+' or implements this native method self.
at java.lang.ref.Reference.refersTo0(Reference.java)
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:wasm'.
> Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
If you want to use classes with native code, you must use a library that implements these native methods, such as 'de.inetsoftware:jwebassembly-api:+' or implements this native method self.
at java.lang.ref.Reference.refersTo0(Reference.java)
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
2 actionable tasks: 2 executed
WASM compile failed with: Native methods cannot be compiled to WebAssembly: java/lang/ref/Reference.refersTo0(Ljava/lang/Object;)Z
This error look like that you use a higher Java version. Currently only with Java 8 you can use Strings.
Ok, i am not able to downgrade unfortunately... when will Strings be supported for java 11?
First I will fix all compiler errors (not API errors) with Java 8. Then I will take a look at Java 11. I have no idea how many errors I will find and that I have no idea how long it will take. Can be a month or multiple years.
With compiler error I means thinks like the original error message GOTO code without target loop/block.
which are result of misinterpreting the Java byte code.
A missing native method is an API error. You can fix it self: https://github.com/i-net-software/JWebAssembly/wiki/Compiler-Errors-and-Problems and make a PR.
Alternative you can ignore it with ignoreNative = true
and convert it to a possible runtime error.