1.0.12 • Published 4 years ago

picoc-js v1.0.12

Weekly downloads
525
License
MIT
Repository
github
Last release
4 years ago

picoc-js

This is Picoc recompiled to WASM and distributed as a npm package.

npm shield version npm shield size

Overview

Original Repo: https://gitlab.com/zsaleeba/picoc/

PicoC is a very small C interpreter for scripting. It was originally written as a script language for a UAV's on-board flight system. It's also very suitable for other robotic, embedded and non-embedded applications.

The core C source code is around 3500 lines of code. It's not intended to be a complete implementation of ISO C but it has all the essentials. When compiled it only takes a few k of code space and is also very sparing of data space. This means it can work well in small embedded devices. It's also a fun example of how to create a very small language implementation while still keeping the code readable.

picoc is now feature frozen. Since it's important that it remain small it's intended that no more major features will be added from now on. It's been tested on x86-32, x86-64, powerpc, arm, ultrasparc, HP-PA and blackfin processors and is easy to port to new targets.

Installation

Node.JS

npm i picoc-js

or

yarn add picoc-js

Browser

<script src="https://unpkg.com/picoc-js@1.0.12/dist/bundle.umd.js" type="text/javascript" charset="utf-8"></script>

Example Usage

Node.JS

import {runC} from 'picoc-js';

const cprog = `
#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!\n");
   return 0;
}
`;

runC(cprog, (output) => { console.log("StdOut: " + output);});

Browser

<script>
const cprog = `
#include <stdio.h>
int main() {
   // printf() displays the string inside quotation
   printf("Hello, World!\n");
   return 0;
}
`;

picocjs.runC(cprog, (output) => { console.log(output) });
</script>

Building Project

Make sure emscripten is installed and sourced. Then you can simply run:

yarn build

Should build the latest version and compile it into bundle.js

1.0.11

4 years ago

1.0.12

4 years ago

1.0.9

4 years ago

1.0.10

4 years ago

1.0.8

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.0

4 years ago