Git Product home page Git Product logo

dart2java's Introduction

Dart2Java dev compiler

The Dart2Java dev compiler is a transpiler from Dart to Java source. It is based on DDC and Kernel IR, and its main goal is to investigate which features of the Dart language make it particularly hard or easy for AOT compilation to a new language. Ideally, Dart2Java will enable interoperability between Dart and Java programs, and automatic translation of Dart programs to Java source.

Compiling the SDK

The easy way to build the SDK is to run the tool/build_sdk.sh script.

The script executes the following steps:

  • Patch the SDK: tool/patch_sdk.sh
  • Compile the SDK: dart2java --dart-sdk=gen/patched_sdk --output=gen/compiled_sdk --package-prefix=dart dart:_internal ...
  • Compile the generated .java files with javac
  • Archive the generated .class files with jar

Disclaimer

This is not an official Google product.

dart2java's People

Contributors

alan-knight avatar andrewkrieger avatar azenla avatar chalin avatar devoncarew avatar dgrove avatar harryterkelsen avatar jacob314 avatar jakemac53 avatar jonaskello avatar justinfagnani avatar kevmoo avatar leafpetersen avatar matthias-springer avatar munificent avatar ochafik avatar priscilla-lee avatar rakudrama avatar sigmundch avatar smanilov avatar stereotype441 avatar vsmenon avatar zoechi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dart2java's Issues

Avoid Boxing for Constructor Invocations

When calling a generic constructor factory (the generated methods that start with _new), all parameters of type of a type variable are boxed implicitly. This should be avoided. Instead, get rid of the generic factory and call a specialized constructor directly (if it is fixed as described, it would probably also fix #4).

This only applies to constructors but not factories (Constructor factory != factory constructor)! Generic method specializations (#6) could be used to get rid of boxing when calling a factory constructor.

E.g.:

class A<T> {
    T variable;
    A(this.variable);
}

new A<int>(42);   // 42 is boxed

Fix Type of Generic `new` Expression without Explicit Assignment

The following code does not compile correctly:

class A<T> {
    T variable;
}

void main() {
    print(new A<int>().variable);
}

There is something wrong with inserting type casts. The following variation works:

var result = new A<int>();
print(result.variable);

Optimize Dynamic Method Calls

The implementation of DynamicHelper is very slow and does a method lookup using the Java Reflection API every time a method is invoked on an expression of dynamic type (see performance results of benchmark tracer).

Use caching, the Java Method Handle API, or generate byte code to take advantage of invokedynamic.

Final Field Declarations

Due to the current translation of Dart constructors (generating an instance method with the constructor body), fields that are declared as final in Dart code are not final in Java code.

Exception Handling

Not implemented at the moment.

throw ... will throw a RuntimeException. Exceptions cannot be caught at the moment.

Security Policy violation Binary Artifacts

This issue was automatically created by Allstar.

Security Policy Violation
Project is out of compliance with Binary Artifacts policy: binaries present in source code

Rule Description
Binary Artifacts are an increased security risk in your repository. Binary artifacts cannot be reviewed, allowing the introduction of possibly obsolete or maliciously subverted executables. For more information see the Security Scorecards Documentation for Binary Artifacts.

Remediation Steps
To remediate, remove the generated executable artifacts from the repository.

Artifacts Found

  • third_party/hamcrest-1.3/hamcrest-core-1.3-src.jar
  • third_party/hamcrest-1.3/hamcrest-core-1.3.jar
  • third_party/hamcrest-1.3/hamcrest-library-1.3-src.jar
  • third_party/hamcrest-1.3/hamcrest-library-1.3.jar
  • third_party/junit-4.12/junit-4.12.jar

Additional Information
This policy is drawn from Security Scorecards, which is a tool that scores a project's adherence to security best practices. You may wish to run a Scorecards scan directly on this repository for more details.


Allstar has been installed on all Google managed GitHub orgs. Policies are gradually being rolled out and enforced by the GOSST and OSPO teams. Learn more at http://go/allstar

This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

Super Initializers

There is a TODO in visitSuperInitializer. The name mangling does not always produce the correct result.

Fix `LetExpression`

The following code does not compile:

List<int> list;
list[4] = list[3]++;

Generated Java code:

dart.core.List_interface__int __tempVar_4;
int __tempVar_5;
int __tempVar_6;
void __tempVar_7;
dart.core.List_interface__int list = null;
list.operatorAtPut_List__int(4, dart._runtime.helpers.LetExpressionHelper.comma(__tempVar_4 = ((dart.core.List_interface__int) list), dart._runtime.helpers.LetExpressionHelper.comma(__tempVar_5 = 3, dart._runtime.helpers.LetExpressionHelper.comma(__tempVar_6 = __tempVar_4.operatorAt_List__int(__tempVar_5), dart._runtime.helpers.LetExpressionHelper.comma(__tempVar_7 = __tempVar_4.operatorAtPut_List__int(__tempVar_5, (__tempVar_6 + 1)), __tempVar_6)))));

This is because of how we use LetExpressionHelper at the moment.

Note: Dart code can always be rewritten in a way such that the code compiles (using extra temp variables).

Core SDK Interoperability

Generated interfaces of (abstract) SDK classes should be implemented by the following Java interfaces.

List_interface<T> extends java.util.List<T>
Map__interface<K, V> extends java.util.Map<K, V>
Iterable_interface<T> extends java.lang.Iterable<T>
Iterator_interface<T> extends java.lang.Iterator<T>
Comparable_interface<T> extends java.lang.Comparable<T>

(There might be more SDK classes, but these are the most important ones IMO.)

This means that additional methods must be inserted as soon as a class implements one of these Dart classes.

Named Parameters

Named parameters are currently not supported. Check places like buildArguments etc.

Public Runtime Type System

The public runtime type system (e.g., is checks) is not well covered in Dart unit tests (but seems to be working fine!). Parts of the runtime type system are not exposed to the public API.

  • Implementation of Type is missing (the logics is there)
  • runtimeType not implemented on DartObject

Explicit Constructor Invocation for Special Classes

Most special classes in the Dart SDK are probably abstract (e.g. int, String). In those cases there should not be any explicit constructor invocations. At the very least, this is required for Java interoperability reasons (instantiating a Java class from Dart once we figured out interop details).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.