jadon

polyglot plt hacker

Home · Blog · GitHub · Twitter · Email


My Previous Programming Languages

Published Tuesday, June 12, 2018 · 2309 words, 12 minute read.

Welcome to the first edition of Language Design with Jadon! I’m a kid who wants to make another programming language. I mostly have zero clue what I’m doing, except for my extensive readings of type theory and the many langauges I’ve learned over the years. Let’s hope that’s enough!

First, some background. I’ve made a lot of languages over the last couple of years, greatly varying in quality. Of my (currently) 231 repositories on GitHub, here are some examples of languages I’ve made.

Toy languages

I have many other toy languages, but these are the more interesting ones. Now we can view some better languages I made.


Good(ish) languages

o (July 2015 - November 2016)

My first big language. The only esoteric language good enough to put on a resume. The original interpreter was written in Java and it was rewritten in obfuscated C in October of 2015 with massive help from Ryan Gonzalez. A Web IDE is available online and was written in Python & CoffeeScript. It was designed for CodeGolf, and it was great at it (until other languages came out that completely abused encoding tables).

“hello world”

"Hello, World! 

“factorial”

H,;]*

“fibonacci”

0J;1Kpj{K:VJ+:KpV:J;}d

“Count from 1 to n in Negabinary and Negaquaternary” (I don’t even..)

j){n.2_bo4_bo' o}d

lang-kotlin-antlr-compiler (August 2016 - June 2017)

I completely gave up on naming things, but this is one of the best compilers I’ve made. Written in Kotlin using ANTLR to generate the parser, the language targeted the LLVM. It supports global variables, functions, classes, methods, “automatic memory management”, type inference, FFI, modules, etc. It can be considered the “first version” of my language.

import std.io

@extern rand() : Int32 0

let initialAccountId = 7 + 11

class Account
    var id : Int32

    setId(i : Int32)
        id = i,
        id
;

incrementId(a : Account, amount : Int32)
    a.id = a.id + amount

main ()
    let account = new Account(),
    let i = account.setId(initialAccountId),
    printInt(i),
    incrementId(account, rand()),
    printInt(account.id),
    0
genComplexExpressionsInWhileLoop (a, z, y, x, w : Int32)
    var i = 0,
    var sum = 0,
    while i < a
        var v = 42 + x,
        let u = 45 * 7 - 16 + 11 + v * 67 + 124 - (w * 4) / 5,
        v = v * 2 - z,
        var t = 1,
        if z < 10
            t = v * z + 24 - 15 + y
        else
            t = v - 7 + 8 + 8 - z
        ;
        let l = 74 * 3 - v + z * x - w,
        i = 5 + u * z * v + t * 2 * l
    ;
    let r = sum * i,
    r
import std.io

fac (n)
    var r = 0,
    if n <=1
        r = 1
    else
        r = n * fac(n - 1)
    ;
    r

inc (a)
    a + 1

main ()
    var i = 1,
    while (i < 11)
        printInt(fac(i)),
        i = inc(i)
    ;
    0

This language quickly became too difficult to maintain because of poor design decisions of the internal structure made early on (no IR for example; doing AST resolution and generating LLVM IR in one pass is quite complex).

f2 (November 2016 - April 2017)

This time using an IR pass and a better AST, I created a language that had a focus on memory management, and how it can be handled better. It contains a Heap to Stack allocation algorithm which is actually pretty nice (imo). This is also going towards what my language will be.

struct X {
  a : Int32
}

struct Y {
  x : X
}

f :: X -> Int32
f x = x.a.

g :: Int32 -> X
g a = X{a}.

h :: Int32 -> Int32
h a = let x = X{a},
      x.a.

i :: Int32 -> Y
i a = Y{X{a}}.

j :: Int32 -> Int32
j a = let x = X{a},
      let y = Y{x},
      let w = y.x,
      w.a.
struct X {
  a : Int32
}

box :: Int32 -> X
box a = X{a}. -- memory is allocated here

f :: Int32 -> Int32
f i = let x = box(i),
      let a = firstThing(x),
      let b = secondThing(x),
      let c = thirdThing(x), -- memory is freed after this call
      a + b + c.

I quickly ran into problems with name resolution and modules, which I believe to have solved with my last blog post and in f3.

You may notice that all of these repositories are just pieces of languages. lang-kotlin-antlr-compiler was my first attempt at generating LLVM IR for an OOP language with Type Inference, f2 contains the language IR, and f3 contains the name resolution code. I’ll eventually merge everything into one language, but it’s good to have to algorithms and such written down and tested.

Whelp, this has been a rundown of my previous languages. Hopefully next time I come back with something worthwhile!



Home · Blog · GitHub · Twitter · Email