8 research outputs found
Scala.js: Type-Directed Interoperability with Dynamically Typed Languages
Interoperability between statically typed and dynamically typed languages is increasingly important, as can be witnessed by the many statically typed languages targeting JavaScript. Interoperating with both the object-oriented and functional features of JavaScript is essential, if only to manipulate the DOM, yet existing languages have very poor support for this. We present Scala.js, a dialect of Scala compiling to JavaScript. Its interoperability system is based on a powerful and intuitive framework for type-directed interoperability with dynamically typed languages. The framework combines facade types for JavaScript values; user-defined, implicit, type-directed cross-language conversions; and a Dynamic type building on facade types and implicit conversions. It accommodates both the functional and object-oriented features of Scala and JavaScript, and provides very natural interoperability between the two languages. It is expressive enough to represent the DOM and jQuery APIs, among others, both in its statically typed and dynamically typed flavors
Cross-Platform Language Design
Programming languages are increasingly compiled to multiple runtimes, each featuring their own rich structures such as their object model.
Furthermore, they need to interact with other languages targeting said runtimes.
A language targeting only one runtime can be designed to tailor its semantics to those of that runtime, for easy interoperability with other languages.
However, in a language targeting multiple runtimes with differing semantics, it is difficult to cater to each of them while retaining a common behavior across runtimes.
We call \emph{cross-platform language} a language that aims at being both \emph{portable} across platforms and \emph{interoperable} with each target platform.
Portability is the ability for a program or a library to cross-compile for multiple platforms, and behave the same way on all of them.
Interoperability is the ability to communicate with other languages on the same platform.
While many cross-compiling languages focus on one of these two properties---only adding support for the other one as an afterthought---, languages that are designed from the ground up to support both are rare.
In this thesis, we present the design of Scala.js, the dialect of Scala targeting the JavaScript platform, which turned Scala into a cross-platform language.
On the one hand, Scala programs can be cross-compiled for the JVM and JavaScript with portable semantics.
On the other hand, whereas Scala/JVM interoperates with Java, Scala.js interoperates with JavaScript, allowing to use any JavaScript library.
Along the dissertation, we give insights that can be transferred to the design of other cross-platform languages, although with a bias towards those targeting the JVM and JavaScript.
The first and most obvious challenge is to reconcile the static nature of Scala's object model with JavaScript's dynamic one.
Besides the ability to mutate a class hierarchy at run-time in JavaScript, there are fundamental differences between the two models, in particular the difference between compile-time overloading and run-time overloading.
We discuss how such semantic mismatches can live in harmony within the language.
The second challenge is to obtain good performance from a language where interoperability with a dynamic and unknown part of the program is pervasive.
To that end, we design and specify an intermediate representation (IR) with first-class support for dynamically typed interoperability features in addition to statically typed JVM-style operations.
Despite its tight integration with the open world of JavaScript, most of the IR can be considered as a closed world where advanced whole-program optimizations can be performed.
The performance of the overall system is evaluated and shown to be competitive with hand-written JavaScript, and even with Scala/JVM in some cases
Semantics-Driven Interoperability between Scala.js and JavaScript
Hundreds of programming languages compile to JavaScript. Yet, most of them fail, at one level or another, to provide satisfactory interoperability with JavaScript APIs. This is limiting, as interoperability is at least required to manipulate web pages through the DOM API, but also to use the ecosystem of existing JavaScript libraries. This paper presents the interoperability features of Scala.js, which solves the shortcomings of previous approaches. Scala. js offers a separate hierarchy of JavaScript types, whose operations have semantics borrowed from ECMAScript 2015. The interoperability features are complete with respect to ECMAScript 2015, save for two exceptions which are still being worked on. This allows Scala. js programs to perform any operation that an ECMAScript program could do, thereby guaranteeing that they can talk to any JavaScript library
A new concurrency model for scala based on a declarative dataflow core
Declarative dataflow values are single assignment variables such that all operations needing their values wait automatically until the values are available. Adding threads and declarative dataflow values to a functional language gives declarative concurrency, a model in which concurrency is deterministic and explicit synchronization is not needed. In our experience, this greatly simplifies the writing of concurrent programs (as explained in several chapters of CTM [20]). We complete this model with lazy execution and message-passing concurrency. Both extensions are tightly integrated with the declarative dataflow core. Lazy execution is provided by extending declarative dataflow with a by-need synchronization operation. Message passing is provided by adding streams equipped with a send operation, where a stream is a list with an unbound single-assignment variable. This paper presents the Ozma language, a conservative extension of Scala that supports all these concepts. We have made a complete implementation of Ozma by combining the implementations of Scala and Oz. Evaluation shows that this implementation supports the full semantics of Scala with concurrent programs based on the new concurrency model. In particular, within the functional subset of Scala the new concurrency model fully supports deterministic concurrency
Modular fault handling in a network-transparent programming language
A programming language is network-transparent if the same program code executes with the same results,whether it is run in a centralized or distributed setting,provided there is no partial failure. The Erlang programming language is network-transparent and handle failures by message passing. We propose in this paper a generalization of the Erlang failure handling model which can be used for more expressive network-transparent languages. The new design introduces two concepts: entity fault states and fault streams. The failure of an entity is modeled in the system as a language entity, and is visible to the programmer via its corresponding fault stream. We also describe an implementation in Mozart 1.4.0. Evaluation shows that this model incurs a slight overhead in performance, but yields much more modular program cod