0.0.9 • Published 6 years ago

node-tinycc v0.0.9

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Run inline C code on the fly.

Tested on:

  • Linux with nodejs 6.11 64 bit, (gcc 4.8 on x86, gcc 6.3 on ARM)
  • Windows 10 with nodejs 6.11 32 and 64 bit
  • OSX 10.10 with nodejs 6.10, llvm 3.5 (Cave! TCC is not fully ported to OSX, support is experimental!)

Features

  • inline C functions in JS
  • JS callbacks in C
  • wchar_t, struct and array support
  • async compilation support

Documentation

See the API documentation.

Usage

const tcc = require('node-tinycc');

// create a code generator
let gen = tcc.CodeGenerator();
// create a compile state
let state = tcc.DefaultTcc();

// declare a C function
let c_func = tcc.c_function(
    'int',                          // return type
    'add',                          // function name in C
    [['int', 'a'], ['int', 'b']],   // parameters as [type, name]
    'return a + b + js_func(a, b);' // actual code
);
gen.addDeclaration(c_func);

// add a JS function declaration to C
let js_func = tcc.c_callable(
    'int',                          // return type
    'js_func',                      // function name in C
    ['int', 'int'],                 // parameter types
    (a, b) => {return a * b;}       // function
);
gen.addDeclaration(js_func);

// compile code and relocate
state.compile(gen.code());
state.relocate();

// resolve symbols between C and JS
gen.bindState(state);

// now the C stuff is usable
console.log(c_func(23, 42));        // --> prints 1031

See demos and tests for more usage examples.

0.0.9

6 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago