yukigo 0.2.2 → 0.3.1

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 (266) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +102 -41
  3. package/README.md +193 -193
  4. package/dist/analyzer/GraphBuilder.d.ts +1 -0
  5. package/dist/analyzer/GraphBuilder.js +2 -1
  6. package/dist/analyzer/index.d.ts +0 -7
  7. package/dist/analyzer/index.js +3 -3
  8. package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
  9. package/dist/analyzer/inspections/functional/functional.js +1 -1
  10. package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
  11. package/dist/analyzer/inspections/functional/smells.js +27 -35
  12. package/dist/analyzer/inspections/generic/generic.d.ts +21 -14
  13. package/dist/analyzer/inspections/generic/generic.js +78 -59
  14. package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
  15. package/dist/analyzer/inspections/generic/smells.js +55 -64
  16. package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
  17. package/dist/analyzer/inspections/imperative/imperative.js +3 -3
  18. package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
  19. package/dist/analyzer/inspections/imperative/smells.js +8 -5
  20. package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
  21. package/dist/analyzer/inspections/logic/logic.js +5 -5
  22. package/dist/analyzer/inspections/logic/smells.js +2 -2
  23. package/dist/analyzer/inspections/object/object.d.ts +5 -5
  24. package/dist/analyzer/inspections/object/object.js +22 -21
  25. package/dist/analyzer/inspections/object/smells.js +11 -23
  26. package/dist/analyzer/utils.d.ts +6 -2
  27. package/dist/analyzer/utils.js +6 -2
  28. package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
  29. package/dist/interpreter/components/EnvBuilder.js +211 -66
  30. package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
  31. package/dist/interpreter/components/EqualityComparer.js +69 -0
  32. package/dist/interpreter/components/Operations.d.ts +17 -14
  33. package/dist/interpreter/components/Operations.js +61 -62
  34. package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
  35. package/dist/interpreter/components/PatternMatcher.js +185 -286
  36. package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
  37. package/dist/interpreter/components/RuntimeContext.js +43 -4
  38. package/dist/interpreter/components/TestRunner.d.ts +15 -13
  39. package/dist/interpreter/components/TestRunner.js +86 -53
  40. package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
  41. package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
  42. package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
  43. package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
  44. package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
  45. package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
  46. package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
  47. package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
  48. package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
  49. package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
  50. package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
  51. package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
  52. package/dist/interpreter/components/evaluators/index.d.ts +110 -0
  53. package/dist/interpreter/components/evaluators/index.js +21 -0
  54. package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
  55. package/dist/interpreter/components/evaluators/utils.js +50 -0
  56. package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
  57. package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
  58. package/dist/interpreter/components/kernel/commands.d.ts +122 -0
  59. package/dist/interpreter/components/kernel/commands.js +203 -0
  60. package/dist/interpreter/components/kernel/index.d.ts +51 -0
  61. package/dist/interpreter/components/kernel/index.js +176 -0
  62. package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
  63. package/dist/interpreter/components/logic/LogicEngine.js +234 -221
  64. package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
  65. package/dist/interpreter/components/logic/LogicResolver.js +73 -440
  66. package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
  67. package/dist/interpreter/components/logic/LogicTerm.js +423 -0
  68. package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
  69. package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
  70. package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
  71. package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
  72. package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
  73. package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
  74. package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
  75. package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
  76. package/dist/interpreter/errors.d.ts +10 -0
  77. package/dist/interpreter/errors.js +17 -0
  78. package/dist/interpreter/index.d.ts +9 -5
  79. package/dist/interpreter/index.js +11 -13
  80. package/dist/interpreter/primitives/YuValue.d.ts +21 -0
  81. package/dist/interpreter/primitives/YuValue.js +40 -0
  82. package/dist/interpreter/primitives/capabilities.d.ts +90 -0
  83. package/dist/interpreter/primitives/capabilities.js +1 -0
  84. package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
  85. package/dist/interpreter/primitives/entities/LazyList.js +164 -0
  86. package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
  87. package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
  88. package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
  89. package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
  90. package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
  91. package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
  92. package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
  93. package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
  94. package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
  95. package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
  96. package/dist/interpreter/primitives/index.d.ts +14 -0
  97. package/dist/interpreter/primitives/index.js +14 -0
  98. package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
  99. package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
  100. package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
  101. package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
  102. package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
  103. package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
  104. package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
  105. package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
  106. package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
  107. package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
  108. package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
  109. package/dist/interpreter/primitives/sequences/YuString.js +130 -0
  110. package/dist/interpreter/utils.d.ts +23 -10
  111. package/dist/interpreter/utils.js +25 -30
  112. package/dist/tester/index.d.ts +3 -3
  113. package/dist/tester/index.js +39 -28
  114. package/dist/utils/helpers.d.ts +12 -5
  115. package/dist/utils/helpers.js +6 -79
  116. package/package.json +3 -16
  117. package/src/analyzer/GraphBuilder.ts +143 -142
  118. package/src/analyzer/index.ts +185 -194
  119. package/src/analyzer/inspections/functional/functional.ts +121 -121
  120. package/src/analyzer/inspections/functional/smells.ts +88 -102
  121. package/src/analyzer/inspections/generic/generic.ts +610 -581
  122. package/src/analyzer/inspections/generic/smells.ts +355 -365
  123. package/src/analyzer/inspections/imperative/imperative.ts +104 -101
  124. package/src/analyzer/inspections/imperative/smells.ts +58 -54
  125. package/src/analyzer/inspections/logic/logic.ts +84 -90
  126. package/src/analyzer/inspections/logic/smells.ts +54 -54
  127. package/src/analyzer/inspections/object/object.ts +295 -264
  128. package/src/analyzer/inspections/object/smells.ts +130 -144
  129. package/src/analyzer/utils.ts +115 -109
  130. package/src/index.ts +3 -3
  131. package/src/interpreter/components/EnvBuilder.ts +405 -202
  132. package/src/interpreter/components/EqualityComparer.ts +107 -0
  133. package/src/interpreter/components/Operations.ts +126 -99
  134. package/src/interpreter/components/PatternMatcher.ts +375 -475
  135. package/src/interpreter/components/RuntimeContext.ts +181 -119
  136. package/src/interpreter/components/TestRunner.ts +223 -151
  137. package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
  138. package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
  139. package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
  140. package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
  141. package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
  142. package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
  143. package/src/interpreter/components/evaluators/index.ts +34 -0
  144. package/src/interpreter/components/evaluators/utils.ts +64 -0
  145. package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
  146. package/src/interpreter/components/kernel/commands.ts +255 -0
  147. package/src/interpreter/components/kernel/index.ts +222 -0
  148. package/src/interpreter/components/logic/LogicEngine.ts +509 -519
  149. package/src/interpreter/components/logic/LogicResolver.ts +209 -858
  150. package/src/interpreter/components/logic/LogicTerm.ts +477 -0
  151. package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
  152. package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
  153. package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
  154. package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
  155. package/src/interpreter/errors.ts +68 -47
  156. package/src/interpreter/index.ts +50 -52
  157. package/src/interpreter/primitives/YuValue.ts +64 -0
  158. package/src/interpreter/primitives/capabilities.ts +111 -0
  159. package/src/interpreter/primitives/entities/LazyList.ts +225 -0
  160. package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
  161. package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
  162. package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
  163. package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
  164. package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
  165. package/src/interpreter/primitives/index.ts +17 -0
  166. package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
  167. package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
  168. package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
  169. package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
  170. package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
  171. package/src/interpreter/primitives/sequences/YuString.ts +165 -0
  172. package/src/interpreter/utils.ts +105 -84
  173. package/src/tester/index.ts +157 -128
  174. package/src/utils/helpers.ts +81 -168
  175. package/tests/analyzer/functional.spec.ts +221 -207
  176. package/tests/analyzer/generic.spec.ts +178 -178
  177. package/tests/analyzer/helpers.spec.ts +83 -89
  178. package/tests/analyzer/logic.spec.ts +237 -237
  179. package/tests/analyzer/oop.spec.ts +320 -323
  180. package/tests/analyzer/transitive.spec.ts +166 -166
  181. package/tests/interpreter/EnvBuilder.spec.ts +181 -183
  182. package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
  183. package/tests/interpreter/LazyRuntime.spec.ts +227 -225
  184. package/tests/interpreter/LogicEngine.spec.ts +371 -327
  185. package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
  186. package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
  187. package/tests/interpreter/Operations.spec.ts +312 -220
  188. package/tests/interpreter/PatternSystem.spec.ts +254 -213
  189. package/tests/interpreter/Tests.spec.ts +122 -122
  190. package/tests/interpreter/interpreter.spec.ts +1143 -991
  191. package/tests/kernel/YukigoKernel.spec.ts +112 -0
  192. package/tests/tester/Tester.spec.ts +188 -152
  193. package/tsconfig.build.json +16 -15
  194. package/tsconfig.json +27 -25
  195. package/dist/interpreter/components/Visitor.d.ts +0 -70
  196. package/dist/interpreter/components/Visitor.js +0 -634
  197. package/dist/interpreter/entities.d.ts +0 -105
  198. package/dist/interpreter/entities.js +0 -96
  199. package/dist/interpreter/trampoline.d.ts +0 -17
  200. package/dist/interpreter/trampoline.js +0 -38
  201. package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
  202. package/dist/src/analyzer/GraphBuilder.js +0 -100
  203. package/dist/src/analyzer/index.d.ts +0 -59
  204. package/dist/src/analyzer/index.js +0 -152
  205. package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
  206. package/dist/src/analyzer/inspections/functional/functional.js +0 -149
  207. package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
  208. package/dist/src/analyzer/inspections/functional/smells.js +0 -98
  209. package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
  210. package/dist/src/analyzer/inspections/generic/generic.js +0 -604
  211. package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
  212. package/dist/src/analyzer/inspections/generic/smells.js +0 -349
  213. package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
  214. package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
  215. package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
  216. package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
  217. package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
  218. package/dist/src/analyzer/inspections/logic/logic.js +0 -96
  219. package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
  220. package/dist/src/analyzer/inspections/logic/smells.js +0 -60
  221. package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
  222. package/dist/src/analyzer/inspections/object/object.js +0 -321
  223. package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
  224. package/dist/src/analyzer/inspections/object/smells.js +0 -135
  225. package/dist/src/analyzer/utils.d.ts +0 -30
  226. package/dist/src/analyzer/utils.js +0 -78
  227. package/dist/src/index.d.ts +0 -4
  228. package/dist/src/index.js +0 -4
  229. package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
  230. package/dist/src/interpreter/components/EnvBuilder.js +0 -155
  231. package/dist/src/interpreter/components/Operations.d.ts +0 -14
  232. package/dist/src/interpreter/components/Operations.js +0 -84
  233. package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
  234. package/dist/src/interpreter/components/PatternMatcher.js +0 -358
  235. package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
  236. package/dist/src/interpreter/components/RuntimeContext.js +0 -93
  237. package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
  238. package/dist/src/interpreter/components/TestRunner.js +0 -110
  239. package/dist/src/interpreter/components/Visitor.d.ts +0 -71
  240. package/dist/src/interpreter/components/Visitor.js +0 -638
  241. package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
  242. package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
  243. package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
  244. package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
  245. package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
  246. package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
  247. package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
  248. package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
  249. package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
  250. package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
  251. package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
  252. package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
  253. package/dist/src/interpreter/errors.d.ts +0 -19
  254. package/dist/src/interpreter/errors.js +0 -36
  255. package/dist/src/interpreter/index.d.ts +0 -24
  256. package/dist/src/interpreter/index.js +0 -41
  257. package/dist/src/interpreter/trampoline.d.ts +0 -17
  258. package/dist/src/interpreter/trampoline.js +0 -38
  259. package/dist/src/interpreter/utils.d.ts +0 -11
  260. package/dist/src/interpreter/utils.js +0 -65
  261. package/dist/src/tester/index.d.ts +0 -25
  262. package/dist/src/tester/index.js +0 -113
  263. package/dist/src/utils/helpers.d.ts +0 -13
  264. package/dist/src/utils/helpers.js +0 -52
  265. package/src/interpreter/components/Visitor.ts +0 -1065
  266. package/src/interpreter/trampoline.ts +0 -71
