musictheory / NilScript

Objective-C-style language superset of JavaScript with a tiny, simple runtime
Other
50 stars 5 forks source link

Working on connect-oj...having questions #27

Closed IngwiePhoenix closed 10 years ago

IngwiePhoenix commented 10 years ago

As I am currently working on my middleware for Connect to preprocess and compile OJ files to JS, I have come to a few questions. Mind you, I am using the 1.0 branch.

I am using a minimalistic preprocessor that you may want to look at when I uploaded the code. It basically allows something like this:

#var needsToDerive=false;
#if(needsToDerive) {
@implementation MyObj: BaseClass
#} else {
@implementation MyObj
#}
+(BOOL)ILike:(String)food {
    // ...
}
@end

Kind regards, Ingwie

IngwiePhoenix commented 10 years ago

Oh I forgot: #include(...) works too.

#include("OJFoundation/main.oj");
//...
IngwiePhoenix commented 10 years ago

https://github.com/IngwiePhoenix/connect-oj/commits?author=IngwiePhoenix

I uploaded my current progress. The only part missing is being able to use ojc(). Otherwise, it runs almost as it should. If you only open it with ?runtime, then it will grab the runtime.js located in the same folder as ojc.js. So far, so good. :)

On a side note, AFAIK, Objective-J does not have such an aproach yet.

iccir commented 10 years ago

Good call, ojc needs to be documented more :) Do you need sync behavior? Or is async ok? I'd rather keep it async for now, as it opens up more possibilities for the future.

IngwiePhoenix commented 10 years ago

Async works just fine. I just need its first parameter documented. :)

IngwiePhoenix commented 10 years ago

Just looked at the short API doc and got confused at .files and .contents. I belive that the order matters, as in:

var opt = {
    files: ["main.oj", "other.oj"],
    contents: ["contents of main.oj", "contents of other.oj"]
};

But, wouldn't it be easier to just have a files object?

var opt = {
    files: { "main.oj": "...", "base.oj": "..." }
};
iccir commented 10 years ago

Your way is definitely cleaner, let me try to remember why I did it with two keys. :)

IngwiePhoenix commented 10 years ago

BTW, if you had skype, we could use that to talk about oj stuff - instead of flooding the issues section. :) my skype is: wlaningwie

iccir commented 10 years ago

Note: going with Ingwie's suggestion and making files an object of filename=>content pairs.

iccir commented 10 years ago

Slight modification ;) The reason for the two keys was to preserve the original order of the passed-in files. While oj 1.0 is much better than 0.x at analyzing dependencies, I think there are still some cases where order is important.

That said, I dislike files and contents as siblings which must be kept in sync. We should just have files.

If files is an Array of String objects, have the compiler read each file for the contents.

If files is an Array of Object objects, both the filename and the contents can be provided. This also opens up per-file compilation options in the future.

iccir commented 10 years ago

All of these should be on master now. Ingwie, please feel free to file more bugs if you have more questions :)