@agoric/xsnap 0.14.3-dev-b047af2.0 → 0.14.3-dev-3eb4230.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.
Files changed (126) hide show
  1. package/api.js +1 -1
  2. package/package.json +16 -23
  3. package/src/build.js +4 -61
  4. package/moddable/modules/data/base64/base64.js +0 -28
  5. package/moddable/modules/data/base64/manifest.json +0 -11
  6. package/moddable/modules/data/base64/modBase64.c +0 -188
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +0 -106
  8. package/moddable/modules/data/crc/crc.c +0 -205
  9. package/moddable/modules/data/crc/crc.js +0 -36
  10. package/moddable/modules/data/crc/manifest.json +0 -8
  11. package/moddable/modules/data/hex/hex.js +0 -28
  12. package/moddable/modules/data/hex/manifest.json +0 -11
  13. package/moddable/modules/data/hex/modHex.c +0 -139
  14. package/moddable/modules/data/logical/logical.js +0 -32
  15. package/moddable/modules/data/logical/modLogical.c +0 -98
  16. package/moddable/modules/data/qrcode/manifest.json +0 -9
  17. package/moddable/modules/data/qrcode/qrcode.c +0 -93
  18. package/moddable/modules/data/qrcode/qrcode.js +0 -23
  19. package/moddable/modules/data/qrcode/qrcodegen.c +0 -1025
  20. package/moddable/modules/data/qrcode/qrcodegen.h +0 -267
  21. package/moddable/modules/data/text/decoder/manifest.json +0 -8
  22. package/moddable/modules/data/text/decoder/textdecoder.c +0 -480
  23. package/moddable/modules/data/text/decoder/textdecoder.js +0 -27
  24. package/moddable/modules/data/text/encoder/manifest.json +0 -8
  25. package/moddable/modules/data/text/encoder/textencoder.c +0 -232
  26. package/moddable/modules/data/text/encoder/textencoder.js +0 -24
  27. package/moddable/modules/data/tinyint/tinyint.c +0 -150
  28. package/moddable/modules/data/tinyint/tinyint.js +0 -53
  29. package/moddable/modules/data/url/manifest.json +0 -17
  30. package/moddable/modules/data/url/url.c +0 -1959
  31. package/moddable/modules/data/url/url.js +0 -210
  32. package/moddable/modules/data/wavreader/manifest.json +0 -8
  33. package/moddable/modules/data/wavreader/wavreader.js +0 -128
  34. package/moddable/modules/data/zlib/deflate.c +0 -161
  35. package/moddable/modules/data/zlib/deflate.js +0 -63
  36. package/moddable/modules/data/zlib/inflate.c +0 -145
  37. package/moddable/modules/data/zlib/inflate.js +0 -66
  38. package/moddable/modules/data/zlib/manifest_deflate.json +0 -9
  39. package/moddable/modules/data/zlib/manifest_inflate.json +0 -9
  40. package/moddable/modules/data/zlib/miniz.c +0 -4924
  41. package/moddable/xs/includes/xs.d.ts +0 -73
  42. package/moddable/xs/includes/xs.h +0 -1533
  43. package/moddable/xs/includes/xsmc.h +0 -206
  44. package/moddable/xs/makefiles/lin/makefile +0 -33
  45. package/moddable/xs/makefiles/lin/xsc.mk +0 -118
  46. package/moddable/xs/makefiles/lin/xsid.mk +0 -90
  47. package/moddable/xs/makefiles/lin/xsl.mk +0 -168
  48. package/moddable/xs/makefiles/lin/xst.mk +0 -201
  49. package/moddable/xs/makefiles/mac/makefile +0 -33
  50. package/moddable/xs/makefiles/mac/xsc.mk +0 -130
  51. package/moddable/xs/makefiles/mac/xsid.mk +0 -102
  52. package/moddable/xs/makefiles/mac/xsl.mk +0 -177
  53. package/moddable/xs/makefiles/mac/xst.mk +0 -203
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +0 -52
  55. package/moddable/xs/makefiles/win/build.bat +0 -26
  56. package/moddable/xs/makefiles/win/xsc.mak +0 -142
  57. package/moddable/xs/makefiles/win/xsid.mak +0 -113
  58. package/moddable/xs/makefiles/win/xsl.mak +0 -186
  59. package/moddable/xs/makefiles/win/xst.mak +0 -195
  60. package/moddable/xs/platforms/lin_xs.h +0 -99
  61. package/moddable/xs/platforms/mac_xs.h +0 -97
  62. package/moddable/xs/platforms/wasm_xs.h +0 -79
  63. package/moddable/xs/platforms/win_xs.h +0 -104
  64. package/moddable/xs/platforms/xsHost.h +0 -63
  65. package/moddable/xs/platforms/xsPlatform.h +0 -618
  66. package/moddable/xs/sources/xsAPI.c +0 -2555
  67. package/moddable/xs/sources/xsAll.c +0 -294
  68. package/moddable/xs/sources/xsAll.h +0 -2741
  69. package/moddable/xs/sources/xsArguments.c +0 -222
  70. package/moddable/xs/sources/xsArray.c +0 -2657
  71. package/moddable/xs/sources/xsAtomics.c +0 -844
  72. package/moddable/xs/sources/xsBigInt.c +0 -1859
  73. package/moddable/xs/sources/xsBoolean.c +0 -109
  74. package/moddable/xs/sources/xsCode.c +0 -4493
  75. package/moddable/xs/sources/xsCommon.c +0 -1710
  76. package/moddable/xs/sources/xsCommon.h +0 -1142
  77. package/moddable/xs/sources/xsDataView.c +0 -2890
  78. package/moddable/xs/sources/xsDate.c +0 -1541
  79. package/moddable/xs/sources/xsDebug.c +0 -2710
  80. package/moddable/xs/sources/xsDefaults.c +0 -134
  81. package/moddable/xs/sources/xsError.c +0 -353
  82. package/moddable/xs/sources/xsFunction.c +0 -776
  83. package/moddable/xs/sources/xsGenerator.c +0 -865
  84. package/moddable/xs/sources/xsGlobal.c +0 -839
  85. package/moddable/xs/sources/xsJSON.c +0 -1091
  86. package/moddable/xs/sources/xsLexical.c +0 -1969
  87. package/moddable/xs/sources/xsLockdown.c +0 -933
  88. package/moddable/xs/sources/xsMapSet.c +0 -1649
  89. package/moddable/xs/sources/xsMarshall.c +0 -1020
  90. package/moddable/xs/sources/xsMath.c +0 -624
  91. package/moddable/xs/sources/xsMemory.c +0 -1941
  92. package/moddable/xs/sources/xsModule.c +0 -3101
  93. package/moddable/xs/sources/xsNumber.c +0 -560
  94. package/moddable/xs/sources/xsObject.c +0 -1102
  95. package/moddable/xs/sources/xsPlatforms.c +0 -480
  96. package/moddable/xs/sources/xsProfile.c +0 -577
  97. package/moddable/xs/sources/xsPromise.c +0 -1199
  98. package/moddable/xs/sources/xsProperty.c +0 -636
  99. package/moddable/xs/sources/xsProxy.c +0 -1014
  100. package/moddable/xs/sources/xsRegExp.c +0 -1168
  101. package/moddable/xs/sources/xsRun.c +0 -4889
  102. package/moddable/xs/sources/xsScope.c +0 -1293
  103. package/moddable/xs/sources/xsScript.c +0 -288
  104. package/moddable/xs/sources/xsScript.h +0 -1186
  105. package/moddable/xs/sources/xsSnapshot.c +0 -2161
  106. package/moddable/xs/sources/xsSnapshot.h +0 -51
  107. package/moddable/xs/sources/xsSourceMap.c +0 -218
  108. package/moddable/xs/sources/xsString.c +0 -3332
  109. package/moddable/xs/sources/xsSymbol.c +0 -503
  110. package/moddable/xs/sources/xsSyntaxical.c +0 -4193
  111. package/moddable/xs/sources/xsTree.c +0 -1893
  112. package/moddable/xs/sources/xsType.c +0 -1488
  113. package/moddable/xs/sources/xsdtoa.c +0 -6672
  114. package/moddable/xs/sources/xsmc.c +0 -340
  115. package/moddable/xs/sources/xsre.c +0 -7578
  116. package/xsnap-native/xsnap/makefiles/lin/makefile +0 -10
  117. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +0 -153
  118. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +0 -144
  119. package/xsnap-native/xsnap/makefiles/mac/makefile +0 -10
  120. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +0 -162
  121. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +0 -153
  122. package/xsnap-native/xsnap/sources/xsnap-worker.c +0 -996
  123. package/xsnap-native/xsnap/sources/xsnap.c +0 -716
  124. package/xsnap-native/xsnap/sources/xsnap.h +0 -142
  125. package/xsnap-native/xsnap/sources/xsnapPlatform.c +0 -1496
  126. package/xsnap-native/xsnap/sources/xsnapPlatform.h +0 -105
