nerd icon indicating copy to clipboard operation
nerd copied to clipboard

Various issues discovered while compiling Rawrcat

Open wbrown opened this issue 5 years ago • 15 comments

I saw this project, and decided to give it a shot on compiling my JavaScript implementation of RawrCat.

https://github.com/ephsec/rawrcat

Tested versions:

  • NectarJS v0.7.99
  • NectarJS master off github.

Invoking nectarjs on rawrcat.js uncovered several issues:

  • delete item[k] throws a parse error in babel

  • for() loops require explicit var declaration inside the for() if the variable isn't defined beforehand. (This is something I will fix in my source code, for linting purposes)

  • My use of null comparison isn't yet supported:

Visitor VISITOR.objectExpression not implemented yet for NullLiteral
  • My use of conditional expressions doesn't seem to be much liked either:
Visitor VISITOR.objectExpression not implemented yet for ConditionalExpression

Is there a debug mode that will tell me exactly where in the source it's having issues? --verbose does not appear to do much.

This project interests me, and I'd like to help get it to where it can compile RawrCat. I'm a language, parser, and compiler nerd myself.

wbrown avatar Nov 10 '20 17:11 wbrown

Hi @wbrown ,

thank you for your interest in NectarJS,

I will try to compile Rawrcat to check the bugs and correct them

Right now there is no debug mode, but it's on the roadmap

adrien-thierry avatar Nov 10 '20 18:11 adrien-thierry

  • for() loops require explicit var declaration inside the for() if the variable isn't defined beforehand. (This is something I will fix in my source code, for linting purposes)

I've just corrected the above in my source code, as it's actually more correct code to use var to avoid bringing in scope from outside the loop.

wbrown avatar Nov 10 '20 18:11 wbrown

the file you want to compile is rawrcat.js ?

adrien-thierry avatar Nov 11 '20 17:11 adrien-thierry

@adrien-thierry Yes, sir. Though now that I think about it -- how does it handle require() calls?

wbrown avatar Nov 11 '20 21:11 wbrown

Ok, i will check it

For require, code is encapsuled into a function call then integrated in the code

adrien-thierry avatar Nov 11 '20 21:11 adrien-thierry

@adrien-thierry Any updates? Any way I can help? :)

wbrown avatar Nov 17 '20 19:11 wbrown

Hi, yes sorry, a lot of things ti do haha

NectarJS doesn't support dynamic require yet, can you modify this ?

I will add the missing visitors and missing method

adrien-thierry avatar Nov 17 '20 23:11 adrien-thierry

I corrected the delete item[k] problem, I will continue to correct things until we can compile Rawrcat

adrien-thierry avatar Nov 19 '20 10:11 adrien-thierry

NectarJS doesn't support dynamic require yet, can you modify this ?

So what do you mean by this? Just static require statements for the modules in question?

Rather than wrapping require in a handler with a variable passed, do static requires for the modules?

i.e. rather than: https://github.com/ephsec/RawrCat/blob/master/rawrcat.js#L17-L36

... and dynamically loading the modules in at runtime, like so: https://github.com/ephsec/RawrCat/blob/master/index.html#L43

... we do:

require("js/rawrterm.js")

... ?

wbrown avatar Nov 19 '20 19:11 wbrown

Yes, exactly, atm, require in NectarJS is a macro that manage code including wrapped in a module. When NectarJS will be self compiled, we will be able to self embed the compiler and generate code from module on the fly, but for now, the only solution is to use static require

adrien-thierry avatar Nov 20 '20 09:11 adrien-thierry

@adrien-thierry Is there a test or variable I can check to detect that that the code is being compiled by NectarJS, or running as a NectarJS-produced executable?

I've managed to avoid a build system thus far by checking the runtime environment, and I'd like to continue to do this if possible. :)

wbrown avatar Nov 20 '20 15:11 wbrown

Yes, you can check the __NJS_ENV global var like :

if(__NJS_ENV)
{
  // NectarJS
}
else 
{
 // not NectarJS
}

The __NJS_ENV var store the name of the env you compile the code with (std, android, arduino, node ...)

adrien-thierry avatar Nov 20 '20 16:11 adrien-thierry

@adrien-thierry I've added the check for the existence of __NJS_ENV, hopefully this works:

https://github.com/ephsec/RawrCat/commit/7b38fd99ec5d7f699a2a9157f4ec8a7c6461e03b

wbrown avatar Nov 20 '20 17:11 wbrown

Hi @wbrown , I corrected some problems, i will continue

adrien-thierry avatar Dec 02 '20 08:12 adrien-thierry

Hi @wbrown , I corrected some problems, i will continue

Awesome. Which problems, out of curiosity?

wbrown avatar Dec 07 '20 21:12 wbrown

Hi @wbrown , we implemented our own parser, we will release a big update soon

adrien-thierry avatar Nov 15 '22 02:11 adrien-thierry