• Stars
    star
    291
  • Rank 141,674 (Top 3 %)
  • Language
    JavaScript
  • License
    BSD 3-Clause "New...
  • Created about 9 years ago
  • Updated about 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C to WebAssembly + asm.js compilation for humans

bonsai-c

Very early work-in-progress

bonsai-c is a compiler from C to WebAssembly and asm.js-compatible Javascript, operating on a fundamentally different model to Emscripten.

Wait, what's wrong with Emscripten?

It's basically Java Applets 2.0.

It's perfect if you've got a great big POSIX C + SDL codebase that you want to run in its own self-contained environment in a browser, but it's not very helpful for writing idiomatic Javascript code that just needs to drop into optimised asm.js occasionally for some heavy lifting.

bonsai-c is a tool for writing programs, not porting them. By building a C compiler from the ground up, rather than bolting a Javascript backend onto a mature C compiler, we can tailor it to the needs of Javascript programmers. You can use it to write a function for calculating fibonacci numbers, and you will get back an asm.js-compliant Javascript module with an obvious entry point, for calculating fibonacci numbers. You will not get a mountain of runtime code to implement file handling and malloc and a million other things you didn't ask for.

bonsai-c won't provide a full C implementation from day one. It won't have fancy features like, for example, strings. What it will do is provide a way for programmers to harness the power of asm.js, with a syntax that's as familiar as it gets.

Build

Install Node.js.

Install jison:

npm install -g jison

Then, from the root of the codebase:

npm install
cd c_parser
npm run build-parser
cd ..

Usage

To compile to asm.js:

node bonsai-c.js --asmjs infile.c

To compile to WebAssembly text format:

node bonsai-c.js --wast infile.c

Running tests

From the root of the codebase:

node ./runtests.js  # run all tests
node ./runtests.js --asmjs  # run asm.js output tests only
node ./runtests.js --wast  # run WebAssembly text output tests only

To run the --wast tests, you must be running Node 8.2 or later, and have wast2wasm from the WABT suite in your path.

More Repositories

1

jasmid

UNMAINTAINED. A MIDI file reader and synthesiser in Javascript
JavaScript
415
star
2

jsspeccy2

Ground-up rewrite of the Javascript Spectrum emulator
JavaScript
164
star
3

jsspeccy3

a ZX Spectrum emulator for the browser
JavaScript
115
star
4

jsmodplayer

A Javascript .MOD music player. (Check out BillyWM and sneilan's forks - this one's out of date...)
JavaScript
69
star
5

django-unjoinify

A library for efficiently retrieving deeply-nested data sets
Python
45
star
6

wagtail-form-example

An example of implementing a Django form on a Wagtail site, without using the 'wagtailforms' module
Python
43
star
7

pharmageddon

a demo on a pharmacy sign
C++
41
star
8

shortcrust

A Python OpenGL framework for Raspberry Pi and the demoscene
Python
24
star
9

fakeplasticcubes

A 9K demoscene intro in Javascript (and framework for future 4-64K intros)
JavaScript
23
star
10

telepath-poc

a proof-of-concept for bridging Python and Javascript objects, for Wagtail StreamField and more
Python
20
star
11

libayemu

C emulation of the AY-3-8912 sound chip and parser for associated file formats - fork of http://sashnov.nm.ru/libayemu.html
C
19
star
12

hdfmonkey

A Swiss Army Knife for working with FAT partitions on Spectrum emulator HDF images
C
16
star
13

papaya

an AY-3-8912 sound chip expansion board for the Raspberry Pi
C
14
star
14

bahn

Ruby API for Deutsche Bahn train information
Ruby
14
star
15

wagtail-freezer

Generates static HTML sites from a Wagtail project
Python
13
star
16

spectrum-sizecoding

Resources from my ZX Spectrum sizecoding seminar at Lovebyte 2021
Assembly
12
star
17

wagtail-headless-preview-poc

Wagtail headless preview proof-of-concept
Python
11
star
18

bazematic

A browser-based ZX Spectrum live-coding environment
HTML
8
star
19

openzxrom

Free replacement for the ZX Spectrum system ROM. (Superseded by OpenSE BASIC: http://sourceforge.net/projects/sebasic/ )
Assembly
6
star
20

actionparsnip

pointy-clicky visualisation builder for javascript
JavaScript
6
star
21

MIDI-to-CNC

Fork of MIDI-to-gcode converter http://tim.cexx.org/?p=633
Python
6
star
22

goldfinch

An open-ended C/Z80 software stack for mass-storage access on the ZX Spectrum
Ruby
6
star
23

midibeep

Convert Standard MIDI (.mid) files into Spectrum BEEP statements
Ruby
5
star
24

spacecrab

An emulator for the Space Invaders arcade machine in CoffeeScript
JavaScript
5
star
25

divideo

Video encoder for ZX Spectrum + DivIDE interface
C
5
star
26

pybahn

A Python library for accessing Deutsche Bahn train information
Python
5
star
27

wagtail-multiple-databases

Sample Wagtail project using multiple databases
Python
4
star
28

kisskill

The ZX Spectrum music video for 'Kiss Kill' by Candy Says
Assembly
4
star
29

wolfy

Wolfenstein raycasting engine for the r0ket platform
C
4
star
30

ticmodplayer

a .mod music player for TIC-80
Python
3
star
31

wagtailstreamfield

prototype for StreamField in Wagtail - see https://github.com/torchbox/wagtail/issues/823
Python
3
star
32

ticfile

A library for reading and writing TIC-80 .tic cartridge files
Python
3
star
33

pnginator

tool for packing javascript into a PNG with an HTML payload
Ruby
2
star
34

fusefat-hdf

ABANDONED - FUSE module for mounting FAT filesystems, extended to support HDF disk images (as used on ZX Spectrum emulators)
C
2
star
35

boogiebadge

a toy sound tracker for the MCH2022 badge
Python
1
star
36

stniccc

An abortive attempt at processing the 2D polygon data from STNICCC 2000 into a coherent 3D scene
JavaScript
1
star
37

this-week-in-wagtail

CSS
1
star
38

bfscript

bfscript: enterprise level web scripting in Brainfuck
JavaScript
1
star
39

djangocon-telepath-demo

Python
1
star
40

alan

a static analyser for Z80 machine code
Python
1
star
41

tic-set-screen

Command-line tool for replacing the cover image of a TIC-80 .tic cartridge file
Python
1
star
42

streamfield-stress-test

A Wagtail project with a really complex StreamField, for testing form rendering performance
Python
1
star
43

mahlerproject

The code powering the 2014 MHS Oxford performance of Mahler's 1st Symphony on 12 networked ZX Spectrums
Assembly
1
star
44

telepathdemo

test project for Wagtail telepath development
Python
1
star
45

exogenesis

demo for the Novation Launchpad
Python
1
star
46

hello-django-libsass

The simplest possible Django project using django-libsass
Python
1
star
47

btfd

Build tool for managing Sphinx documentation across multiple versions
Python
1
star
48

wosproxy

HTTP proxy to the World Of Spectrum archive, for HTML apps and other non-FTP-friendly clients
Python
1
star
49

dogsandducks

Using social media to establish links between human activity and river pollution
Python
1
star