@jhlagado/azm 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 (301) hide show
  1. package/LICENSE +649 -0
  2. package/README.md +142 -0
  3. package/dist/src/analysis.d.ts +11 -0
  4. package/dist/src/analysis.js +41 -0
  5. package/dist/src/api-compile.d.ts +8 -0
  6. package/dist/src/api-compile.js +3 -0
  7. package/dist/src/api-tooling.d.ts +25 -0
  8. package/dist/src/api-tooling.js +21 -0
  9. package/dist/src/cli.d.ts +30 -0
  10. package/dist/src/cli.js +523 -0
  11. package/dist/src/compile.d.ts +10 -0
  12. package/dist/src/compile.js +175 -0
  13. package/dist/src/compileShared.d.ts +3 -0
  14. package/dist/src/compileShared.js +7 -0
  15. package/dist/src/diagnosticTypes.d.ts +77 -0
  16. package/dist/src/diagnosticTypes.js +53 -0
  17. package/dist/src/formats/index.d.ts +7 -0
  18. package/dist/src/formats/index.js +17 -0
  19. package/dist/src/formats/range.d.ts +17 -0
  20. package/dist/src/formats/range.js +45 -0
  21. package/dist/src/formats/types.d.ts +208 -0
  22. package/dist/src/formats/types.js +1 -0
  23. package/dist/src/formats/writeAsm80.d.ts +6 -0
  24. package/dist/src/formats/writeAsm80.js +86 -0
  25. package/dist/src/formats/writeBin.d.ts +7 -0
  26. package/dist/src/formats/writeBin.js +23 -0
  27. package/dist/src/formats/writeD8m.d.ts +9 -0
  28. package/dist/src/formats/writeD8m.js +239 -0
  29. package/dist/src/formats/writeHex.d.ts +9 -0
  30. package/dist/src/formats/writeHex.js +39 -0
  31. package/dist/src/formats/writeListing.d.ts +8 -0
  32. package/dist/src/formats/writeListing.js +83 -0
  33. package/dist/src/frontend/asm80/asmLine.d.ts +39 -0
  34. package/dist/src/frontend/asm80/asmLine.js +89 -0
  35. package/dist/src/frontend/asm80/parseAsmRawValues.d.ts +4 -0
  36. package/dist/src/frontend/asm80/parseAsmRawValues.js +94 -0
  37. package/dist/src/frontend/asm80/quoteScan.d.ts +10 -0
  38. package/dist/src/frontend/asm80/quoteScan.js +25 -0
  39. package/dist/src/frontend/ast.d.ts +376 -0
  40. package/dist/src/frontend/ast.js +1 -0
  41. package/dist/src/frontend/directiveAliases.d.ts +14 -0
  42. package/dist/src/frontend/directiveAliases.js +189 -0
  43. package/dist/src/frontend/grammarData.d.ts +14 -0
  44. package/dist/src/frontend/grammarData.js +65 -0
  45. package/dist/src/frontend/immExprUtils.d.ts +2 -0
  46. package/dist/src/frontend/immExprUtils.js +12 -0
  47. package/dist/src/frontend/parseAsmFlatDirectiveLine.d.ts +17 -0
  48. package/dist/src/frontend/parseAsmFlatDirectiveLine.js +187 -0
  49. package/dist/src/frontend/parseAsmInstruction.d.ts +3 -0
  50. package/dist/src/frontend/parseAsmInstruction.js +73 -0
  51. package/dist/src/frontend/parseAsmStatements.d.ts +6 -0
  52. package/dist/src/frontend/parseAsmStatements.js +16 -0
  53. package/dist/src/frontend/parseAsmStream.d.ts +10 -0
  54. package/dist/src/frontend/parseAsmStream.js +33 -0
  55. package/dist/src/frontend/parseAsmTopLevel.d.ts +18 -0
  56. package/dist/src/frontend/parseAsmTopLevel.js +34 -0
  57. package/dist/src/frontend/parseDiagnostics.d.ts +9 -0
  58. package/dist/src/frontend/parseDiagnostics.js +16 -0
  59. package/dist/src/frontend/parseEnum.d.ts +12 -0
  60. package/dist/src/frontend/parseEnum.js +70 -0
  61. package/dist/src/frontend/parseImm.d.ts +10 -0
  62. package/dist/src/frontend/parseImm.js +397 -0
  63. package/dist/src/frontend/parseLogicalLines.d.ts +11 -0
  64. package/dist/src/frontend/parseLogicalLines.js +94 -0
  65. package/dist/src/frontend/parseOp.d.ts +25 -0
  66. package/dist/src/frontend/parseOp.js +120 -0
  67. package/dist/src/frontend/parseOpHeader.d.ts +20 -0
  68. package/dist/src/frontend/parseOpHeader.js +32 -0
  69. package/dist/src/frontend/parseOperands.d.ts +4 -0
  70. package/dist/src/frontend/parseOperands.js +290 -0
  71. package/dist/src/frontend/parseParams.d.ts +6 -0
  72. package/dist/src/frontend/parseParams.js +62 -0
  73. package/dist/src/frontend/parseParserRecovery.d.ts +12 -0
  74. package/dist/src/frontend/parseParserRecovery.js +17 -0
  75. package/dist/src/frontend/parseParserShared.d.ts +2 -0
  76. package/dist/src/frontend/parseParserShared.js +8 -0
  77. package/dist/src/frontend/parseRawDataDirectiveStart.d.ts +1 -0
  78. package/dist/src/frontend/parseRawDataDirectiveStart.js +3 -0
  79. package/dist/src/frontend/parseRawDataDirectives.d.ts +7 -0
  80. package/dist/src/frontend/parseRawDataDirectives.js +142 -0
  81. package/dist/src/frontend/parseRecordFieldDecl.d.ts +34 -0
  82. package/dist/src/frontend/parseRecordFieldDecl.js +177 -0
  83. package/dist/src/frontend/parseSourceItemDispatch.d.ts +46 -0
  84. package/dist/src/frontend/parseSourceItemDispatch.js +53 -0
  85. package/dist/src/frontend/parseSourceItemTable.d.ts +16 -0
  86. package/dist/src/frontend/parseSourceItemTable.js +68 -0
  87. package/dist/src/frontend/parseTopLevelCommon.d.ts +11 -0
  88. package/dist/src/frontend/parseTopLevelCommon.js +50 -0
  89. package/dist/src/frontend/parseTypes.d.ts +24 -0
  90. package/dist/src/frontend/parseTypes.js +77 -0
  91. package/dist/src/frontend/parser.d.ts +11 -0
  92. package/dist/src/frontend/parser.js +88 -0
  93. package/dist/src/frontend/source.d.ts +28 -0
  94. package/dist/src/frontend/source.js +58 -0
  95. package/dist/src/frontend/sourceExtensions.d.ts +2 -0
  96. package/dist/src/frontend/sourceExtensions.js +6 -0
  97. package/dist/src/index.d.ts +3 -0
  98. package/dist/src/index.js +2 -0
  99. package/dist/src/lintCaseStyle.d.ts +4 -0
  100. package/dist/src/lintCaseStyle.js +129 -0
  101. package/dist/src/lowering/asmDirectiveLowering.d.ts +4 -0
  102. package/dist/src/lowering/asmDirectiveLowering.js +229 -0
  103. package/dist/src/lowering/asmDirectiveTraversal.d.ts +47 -0
  104. package/dist/src/lowering/asmDirectiveTraversal.js +52 -0
  105. package/dist/src/lowering/asmEquResolution.d.ts +8 -0
  106. package/dist/src/lowering/asmEquResolution.js +69 -0
  107. package/dist/src/lowering/asmInstructionLdHelpers.d.ts +15 -0
  108. package/dist/src/lowering/asmInstructionLdHelpers.js +102 -0
  109. package/dist/src/lowering/asmInstructionLowering.d.ts +5 -0
  110. package/dist/src/lowering/asmInstructionLowering.js +54 -0
  111. package/dist/src/lowering/asmInstructionStream.d.ts +46 -0
  112. package/dist/src/lowering/asmInstructionStream.js +51 -0
  113. package/dist/src/lowering/asmLoweringBranchCall.d.ts +43 -0
  114. package/dist/src/lowering/asmLoweringBranchCall.js +254 -0
  115. package/dist/src/lowering/asmLoweringHost.d.ts +23 -0
  116. package/dist/src/lowering/asmLoweringHost.js +1 -0
  117. package/dist/src/lowering/asmLoweringLd.d.ts +28 -0
  118. package/dist/src/lowering/asmLoweringLd.js +144 -0
  119. package/dist/src/lowering/asmRangeLowering.d.ts +17 -0
  120. package/dist/src/lowering/asmRangeLowering.js +39 -0
  121. package/dist/src/lowering/asmRawDataLowering.d.ts +16 -0
  122. package/dist/src/lowering/asmRawDataLowering.js +209 -0
  123. package/dist/src/lowering/asmSourceEmitter.d.ts +4 -0
  124. package/dist/src/lowering/asmSourceEmitter.js +9 -0
  125. package/dist/src/lowering/asmSourceInstructionLowering.d.ts +4 -0
  126. package/dist/src/lowering/asmSourceInstructionLowering.js +14 -0
  127. package/dist/src/lowering/asmUtils.d.ts +13 -0
  128. package/dist/src/lowering/asmUtils.js +105 -0
  129. package/dist/src/lowering/assemblerFlowSetup.d.ts +54 -0
  130. package/dist/src/lowering/assemblerFlowSetup.js +128 -0
  131. package/dist/src/lowering/assemblerLoweringContext.d.ts +151 -0
  132. package/dist/src/lowering/assemblerLoweringContext.js +16 -0
  133. package/dist/src/lowering/assemblerLoweringContextSplit.d.ts +7 -0
  134. package/dist/src/lowering/assemblerLoweringContextSplit.js +75 -0
  135. package/dist/src/lowering/assemblerLoweringPhases.d.ts +66 -0
  136. package/dist/src/lowering/assemblerLoweringPhases.js +166 -0
  137. package/dist/src/lowering/bytePlacement.d.ts +7 -0
  138. package/dist/src/lowering/bytePlacement.js +37 -0
  139. package/dist/src/lowering/capabilities.d.ts +67 -0
  140. package/dist/src/lowering/capabilities.js +1 -0
  141. package/dist/src/lowering/eaResolution.d.ts +58 -0
  142. package/dist/src/lowering/eaResolution.js +159 -0
  143. package/dist/src/lowering/emissionCore.d.ts +17 -0
  144. package/dist/src/lowering/emissionCore.js +21 -0
  145. package/dist/src/lowering/emit.d.ts +17 -0
  146. package/dist/src/lowering/emit.js +46 -0
  147. package/dist/src/lowering/emitContextBuilder.d.ts +63 -0
  148. package/dist/src/lowering/emitContextBuilder.js +41 -0
  149. package/dist/src/lowering/emitFinalization.d.ts +61 -0
  150. package/dist/src/lowering/emitFinalization.js +66 -0
  151. package/dist/src/lowering/emitFinalizationSetup.d.ts +19 -0
  152. package/dist/src/lowering/emitFinalizationSetup.js +26 -0
  153. package/dist/src/lowering/emitPhase1BuildProgramLoweringContext.d.ts +7 -0
  154. package/dist/src/lowering/emitPhase1BuildProgramLoweringContext.js +119 -0
  155. package/dist/src/lowering/emitPhase1Helpers.d.ts +4 -0
  156. package/dist/src/lowering/emitPhase1Helpers.js +12 -0
  157. package/dist/src/lowering/emitPhase1Types.d.ts +21 -0
  158. package/dist/src/lowering/emitPhase1Types.js +1 -0
  159. package/dist/src/lowering/emitPhase1WirePipeline.d.ts +70 -0
  160. package/dist/src/lowering/emitPhase1WirePipeline.js +203 -0
  161. package/dist/src/lowering/emitPhase1Workspace.d.ts +82 -0
  162. package/dist/src/lowering/emitPhase1Workspace.js +55 -0
  163. package/dist/src/lowering/emitPipeline.d.ts +121 -0
  164. package/dist/src/lowering/emitPipeline.js +57 -0
  165. package/dist/src/lowering/emitProgramContext.d.ts +39 -0
  166. package/dist/src/lowering/emitProgramContext.js +29 -0
  167. package/dist/src/lowering/emitState.d.ts +90 -0
  168. package/dist/src/lowering/emitState.js +124 -0
  169. package/dist/src/lowering/fixupBaseResolution.d.ts +7 -0
  170. package/dist/src/lowering/fixupBaseResolution.js +23 -0
  171. package/dist/src/lowering/fixupEmission.d.ts +64 -0
  172. package/dist/src/lowering/fixupEmission.js +199 -0
  173. package/dist/src/lowering/immMath.d.ts +2 -0
  174. package/dist/src/lowering/immMath.js +34 -0
  175. package/dist/src/lowering/inputAssets.d.ts +7 -0
  176. package/dist/src/lowering/inputAssets.js +106 -0
  177. package/dist/src/lowering/ldEncoding.d.ts +15 -0
  178. package/dist/src/lowering/ldEncoding.js +12 -0
  179. package/dist/src/lowering/ldEncodingRegMemHelpers.d.ts +5 -0
  180. package/dist/src/lowering/ldEncodingRegMemHelpers.js +124 -0
  181. package/dist/src/lowering/ldFormSelection.d.ts +26 -0
  182. package/dist/src/lowering/ldFormSelection.js +92 -0
  183. package/dist/src/lowering/ldLowering.d.ts +7 -0
  184. package/dist/src/lowering/ldLowering.js +13 -0
  185. package/dist/src/lowering/loweredAsmByteEmission.d.ts +23 -0
  186. package/dist/src/lowering/loweredAsmByteEmission.js +185 -0
  187. package/dist/src/lowering/loweredAsmPlacement.d.ts +13 -0
  188. package/dist/src/lowering/loweredAsmPlacement.js +86 -0
  189. package/dist/src/lowering/loweredAsmStreamRecording.d.ts +27 -0
  190. package/dist/src/lowering/loweredAsmStreamRecording.js +215 -0
  191. package/dist/src/lowering/loweredAsmTypes.d.ts +202 -0
  192. package/dist/src/lowering/loweredAsmTypes.js +1 -0
  193. package/dist/src/lowering/loweredFormat.d.ts +3 -0
  194. package/dist/src/lowering/loweredFormat.js +26 -0
  195. package/dist/src/lowering/loweredItemSize.d.ts +4 -0
  196. package/dist/src/lowering/loweredItemSize.js +17 -0
  197. package/dist/src/lowering/loweringDiagnostics.d.ts +9 -0
  198. package/dist/src/lowering/loweringDiagnostics.js +55 -0
  199. package/dist/src/lowering/loweringTypes.d.ts +27 -0
  200. package/dist/src/lowering/loweringTypes.js +1 -0
  201. package/dist/src/lowering/opCandidateRegistry.d.ts +9 -0
  202. package/dist/src/lowering/opCandidateRegistry.js +9 -0
  203. package/dist/src/lowering/opExpansionExecution.d.ts +15 -0
  204. package/dist/src/lowering/opExpansionExecution.js +45 -0
  205. package/dist/src/lowering/opExpansionOrchestration.d.ts +15 -0
  206. package/dist/src/lowering/opExpansionOrchestration.js +88 -0
  207. package/dist/src/lowering/opExpansionStream.d.ts +12 -0
  208. package/dist/src/lowering/opExpansionStream.js +176 -0
  209. package/dist/src/lowering/opMatching.d.ts +52 -0
  210. package/dist/src/lowering/opMatching.js +355 -0
  211. package/dist/src/lowering/opSubstitution.d.ts +13 -0
  212. package/dist/src/lowering/opSubstitution.js +175 -0
  213. package/dist/src/lowering/prescanTypes.d.ts +7 -0
  214. package/dist/src/lowering/prescanTypes.js +1 -0
  215. package/dist/src/lowering/programLowering.d.ts +144 -0
  216. package/dist/src/lowering/programLowering.js +2 -0
  217. package/dist/src/lowering/programLoweringDeclarations.d.ts +5 -0
  218. package/dist/src/lowering/programLoweringDeclarations.js +5 -0
  219. package/dist/src/lowering/programLoweringFinalize.d.ts +18 -0
  220. package/dist/src/lowering/programLoweringFinalize.js +115 -0
  221. package/dist/src/lowering/programLoweringTraversal.d.ts +2 -0
  222. package/dist/src/lowering/programLoweringTraversal.js +93 -0
  223. package/dist/src/lowering/programPrescan.d.ts +3 -0
  224. package/dist/src/lowering/programPrescan.js +37 -0
  225. package/dist/src/lowering/traceFormat.d.ts +13 -0
  226. package/dist/src/lowering/traceFormat.js +211 -0
  227. package/dist/src/pathCompare.d.ts +3 -0
  228. package/dist/src/pathCompare.js +26 -0
  229. package/dist/src/pipeline.d.ts +78 -0
  230. package/dist/src/pipeline.js +1 -0
  231. package/dist/src/registerCare/analyze.d.ts +24 -0
  232. package/dist/src/registerCare/analyze.js +327 -0
  233. package/dist/src/registerCare/annotate.d.ts +11 -0
  234. package/dist/src/registerCare/annotate.js +76 -0
  235. package/dist/src/registerCare/boundaryHints.d.ts +2 -0
  236. package/dist/src/registerCare/boundaryHints.js +10 -0
  237. package/dist/src/registerCare/carriers.d.ts +4 -0
  238. package/dist/src/registerCare/carriers.js +78 -0
  239. package/dist/src/registerCare/controlFlow.d.ts +5 -0
  240. package/dist/src/registerCare/controlFlow.js +35 -0
  241. package/dist/src/registerCare/fix.d.ts +11 -0
  242. package/dist/src/registerCare/fix.js +119 -0
  243. package/dist/src/registerCare/liveness.d.ts +7 -0
  244. package/dist/src/registerCare/liveness.js +227 -0
  245. package/dist/src/registerCare/profiles.d.ts +11 -0
  246. package/dist/src/registerCare/profiles.js +45 -0
  247. package/dist/src/registerCare/programModel.d.ts +3 -0
  248. package/dist/src/registerCare/programModel.js +181 -0
  249. package/dist/src/registerCare/report.d.ts +5 -0
  250. package/dist/src/registerCare/report.js +139 -0
  251. package/dist/src/registerCare/smartComments.d.ts +5 -0
  252. package/dist/src/registerCare/smartComments.js +247 -0
  253. package/dist/src/registerCare/sourceText.d.ts +8 -0
  254. package/dist/src/registerCare/sourceText.js +15 -0
  255. package/dist/src/registerCare/summary.d.ts +3 -0
  256. package/dist/src/registerCare/summary.js +492 -0
  257. package/dist/src/registerCare/tooling.d.ts +42 -0
  258. package/dist/src/registerCare/tooling.js +50 -0
  259. package/dist/src/registerCare/types.d.ts +154 -0
  260. package/dist/src/registerCare/types.js +1 -0
  261. package/dist/src/semantics/declVisitor.d.ts +5 -0
  262. package/dist/src/semantics/declVisitor.js +11 -0
  263. package/dist/src/semantics/env.d.ts +28 -0
  264. package/dist/src/semantics/env.js +432 -0
  265. package/dist/src/semantics/layout.d.ts +21 -0
  266. package/dist/src/semantics/layout.js +226 -0
  267. package/dist/src/semantics/layoutCastFold.d.ts +22 -0
  268. package/dist/src/semantics/layoutCastFold.js +118 -0
  269. package/dist/src/semantics/semanticsDiagnostics.d.ts +2 -0
  270. package/dist/src/semantics/semanticsDiagnostics.js +4 -0
  271. package/dist/src/semantics/typeQueries.d.ts +31 -0
  272. package/dist/src/semantics/typeQueries.js +124 -0
  273. package/dist/src/sourceIncludeExpansion.d.ts +17 -0
  274. package/dist/src/sourceIncludeExpansion.js +124 -0
  275. package/dist/src/sourceIncludePaths.d.ts +1 -0
  276. package/dist/src/sourceIncludePaths.js +12 -0
  277. package/dist/src/sourceLoader.d.ts +15 -0
  278. package/dist/src/sourceLoader.js +118 -0
  279. package/dist/src/z80/effects.d.ts +3 -0
  280. package/dist/src/z80/effects.js +516 -0
  281. package/dist/src/z80/encode.d.ts +10 -0
  282. package/dist/src/z80/encode.js +412 -0
  283. package/dist/src/z80/encodeAlu.d.ts +7 -0
  284. package/dist/src/z80/encodeAlu.js +219 -0
  285. package/dist/src/z80/encodeBitOps.d.ts +7 -0
  286. package/dist/src/z80/encodeBitOps.js +123 -0
  287. package/dist/src/z80/encodeContext.d.ts +29 -0
  288. package/dist/src/z80/encodeContext.js +1 -0
  289. package/dist/src/z80/encodeControl.d.ts +26 -0
  290. package/dist/src/z80/encodeControl.js +180 -0
  291. package/dist/src/z80/encodeCoreOps.d.ts +7 -0
  292. package/dist/src/z80/encodeCoreOps.js +131 -0
  293. package/dist/src/z80/encodeIo.d.ts +9 -0
  294. package/dist/src/z80/encodeIo.js +128 -0
  295. package/dist/src/z80/encodeLd.d.ts +13 -0
  296. package/dist/src/z80/encodeLd.js +273 -0
  297. package/dist/src/z80/encoderRegistry.d.ts +13 -0
  298. package/dist/src/z80/encoderRegistry.js +169 -0
  299. package/docs/reference/cli.md +134 -0
  300. package/docs/reference/tooling-api.md +248 -0
  301. package/package.json +98 -0