@@ -1,105 +0,0 @@
1
- import { Fact, Rule, Pattern, GuardedBody, UnguardedBody } from "yukigo-ast";
2
- export type SuccessLogicResult = {
3
- success: true;
4
- solutions: Map<string, PrimitiveValue>;
5
- };
6
- export type FailedLogicResult = {
7
- success: false;
8
- };
9
- export type LogicResult = SuccessLogicResult | FailedLogicResult;
10
- export type PrimitiveValue = number | boolean | string | RuntimeFunction | RuntimePredicate | LogicResult | LazyList | null | void | PrimitiveValue[] | RuntimeObject | RuntimeClass | undefined;
11
- export declare function isLogicResult(value: PrimitiveValue): value is LogicResult;
12
- export type PrimitiveThunk = () => PrimitiveValue;
13
- export type Environment = Map<string, PrimitiveValue>;
14
- export type EnvStack = {
15
- head: Environment;
16
- tail: EnvStack | null;
17
- };
18
- type RuntimePredicateKind = "Fact" | "Rule" | "Predicate";
19
- type PredicateEquation = Fact | Rule;
20
- export interface IRuntimePredicate {
21
- kind: RuntimePredicateKind;
22
- identifier: string;
23
- equations: PredicateEquation[];
24
- }
25
- export declare class RuntimePredicate implements IRuntimePredicate {
26
- kind: RuntimePredicateKind;
27
- identifier: string;
28
- equations: PredicateEquation[];
29
- constructor(kind: RuntimePredicateKind, identifier: string, equations: PredicateEquation[]);
30
- pushEquation<T extends Fact | Rule>(eq: T): void;
31
- }
32
- export declare const isRuntimePredicate: (prim: PrimitiveValue) => prim is RuntimePredicate;
33
- type Body = GuardedBody[] | UnguardedBody;
34
- export interface IRuntimeEquation {
35
- patterns: Pattern[];
36
- body: Body;
37
- }
38
- export declare class RuntimeEquation implements IRuntimeEquation {
39
- patterns: Pattern[];
40
- body: Body;
41
- constructor(patterns: Pattern[], body: Body);
42
- }
43
- type PendingArg = PrimitiveValue | PrimitiveThunk;
44
- /**
45
- * Runtime Function used in the Interpreter
46
- */
47
- export interface IRuntimeFunction {
48
- arity: number;
49
- identifier: string;
50
- equations: RuntimeEquation[];
51
- pendingArgs: PendingArg[];
52
- closure?: EnvStack;
53
- }
54
- export declare class RuntimeFunction implements IRuntimeFunction {
55
- arity: number;
56
- identifier: string;
57
- equations: RuntimeEquation[];
58
- pendingArgs: PendingArg[];
59
- closure?: EnvStack;
60
- constructor(arity: number, identifier: string, equations: RuntimeEquation[], pendingArgs: PendingArg[], closure?: EnvStack);
61
- setPendingArgs(args: PendingArg[]): void;
62
- }
63
- export declare function isRuntimeFunction(val: PrimitiveValue): val is RuntimeFunction;
64
- type Fields = Map<string, PrimitiveValue>;
65
- type Methods = Map<string, RuntimeFunction>;
66
- export interface IRuntimeClass {
67
- identifier: string;
68
- fields: Fields;
69
- methods: Methods;
70
- mixins: string[];
71
- superclass?: string;
72
- }
73
- export declare class RuntimeClass implements IRuntimeClass {
74
- identifier: string;
75
- fields: Fields;
76
- methods: Methods;
77
- mixins: string[];
78
- superclass?: string;
79
- constructor(identifier: string, fields: Fields, methods: Methods, mixins: string[], superclass?: string);
80
- }
81
- export declare function isRuntimeClass(val: PrimitiveValue): val is RuntimeClass;
82
- export interface IRuntimeObject {
83
- identifier: string;
84
- className: string;
85
- fields: Map<string, PrimitiveValue>;
86
- methods: Map<string, RuntimeFunction>;
87
- }
88
- export declare class RuntimeObject implements IRuntimeObject {
89
- identifier: string;
90
- className: string;
91
- fields: Fields;
92
- methods: Methods;
93
- constructor(identifier: string, className: string, fields: Fields, methods: Methods);
94
- }
95
- export declare function isRuntimeObject(val: PrimitiveValue): val is RuntimeObject;
96
- export type LazyGenerator = () => Generator<PrimitiveValue, void, unknown>;
97
- export interface ILazyList {
98
- readonly generator: LazyGenerator;
99
- }
100
- export declare class LazyList implements ILazyList {
101
- readonly generator: LazyGenerator;
102
- constructor(generator: LazyGenerator);
103
- }
104
- export declare function isLazyList(prim: unknown): prim is LazyList;
105
- export {};
@@ -1,96 +0,0 @@
1
- export function isLogicResult(value) {
2
- return (value &&
3
- typeof value === "object" &&
4
- "success" in value &&
5
- typeof value.success === "boolean" &&
6
- "solutions" in value &&
7
- value.solutions instanceof Map);
8
- }
9
- export class RuntimePredicate {
10
- kind;
11
- identifier;
12
- equations;
13
- constructor(kind, identifier, equations) {
14
- this.kind = kind;
15
- this.identifier = identifier;
16
- this.equations = equations;
17
- }
18
- pushEquation(eq) {
19
- this.equations.push(eq);
20
- }
21
- }
22
- // TODO: Replace with correct polymorphism
23
- export const isRuntimePredicate = (prim) => {
24
- return prim instanceof RuntimePredicate;
25
- };
26
- export class RuntimeEquation {
27
- patterns;
28
- body;
29
- constructor(patterns, body) {
30
- this.patterns = patterns;
31
- this.body = body;
32
- }
33
- }
34
- export class RuntimeFunction {
35
- arity;
36
- identifier;
37
- equations;
38
- pendingArgs;
39
- closure;
40
- constructor(arity, identifier, equations, pendingArgs, closure) {
41
- this.arity = arity;
42
- this.identifier = identifier;
43
- this.equations = equations;
44
- this.pendingArgs = pendingArgs;
45
- this.closure = closure;
46
- }
47
- setPendingArgs(args) {
48
- this.pendingArgs = args;
49
- }
50
- }
51
- // TODO: Replace with correct polymorphism
52
- export function isRuntimeFunction(val) {
53
- return val instanceof RuntimeFunction;
54
- }
55
- export class RuntimeClass {
56
- identifier;
57
- fields;
58
- methods;
59
- mixins;
60
- superclass;
61
- constructor(identifier, fields, methods, mixins, superclass) {
62
- this.identifier = identifier;
63
- this.fields = fields;
64
- this.methods = methods;
65
- this.mixins = mixins;
66
- this.superclass = superclass;
67
- }
68
- }
69
- // TODO: prev as before
70
- export function isRuntimeClass(val) {
71
- return val instanceof RuntimeClass;
72
- }
73
- export class RuntimeObject {
74
- identifier;
75
- className;
76
- fields;
77
- methods;
78
- constructor(identifier, className, fields, methods) {
79
- this.identifier = identifier;
80
- this.className = className;
81
- this.fields = fields;
82
- this.methods = methods;
83
- }
84
- }
85
- export function isRuntimeObject(val) {
86
- return val instanceof RuntimeObject;
87
- }
88
- export class LazyList {
89
- generator;
90
- constructor(generator) {
91
- this.generator = generator;
92
- }
93
- }
94
- export function isLazyList(prim) {
95
- return prim instanceof LazyList;
96
- }
@@ -1,17 +0,0 @@
1
- import { PrimitiveValue } from "yukigo-ast";
2
- export type CallableThunk<T> = () => Thunk<T>;
3
- export type Thunk<T> = T | CallableThunk<T>;
4
- export type Continuation<T, R = any> = (value: T) => Thunk<R>;
5
- export declare const idContinuation: Continuation<PrimitiveValue>;
6
- export declare function trampoline<T>(thunk: Thunk<T>): T;
7
- /**
8
- * A specialized Thunk type for our CPS visitor.
9
- * This is a function that, when called, takes the continuation for the current node's evaluation
10
- * and returns the actual Thunk chain for that node.
11
- * This effectively injects the continuation *after* the `visit` method has returned.
12
- */
13
- export type CPSThunk<T, R = any> = (k: Continuation<T, R>) => Thunk<R>;
14
- export declare function makeCPSThunk<T>(fn: (k: Continuation<T>) => Thunk<T>): CPSThunk<T>;
15
- export declare function bindCPS<A, B, R>(cpsA: CPSThunk<A, R>, f: (valueA: A) => CPSThunk<B, R>): CPSThunk<B, R>;
16
- export declare function valueToCPS<T, R>(value: T): CPSThunk<T, R>;
17
- export declare function thunkToCPS<T>(thunk: Thunk<T>): CPSThunk<T>;
@@ -1,38 +0,0 @@
1
- const isCallableThunk = (thunk) => typeof thunk === "function";
2
- // The identity continuation: simply returns the value as a resolved Thunk.
3
- // This is used for the very last step of a computation or when a value is final.
4
- export const idContinuation = (value) => value;
5
- // The trampoline function executes a chain of Thunks until a final non-function value is reached.
6
- export function trampoline(thunk) {
7
- let result = thunk;
8
- while (isCallableThunk(result))
9
- result = result();
10
- return result;
11
- }
12
- // Helper to create a CPSThunk for visitor methods.
13
- // Visitor methods will call this, providing a function that knows how to use 'k'.
14
- export function makeCPSThunk(fn) {
15
- return fn;
16
- }
17
- // Helper to compose asynchronous/CPS operations.
18
- // `cpsA` is a CPSThunk that eventually produces a value A.
19
- // `f` is a function that takes A and returns a CPSThunk that eventually produces B.
20
- export function bindCPS(cpsA, f) {
21
- return (k) => {
22
- return () => cpsA((valueA) => {
23
- // f(valueA) returns a CPSThunk<B, R>
24
- // calling that with 'k' returns Thunk<R>
25
- return f(valueA)(k);
26
- });
27
- };
28
- }
29
- // Helper to lift a direct value into a CPSThunk
30
- export function valueToCPS(value) {
31
- return (k) => () => k(value);
32
- }
33
- // Helper to lift a regular Thunk into a CPSThunk (if it resolves a simple Thunk)
34
- export function thunkToCPS(thunk) {
35
- return (k) => {
36
- return () => k(trampoline(thunk)); // Trampoline the simple thunk and pass its result to k
37
- };
38
- }
@@ -1,30 +0,0 @@
1
- import { Application, AST, ASTNode, Call, Class, Fact, Function, Interface, Method, New, Object as YuObject, Procedure, Rule, TraverseVisitor, TypeAlias, TypeSignature, Exist } from "yukigo-ast";
2
- type DefinitionMap = Map<string, ASTNode[]>;
3
- type CallsMap = Map<string, string[]>;
4
- export type SymbolGraph = {
5
- defs: DefinitionMap;
6
- calls: CallsMap;
7
- };
8
- export declare class GraphBuilder extends TraverseVisitor {
9
- private defs;
10
- private calls;
11
- private scope;
12
- build(ast: AST): SymbolGraph;
13
- private addDefinition;
14
- visitFunction(node: Function): void;
15
- visitMethod(node: Method): void;
16
- visitProcedure(node: Procedure): void;
17
- visitRule(node: Rule): void;
18
- visitFact(node: Fact): void;
19
- visitClass(node: Class): void;
20
- visitObject(node: YuObject): void;
21
- visitInterface(node: Interface): void;
22
- visitTypeAlias(node: TypeAlias): void;
23
- visitTypeSignature(node: TypeSignature): void;
24
- visitCall(node: Call): void;
25
- visitApplication(node: Application): void;
26
- visitNew(node: New): void;
27
- visitExist(node: Exist): void;
28
- fallback(node: ASTNode): void;
29
- }
30
- export {};
@@ -1,100 +0,0 @@
1
- import { SymbolPrimitive, TraverseVisitor, } from "yukigo-ast";
2
- export class GraphBuilder extends TraverseVisitor {
3
- defs = new Map();
4
- calls = new Map();
5
- scope = "";
6
- build(ast) {
7
- ast.forEach((node) => node.accept(this));
8
- return { defs: this.defs, calls: this.calls };
9
- }
10
- addDefinition(name, node) {
11
- const existing = this.defs.get(name) || [];
12
- this.defs.set(name, [...existing, node]);
13
- }
14
- visitFunction(node) {
15
- this.scope = node.identifier.value;
16
- this.addDefinition(this.scope, node);
17
- this.traverseCollection(node.equations);
18
- this.scope = "";
19
- }
20
- visitMethod(node) {
21
- this.scope = node.identifier.value;
22
- this.addDefinition(this.scope, node);
23
- this.traverseCollection(node.equations);
24
- this.scope = "";
25
- }
26
- visitProcedure(node) {
27
- this.scope = node.identifier.value;
28
- this.addDefinition(this.scope, node);
29
- this.traverseCollection(node.equations);
30
- this.scope = "";
31
- }
32
- visitRule(node) {
33
- this.scope = node.identifier.value;
34
- this.addDefinition(this.scope, node);
35
- this.traverseCollection(node.equations);
36
- this.scope = "";
37
- }
38
- visitFact(node) {
39
- this.scope = node.identifier.value;
40
- this.addDefinition(this.scope, node);
41
- this.traverseCollection(node.patterns);
42
- this.scope = "";
43
- }
44
- visitClass(node) {
45
- this.scope = node.identifier.value;
46
- this.addDefinition(this.scope, node);
47
- node.expression.accept(this);
48
- this.scope = "";
49
- }
50
- visitObject(node) {
51
- this.scope = node.identifier.value;
52
- this.addDefinition(this.scope, node);
53
- node.expression.accept(this);
54
- this.scope = "";
55
- }
56
- visitInterface(node) {
57
- this.scope = node.identifier.value;
58
- this.addDefinition(this.scope, node);
59
- node.expression.accept(this);
60
- this.scope = "";
61
- }
62
- visitTypeAlias(node) {
63
- this.scope = node.identifier.value;
64
- this.addDefinition(this.scope, node);
65
- this.scope = "";
66
- }
67
- visitTypeSignature(node) {
68
- this.scope = node.identifier.value;
69
- this.addDefinition(this.scope, node);
70
- this.scope = "";
71
- }
72
- visitCall(node) {
73
- if (!this.scope)
74
- return;
75
- const arr = this.calls.get(this.scope) || [];
76
- this.calls.set(this.scope, [node.callee.value, ...arr]);
77
- }
78
- visitApplication(node) {
79
- if (!this.scope)
80
- return;
81
- const arr = this.calls.get(this.scope) || [];
82
- if (node.functionExpr instanceof SymbolPrimitive)
83
- this.calls.set(this.scope, [node.functionExpr.value, ...arr]);
84
- else
85
- node.functionExpr.accept(this);
86
- }
87
- visitNew(node) {
88
- if (!this.scope)
89
- return;
90
- const arr = this.calls.get(this.scope) || [];
91
- this.calls.set(this.scope, [node.identifier.value, ...arr]);
92
- }
93
- visitExist(node) {
94
- if (!this.scope)
95
- return;
96
- const arr = this.calls.get(this.scope) || [];
97
- this.calls.set(this.scope, [node.identifier.value, ...arr]);
98
- }
99
- fallback(node) { }
100
- }
@@ -1,59 +0,0 @@
1
- import { AST } from "yukigo-ast";
2
- import { InspectionMap, VisitorConstructor } from "./utils.js";
3
- export type AnalysisResult = {
4
- rule: InspectionRule;
5
- passed: boolean;
6
- actual: boolean;
7
- error?: string;
8
- };
9
- export type InspectionRule = {
10
- inspection: string;
11
- binding?: string;
12
- args?: string[];
13
- expected: boolean;
14
- };
15
- export declare const DefaultInspectionSet: InspectionMap;
16
- export declare const DefaultSmellsSet: InspectionMap;
17
- /**
18
- * The Analyzer class.
19
- * @remarks
20
- * The Analyzer is the part of Yukigo which runs the inspections on the AST.s
21
- */
22
- export declare class Analyzer {
23
- /**
24
- * The set of inspections that are available for the Analyzer.
25
- * You can load your set of inspections or leave the default one.
26
- * @defaultValue a default set of inspections for each supported paradigm
27
- */
28
- private inspectionConstructors;
29
- private smellsConstructors;
30
- constructor(inspectionSet?: InspectionMap, smellsSet?: InspectionMap);
31
- /**
32
- * Registers a new custom inspection handler after Analyzer was instantiated.
33
- * @param name The name of the inspection (e.g., "HasArithmetic").
34
- * @param visitorConstructor The constructor for the TraverseVisitor class.
35
- */
36
- registerInspection(name: string, visitorConstructor: VisitorConstructor): void;
37
- /**
38
- * Runs a list of inspection rules against the AST.
39
- * @param ast The parsed AST.
40
- * @param rules The array of inspection rules to run.
41
- * @returns An array of analysis results.
42
- * @example
43
- * const rules: InspectionRule[] = [
44
- * {
45
- * inspection: "HasBinding",
46
- * args: { name: "minimoEntre" },
47
- * expected: false,
48
- * },
49
- * {
50
- * inspection: "HasBinding",
51
- * args: { name: "squareList" },
52
- * expected: true,
53
- * }
54
- * ]
55
- * const analyzer = new ASTAnalyzer(ast);
56
- * const analysisResults = analyzer.analyze(expectations);
57
- */
58
- analyze(ast: AST, rules: InspectionRule[]): AnalysisResult[];
59
- }
@@ -1,152 +0,0 @@
1
- import { StopTraversalException } from "yukigo-ast";
2
- import { genericInspections } from "./inspections/generic/generic.js";
3
- import { functionalInspections } from "./inspections/functional/functional.js";
4
- import { logicInspections } from "./inspections/logic/logic.js";
5
- import { objectInspections } from "./inspections/object/object.js";
6
- import { imperativeInspections } from "./inspections/imperative/imperative.js";
7
- import { functionalSmells } from "./inspections/functional/smells.js";
8
- import { logicSmells } from "./inspections/logic/smells.js";
9
- import { objectSmells } from "./inspections/object/smells.js";
10
- import { imperativeSmells } from "./inspections/imperative/smells.js";
11
- import { genericSmells } from "./inspections/generic/smells.js";
12
- import { GraphBuilder } from "./GraphBuilder.js";
13
- export const DefaultInspectionSet = {
14
- ...genericInspections,
15
- ...functionalInspections,
16
- ...logicInspections,
17
- ...objectInspections,
18
- ...imperativeInspections,
19
- };
20
- export const DefaultSmellsSet = {
21
- ...genericSmells,
22
- ...functionalSmells,
23
- ...logicSmells,
24
- ...objectSmells,
25
- ...imperativeSmells,
26
- };
27
- /**
28
- * The Analyzer class.
29
- * @remarks
30
- * The Analyzer is the part of Yukigo which runs the inspections on the AST.s
31
- */
32
- export class Analyzer {
33
- /**
34
- * The set of inspections that are available for the Analyzer.
35
- * You can load your set of inspections or leave the default one.
36
- * @defaultValue a default set of inspections for each supported paradigm
37
- */
38
- inspectionConstructors = {};
39
- smellsConstructors = {};
40
- constructor(inspectionSet, smellsSet) {
41
- this.inspectionConstructors = inspectionSet ?? DefaultInspectionSet;
42
- this.smellsConstructors = smellsSet ?? DefaultSmellsSet;
43
- }
44
- /**
45
- * Registers a new custom inspection handler after Analyzer was instantiated.
46
- * @param name The name of the inspection (e.g., "HasArithmetic").
47
- * @param visitorConstructor The constructor for the TraverseVisitor class.
48
- */
49
- registerInspection(name, visitorConstructor) {
50
- this.inspectionConstructors[name] = visitorConstructor;
51
- }
52
- /**
53
- * Runs a list of inspection rules against the AST.
54
- * @param ast The parsed AST.
55
- * @param rules The array of inspection rules to run.
56
- * @returns An array of analysis results.
57
- * @example
58
- * const rules: InspectionRule[] = [
59
- * {
60
- * inspection: "HasBinding",
61
- * args: { name: "minimoEntre" },
62
- * expected: false,
63
- * },
64
- * {
65
- * inspection: "HasBinding",
66
- * args: { name: "squareList" },
67
- * expected: true,
68
- * }
69
- * ]
70
- * const analyzer = new ASTAnalyzer(ast);
71
- * const analysisResults = analyzer.analyze(expectations);
72
- */
73
- analyze(ast, rules) {
74
- const ruleResults = new Map();
75
- const graphBuilder = new GraphBuilder();
76
- const { defs, calls } = graphBuilder.build(ast);
77
- for (const rule of rules) {
78
- let inspectionName = rule.inspection;
79
- let isTransitive = true;
80
- if (inspectionName.startsWith("Intransitive:")) {
81
- isTransitive = false;
82
- inspectionName = inspectionName.replace("Intransitive:", "");
83
- }
84
- const InspectionClass = this.inspectionConstructors[inspectionName];
85
- if (!InspectionClass) {
86
- ruleResults.set(rule, {
87
- rule,
88
- passed: false,
89
- actual: false,
90
- error: "Unknown inspection: " + inspectionName,
91
- });
92
- continue;
93
- }
94
- if (InspectionClass.IS_INTRANSITIVE)
95
- isTransitive = false;
96
- let targets = [];
97
- // Case 1: Global Inspection (No binding or wildcard)
98
- if (!rule.binding || rule.binding === "*") {
99
- targets = ast.map((n) => ({ node: n, binding: undefined }));
100
- }
101
- // Case 2: Directed Inspection (Specific binding)
102
- else {
103
- const workList = [rule.binding];
104
- const visited = new Set();
105
- while (workList.length > 0) {
106
- const currentBinding = workList.shift();
107
- if (!currentBinding || visited.has(currentBinding))
108
- continue;
109
- visited.add(currentBinding);
110
- const node = defs.get(currentBinding);
111
- if (node)
112
- node.forEach((n) => targets.push({ node: n, binding: currentBinding }));
113
- if (isTransitive) {
114
- const deps = calls.get(currentBinding) || [];
115
- workList.push(...deps);
116
- }
117
- }
118
- }
119
- let actual = false;
120
- let error = undefined;
121
- // Execution Loop
122
- const isGlobalVisitor = !rule.binding || rule.binding === "*";
123
- const normalizedBinding = isGlobalVisitor ? undefined : rule.binding;
124
- const args = rule.args ?? [];
125
- const visitor = new InspectionClass(...args, normalizedBinding);
126
- for (const { node, binding } of targets) {
127
- try {
128
- if (!isGlobalVisitor && visitor.setBinding && binding) {
129
- visitor.setBinding(binding);
130
- }
131
- node.accept(visitor);
132
- }
133
- catch (e) {
134
- if (e instanceof StopTraversalException) {
135
- actual = true;
136
- break; // Short-circuit: Rule passed
137
- }
138
- else {
139
- error = e.message;
140
- }
141
- }
142
- }
143
- ruleResults.set(rule, {
144
- rule,
145
- passed: actual === rule.expected,
146
- actual,
147
- error,
148
- });
149
- }
150
- return [...ruleResults.values()];
151
- }
152
- }
@@ -1,44 +0,0 @@
1
- import * as Yu from "yukigo-ast";
2
- import { VisitorConstructor, ScopedVisitor } from "../../utils.js";
3
- export declare class UsesComposition extends ScopedVisitor {
4
- constructor(scope?: string);
5
- visitCompositionExpression(node: Yu.CompositionExpression): void;
6
- }
7
- export declare class UsesAnonymousVariable extends ScopedVisitor {
8
- constructor(scope?: string);
9
- visitWildcardPattern(node: Yu.WildcardPattern): void;
10
- }
11
- export declare class UsesComprehension extends ScopedVisitor {
12
- constructor(scope?: string);
13
- visitListComprehension(node: Yu.ListComprehension): void;
14
- }
15
- export declare class UsesGuards extends ScopedVisitor {
16
- constructor(scope?: string);
17
- visitGuardedBody(node: Yu.GuardedBody): void;
18
- }
19
- export declare class UsesOtherwise extends ScopedVisitor {
20
- constructor(scope?: string);
21
- visitOtherwise(node: Yu.Otherwise): void;
22
- }
23
- export declare class UsesLambda extends ScopedVisitor {
24
- constructor(scope?: string);
25
- visitLambda(node: Yu.Lambda): void;
26
- }
27
- export declare class UsesYield extends ScopedVisitor {
28
- constructor(scope?: string);
29
- visitYield(node: Yu.Yield): void;
30
- }
31
- export declare class UsesPatternMatching extends ScopedVisitor {
32
- constructor(scope?: string);
33
- visitConsPattern(node: Yu.ConsPattern): void;
34
- visitAsPattern(node: Yu.AsPattern): void;
35
- visitListPattern(node: Yu.ListPattern): void;
36
- visitTuplePattern(node: Yu.TuplePattern): void;
37
- visitLiteralPattern(node: Yu.LiteralPattern): void;
38
- visitApplicationPattern(node: Yu.ApplicationPattern): void;
39
- visitConstructorPattern(node: Yu.ConstructorPattern): void;
40
- visitUnionPattern(node: Yu.UnionPattern): void;
41
- visitFunctorPattern(node: Yu.FunctorPattern): void;
42
- visitWildcardPattern(node: Yu.WildcardPattern): void;
43
- }
44
- export declare const functionalInspections: Record<string, VisitorConstructor>;