Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with JavaCC generate code: GOTO code without target loop/block. #51

Open
JWood48 opened this issue Jul 28, 2022 · 5 comments
Open

Comments

@JWood48
Copy link

JWood48 commented Jul 28, 2022

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;
        }
@Horcrux7
Copy link
Member

  • Do you use the latest snapshot from Jitpack? if not then try it.
  • Where can I find binaries for reproduction (maven artifact name)?

@JWood48
Copy link
Author

JWood48 commented Jul 28, 2022

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

@Horcrux7
Copy link
Member

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.

@JWood48
Copy link
Author

JWood48 commented Aug 8, 2022

Ok, i am not able to downgrade unfortunately... when will Strings be supported for java 11?

@Horcrux7
Copy link
Member

Horcrux7 commented Aug 8, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants