Skip to content

Move JS codegen for compile into psc#1095

Merged
paf31 merged 25 commits intomasterfrom
external-ffi-files
Jun 3, 2015
Merged

Move JS codegen for compile into psc#1095
paf31 merged 25 commits intomasterfrom
external-ffi-files

Conversation

@garyb
Copy link
Copy Markdown
Member

@garyb garyb commented May 2, 2015

@paf31 how does this approach look for psc?

I really like the idea of using require for the psc-make foreigns, if we can figure out the details for that.

  • Load foreign files in psci
  • Don't use error for foreign-related errors in psc
  • Don't use error for foreign-related errors in psc-make
  • Don't use error for foreign-related errors in psci
  • Error on duplicate foreign modules (multiple JS files with the same // module X.Y.Z comment)
  • Output deprecation message when encountering foreign import with literal
  • Restore DCE for psc
  • Make tests work again

@garyb
Copy link
Copy Markdown
Member Author

garyb commented May 2, 2015

A proposal for how psc-make might work with require (I mostly rambled this on IRC but not sure if you saw it):

  1. We still use the method of a second command line option to accept FFI files
  2. We still read these files for a // module X.Y.Z comment
  3. During make, copy these js files to output/X.Y.Z/foreign.js
  4. Then we just need to include var _ffi = require("./foreign.js"); (or whatever for the var) in the output/X.Y.Z/input.js file.

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented May 2, 2015

👍 Looks nice, and I like the FFI suggestion.

I guess we can tidy up the Options structure if we manage to do a similar thing with psc-make too.

So what's the plan for psc-make? I guess if we want to use require for module imports, it seems like we're heading down the path of using psc-make as the main JS backend. That's good, but we would need to figure out a way to do dead code elimination afterwards. I like the idea of adding simple delimiting comments to the Common JS module, and also indicating dependencies. That way, psc-make could generate those comments too, and psc-bundle (or whatever we want to call it) could process those comments and do DCE. The comments might get a bit large though.

@garyb garyb added this to the 0.7.0 milestone May 3, 2015
@garyb
Copy link
Copy Markdown
Member Author

garyb commented May 3, 2015

Like an idiot I spent half the afternoon using language-javascript to try and extract the module comment out of the source, which worked, but was a ton of code as I made a traversal type thing for the AST, etc. and then as soon as I was done realised that just parsing the lines in the file would be a lot easier. Oh well.

I'm going out for a bit, but will be back later to get this working at last.

How does $foreign sound for the JS name for the require'd/embedded object containing the foreign definitions?

@garyb garyb force-pushed the external-ffi-files branch 2 times, most recently from cf5de08 to ddb98d9 Compare May 9, 2015 18:05
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using TokenParser here seems a little odd, since we're not really dealing with PS tokens. Maybe just using lines, and looking for // at the start is enough.

Also, maybe we want to define some type of custom comment, since it's not out of the question that a normal JS comment would begin with // module.

Finally, if we use lines, we can define a custom format for other metadata, like dependencies for DCE.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess that's true. It is a convenient way of extracting a proper ModuleName from a string though.

This does run over all the lines in the file, so if there are multiple comments that look like // module it will only take the first one that actually parses as having a ModuleName following it.

@garyb garyb force-pushed the external-ffi-files branch from 2d8ed9d to 911af32 Compare May 14, 2015 08:53
@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 3, 2015

@garyb I fixed up psci and the test suites. All that's left now is hopefully DCE so let's discuss that when you have time. I think we should make a release candidate though, so that we can start updating libraries again, and so that @hdgarrood and @nicodelpiano have a reasonable place to send PRs for GSOC.

Fingers crossed that the CI build works ...

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 3, 2015

Well, CI is passing apart from the core-tests step, which we expect to break right now.

@garyb
Copy link
Copy Markdown
Member Author

garyb commented Jun 3, 2015

I'm happy to merge this then, if you are?

@paf31
Copy link
Copy Markdown
Contributor

paf31 commented Jun 3, 2015

Yep!

paf31 added a commit that referenced this pull request Jun 3, 2015
Move JS codegen for compile into psc
@paf31 paf31 merged commit ef27736 into master Jun 3, 2015
@paf31 paf31 deleted the external-ffi-files branch June 16, 2015 01:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants