@agoric/xsnap 0.14.3-u13.0 → 0.14.3-u16.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 (137) hide show
  1. package/README.md +3 -3
  2. package/api.js +4 -2
  3. package/build.env +1 -1
  4. package/moddable/modules/data/base64/base64.js +28 -0
  5. package/moddable/modules/data/base64/manifest.json +11 -0
  6. package/moddable/modules/data/base64/modBase64.c +188 -0
  7. package/moddable/modules/data/binaryMessage/BinaryMessage.js +106 -0
  8. package/moddable/modules/data/crc/crc.c +205 -0
  9. package/moddable/modules/data/crc/crc.js +36 -0
  10. package/moddable/modules/data/crc/manifest.json +8 -0
  11. package/moddable/modules/data/hex/hex.js +28 -0
  12. package/moddable/modules/data/hex/manifest.json +11 -0
  13. package/moddable/modules/data/hex/modHex.c +139 -0
  14. package/moddable/modules/data/logical/logical.js +32 -0
  15. package/moddable/modules/data/logical/modLogical.c +98 -0
  16. package/moddable/modules/data/qrcode/manifest.json +9 -0
  17. package/moddable/modules/data/qrcode/qrcode.c +93 -0
  18. package/moddable/modules/data/qrcode/qrcode.js +23 -0
  19. package/moddable/modules/data/qrcode/qrcodegen.c +1025 -0
  20. package/moddable/modules/data/qrcode/qrcodegen.h +267 -0
  21. package/moddable/modules/data/text/decoder/manifest.json +8 -0
  22. package/moddable/modules/data/text/decoder/textdecoder.c +480 -0
  23. package/moddable/modules/data/text/decoder/textdecoder.js +27 -0
  24. package/moddable/modules/data/text/encoder/manifest.json +8 -0
  25. package/moddable/modules/data/text/encoder/textencoder.c +232 -0
  26. package/moddable/modules/data/text/encoder/textencoder.js +24 -0
  27. package/moddable/modules/data/tinyint/tinyint.c +150 -0
  28. package/moddable/modules/data/tinyint/tinyint.js +53 -0
  29. package/moddable/modules/data/url/manifest.json +17 -0
  30. package/moddable/modules/data/url/url.c +1959 -0
  31. package/moddable/modules/data/url/url.js +210 -0
  32. package/moddable/modules/data/wavreader/manifest.json +8 -0
  33. package/moddable/modules/data/wavreader/wavreader.js +128 -0
  34. package/moddable/modules/data/zlib/deflate.c +161 -0
  35. package/moddable/modules/data/zlib/deflate.js +63 -0
  36. package/moddable/modules/data/zlib/inflate.c +145 -0
  37. package/moddable/modules/data/zlib/inflate.js +66 -0
  38. package/moddable/modules/data/zlib/manifest_deflate.json +9 -0
  39. package/moddable/modules/data/zlib/manifest_inflate.json +9 -0
  40. package/moddable/modules/data/zlib/miniz.c +4924 -0
  41. package/moddable/xs/includes/xs.d.ts +73 -0
  42. package/moddable/xs/includes/xs.h +1533 -0
  43. package/moddable/xs/includes/xsmc.h +206 -0
  44. package/moddable/xs/makefiles/lin/makefile +33 -0
  45. package/moddable/xs/makefiles/lin/xsc.mk +118 -0
  46. package/moddable/xs/makefiles/lin/xsid.mk +90 -0
  47. package/moddable/xs/makefiles/lin/xsl.mk +168 -0
  48. package/moddable/xs/makefiles/lin/xst.mk +201 -0
  49. package/moddable/xs/makefiles/mac/makefile +33 -0
  50. package/moddable/xs/makefiles/mac/xsc.mk +130 -0
  51. package/moddable/xs/makefiles/mac/xsid.mk +102 -0
  52. package/moddable/xs/makefiles/mac/xsl.mk +177 -0
  53. package/moddable/xs/makefiles/mac/xst.mk +203 -0
  54. package/moddable/xs/makefiles/mac/xst_no_asan.txt +52 -0
  55. package/moddable/xs/makefiles/win/build.bat +26 -0
  56. package/moddable/xs/makefiles/win/xsc.mak +142 -0
  57. package/moddable/xs/makefiles/win/xsid.mak +113 -0
  58. package/moddable/xs/makefiles/win/xsl.mak +186 -0
  59. package/moddable/xs/makefiles/win/xst.mak +195 -0
  60. package/moddable/xs/platforms/lin_xs.h +99 -0
  61. package/moddable/xs/platforms/mac_xs.h +97 -0
  62. package/moddable/xs/platforms/wasm_xs.h +79 -0
  63. package/moddable/xs/platforms/win_xs.h +104 -0
  64. package/moddable/xs/platforms/xsHost.h +63 -0
  65. package/moddable/xs/platforms/xsPlatform.h +618 -0
  66. package/moddable/xs/sources/xsAPI.c +2555 -0
  67. package/moddable/xs/sources/xsAll.c +294 -0
  68. package/moddable/xs/sources/xsAll.h +2741 -0
  69. package/moddable/xs/sources/xsArguments.c +222 -0
  70. package/moddable/xs/sources/xsArray.c +2657 -0
  71. package/moddable/xs/sources/xsAtomics.c +844 -0
  72. package/moddable/xs/sources/xsBigInt.c +1859 -0
  73. package/moddable/xs/sources/xsBoolean.c +109 -0
  74. package/moddable/xs/sources/xsCode.c +4493 -0
  75. package/moddable/xs/sources/xsCommon.c +1710 -0
  76. package/moddable/xs/sources/xsCommon.h +1142 -0
  77. package/moddable/xs/sources/xsDataView.c +2890 -0
  78. package/moddable/xs/sources/xsDate.c +1541 -0
  79. package/moddable/xs/sources/xsDebug.c +2710 -0
  80. package/moddable/xs/sources/xsDefaults.c +134 -0
  81. package/moddable/xs/sources/xsError.c +353 -0
  82. package/moddable/xs/sources/xsFunction.c +776 -0
  83. package/moddable/xs/sources/xsGenerator.c +865 -0
  84. package/moddable/xs/sources/xsGlobal.c +839 -0
  85. package/moddable/xs/sources/xsJSON.c +1091 -0
  86. package/moddable/xs/sources/xsLexical.c +1969 -0
  87. package/moddable/xs/sources/xsLockdown.c +933 -0
  88. package/moddable/xs/sources/xsMapSet.c +1649 -0
  89. package/moddable/xs/sources/xsMarshall.c +1020 -0
  90. package/moddable/xs/sources/xsMath.c +624 -0
  91. package/moddable/xs/sources/xsMemory.c +1941 -0
  92. package/moddable/xs/sources/xsModule.c +3101 -0
  93. package/moddable/xs/sources/xsNumber.c +560 -0
  94. package/moddable/xs/sources/xsObject.c +1102 -0
  95. package/moddable/xs/sources/xsPlatforms.c +480 -0
  96. package/moddable/xs/sources/xsProfile.c +577 -0
  97. package/moddable/xs/sources/xsPromise.c +1199 -0
  98. package/moddable/xs/sources/xsProperty.c +636 -0
  99. package/moddable/xs/sources/xsProxy.c +1014 -0
  100. package/moddable/xs/sources/xsRegExp.c +1168 -0
  101. package/moddable/xs/sources/xsRun.c +4889 -0
  102. package/moddable/xs/sources/xsScope.c +1293 -0
  103. package/moddable/xs/sources/xsScript.c +288 -0
  104. package/moddable/xs/sources/xsScript.h +1186 -0
  105. package/moddable/xs/sources/xsSnapshot.c +2161 -0
  106. package/moddable/xs/sources/xsSnapshot.h +51 -0
  107. package/moddable/xs/sources/xsSourceMap.c +218 -0
  108. package/moddable/xs/sources/xsString.c +3332 -0
  109. package/moddable/xs/sources/xsSymbol.c +503 -0
  110. package/moddable/xs/sources/xsSyntaxical.c +4193 -0
  111. package/moddable/xs/sources/xsTree.c +1893 -0
  112. package/moddable/xs/sources/xsType.c +1488 -0
  113. package/moddable/xs/sources/xsdtoa.c +6672 -0
  114. package/moddable/xs/sources/xsmc.c +340 -0
  115. package/moddable/xs/sources/xsre.c +7578 -0
  116. package/package.json +39 -22
  117. package/scripts/get_xsnap_version.sh +14 -0
  118. package/scripts/test-package.sh +21 -0
  119. package/src/avaAssertXS.js +6 -2
  120. package/src/avaHandler.cjs +2 -5
  121. package/src/avaXS.js +7 -8
  122. package/src/build.js +161 -28
  123. package/src/replay.js +0 -3
  124. package/src/xsnap.js +105 -91
  125. package/src/xsrepl.js +2 -3
  126. package/xsnap-native/xsnap/makefiles/lin/makefile +10 -0
  127. package/xsnap-native/xsnap/makefiles/lin/xsnap-worker.mk +156 -0
  128. package/xsnap-native/xsnap/makefiles/lin/xsnap.mk +144 -0
  129. package/xsnap-native/xsnap/makefiles/mac/makefile +10 -0
  130. package/xsnap-native/xsnap/makefiles/mac/xsnap-worker.mk +165 -0
  131. package/xsnap-native/xsnap/makefiles/mac/xsnap.mk +153 -0
  132. package/xsnap-native/xsnap/sources/xsnap-worker.c +1008 -0
  133. package/xsnap-native/xsnap/sources/xsnap.c +717 -0
  134. package/xsnap-native/xsnap/sources/xsnap.h +142 -0
  135. package/xsnap-native/xsnap/sources/xsnapPlatform.c +1501 -0
  136. package/xsnap-native/xsnap/sources/xsnapPlatform.h +105 -0
  137. package/CHANGELOG.md +0 -646
