Thread overview
Moonshot: a DMD fork that outputs Lua
Feb 21, 2017
Mithun Hunsur
Feb 21, 2017
Meta
Feb 21, 2017
Stefan Koch
Feb 21, 2017
Mithun Hunsur
Feb 21, 2017
pineapple
Feb 22, 2017
Mithun Hunsur
February 21, 2017
Hi all,

I've been working on a little project over the last month and a half, inspired by Adam's dtojs (https://github.com/adamdruppe/dtojs). I've always wanted a typed, powerful, embeddable scripting language, but found the contenders lacking - which is why I decided to hack up DMD to emit Lua.

Introducing Moonshot (https://github.com/Philpax/moonshot)!

Moonshot's based off an early DMD 2.074, and builds up a Lua AST from the D AST. It aims to compile a reasonable subset of @safe code, so that high-level D can be used in scripting environments (i.e. games, scriptable applications, and more.)

Because it's based upon the D frontend, it can already compile a lot of what we consider to be D - including foreach, the full power of metaprogramming, *ranges*, and more. There's an awful lot missing, as well (see the GitHub page for more information), but it's quite promising so far.

Of course, this is still a very early, very untested project - so it's going to break on 99.9% of D code. I'd like to gauge community reaction, but it's nowhere near ready to show off to the wider programming community.

I'd also like to find out if anyone would be interested in me submitting a DConf talk about how Moonshot works, and the benefits of using D as a typed scripting language.

Cheers!

------

P.S. It was incredibly exciting to see `10.iota.map!(a => a * a).filter!(a => a > 50).each!print;` work with unmodified Phobos. The less I have to modify Phobos, the better! :)

February 21, 2017
On Tuesday, 21 February 2017 at 12:45:47 UTC, Mithun Hunsur wrote:
> Hi all,
>
> I've been working on a little project over the last month and a half, inspired by Adam's dtojs (https://github.com/adamdruppe/dtojs). I've always wanted a typed, powerful, embeddable scripting language, but found the contenders lacking - which is why I decided to hack up DMD to emit Lua.
>
> Introducing Moonshot (https://github.com/Philpax/moonshot)!
>
> Moonshot's based off an early DMD 2.074, and builds up a Lua AST from the D AST. It aims to compile a reasonable subset of @safe code, so that high-level D can be used in scripting environments (i.e. games, scriptable applications, and more.)
>
> Because it's based upon the D frontend, it can already compile a lot of what we consider to be D - including foreach, the full power of metaprogramming, *ranges*, and more. There's an awful lot missing, as well (see the GitHub page for more information), but it's quite promising so far.
>
> Of course, this is still a very early, very untested project - so it's going to break on 99.9% of D code. I'd like to gauge community reaction, but it's nowhere near ready to show off to the wider programming community.

This is really cool.

> I'd also like to find out if anyone would be interested in me submitting a DConf talk about how Moonshot works, and the benefits of using D as a typed scripting language.
>
> Cheers!
>
> ------

Absolutely. I'd love to hear you talk about this.


February 21, 2017
On Tuesday, 21 February 2017 at 12:45:47 UTC, Mithun Hunsur wrote:
> Hi all,
>
> Introducing Moonshot (https://github.com/Philpax/moonshot)!

Hi Mithun,

Looking over the code for lua it seems that you use std.format a lot a ctfe.
I would advise against that as it needlessly increases compile times.
The built-in concat operator is supposed to be faster in many cases.

I am interested in how you handle complex types i.e. structs with pointers of the same struct type and the like.

I think moonshot is a worthwhile effort.
Congrats for getting something like this to work.
February 21, 2017
On Tuesday, 21 February 2017 at 12:45:47 UTC, Mithun Hunsur wrote:
> Hi all,
>
> I've been working on a little project over the last month and a half, inspired by Adam's dtojs (https://github.com/adamdruppe/dtojs). I've always wanted a typed, powerful, embeddable scripting language, but found the contenders lacking - which is why I decided to hack up DMD to emit Lua.

This is awesome. Great work! Is there an easy way to see compiler output for some example programs?

I encourage you to submit a dconf talk - I know I'd like to hear more about this - just mind that the submission deadline is coming up in a few days.

February 21, 2017
On Tuesday, 21 February 2017 at 16:18:44 UTC, Stefan Koch wrote:
> On Tuesday, 21 February 2017 at 12:45:47 UTC, Mithun Hunsur wrote:
>> Hi all,
>>
>> Introducing Moonshot (https://github.com/Philpax/moonshot)!
>
> Hi Mithun,
>
> Looking over the code for lua it seems that you use std.format a lot a ctfe.
> I would advise against that as it needlessly increases compile times.
> The built-in concat operator is supposed to be faster in many cases.
>
> I am interested in how you handle complex types i.e. structs with pointers of the same struct type and the like.
>
> I think moonshot is a worthwhile effort.
> Congrats for getting something like this to work.

Hi Stefan,

I figured you'd have some thoughts on the matter! You're right, I've used `std.format` a fair bit out of convenience; I'll see what I can do about going back to regular old concat.

I'm not sure about how I'm going to support pointers/references yet, but I suspect the case you've suggested should be fairly simple. As Lua has reference semantics by default, I'm representing the struct as a table that gets copied on assignment; this means the representation of Struct* should be the same thing, but without the auto-copy.

(Ooh, there's a fun subtopic for a potential talk: representing value types with reference types.)

Thanks for the feedback!
February 22, 2017
On Tuesday, 21 February 2017 at 21:32:51 UTC, pineapple wrote:
> On Tuesday, 21 February 2017 at 12:45:47 UTC, Mithun Hunsur wrote:
>> Hi all,
>>
>> I've been working on a little project over the last month and a half, inspired by Adam's dtojs (https://github.com/adamdruppe/dtojs). I've always wanted a typed, powerful, embeddable scripting language, but found the contenders lacking - which is why I decided to hack up DMD to emit Lua.
>
> This is awesome. Great work! Is there an easy way to see compiler output for some example programs?
>
> I encourage you to submit a dconf talk - I know I'd like to hear more about this - just mind that the submission deadline is coming up in a few days.

Thanks for the feedback! There's no easy way of seeing compiler output, but I've included a few samples here: https://gist.github.com/Philpax/79501f24c22f0b8582252d800bd28dbc. The codegen's pretty bad - there's been little effort to optimise it - but hopefully it will improve over time.

I'm aware of the deadline; just wanted to make sure I had a chance to get feedback first.