Discovering How to Extend the Dart Language

 I am able to load the flutter_frontend_server using:

dart bin/starter.dart
compile tmp/hello.dart

I'm seeing the error: 
Error: SDK root directory not found: ../../out/android_debug/flutter_patched_sdk/

Suspect I either need to compile the sdk or provide an environment variable.

There is now a new error, after running: 

dart bin/starter.dart --sdk-root='/usr/local/Caskroom/flutter/2.0.5/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk' compile tmp/hello.dart

Bad state: createLibraryBuilder for uri dart:_builtin, fileUri org-dartlang-untranslatable-uri:dart%3A_builtin returned null


Success! 

dart bin/starter.dart --sdk-root='/usr/local/Caskroom/flutter/2.0.5/flutter/bin/cache/artifacts/engine/common/flutter_patched_sdk' --target=flutter tmp/hello.dart

result 633ec087-419b-47fd-bb64-1e3773c131e1
633ec087-419b-47fd-bb64-1e3773c131e1
+file:///Users/johnmcconnell/dev/github.com/johnmcconnell/flojure-engine/src/flutter/flutter_frontend_server/tmp/hello.dart
633ec087-419b-47fd-bb64-1e3773c131e1 tmp/hello.dart.dill 0

However, now I realize the almost all of the frontend compilation is done in the dart-sdk: https://github.com/dart-lang/sdk/blob/375dc2889b25082a410d5ee02bfd38ec0bcb1518/pkg/frontend_server/lib/frontend_server.dart
 
Finish for now. Next is to figure out how to compile using the dart-sdk.

Note: I believe fasta has the language specification to create the AST for the IncrementalCompilier: https://github.com/dart-lang/sdk/search?q=IncrementalCompiler 

Note:
  1. Someone else using a local engine: https://www.fatalerrors.org/a/notes-on-compiling-with-flutter-engine.html
  2. Search for language features: https://github.com/dart-lang/sdk/issues?page=2&q=is%3Aissue+fasta+language+is%3Aclosed
I can use the patched sdk located here:

dart bin/starter.dart --sdk-root='../../out/ios_debug_sim_unopt/flutter_patched_sdk' --target=flutter tmp/hello.dart

Done.

Looking for where the language compilation occurs.

Found:
  1. Tokenizer - https://github.com/dart-lang/sdk/blob/master/pkg/_fe_analyzer_shared/lib/src/scanner/token_impl.dart
  2. Parser - https://github.com/dart-lang/sdk/blob/master/pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
  3. Language Roadmap - https://github.com/dart-lang/language/projects/1
  4. TreeShaking Doc - https://github.com/dart-lang/sdk/issues/33920
  5. AST Building might happen in listener as parser only propagates events - https://github.com/dart-lang/sdk/blob/master/pkg/_fe_analyzer_shared/lib/src/parser/listener.dart
  6. Handling Literal Int - https://github.com/dart-lang/sdk/blob/9c5ac0150458cb23d44be625c834f2a13237c302/pkg/front_end/lib/src/fasta/util/direct_parser_ast_helper.dart#L2167
    1. Changing the language might require patching multiple listeners for different compilation/interpretation modes.
Root project directory for dart-sdk is: <flutter-engine-root>/src/third_party/dart

Finish for now. Next, I'll create a simple program with a new keyword.

Comments

Popular posts from this blog

Setting Up Your Own Local Copy of the Flutter Engine

Adding a New Keyword to the Dart Language