Skip to content

Flutter/Dart web support #3190

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

Closed
JulianBissekkou opened this issue May 26, 2021 · 2 comments · Fixed by #3250
Closed

Flutter/Dart web support #3190

JulianBissekkou opened this issue May 26, 2021 · 2 comments · Fixed by #3250
Milestone

Comments

@JulianBissekkou
Copy link

First of all, great job with the current dart runtime and the quick nullable release that you did in the last weeks. 👍🏽

We are using antlr4 in our flutter app which will run on the web soon. The current antlr4 dart runtime is not able to compile to js.
Here is the output when compiling the flutter web project:

../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:31:16: Error: The integer literal 0x5555555555555555 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 0x5555555555555400 is the nearest value that can be represented exactly.
    const m1 = 0x5555555555555555;
               ^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:32:16: Error: The integer literal 0x3333333333333333 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 0x3333333333333400 is the nearest value that can be represented exactly.
    const m2 = 0x3333333333333333;
               ^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:33:16: Error: The integer literal 0x0F0F0F0F0F0F0F0F can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 0xf0f0f0f0f0f0f00 is the nearest value that can be represented exactly.
    const m4 = 0x0F0F0F0F0F0F0F0F;
               ^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:34:16: Error: The integer literal 0x00FF00FF00FF00FF can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 0xff00ff00ff0100 is the nearest value that can be represented exactly.
    const m8 = 0x00FF00FF00FF00FF;
               ^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:36:17: Error: The integer literal 0x0101010101010101 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 0x101010101010100 is the nearest value that can be represented exactly.
    const h01 = 0x0101010101010101;
                ^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:75:30: Error: The operator '>>' isn't defined for the class 'num'.
Try correcting the operator to an existing operator, or defining a '>>' operator.
      bitCount += ((x * h01) >> 56);
                             ^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:75:16: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
      bitCount += ((x * h01) >> 56);
               ^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:151:24: Error: The integer literal 0x03f79d71b4cb0a89 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in Javascript. In Javascript 0x3f79d71b4cb0a80 is the nearest value that can be represented exactly.
    const debruijn64 = 0x03f79d71b4cb0a89;
                       ^^^^^^^^^^^^^^^^^^
../../../../../.pub-cache/git/antlr4-f0d4d129b7f146c314101bd3c99e630dc433af50/runtime/Dart/lib/src/util/bit_set.dart:152:58: Error: The operator '>>' isn't defined for the class 'num'.
Try correcting the operator to an existing operator, or defining a '>>' operator.
    return index64[(((value ^ (value - 1)) * debruijn64) >> 58) % 64];
                                                         ^^
Failed to compile application.

Maybe this requires only a small fix by using BigInt in bit_set.dart.

@JulianBissekkou
Copy link
Author

I added a PR that fixes the compile issues and some runtime crashes.
This requires some more work because every dart:io import should be checked and replaced if needed.
I need some more input from a maintainer to finish this.

@lingyv-li
Copy link
Member

Thanks for your contribution! I have also tried to remove dart:io before:

  1. runtime/Dart/lib/src/input_stream.dart which is for fromPath method. We could consider removing this method as users can do it easily. Or figure out a way to make this method visible only when calling from native Dart.
  2. runtime/Dart/lib/src/parser.dart which is for stdout. We should be able to replace it with print, but it means a newline will be added. This may affect testing.
  3. runtime/Dart/lib/src/error/src/error_listener.dart which is for stderr. Again changing this to print can affect testing.
  4. tool/resources/org/antlr/v4/tool/templates/codegen/Dart/Dart.stg. I can't remember what these are for at the moment.

I didn't continue with it because I couldn't find a easy way making it work without breaking tests. And people can use Dart JS interop with JS target anyway.

@parrt parrt added this to the 4.9.3 milestone Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants