@mikrojs/native 0.0.7

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 (109) hide show
  1. package/CMakeLists.txt +198 -0
  2. package/LICENSE +21 -0
  3. package/README.md +49 -0
  4. package/cmake/mikrojs_bytecode.cmake +146 -0
  5. package/cmake.js +22 -0
  6. package/dist/index.d.ts +52 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +132 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/types.d.ts +43 -0
  11. package/dist/types.d.ts.map +1 -0
  12. package/dist/types.js +2 -0
  13. package/dist/types.js.map +1 -0
  14. package/include/byteorder_apple.h +11 -0
  15. package/include/byteorder_windows.h +12 -0
  16. package/include/mikrojs/cbor_helpers.h +24 -0
  17. package/include/mikrojs/cutils_wrap.h +59 -0
  18. package/include/mikrojs/errors.h +144 -0
  19. package/include/mikrojs/mem.h +11 -0
  20. package/include/mikrojs/mik_color.h +32 -0
  21. package/include/mikrojs/mikrojs.h +331 -0
  22. package/include/mikrojs/platform.h +82 -0
  23. package/include/mikrojs/private.h +281 -0
  24. package/include/mikrojs/utils.h +125 -0
  25. package/package.json +100 -0
  26. package/prebuilds/darwin-arm64/mikrojs.napi.node +0 -0
  27. package/prebuilds/linux-arm64/mikrojs.napi.node +0 -0
  28. package/prebuilds/linux-x64/mikrojs.napi.node +0 -0
  29. package/runtime/ble/ble.ts +231 -0
  30. package/runtime/ble/types.ts +194 -0
  31. package/runtime/ble/uuid.ts +89 -0
  32. package/runtime/ble/validators.ts +61 -0
  33. package/runtime/cbor/cbor.ts +1 -0
  34. package/runtime/cbor/types.ts +8 -0
  35. package/runtime/console/types.ts +50 -0
  36. package/runtime/env/env.ts +17 -0
  37. package/runtime/env/types.ts +12 -0
  38. package/runtime/format/types.ts +4 -0
  39. package/runtime/fs/fs.ts +93 -0
  40. package/runtime/fs/types.ts +92 -0
  41. package/runtime/globals.d.ts +87 -0
  42. package/runtime/http/helpers.ts +222 -0
  43. package/runtime/http/native.ts +151 -0
  44. package/runtime/http/request.ts +25 -0
  45. package/runtime/i2c/i2c.ts +35 -0
  46. package/runtime/i2c/types.ts +55 -0
  47. package/runtime/inspect/types.ts +10 -0
  48. package/runtime/internal.d.ts +456 -0
  49. package/runtime/kv/nvs.ts +17 -0
  50. package/runtime/kv/rtc.ts +17 -0
  51. package/runtime/kv/shared.ts +107 -0
  52. package/runtime/kv/types.ts +150 -0
  53. package/runtime/neopixel/neopixel.ts +38 -0
  54. package/runtime/neopixel/types.ts +27 -0
  55. package/runtime/pin/pin.ts +51 -0
  56. package/runtime/pin/types.ts +49 -0
  57. package/runtime/pwm/pwm.ts +32 -0
  58. package/runtime/pwm/types.ts +29 -0
  59. package/runtime/reader/reader.ts +167 -0
  60. package/runtime/reader/types.ts +34 -0
  61. package/runtime/result/native-result.node-shim.ts +44 -0
  62. package/runtime/result/result.ts +26 -0
  63. package/runtime/result/types.ts +60 -0
  64. package/runtime/schema/schema.ts +321 -0
  65. package/runtime/schema/types.ts +152 -0
  66. package/runtime/sleep/sleep.ts +14 -0
  67. package/runtime/sleep/types.ts +44 -0
  68. package/runtime/sntp/sntp.ts +54 -0
  69. package/runtime/sntp/types.ts +38 -0
  70. package/runtime/spi/spi.ts +31 -0
  71. package/runtime/spi/types.ts +42 -0
  72. package/runtime/stdio/stdio.ts +44 -0
  73. package/runtime/stdio/types.ts +22 -0
  74. package/runtime/stream/stream.ts +150 -0
  75. package/runtime/stream/types.ts +47 -0
  76. package/runtime/sys/sys.ts +90 -0
  77. package/runtime/sys/types.ts +131 -0
  78. package/runtime/test/test.ts +595 -0
  79. package/runtime/test/types.ts +97 -0
  80. package/runtime/uart/types.ts +75 -0
  81. package/runtime/uart/uart.ts +51 -0
  82. package/runtime/wifi/types.ts +156 -0
  83. package/runtime/wifi/wifi.ts +208 -0
  84. package/scripts/bundle-runtime.js +149 -0
  85. package/scripts/compare-minifiers.js +189 -0
  86. package/scripts/compile-bytecode.sh +38 -0
  87. package/scripts/copy-prebuild.js +20 -0
  88. package/scripts/generate-symbol-map.js +146 -0
  89. package/src/builtins.cpp +82 -0
  90. package/src/cutils_compat.c +38 -0
  91. package/src/eval_bytecode.cpp +42 -0
  92. package/src/fs.cpp +878 -0
  93. package/src/mem.cpp +63 -0
  94. package/src/mik_abort.cpp +160 -0
  95. package/src/mik_app_config.cpp +358 -0
  96. package/src/mik_cbor.cpp +334 -0
  97. package/src/mik_color.cpp +46 -0
  98. package/src/mik_console.cpp +422 -0
  99. package/src/mik_inspect.cpp +850 -0
  100. package/src/mik_repl.cpp +1122 -0
  101. package/src/mik_result.cpp +344 -0
  102. package/src/mik_stdio.cpp +147 -0
  103. package/src/mik_sys.cpp +239 -0
  104. package/src/mik_text_encoding.cpp +443 -0
  105. package/src/mikrojs.cpp +942 -0
  106. package/src/modules.cpp +944 -0
  107. package/src/platform_posix.cpp +134 -0
  108. package/src/timers.cpp +208 -0
  109. package/src/utils.cpp +173 -0
