News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

JavaScript compiler for z80 machines is available!

Started by reeagbo, 08:14, 06 June 25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

reeagbo

Hi all,

I´m coming from the ZX spectrum world and I have some news that might be interesting for some of you. As some of you I'm spending long hours writing code in z80 assembly. In the case of the ZX Spectrum, there is also its embedded (and not very useful) Basic interpreter. Well, I've spent last months writing a JavaScript cross-compiler for the ZX, but now I´m thinking that with little adaptations it could work in other z80 machines as MSX, Amstrad o Gameboy. That's why I´m here.

All the information can be found here:
https://github.com/reeagbo/Jassco

If you are curious about what it does, there is a technical description here:
https://github.com/reeagbo/Jassco/blob/ ... ription.md

Basically, the compiler is written in Python and you can run it easily in your PC. It can create z80 assembly code for pretty much any code written in JavaScript ES2, which is an old version, but it already does a lot of things (if/break continue, while/do, do/while, for, switch, etc...). It works with 16-bits signed integers. It does binary expressions, unaries, ternaries, comparisons, arrays, matrices, bit-wise operation, logical operations...

I´d like to know if the GB community would be interested in having something like this. Supporting GB would not be a big deal since I've separated all the I/O stuff from the main code.

Please, let me know what you think and if someone would be willing to help me with the adaptation.

eto

Quote from: reeagbo on 08:14, 06 June 25I´d like to know if the GB community would be interested in having something like this. Supporting GB would not be a big deal since I've separated all the I/O stuff from the main code.
Not sure about the GB community as they are not really on this forum ;-) but I definitely am.

reeagbo

My bad. I confused the GameBoy forum and the CPC forum, that's why it reads GB.

Anyway, if you are interested in trying itÇ:
- the latest version is in the Software folder.
- there is a User Manual, explaining how to do the "Hello, World!" thing in Eclipse or in a more pedestrian environment. It´s not so great but it helps.
- And then, once you manage to make it work, you can find some tested examples in the Example folder, showing the kind of complexity the compiler allows. It's not something you can use directly in your CPC emulator. 

As I mentioned, all the output compilation is ZX Spectrum oriented, but only by adapting the "io.asc" file to the requirements of the CPC, it should work (I guess).

Let me know if you want to try yourself and, if so, how far you got.
Alex



Quote from: eto on 13:15, 06 June 25
Quote from: reeagbo on 08:14, 06 June 25I´d like to know if the GB community would be interested in having something like this. Supporting GB would not be a big deal since I've separated all the I/O stuff from the main code.
Not sure about the GB community as they are not really on this forum ;-) but I definitely am.

zhulien

That's cool, thanks

I am going to add transformer plugins to CyborgShell (new name for hcjs) so that as you type in one file, the transformer can generate the content of another.  This will let me plugin me JSCC logic in so we end up with automatic Z80 from typing JS.

CyborgShell (HCJS before rebrand) http://8bitology.com/

JSCC https://youtu.be/q8kBgWHT944?si=bJJt-JzT97s-PrVX

OHCJS and JSCC soursecode here. https://github.com/PrimalNinja?tab=repositories

It's interesting they support ES2, I also chose a subset of ES5 (possibly it fits into ES2 subset also)

zhulien

BTW eval is one of the most used JS functions for dynamic and system programming,  I couldn't imagine lack of eval

reeagbo

Quote from: zhulien on 18:15, 07 June 25I'm kind of overflown by your message.  ;)
I'm not familiar with CyborgShell or jscc. I've seen the video and it's supercool to see how it translates on the go. I'm wondering if you expect me to do something on my side.
Regarding JS version chosen, ES2 is simple enough for me to make it doable. ES2 is complex enough to produce nice z80 code.  Later versions include too many possibilities.
Alex

That's cool, thanks
I am going to add transformer plugins to CyborgShell (new name for hcjs) so that as you type in one file, the transformer can generate the content of another.  This will let me plugin me JSCC logic in so we end up with automatic Z80 from typing JS.
CyborgShell (HCJS before rebrand) http://8bitology.com/
JSCC https://youtu.be/q8kBgWHT944?si=bJJt-JzT97s-PrVX
OHCJS and JSCC soursecode here. https://github.com/PrimalNinja?tab=repositories
It's interesting they support ES2, I also chose a subset of ES5 (possibly it fits into ES2 subset also)
Quote from: zhulien on 18:15, 07 June 25That's cool, thanks

