Possum Devlog 1: Introduction

As I’ve mentioned in several places, I’m working on implementing a new programming language in Xojo. I’ve done this before (check out Roo) but I want to do it better. I thought I would create a central topic as a place I can write about it. Feel free to chip in if you like. The language is called Possum (like Roo, this is one of my daughter’s nicknames).

Why create a programming language at all?

There are hundreds of programming languages so does the world need another? I have four simple reasons for wanting to do this:

1. I want a better environment to teach novices to code.

I have five and an eight year old daughters. They’re smart and they are showing an interest in watching me code. We’ve played around with things like Scratch and Swift Playgrounds but I want to introduce them to something more like Xojo. The trouble is, The Xojo IDE is more complicated than it needs to be for a computer novice. Also it’s a statically typed language (needless cognitive overhead for beginners) and there are features that I want to see in the language that aren’t there and I can’t do anything about that.

2. I like the look of Python and Ruby but hate their tooling

Python is really popular but its tooling is awful. I wish their was a Xojo-like IDE for Python but there isn’t (trust me, I’ve looked!). Also, distributing a Python app once it’s finished is a nightmare. You can’t reliably protect your source code, you can’t reliably package your code up into an easily distributable form that you can just give to a friend and get it to run on their computer. You can’t write a GUI-based app easily. Yes I’m aware of the myriad of Python “freezing” solutions but, quite frankly, they’re shit.

3. I want to create an easy-to-use IDE and need an embeddable language

I have so many ideas for an IDE that I want to write myself. To do this though I need a language that I can embed / call from Xojo. Believe it or not, the easiest way to do this is to write my own. I had hoped Roo could fill that need but Roo has two big flaws:

  1. It’s slow. This is because its interpreter walks the AST. There are only incremental improvements I can make to it to improve it.

  2. The language was created on the fly which means I didn’t put a lot of thought into it in advance. There are things in the language that I’d like to change but polishing it after the fact isn’t as elegant as starting properly from scratch.

4. I enjoy this stuff

Perhaps this is the most important reason. Creating Roo was one of the best things I have ever achieved in my programming career and I want to do it again, but better.

What will Possum be like?

Possum is designed to be a dynamically-typed fully object-oriented language that is succinct but easy to learn. It looks a lot like Python in that indentation is a crucial part of the language. Unlike Python, it’s syntactically impossible to confuse spaces with tabs, you don’t have to pass self around everywhere and I’m designing it to be “compilable” into a form that will make distributing it easy.

The language specification itself will be open source, as will the reference Xojo implementation. Perhaps I will seek to monetise it in the future by making a great IDE for it that people might pay for but I’m not doing this to make :dollar:.

Below are some examples of what it will look like:


var x, y, z

#Lists (arrays).

var a = ["cat", 3, "dog", true]

a[0] # "cat"

# Dictionaries.

var d = {

"name" => "Garry",

"age" => 38

}

# Loops.

while true:

print("Balance: £" + balance)

balance += 1000

exit if balance > 4999

repeat:

print("Conditional loop")

until someCondition == true

for i = 0..10: # 0 to 10 INclusive

print(j) # 0 2 3 4 5 6 7 8 9 10

for i = 5..1: # decrementing 5 down to 1 INclusive

print(i) # 5 4 3 2 1

foreach day in daysOfWeek:

print(day)

# Conditionals.

if true then print("This is true")

var day = "Thursday"

if day == "Friday":

print("It's the weekend!")

elseif day == "Monday":

print("The start of the week")

else:

print("Not friday or Monday")

# The ternary conditional.

var a = 1 > 2 ? 3 : 4 # a becomes 4

# Functions.

function double(x):

x * x # Implicit return of x squared

function double(x):

return x * x # Explicit return

# Functions can accept blocks of code as an argument.

# Define a function that takes a block requiring a

# single parameter.

function each() <= block(item):

yield("An item")

# Call the `each()` function, passing to it a block.

# We name the parameters for the block after the `:`

# following the function's closing parentheses. These will

# become locally-scoped variables to the block.

each(): item

print(item)

# Functions can be overloaded by arity:

function each() <= block():

pass

function each(x) <= block():

pass

function each(x) <= block(y):

pass

# Classes support operator overloading:

class Superhero:

-:

print("Negating a superhero is odd.")

-(other):

print("Subtracting " + other + " from a superhero is weird")

[index]:

print("Superheroes are not lists!")

[x, y]:

print("Superheroes are not matrices either!")

[index]=(value):

print("You can't put " + value + " into me at " + index)

# Classes have named constructors.

class Superhero:

constructor new(name, power):

print("My name is " + name + ", my power is " + power)

var elastigirl = Superhero.new("Elastigirl", "stretchiness")

#Giving constructors names is handy because it means you can have more

# than one, and each can clarify how it creates the instance:

class Superhero:

constructor good(name, power):

print("My name is " + name + ", my power is " + power + " and I'm good")

var elastigirl = Superhero.good("Elastigirl", "stretchiness")

# Classes support single inheritance.

Class Superhero: pass

Class Avenger Is Superhero: pass

How will Possum be implemented?

Unlike Roo, The reference implementation of Possum will take source code and compile it to bytecode in a single pass. I have decided not to build an intermediate abstract syntax tree during parsing as I want compilation to be fast. Time will tell if this is the right call as by doing this I lose the ability to do a pre-compilation walk of the tree to do semantic analysis but I should gain a significant speed boost and a big reduction in the compiler’s memory footprint. This is important as I want Possum to run on low end hardware like the Raspberry Pi 3.

How far along is its implementation?

It is really early days but below is a rough road map. A check means completed, a - means in progress.

  • Language semantics (see excerpt above)
  • Language grammar (required for parsing, see post below)
  • Scanner (almost done, a complete rewrite)
  • Bytecode format (in-memory representation already done)
  • VM
  • Compiler
  • Serialise bytecode to disk
  • IDE

Obviously there is a lot to do in those few tasks but I’m hoping to at least soon be able to compile simple expressions containing primitives. Remember, I have made a language in Xojo before so this isn’t a pipe dream.

1 Like