What is a good VM for developing a hobby language?
Asked Answered
G

4

8

I'm thinking about writing my own little language.

I found a few options, but feel free to suggest more.

  • JVM
  • Parrot
  • OSA

A lot of languages are using the JVM, but unless you write a Java-ish language, all the power the stdlib gives you is going to feel ugly; It's not very good at dynamic stuff either.

Parrot seems a good VM for developing languages, but it has a little abandoned/unfinished/hobby project smell to it.

OSA is what powers Applescript, not a particularly well known VM, but I use Mac, and it offers good system integration.

CLR+Mac doesn't seem a good combination...

My language is going to be an object orientated functional concurrent dataflow language with strong typing and a mix of Python and Lisp syntax. Sounds good, eh?

[edit]
I accepted Python for now, but I'd like to hear more about OSA and Parrot.

Gurnard answered 30/1, 2010 at 10:52 Comment(2)
What about performance and scalability requirements?Expiate
I'd rather use Python or Lua than Scheme I think. There are almost no performance and scalability requirements, it's only going to be used for small tools I write.Gurnard
S
5

One approach I've played with is to use the Python ast module to build an abstract syntax tree representing the code to run. The Python compile function can compile an AST into Python bytecode, which exec can then run. This is a bit higher level than directly generating bytecode, but you will have to deal with some quirks of the Python language (for example, the fundamental difference between statements and expressions).

In doing this I've also written a "deparse" module that attempts to convert an AST back to equivalent Python source code, just for debugging. You can find code in the psil repository if you're interested.

Stomachache answered 30/1, 2010 at 11:26 Comment(5)
That means writing my language in Python, doesn't it? That would be fun... I'll have to think about the limitations.Gurnard
True, using the Python ast library is certainly easiest from Python. You could certainly do worse than choosing Python.Stomachache
How is ast for making a static type system and especially for writing dataflow style functions(call as soon as data arrives)?Gurnard
Naturally, the Python AST isn't specifically designed to be general purpose, but rather it's designed to implement what is needed by Python itself (which is a general purpose language). It's certainly possible to build features such as a static type system and dataflow functions on top of Python, therefore it's also possible in Python AST. It might just be a bit of work, just as implementing such features in straight bytecode for a VM will be a bit of work.Stomachache
Isn't it easier to use Parrot, which is designed to be general purpose?Gurnard
R
4

Have a look at LLVM. It's not a pure VM as such, more a framework with it's own IR that allows you to build high level VMs. Has nice stuff like static code analysis and JIT support

Ricercar answered 30/1, 2010 at 10:57 Comment(1)
I know LLVM from Unladen swallow. Because my language is just a hobby project I think it's better to borrow a VM with a stdlib.Gurnard
Y
2
  • Lua has a small, well-written and fast VM
  • Python VM - you can really attach a new language to it if you want. Or write (use?) something like tinypy which is a small and simple implementation of the Python VM.

Both options above have access to useful standard libraries that will save you work, and are coded in relatively clean and modular C, so they shouldn't be hard to connect to.

That said, I disagree that Parrot is abandoned/hobby. It's quite mature, and has some very strong developers working on it. Furthermore, it's specifically a VM designed to be targeted by multiple dynamic languages. Thus, is was designed with flexibility in mind.

Yurik answered 30/1, 2010 at 10:55 Comment(4)
I'd like to know more about why you think the Lua or Python VM is suitable for me. Parrot might be mature, at least most of the languages on it are incomplete or abandoned.Gurnard
@Pepijn: I've updated the answer. Not sure what else to suggest, unless you have more specific questions?Yurik
I want to pass functions and objects around like values and I'm thinking about a more or less static type system, I also need dataflow stuff. Python has a clear distinction between functions, values, expressions and statements, but its type system is rather dynamic. Will that hinder me? How is that for Lua, Parrot, JVM or OSA?Gurnard
@Pepijn: You can implement type checking on top of Python's VM if you want to.Yurik
G
1

Have you considered Pypy? From what I've read, in addition to being a Python JIT Compiler, it also has the capability to handle other languages. For example there is a tutorial which explains how to create a Brainfuck JIT compiler using Pypy.

Geostrophic answered 10/6, 2012 at 0:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.