I am going to add transformer plugins to CyborgShell (new name for hcjs) so that as you type in one file, the transformer can generate the content of another.  This will let me plugin me JSCC logic in so we end up with automatic Z80 from typing JS.

CyborgShell (HCJS before rebrand) http://8bitology.com/

JSCC https://youtu.be/q8kBgWHT944?si=bJJt-JzT97s-PrVX

OHCJS and JSCC soursecode here. https://github.com/PrimalNinja?tab=repositories

It's interesting they support ES2, I also chose a subset of ES5 (possibly it fits into ES2 subset also)

reeagbo

I´m not an advanced programmer myself so i trusted some place on the internet indicating eval() was sort of outdated, but if you have a better advice, I´m happy to consider it. I can choose whatever I like for the trick that I´m doing.

BTW eval is one of the most used JS functions for dynamic and system programming,  I couldn't imagine lack of eval

zhulien

thanks for introducing us to Jassco - i hope it enables JS programmers to code on CPC too.

zhulien

Quote from: reeagbo on Yesterday at 09:56I´m not an advanced programmer myself so i trusted some place on the internet indicating eval() was sort of outdated, but if you have a better advice, I´m happy to consider it. I can choose whatever I like for the trick that I´m doing.

BTW eval is one of the most used JS functions for dynamic and system programming,  I couldn't imagine lack of eval
One of the most useful uses of eval is to callbyname, or to generate code / or inject code on the fly then call it - since you have inbuilt assembler you probably don't need eval.  Can you currently use functions as parameters in Jassco? I didn't see that mentioned. It is sort of like the JS equivalent to a pointer to a function so you can pass it as a parameter into a fucntion then call it later.


function doSomethingA() {alert('a');}
function doSomethingB() {alert('b');}
function doAnything(callback) {callback();}
doAnything(doSomethingA);  doAnything(doSomethingB);

The above code will first alert A, then alert B

function doSomethingA() {alert('a');}
function doSomethingB() {alert('b');}
eval('doSomethingA(); doSomethingB();');

The above code has the same result as the callback example, but done in a different way.  If you wanted to read JS from a script at runtime, you can do the eval.  But given you are not running JS on the Z80, maybe the callback method is useful, eval would not be so.

reeagbo

Quote from: zhulien on Yesterday at 17:27
Quote from: reeagbo on Yesterday at 09:56I´m not an advanced programmer myself so i trusted some place on the internet indicating eval() was sort of outdated, but if you have a better advice, I´m happy to consider it. I can choose whatever I like for the trick that I´m doing.

BTW eval is one of the most used JS functions for dynamic and system programming,  I couldn't imagine lack of eval
One of the most useful uses of eval is to callbyname, or to generate code / or inject code on the fly then call it - since you have inbuilt assembler you probably don't need eval.  Can you currently use functions as parameters in Jassco? I didn't see that mentioned. It is sort of like the JS equivalent to a pointer to a function so you can pass it as a parameter into a fucntion then call it later.


function doSomethingA() {alert('a');}
function doSomethingB() {alert('b');}
function doAnything(callback) {callback();}
doAnything(doSomethingA);  doAnything(doSomethingB);

The above code will first alert A, then alert B

function doSomethingA() {alert('a');}
function doSomethingB() {alert('b');}
eval('doSomethingA(); doSomethingB();');

The above code has the same result as the callback example, but done in a different way.  If you wanted to read JS from a script at runtime, you can do the eval.  But given you are not running JS on the Z80, maybe the callback method is useful, eval would not be so.

That sort of call is not something I´m even considering at the moment. You can pass parameters in the function call, and those can be integers or strings. And you can return 1 result, and that would be it, so i guess I can continue using eval() after all. If I discover this is a problem I can change it to anything else in the future.

Powered by SMFPacks Menu Editor Mod