• Stars
    star
    351
  • Rank 117,236 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created over 15 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Magpie programming language
                          _/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

More Repositories

1

craftinginterpreters

Repository for the book "Crafting Interpreters"
HTML
8,160
star
2

game-programming-patterns

Source repo for the book
HTML
3,967
star
3

vigil

Vigil, the eternal morally vigilant programming language
Python
2,840
star
4

hauberk

A web-based roguelike written in Dart.
Dart
1,951
star
5

mark-sweep

A simple mark-sweep garbage collector in C
C
709
star
6

bantam

A simple demo app for Pratt parsing
Java
298
star
7

finch

The Finch programming language
C++
213
star
8

jasic

A complete interpreter for a dialect of BASIC in one Java sourcefile
Java
147
star
9

rooms-and-mazes

Animated demo code for a random dungeon generator
Dart
137
star
10

ui-as-code

Design work on improving Dart's syntax for UI code
Dart
121
star
11

amaranth

An open source roguelike written in C#
C#
115
star
12

journal

My blog, in all its statically-generated glory.
HTML
93
star
13

malison

A little terminal emulation package for Dart.
Dart
71
star
14

lark

The Lark programming language.
Java
57
star
15

piecemeal

Basic data structures your 2D Dart game may need.
Dart
51
star
16

wrenalyzer

Static analyzer for the Wren programming language
41
star
17

lisp2-gc

A simple implementation of the LISP2 mark-compact GC algorithm
C
37
star
18

malison-dotnet

A terminal emulation library in C#
C#
36
star
19

a-turn-based-game-loop

Demo code for http://journal.stuffwithstuff.com/2014/07/15/a-turn-based-game-loop/
Dart
27
star
20

markymark

A tiny static web server for previewing Markdown files
Dart
23
star
21

bulfinch

Just a little toy language to learn about register-based VMs.
Java
20
star
22

fov

Demo code for a blog post about field-of-view calculation
Dart
19
star
23

pattern_matching

A simple ML-like pattern-matching library in C#.
C#
18
star
24

bramble-dotnet

A set of utility classes and extension methods in C#
C#
17
star
25

bits

Tiny web page for converting between binary, decimal, hex and UTF-8
HTML
9
star
26

dep-external-libraries

Proposal for handling platform-specific code in Dart
Dart
8
star
27

wren-sublime

A Sublime Package for the Wren programming language
6
star
28

settings

My personal settings, configurations, and dotfiles.
Shell
5
star
29

multipleinheritance.js

A little hack to get multiple inheritance working in JavaScript.
JavaScript
5
star
30

wren-atom

Atom package for Wren
CoffeeScript
4
star
31

linkedlist

Reversing a linked list
Go
4
star
32

magpie-optionally-typed

The old single-dispatch optionally-typed flavor of the Magpie programming language.
C#
3
star
33

temp-flutter-examples

Temporary repo looking at some Flutter examples
Dart
2
star
34

dep-interface-libraries

DEP for configuration-specific code in Dart
2
star
35

magpie-csharp

The old C#-based Magpie programming language
C#
2
star
36

gallery-constructors

Temporary repo to test out some potential changes around constructors in Dart
Dart
1
star
37

format-flutter

Temporary repo to apply an experimental dart format style to Flutter.
Dart
1
star
38

module_scrape

Temporary code for investigating a module system for Dart
Dart
1
star
39

support

My personal repository for support files: things like color schemes, preferences, and other settings files that it's handy to have centrally accessible.
1
star