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.

2
  • What about performance and scalability requirements? Commented Jan 30, 2010 at 11:01
  • 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. Commented Jan 30, 2010 at 11:46

4 Answers 4

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.

Sign up to request clarification or add additional context in comments.

5 Comments

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

1 Comment

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.
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.

4 Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.