Batavia ES6

25 views
Skip to first unread message

Jonas Obrist

unread,
Jan 21, 2016, 9:38:11 AM1/21/16
to Beeware Developers
Hi everyone,

Batavia looks really interesting, it's something I've thought about attempting myself a few times after discovering byterun [1]. So I thought about maybe trying to hack on it a bit, however it makes extensive use of prototypes in JS, something which I always had trouble properly wrapping my head around. At work, I recently ported all our JS to ES6 and we use babel [2] (and browserify [3] for module support) to turn it into something browsers can run. The result is what I'd consider vastly easier to ready Javascript code that I feel like is a lot easier to maintain/hack too. I'm wondering if this would be something that could be done in batavia.

Please note that I'm not saying the current code is wrong/bad. Also it might come off a bit arrogant for someone who hasn't contributed to the project at all yet to suggest such a change, this was not my intention, it's just that the transition to ES6 made me actually enjoy writing JS at work again and I'd like to share that joy with everyone.

If this is something that you're not interested in at all, I understand that completely. Just wanted to drop my 2ct.

Jonas

Russell Keith-Magee

unread,
Jan 21, 2016, 9:45:03 AM1/21/16
to beeware-d...@googlegroups.com
Hi Jonas,

I’ve only done a surface scan of the capabilities of ES6, but from what I’ve seen, I agree - it looks like a much more humane version of Javascript. 

The usage of prototypes in Batavia isn’t a specific design choice - it’s more a case of making the most of what OO capabilities Javascript provides. I’m certainly open to patches that add ES6 features and conventions to Batavia.

The only pre-requisite I’d put on that would be to ensure that babel (and any other tooling that is appropriate) is fully integrated into he build system. Getting a working Batavia build shouldn’t be major exercise - it should be a single build command, or a simple installation process. I don’t profess any particular expertise in Javascript, so I’m willing to take any advice on what that looks like in practice.

Yours,
Russ Magee %-)

Jonas Obrist

unread,
Jan 23, 2016, 8:05:12 AM1/23/16
to Beeware Developers
Started hacking on this, progress can be seen at https://github.com/ojii/batavia/tree/es6. Wasted a lot of time fighting the build system, but it builds now. Unfortunately looks like I broke some stuff, so I hit errors left right and center. Will see if I can fix this (or need to re-start). Assuming I get this to work, my first real "addition" will be some sort of test runner, as I feel like that might be extremely useful.

Jonas

Jonas Obrist

unread,
Jan 24, 2016, 9:08:23 PM1/24/16
to Beeware Developers
 My branch runs all the examples now, though test.pystone "fails" reporting really weird results. Will have to further investigate.

In the progress of porting, I found a few bugs in the main branch (which don't error because it's run in non-strict mode, so pretty much anything goes). One example is that STORE_SUBSCR uses the wrong order of stack items [1][2][3]. In non strict mode, `7[[1,2,3]] = 4` is "valid" in Javascript, since the es6 code I write runs in strict mode, that errors (as it should!).

I'm trying to find a good way to test this whole thing to find more subtle bugs like that.

If anyone wants to hack on this, here's how to get it set up:

1. check out my branch (see previous msg)
2. run `npm install`
3. run `gulp build`
4. You now have a file batavia/batavia.js. To use it in a browser, you have to load batavia/lib/polyfill.js (or polyfill.min.js) first.

You should usually not edit the files batavia/batavia.js, batavia/batavia.map or batavia/batavia.min.js, those are generated files. Instead hack the stuff in batavia/src/* and run `gulp build`. You can use `gulp watch` to build on file changes. `gulp jshint` can be used to run static analysis (which reports some issues right now because of unimplemented stuff).

Jonas

Reply all
Reply to author
Forward
0 new messages