@bakkot-dumping-ground/zig-compile

0.0.1 • Public • Published

EXPERIMENTAL

Use zig to eval c via wasm, in JavaScript

let { compile } = require('@bakkot-dumping-ground/zig-compile');

let c = `
  extern int print(int arg);

  int add(int x, int y) {
    return x + y;
  }

  void addAndPrint(int x, int y) {
    print(add(x, y));
  }
`;

let { add, addAndPrint } = await compile({
  source: c,
  language: 'c',
  env: { print: x => console.log('printing from c', x) },
});
console.log('printing from js', add(5, 6));
addAndPrint(20, 22);

But why?

I saw that Knob A fit into Hole B, and then I couldn't stop myself.

Should I use this in production?

No.

Platforms

Right now, just macOS-x86, because that's the only one I've bothered packaging. It's not a lot of work to add more if you want that.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.1
    1
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.0.1
    1

Package Sidebar

Install

npm i @bakkot-dumping-ground/zig-compile

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

3.01 kB

Total Files

3

Last publish

Collaborators

  • bakkot