Wednesday, May 20, 2015

Monkey2 translator output.

One of the things I was hoping to achieve this time around with monkey2 was 'clean' translator output. Anyone who's looked at the native code monkey1 generates will agree it's a bit of a mess!

I was hoping that the c++ output, at least, could look like a bit like 'real' c++, eg: this...

namespace mojo

class Image
   class Frame

...could translate to...

namespace mojo{
   class Image{
      class Frame{

Alas, it's not that simple.

The main issue with nicely scoped c++ is that it turns out you can't 'forward reference' inner classes - at all! This is a new one on me, but one of the things I really like about monkey1 is how all the forward referencing issues you have in c/c++ just don't exist, and I want the same to be true of monkey2. So I have decided to abandon nicely scoped c++ output for now.

I was also hoping I could rely on c++'s function overloading to allow me to use the same function names for overloaded functions.

This mostly works, except when using overloaded member pointers. You can 'cast your way' out of the problem (see: but that's pretty nasty. It's easier for monkey to just mung a new name for overloaded functions, so I've decided to go with that for now too.

So c++ output wont be as sexy as I'd hoped, but there is an upside to this: the translator is now much more 'universal' and will be easier to adapt to other target languages. This is probably what I should have aimed for in the first place.

The output WILL be cleaner than monkey1's though, mainly because, for now at least, I only have to write one translator! Having to write 5 at once was a killer, and the quality of each suffered.

Thursday, May 14, 2015

...and Mojo2!

And in further news...mojo2 is on the way!

I've been working on this for several months now, in collaboration with Tony from Playniax (who has news of his own!) and it looks like mojo2 should be ready for release within a month or so.

Mojo2 is, like mojo1, fundamentally a 2D engine. However, it adds a few useful 3d features such as lighting (with normal/specular maps) and the ability to use 3d projection/view matrices. Mojo2 is ONLY compatible with targets that support the OpenGL module. That is, the desktop, ios, android and html5 targets.

A brief overview of features:

You can render directly to the app window or an image using the Canvas class, eg:

Local canvas1:=New Canvas                  'render to app window
canvas1.SetProjection2d 0,VWIDTH,0,VHEIGHT 'set 'virtual resolution'.

And to render to image:

Local image:=New Image( 256,256 )
Local canvas:=New Canvas( image )       'render to image!

The canvas methods available should be familiar to anyone who has used mojo1, although a  few have been tweaked/renamed here and there.

You can also perform simple 'direct mode' lighting using canvas, eg:

canvas.SetLightType 0,1                'turn on light 0.
canvas.SetLightRange 0,100             'set light 0 range.
canvas.SetLightPosition 0,320,240,-25  'set light 0 position.
canvas.DrawImage...                    'image will be lit!
canvas.SetLightType 0,0,               'light 0 off again.

You can use up to 4 lights in 'direct mode' like this. Shadows are also possible using direct mode, but it starts getting tricky...

To help deal with multiple lights and shadows, mojo2 also provides a 'Renderer' class that provides a sort of 'virtual scene manger'. You add layers and lights to a renderer, and when you call Render() it will take care of all the tricky multi-pass rendering stuff. It is NOT a complete scene graph, but something you can plug a scene graph (simple or complicated) into.

There is also simple 'shader support' in that you can write glsl shader code that samples textures and produces values suitable for lighting.

There are still a few details to be worked out, but that's about the jist of it! Price wise, it'll be added to the commercial monkey-x package and will be free to existing monkey-x owners.


Saturday, May 2, 2015


Ok, some fairly big news: I've decided to start work on Monkey2!

I'm going with an open source/crowd funded approach this time, as I don't consider the idea of selling languages to be commercially viable these days. I am planning to start with a patreon project (see: which I hope to have up in a week or so.

Is there any point to writing a new language? In a way, probably not, as I'm constantly reminded each time I read a slashdot thread about new language XYZ! But I do think there's a core bunch of people who like using BRL languages (myself included) and since I also really like making them, I'm gonna try to figure out a way to continue to do just that as a full time thing.

The basic idea is to fix the problems in the monkey1 language, add some cool new language features, and take the build/runtime system in a much more blitzmax-ish direction. To this end, monkey2 will initially only support c++ targets that have a posix-ish api, which effectively means that only the desktop, ios and android targets will be supported. However, since the overall approach is basically the same as monkey1 - ie: everything ends up going through a translator - the potential is there to support more targets in the future. Alas, as I found out with monkey1, emitting code in bunch of target languages is the 'easy' bit...

Losing html5 hurts, but without it the range of 'lowest common denominator' features becomes much richer, and the job of supporting all those features much simpler. Most of the other targets are pretty much dead now, so I'm not too sad about losing them. Besides, they'll live on in monkey1 which I fully intend to continue to support and tweak.

Why not just 'fix' Monkey1? Mainly because it's gotten pretty tricky to sanely tinker with in certain areas - areas that I really, really want to tinker with. It was my first attempt at an OO language with generics, and I will freely admit that I didn't quite nail it first time around. But I've been hacking away on Monkey2 for the last week or so, starting from the ground up with a new parser, a new approach to semantic analysis etc, and I am very happy with how it's going and (finally) feel confident I can do much better this time.

All in all, it is my hope that monkey2 will find a nice balance between monkey1's sexier language and blitzmax's 'hackability'.

There is nothing to release yet, but I've added a Monkey2 forum to so feel free to post comments and questions there.