@@ -0,0 +1,43 @@
1
+ export interface MikroRuntimeOptions {
2
+ memLimit?: number;
3
+ stackSize?: number;
4
+ fsBasePath?: string;
5
+ fsRoot?: string;
6
+ fsLimit?: number;
7
+ fsReadMax?: number;
8
+ env?: Record<string, string>;
9
+ /** Virtual module sources to register, keyed by module name (e.g. 'native:pin'). */
10
+ modules?: Record<string, string>;
11
+ }
12
+ export interface HostMessage {
13
+ type: string;
14
+ data: string;
15
+ }
16
+ export interface ProfileEntry {
17
+ name: string;
18
+ deltaBytes: number;
19
+ order: number;
20
+ }
21
+ export interface NativeMikroRuntime {
22
+ evalModule(filename: string, isMain?: boolean): void;
23
+ evalModuleContent(filename: string, content: string): void;
24
+ evalScript(code: string): string | undefined;
25
+ loop(): Promise<void>;
26
+ loopOnce(): number;
27
+ stop(): void;
28
+ dispose(): void;
29
+ registerModuleSource(name: string, source: string): void;
30
+ drainMessages(): HostMessage[];
31
+ postMessage(type: string, data: string): void;
32
+ setPreprocessor(fn: (filename: string, source: string) => string | undefined): void;
33
+ setRpcHandler(handler: (method: string, argsJson: string) => string | Promise<string>): void;
34
+ enableProfiling(): void;
35
+ getProfile(): ProfileEntry[];
36
+ getProfileBaseline(): number;
37
+ }
38
+ export interface NativeBindings {
39
+ MikroRuntime: new (options?: MikroRuntimeOptions) => NativeMikroRuntime;
40
+ jsonToBjson(json: string): Buffer;
41
+ compileBytecode(source: string, moduleName: string, externals?: string[]): Buffer;
42
+ }
43
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../addon/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,oFAAoF;IACpF,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CACjC;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACb;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACpD,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1D,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAC5C,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACrB,QAAQ,IAAI,MAAM,CAAA;IAClB,IAAI,IAAI,IAAI,CAAA;IACZ,OAAO,IAAI,IAAI,CAAA;IACf,oBAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACxD,aAAa,IAAI,WAAW,EAAE,CAAA;IAC9B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7C,eAAe,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,GAAG,IAAI,CAAA;IACnF,aAAa,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,IAAI,CAAA;IAC5F,eAAe,IAAI,IAAI,CAAA;IACvB,UAAU,IAAI,YAAY,EAAE,CAAA;IAC5B,kBAAkB,IAAI,MAAM,CAAA;CAC7B;AAED,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,KAAK,OAAO,CAAC,EAAE,mBAAmB,KAAK,kBAAkB,CAAA;IACvE,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;IACjC,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAAA;CAClF"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../addon/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ // Apple uses libkern/OSByteOrder.h instead of <endian.h> / <sys/endian.h>.
2
+ // nanocbor expects htobe16/32/64 and be16toh/32toh/64toh names; map them.
3
+ #pragma once
4
+ #include <libkern/OSByteOrder.h>
5
+
6
+ #define htobe16(x) OSSwapHostToBigInt16(x)
7
+ #define htobe32(x) OSSwapHostToBigInt32(x)
8
+ #define htobe64(x) OSSwapHostToBigInt64(x)
9
+ #define be16toh(x) OSSwapBigToHostInt16(x)
10
+ #define be32toh(x) OSSwapBigToHostInt32(x)
11
+ #define be64toh(x) OSSwapBigToHostInt64(x)
@@ -0,0 +1,12 @@
1
+ // MSVC has no <endian.h>. Windows is always little-endian on the
2
+ // architectures we ship (x64, arm64), so map nanocbor's htobe*/be*toh to
3
+ // _byteswap_* intrinsics from <stdlib.h>.
4
+ #pragma once
5
+ #include <stdlib.h>
6
+
7
+ #define htobe16(x) _byteswap_ushort(x)
8
+ #define htobe32(x) _byteswap_ulong(x)
9
+ #define htobe64(x) _byteswap_uint64(x)
10
+ #define be16toh(x) _byteswap_ushort(x)
11
+ #define be32toh(x) _byteswap_ulong(x)
12
+ #define be64toh(x) _byteswap_uint64(x)
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Internal CBOR encode/decode helpers for JSValue ↔ nanocbor.
3
+ * Used by mik_cbor.cpp (user-facing module) and mik_rtc.cpp (RTC storage).
4
+ */
5
+
6
+ #pragma once
7
+
8
+ #include <nanocbor/nanocbor.h>
9
+ #include <quickjs.h>
10
+
11
+ #define MIK_CBOR_MAX_DEPTH 32
12
+
13
+ /**
14
+ * Recursively encode a JS value into a nanocbor encoder.
15
+ * Returns 0 on success, negative on error.
16
+ * Works with both NULL-buffer (size calculation) and real-buffer passes.
17
+ */
18
+ int mik__cbor_encode_value(JSContext* ctx, nanocbor_encoder_t* enc, JSValue val, int depth);
19
+
20
+ /**
21
+ * Decode one CBOR value from a nanocbor decoder into a JS value.
22
+ * Returns JS_EXCEPTION on error.
23
+ */
24
+ JSValue mik__cbor_decode_value(JSContext* ctx, nanocbor_value_t* val, int depth);
@@ -0,0 +1,59 @@
1
+ /* C++ compatible wrapper for QuickJS cutils.h.
2
+ *
3
+ * cutils.h contains inline functions with implicit void* → typed pointer
4
+ * conversions that are valid in C but errors in C++/Clang.
5
+ *
6
+ * - On GCC: -fpermissive downgrades these to warnings, so we can include
7
+ * cutils.h directly.
8
+ * - On Clang: we provide standalone declarations that map to wrapper
9
+ * functions in cutils_compat.c.
10
+ * - In C: just include cutils.h directly.
11
+ */
12
+ #pragma once
13
+
14
+ #if !defined(__cplusplus) || (defined(__GNUC__) && !defined(__clang__))
15
+ /* C code, or GCC C++ (where -fpermissive handles the void* casts) */
16
+ #include <cutils.h>
17
+ #else
18
+ /* Clang C++ — cannot include cutils.h inline functions, use wrappers */
19
+
20
+ #include <stdint.h>
21
+ #include <stddef.h>
22
+
23
+ extern "C" {
24
+
25
+ /* Must match the DynBuf definition in cutils.h exactly */
26
+ typedef void *DynBufReallocFunc(void *opaque, void *ptr, size_t size);
27
+
28
+ typedef struct DynBuf {
29
+ uint8_t *buf;
30
+ size_t size;
31
+ size_t allocated_size;
32
+ int error;
33
+ DynBufReallocFunc *realloc_func;
34
+ void *opaque;
35
+ } DynBuf;
36
+
37
+ /* Wrapper functions defined in cutils_compat.c */
38
+ int mik__dbuf_put(DynBuf *s, const void *data, size_t len);
39
+ int mik__dbuf_putc(DynBuf *s, uint8_t val);
40
+ int mik__dbuf_putstr(DynBuf *s, const char *str);
41
+ void mik__dbuf_free(DynBuf *s);
42
+ void mik__dbuf_init2(DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func);
43
+ int mik__js_has_suffix(const char *str, const char *suffix);
44
+ void mik__js_pstrcpy(char *buf, int buf_size, const char *str);
45
+ char *mik__js_pstrcat(char *buf, int buf_size, const char *s);
46
+
47
+ /* Map original names to wrapper names */
48
+ #define dbuf_put mik__dbuf_put
49
+ #define dbuf_putc mik__dbuf_putc
50
+ #define dbuf_putstr mik__dbuf_putstr
51
+ #define dbuf_free mik__dbuf_free
52
+ #define dbuf_init2 mik__dbuf_init2
53
+ #define js__has_suffix mik__js_has_suffix
54
+ #define js__pstrcpy mik__js_pstrcpy
55
+ #define js__pstrcat mik__js_pstrcat
56
+
57
+ } /* extern "C" */
58
+
59
+ #endif
@@ -0,0 +1,144 @@
1
+ #ifndef MIK_ERRORS_H
2
+ #define MIK_ERRORS_H
3
+
4
+ /**
5
+ * mikrojs error codes.
6
+ *
7
+ * Platform-independent error codes starting at 0x8000 to avoid collision
8
+ * with platform-specific error codes (ESP-IDF uses 0x1XX–0xXXXX).
9
+ *
10
+ * Native result error objects carry:
11
+ * - code: mikrojs error code (always present)
12
+ * - message: human-readable description
13
+ * - errno: platform error code (e.g. esp_err_t), only when non-zero
14
+ */
15
+
16
+ #define MIK_ERR_BASE 0x8000
17
+
18
+ #define MIK_ERR_INVALID_PIN (MIK_ERR_BASE + 1)
19
+ #define MIK_ERR_SET_MODE_FAILED (MIK_ERR_BASE + 2)
20
+ #define MIK_ERR_WRITE_FAILED (MIK_ERR_BASE + 3)
21
+ #define MIK_ERR_ADC_INIT_FAILED (MIK_ERR_BASE + 4)
22
+ #define MIK_ERR_INVALID_ADC_PIN (MIK_ERR_BASE + 5)
23
+ #define MIK_ERR_ADC_READ_FAILED (MIK_ERR_BASE + 6)
24
+
25
+ /* I2C errors */
26
+ #define MIK_ERR_I2C_BUS_INIT (MIK_ERR_BASE + 0x10)
27
+ #define MIK_ERR_I2C_BUS_DEINIT (MIK_ERR_BASE + 0x11)
28
+ #define MIK_ERR_I2C_NOT_STARTED (MIK_ERR_BASE + 0x12)
29
+ #define MIK_ERR_I2C_ADD_DEVICE (MIK_ERR_BASE + 0x13)
30
+ #define MIK_ERR_I2C_WRITE (MIK_ERR_BASE + 0x14)
31
+ #define MIK_ERR_I2C_READ (MIK_ERR_BASE + 0x15)
32
+ #define MIK_ERR_I2C_WRITE_TOO_LARGE (MIK_ERR_BASE + 0x16)
33
+ #define MIK_ERR_I2C_MISSING_PINS (MIK_ERR_BASE + 0x17)
34
+
35
+ /* WiFi errors */
36
+ #define MIK_ERR_WIFI_INIT_FAILED (MIK_ERR_BASE + 0x20)
37
+ #define MIK_ERR_WIFI_START_FAILED (MIK_ERR_BASE + 0x21)
38
+ #define MIK_ERR_WIFI_COUNTRY_NOT_SET (MIK_ERR_BASE + 0x22)
39
+ #define MIK_ERR_WIFI_CONNECT_FAILED (MIK_ERR_BASE + 0x23)
40
+ #define MIK_ERR_WIFI_CONNECT_IN_PROGRESS (MIK_ERR_BASE + 0x24)
41
+ #define MIK_ERR_WIFI_DISCONNECT_FAILED (MIK_ERR_BASE + 0x25)
42
+ #define MIK_ERR_WIFI_SCAN_FAILED (MIK_ERR_BASE + 0x26)
43
+ #define MIK_ERR_WIFI_SCAN_IN_PROGRESS (MIK_ERR_BASE + 0x27)
44
+ #define MIK_ERR_WIFI_NOT_INITIALIZED (MIK_ERR_BASE + 0x28)
45
+ #define MIK_ERR_WIFI_CONFIG_FAILED (MIK_ERR_BASE + 0x29)
46
+ #define MIK_ERR_WIFI_AP_START_FAILED (MIK_ERR_BASE + 0x2A)
47
+ #define MIK_ERR_WIFI_AP_STOP_FAILED (MIK_ERR_BASE + 0x2B)
48
+ #define MIK_ERR_WIFI_SET_FAILED (MIK_ERR_BASE + 0x2C)
49
+ #define MIK_ERR_WIFI_GET_FAILED (MIK_ERR_BASE + 0x2D)
50
+
51
+ /* SPI errors */
52
+ #define MIK_ERR_SPI_BUS_INIT (MIK_ERR_BASE + 0x30)
53
+ #define MIK_ERR_SPI_ADD_DEVICE (MIK_ERR_BASE + 0x31)
54
+ #define MIK_ERR_SPI_NOT_STARTED (MIK_ERR_BASE + 0x32)
55
+ #define MIK_ERR_SPI_TRANSFER (MIK_ERR_BASE + 0x33)
56
+ #define MIK_ERR_SPI_WRITE (MIK_ERR_BASE + 0x34)
57
+ #define MIK_ERR_SPI_MISSING_PINS (MIK_ERR_BASE + 0x35)
58
+
59
+ /* PWM errors */
60
+ #define MIK_ERR_PWM_NO_CHANNEL (MIK_ERR_BASE + 0x40)
61
+ #define MIK_ERR_PWM_NO_TIMER (MIK_ERR_BASE + 0x41)
62
+ #define MIK_ERR_PWM_CONFIG (MIK_ERR_BASE + 0x42)
63
+ #define MIK_ERR_PWM_NOT_ACTIVE (MIK_ERR_BASE + 0x43)
64
+ #define MIK_ERR_PWM_DUTY (MIK_ERR_BASE + 0x44)
65
+ #define MIK_ERR_PWM_FREQ (MIK_ERR_BASE + 0x45)
66
+ #define MIK_ERR_PWM_FADE (MIK_ERR_BASE + 0x46)
67
+
68
+ /* Sleep errors */
69
+ #define MIK_ERR_SLEEP_WAKEUP_CONFIG (MIK_ERR_BASE + 0x60)
70
+ #define MIK_ERR_SLEEP_LIGHT_SLEEP (MIK_ERR_BASE + 0x61)
71
+ #define MIK_ERR_SLEEP_DISABLE_WAKEUP (MIK_ERR_BASE + 0x62)
72
+
73
+ /* NeoPixel errors */
74
+ #define MIK_ERR_NEOPIXEL_NOT_ACTIVE (MIK_ERR_BASE + 0x50)
75
+ #define MIK_ERR_NEOPIXEL_INDEX_RANGE (MIK_ERR_BASE + 0x51)
76
+ #define MIK_ERR_NEOPIXEL_SHOW (MIK_ERR_BASE + 0x52)
77
+
78
+ /* SNTP errors */
79
+ #define MIK_ERR_SNTP_INIT_FAILED (MIK_ERR_BASE + 0x70)
80
+ #define MIK_ERR_SNTP_CANCELLED (MIK_ERR_BASE + 0x71)
81
+
82
+ /* HTTP errors */
83
+ #define MIK_ERR_HTTP_TOO_MANY_PENDING (MIK_ERR_BASE + 0x80)
84
+ #define MIK_ERR_HTTP_TASK_FAILED (MIK_ERR_BASE + 0x81)
85
+ #define MIK_ERR_HTTP_REQUEST_FAILED (MIK_ERR_BASE + 0x82)
86
+ #define MIK_ERR_HTTP_CANCELLED (MIK_ERR_BASE + 0x83)
87
+
88
+ /* CBOR errors */
89
+ #define MIK_ERR_CBOR_ENCODE (MIK_ERR_BASE + 0x90)
90
+ #define MIK_ERR_CBOR_DECODE (MIK_ERR_BASE + 0x91)
91
+
92
+ /* UART errors */
93
+ #define MIK_ERR_UART_DRIVER_INSTALL (MIK_ERR_BASE + 0xA0)
94
+ #define MIK_ERR_UART_SET_PIN (MIK_ERR_BASE + 0xA1)
95
+ #define MIK_ERR_UART_PARAM (MIK_ERR_BASE + 0xA2)
96
+ #define MIK_ERR_UART_WRITE (MIK_ERR_BASE + 0xA3)
97
+ #define MIK_ERR_UART_READ (MIK_ERR_BASE + 0xA4)
98
+ #define MIK_ERR_UART_NOT_STARTED (MIK_ERR_BASE + 0xA5)
99
+ #define MIK_ERR_UART_ALREADY_READING (MIK_ERR_BASE + 0xA6)
100
+ #define MIK_ERR_UART_NO_RX (MIK_ERR_BASE + 0xA7)
101
+ #define MIK_ERR_UART_NO_TX (MIK_ERR_BASE + 0xA8)
102
+
103
+ /* BLE errors */
104
+ #define MIK_ERR_BLE_STACK_INIT_FAILED (MIK_ERR_BASE + 0xB0)
105
+ #define MIK_ERR_BLE_CONTROLLER_INIT_FAILED (MIK_ERR_BASE + 0xB1)
106
+ #define MIK_ERR_BLE_ADVERTISE_START_FAILED (MIK_ERR_BASE + 0xB2)
107
+ #define MIK_ERR_BLE_ADVERTISE_STOP_FAILED (MIK_ERR_BASE + 0xB3)
108
+ #define MIK_ERR_BLE_ALREADY_ADVERTISING (MIK_ERR_BASE + 0xB4)
109
+ #define MIK_ERR_BLE_SET_FAILED (MIK_ERR_BASE + 0xB5)
110
+ #define MIK_ERR_BLE_GET_FAILED (MIK_ERR_BASE + 0xB6)
111
+ #define MIK_ERR_BLE_STACK_SHUTDOWN (MIK_ERR_BASE + 0xB7)
112
+ #define MIK_ERR_BLE_NOT_INITIALIZED (MIK_ERR_BASE + 0xB8)
113
+ #define MIK_ERR_BLE_INVALID_UUID (MIK_ERR_BASE + 0xB9)
114
+ #define MIK_ERR_BLE_DUPLICATE_CHARACTERISTIC (MIK_ERR_BASE + 0xBA)
115
+ #define MIK_ERR_BLE_INVALID_PROPERTIES (MIK_ERR_BASE + 0xBB)
116
+ #define MIK_ERR_BLE_GATT_REGISTRATION_FAILED (MIK_ERR_BASE + 0xBC)
117
+ #define MIK_ERR_BLE_GATT_ALREADY_REGISTERED (MIK_ERR_BASE + 0xBD)
118
+ #define MIK_ERR_BLE_NO_SUCH_CHARACTERISTIC (MIK_ERR_BASE + 0xBE)
119
+ #define MIK_ERR_BLE_NOT_CONNECTED (MIK_ERR_BASE + 0xBF)
120
+ #define MIK_ERR_BLE_VALUE_TOO_LARGE (MIK_ERR_BASE + 0xC0)
121
+ #define MIK_ERR_BLE_NOTIFY_FAILED (MIK_ERR_BASE + 0xC1)
122
+
123
+ /* KV storage errors */
124
+ #define MIK_ERR_KV_INVALID_KEY (MIK_ERR_BASE + 0xD0)
125
+ #define MIK_ERR_KV_ENCODE (MIK_ERR_BASE + 0xD1)
126
+ #define MIK_ERR_KV_TOO_LARGE (MIK_ERR_BASE + 0xD2)
127
+ #define MIK_ERR_KV_STORAGE_FULL (MIK_ERR_BASE + 0xD3)
128
+ #define MIK_ERR_KV_WRITE (MIK_ERR_BASE + 0xD4)
129
+
130
+ /* Filesystem errors — mikrojs/fs.
131
+ * Codes cover the curated FSError variants. Anything unexpected at the
132
+ * C/errno layer falls through to MIK_ERR_FS_UNKNOWN; the JS mapping layer
133
+ * produces FSError.Unknown carrying the raw errno and message. */
134
+ #define MIK_ERR_FS_NOT_FOUND (MIK_ERR_BASE + 0xE0)
135
+ #define MIK_ERR_FS_ALREADY_EXISTS (MIK_ERR_BASE + 0xE1)
136
+ #define MIK_ERR_FS_ACCESS_DENIED (MIK_ERR_BASE + 0xE2)
137
+ #define MIK_ERR_FS_NO_SPACE (MIK_ERR_BASE + 0xE3)
138
+ #define MIK_ERR_FS_TOO_LARGE (MIK_ERR_BASE + 0xE4)
139
+ #define MIK_ERR_FS_IS_DIRECTORY (MIK_ERR_BASE + 0xE5)
140
+ #define MIK_ERR_FS_NOT_DIRECTORY (MIK_ERR_BASE + 0xE6)
141
+ #define MIK_ERR_FS_BAD_FILE_DESCRIPTOR (MIK_ERR_BASE + 0xE7)
142
+ #define MIK_ERR_FS_UNKNOWN (MIK_ERR_BASE + 0xE8)
143
+
144
+ #endif // MIK_ERRORS_H
@@ -0,0 +1,11 @@
1
+ #pragma once
2
+
3
+ #include <stddef.h>
4
+ #include <stdlib.h>
5
+
6
+ size_t mik__malloc_usable_size(const void* ptr);
7
+ void* mik__malloc(size_t size);
8
+ void* mik__mallocz(size_t size);
9
+ void* mik__calloc(size_t count, size_t size);
10
+ void mik__free(void* ptr);
11
+ void* mik__realloc(void* ptr, size_t size);
@@ -0,0 +1,32 @@
1
+ #pragma once
2
+
3
+ #include <string>
4
+ #include <string_view>
5
+
6
+ /* Theme tokens — semantic categories for syntax highlighting */
7
+ enum MikThemeToken {
8
+ MIK_TOKEN_ANNOTATION,
9
+ MIK_TOKEN_BOOLEAN,
10
+ MIK_TOKEN_COMMENT,
11
+ MIK_TOKEN_DATE,
12
+ MIK_TOKEN_ERROR,
13
+ MIK_TOKEN_WARNING,
14
+ MIK_TOKEN_FUNCTION,
15
+ MIK_TOKEN_IDENTIFIER,
16
+ MIK_TOKEN_KEYWORD,
17
+ MIK_TOKEN_NULL,
18
+ MIK_TOKEN_NUMBER,
19
+ MIK_TOKEN_OTHER,
20
+ MIK_TOKEN_REGEXP,
21
+ MIK_TOKEN_STRING,
22
+ MIK_TOKEN_SYMBOL,
23
+ MIK_TOKEN_TYPE,
24
+ MIK_TOKEN_UNDEFINED,
25
+ MIK_TOKEN_BIGINT,
26
+ MIK_TOKEN_RESULT,
27
+ MIK_TOKEN__COUNT,
28
+ };
29
+
30
+ /* Colorize a string with ANSI escapes for the given theme token.
31
+ * Returns the input unchanged if the token is invalid. */
32
+ std::string mik_colorize(MikThemeToken token, std::string_view value);