Closed decahedron1 closed 4 years ago
Hi @eclipticccc ,
I'm developing NectarJS ( https://github.com/NectarJS/nectarjs ) and we are able to compile a good part of js, object, class ... Our function system looks like what you described.
We use a c++ backend to achieve that, and NectarJS is right now compatible with a lot of environment ( Windows, Mac, Linux, Android, iPhone, Arduino ...)
We will target to properly finish to compile ES3 before the other specs, but the intetesting part is that we can also compile TypeScript, and it's easy to include C or C++ lib with our ffi system (kind of c++ js macro). We also manage infinity, Object, JSON, and we are starting Date and Regexp. We are experimenting some databases module (mysqlx). We use different --env flags regarding the compilation target (std, node, android, ios...), and we started to integrate LibUV for Node env.
Memory is completly managed in real time without garbage collector and we beat NodeJS with mathematical functions (you can try fibo.js)
Don't hesitate to take a look at the project and to submit issues.
Oh god, AGPL
@kungfooman we will change it soon
@adrien-thierry NectarJS looks great! However, the license is a bit disappointing as kungfooman said. Right now I'd say NectarJS and ts2c are about the same in terms of ES3 support. Nectar looks really promising though, and maybe ts2c can learn from some parts of Nectar.
I think Nectar would be perfect if:
.prototype
s.prototype
s once prototype support is addedI won't go too much farther as this is a ts2c issue. If you'd like I could make some pulls to address some of these issues to the best of my ability (again, not too good with C).
As for ts2c though, I feel that functions being objects should be our main priority. If we can get this implemented then we can finally finish classes.
@eclipticccc i will add . prototype support, object are working in NectarJS, i just have to add a default property to objects to support it.
In NectarJS, functions are objects and this is already implemented.
Object, Array, Date, JSON are already builtin
Don't hesitate to open issues on NectarJS. Right now, we are developing what we need for production, if people Can Say what they need, we can add it.
Btw, the license problem will be solved very soon
We are really, really close to finishing all ES3 features. I'd love to implement all of these, but I'm a bit busy right now...
with
- nobody really uses it, it's best to just leave it out right nowinstanceof
- sadly, I don't think we'll be able to implement this, seeing as we're in C...Infinity
- could be defined as1.0 / 0.0
. In C99,INFINITY
is defined inmath.h
. however, due to the nature of C, numbers overflow instead of stopping at Infinity, so maybe this won't be implemented :/parseFloat
- could useatof
decodeURI*, encodeURI*
- can use this and this*.toLocaleString
- no way!Object.toString
- can convert object to JSONObject.hasOwnProperty
- doesn't seem possible sadly... but it wouldn't matter anyways because of the way objects are implementedString.to*Case
could usetoupper()
andtolower()
.Math
object can just wrap aroundmath.h
.Dates will take a lot of work; let's not touch it for now.
Regexes. Oh boy. We could use something like SLRE which seems pretty promising and light.
As for functions, I think we should completely redesign the way we define & call them in order to have
.call()
,.apply()
, andarguments
. The first parameter of every function will be their ownthis
object. When calling a function, then, if it's not.call()
ed, then we just pass either a globalthis
(likewindow
in the browser orglobal
on node) or the parent object of the function. For example,a.b.c()
->a.b.c(a.b)
, butfoo()
->foo(GLOBAL_THIS)
. The second parameter would be an array of arguments, simply calledarguments
. Then, we parse the JS function parameters and define variables corresponding to each argument in the array.So,
function foo(a, b, c) { ... }
would turn into... (pseudocode)Then, we can implement global
this
by creating an object calledGLOBAL_THIS
and every global variable defined will be put into that object.Also, I might make a PR soon to change
int16_t
tosize_t
, so all processors are happy.