@@ -0,0 +1,480 @@
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
+ * This file incorporates work covered by the following copyright and
20
+ * permission notice:
21
+ *
22
+ * Copyright (C) 2010-2016 Marvell International Ltd.
23
+ * Copyright (C) 2002-2010 Kinoma, Inc.
24
+ *
25
+ * Licensed under the Apache License, Version 2.0 (the "License");
26
+ * you may not use this file except in compliance with the License.
27
+ * You may obtain a copy of the License at
28
+ *
29
+ * http://www.apache.org/licenses/LICENSE-2.0
30
+ *
31
+ * Unless required by applicable law or agreed to in writing, software
32
+ * distributed under the License is distributed on an "AS IS" BASIS,
33
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34
+ * See the License for the specific language governing permissions and
35
+ * limitations under the License.
36
+ */
37
+
38
+ #include "xsAll.h"
39
+ #include "xsScript.h"
40
+
41
+ /* old programming interface defaults to 0 */
42
+
43
+ #ifndef mxUseDefaultMachinePlatform
44
+ #define mxUseDefaultMachinePlatform 0
45
+ #endif
46
+ #ifndef mxUseDefaultBuildKeys
47
+ #define mxUseDefaultBuildKeys 0
48
+ #endif
49
+ #ifndef mxUseDefaultChunkAllocation
50
+ #define mxUseDefaultChunkAllocation 0
51
+ #endif
52
+ #ifndef mxUseDefaultSlotAllocation
53
+ #define mxUseDefaultSlotAllocation 0
54
+ #endif
55
+ #ifndef mxUseDefaultFindModule
56
+ #define mxUseDefaultFindModule 0
57
+ #endif
58
+ #ifndef mxUseDefaultLoadModule
59
+ #define mxUseDefaultLoadModule 0
60
+ #endif
61
+ #ifndef mxUseDefaultParseScript
62
+ #define mxUseDefaultParseScript 0
63
+ #endif
64
+ #ifndef mxUseDefaultQueuePromiseJobs
65
+ #define mxUseDefaultQueuePromiseJobs 0
66
+ #endif
67
+ #ifndef mxUseDefaultAbort
68
+ #define mxUseDefaultAbort 0
69
+ #endif
70
+ #ifndef mxUseDefaultDebug
71
+ #define mxUseDefaultDebug 0
72
+ #endif
73
+
74
+ #if mxUseDefaultMachinePlatform
75
+
76
+ void fxCreateMachinePlatform(txMachine* the)
77
+ {
78
+ }
79
+
80
+ void fxDeleteMachinePlatform(txMachine* the)
81
+ {
82
+ }
83
+
84
+ #endif /* mxUseDefaultMachinePlatform */
85
+
86
+ #if mxUseDefaultBuildKeys
87
+
88
+ void fxBuildKeys(txMachine* the)
89
+ {
90
+ int i;
91
+ for (i = 0; i < XS_SYMBOL_ID_COUNT; i++) {
92
+ txID id = the->keyIndex;
93
+ txSlot* description = fxNewSlot(the);
94
+ fxCopyStringC(the, description, gxIDStrings[i]);
95
+ the->keyArray[id] = description;
96
+ the->keyIndex++;
97
+ }
98
+ for (; i < XS_ID_COUNT; i++) {
99
+ fxID(the, gxIDStrings[i]);
100
+ }
101
+ }
102
+
103
+ #endif /* mxUseDefaultBuildKeys */
104
+
105
+
106
+ #if mxUseDefaultChunkAllocation
107
+
108
+ void* fxAllocateChunks(txMachine* the, txSize theSize)
109
+ {
110
+ return c_malloc(theSize);
111
+ }
112
+
113
+ void fxFreeChunks(txMachine* the, void* theChunks)
114
+ {
115
+ c_free(theChunks);
116
+ }
117
+
118
+ #endif /* mxUseDefaultChunkAllocation */
119
+
120
+
121
+ #if mxUseDefaultSlotAllocation
122
+
123
+ txSlot* fxAllocateSlots(txMachine* the, txSize theCount)
124
+ {
125
+ return(txSlot*)c_malloc(theCount * sizeof(txSlot));
126
+ }
127
+
128
+ void fxFreeSlots(txMachine* the, void* theSlots)
129
+ {
130
+ c_free(theSlots);
131
+ }
132
+
133
+ #endif /* mxUseDefaultSlotAllocation */
134
+
135
+ #if mxUseDefaultFindModule
136
+
137
+ txID fxFindModule(txMachine* the, txSlot* realm, txID moduleID, txSlot* slot)
138
+ {
139
+ txPreparation* preparation = the->preparation;
140
+ char name[C_PATH_MAX];
141
+ #if MODDEF_XS_TEST
142
+ char extension[5] = "";
143
+ #endif
144
+ char buffer[C_PATH_MAX];
145
+ txInteger dot = 0;
146
+ txString slash;
147
+ txString path;
148
+ fxToStringBuffer(the, slot, name, sizeof(name));
149
+ if (name[0] == '.') {
150
+ if (name[1] == '/') {
151
+ dot = 1;
152
+ }
153
+ else if ((name[1] == '.') && (name[2] == '/')) {
154
+ dot = 2;
155
+ }
156
+ }
157
+ #if mxWindows
158
+ {
159
+ char c;
160
+ slash = name;
161
+ if (!c_strncmp(name, "xsbug://", 8))
162
+ slash += 8;
163
+ while ((c = *slash)) {
164
+ if (c == '/')
165
+ *slash = '\\';
166
+ slash++;
167
+ }
168
+ }
169
+ #endif
170
+ slash = c_strrchr(name, mxSeparator);
171
+ if (!slash)
172
+ slash = name;
173
+ slash = c_strrchr(slash, '.');
174
+ if (slash && (!c_strcmp(slash, ".js") || !c_strcmp(slash, ".mjs"))) {
175
+ #if MODDEF_XS_TEST
176
+ c_strcpy(extension, slash);
177
+ #endif
178
+ *slash = 0;
179
+ }
180
+ if (dot) {
181
+ if (moduleID == XS_NO_ID)
182
+ return XS_NO_ID;
183
+ buffer[0] = mxSeparator;
184
+ path = buffer + 1;
185
+ c_strcpy(path, fxGetKeyName(the, moduleID));
186
+ slash = c_strrchr(buffer, mxSeparator);
187
+ if (!slash)
188
+ return XS_NO_ID;
189
+ if (dot == 2) {
190
+ *slash = 0;
191
+ slash = c_strrchr(buffer, mxSeparator);
192
+ if (!slash)
193
+ return XS_NO_ID;
194
+ }
195
+ *slash = 0;
196
+ if ((c_strlen(buffer) + c_strlen(name + dot)) >= sizeof(buffer))
197
+ mxRangeError("path too long");
198
+ c_strcat(buffer, name + dot);
199
+ }
200
+ else
201
+ path = name;
202
+ if (preparation) {
203
+ txInteger c = preparation->scriptCount;
204
+ txScript* script = preparation->scripts;
205
+ size_t size;
206
+ if (fxGetArchiveCode(the, the->archive, path, &size))
207
+ return fxNewNameC(the, path);
208
+ while (c > 0) {
209
+ if (!c_strcmp(path, script->path))
210
+ return fxNewNameC(the, path);
211
+ c--;
212
+ script++;
213
+ }
214
+ }
215
+ #if MODDEF_XS_TEST
216
+ if (!c_strncmp(path, "xsbug://", 8)) {
217
+ c_strcat(path, extension);
218
+ return fxNewNameC(the, path);
219
+ }
220
+ #endif
221
+ return XS_NO_ID;
222
+ }
223
+
224
+ #endif /* mxUseDefaultFindModule */
225
+
226
+ #if mxUseDefaultLoadModule
227
+
228
+ #if MODDEF_XS_TEST
229
+ extern void fxDebugImport(txMachine* the, txSlot* module, txString path);
230
+ #endif
231
+
232
+ void fxLoadModule(txMachine* the, txSlot* module, txID moduleID)
233
+ {
234
+ txString path = fxGetKeyName(the, moduleID);
235
+ txByte* code;
236
+ size_t size;
237
+ code = fxGetArchiveCode(the, the->archive, path, &size);
238
+ if (code) {
239
+ txScript script;
240
+ script.callback = NULL;
241
+ script.symbolsBuffer = NULL;
242
+ script.symbolsSize = 0;
243
+ script.codeBuffer = code;
244
+ script.codeSize = (txSize)size;
245
+ script.hostsBuffer = NULL;
246
+ script.hostsSize = 0;
247
+ script.path = path;
248
+ script.version[0] = XS_MAJOR_VERSION;
249
+ script.version[1] = XS_MINOR_VERSION;
250
+ script.version[2] = XS_PATCH_VERSION;
251
+ script.version[3] = 0;
252
+ fxResolveModule(the, module, moduleID, &script, C_NULL, C_NULL);
253
+ }
254
+ else {
255
+ txPreparation* preparation = the->preparation;
256
+ if (preparation) {
257
+ txInteger c = preparation->scriptCount;
258
+ txScript* script = preparation->scripts;
259
+ while (c > 0) {
260
+ if (!c_strcmp(path, script->path)) {
261
+ fxResolveModule(the, module, moduleID, script, C_NULL, C_NULL);
262
+ return;
263
+ }
264
+ c--;
265
+ script++;
266
+ }
267
+ }
268
+ }
269
+ #if MODDEF_XS_TEST
270
+ if (!c_strncmp(path, "xsbug://", 8)) {
271
+ fxDebugImport(the, module, path);
272
+ return;
273
+ }
274
+ #endif
275
+ }
276
+
277
+ #endif /* mxUseDefaultLoadModule */
278
+
279
+ #if mxUseDefaultParseScript
280
+
281
+ txScript* fxParseScript(txMachine* the, void* stream, txGetter getter, txUnsigned flags)
282
+ {
283
+ txParser _parser;
284
+ txParser* parser = &_parser;
285
+ txParserJump jump;
286
+ txScript* script = NULL;
287
+ fxInitializeParser(parser, the, the->parserBufferSize, the->parserTableModulo);
288
+ parser->firstJump = &jump;
289
+ if (c_setjmp(jump.jmp_buf) == 0) {
290
+ fxParserTree(parser, stream, getter, flags, NULL);
291
+ #ifdef mxDebug
292
+ parser->flags |= mxDebugFlag;
293
+ if (!parser->source) {
294
+ char tag[16];
295
+ parser->flags |= mxDebugFlag;
296
+ fxGenerateTag(the, tag, sizeof(tag), C_NULL);
297
+ parser->source = fxNewParserSymbol(parser, tag);
298
+ }
299
+ if (fxIsConnected(the)) {
300
+ if (getter == fxStringGetter)
301
+ fxFileEvalString(the, ((txStringStream*)stream)->slot->value.string, parser->source->string);
302
+ else if (getter == fxStringCGetter)
303
+ fxFileEvalString(the, ((txStringCStream*)stream)->buffer, parser->source->string);
304
+ }
305
+ #endif
306
+ fxParserHoist(parser);
307
+ fxParserBind(parser);
308
+ script = fxParserCode(parser);
309
+ }
310
+ #ifdef mxInstrument
311
+ if (the->peakParserSize < parser->total)
312
+ the->peakParserSize = parser->total;
313
+ #endif
314
+ fxTerminateParser(parser);
315
+ return script;
316
+ }
317
+
318
+ #endif /* mxUseDefaultParseScript */
319
+
320
+ #if mxUseDefaultQueuePromiseJobs
321
+
322
+ void fxQueuePromiseJobs(txMachine* the)
323
+ {
324
+ mxUnknownError("promise: no queue");
325
+ }
326
+
327
+ #endif /* mxUseDefaultQueuePromiseJobs */
328
+
329
+ #if mxUseDefaultAbort
330
+
331
+ void fxAbort(txMachine* the, int status)
332
+ {
333
+ txString why = C_NULL;
334
+ switch (status) {
335
+ case XS_STACK_OVERFLOW_EXIT:
336
+ why = "stack overflow";
337
+ break;
338
+ case XS_NOT_ENOUGH_MEMORY_EXIT:
339
+ why = "memory full";
340
+ break;
341
+ case XS_NO_MORE_KEYS_EXIT:
342
+ why = "not enough keys";
343
+ break;
344
+ case XS_DEAD_STRIP_EXIT:
345
+ why = "dead strip";
346
+ break;
347
+ case XS_DEBUGGER_EXIT:
348
+ break;
349
+ case XS_FATAL_CHECK_EXIT:
350
+ break;
351
+ case XS_UNHANDLED_EXCEPTION_EXIT:
352
+ why = "unhandled exception";
353
+ break;
354
+ case XS_UNHANDLED_REJECTION_EXIT:
355
+ why = "unhandled rejection";
356
+ break;
357
+ case XS_TOO_MUCH_COMPUTATION_EXIT:
358
+ why = "too much computation";
359
+ break;
360
+ default:
361
+ why = "unknown";
362
+ break;
363
+ }
364
+ if (why)
365
+ fprintf(stderr, "Error: %s\n", why);
366
+ c_exit(status);
367
+ }
368
+
369
+ #endif /* mxUseDefaultAbort */
370
+
371
+ #ifdef mxDebug
372
+
373
+ #if mxUseDefaultDebug
374
+
375
+ void fxConnect(txMachine* the)
376
+ {
377
+ }
378
+
379
+ void fxDisconnect(txMachine* the)
380
+ {
381
+ }
382
+
383
+ txBoolean fxIsConnected(txMachine* the)
384
+ {
385
+ return 0;
386
+ }
387
+
388
+ txBoolean fxIsReadable(txMachine* the)
389
+ {
390
+ return 0;
391
+ }
392
+
393
+ void fxReceive(txMachine* the)
394
+ {
395
+ }
396
+
397
+ void fxSend(txMachine* the, txBoolean more)
398
+ {
399
+ }
400
+
401
+ #endif /* mxUseDefaultDebug */
402
+
403
+ #endif
404
+
405
+ #if mxWindows || mxMacOSX || mxLinux || mxWasm
406
+ uint32_t modMilliseconds()
407
+ {
408
+ c_timeval tv;
409
+ c_gettimeofday(&tv, NULL);
410
+ // #if (mxWasm || mxWindows || mxMacOSX)
411
+ return (uint32_t)(uint64_t)(((double)(tv.tv_sec) * 1000.0) + ((double)(tv.tv_usec) / 1000.0));
412
+ // #else
413
+ // return (uint32_t)(((double)(tv.tv_sec) * 1000.0) + ((double)(tv.tv_usec) / 1000.0));
414
+ // #endif
415
+ }
416
+ #endif
417
+
418
+ #if mxWindows
419
+
420
+ #if _MSC_VER < 1800
421
+
422
+ unsigned long c_nan[2]={0xffffffff, 0x7fffffff};
423
+ unsigned long c_infinity[2]={0x00000000, 0x7ff00000};
424
+
425
+ int c_fpclassify(double x)
426
+ {
427
+ int result = FP_NORMAL;
428
+ switch (_fpclass(x)) {
429
+ case _FPCLASS_SNAN:
430
+ case _FPCLASS_QNAN:
431
+ result = FP_NAN;
432
+ break;
433
+ case _FPCLASS_NINF:
434
+ case _FPCLASS_PINF:
435
+ result = FP_INFINITE;
436
+ break;
437
+ case _FPCLASS_NZ:
438
+ case _FPCLASS_PZ:
439
+ result = FP_ZERO;
440
+ break;
441
+ case _FPCLASS_ND:
442
+ case _FPCLASS_PD:
443
+ result = FP_SUBNORMAL;
444
+ break;
445
+ }
446
+ return result;
447
+ }
448
+
449
+ #endif /* _MSC_VER < 1800 */
450
+
451
+ int c_gettimeofday(c_timeval *tp, struct c_timezone *tzp)
452
+ {
453
+ struct _timeb tb;
454
+
455
+ _ftime(&tb);
456
+ if (tp != 0) {
457
+ tp->tv_sec = (long)tb.time;
458
+ tp->tv_usec = tb.millitm * 1000;
459
+ }
460
+ if (tzp != 0) {
461
+ tzp->tz_minuteswest = tb.timezone;
462
+ tzp->tz_dsttime = tb.dstflag;
463
+ }
464
+ return (0);
465
+ }
466
+
467
+ #ifdef mxParse
468
+ char *c_realpath(const char *path, char *real)
469
+ {
470
+ if (_fullpath(real, path, C_PATH_MAX) != NULL) {
471
+ DWORD attributes = GetFileAttributes(real);
472
+ if (attributes != 0xFFFFFFFF) {
473
+ return real;
474
+ }
475
+ }
476
+ return C_NULL;
477
+ }
478
+ #endif
479
+
480
+ #endif