stone-lang 0.1.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 (68) hide show
  1. package/README.md +52 -0
  2. package/StoneEngine.js +879 -0
  3. package/StoneEngineService.js +1727 -0
  4. package/adapters/FileSystemAdapter.js +230 -0
  5. package/adapters/OutputAdapter.js +208 -0
  6. package/adapters/index.js +6 -0
  7. package/cli/CLIOutputAdapter.js +196 -0
  8. package/cli/DaemonClient.js +349 -0
  9. package/cli/JSONOutputAdapter.js +135 -0
  10. package/cli/ReplSession.js +567 -0
  11. package/cli/ViewerServer.js +590 -0
  12. package/cli/commands/check.js +84 -0
  13. package/cli/commands/daemon.js +189 -0
  14. package/cli/commands/kill.js +66 -0
  15. package/cli/commands/package.js +713 -0
  16. package/cli/commands/ps.js +65 -0
  17. package/cli/commands/run.js +537 -0
  18. package/cli/entry.js +169 -0
  19. package/cli/index.js +14 -0
  20. package/cli/stonec.js +358 -0
  21. package/cli/test-compiler.js +181 -0
  22. package/cli/viewer/index.html +495 -0
  23. package/daemon/IPCServer.js +455 -0
  24. package/daemon/ProcessManager.js +327 -0
  25. package/daemon/ProcessRunner.js +307 -0
  26. package/daemon/daemon.js +398 -0
  27. package/daemon/index.js +16 -0
  28. package/frontend/analysis/index.js +5 -0
  29. package/frontend/analysis/livenessAnalyzer.js +568 -0
  30. package/frontend/analysis/treeShaker.js +265 -0
  31. package/frontend/index.js +20 -0
  32. package/frontend/parsing/astBuilder.js +2196 -0
  33. package/frontend/parsing/index.js +7 -0
  34. package/frontend/parsing/sonParser.js +592 -0
  35. package/frontend/parsing/stoneAstTypes.js +703 -0
  36. package/frontend/parsing/terminal-registry.js +435 -0
  37. package/frontend/parsing/tokenizer.js +692 -0
  38. package/frontend/type-checker/OverloadedFunctionType.js +43 -0
  39. package/frontend/type-checker/TypeEnvironment.js +165 -0
  40. package/frontend/type-checker/bidirectionalInference.js +149 -0
  41. package/frontend/type-checker/index.js +10 -0
  42. package/frontend/type-checker/moduleAnalysis.js +248 -0
  43. package/frontend/type-checker/operatorMappings.js +35 -0
  44. package/frontend/type-checker/overloadResolution.js +605 -0
  45. package/frontend/type-checker/typeChecker.js +452 -0
  46. package/frontend/type-checker/typeCompatibility.js +389 -0
  47. package/frontend/type-checker/visitors/controlFlow.js +483 -0
  48. package/frontend/type-checker/visitors/functions.js +604 -0
  49. package/frontend/type-checker/visitors/index.js +38 -0
  50. package/frontend/type-checker/visitors/literals.js +341 -0
  51. package/frontend/type-checker/visitors/modules.js +159 -0
  52. package/frontend/type-checker/visitors/operators.js +109 -0
  53. package/frontend/type-checker/visitors/statements.js +768 -0
  54. package/frontend/types/index.js +5 -0
  55. package/frontend/types/operatorMap.js +134 -0
  56. package/frontend/types/types.js +2046 -0
  57. package/frontend/utils/errorCollector.js +244 -0
  58. package/frontend/utils/index.js +5 -0
  59. package/frontend/utils/moduleResolver.js +479 -0
  60. package/package.json +50 -0
  61. package/packages/browserCache.js +359 -0
  62. package/packages/fetcher.js +236 -0
  63. package/packages/index.js +130 -0
  64. package/packages/lockfile.js +271 -0
  65. package/packages/manifest.js +291 -0
  66. package/packages/packageResolver.js +356 -0
  67. package/packages/resolver.js +310 -0
  68. package/packages/semver.js +635 -0
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Frontend Types - Barrel exports
3
+ */
4
+ export * from './types.js';
5
+ export * from './operatorMap.js';
@@ -0,0 +1,134 @@
1
+ /**
2
+ * Stone Operator to Function Mapping
3
+ *
4
+ * Maps operators to function names for desugaring.
5
+ * Operators are transformed into function calls which are then
6
+ * resolved via the overload system.
7
+ *
8
+ * Example: a + b → add(a, b)
9
+ */
10
+
11
+ /**
12
+ * Binary operators mapped to function names
13
+ *
14
+ * Scalar operators (+, -, *, /) only work on scalars.
15
+ * Elementwise operators (.+, .-, .*, ./) work on arrays.
16
+ * Using scalar operators on arrays is a type error.
17
+ */
18
+ export const BINARY_OP_NAMES = {
19
+ // Scalar arithmetic (num, complex, string only)
20
+ "+": "add",
21
+ "-": "sub",
22
+ "*": "mul",
23
+ "/": "div",
24
+ "%": "mod",
25
+ "^": "pow",
26
+
27
+ // Elementwise arithmetic (works on arrays)
28
+ ".+": "elem_add",
29
+ ".-": "elem_sub",
30
+ ".*": "elem_mul",
31
+ "./": "elem_div",
32
+ ".^": "elem_pow",
33
+
34
+ // Matrix operations
35
+ "@": "matmul",
36
+
37
+ // Comparison
38
+ "<": "lt",
39
+ ">": "gt",
40
+ "<=": "lte",
41
+ ">=": "gte",
42
+ "==": "eq",
43
+ "!=": "neq",
44
+ };
45
+
46
+ /**
47
+ * Unary operators mapped to function names
48
+ */
49
+ export const UNARY_OP_NAMES = {
50
+ "-": "neg",
51
+ "!": "not",
52
+ };
53
+
54
+ /**
55
+ * Postfix operators mapped to function names
56
+ */
57
+ export const POSTFIX_OP_NAMES = {};
58
+
59
+ /**
60
+ * Index access operator
61
+ * arr[i] → index_get(arr, i)
62
+ */
63
+ export const INDEX_OP_NAME = "index_get";
64
+
65
+ /**
66
+ * Operators that do NOT desugar to functions
67
+ * These have special semantics that require direct handling.
68
+ */
69
+ export const SPECIAL_CASES = {
70
+ // Short-circuit evaluation - cannot be desugared
71
+ "&&": { reason: "short-circuit evaluation" },
72
+ "||": { reason: "short-circuit evaluation" },
73
+
74
+ // Static member access - resolved at compile time
75
+ ".": { reason: "static member access" },
76
+
77
+ // Assignment - modifies environment
78
+ "=": { reason: "assignment" },
79
+
80
+ // Destructuring assignment
81
+ ":=": { reason: "destructuring assignment" },
82
+ };
83
+
84
+ /**
85
+ * Check if an operator should be desugared to a function call
86
+ *
87
+ * @param {string} op - Operator symbol
88
+ * @returns {boolean}
89
+ */
90
+ export function shouldDesugar(op) {
91
+ return !SPECIAL_CASES.hasOwnProperty(op);
92
+ }
93
+
94
+ /**
95
+ * Get the function name for a binary operator
96
+ *
97
+ * @param {string} op - Operator symbol
98
+ * @returns {string|null} Function name or null if not found
99
+ */
100
+ export function getBinaryOpName(op) {
101
+ return BINARY_OP_NAMES[op] || null;
102
+ }
103
+
104
+ /**
105
+ * Get the function name for a unary operator
106
+ *
107
+ * @param {string} op - Operator symbol
108
+ * @returns {string|null} Function name or null if not found
109
+ */
110
+ export function getUnaryOpName(op) {
111
+ return UNARY_OP_NAMES[op] || null;
112
+ }
113
+
114
+ /**
115
+ * Get the function name for a postfix operator
116
+ *
117
+ * @param {string} op - Operator symbol
118
+ * @returns {string|null} Function name or null if not found
119
+ */
120
+ export function getPostfixOpName(op) {
121
+ return POSTFIX_OP_NAMES[op] || null;
122
+ }
123
+
124
+ export default {
125
+ BINARY_OP_NAMES,
126
+ UNARY_OP_NAMES,
127
+ POSTFIX_OP_NAMES,
128
+ INDEX_OP_NAME,
129
+ SPECIAL_CASES,
130
+ shouldDesugar,
131
+ getBinaryOpName,
132
+ getUnaryOpName,
133
+ getPostfixOpName,
134
+ };