@@ -0,0 +1,202 @@
1
+ import type { PlacementKind } from './loweringTypes.js';
2
+ export type LoweredAsmStream = {
3
+ /** Ordered blocks as emitted during lowering (pre-placement). */
4
+ blocks: LoweredAsmStreamBlock[];
5
+ };
6
+ export type LoweredAsmStreamBlock = {
7
+ /** Base placement chunk. */
8
+ kind: 'base';
9
+ /** Which logical placement this block belongs to. */
10
+ placement: PlacementKind;
11
+ /** Lowered items in emission order. */
12
+ items: LoweredAsmItem[];
13
+ };
14
+ export type LoweredAsmProgram = {
15
+ /** Blocks with assigned origins after placement. */
16
+ blocks: LoweredAsmBlock[];
17
+ /** Optional symbol table snapshot for listings. */
18
+ symbols?: LoweredAsmSymbol[];
19
+ };
20
+ export type LoweredAsmBlock = {
21
+ /** Placement-relative block vs absolute-origin blob. */
22
+ kind: 'placed' | 'absolute';
23
+ /** Base address for this block’s bytes. */
24
+ origin: number;
25
+ /** Code/data placement when `kind === 'placed'`. */
26
+ placement?: PlacementKind;
27
+ /** Lowered items. */
28
+ items: LoweredAsmItem[];
29
+ };
30
+ type LoweredAsmSymbol = {
31
+ /** Compile-time named constant. */
32
+ kind: 'constant';
33
+ /** Constant identifier text. */
34
+ name: string;
35
+ /** Folded imm expression. */
36
+ value: LoweredImmExpr;
37
+ } | {
38
+ /** Runtime label or reserved-data symbol. */
39
+ kind: 'label' | 'data' | 'unknown';
40
+ /** Symbol name. */
41
+ name: string;
42
+ /** Address expression (may reference other symbols). */
43
+ address: LoweredImmExpr;
44
+ };
45
+ export type LoweredAsmItem = {
46
+ kind: 'label';
47
+ /** Label name for this position. */
48
+ name: string;
49
+ } | {
50
+ kind: 'const';
51
+ /** Const name. */
52
+ name: string;
53
+ /** Const value expression. */
54
+ value: LoweredImmExpr;
55
+ } | {
56
+ kind: 'db';
57
+ /** Byte values. */
58
+ values: LoweredImmExpr[];
59
+ } | {
60
+ kind: 'dw';
61
+ /** Word values. */
62
+ values: LoweredImmExpr[];
63
+ } | {
64
+ kind: 'ds';
65
+ /** Reserve size in bytes. */
66
+ size: LoweredImmExpr;
67
+ /** Optional fill byte; omit for undefined fill. */
68
+ fill?: LoweredImmExpr;
69
+ } | {
70
+ kind: 'instr';
71
+ /** Mnemonic head token. */
72
+ head: string;
73
+ /** Rendered operands. */
74
+ operands: LoweredOperand[];
75
+ /** Encoded bytes when available; omit before encoding. */
76
+ bytes?: number[];
77
+ } | {
78
+ kind: 'comment';
79
+ /** Comment text. */
80
+ text: string;
81
+ /** User source comment vs compiler-generated trace. */
82
+ origin: 'user' | 'generated';
83
+ };
84
+ export type LoweredOperand = {
85
+ kind: 'reg';
86
+ /** Canonical register name. */
87
+ name: string;
88
+ } | {
89
+ kind: 'imm';
90
+ /** Immediate subexpression. */
91
+ expr: LoweredImmExpr;
92
+ } | {
93
+ kind: 'mem';
94
+ /** Memory EA expression. */
95
+ expr: LoweredEaExpr;
96
+ } | {
97
+ kind: 'ea';
98
+ /** Standalone EA operand. */
99
+ expr: LoweredEaExpr;
100
+ } | {
101
+ kind: 'portImm8';
102
+ /** 8-bit port immediate. */
103
+ expr: LoweredImmExpr;
104
+ } | {
105
+ /** `(C)` port form. */
106
+ kind: 'portC';
107
+ };
108
+ export type LoweredImmExpr = {
109
+ kind: 'literal';
110
+ /** Numeric literal value. */
111
+ value: number;
112
+ } | {
113
+ kind: 'symbol';
114
+ /** Symbol name (may be address-bearing). */
115
+ name: string;
116
+ /** Byte offset added to the symbol’s value. */
117
+ addend: number;
118
+ } | {
119
+ kind: 'unary';
120
+ /** Unary operator. */
121
+ op: '+' | '-' | '~';
122
+ /** Inner expression. */
123
+ expr: LoweredImmExpr;
124
+ } | {
125
+ kind: 'binary';
126
+ /** Binary operator. */
127
+ op: '*' | '/' | '%' | '+' | '-' | '&' | '^' | '|' | '<<' | '>>';
128
+ /** Left operand. */
129
+ left: LoweredImmExpr;
130
+ /** Right operand. */
131
+ right: LoweredImmExpr;
132
+ } | {
133
+ kind: 'opaque';
134
+ /** Unparsed / passthrough text for listing. */
135
+ text: string;
136
+ };
137
+ export type LoweredEaExpr = {
138
+ kind: 'name';
139
+ /** Identifier in an EA. */
140
+ name: string;
141
+ } | {
142
+ kind: 'imm';
143
+ /** Nested immediate. */
144
+ expr: LoweredImmExpr;
145
+ } | {
146
+ kind: 'layoutCast';
147
+ /** Target type name for the layout cast. */
148
+ typeName: string;
149
+ /** Base EA. */
150
+ base: LoweredEaExpr;
151
+ } | {
152
+ kind: 'field';
153
+ /** Record/union base. */
154
+ base: LoweredEaExpr;
155
+ /** Field name. */
156
+ field: string;
157
+ } | {
158
+ kind: 'index';
159
+ /** Array base. */
160
+ base: LoweredEaExpr;
161
+ /** Index selector. */
162
+ index: LoweredIndexExpr;
163
+ } | {
164
+ kind: 'add';
165
+ /** Base EA. */
166
+ base: LoweredEaExpr;
167
+ /** Positive offset imm. */
168
+ offset: LoweredImmExpr;
169
+ } | {
170
+ kind: 'sub';
171
+ /** Base EA. */
172
+ base: LoweredEaExpr;
173
+ /** Subtracted offset imm. */
174
+ offset: LoweredImmExpr;
175
+ };
176
+ export type LoweredIndexExpr = {
177
+ kind: 'imm';
178
+ /** Constant index expression. */
179
+ value: LoweredImmExpr;
180
+ } | {
181
+ kind: 'reg8';
182
+ /** 8-bit index register name. */
183
+ reg: string;
184
+ } | {
185
+ kind: 'reg16';
186
+ /** 16-bit index register name. */
187
+ reg: string;
188
+ } | {
189
+ /** `(HL)` addressing form. */
190
+ kind: 'memHL';
191
+ } | {
192
+ kind: 'memIxIy';
193
+ /** Which index register. */
194
+ base: 'IX' | 'IY';
195
+ /** Displacement; omit for 0. */
196
+ disp?: LoweredImmExpr;
197
+ } | {
198
+ kind: 'ea';
199
+ /** General EA used as index. */
200
+ expr: LoweredEaExpr;
201
+ };
202
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { LoweredImmExpr } from './loweredAsmTypes.js';
2
+ export declare const formatLoweredNumber: (value: number) => string;
3
+ export declare function formatLoweredImmExpr(expr: LoweredImmExpr): string;
@@ -0,0 +1,26 @@
1
+ const toHex = (value, width) => value.toString(16).toUpperCase().padStart(width, '0');
2
+ export const formatLoweredNumber = (value) => {
3
+ if (value < 0) {
4
+ const abs = Math.abs(value);
5
+ return `-$${toHex(abs, abs > 0xff ? 4 : 2)}`;
6
+ }
7
+ return `$${toHex(value, value > 0xff ? 4 : 2)}`;
8
+ };
9
+ export function formatLoweredImmExpr(expr) {
10
+ switch (expr.kind) {
11
+ case 'literal':
12
+ return formatLoweredNumber(expr.value);
13
+ case 'symbol': {
14
+ if (expr.addend === 0)
15
+ return expr.name;
16
+ const addend = formatLoweredNumber(Math.abs(expr.addend));
17
+ return expr.addend > 0 ? `${expr.name}+${addend}` : `${expr.name}-${addend}`;
18
+ }
19
+ case 'unary':
20
+ return `${expr.op}${formatLoweredImmExpr(expr.expr)}`;
21
+ case 'binary':
22
+ return `(${formatLoweredImmExpr(expr.left)} ${expr.op} ${formatLoweredImmExpr(expr.right)})`;
23
+ case 'opaque':
24
+ return expr.text;
25
+ }
26
+ }
@@ -0,0 +1,4 @@
1
+ import type { LoweredAsmItem, LoweredImmExpr } from './loweredAsmTypes.js';
2
+ type LoweredSizeEvaluator = (expr: LoweredImmExpr) => number | undefined;
3
+ export declare function loweredItemSize(item: LoweredAsmItem, evalSize?: LoweredSizeEvaluator): number;
4
+ export {};
@@ -0,0 +1,17 @@
1
+ const literalSize = (expr) => expr.kind === 'literal' ? expr.value : undefined;
2
+ export function loweredItemSize(item, evalSize = literalSize) {
3
+ switch (item.kind) {
4
+ case 'label':
5
+ case 'const':
6
+ case 'comment':
7
+ return 0;
8
+ case 'db':
9
+ return item.values.length;
10
+ case 'dw':
11
+ return item.values.length * 2;
12
+ case 'ds':
13
+ return Math.max(0, evalSize(item.size) ?? 0);
14
+ case 'instr':
15
+ return item.bytes?.length ?? 0;
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import type { Diagnostic, DiagnosticId } from '../diagnosticTypes.js';
2
+ import type { SourceSpan } from '../frontend/ast.js';
3
+ export declare function diag(diagnostics: Diagnostic[], file: string, message: string): void;
4
+ /** Encoder-time diagnostic with stable {@link DiagnosticIds.EncodeError} id and source span. */
5
+ export declare function diagEncodeAt(diagnostics: Diagnostic[], span: SourceSpan, message: string): void;
6
+ export declare function diagAt(diagnostics: Diagnostic[], span: SourceSpan, message: string): void;
7
+ export declare function diagAtWithId(diagnostics: Diagnostic[], span: SourceSpan, id: DiagnosticId, message: string): void;
8
+ export declare function diagAtWithSeverityAndId(diagnostics: Diagnostic[], span: SourceSpan, id: DiagnosticId, severity: 'error' | 'warning', message: string): void;
9
+ export declare function warnAt(diagnostics: Diagnostic[], span: SourceSpan, message: string): void;
@@ -0,0 +1,55 @@
1
+ import { DiagnosticIds } from '../diagnosticTypes.js';
2
+ export function diag(diagnostics, file, message) {
3
+ diagnostics.push({ id: DiagnosticIds.EmitError, severity: 'error', message, file });
4
+ }
5
+ /** Encoder-time diagnostic with stable {@link DiagnosticIds.EncodeError} id and source span. */
6
+ export function diagEncodeAt(diagnostics, span, message) {
7
+ diagnostics.push({
8
+ id: DiagnosticIds.EncodeError,
9
+ severity: 'error',
10
+ message,
11
+ file: span.file,
12
+ line: span.start.line,
13
+ column: span.start.column,
14
+ });
15
+ }
16
+ export function diagAt(diagnostics, span, message) {
17
+ diagnostics.push({
18
+ id: DiagnosticIds.EmitError,
19
+ severity: 'error',
20
+ message,
21
+ file: span.file,
22
+ line: span.start.line,
23
+ column: span.start.column,
24
+ });
25
+ }
26
+ export function diagAtWithId(diagnostics, span, id, message) {
27
+ diagnostics.push({
28
+ id,
29
+ severity: 'error',
30
+ message,
31
+ file: span.file,
32
+ line: span.start.line,
33
+ column: span.start.column,
34
+ });
35
+ }
36
+ export function diagAtWithSeverityAndId(diagnostics, span, id, severity, message) {
37
+ diagnostics.push({
38
+ id,
39
+ severity,
40
+ message,
41
+ file: span.file,
42
+ line: span.start.line,
43
+ column: span.start.column,
44
+ });
45
+ }
46
+ export function warnAt(diagnostics, span, message) {
47
+ diagnostics.push({
48
+ id: DiagnosticIds.EmitWarning,
49
+ severity: 'warning',
50
+ message,
51
+ file: span.file,
52
+ line: span.start.line,
53
+ column: span.start.column,
54
+ });
55
+ }
@@ -0,0 +1,27 @@
1
+ import type { TypeExprNode } from '../frontend/ast.js';
2
+ import type { EmittedSourceSegment } from '../formats/types.js';
3
+ export type PlacementKind = 'code' | 'data';
4
+ export type PendingSymbol = {
5
+ /** What kind of symbol is pending resolution. */
6
+ kind: 'label' | 'data';
7
+ /** Declared name (not yet bound to an address). */
8
+ name: string;
9
+ /** Target placement for the symbol. */
10
+ placement: PlacementKind;
11
+ /** Tentative offset within the placement; refined at finalize. */
12
+ offset: number;
13
+ /** Source file when known; omit for synthetic entries. */
14
+ file?: string;
15
+ /** 1-based source line when known. */
16
+ line?: number;
17
+ /** Local vs global source scope when applicable. */
18
+ scope?: 'global' | 'local';
19
+ /** Byte size for data when known. */
20
+ size?: number;
21
+ };
22
+ export type SourceSegmentTag = Omit<EmittedSourceSegment, 'start' | 'end'>;
23
+ /** Array shape extracted for lowering; `length` omitted when unknown. */
24
+ export type ResolvedArrayType = {
25
+ element: TypeExprNode;
26
+ length?: number;
27
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { OpDeclNode } from '../frontend/ast.js';
2
+ type OpCandidateRegistryContext = {
3
+ /** Per-file op overload lists keyed by lowercased op name. */
4
+ localOpsByFile: Map<string, Map<string, OpDeclNode[]>>;
5
+ };
6
+ export declare function createOpCandidateRegistryHelpers(ctx: OpCandidateRegistryContext): {
7
+ resolveOpCandidatesForFile: (name: string, file: string) => OpDeclNode[] | undefined;
8
+ };
9
+ export {};
@@ -0,0 +1,9 @@
1
+ export function createOpCandidateRegistryHelpers(ctx) {
2
+ const resolveOpCandidatesForFile = (name, file) => {
3
+ const lower = name.toLowerCase();
4
+ return ctx.localOpsByFile.get(file)?.get(lower);
5
+ };
6
+ return {
7
+ resolveOpCandidatesForFile,
8
+ };
9
+ }
@@ -0,0 +1,15 @@
1
+ import type { AsmItemNode, AsmOperandNode, OpDeclNode } from '../frontend/ast.js';
2
+ import type { AsmRangeLoweringCapability, HiddenLabelCapability, LoweringDiagnosticsCapability } from './capabilities.js';
3
+ type OpExpansionExecutionContext = LoweringDiagnosticsCapability & HiddenLabelCapability & AsmRangeLoweringCapability;
4
+ type ExpandAndLowerArgs = {
5
+ opDecl: OpDeclNode;
6
+ substituteOperandWithOpLabels: (operand: AsmOperandNode, localLabelMap: Map<string, string>) => AsmOperandNode;
7
+ };
8
+ type ExpandInlineOpBodyItemsArgs = ExpandAndLowerArgs & {
9
+ allocateLocalLabel: (labelName: string, opDecl: OpDeclNode) => string;
10
+ };
11
+ export declare function expandInlineOpBodyItems({ opDecl, allocateLocalLabel, substituteOperandWithOpLabels, }: ExpandInlineOpBodyItemsArgs): AsmItemNode[];
12
+ export declare function createOpExpansionExecutionHelpers(ctx: OpExpansionExecutionContext): {
13
+ expandAndLowerOpBody: ({ opDecl, substituteOperandWithOpLabels, }: ExpandAndLowerArgs) => void;
14
+ };
15
+ export {};
@@ -0,0 +1,45 @@
1
+ export function expandInlineOpBodyItems({ opDecl, allocateLocalLabel, substituteOperandWithOpLabels, }) {
2
+ const localLabelMap = new Map();
3
+ for (const bodyItem of opDecl.body.items) {
4
+ if (bodyItem.kind !== 'AsmLabel')
5
+ continue;
6
+ const key = bodyItem.name.toLowerCase();
7
+ if (!localLabelMap.has(key)) {
8
+ localLabelMap.set(key, allocateLocalLabel(bodyItem.name, opDecl));
9
+ }
10
+ }
11
+ return opDecl.body.items.map((bodyItem) => {
12
+ if (bodyItem.kind === 'AsmInstruction') {
13
+ return {
14
+ kind: 'AsmInstruction',
15
+ span: bodyItem.span,
16
+ head: bodyItem.head,
17
+ operands: bodyItem.operands.map((operand) => substituteOperandWithOpLabels(operand, localLabelMap)),
18
+ };
19
+ }
20
+ if (bodyItem.kind === 'AsmLabel') {
21
+ return {
22
+ kind: 'AsmLabel',
23
+ span: bodyItem.span,
24
+ name: localLabelMap.get(bodyItem.name.toLowerCase()) ?? bodyItem.name,
25
+ };
26
+ }
27
+ return bodyItem;
28
+ });
29
+ }
30
+ export function createOpExpansionExecutionHelpers(ctx) {
31
+ const expandAndLowerOpBody = ({ opDecl, substituteOperandWithOpLabels, }) => {
32
+ const expandedItems = expandInlineOpBodyItems({
33
+ opDecl,
34
+ allocateLocalLabel: () => ctx.newHiddenLabel(`__azm_op_${opDecl.name.toLowerCase()}_lbl`),
35
+ substituteOperandWithOpLabels,
36
+ });
37
+ const consumed = ctx.lowerAsmRange(expandedItems, 0, new Set());
38
+ if (consumed < expandedItems.length) {
39
+ ctx.diagAt(ctx.diagnostics, expandedItems[consumed].span, 'Internal control-flow lowering error.');
40
+ }
41
+ };
42
+ return {
43
+ expandAndLowerOpBody,
44
+ };
45
+ }
@@ -0,0 +1,15 @@
1
+ import type { AsmInstructionNode, SourceSpan } from '../frontend/ast.js';
2
+ import type { AsmRangeLoweringCapability, AstCloneCapability, CompileEnvCapability, DottedEaNameCapability, FixedTokenNormalizationCapability, FlowSyncCapability, HiddenLabelCapability, InverseConditionCapability, LoweringDiagnosticsWithSeverityCapability, OpCandidateResolverCapability, OpOperandFormattingCapability, OpOverloadSelectionCapability } from './capabilities.js';
3
+ type OpExpansionStackEntry = {
4
+ key: string;
5
+ name: string;
6
+ declSpan: SourceSpan;
7
+ callSiteSpan: SourceSpan;
8
+ };
9
+ type OpExpansionOrchestrationContext = LoweringDiagnosticsWithSeverityCapability & CompileEnvCapability & OpCandidateResolverCapability & OpOperandFormattingCapability & OpOverloadSelectionCapability & AstCloneCapability & DottedEaNameCapability & FixedTokenNormalizationCapability & InverseConditionCapability & HiddenLabelCapability & AsmRangeLoweringCapability & FlowSyncCapability & {
10
+ opExpansionStack: OpExpansionStackEntry[];
11
+ };
12
+ export declare function createOpExpansionOrchestrationHelpers(ctx: OpExpansionOrchestrationContext): {
13
+ tryHandleOpExpansion: (asmItem: AsmInstructionNode) => boolean;
14
+ };
15
+ export {};
@@ -0,0 +1,88 @@
1
+ import { DiagnosticIds } from '../diagnosticTypes.js';
2
+ import { createOpExpansionExecutionHelpers } from './opExpansionExecution.js';
3
+ import { createOpSubstitutionHelpers } from './opSubstitution.js';
4
+ export function createOpExpansionOrchestrationHelpers(ctx) {
5
+ const tryHandleOpExpansion = (asmItem) => {
6
+ const opCandidates = ctx.resolveOpCandidates(asmItem.head, asmItem.span.file);
7
+ if (!opCandidates || opCandidates.length === 0)
8
+ return false;
9
+ const selection = ctx.selectOpOverload(opCandidates, asmItem.operands);
10
+ if (selection.kind === 'arity_mismatch') {
11
+ const available = selection.signatures.map((signature) => ` - ${signature}`).join('\n');
12
+ ctx.diagAtWithId(ctx.diagnostics, asmItem.span, DiagnosticIds.OpArityMismatch, `No op overload of "${asmItem.head}" accepts ${asmItem.operands.length} operand(s).\n` +
13
+ `available overloads:\n${available}`);
14
+ return true;
15
+ }
16
+ if (selection.kind === 'no_match') {
17
+ const operandSummary = asmItem.operands.map(ctx.formatAsmOperandForOpDiag).join(', ');
18
+ const available = selection.mismatchDetails.map((detail) => ` - ${detail}`).join('\n');
19
+ ctx.diagAtWithId(ctx.diagnostics, asmItem.span, DiagnosticIds.OpNoMatchingOverload, `No matching op overload for "${asmItem.head}" with provided operands.\n` +
20
+ `call-site operands: (${operandSummary})\n` +
21
+ `available overloads:\n${available}`);
22
+ return true;
23
+ }
24
+ if (selection.kind === 'ambiguous') {
25
+ const operandSummary = asmItem.operands.map(ctx.formatAsmOperandForOpDiag).join(', ');
26
+ const equallySpecific = selection.definitions
27
+ .map((definition) => ` - ${definition}`)
28
+ .join('\n');
29
+ ctx.diagAtWithId(ctx.diagnostics, asmItem.span, DiagnosticIds.OpAmbiguousOverload, `Ambiguous op overload for "${asmItem.head}" (${selection.overloads.length} matches).\n` +
30
+ `call-site operands: (${operandSummary})\n` +
31
+ `equally specific candidates:\n${equallySpecific}`);
32
+ return true;
33
+ }
34
+ const opDecl = selection.overload;
35
+ const opKey = opDecl.name.toLowerCase();
36
+ const cycleStart = ctx.opExpansionStack.findIndex((entry) => entry.key === opKey);
37
+ if (cycleStart !== -1) {
38
+ const cycleChain = [
39
+ ...ctx.opExpansionStack
40
+ .slice(cycleStart)
41
+ .map((entry) => `${entry.name} (${entry.declSpan.file}:${entry.declSpan.start.line})`),
42
+ `${opDecl.name} (${opDecl.span.file}:${opDecl.span.start.line})`,
43
+ ].join(' -> ');
44
+ ctx.diagAtWithId(ctx.diagnostics, asmItem.span, DiagnosticIds.OpExpansionCycle, `Cyclic op expansion detected for "${opDecl.name}".\n` + `expansion chain: ${cycleChain}`);
45
+ return true;
46
+ }
47
+ const bindings = new Map();
48
+ for (let idx = 0; idx < opDecl.params.length; idx++) {
49
+ bindings.set(opDecl.params[idx].name.toLowerCase(), asmItem.operands[idx]);
50
+ }
51
+ const { substituteOperandWithOpLabels } = createOpSubstitutionHelpers({
52
+ bindings,
53
+ env: ctx.env,
54
+ diagnostics: ctx.diagnostics,
55
+ diagAt: ctx.diagAt,
56
+ cloneImmExpr: ctx.cloneImmExpr,
57
+ cloneEaExpr: ctx.cloneEaExpr,
58
+ cloneOperand: ctx.cloneOperand,
59
+ flattenEaDottedName: ctx.flattenEaDottedName,
60
+ });
61
+ ctx.opExpansionStack.push({
62
+ key: opKey,
63
+ name: opDecl.name,
64
+ declSpan: opDecl.span,
65
+ callSiteSpan: asmItem.span,
66
+ });
67
+ try {
68
+ const { expandAndLowerOpBody } = createOpExpansionExecutionHelpers({
69
+ diagnostics: ctx.diagnostics,
70
+ diagAt: ctx.diagAt,
71
+ newHiddenLabel: ctx.newHiddenLabel,
72
+ lowerAsmRange: ctx.lowerAsmRange,
73
+ });
74
+ expandAndLowerOpBody({
75
+ opDecl,
76
+ substituteOperandWithOpLabels,
77
+ });
78
+ }
79
+ finally {
80
+ ctx.opExpansionStack.pop();
81
+ }
82
+ ctx.syncToFlow();
83
+ return true;
84
+ };
85
+ return {
86
+ tryHandleOpExpansion,
87
+ };
88
+ }
@@ -0,0 +1,12 @@
1
+ import type { AsmInstructionNode, AsmLabelNode, ProgramNode } from '../frontend/ast.js';
2
+ type ExpandedOpStreamItem = {
3
+ kind: 'label';
4
+ label: AsmLabelNode;
5
+ } | {
6
+ kind: 'instruction';
7
+ instruction: AsmInstructionNode;
8
+ };
9
+ export declare function createInlineOpInstructionStreamExpander(program: ProgramNode): {
10
+ expandInstruction: (inst: AsmInstructionNode) => ExpandedOpStreamItem[];
11
+ };
12
+ export {};