Skip to content

Commit 19451c0

Browse files
authored
Merge pull request #1 from jerch/upgrade_22
node 22 & 24 support
2 parents 3139700 + 7444da4 commit 19451c0

9 files changed

Lines changed: 3788 additions & 180 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
Run inline C code on the fly.
22

3-
Tested on:
3+
Version 0.0.9 tested on:
44

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

10+
Version 0.1.0 tested on:
11+
12+
- Linux with nodejs 22 & 24 (x86 only)
13+
1014
### Features
1115

1216
- inline C functions in JS

demos/sdl.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77
const C_CODE = `
88
#include <stdio.h>
9+
#define SDL_DISABLE_IMMINTRIN_H
910
#include <SDL2/SDL.h>
1011
1112
typedef void (*Callback)(int, int, int);
@@ -19,7 +20,7 @@ void run_sdl(int width, int height) {
1920
SDL_Window* window = NULL;
2021
SDL_Surface* screenSurface = NULL;
2122
if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
22-
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
23+
printf("SDL could not initialize! SDL_Error: %s\\n", SDL_GetError());
2324
return;
2425
}
2526
window = SDL_CreateWindow("SDL Example",
@@ -28,7 +29,7 @@ void run_sdl(int width, int height) {
2829
width, height,
2930
SDL_WINDOW_SHOWN);
3031
if(!window) {
31-
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
32+
printf("Window could not be created! SDL_Error: %s\\n", SDL_GetError());
3233
return;
3334
}
3435
screenSurface = SDL_GetWindowSurface(window);

doc/api.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ With this module it is possible to declare inline C code in nodejs
77
and run it on the fly. This is possible due to the fascinating
88
Tiny C Compiler originally made by Fabrice Bellard.
99

10-
**Requires**: <code>module:node-gyp</code>, <code>module:ffi</code>, <code>module:ref</code>
10+
**Requires**: <code>module:node-gyp</code>, <code>module:@napi-ffi/ffi-napi</code>, <code>module:@napi-ffi/ref-napi</code>
1111
**Note**: The module is still alpha, interfaces are still likely to change a lot.
1212
**Example**
1313
```js
@@ -111,7 +111,7 @@ let state1 = Tcc();
111111
...
112112
state1.compile('...') && state1.relocate(); // finished with state1
113113

114-
let state2 = Tcc(); // state1 got corrupted but we are with it anyways
114+
let state2 = Tcc(); // state1 got corrupted but we are done with it anyways
115115
...
116116
state2.compile('...') && state2.relocate(); // finished with state2
117117

@@ -499,7 +499,7 @@ It adds the following types:
499499
| ulonglong | unsigned long long |
500500

501501
Furthermore it includes `<stddef.h>`, `<stdint.h>` and `<stdbool.h>`.
502-
If the module `ref-wchar` is installed, `WCString` is typedef'd as
502+
If the module `ref-wchar-napi` is installed, `WCString` is typedef'd as
503503
`wchar_t` pointer.
504504

