going-deep-with-dart
going-deep-with-dart copied to clipboard
Some Questions about the generated codes
Hi, dear Vandad!
I have some questions about the dart compilers that I thought this repository would be a great place to speak about it and document for others.
- As you know in the dart JIT/AOT compiler we can pass definitions via
--define=<key>=<value>
option. Now my question is the below code snnipts.
// JIT compiler
// $ dart --define=name=ehsan main.dart
var definition = String.fromEnvironment('name');
print(definition); // ehsan
but in AOT compilation value isn't accessible, if the variable type qualifier be var
and should be const
// AOT compiler
// $ dart compile exe --define=name=ehsan -o main main.dart; ./main
var definition = String.fromEnvironment('name'); // also `bool.hasEnvironment('name')` returns false
print(definition); // '' empty String, false boolean, 0 int
Actully my question is what happen in generated code that makes this difference in AOT and JIT compilation?
- Is platform checking will happen in runtime? (in AOT compilation)
// the is<platform> static variables also use this getter
switch (Platform.operatingSystem) {
case 'linux':
// do something linux
break;
case 'macos':
// do something in mac
break;
// and so on...
}
Hi!
In the dart-lang/language
repository I found an issue which is related to my question (I think second one). I will put it here ti make it more clear for others and maybe in documentations.
https://github.com/dart-lang/language/issues/1889