ranger-compiler 3.4.0 → 3.5.0
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/CHANGELOG.md +6 -25
- package/README.md +3 -2
- package/dist/api.d.ts +393 -0
- package/dist/api.js +4140 -413
- package/dist/git-http.mjs +126 -0
- package/dist/lib/zip/Inflate.rgr +675 -0
- package/dist/lib/zip/ZipBuffer.rgr +358 -0
- package/dist/package.json +1 -1
- package/dist/rgrc.js +3540 -56
- package/package.json +10 -10
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
; SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
; ZipBuffer.rgr - Little-endian buffer utilities for ZIP format
|
|
4
|
+
; ZIP uses little-endian byte order (unlike JPEG which uses big-endian)
|
|
5
|
+
|
|
6
|
+
class ZipBuffer {
|
|
7
|
+
def data:buffer (buffer_alloc 0)
|
|
8
|
+
def pos:int 0
|
|
9
|
+
def length:int 0
|
|
10
|
+
|
|
11
|
+
Constructor () {
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
fn initWithBuffer:void (buf:buffer) {
|
|
15
|
+
data = buf
|
|
16
|
+
length = (buffer_length buf)
|
|
17
|
+
pos = 0
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
fn initWithSize:void (size:int) {
|
|
21
|
+
data = (buffer_alloc size)
|
|
22
|
+
length = size
|
|
23
|
+
pos = 0
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
; === Position Management ===
|
|
27
|
+
|
|
28
|
+
fn getPosition:int () {
|
|
29
|
+
return pos
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fn setPosition:void (newPos:int) {
|
|
33
|
+
pos = newPos
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
fn seek:void (offset:int) {
|
|
37
|
+
pos = offset
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fn skip:void (count:int) {
|
|
41
|
+
pos = pos + count
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fn remaining:int () {
|
|
45
|
+
return (length - pos)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
fn isEOF:boolean () {
|
|
49
|
+
return (pos >= length)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
; === Little-Endian Read Operations ===
|
|
53
|
+
|
|
54
|
+
fn readUint8:int () {
|
|
55
|
+
if (pos >= length) {
|
|
56
|
+
return 0
|
|
57
|
+
}
|
|
58
|
+
def value:int (buffer_get data pos)
|
|
59
|
+
pos = pos + 1
|
|
60
|
+
return value
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn readUint16LE:int () {
|
|
64
|
+
; Read 16-bit unsigned integer, little-endian (low byte first)
|
|
65
|
+
def b0:int (this.readUint8())
|
|
66
|
+
def b1:int (this.readUint8())
|
|
67
|
+
return (b0 + (b1 * 256))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fn readUint32LE:int () {
|
|
71
|
+
; Read 32-bit unsigned integer, little-endian
|
|
72
|
+
def b0:int (this.readUint8())
|
|
73
|
+
def b1:int (this.readUint8())
|
|
74
|
+
def b2:int (this.readUint8())
|
|
75
|
+
def b3:int (this.readUint8())
|
|
76
|
+
return (b0 + (b1 * 256) + (b2 * 65536) + (b3 * 16777216))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
fn readBytes:buffer (count:int) {
|
|
80
|
+
; Read count bytes into a new buffer
|
|
81
|
+
def result:buffer (buffer_alloc count)
|
|
82
|
+
def i 0
|
|
83
|
+
while (i < count) {
|
|
84
|
+
if (pos < length) {
|
|
85
|
+
def b:int (buffer_get data pos)
|
|
86
|
+
buffer_set result i b
|
|
87
|
+
pos = pos + 1
|
|
88
|
+
}
|
|
89
|
+
i = i + 1
|
|
90
|
+
}
|
|
91
|
+
return result
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
fn readString:string (count:int) {
|
|
95
|
+
; Read count bytes as ASCII string
|
|
96
|
+
def result:string ""
|
|
97
|
+
def i 0
|
|
98
|
+
while (i < count) {
|
|
99
|
+
if (pos < length) {
|
|
100
|
+
def ch:int (buffer_get data pos)
|
|
101
|
+
result = (result + (strfromcode ch))
|
|
102
|
+
pos = pos + 1
|
|
103
|
+
}
|
|
104
|
+
i = i + 1
|
|
105
|
+
}
|
|
106
|
+
return result
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fn peekUint8:int () {
|
|
110
|
+
if (pos >= length) {
|
|
111
|
+
return 0
|
|
112
|
+
}
|
|
113
|
+
return (buffer_get data pos)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fn peekUint32LE:int () {
|
|
117
|
+
def savedPos:int pos
|
|
118
|
+
def value:int (this.readUint32LE())
|
|
119
|
+
pos = savedPos
|
|
120
|
+
return value
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
; === Little-Endian Write Operations ===
|
|
124
|
+
|
|
125
|
+
fn writeUint8:void (value:int) {
|
|
126
|
+
if (pos < length) {
|
|
127
|
+
buffer_set data pos value
|
|
128
|
+
pos = pos + 1
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn writeUint16LE:void (value:int) {
|
|
133
|
+
; Write 16-bit unsigned integer, little-endian (low byte first).
|
|
134
|
+
; Use bit ops — signed `%` / `/` on C++ break for values with the high bit set.
|
|
135
|
+
def b0:int (bit_and value 255)
|
|
136
|
+
def b1:int (bit_and (bit_ushr value 8) 255)
|
|
137
|
+
this.writeUint8(b0)
|
|
138
|
+
this.writeUint8(b1)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
fn writeUint32LE:void (value:int) {
|
|
142
|
+
; Write 32-bit unsigned integer, little-endian.
|
|
143
|
+
def b0:int (bit_and value 255)
|
|
144
|
+
def b1:int (bit_and (bit_ushr value 8) 255)
|
|
145
|
+
def b2:int (bit_and (bit_ushr value 16) 255)
|
|
146
|
+
def b3:int (bit_and (bit_ushr value 24) 255)
|
|
147
|
+
this.writeUint8(b0)
|
|
148
|
+
this.writeUint8(b1)
|
|
149
|
+
this.writeUint8(b2)
|
|
150
|
+
this.writeUint8(b3)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fn writeBytes:void (src:buffer srcOffset:int count:int) {
|
|
154
|
+
def i 0
|
|
155
|
+
while (i < count) {
|
|
156
|
+
def b:int (buffer_get src (srcOffset + i))
|
|
157
|
+
this.writeUint8(b)
|
|
158
|
+
i = i + 1
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
fn writeBuffer:void (src:buffer) {
|
|
163
|
+
def len:int (buffer_length src)
|
|
164
|
+
this.writeBytes(src 0 len)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
fn writeString:void (s:string) {
|
|
168
|
+
def len:int (strlen s)
|
|
169
|
+
def i 0
|
|
170
|
+
while (i < len) {
|
|
171
|
+
def ch:int (charAt s i)
|
|
172
|
+
this.writeUint8(ch)
|
|
173
|
+
i = i + 1
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
; === Buffer Access ===
|
|
178
|
+
|
|
179
|
+
fn getBuffer:buffer () {
|
|
180
|
+
return data
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
fn getLength:int () {
|
|
184
|
+
return length
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
; === Search Operations ===
|
|
188
|
+
|
|
189
|
+
fn findSignatureBackward:int (sig:int startPos:int) {
|
|
190
|
+
; Search backward from startPos for a 4-byte signature (little-endian)
|
|
191
|
+
; Returns position of signature or -1 if not found
|
|
192
|
+
def searchPos:int startPos
|
|
193
|
+
while (searchPos >= 0) {
|
|
194
|
+
def savedPos:int pos
|
|
195
|
+
pos = searchPos
|
|
196
|
+
def value:int (this.readUint32LE())
|
|
197
|
+
pos = savedPos
|
|
198
|
+
if (value == sig) {
|
|
199
|
+
return searchPos
|
|
200
|
+
}
|
|
201
|
+
searchPos = searchPos - 1
|
|
202
|
+
}
|
|
203
|
+
return -1
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
; GrowableZipBuffer - Dynamic buffer that grows as needed
|
|
208
|
+
; A ZIP is written front to back and its size is not known until it is
|
|
209
|
+
; finished, so the bytes land in a chain of fixed chunks and are consolidated
|
|
210
|
+
; once at the end. Two things matter for a big sheet — a 500,000-row export is
|
|
211
|
+
; well over a hundred megabytes — and neither is about the chunking itself:
|
|
212
|
+
;
|
|
213
|
+
; * Bytes move in BLOCKS. `buffer_copy` is memmove on the native target and
|
|
214
|
+
; a tight loop on the others; copying a hundred megabytes one
|
|
215
|
+
; `writeUint8` call at a time is the same work with a function call
|
|
216
|
+
; around every byte of it.
|
|
217
|
+
; * A chunk remembers how full it is. The old code assumed every chunk in
|
|
218
|
+
; the list was exactly `chunkSize` long, which is true only while nobody
|
|
219
|
+
; changes the chunk size — and silently writes garbage the moment
|
|
220
|
+
; somebody does.
|
|
221
|
+
class GrowableZipBuffer {
|
|
222
|
+
def chunks:[buffer]
|
|
223
|
+
def chunkLens:[int]
|
|
224
|
+
def chunkSize:int 65536
|
|
225
|
+
def currentChunk:buffer (buffer_alloc 0)
|
|
226
|
+
def currentPos:int 0
|
|
227
|
+
def totalSize:int 0
|
|
228
|
+
|
|
229
|
+
Constructor () {
|
|
230
|
+
currentPos = 0
|
|
231
|
+
totalSize = 0
|
|
232
|
+
def initSize:int chunkSize
|
|
233
|
+
currentChunk = (buffer_alloc initSize)
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
; Only meaningful before the first byte: the chunk being filled was
|
|
237
|
+
; allocated at the old size and cannot be re-cut underneath itself.
|
|
238
|
+
fn setChunkSize:void (size:int) {
|
|
239
|
+
if (size < 1) {
|
|
240
|
+
return
|
|
241
|
+
}
|
|
242
|
+
if (totalSize > 0) {
|
|
243
|
+
return
|
|
244
|
+
}
|
|
245
|
+
chunkSize = size
|
|
246
|
+
currentChunk = (buffer_alloc size)
|
|
247
|
+
currentPos = 0
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
fn allocateNewChunk:void () {
|
|
251
|
+
push chunks currentChunk
|
|
252
|
+
push chunkLens currentPos
|
|
253
|
+
def size:int chunkSize
|
|
254
|
+
currentChunk = (buffer_alloc size)
|
|
255
|
+
currentPos = 0
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
fn writeUint8:void (value:int) {
|
|
259
|
+
if (currentPos >= chunkSize) {
|
|
260
|
+
this.allocateNewChunk()
|
|
261
|
+
}
|
|
262
|
+
buffer_set currentChunk currentPos value
|
|
263
|
+
currentPos = (currentPos + 1)
|
|
264
|
+
totalSize = (totalSize + 1)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
fn writeUint16LE:void (value:int) {
|
|
268
|
+
def b0:int (value % 256)
|
|
269
|
+
def b1D:double ((to_double value) / 256.0)
|
|
270
|
+
def b1:int ((to_int b1D) % 256)
|
|
271
|
+
this.writeUint8(b0)
|
|
272
|
+
this.writeUint8(b1)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
fn writeUint32LE:void (value:int) {
|
|
276
|
+
def b0:int (value % 256)
|
|
277
|
+
def rem1D:double ((to_double value) / 256.0)
|
|
278
|
+
def rem1:int (to_int rem1D)
|
|
279
|
+
def b1:int (rem1 % 256)
|
|
280
|
+
def rem2D:double ((to_double rem1) / 256.0)
|
|
281
|
+
def rem2:int (to_int rem2D)
|
|
282
|
+
def b2:int (rem2 % 256)
|
|
283
|
+
def rem3D:double ((to_double rem2) / 256.0)
|
|
284
|
+
def b3:int (to_int rem3D)
|
|
285
|
+
this.writeUint8(b0)
|
|
286
|
+
this.writeUint8(b1)
|
|
287
|
+
this.writeUint8(b2)
|
|
288
|
+
this.writeUint8(b3)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
fn writeBytes:void (src:buffer srcOffset:int count:int) {
|
|
292
|
+
def left:int count
|
|
293
|
+
def at:int srcOffset
|
|
294
|
+
while (left > 0) {
|
|
295
|
+
if (currentPos >= chunkSize) {
|
|
296
|
+
this.allocateNewChunk()
|
|
297
|
+
}
|
|
298
|
+
def room:int (chunkSize - currentPos)
|
|
299
|
+
def take:int left
|
|
300
|
+
if (take > room) {
|
|
301
|
+
take = room
|
|
302
|
+
}
|
|
303
|
+
buffer_copy currentChunk currentPos src at take
|
|
304
|
+
currentPos = (currentPos + take)
|
|
305
|
+
totalSize = (totalSize + take)
|
|
306
|
+
at = (at + take)
|
|
307
|
+
left = (left - take)
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
fn writeBuffer:void (src:buffer) {
|
|
312
|
+
def len:int (buffer_length src)
|
|
313
|
+
this.writeBytes(src 0 len)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
fn writeString:void (s:string) {
|
|
317
|
+
def len:int (strlen s)
|
|
318
|
+
def i 0
|
|
319
|
+
while (i < len) {
|
|
320
|
+
def ch:int (charAt s i)
|
|
321
|
+
this.writeUint8(ch)
|
|
322
|
+
i = i + 1
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
fn getSize:int () {
|
|
327
|
+
return totalSize
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
fn toBuffer:buffer () {
|
|
331
|
+
; Consolidate all chunks into a single buffer
|
|
332
|
+
def size:int totalSize
|
|
333
|
+
def result:buffer (buffer_alloc size)
|
|
334
|
+
def destPos:int 0
|
|
335
|
+
|
|
336
|
+
def numChunks:int (array_length chunks)
|
|
337
|
+
def i 0
|
|
338
|
+
while (i < numChunks) {
|
|
339
|
+
def chunk:buffer (itemAt chunks i)
|
|
340
|
+
def used:int (itemAt chunkLens i)
|
|
341
|
+
if (used > 0) {
|
|
342
|
+
buffer_copy result destPos chunk 0 used
|
|
343
|
+
destPos = (destPos + used)
|
|
344
|
+
}
|
|
345
|
+
i = i + 1
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
; Copy current chunk (partial)
|
|
349
|
+
def curPos:int currentPos
|
|
350
|
+
if (curPos > 0) {
|
|
351
|
+
def curChunk:buffer currentChunk
|
|
352
|
+
buffer_copy result destPos curChunk 0 curPos
|
|
353
|
+
destPos = (destPos + curPos)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return result
|
|
357
|
+
}
|
|
358
|
+
}
|
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ranger-compiler",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Ranger cross-language compiler - compile once, run anywhere. Write code in Ranger and compile to JavaScript, TypeScript, Python, Go, Rust, Swift, C++, Java, Kotlin, C#, PHP, and Scala.",
|
|
5
5
|
"main": "api.js",
|
|
6
6
|
"types": "api.d.ts",
|