A toy programming language
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
README.markdown
Rakefile
mirror.rb

README.markdown

Mirror

Mirror is a toy language I wrote in a couple hours to demonstrate a few tools and concepts in a presentation I gave in a local event in Brazil. It has a syntax inspired by Smalltalk and semantics inspired by Self and IO as seen in the example below:

World mirrorInto: "Fib".

Fib set: "of:" to: [ n |
  n < 3
    ifTrue: [ 1. ]
    ifFalse: [ (of: n - 1) + (of: n - 2). ].
].

(Fib of: 10) transcribeAndBreak.

A few more details

  • It uses Treetop for parsing
  • Classes and objects are represented by containers which contain slots.
  • Slots may be code or literal values.
  • Class and object creation is done by "mirrroring" another object.
  • The ground object is called Universe and it contains a World object from which all other primary objects are "mirrored".
  • It uses a very naive code generator and an even more naive interpreter

Requirements

  • Treetop
  • Not really a requirement, but it runs better on Ruby 1.9

Running

Usage is pretty simple:

$ ruby mirror.rb test.mirror

Or:

$ echo "[ 2 + 2. ] value transcribeAndBreak." | ruby mirror.rb

Tests

There are a few tests and test scripts in the test directory.

TO DO

  • Arrays
  • A more specific bytecode syntax
  • A more coherent handling of contexts
  • Inlining of common sends
    • ifTrue:
    • ifFalse:
    • ifTrue:ifFalse:
    • to:do:
    • downTo:do:
    • Binary primitives: +, -, *, /, etc
  • Code cleanup
  • LLVM