...
 
Commits (2)
......@@ -18,7 +18,7 @@ are a big deal in any clojure developers world. As fan I'd like to start
my new programming language by writing down the rational of what I'm trying
to achieve.
### Rational (Take 1)
### Rational(Take 1) and goals
So far, the main reason to create a new language for me is to **learn more and
educate myself**. But it doesn't mean that I'm aiming for a toy language. I want
to create a general purpose language that solves some problems. Here is a list of
......@@ -46,3 +46,13 @@ table.
#### Development process
#### Better core development
#### Built-in Concurrency and parallelism
### A Name
If you're a programmer, I'm pretty sure that you already experienced the terror
of trying to find a name for your project. Franly, It's even hard to find a good
name for your variable.
After about 10 days of searching finally my wife came up with a good name. **Serene**.
Calm and peaceful. I like it. It's simple and beautiful with a great meaning.
I can't wait to start working on it. :P
......@@ -3,7 +3,7 @@ layout: post
title: "Choosing the right platform"
date: 2019-12-07
categories: Programming
tags: language
tags: Serene language
theme: dark
---
After wrapping my head around the [rational](/programming/rational-and-a-name/) of
......@@ -32,11 +32,12 @@ constantly iterate to come up with the right implementation. The evolution of
programming languages such as [Scheme](https://en.wikipedia.org/wiki/Scheme_%28programming_language%29)
is a good example of it (for more information take a look at [R6RS](http://www.r6rs.org/)).
While I think creating a programming language and a VM from scratch is really fun,
but it can be really frustrating as well. I don't want to get annoyed with myself
during the process and abandon my goal. I should ride on the shoulders of the giants
to gain benefit from their great work. I should choose a platform that helps me to
move faster and iterate through different ideas quicker.
Building a VM is hard and Building a fast VM is even harder. While I think creating
a programming language and a VM from scratch is really fun, but it can be really
frustrating as well. I don't want to get annoyed with myself during the process and
abandon my goal. I should ride on the shoulders of the giants to gain benefit from
their great work. I should choose a platform that helps me to move faster and iterate
through different ideas quicker.
From technical perspective, Starting from scratch means that I have to write a
program that includes at least a parser and a compiler. Building a compiler
......@@ -110,7 +111,76 @@ around it is only theoretical. Building a language on top a platform needs a goo
of practical experience on the platform as well which I don't have that. So it's obvious
that I have to pass.
## JVM
## The JVM
As much as I dislike Java (Mostly because of the syntax and the fact that it is an object
oriented language), I like JVM a lot.
oriented language), I like JVM a lot. The JVM is battle tested, well design (Well, sort of.
But it's certainly evolving.) and fast VM. It should be the most popular VM in the world
(I'm just guessing). It is one of the world's most heavily-optimized pieces of software.
Plenty of researches have been made to make it better and better.
The JVM has a mature ecosystem and a massive community of developers that resulted in an
unbelievable number of libraries (not the largest though, NPM is the largest artifact
repository. But it has huge amount of useless BS as well). By targeting the the JVM,
users will have an easy time adopting the new languages because of the rich tools set
provided by the Java ecosystem and all the languages that targeted JVM as well. For example,
it will be possible to use libraries written in Scala or Clojure as well.
Long story short, I think the JVM is the right platform for me. The fact that many languages
have chosen it as their base platform shows that how useful it can be. But there is a problem.
Targeting a higher level virtual machines like the JVM means that I'll have an easier job to
create a compiler. But I still have to write one. A compiler that takes the code and produces
JVM bytecode. As I mentioned earlier writing a compiler is an enormous task and the chance
of doing it wrong with some one like me who never has built a compiler before is very high.
## One VM to rule them all
Luckily there is a solution. I can write an interpreter in a VM that is designed to optimize
my interpreter with all that wonderful JIT compilation magic. Oracle has released a new VM
that hopes to make writing language interpreters both easy and fast. It can also leverage
the huge ecosystem of the JVM. It is an enhanced JVM that contains a new JIT compiler which
can speed up interpreters to near Java speed. The new JIT compiler is called Graal. To use
the Graal’s JIT magic we can use the Truffle library to create the interpreter. We will
annotate the interpreter and give Graal some hints on invariants and type information.
According to Graal's documents, By doing this integration effort we get significant speedups
in out interpreter without having to resort to writing a bytecode compiler.
[GraalVM](https://www.graalvm.org/) is a Java VM and JDK based on HotSpot/OpenJDK,
implemented in Java. It supports different execution modes, like ahead-of-time compilation
of Java applications for fast startup and low memory footprint.
> GraalVM is a universal virtual machine for running applications written in JavaScript,
> Python, Ruby, R, JVM-based languages like Java, Scala, Groovy, Kotlin, Clojure, and
> LLVM-based languages such as C and C++.
>
> GraalVM removes the isolation between programming languages and enables
> interoperability in a shared runtime. It can run either standalone or in
> the context of OpenJDK, Node.js or Oracle Database.
I copied the above paragraph from GraalVM's official website. It is truly a VM to rule
them all.
[Truffle](https://github.com/oracle/graal/tree/master/truffle) library is one the key
players in GraalVM. The initial results of Truffle are super exciting. Implementations
of Ruby in Truffle has a performances on the same order of magnitude as the much bigger
projects of JRuby. Just checkout [Truffle Ruby](https://chrisseaton.com/truffleruby/)'s
website to get amazed by it.
There is a [Javascript implementation](https://github.com/graalvm/graaljs)
as well which showed great progress as well.
Lots of research has been dedicated to this topic and the result is mind blowing.
The interesting thing is that these Truffle implementations were done with fewer people
in a shorter period of time. This means you can create your own language on the JVM that
takes advantage of all it’s existing libraries, native threading, JIT compiler without
having to write your own compiler, and you get speeds that took other languages years
to achieve.
Using GraalVM as the platform for my new language will help me to be much faster because
All I need to do is to build an [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree)
interpreter and Graal will handle the rest. It means that I can start by building what is
important and use a very well engineered toolkit in my advantage to get to my goal quicker
and then later on replace any part that I like with my own implementation. How cool is that???
But as an engineer and a wannabe scientist I'd like to see the proof with my own eye. Not
because I don't trust academic work, Just because it feels good to experience the proof.
So to begin with I'm going to create a dead simple Serene interpreter in Java and OpenJDK
and then build the same interpreter using Java on GraalVM using Truffle library and
compare the result and prove myself that choosing GraalVM is the right choice.