munificent / magpie
The Magpie programming language.
Clone this repository (size: 970.5 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/munificent/magpie/
| commit 66: | 3c6192cb83f0 |
| parent 65: | 011b31e22ff5 |
| child 67: | e717210cc6ae |
Got rid of unneeded TupleFieldExpr.
NB: This is not the latest revision. For the latest view, go to tip.
| filename | size | last modified | ||
|---|---|---|---|---|
| BytecodeFile.cs | 2.4 KB | 4 months ago | Added support for passing a string to Main (or not). | |
| BytecodeGenerator.cs | 8.0 KB | 4 months ago | Got rid of some unneeded bound expr types. | |
| JumpTable.cs | 2.5 KB | 11 months ago | Cleaning up a few more loose ends after the bytecode format… | |
| OffsetTable.cs | 1.6 KB | 11 months ago | Cleaning up a few more loose ends after the bytecode format… | |
| OpCode.cs | 2.4 KB | 4 months ago | Got a bunch of infrastructure in place for compiling code… | |
| StringTable.cs | 1.2 KB | 11 months ago | Bytecode format is now a "purer" binary format. |
README
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | _/Oo>
/(MM)
A___/ m a g p i e
_______AV_h_h___________________________
AV
AV
AV
Magpie is a simple, embeddable, strongly-typed
memory-managed procedural language.
Like its namesake, it collects the shiniest parts
of several different languages:
- The syntax looks a lot like Ruby.
- But is as simple as Smalltalk.
- Its simple and procedural like C.
- But garbage collects memory like Java.
- Its type system is like ML's.
- But its generics are like C++ templates.
- Its small and embeddable like Lua.
The result, I hope, is a cohesive little language
suitable for embedding but with better error-
checking and performance than the dynamic
languages most typically used for embedding today.
It is also a bit of an experiment to see if the
procedural paradigm is still relevant if you bring
in modern advancements in memory management and a
cleaner syntax.
--- Hello, world! --------------------------------
Here's a tiny sample of Magpie:
Main (->) Print "Hello, world!"
Like C, all code must reside in functions, and
execution starts by calling Main. The (->) is the
signature for the function. In this case, Main
takes no arguments and returns nothing. Here's a
slightly more interesting example:
Main (->) Hello World
Hello (who String ->)
def text <- "Hello, " + who
Print text
end
World (-> String) "world!"
This program still prints "Hello, world!", but
shows a few more language features. It defines
three functions: Main, Hello, and World.
Main calls World, passing it no parameters. It
then passes the result of that to Hello. In C,
this would look like Hello(World()).
Hello takes a single string argument and places it
in the variable "who". The body of Hello is a
block: an expression containing a list of other
expressions. The first expression in the block
defines a local variable "text", and assigns it
the result of concatenating "Hello, " and who.
In Magpie, variables are not declared with types.
Instead, the type is inferred from the expression
used to initialize it. Variables are always
initialized when declared. This gets rid of
uninitialized variable errors.
Assignment is done using "<-" instead of "=" like
in other languages. This is to clarify that
assignment isn't really related to equality at
all.
World takes no arguments but returns a string, in
this case the literal "world!". Functions do not
need an explicit "return" in Magpie: the result of
evaluating the function body is implicitly
returned like in Ruby.
--- How do I poke at it? -------------------------
To try things out for yourself, you'll need to:
1. Get the source. If you're reading this, you
probably have it.
2. Build Magpie. The Visual Studio solution is
/csharp/Magpie.sln
If you don't have Visual Studio, you can
download Visual Studio Express for free from
Microsoft. It's quite nice actually.
Magpie *should* be able to build with Mono, I
think. It doesn't really depend on much. But I
haven't tried to yet.
Anyway, build that solution.
3. Write yourself a little script. Call it
"awesome.mag" and put something awesome in it.
Maybe:
Main (->)
for i <- 1 -to- 100 do
Print "Awesome!"
end
end
4. Run it. The VS solution builds magpie to
/csharp/bin/Debug/magpie.exe
Open that in a command prompt and do:
magpie.exe awesome.mag
If you actually put your awesome script in
there, you should see a lot of awesome now.
--- Where's it at --------------------------------
Magpie still has a good way to go before it's
ready for real use. The ultimate goal is to have
a portable ANSI C interpreter and a self-hosting
compiler.
Right now, there is a prototype C# compiler and
interpreter. My plan is to get most of the
language features working cleanly in the C#
compiler, and then port that over to Magpie. The
C interpreter should be comparatively easy (with
static languages, most of the work is in the
compiler).
In the meantime, a lot of the language is still in
flux, and several important features (pattern
matching, lazy evaluation, closures) have yet to
be implemented. But many other things are there
and working: unions, structs, generics. There's
plenty to play around with.
|