505505
**Kind**: instance method of [<code>CodeGenerator</code>](#module_node-tinycc.CodeGenerator)
@@ -563,7 +563,7 @@ corresponding type.
563563
Helper function for easy wide string creation.
564564

565565
**Kind**: static method of [<code>node-tinycc</code>](#module_node-tinycc)
566-
**Note**: The function is only exported, if the module `ref-wchar` is installed.
566+
**Note**: The function is only exported, if the module `ref-wchar-napi` is installed.
567567

568568
| Param | Type |
569569
| --- | --- |
@@ -577,7 +577,7 @@ This is useful when writing C source code strings directly in Javascript.
577577
The function escapes the UTF-8 input to the appropriate wchar_t type.
578578

579579
**Kind**: static method of [<code>node-tinycc</code>](#module_node-tinycc)
580-
**Note**: The function is only exported, if the module `ref-wchar` is installed.
580+
**Note**: The function is only exported, if the module `ref-wchar-napi` is installed.
581581

582582
| Param | Type |
583583
| --- | --- |
@@ -615,7 +615,7 @@ until we got the real C symbol pointer.
615615

616616
<a name="module_node-tinycc.c_callable"></a>
617617

618-
### tcc.c_callable(restype, name, args, f) ⇒ <code>Declaration</code>
618+
### tcc.c\_callable(restype, name, args, f) ⇒ <code>Declaration</code>
619619
Convenvient declaration function to import a function symbol from JS to C code.
620620

621621
The function creates a function pointer declaration in C. After
@@ -641,7 +641,7 @@ gen.addDeclaration(decl);
641641

642642
<a name="module_node-tinycc.c_function"></a>
643643

644-
### tcc.c_function(restype, name, args, code) ⇒ <code>func</code>
644+
### tcc.c\_function(restype, name, args, code) ⇒ <code>func</code>
645645
Convenient declaration function to create a C function that is usable from Javascript.
646646

647647
The Javascript code:
@@ -682,10 +682,10 @@ console.log(add(23, 42)); // use it
682682

683683
<a name="module_node-tinycc.c_struct"></a>
684684

685-
### tcc.c_struct(name, structType) ⇒ <code>StructType</code>
685+
### tcc.c\_struct(name, structType) ⇒ <code>StructType</code>
686686
Convenient declaration function to declare a struct type usable in C and Javascript.
687687

688-
This function extracts the field names and types of a StructType (module `ref-struct`)
688+
This function extracts the field names and types of a StructType (module `ref-struct-napi`)
689689
to create a struct declaration (forward section) and definition for C (code section).
690690
A field type is resolved recursively to catch complicated type mixtures that
691691
can easily be build with StructTypes, ArrayTypes and pointer types
@@ -695,7 +695,7 @@ struct type by `struct name` in C. The struct type can be used at any point wher
695695
a `ref.types` type is needed, e.g. as function parameter or return type.
696696
Usage example:
697697
```js
698-
const StructType = require('ref-struct');
698+
const StructType = require('ref-struct-napi');
699699
let gen = tcc.CodeGenerator();
700700
let S = tcc.c_struct('S', StructType({a: 'int', b: 'char*'}));
701701
addDeclaration(S);

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363

6464
'use strict';
6565

66-
const ffi = require('ffi');
67-
const ref = require('ref');
66+
const ffi = require('@napi-ffi/ffi-napi');
67+
const ref = require('@napi-ffi/ref-napi');
6868
const path = require('path');
6969

7070
// optional wchar_t support
7171
let wchar_t = null;
7272
try {
73-
wchar_t = require('ref-wchar');
73+
wchar_t = require('ref-wchar-napi');
7474
const Iconv = require('iconv').Iconv;
7575
let encoding = ((process.platform === 'win32') ? 'UTF-16' : 'UTF-32') + ref.endianness;
7676
const wchar_set = new Iconv('UTF-8', encoding).convert;
@@ -113,7 +113,7 @@ try {
113113
* ```
114114
* @param {string} s
115115
* @return {string}
116-
* @note The function is only exported, if the module `ref-wchar` is installed.
116+
* @note The function is only exported, if the module `ref-wchar-napi` is installed.
117117
*/
118118
module.exports.escapeWchar = function(s) {
119119
/* istanbul ignore next */
@@ -392,6 +392,7 @@ function DefaultTcc() {
392392
} else {
393393
state = new Tcc();
394394
state.setLibPath(path.join(__dirname, 'posix', 'lib', 'tcc'));
395+
state.addLibraryPath(path.join(__dirname, 'posix', 'lib', 'tcc'));
395396
state.addIncludePath(path.join(__dirname, 'posix', 'lib', 'tcc', 'include'));
396397
state.addIncludePath(path.join(__dirname, 'posix', 'include'));
397398
}
@@ -564,7 +565,7 @@ function CodeGenerator() {
564565
* | ulonglong | unsigned long long |
565566
*
566567
* Furthermore it includes `<stddef.h>`, `<stdint.h>` and `<stdbool.h>`.
567-
* If the module `ref-wchar` is installed, `WCString` is typedef'd as
568+
* If the module `ref-wchar-napi` is installed, `WCString` is typedef'd as
568569
* `wchar_t` pointer.
569570
* @method module:node-tinycc.CodeGenerator#loadBasicTypes
570571
*/
@@ -862,7 +863,7 @@ function c_function(restype, name, args, code) {
862863
/**
863864
* Convenient declaration function to declare a struct type usable in C and Javascript.
864865
*
865-
* This function extracts the field names and types of a StructType (module `ref-struct`)
866+
* This function extracts the field names and types of a StructType (module `ref-struct-napi`)
866867
* to create a struct declaration (forward section) and definition for C (code section).
867868
* A field type is resolved recursively to catch complicated type mixtures that
868869
* can easily be build with StructTypes, ArrayTypes and pointer types
@@ -872,7 +873,7 @@ function c_function(restype, name, args, code) {
872873
* a `ref.types` type is needed, e.g. as function parameter or return type.
873874
* Usage example:
874875
* ```js
875-
* const StructType = require('ref-struct');
876+
* const StructType = require('ref-struct-napi');
876877
* let gen = tcc.CodeGenerator();
877878
* let S = tcc.c_struct('S', StructType({a: 'int', b: 'char*'}));
878879
* addDeclaration(S);

install_tcc.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
rm -rf ./tinycc
33
rm -rf ./lib_build
44
#git clone git://repo.or.cz/tinycc.git
5-
git clone https://github.com/andreiw/tinycc.git
5+
#git clone https://github.com/andreiw/tinycc.git
6+
git clone git@github.com:TinyCC/tinycc.git
7+
# tested with commit 4fccaf61241a5eb72b0777b3a44bd7abbea48604
68
mkdir lib_build
79
cd lib_build
810
../tinycc/configure --prefix=../posix --extra-cflags="-fPIC"

0 commit comments

Comments
 (0)