views:

227

answers:

3

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.

+2  A: 
  • 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.

Eli Bendersky
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.
Pepijn
@Pepijn: I've updated the answer. Not sure what else to suggest, unless you have more specific questions?
Eli Bendersky
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?
Pepijn
@Pepijn: You can implement type checking on top of Python's VM if you want to.
Eli Bendersky
+3  A: 

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

zebrabox
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.
Pepijn
+2  A: 

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.

Greg Hewgill
That means writing my language in Python, doesn't it? That would be fun... I'll have to think about the limitations.
Pepijn
True, using the Python `ast` library is certainly easiest from Python. You could certainly do worse than choosing Python.
Greg Hewgill
How is `ast` for making a static type system and especially for writing dataflow style functions(call as soon as data arrives)?
Pepijn
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.
Greg Hewgill
Isn't it easier to use Parrot, which is designed to be general purpose?
Pepijn