Dart is compiled or interpreted language? - dart

I've searched a lot on the internet about if Dart is a compiled or interpreted language, also I searched in the documentation and didn't get a clear answer about if Dart is compiled or interpreted or both, and how that works

Yes!
The concepts of "compiled language" and "interpreted language" are not well defined.
Dart is definitely compiled in some cases. Say, when compiling to JavaScript for the web. That translates the program to a program in a different language, while preserving runtime behavior, which is the definition of compilation. (So "compilation" is well defined!)
To be pedantic, languages are not inherently compiled or interpreted. Implementations of languages may compiling or interpreting.
When running Dart on the native VM, directly from source code, it looks very much interpreted. But "interpretation" is a much mushier concept than compilation.
The only thing which is fundamentally and unequivocally interpretation is executing code directly by interpreting the source code, with no intermediate representation.
Nobody does that, not since BASIC. It's just too inefficient.
These days, you at least convert the source code to an abstract syntax tree. That's technically a compilation (converts a program from one representation to another, while preserving semantics). Then you might compile to a different internal representation. Maybe to byte code. Maybe even to native code.
Sometimes you do all of these, doing just-in-time compilation to the next level when optimization calls for it.
The Dart VM compiles source code, through a number of steps, into native machine code. (Which is then interpreted by the CPU.)
Whether that counts as "interpretation" or not is really a philosophical question.
From the outside, it matches one of the definitions of interpretation ("program goes in, runtime behavior occurs", as opposed to compilation which is "program goes in, other program comes out").
Internally, the VM is very much considering itself a compiler.

Related

Getting the typed syntax tree from dart2js or dart-analyzer

I'd like to derive exactly that subset of the sources of a dart comiler (dart2js or dartdevc or other) or of a dart analyser that can 1. transform a string of dart code (or better a list of strings each representing a compilation unit) into a typed syntax tree, 2. be translated into js, 3. be run in the browser. Is there a marked subset that fulfills these requirements, which is it, and how can I find it, in general.
Accomplishing #1 is fairly simple using package:analyzer, which is the same static analyzer used to provide IDE hinting and autocomplete, etc. The Dart Team is currently working on unifying their compiler frontends behind on main API, but for now, analyzer should definitely take care of most of what you need.
Here's an example of getting a syntax tree and running analysis on it: https://github.com/thosakwe/analyzer_examples/blob/master/analyze_a_file/analyze_a_file.dart
As for #2, you'll likely have to fork the dart-lang/sdk repo and make your own adjustments to dart2js. It's not published as a standalone package. Otherwise, you can write your own compiler, which is probably not going be fun.
I suppose you'd have to figure out how to get #2 up and running, but hypothetically, if you could compile a JavaScript source, you could just eval it after compilation.
To answer your final question, no, AFAIK, there is no subset of dart2js available that lets you create your own Dart-to-JavaScript compiler.

Evaluating Rascal's Performance?

I want to evaluate the performance of Rascal for a given rewrite system that I've written. I'm wondering if there's a good way of doing it?
Ideally, I'd generate some compiled Java classes from the system and then run them manually against my inputs. Is there an easy or recommended way to do it?
Cheers,
One way to do this is to use the functions in the library util::Benchmark. Typically, you could write something like
cpuType( (){ call_the_function_I_want_to_observe(); } ). This will execute your function and print the cpu time used.
Note that Rascal can be executed in two ways: interpreted and compiled which makes a big difference when measuring performance. We are working hard at the moment to fully integrate the compiler in the Eclipse IDE, but a stand alone version is available as well. This can be called as java -Xss8m -jar rascal-0.8.4-SNAPSHOT.jar --compiledREPL followed by at least values for directories for sources (--src), and binaries (--bin). Here rascal-0.8.4-SNAPSHOT.jar (but most likely named differently) is downloaded from the https://update.rascal-mpl.org/console/rascal-shell-unstable.jar.
If you need more information, don't hesitate to ask for more details: this part of our tool chain is unfortunately still undocumented.

How to obtain a file with the content of all include files explicitly included?

