Skip to content
The Magpie programming language
Python C C++ Java Shell Emacs Lisp Other
Find file
Failed to load latest commit information.
core Start sketching in streams. Apr 28, 2013
dep Get gyp + libuv more or less happy. Jan 10, 2013
doc Rethrow if no catch clause matches. Apr 20, 2013
example Start sketching in streams. Apr 28, 2013
lib Start hacking together Magpie parser in Magpie. Apr 4, 2012
magpie.xcodeproj/project.xcworkspace Add skip() on Iterables. Apr 14, 2013
magpie.xcworkspace Get gyp + libuv more or less happy. Jan 10, 2013
script Make "done" a reserved word and built-in type. Apr 17, 2013
spec Start hacking together Magpie parser in Magpie. Apr 4, 2012
src Create a correctly-sized buffer when reading from TCP. Apr 28, 2013
support Add parameter patterns to block arguments. Jan 26, 2013
test Tweak how tokens are consumed after an error. Apr 20, 2013
.classpath Starting to sketch out the Java version of Magpie v2. Jul 25, 2010
.gitignore Get gyp + libuv more or less happy. Jan 10, 2013
.project Starting to sketch out the Java version of Magpie v2. Jul 26, 2010
AUTHORS Add Antal to AUTHORS. Jan 24, 2013
COPYRIGHT First stab at a FFI. Doesn't support namespaces yet, but is a good pr… Apr 29, 2009
README.md Update build instructions now that gyp is vendored. Jan 12, 2013
build.xml Teach `ant clean` to delete magpie.jar. Jun 7, 2011
common.gypi Get gyp + libuv more or less happy. Jan 10, 2013
magpie Make top-level shell script handle VM. Nov 4, 2012
magpie.gyp Start sketching in streams. Apr 28, 2013
run_gyp Get gyp + libuv more or less happy. Jan 10, 2013
run_gyp.bat Add run_gyp.bat Jan 21, 2013

README.md

                          _/Oo>
                         /(MM)
                        A___/       m a g p i e
                _______AV_h_h___________________________
                      AV
                     AV
                    AV

Magpie is a small dynamically-typed programming language built around patterns, classes, and multimethods. It has a prototype interpreter that runs on the JVM and an in-progress bytecode VM written in C++.

It looks a bit like this:

// Generates the sequence of turns needed to draw a dragon curve.
// See: http://en.wikipedia.org/wiki/Dragon_curve
def dragon(0, _)
    ""
end

def dragon(n is Num, turn)
    dragon(n - 1, "R") + turn + dragon(n - 1, "L")
end

print(dragon(5, ""))

Its goal is to let you write code that's beautiful and easy to read, and to allow you to seamlessly extend the language and libraries as you see fit.

You can learn more about the language at http://magpie-lang.org/.

Getting Started

Magpie has two implementations right now. There is a prototype interpreter written in Java. This supports more of the language, but is (of course) tied to the JVM and is much slower. It's main job was to let me iterate on the language semantics quickly.

Now that the language has (mostly) settled down, I've started writing a bytecode VM in C++. This is the "real" Magpie implementation, but it's still a work in progress. All current development is going on here. The Java interpreter is mainly a reference.

Building the Bytecode VM

  1. Pull down the code. It lives here: https://github.com/munificent/magpie

  2. Generate a project. From the root directory of the magpie repo:

    $ cd <path to magpie repo>
    $ ./run_gyp
    
  3. Set the output directory (XCode 4 only). Recent versions of XCode build into some shared directory not related to where the project is. This borks Magpie since it's a command-line executable that loads the core library from a path relative to that executable.

    Unfortunately, this setting isn't in the project itself, so gyp can't help. After you generate the project, open it in XCode, then:

    1. Choose "File > Project Settings...".
    2. On the "Build" tab, click "Advanced...".
    3. Set "Build Location" to "Custom > Relative to Workspace".
    4. Set "Products" to build.
    5. Set "Intermediates" to build/Intermediates.
    6. Click "Done".

    This should ensure that Magpie gets built into build/<config>/magpie.

  4. Build the project. Do what you usually do on your OS to build the thing. On Mac, that means open the XCode project and build from there. In Windows, there is a Visual Studio solution you can build. On Linux, you can just run make.

Building the Java Interpreter

  1. Pull down the code. It lives here: https://github.com/munificent/magpie

  2. Build it. The repo includes an Eclipse project if that's your thing. If you rock the command-line, you can just do:

    $ cd magpie
    $ ant jar
    

Running Magpie

Magpie is a command line app. After building it, you can run it by doing:

    $ ./magpie

This will run the Java interpreter or the bytecode VM, whichever is more recent.

If you run it with no arguments, it drops you into a simple REPL. Enter a Magpie expression and it will immediately evaluate it. Since everything is an expression, even things like class definitions, you can build entire programs incrementally this way. Here's one to get you started:

for i in 1..20 do print("<your name> is awesome!")

If you pass an argument to the app, it will assume it's a path to a script file and it will load and execute it:

$ ./magpie example/hello.mag
Something went wrong with that request. Please try again.