Coder Social home page Coder Social logo

grain-loader's Introduction

Grain Webpack Loader

Introduction

This is an experiment with loading the Grain programming language in Webpack. The loader packs .gr files into runnable JS functions that return a promise that resolves with a string containing the result from running the Grain program.

This loader is extremely rough and mostly serves as a exploration into what compiler/runtime/lib changes are required for this to work eventually.

Caveats

  • The Grain runtime is injected with every .gr file that gets loaded at the moment.
  • All dependencies of a single Grain file are included in the bundled code rather than required separately.

Alternative implementations

Since static linking doesn't exist in Grain yet, the way this loader works (turning .gr files directly into runnable JS) requires hackily finding dependencies by parsing out the module imports of the compiled Grain WASM and then recursively injecting all module imports required as part of the outputted JS code.

Some other ideas that might work better:

  1. The loader could be setup to require wasm-loader, and then grain-loader would only compile the Grain files and then wasm-loader would be used to load the .wasm. This should allow the URL locator built into the Grain's runtime browser to load modules properly as long as all of the wasm files are outputted to the build directory.
  2. The existing implementation would probably be fine if Grain had some sort of linking metadata and then we could confidently inject those modules rather than the hacky "linking" done by this load.

grain-loader's People

Contributors

z0w0 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.