@@ -1,205 +0,0 @@
1
- /*
2
- * Copyright (c) 2021-2022 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- #include "xsmc.h"
22
- #include "xsHost.h"
23
-
24
- // https://graphics.stanford.edu/~seander/bithacks.html
25
- uint8_t reflect8(uint8_t b) {
26
- return ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
27
- }
28
-
29
- static void make_crc8_table(uint8_t polynomial, uint8_t *crc8_table)
30
- {
31
- int i, j, cur;
32
-
33
- for (i=0; i<256; i++) {
34
- for (cur=i, j=0; j<8; j++) {
35
- if (cur & 0x80)
36
- cur = ((cur << 1) ^ polynomial) % 256;
37
- else
38
- cur = (cur << 1) % 256;
39
- }
40
- crc8_table[i] = cur;
41
- }
42
- }
43
-
44
- static uint8_t checksum8(uint8_t *bytes, uint32_t length, uint8_t *crc8_table, uint8_t crc, uint8_t refIn) {
45
- uint32_t i;
46
-
47
- for (i=0; i<length; i++) {
48
- uint8_t b = bytes[i];
49
- if (refIn)
50
- b = reflect8(b);
51
- crc = crc8_table[(crc ^ b) % 256];
52
- }
53
- return crc;
54
- }
55
-
56
- typedef struct {
57
- uint8_t reset;
58
- uint8_t initial;
59
- uint8_t reflectInput;
60
- uint8_t reflectOutput;
61
- uint8_t xorOutput;
62
- uint8_t table[256];
63
- } CRC8Record, *CRC8;
64
-
65
- void xs_crc8_destructor(void *data)
66
- {
67
- }
68
-
69
- void xs_crc8(xsMachine *the)
70
- {
71
- int argc = xsmcArgc;
72
- int polynomial = xsmcToInteger(xsArg(0));
73
- int initial = (argc > 1) ? xsmcToInteger(xsArg(1)) : 0;
74
- int reflectInput = (argc > 2) ? xsmcToInteger(xsArg(2)) : 0;
75
- int reflectOutput = (argc > 3) ? xsmcToInteger(xsArg(3)) : 0;
76
- int xorOutput = (argc > 4) ? xsmcToInteger(xsArg(4)) : 0;
77
- CRC8 crc8 = xsmcSetHostChunk(xsThis, NULL, sizeof(CRC8Record));
78
-
79
- crc8->reset = initial;
80
- crc8->initial = initial;
81
- crc8->reflectInput = reflectInput;
82
- crc8->reflectOutput = reflectOutput;
83
- crc8->xorOutput = xorOutput;
84
-
85
- make_crc8_table(polynomial, crc8->table);
86
- }
87
-
88
- void xs_crc8_close(xsMachine *the)
89
- {
90
- xsmcSetHostData(xsThis, NULL);
91
- }
92
-
93
- void xs_crc8_reset(xsMachine *the)
94
- {
95
- CRC8 crc8 = xsmcGetHostChunk(xsThis);
96
-
97
- crc8->initial = crc8->reset;
98
- xsResult = xsThis;
99
- }
100
-
101
- void xs_crc8_checksum(xsMachine *the)
102
- {
103
- CRC8 crc8 = xsmcGetHostChunk(xsThis);
104
- uint8_t *data;
105
- uint32_t length;
106
-
107
- xsmcGetBufferReadable(xsArg(0), (void **)&data, &length);
108
- crc8->initial = checksum8(data, length, crc8->table, crc8->initial, crc8->reflectInput);
109
-
110
- uint8_t crc = crc8->initial;
111
- if (crc8->reflectOutput)
112
- crc = reflect8(crc);
113
-
114
- xsmcSetInteger(xsResult, crc ^ crc8->xorOutput);
115
- }
116
-
117
-
118
- static void make_crc16_table(uint16_t polynomial, uint16_t *crc16_table) {
119
- int i, j;
120
- uint16_t crc;
121
-
122
- for (i=0; i<256; i++) {
123
- for (crc=i<<8, j=0; j<8; j++) {
124
- if (crc & 0x8000) {
125
- crc <<= 1;
126
- crc ^= polynomial;
127
- }
128
- else
129
- crc <<= 1;
130
- }
131
- crc16_table[i] = crc;
132
- }
133
- }
134
-
135
- static uint16_t checksum16(uint8_t *bytes, uint32_t length, uint16_t *crc16_table, uint16_t crc, uint8_t refIn) {
136
- uint32_t i;
137
-
138
- for (i=0; i<length; i++) {
139
- uint8_t b = bytes[i];
140
- if (refIn)
141
- b = reflect8(b);
142
- crc = crc ^ (b << 8);
143
- crc = ((crc << 8) ^ crc16_table[crc >> 8]);
144
- }
145
- return crc;
146
- }
147
-
148
- typedef struct {
149
- uint16_t reset;
150
- uint16_t initial;
151
- uint16_t reflectInput;
152
- uint16_t reflectOutput;
153
- uint16_t xorOutput;
154
- uint16_t table[256];
155
- } CRC16Record, *CRC16;
156
-
157
- void xs_crc16_destructor(void *data)
158
- {
159
- }
160
-
161
- void xs_crc16(xsMachine *the)
162
- {
163
- int argc = xsmcArgc;
164
- int polynomial = xsmcToInteger(xsArg(0));
165
- int initial = (argc > 1) ? xsmcToInteger(xsArg(1)) : 0;
166
- int reflectInput = (argc > 2) ? xsmcToInteger(xsArg(2)) : 0;
167
- int reflectOutput = (argc > 3) ? xsmcToInteger(xsArg(3)) : 0;
168
- int xorOutput = (argc > 4) ? xsmcToInteger(xsArg(4)) : 0;
169
- CRC16 crc16 = xsmcSetHostChunk(xsThis, NULL, sizeof(CRC16Record));
170
-
171
- crc16->reset = initial;
172
- crc16->initial = initial;
173
- crc16->reflectInput = reflectInput;
174
- crc16->reflectOutput = reflectOutput;
175
- crc16->xorOutput = xorOutput;
176
-
177
- make_crc16_table(polynomial, crc16->table);
178
- }
179
-
180
- void xs_crc16_close(xsMachine *the)
181
- {
182
- xsmcSetHostData(xsThis, NULL);
183
- }
184
-
185
- void xs_crc16_reset(xsMachine *the)
186
- {
187
- CRC16 crc16 = xsmcGetHostChunk(xsThis);
188
-
189
- crc16->initial = crc16->reset;
190
- }
191
-
192
- void xs_crc16_checksum(xsMachine *the)
193
- {
194
- CRC16 crc16 = xsmcGetHostChunk(xsThis);
195
- uint8_t *data;
196
- uint32_t length;
197
-
198
- xsmcGetBufferReadable(xsArg(0), (void **)&data, &length);
199
- crc16->initial = checksum16(data, length, crc16->table, crc16->initial, crc16->reflectInput);
200
-
201
- uint16_t crc = crc16->initial;
202
- if (crc16->reflectOutput)
203
- crc = (reflect8(crc & 0xff) << 8) | reflect8(crc >> 8);
204
- xsmcSetInteger(xsResult, crc ^ crc16->xorOutput);
205
- }
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright (c) 2021 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
-
22
- class CRC8 @ "xs_crc8_destructor" {
23
- constructor(polynomial, initial, reflectInput, reflectOutput, xorOutput) @ "xs_crc8";
24
- close() @ "xs_crc8_close";
25
- checksum(buffer) @ "xs_crc8_checksum";
26
- reset() @ "xs_crc8_reset";
27
- }
28
-
29
- class CRC16 @ "xs_crc16_destructor" {
30
- constructor(polynomial, initial, reflectInput, reflectOutput, xorOutput) @ "xs_crc16";
31
- close() @ "xs_crc16_close";
32
- checksum(buffer) @ "xs_crc16_checksum";
33
- reset() @ "xs_crc16_reset";
34
- }
35
-
36
- export { CRC8 as default, CRC8, CRC16 };
@@ -1,8 +0,0 @@
1
- {
2
- "modules": {
3
- "*": [
4
- "./crc"
5
- ]
6
- },
7
- "preload": "crc"
8
- }
@@ -1,28 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2017 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- /*
22
- hex
23
- */
24
-
25
- export default class {
26
- static toString(buffer) @ "xs_hex_toString";
27
- static toBuffer(string) @ "xs_hex_toBuffer";
28
- }
@@ -1,11 +0,0 @@
1
- {
2
- "modules": {
3
- "*": [
4
- "./hex",
5
- "./modHex"
6
- ]
7
- },
8
- "preload": [
9
- "hex"
10
- ]
11
- }
@@ -1,139 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2022 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- #include "xsPlatform.h"
22
- #include "xsmc.h"
23
-
24
- static const char *gHexUpper ICACHE_FLASH_ATTR = "0123456789ABCDEF";
25
-
26
- void xs_hex_toString(xsMachine *the)
27
- {
28
- int argc = xsmcArgc;
29
- const uint8_t *bytes;
30
- char *string;
31
- xsUnsignedValue length, i;
32
- char separator = 0;
33
- char *gHex = (char *)gHexUpper;
34
-
35
- xsmcGetBufferReadable(xsArg(0), (void **)&bytes, &length);
36
- if (0 == length)
37
- xsUnknownError("0 length buffer");
38
-
39
- if (argc > 1) {
40
- char *str = xsmcToString(xsArg(1));
41
- int len = c_strlen(str);
42
- if (len) {
43
- if (len > 1)
44
- xsUnknownError("invalid separator");
45
- separator = c_read8(str);
46
- if (!separator || (0x80 & separator))
47
- xsUnknownError("invalid separator");
48
- }
49
- if (argc > 2) {
50
- gHex = xsmcToString(xsArg(2));
51
- if (16 != c_strlen(gHex))
52
- xsUnknownError("bad string");
53
- for (i = 0; i < 16; i++) { // 7-bit ASCII, not UTF-8
54
- if (!gHex[i] || (0x80 & gHex[i]))
55
- xsUnknownError("bad string");
56
- }
57
- }
58
- }
59
-
60
- xsResult = xsStringBuffer(NULL, (length * 2) + (separator ? (length - 1) : 0));
61
- string = xsmcToString(xsResult);
62
- xsmcGetBufferReadable(xsArg(0), (void **)&bytes, &length);
63
- if (argc > 2)
64
- gHex = xsmcToString(xsArg(2));
65
-
66
- for (i = 0; i < length; i++) {
67
- uint8_t byte = c_read8(bytes++);
68
- if (separator && (0 != i))
69
- *string++ = separator;
70
- *string++ = c_read8(&gHex[byte >> 4]);
71
- *string++ = c_read8(&gHex[byte & 0x0F]);
72
- }
73
- }
74
-
75
- void xs_hex_toBuffer(xsMachine *the)
76
- {
77
- int argc = xsmcArgc;
78
- char separator = 0;
79
- const char *string;
80
- uint8_t *bytes;
81
- int length, i;
82
-
83
- if (argc > 1) {
84
- char *str = xsmcToString(xsArg(1));
85
- length = c_strlen(str);
86
- if (length) {
87
- if (length > 1)
88
- xsUnknownError("invalid separator");
89
- separator = c_read8(str);
90
- if (!separator || (0x80 & separator))
91
- xsUnknownError("invalid separator");
92
- }
93
- }
94
-
95
- string = xsmcToString(xsArg(0));
96
- length = c_strlen(string);
97
- if (length < 2)
98
- xsUnknownError("string too small");
99
-
100
- if ((separator && ((length + 1) % 3)) || (!separator && (length % 2)))
101
- xsUnknownError("bad string length");
102
-
103
- length = separator ? ((length + 1) / 3) : (length / 2);
104
- xsmcSetArrayBuffer(xsResult, NULL, length);
105
- bytes = xsmcToArrayBuffer(xsResult);
106
- string = xsmcToString(xsArg(0)); // refresh
107
- for (i = 0; i < length; i++) {
108
- uint8_t c;
109
- uint8_t byte;
110
-
111
- if (separator && (0 != i)) {
112
- if (c_read8(string++) != separator)
113
- xsUnknownError("expected separator");
114
- }
115
-
116
- c = c_read8(string++);
117
- if (('0' <= c) && (c <= '9'))
118
- byte = c - '0';
119
- else if (('A' <= c) && (c <= 'F'))
120
- byte = c - 'A' + 10;
121
- else if (('a' <= c) && (c <= 'f'))
122
- byte = c - 'a' + 10;
123
- else
124
- xsUnknownError("bad data");
125
- byte <<= 4;
126
-
127
- c = c_read8(string++);
128
- if (('0' <= c) && (c <= '9'))
129
- byte |= c - '0';
130
- else if (('A' <= c) && (c <= 'F'))
131
- byte |= c - 'A' + 10;
132
- else if (('a' <= c) && (c <= 'f'))
133
- byte |= c - 'a' + 10;
134
- else
135
- xsUnknownError("bad data");
136
-
137
- *bytes++ = byte;
138
- }
139
- }
@@ -1,32 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2017 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- /*
22
- logical operations on buffers
23
- */
24
-
25
- export default class {
26
- static not(dst) {
27
- this.xor(dst, 0xff);
28
- }
29
- static xor(dst, src) @ "xs_logical_xor";
30
- static and(dst, src) @ "xs_logical_and";
31
- static or(dst, src) @ "xs_logical_or";
32
- }
@@ -1,98 +0,0 @@
1
- /*
2
- * Copyright (c) 2016-2022 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- #include "xsPlatform.h"
22
- #include "xsmc.h"
23
-
24
- enum {
25
- kOpXor,
26
- kOpAnd,
27
- kOpOr
28
- };
29
-
30
- static void xs_logical_op(xsMachine *the, int operation)
31
- {
32
- int srcType = xsmcTypeOf(xsArg(1));
33
- uint8_t scratch;
34
- uint8_t *src, *dst;
35
- xsUnsignedValue srcLen, dstLen, i = 0;
36
-
37
- xsmcGetBufferWritable(xsArg(0), (void **)&dst, &dstLen);
38
-
39
- switch (srcType) {
40
- case xsIntegerType:
41
- case xsNumberType:
42
- scratch = (uint8_t)xsmcToInteger(xsArg(1));
43
- src = &scratch;
44
- srcLen = 1;
45
- break;
46
-
47
- case xsStringType:
48
- src = (uint8_t *)xsmcToString(xsArg(1));
49
- srcLen = c_strlen((char *)src);
50
- break;
51
-
52
- case xsReferenceType:
53
- xsmcGetBufferReadable(xsArg(1), (void **)&src, &srcLen);
54
- break;
55
-
56
- default:
57
- xsUnknownError("unsupported source");
58
- break;
59
- }
60
-
61
- if (kOpXor == operation) {
62
- while (dstLen--) {
63
- *dst++ ^= src[i++];
64
- if (i == srcLen)
65
- i = 0;
66
- }
67
- }
68
- else
69
- if (kOpOr == operation) {
70
- while (dstLen--) {
71
- *dst++ |= src[i++];
72
- if (i == srcLen)
73
- i = 0;
74
- }
75
- }
76
- else {
77
- while (dstLen--) {
78
- *dst++ &= src[i++];
79
- if (i == srcLen)
80
- i = 0;
81
- }
82
- }
83
- }
84
-
85
- void xs_logical_xor(xsMachine *the)
86
- {
87
- xs_logical_op(the, kOpXor);
88
- }
89
-
90
- void xs_logical_and(xsMachine *the)
91
- {
92
- xs_logical_op(the, kOpAnd);
93
- }
94
-
95
- void xs_logical_or(xsMachine *the)
96
- {
97
- xs_logical_op(the, kOpOr);
98
- }
@@ -1,9 +0,0 @@
1
- {
2
- "modules": {
3
- "*": [
4
- "./qrcode",
5
- "./qrcodegen"
6
- ]
7
- },
8
- "preload": "qrcode"
9
- }
@@ -1,93 +0,0 @@
1
- /*
2
- * Copyright (c) 2018-2022 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
- #include "xsmc.h"
21
- #include "mc.xs.h" // for xsID_ values
22
-
23
- #include "qrcodegen.h"
24
- #include "xsHost.h"
25
-
26
- void xs_qrcode(xsMachine *the)
27
- {
28
- size_t bufferSize;
29
- uint8_t *qr0 = NULL;
30
- void *data;
31
- xsType type;
32
- uint8_t ok;
33
- int x, y;
34
- uint8_t *module;
35
- int maxVersion = qrcodegen_VERSION_MAX;
36
-
37
- xsmcVars(3);
38
-
39
- if (xsmcHas(xsArg(0), xsID_maxVersion)) {
40
- xsmcGet(xsVar(0), xsArg(0), xsID_maxVersion);
41
- maxVersion = xsmcToInteger(xsVar(0));
42
- if ((maxVersion > qrcodegen_VERSION_MAX) || (maxVersion < qrcodegen_VERSION_MIN))
43
- xsRangeError("invalid");
44
- }
45
-
46
- bufferSize = qrcodegen_BUFFER_LEN_FOR_VERSION(maxVersion);
47
- qr0 = c_malloc(bufferSize << 1);
48
- if (!qr0)
49
- xsUnknownError("no memory");
50
-
51
- xsTry {
52
- xsmcGet(xsVar(0), xsArg(0), xsID_input);
53
- type = xsmcTypeOf(xsVar(0));
54
- if (xsStringType == type) {
55
- data = xsmcToString(xsVar(0));
56
- ok = qrcodegen_encodeText(data, qr0 + bufferSize, qr0,
57
- qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, maxVersion, qrcodegen_Mask_AUTO, true);
58
- }
59
- else {
60
- xsUnsignedValue dataSize;
61
-
62
- xsmcGetBufferReadable(xsVar(0), &data, &dataSize);
63
- if (dataSize > bufferSize)
64
- xsUnknownError("invalid");
65
- c_memcpy(qr0 + bufferSize, data, dataSize);
66
- ok = qrcodegen_encodeBinary(qr0 + bufferSize, dataSize, qr0,
67
- qrcodegen_Ecc_MEDIUM, qrcodegen_VERSION_MIN, maxVersion, qrcodegen_Mask_AUTO, true);
68
- }
69
-
70
- if (!ok)
71
- xsUnknownError("qrcode failed");
72
-
73
- int size = qrcodegen_getSize(qr0);
74
-
75
- xsmcSetArrayBuffer(xsResult, NULL, size * size);
76
-
77
- xsmcSetInteger(xsVar(0), size);
78
- xsmcSet(xsResult, xsID_size, xsVar(0));
79
-
80
- module = xsmcToArrayBuffer(xsResult);
81
- for (y = 0; y < size; y++) {
82
- for (x = 0; x < size; x++)
83
- *module++ = qrcodegen_getModule(qr0, x, y);
84
- }
85
-
86
- c_free(qr0);
87
- }
88
- xsCatch {
89
- c_free(qr0);
90
-
91
- xsThrow(xsException);
92
- }
93
- }
@@ -1,23 +0,0 @@
1
- /*
2
- * Copyright (c) 2018 Moddable Tech, Inc.
3
- *
4
- * This file is part of the Moddable SDK Runtime.
5
- *
6
- * The Moddable SDK Runtime is free software: you can redistribute it and/or modify
7
- * it under the terms of the GNU Lesser General Public License as published by
8
- * the Free Software Foundation, either version 3 of the License, or
9
- * (at your option) any later version.
10
- *
11
- * The Moddable SDK Runtime is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
- * GNU Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public License
17
- * along with the Moddable SDK Runtime. If not, see <http://www.gnu.org/licenses/>.
18
- *
19
- */
20
-
21
- function QRCode(dictonary) @ "xs_qrcode";
22
-
23
- export default QRCode;