@retrovm/nobj 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -8
- package/nobj.ts +10 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,14 +48,8 @@ await Bun.write('assets.o', buf)
|
|
|
48
48
|
Link normally:
|
|
49
49
|
|
|
50
50
|
```bash
|
|
51
|
-
#
|
|
51
|
+
# Any Os
|
|
52
52
|
clang main.c assets.o -o app
|
|
53
|
-
|
|
54
|
-
# Linux
|
|
55
|
-
clang main.c assets.o -o app
|
|
56
|
-
|
|
57
|
-
# Windows
|
|
58
|
-
clang-cl main.c assets.obj -o app.exe
|
|
59
53
|
```
|
|
60
54
|
|
|
61
55
|
Reference from C with no runtime overhead:
|
|
@@ -93,7 +87,7 @@ const buf = encodeSymbols([
|
|
|
93
87
|
|
|
94
88
|
| TypeScript type | C declaration | Notes |
|
|
95
89
|
|-----------------|--------------------------|----------------------------------------|
|
|
96
|
-
| `
|
|
90
|
+
| `Uint8Array` | `const uint8_t[]` | Raw bytes, no transformation |
|
|
97
91
|
| `string` | `const char[]` | ASCII, null-terminated (except macOS) |
|
|
98
92
|
| `number` | `const double` | IEEE 754, 8 bytes |
|
|
99
93
|
|
package/nobj.ts
CHANGED
|
@@ -18,7 +18,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
19
|
SOFTWARE.*/
|
|
20
20
|
|
|
21
|
-
export type SymbolValue =
|
|
21
|
+
export type SymbolValue = Uint8Array | string | number;
|
|
22
22
|
|
|
23
23
|
export interface ObjSymbol {
|
|
24
24
|
name: string;
|
|
@@ -97,7 +97,7 @@ function doObjectWindows(symbols: ObjSymbol[], arch: TargetArch): Buffer {
|
|
|
97
97
|
for (const { name, obj } of symbols) {
|
|
98
98
|
strTabSz += name.length + 1;
|
|
99
99
|
directives.push(` /EXPORT:${name},DATA`);
|
|
100
|
-
if (
|
|
100
|
+
if (obj instanceof Uint8Array) dataSz += al(obj.length, 8);
|
|
101
101
|
else if (typeof obj === 'string') dataSz += al(obj.length + 1, 8);
|
|
102
102
|
else if (typeof obj === 'number') dataSz += 8;
|
|
103
103
|
else throw new Error('Invalid symbol type');
|
|
@@ -128,8 +128,8 @@ function doObjectWindows(symbols: ObjSymbol[], arch: TargetArch): Buffer {
|
|
|
128
128
|
tsd.write(name, strOff, 'ascii');
|
|
129
129
|
strOff += name.length + 1;
|
|
130
130
|
|
|
131
|
-
if (
|
|
132
|
-
|
|
131
|
+
if (obj instanceof Uint8Array) {
|
|
132
|
+
dsd.set(obj, dataOff);
|
|
133
133
|
dataOff += al(obj.length, 8);
|
|
134
134
|
} else if (typeof obj === 'string') {
|
|
135
135
|
dsd.write(obj, dataOff, 'ascii');
|
|
@@ -234,7 +234,7 @@ function doObjectMacOS(symbols: ObjSymbol[], arch: TargetArch): Buffer {
|
|
|
234
234
|
let dataSz = 0, strTabSz = 1, symTabSz = 0;
|
|
235
235
|
|
|
236
236
|
for (const { name, obj } of symbols) {
|
|
237
|
-
if (
|
|
237
|
+
if (obj instanceof Uint8Array) dataSz += al(obj.length, 16);
|
|
238
238
|
else if (typeof obj === 'string') dataSz += al(obj.length, 16); // raw bytes, no null
|
|
239
239
|
else if (typeof obj === 'number') dataSz += al(8, 16); // = 16
|
|
240
240
|
else throw new Error('Invalid symbol type');
|
|
@@ -253,8 +253,8 @@ function doObjectMacOS(symbols: ObjSymbol[], arch: TargetArch): Buffer {
|
|
|
253
253
|
const { name, obj } = symbols[k]!;
|
|
254
254
|
const valueInSection = dataOff;
|
|
255
255
|
|
|
256
|
-
if (
|
|
257
|
-
|
|
256
|
+
if (obj instanceof Uint8Array) {
|
|
257
|
+
dt.set(obj, dataOff);
|
|
258
258
|
dataOff += al(obj.length, 16);
|
|
259
259
|
} else if (typeof obj === 'string') {
|
|
260
260
|
dt.write(obj, dataOff, 'ascii');
|
|
@@ -386,7 +386,7 @@ function doObjectLinux(symbols: ObjSymbol[], arch: TargetArch): Buffer {
|
|
|
386
386
|
|
|
387
387
|
for (const { name, obj } of symbols) {
|
|
388
388
|
strTabSz += name.length + 1;
|
|
389
|
-
if (
|
|
389
|
+
if (obj instanceof Uint8Array) dataSz += al(obj.length, 8);
|
|
390
390
|
else if (typeof obj === 'string') dataSz += al(obj.length + 1, 8);
|
|
391
391
|
else if (typeof obj === 'number') dataSz += 8;
|
|
392
392
|
else throw new Error('Invalid symbol type');
|
|
@@ -414,8 +414,8 @@ function doObjectLinux(symbols: ObjSymbol[], arch: TargetArch): Buffer {
|
|
|
414
414
|
ts.write(name, strOff, 'ascii');
|
|
415
415
|
strOff += name.length + 1;
|
|
416
416
|
|
|
417
|
-
if (
|
|
418
|
-
|
|
417
|
+
if (obj instanceof Uint8Array) {
|
|
418
|
+
d.set(obj, dataOff);
|
|
419
419
|
writeU64(symd, sb + EY.SIZE, obj.length);
|
|
420
420
|
dataOff += al(obj.length, 8);
|
|
421
421
|
} else if (typeof obj === 'string') {
|
package/package.json
CHANGED