Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Scala.js not compile itself?

Tags:

scala.js

I'm going through the tutorial and it looks like Scala.js only runs under sbt.

Are there bits of Scala.js (or the Scala environment generally) that are not written in Scala? Or cannot all the necessary bits go through Scala.js for some other reason? What am I missing?

like image 326
Michael Lorton Avatar asked Apr 03 '15 01:04

Michael Lorton


People also ask

Does Scala compile to JavaScript?

Scala. js lets you write Scala code that is compiled to JavaScript code that can then be used in the browser. The approach is similar to TypeScript, ReScript, and other languages that are compiled to JavaScript. Note that although Scala is a type-safe language, no types are declared in the above code.

Why js is not compiled?

JavaScript is an interpreted language, not a compiled language. A program such as C++ or Java needs to be compiled before it is run. The source code is passed through a program called a compiler, which translates it into bytecode that the machine understands and can execute.

What is Scala js used for?

Scala. js is a compiler that compiles Scala source code to equivalent Javascript code. That lets you write Scala code that you can run in a web browser, or other environments (Chrome plugins, Node. js, etc.)

Does Scala js support Scala 3?

js compiler plugin to work with Scala 3. For convenience, we chose to implement the Scala. js support directly inside the Scala 3 compiler (dotc) rather than as an external compiler plugin.


1 Answers

Mostly, this is because the Scala compiler uses too many parts of the JDK that have not been ported to Scala.js (yet). Some of these parts, most notably related to reading files (in the classpath, and source files), which cannot be implemented in JavaScript as such (though could be implemented for one particular platform, such as Node.js).

There is also the dependency on ASM, a Java bytecode manipulation library written in Java. Even though Scala.js compiles to JavaScript, the Java bytecode is still used for separate compilation (symbol lookup in previously compiled parts, such as libraries).

So, even though the Scala.js specific parts are written in a platform-independent way (e.g., we test that the Scala.js optimizer can optimize itself), there are a lot of parts in scalac that do not work out-of-the-box in Scala.js.

like image 80
sjrd Avatar answered Sep 17 '22 20:09

sjrd