George "Mirage" Bakhtadze, the author of Cast II engine, has wrote about an include-based technique which can be used to create generic containers and algorithms. The source is avaiable from the repo at Github. For me, his include-based technique is very interesting and useful, because it can be used for older Delphi and it is compatible between Delphi and Free Pascal (and non-Windows OS ready).
It would be more useful for me if the _GenVector written in "gen_coll_vector.inc" has Sorted & Duplicates properties and related behaviors (behaving the same way as in TStringList).
However, it is less obvious for me to insert the code when there are many include directives (I wonder how George managed this in the first place). Therefore, I wonder whether it is possible to obtain a sample file with all include files explicitly included ? It might be more straightforward for me to start from there.
I mean that there is certain built-in pre-processor that works before the actual compiling and whether there is a way to keep these intermediate files ?
Delphi does not use a pre-processor. It is (and always has been, since Turbo Pascal days) a single-pass compiler. There is no intermediate step. When you {$I} to include files, they are inserted in place in memory during the compilation process. Therefore, there is no "intermediate file" that can be kept.

Why do erlang builds include .c and .erl source?

I am not even a newbie to erlang yet, I am just using RabbitMQ, which is written in Erlang. After I run configure/make/make install, the build output directories have plenty of .c and .erl files. Is this necessary? What's the reasoning behind it?
some examples:
./lib/erlang/lib/erl_interface-3.7.6/src/misc/show_msg.c
./lib/erlang/lib/cosNotification-1.1.18/src/oe_CosNotification.erl
Yes, it's necessary. The runtime system of Erlang is written in C, and most of the standard library is written in Erlang.
What's the reasoning behind it?
What would be the alternative? In order to execute any Erlang code, you need to have the runtime system already started, and so it can't be written in Erlang. It could be written in:
Assembly
C
C++ or some other language
Erlang could be executed without a runtime
Assembly is obviously a bad choice: you'd have to rewrite it nearly completely for any new CPU target and it would be much harder to maintain.
C provides excellent performance and portability, and ability to call C code from Erlang would at any rate be required. This is the choice made not only by Erlang, but by Python, Ruby, Perl, etc. as well.
C++ complicates portability (some OSes have C compilers available, but not C++ compilers; quality of C++ compilers varies more); other languages even more so (along with performance, possibly requiring their own runtime, etc.).
The final option would make Erlang a completely different language.

Why ActionScript is said scripting language even after grown up so much and having compiled language?

From the Wikipedia defination,
Programming language is
Scripting languages are languages that allow you to send commands directly to a system that executes these commands. These commands are read line by line and executed-interpreted, but not compiled.
Whilst, Scripting language is
Programming languages are languages that allow you to create a program by writing structured code that is read all at once by the system, checked for errors, and translated into an unreadable format that the machine can then execute(compiled).
ActionScript is now quite developed language(Which runs after compilation not interpreted) and after ActionScript 3,Flex and Air, Its hard to believe ActionScript is still dubbed as Scripting language.
The line between a programming language and a scripting language is blurry. Once upon a time, a "programming language" was a compiled language like C or C++, because only those languages were really efficient enough to write non-trivial programs in. Scripting languages were languages that were typically not compiled and thus slower; their relative inefficiency relegated them to systems maintenance tasks or "gluing" parts of a compiled program together. Now, computers are getting faster and language interpreters are getting more advanced, so even a traditional "scripting" language like Python or Tcl can be used to write a full-fledged application. However, once a language is dubbed a scripting language, it's hard to shirk off the title.
Don't believe everything in the Wikipedia.
PHP for example is compiled into bytecode at runtime, while java is compiled into bytecode at compilation time. The php interpreter executes the bytecode, and the java VM executes its bytecode both doing about the same thing.
A bash script is not compiled at all and is interpreted run line by line.
C is compiled into machine code that is read directly by the hardware.
According to the wiki entry, only the bash is truly a script which is a misnomer.
It is much more nuanced than the wiki entry implies.
JavaScript is a scripting language in browsers because it scripts the browser.
Bash is a scripting language because it scripts the OS.
Python and ActionScript are called scripting languages because they share things in common with real scripting languages (dynamically typed, sometimes interpreted, higher-level than C). I think "scripting language" as a term is far too over-used, and is mainly used to put down dynamically typed languages.
Reading the definitions above, the machine can't execute the format that the Flex compiler creates, therefore ActionScript is a scripting language.
Of course, anything that compiles to a VM would be considered a scripting language by that definition, including Java. Forth, being a threaded interpreted language, would also be a scripting language.
So forget Wikipedia. These distinctions used to make more sense than they do now.
JavaScript is getting faster monthly, and will probably soon be faster than ActionScript, if it isn't already.
I'd say a better definition for "scripting language" is, "a scripting language controls an application or enclosed environment, like a browser or a word processor or Flash."
But with the Chrome OS, even that definition is in peril, as the browser (including Flash, which Google has embraced) threatens to become an OS.

Resources