@divmain/jdm-asm 0.2.1 → 0.2.3
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.
- package/dist/index.js +2227 -29
- package/dist/index.js.map +1 -1
- package/package.json +8 -2
- package/.github/workflows/ci.yml +0 -53
- package/.oxfmtrc.json +0 -16
- package/.oxlintrc.json +0 -183
- package/AGENTS.md +0 -81
- package/asconfig.json +0 -23
- package/benchmarks/fixtures.ts +0 -111
- package/benchmarks/input-fixtures.ts +0 -80
- package/benchmarks/run.ts +0 -913
- package/benchmarks/worker-pool.ts +0 -223
- package/benchmarks/worker.ts +0 -374
- package/scripts/run-all-tests.ts +0 -220
- package/src/compiler/EXPRESSION_SUBSETS.md +0 -228
- package/src/compiler/asc-compiler.ts +0 -315
- package/src/compiler/ast-types.ts +0 -215
- package/src/compiler/build.ts +0 -56
- package/src/compiler/cache.ts +0 -414
- package/src/compiler/code-generators.ts +0 -211
- package/src/compiler/codegen/index.ts +0 -15
- package/src/compiler/codegen/js-marshal.ts +0 -999
- package/src/compiler/codegen/js-validation.ts +0 -243
- package/src/compiler/codegen.ts +0 -19
- package/src/compiler/compile-time-validation.ts +0 -507
- package/src/compiler/cst-visitor.ts +0 -434
- package/src/compiler/errors.ts +0 -227
- package/src/compiler/expression-parser.ts +0 -536
- package/src/compiler/graph.ts +0 -197
- package/src/compiler/index.ts +0 -199
- package/src/compiler/input-validation.ts +0 -33
- package/src/compiler/marshal-gen.ts +0 -21
- package/src/compiler/nodes/context-resolvers.ts +0 -197
- package/src/compiler/nodes/decision-table.ts +0 -507
- package/src/compiler/nodes/decision.ts +0 -292
- package/src/compiler/nodes/expression-compiler.ts +0 -526
- package/src/compiler/nodes/expression.ts +0 -425
- package/src/compiler/nodes/function.ts +0 -316
- package/src/compiler/nodes/input.ts +0 -60
- package/src/compiler/nodes/switch.ts +0 -547
- package/src/compiler/optimizer.ts +0 -948
- package/src/compiler/orchestrator.ts +0 -352
- package/src/compiler/parser.ts +0 -115
- package/src/compiler/result-selection.ts +0 -161
- package/src/compiler/runtime/index.ts +0 -26
- package/src/compiler/runtime-codegen.ts +0 -211
- package/src/compiler/runtime-validation-codegen.ts +0 -294
- package/src/compiler/runtime.ts +0 -452
- package/src/compiler/schema.ts +0 -245
- package/src/compiler/switch-branch-detection.ts +0 -92
- package/src/compiler/types.ts +0 -136
- package/src/compiler/unary-ast-transforms.ts +0 -148
- package/src/compiler/unary-parser.ts +0 -301
- package/src/compiler/unary-transform.ts +0 -161
- package/src/compiler/utils.ts +0 -27
- package/src/compiler/virtual-fs.ts +0 -90
- package/src/compiler/wasm-instantiate.ts +0 -127
- package/src/index.ts +0 -1
- package/src/runtime/arrays.ts +0 -579
- package/src/runtime/context.ts +0 -189
- package/src/runtime/expressions.ts +0 -1811
- package/src/runtime/index.ts +0 -8
- package/src/runtime/memory.ts +0 -607
- package/src/runtime/strings.ts +0 -260
- package/src/runtime/tables.ts +0 -96
- package/src/runtime/tsconfig.json +0 -4
- package/src/runtime/values.ts +0 -209
- package/test-data/README.md +0 -83
- package/test-data/decision-tables/basic/8k.json +0 -87992
- package/test-data/decision-tables/basic/affiliate-commission-calculator.json +0 -228
- package/test-data/decision-tables/basic/airline-loyalty-points-calculations.json +0 -285
- package/test-data/decision-tables/basic/airline-upgrade-eligibility.json +0 -466
- package/test-data/decision-tables/basic/auto-insurance-premium-calculator.json +0 -412
- package/test-data/decision-tables/basic/booking-personalization-system.json +0 -553
- package/test-data/decision-tables/basic/care-team-assignment-system.json +0 -585
- package/test-data/decision-tables/basic/claim-validation-system.json +0 -307
- package/test-data/decision-tables/basic/clinical-lab-result-interpreter.json +0 -433
- package/test-data/decision-tables/basic/clinical-treatment-protocol.json +0 -474
- package/test-data/decision-tables/basic/credit-limit-adjustment.json +0 -479
- package/test-data/decision-tables/basic/customer-eligibility-engine.json +0 -551
- package/test-data/decision-tables/basic/customer-lifetime-value.json +0 -200
- package/test-data/decision-tables/basic/customer-onboarding-kyc-verification.json +0 -611
- package/test-data/decision-tables/basic/customer-service-escalation.json +0 -191
- package/test-data/decision-tables/basic/decision-table-discounts.json +0 -168
- package/test-data/decision-tables/basic/decision-table-shipping.json +0 -398
- package/test-data/decision-tables/basic/delivery-route-optimizer.json +0 -271
- package/test-data/decision-tables/basic/device-compatibility-checker.json +0 -303
- package/test-data/decision-tables/basic/disaster-relief-fund-allocation.json +0 -296
- package/test-data/decision-tables/basic/dynamic-fx-rate-pricing-system.json +0 -237
- package/test-data/decision-tables/basic/dynamic-marketplace-comission-calculator.json +0 -242
- package/test-data/decision-tables/basic/dynamic-shipping-cost-calculator.json +0 -378
- package/test-data/decision-tables/basic/dynamic-tarrif-engine.json +0 -289
- package/test-data/decision-tables/basic/dynamic-ticket-pricing.json +0 -325
- package/test-data/decision-tables/basic/empty-column-with-space.json +0 -100
- package/test-data/decision-tables/basic/empty-column-without-space.json +0 -100
- package/test-data/decision-tables/basic/environment-compliance-assessment.json +0 -386
- package/test-data/decision-tables/basic/expression-table-map.json +0 -313
- package/test-data/decision-tables/basic/flash-sale-eligibility.json +0 -366
- package/test-data/decision-tables/basic/flight-dispatch-decision-system.json +0 -455
- package/test-data/decision-tables/basic/flight-rebooking-fee-calculator.json +0 -406
- package/test-data/decision-tables/basic/government-assistance.json +0 -299
- package/test-data/decision-tables/basic/grant-funding-distribution.json +0 -307
- package/test-data/decision-tables/basic/hazardous-materials-management-system.json +0 -414
- package/test-data/decision-tables/basic/immigration-eligibility-evaluator.json +0 -765
- package/test-data/decision-tables/basic/import-duties-calculator.json +0 -318
- package/test-data/decision-tables/basic/insurance-agent-commission.json +0 -228
- package/test-data/decision-tables/basic/insurance-coverage-calculator.json +0 -362
- package/test-data/decision-tables/basic/insurance-underwriting-risk.json +0 -321
- package/test-data/decision-tables/basic/international-roaming-policy-manager.json +0 -199
- package/test-data/decision-tables/basic/legacy-plan-management.json +0 -434
- package/test-data/decision-tables/basic/marketplace-listing-verification-system.json +0 -334
- package/test-data/decision-tables/basic/medication-dosage-calculator.json +0 -318
- package/test-data/decision-tables/basic/merch-bags.json +0 -171
- package/test-data/decision-tables/basic/municipal-permit-evaluation-system.json +0 -364
- package/test-data/decision-tables/basic/mvno-partner-enablement.json +0 -313
- package/test-data/decision-tables/basic/partner-revenue-sharing.json +0 -244
- package/test-data/decision-tables/basic/payment-routing-and-fee-calculator.json +0 -475
- package/test-data/decision-tables/basic/policy-discount-calculator.json +0 -307
- package/test-data/decision-tables/basic/policy-eligibility-analyzer.json +0 -299
- package/test-data/decision-tables/basic/product-listing-scoring.json +0 -358
- package/test-data/decision-tables/basic/realtime-fraud-detection.json +0 -235
- package/test-data/decision-tables/basic/regional-compliance-manager.json +0 -278
- package/test-data/decision-tables/basic/returns-and-refund-policy.json +0 -366
- package/test-data/decision-tables/basic/returns-processing-system.json +0 -448
- package/test-data/decision-tables/basic/school-district-resource-allocation.json +0 -282
- package/test-data/decision-tables/basic/seat-map-optimization.json +0 -325
- package/test-data/decision-tables/basic/seller-fee-calculator.json +0 -307
- package/test-data/decision-tables/basic/service-level-agreement-enforcement.json +0 -575
- package/test-data/decision-tables/basic/smart-financial-product-matcher.json +0 -249
- package/test-data/decision-tables/basic/supply-chain-risk.json +0 -316
- package/test-data/decision-tables/basic/table-loop.json +0 -93
- package/test-data/decision-tables/basic/table.json +0 -76
- package/test-data/decision-tables/basic/traffic-violation-penalty-calculator.json +0 -436
- package/test-data/decision-tables/basic/transaction-compliance-classifier.json +0 -525
- package/test-data/decision-tables/basic/vehicle-claims-resolution.json +0 -310
- package/test-data/decision-tables/basic/warehouse-storage-location.json +0 -345
- package/test-data/decision-tables/hit-policy-collect/collect-multiple-matches.json +0 -127
- package/test-data/decision-tables/hit-policy-collect/collect-no-match.json +0 -95
- package/test-data/decision-tables/hit-policy-first/first-match.json +0 -103
- package/test-data/decision-tables/hit-policy-first/no-match.json +0 -95
- package/test-data/decision-tables/hit-policy-output-order/output-order-respected.json +0 -94
- package/test-data/decision-tables/hit-policy-output-order/string-output-order.json +0 -94
- package/test-data/decision-tables/hit-policy-priority/priority-respected.json +0 -86
- package/test-data/decision-tables/hit-policy-rule-order/rule-order-respected.json +0 -94
- package/test-data/decision-tables/hit-policy-unique/all-match-error.json +0 -89
- package/test-data/decision-tables/hit-policy-unique/multiple-match-error.json +0 -89
- package/test-data/decision-tables/hit-policy-unique/no-match.json +0 -88
- package/test-data/decision-tables/hit-policy-unique/unique-match.json +0 -99
- package/test-data/expressions/arithmetic/error-cyclic.json +0 -114
- package/test-data/expressions/arithmetic/error-missing-input.json +0 -54
- package/test-data/expressions/arithmetic/error-missing-output.json +0 -54
- package/test-data/expressions/arithmetic/expression-default.json +0 -93
- package/test-data/expressions/arithmetic/expression-fields.json +0 -94
- package/test-data/expressions/arithmetic/expression-loop.json +0 -94
- package/test-data/expressions/arithmetic/expression-passthrough.json +0 -108
- package/test-data/expressions/arithmetic/expression.json +0 -69
- package/test-data/expressions/arithmetic/nested-request.json +0 -125
- package/test-data/expressions/arithmetic/number-function.json +0 -58
- package/test-data/expressions/arithmetic/test-number-functions.json +0 -68
- package/test-data/expressions/functions/all.json +0 -149
- package/test-data/expressions/functions/avg.json +0 -89
- package/test-data/expressions/functions/filter.json +0 -109
- package/test-data/expressions/functions/flat.json +0 -167
- package/test-data/expressions/functions/map-strings.json +0 -65
- package/test-data/expressions/functions/map.json +0 -73
- package/test-data/expressions/functions/reduce.json +0 -49
- package/test-data/expressions/functions/some.json +0 -175
- package/test-data/expressions/functions/sort-strings.json +0 -97
- package/test-data/expressions/functions/sort.json +0 -97
- package/test-data/expressions/logical/logical-and.json +0 -116
- package/test-data/expressions/logical/logical-complex.json +0 -260
- package/test-data/expressions/logical/logical-not.json +0 -111
- package/test-data/expressions/logical/logical-or.json +0 -123
- package/test-data/expressions/string/string-comparison.json +0 -128
- package/test-data/expressions/string/string-concat.json +0 -106
- package/test-data/expressions/string/string-contains.json +0 -125
- package/test-data/expressions/string/string-endsWith.json +0 -113
- package/test-data/expressions/string/string-indexOf.json +0 -131
- package/test-data/expressions/string/string-join.json +0 -92
- package/test-data/expressions/string/string-lower.json +0 -94
- package/test-data/expressions/string/string-replace.json +0 -130
- package/test-data/expressions/string/string-split.json +0 -101
- package/test-data/expressions/string/string-startsWith.json +0 -113
- package/test-data/expressions/string/string-substring.json +0 -138
- package/test-data/expressions/string/string-trim.json +0 -100
- package/test-data/expressions/string/string-upper.json +0 -94
- package/test-data/other/custom.json +0 -51
- package/test-data/other/customer-input-schema.json +0 -34
- package/test-data/other/customer-output-schema.json +0 -34
- package/test-data/other/passthrough.json +0 -31
- package/test-data/sub-decisions/basic/$nodes-child.json +0 -31
- package/test-data/sub-decisions/basic/$nodes-parent.json +0 -49
- package/test-data/sub-decisions/basic/recursive-table1.json +0 -49
- package/test-data/sub-decisions/basic/recursive-table2.json +0 -49
- package/test-data/sub-decisions/complex-multi/approval-decision.json +0 -31
- package/test-data/sub-decisions/complex-multi/complex-dag.json +0 -175
- package/test-data/sub-decisions/complex-multi/credit-check.json +0 -31
- package/test-data/sub-decisions/complex-multi/customer-segmentation.json +0 -31
- package/test-data/sub-decisions/complex-multi/discount-eligibility.json +0 -31
- package/test-data/sub-decisions/complex-multi/eligibility-check.json +0 -31
- package/test-data/sub-decisions/complex-multi/final-offer.json +0 -31
- package/test-data/sub-decisions/complex-multi/income-verification.json +0 -31
- package/test-data/sub-decisions/complex-multi/linear-chain.json +0 -121
- package/test-data/sub-decisions/complex-multi/pricing-calculation.json +0 -31
- package/test-data/sub-decisions/complex-multi/product-eligibility.json +0 -31
- package/test-data/sub-decisions/complex-multi/risk-assessment.json +0 -31
- package/test-data/sub-decisions/complex-multi/shared-validation.json +0 -31
- package/test-data/sub-decisions/complex-multi/validation.json +0 -31
- package/test-data/sub-decisions/diamond/decision-a.json +0 -31
- package/test-data/sub-decisions/diamond/decision-b.json +0 -31
- package/test-data/sub-decisions/diamond/decision-c.json +0 -31
- package/test-data/sub-decisions/diamond/decision-shared.json +0 -31
- package/test-data/sub-decisions/diamond/diamond-pattern.json +0 -109
- package/test-data/sub-decisions/error-propagation/parent-calls-error.json +0 -44
- package/test-data/sub-decisions/error-propagation/sub-decision-with-error.json +0 -60
- package/test-data/switch-nodes/basic/account-dormancy-management.json +0 -245
- package/test-data/switch-nodes/basic/application-risk-assessment.json +0 -474
- package/test-data/switch-nodes/basic/cellular-data-rollover-system.json +0 -281
- package/test-data/switch-nodes/basic/clinical-pathway-selection.json +0 -454
- package/test-data/switch-nodes/basic/insurance-prior-authorization.json +0 -467
- package/test-data/switch-nodes/basic/last-mile-delivery-assignment.json +0 -373
- package/test-data/switch-nodes/basic/loan-approval.json +0 -469
- package/test-data/switch-nodes/basic/multi-switch.json +0 -498
- package/test-data/switch-nodes/basic/online-checkin-eligibility.json +0 -285
- package/test-data/switch-nodes/basic/order-consolidation-system.json +0 -493
- package/test-data/switch-nodes/basic/seller-approval-workflow.json +0 -383
- package/test-data/switch-nodes/basic/set-fee.json +0 -243
- package/test-data/switch-nodes/basic/shipping-carrier-selector.json +0 -379
- package/test-data/switch-nodes/basic/switch-node.json +0 -167
- package/test-data/switch-nodes/basic/switch-performance-2.json +0 -1307
- package/test-data/switch-nodes/basic/switch-performance.json +0 -691
- package/test-data/switch-nodes/basic/tax-exemption.json +0 -295
- package/test-data/switch-nodes/basic/warehouse-cross-docking.json +0 -313
- package/test-data/switch-nodes/default-cases/switch-with-default.json +0 -134
- package/test-data/zen-reference/$nodes-child.json +0 -69
- package/test-data/zen-reference/$nodes-parent.json +0 -34
- package/test-data/zen-reference/8k.json +0 -87992
- package/test-data/zen-reference/credit-analysis.json +0 -324
- package/test-data/zen-reference/custom.json +0 -51
- package/test-data/zen-reference/customer-input-schema.json +0 -34
- package/test-data/zen-reference/customer-output-schema.json +0 -34
- package/test-data/zen-reference/error-cyclic.json +0 -114
- package/test-data/zen-reference/error-missing-input.json +0 -54
- package/test-data/zen-reference/error-missing-output.json +0 -54
- package/test-data/zen-reference/expression.json +0 -69
- package/test-data/zen-reference/function-v2.json +0 -48
- package/test-data/zen-reference/function.json +0 -46
- package/test-data/zen-reference/graphs/account-dormancy-management.json +0 -245
- package/test-data/zen-reference/graphs/affiliate-commission-calculator.json +0 -228
- package/test-data/zen-reference/graphs/airline-loyalty-points-calculations.json +0 -285
- package/test-data/zen-reference/graphs/airline-upgrade-eligibility.json +0 -466
- package/test-data/zen-reference/graphs/aml.json +0 -537
- package/test-data/zen-reference/graphs/application-risk-assessment.json +0 -474
- package/test-data/zen-reference/graphs/auto-insurance-premium-calculator.json +0 -412
- package/test-data/zen-reference/graphs/booking-personalization-system.json +0 -553
- package/test-data/zen-reference/graphs/care-team-assignment-system.json +0 -585
- package/test-data/zen-reference/graphs/cellular-data-rollover-system.json +0 -281
- package/test-data/zen-reference/graphs/claim-validation-system.json +0 -307
- package/test-data/zen-reference/graphs/clinical-lab-result-interpreter.json +0 -433
- package/test-data/zen-reference/graphs/clinical-pathway-selection.json +0 -454
- package/test-data/zen-reference/graphs/clinical-treatment-protocol.json +0 -474
- package/test-data/zen-reference/graphs/company-analysis.json +0 -390
- package/test-data/zen-reference/graphs/credit-limit-adjustment.json +0 -479
- package/test-data/zen-reference/graphs/customer-eligibility-engine.json +0 -551
- package/test-data/zen-reference/graphs/customer-lifetime-value.json +0 -200
- package/test-data/zen-reference/graphs/customer-onboarding-kyc-verification.json +0 -611
- package/test-data/zen-reference/graphs/customer-service-escalation.json +0 -191
- package/test-data/zen-reference/graphs/decision-table-discounts.json +0 -168
- package/test-data/zen-reference/graphs/decision-table-shipping.json +0 -398
- package/test-data/zen-reference/graphs/delivery-route-optimizer.json +0 -271
- package/test-data/zen-reference/graphs/device-compatibility-checker.json +0 -303
- package/test-data/zen-reference/graphs/disaster-relief-fund-allocation.json +0 -296
- package/test-data/zen-reference/graphs/dynamic-fx-rate-pricing-system.json +0 -237
- package/test-data/zen-reference/graphs/dynamic-marketplace-comission-calculator.json +0 -242
- package/test-data/zen-reference/graphs/dynamic-shipping-cost-calculator.json +0 -378
- package/test-data/zen-reference/graphs/dynamic-tarrif-engine.json +0 -289
- package/test-data/zen-reference/graphs/dynamic-ticket-pricing.json +0 -325
- package/test-data/zen-reference/graphs/empty-column-with-space.json +0 -100
- package/test-data/zen-reference/graphs/empty-column-without-space.json +0 -100
- package/test-data/zen-reference/graphs/environment-compliance-assessment.json +0 -386
- package/test-data/zen-reference/graphs/expression-default.json +0 -93
- package/test-data/zen-reference/graphs/expression-fields.json +0 -94
- package/test-data/zen-reference/graphs/expression-loop.json +0 -94
- package/test-data/zen-reference/graphs/expression-passthrough.json +0 -108
- package/test-data/zen-reference/graphs/expression-table-map.json +0 -313
- package/test-data/zen-reference/graphs/flash-sale-eligibility.json +0 -366
- package/test-data/zen-reference/graphs/flight-dispatch-decision-system.json +0 -455
- package/test-data/zen-reference/graphs/flight-rebooking-fee-calculator.json +0 -406
- package/test-data/zen-reference/graphs/government-assistance.json +0 -299
- package/test-data/zen-reference/graphs/grant-funding-distribution.json +0 -307
- package/test-data/zen-reference/graphs/hazardous-materials-management-system.json +0 -414
- package/test-data/zen-reference/graphs/immigration-eligibility-evaluator.json +0 -765
- package/test-data/zen-reference/graphs/import-duties-calculator.json +0 -318
- package/test-data/zen-reference/graphs/insurance-agent-commission.json +0 -228
- package/test-data/zen-reference/graphs/insurance-breakdown.json +0 -421
- package/test-data/zen-reference/graphs/insurance-coverage-calculator.json +0 -362
- package/test-data/zen-reference/graphs/insurance-prior-authorization.json +0 -467
- package/test-data/zen-reference/graphs/insurance-underwriting-risk.json +0 -321
- package/test-data/zen-reference/graphs/international-roaming-policy-manager.json +0 -199
- package/test-data/zen-reference/graphs/last-mile-delivery-assignment.json +0 -373
- package/test-data/zen-reference/graphs/legacy-plan-management.json +0 -434
- package/test-data/zen-reference/graphs/loan-approval.json +0 -469
- package/test-data/zen-reference/graphs/marketplace-listing-verification-system.json +0 -334
- package/test-data/zen-reference/graphs/medication-dosage-calculator.json +0 -318
- package/test-data/zen-reference/graphs/merch-bags.json +0 -171
- package/test-data/zen-reference/graphs/multi-switch.json +0 -498
- package/test-data/zen-reference/graphs/municipal-permit-evaluation-system.json +0 -364
- package/test-data/zen-reference/graphs/mvno-partner-enablement.json +0 -313
- package/test-data/zen-reference/graphs/nested-request.json +0 -125
- package/test-data/zen-reference/graphs/online-checkin-eligibility.json +0 -285
- package/test-data/zen-reference/graphs/order-consolidation-system.json +0 -493
- package/test-data/zen-reference/graphs/partner-revenue-sharing.json +0 -244
- package/test-data/zen-reference/graphs/payment-routing-and-fee-calculator.json +0 -475
- package/test-data/zen-reference/graphs/policy-discount-calculator.json +0 -307
- package/test-data/zen-reference/graphs/policy-eligibility-analyzer.json +0 -299
- package/test-data/zen-reference/graphs/product-listing-scoring.json +0 -358
- package/test-data/zen-reference/graphs/realtime-fraud-detection.json +0 -235
- package/test-data/zen-reference/graphs/regional-compliance-manager.json +0 -278
- package/test-data/zen-reference/graphs/returns-and-refund-policy.json +0 -366
- package/test-data/zen-reference/graphs/returns-processing-system.json +0 -448
- package/test-data/zen-reference/graphs/school-district-resource-allocation.json +0 -282
- package/test-data/zen-reference/graphs/seat-map-optimization.json +0 -325
- package/test-data/zen-reference/graphs/seller-approval-workflow.json +0 -383
- package/test-data/zen-reference/graphs/seller-fee-calculator.json +0 -307
- package/test-data/zen-reference/graphs/service-level-agreement-enforcement.json +0 -575
- package/test-data/zen-reference/graphs/set-fee.json +0 -243
- package/test-data/zen-reference/graphs/shipping-carrier-selector.json +0 -379
- package/test-data/zen-reference/graphs/smart-financial-product-matcher.json +0 -249
- package/test-data/zen-reference/graphs/supply-chain-risk.json +0 -316
- package/test-data/zen-reference/graphs/table-loop.json +0 -93
- package/test-data/zen-reference/graphs/tax-exemption.json +0 -295
- package/test-data/zen-reference/graphs/traffic-violation-penalty-calculator.json +0 -436
- package/test-data/zen-reference/graphs/transaction-compliance-classifier.json +0 -525
- package/test-data/zen-reference/graphs/vehicle-claims-resolution.json +0 -310
- package/test-data/zen-reference/graphs/warehouse-cross-docking.json +0 -313
- package/test-data/zen-reference/graphs/warehouse-storage-location.json +0 -345
- package/test-data/zen-reference/http-function.json +0 -34
- package/test-data/zen-reference/infinite-function.json +0 -46
- package/test-data/zen-reference/js/imports.js +0 -25
- package/test-data/zen-reference/passthrough.json +0 -31
- package/test-data/zen-reference/recursive-table1.json +0 -49
- package/test-data/zen-reference/recursive-table2.json +0 -49
- package/test-data/zen-reference/sleep-function.json +0 -34
- package/test-data/zen-reference/switch-node.json +0 -167
- package/test-data/zen-reference/switch-performance-2.json +0 -1307
- package/test-data/zen-reference/switch-performance.json +0 -691
- package/test-data/zen-reference/table.json +0 -76
- package/tests/helpers/index.ts +0 -73
- package/tests/helpers/mock-context.ts +0 -231
- package/tests/helpers/round-trip.ts +0 -398
- package/tests/helpers/test-harness-comparison.ts +0 -325
- package/tests/helpers/test-harness-wasm.ts +0 -710
- package/tests/helpers/test-harness.ts +0 -28
- package/tests/helpers/wasm-test.ts +0 -659
- package/tests/integration/compilation-errors.test.ts +0 -864
- package/tests/integration/decision-tables.test.ts +0 -531
- package/tests/integration/edge-cases.test.ts +0 -787
- package/tests/integration/expressions.test.ts +0 -513
- package/tests/integration/function-node-integration.test.ts +0 -182
- package/tests/integration/sub-decisions.test.ts +0 -108
- package/tests/integration/switch-nodes.test.ts +0 -399
- package/tests/integration/unary-or-matching.test.ts +0 -53
- package/tests/integration/wasm-data-types.test.ts +0 -398
- package/tests/integration/wasm-errors.test.ts +0 -199
- package/tests/integration/wasm-execution.test.ts +0 -348
- package/tests/integration/wasm-memory.test.ts +0 -228
- package/tests/scripts/analyze-coverage.ts +0 -166
- package/tests/scripts/categorize-tests.ts +0 -396
- package/tests/scripts/coverage-analysis.ts +0 -836
- package/tests/unit/compiler/cache.test.ts +0 -238
- package/tests/unit/compiler/errors.test.ts +0 -316
- package/tests/unit/compiler/graph-scalability.test.ts +0 -510
- package/tests/unit/compiler/graph.test.ts +0 -878
- package/tests/unit/compiler/input-validation.test.ts +0 -447
- package/tests/unit/compiler/logical-and-parser.test.ts +0 -143
- package/tests/unit/compiler/logical-not-parser.test.ts +0 -107
- package/tests/unit/compiler/logical-or-parser.test.ts +0 -236
- package/tests/unit/compiler/marshal-gen/marshal-gen.test.ts +0 -97
- package/tests/unit/compiler/nodes/decision-table.test.ts +0 -103
- package/tests/unit/compiler/nodes/decision.test.ts +0 -182
- package/tests/unit/compiler/nodes/function-compile.test.ts +0 -204
- package/tests/unit/compiler/nodes/function.test.ts +0 -176
- package/tests/unit/compiler/nodes/input.test.ts +0 -30
- package/tests/unit/compiler/nodes/switch.test.ts +0 -127
- package/tests/unit/compiler/optimizer-cache.test.ts +0 -327
- package/tests/unit/compiler/optimizer-implementation.test.ts +0 -625
- package/tests/unit/compiler/parser.test.ts +0 -508
- package/tests/unit/compiler/runtime-error-cleanup.test.ts +0 -426
- package/tests/unit/compiler/runtime-validation.test.ts +0 -303
- package/tests/unit/compiler/runtime.test.ts +0 -221
- package/tests/unit/compiler/schema/schema.test.ts +0 -248
- package/tests/unit/compiler/unary-ast-transforms.test.ts +0 -245
- package/tsconfig.json +0 -27
- package/tsup.config.ts +0 -11
- package/vitest.config.ts +0 -12
package/src/runtime/index.ts
DELETED
package/src/runtime/memory.ts
DELETED
|
@@ -1,607 +0,0 @@
|
|
|
1
|
-
// assembly/runtime/memory.ts (AssemblyScript)
|
|
2
|
-
// Memory layout and management utilities for WASM linear memory
|
|
3
|
-
|
|
4
|
-
import { writeString } from './strings';
|
|
5
|
-
|
|
6
|
-
// ============================================================================
|
|
7
|
-
// Memory Layout Constants
|
|
8
|
-
// ============================================================================
|
|
9
|
-
|
|
10
|
-
// Reserved space for null pointer trap (first 4 bytes)
|
|
11
|
-
// Accessing address 0 should trap, catching null/nullish pointer bugs
|
|
12
|
-
export const NULL_POINTER_TRAP_SIZE: usize = 4;
|
|
13
|
-
|
|
14
|
-
// Fixed memory region offsets
|
|
15
|
-
export const INPUT_BUFFER_START: usize = NULL_POINTER_TRAP_SIZE; // 0x0004
|
|
16
|
-
|
|
17
|
-
// Schema-specific field layouts require different buffer sizes. Computing sizes at
|
|
18
|
-
// compile time based on actual schema ensures optimal memory usage per decision.
|
|
19
|
-
export let INPUT_BUFFER_SIZE: usize = 0;
|
|
20
|
-
|
|
21
|
-
// Variable-length input data starts after the fixed input buffer
|
|
22
|
-
export let INPUT_VAR_START: usize = 0;
|
|
23
|
-
|
|
24
|
-
// Output buffer follows input variable data
|
|
25
|
-
export let OUTPUT_START: usize = 0;
|
|
26
|
-
|
|
27
|
-
// Computed at compilation time based on input/output schema field sizes
|
|
28
|
-
export let OUTPUT_BUFFER_SIZE: usize = 0;
|
|
29
|
-
|
|
30
|
-
// Variable-length output data starts after the fixed output buffer
|
|
31
|
-
export let OUTPUT_VAR_START: usize = 0;
|
|
32
|
-
|
|
33
|
-
// Runtime heap for intermediate values (temporary arrays, string concat buffers, etc.)
|
|
34
|
-
export let HEAP_START: usize = 0;
|
|
35
|
-
|
|
36
|
-
// ============================================================================
|
|
37
|
-
// Header Constants
|
|
38
|
-
// ============================================================================
|
|
39
|
-
|
|
40
|
-
// Schema hash size in bytes
|
|
41
|
-
export const SCHEMA_HASH_SIZE: usize = 8;
|
|
42
|
-
|
|
43
|
-
// String descriptor format: [offset (4 bytes)] [length (4 bytes)]
|
|
44
|
-
export const STRING_DESC_SIZE: usize = 8;
|
|
45
|
-
|
|
46
|
-
// Array descriptor format: [offset (4 bytes)] [length (4 bytes)]
|
|
47
|
-
export const ARRAY_DESC_SIZE: usize = 8;
|
|
48
|
-
|
|
49
|
-
// ============================================================================
|
|
50
|
-
// Memory Allocation
|
|
51
|
-
// ============================================================================
|
|
52
|
-
|
|
53
|
-
// Decision evaluation is single-pass (no GC needed), and most allocations are temporary
|
|
54
|
-
// (freed after result is marshaled). Linear bump allocator is fast and simple.
|
|
55
|
-
let heapPointer: usize = 0;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Initialize memory layout.
|
|
59
|
-
*
|
|
60
|
-
* This function must be called once at startup with the computed sizes
|
|
61
|
-
* for the input and output buffers based on the schema.
|
|
62
|
-
*
|
|
63
|
-
* @param inputFixedSize - Size of fixed input fields in bytes
|
|
64
|
-
* @param outputFixedSize - Size of fixed output fields in bytes
|
|
65
|
-
*/
|
|
66
|
-
export function initializeMemoryLayout(inputFixedSize: usize, outputFixedSize: usize): void {
|
|
67
|
-
INPUT_BUFFER_SIZE = inputFixedSize;
|
|
68
|
-
INPUT_VAR_START = INPUT_BUFFER_START + inputFixedSize;
|
|
69
|
-
|
|
70
|
-
OUTPUT_BUFFER_SIZE = outputFixedSize;
|
|
71
|
-
OUTPUT_START = INPUT_VAR_START; // Output follows input variable data
|
|
72
|
-
OUTPUT_VAR_START = OUTPUT_START + outputFixedSize;
|
|
73
|
-
|
|
74
|
-
HEAP_START = OUTPUT_VAR_START; // Heap follows output variable data
|
|
75
|
-
heapPointer = HEAP_START; // Reset heap pointer
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Get the current memory layout info.
|
|
80
|
-
*
|
|
81
|
-
* @returns Object with all memory region offsets and sizes
|
|
82
|
-
*/
|
|
83
|
-
export function getMemoryLayout(): MemoryLayout {
|
|
84
|
-
return new MemoryLayout(
|
|
85
|
-
NULL_POINTER_TRAP_SIZE,
|
|
86
|
-
INPUT_BUFFER_START,
|
|
87
|
-
INPUT_BUFFER_SIZE,
|
|
88
|
-
INPUT_VAR_START,
|
|
89
|
-
OUTPUT_START,
|
|
90
|
-
OUTPUT_BUFFER_SIZE,
|
|
91
|
-
OUTPUT_VAR_START,
|
|
92
|
-
HEAP_START,
|
|
93
|
-
);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Memory layout information structure.
|
|
98
|
-
*/
|
|
99
|
-
export class MemoryLayout {
|
|
100
|
-
nullPointerTrapSize: usize;
|
|
101
|
-
inputBufferStart: usize;
|
|
102
|
-
inputBufferSize: usize;
|
|
103
|
-
inputVarStart: usize;
|
|
104
|
-
outputStart: usize;
|
|
105
|
-
outputBufferSize: usize;
|
|
106
|
-
outputVarStart: usize;
|
|
107
|
-
heapStart: usize;
|
|
108
|
-
|
|
109
|
-
constructor(
|
|
110
|
-
nullPointerTrapSize: usize,
|
|
111
|
-
inputBufferStart: usize,
|
|
112
|
-
inputBufferSize: usize,
|
|
113
|
-
inputVarStart: usize,
|
|
114
|
-
outputStart: usize,
|
|
115
|
-
outputBufferSize: usize,
|
|
116
|
-
outputVarStart: usize,
|
|
117
|
-
heapStart: usize,
|
|
118
|
-
) {
|
|
119
|
-
this.nullPointerTrapSize = nullPointerTrapSize;
|
|
120
|
-
this.inputBufferStart = inputBufferStart;
|
|
121
|
-
this.inputBufferSize = inputBufferSize;
|
|
122
|
-
this.inputVarStart = inputVarStart;
|
|
123
|
-
this.outputStart = outputStart;
|
|
124
|
-
this.outputBufferSize = outputBufferSize;
|
|
125
|
-
this.outputVarStart = outputVarStart;
|
|
126
|
-
this.heapStart = heapStart;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// ============================================================================
|
|
131
|
-
// Simple Linear Heap Allocator
|
|
132
|
-
// ============================================================================
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Allocate memory from the runtime heap.
|
|
136
|
-
*
|
|
137
|
-
* A simple linear allocator - memory is never freed during a single evaluation.
|
|
138
|
-
* Suitable for short-lived operations like decision table evaluation.
|
|
139
|
-
*
|
|
140
|
-
* Memory is never freed during a single evaluation because:
|
|
141
|
-
* (1) evaluations are short-lived (milliseconds),
|
|
142
|
-
* (2) heap is reset between evaluations, and
|
|
143
|
-
* (3) avoiding free list management simplifies allocator and improves performance.
|
|
144
|
-
*
|
|
145
|
-
* @param size - Number of bytes to allocate (must be > 0)
|
|
146
|
-
* @returns Pointer to allocated memory
|
|
147
|
-
* @throws Calls abort() on OUT_OF_MEMORY - this is a critical error that halts execution
|
|
148
|
-
*/
|
|
149
|
-
export function heapAlloc(size: usize): usize {
|
|
150
|
-
if (size == 0) return 0;
|
|
151
|
-
|
|
152
|
-
// Get current memory size in bytes (1 page = 64KB = 65536 bytes)
|
|
153
|
-
const memorySize: usize = (<usize>memory.size()) << 16;
|
|
154
|
-
|
|
155
|
-
// Align the heap pointer to 8-byte boundary
|
|
156
|
-
const alignedPtr = alignPtr(heapPointer, 8);
|
|
157
|
-
|
|
158
|
-
// Check for overflow when computing aligned pointer
|
|
159
|
-
// If alignedPtr wrapped around (became smaller than heapPointer), we've overflowed
|
|
160
|
-
if (alignedPtr < heapPointer) {
|
|
161
|
-
SetLastError(RuntimeErrorCode.OUT_OF_MEMORY);
|
|
162
|
-
return 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Check for overflow when computing new heap pointer
|
|
166
|
-
// If newHeapPointer would wrap around, we've overflowed
|
|
167
|
-
const maxAllowedSize = memorySize - alignedPtr;
|
|
168
|
-
if (size > maxAllowedSize) {
|
|
169
|
-
SetLastError(RuntimeErrorCode.OUT_OF_MEMORY);
|
|
170
|
-
return 0;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
const newHeapPointer = alignedPtr + size;
|
|
174
|
-
|
|
175
|
-
// Bounds check: ensure new heap pointer doesn't exceed memory
|
|
176
|
-
if (newHeapPointer > memorySize) {
|
|
177
|
-
SetLastError(RuntimeErrorCode.OUT_OF_MEMORY);
|
|
178
|
-
return 0;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
// All checks passed, update heap pointer and return allocation
|
|
182
|
-
heapPointer = newHeapPointer;
|
|
183
|
-
return alignedPtr;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* Get the current heap pointer (next allocation will start here).
|
|
188
|
-
*
|
|
189
|
-
* @returns Current heap pointer address
|
|
190
|
-
*/
|
|
191
|
-
export function getHeapPointer(): usize {
|
|
192
|
-
return heapPointer;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Reset the heap pointer to the start of the heap region.
|
|
197
|
-
*
|
|
198
|
-
* This allows reusing heap memory for multiple evaluations.
|
|
199
|
-
*/
|
|
200
|
-
export function resetHeap(): void {
|
|
201
|
-
heapPointer = HEAP_START;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Save the current heap pointer state.
|
|
206
|
-
*
|
|
207
|
-
* @returns Current heap pointer address
|
|
208
|
-
*/
|
|
209
|
-
export function saveHeapPointer(): usize {
|
|
210
|
-
return heapPointer;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Restore the heap pointer to a previously saved state.
|
|
215
|
-
*
|
|
216
|
-
* @param saved - Saved heap pointer address from saveHeapPointer()
|
|
217
|
-
*/
|
|
218
|
-
export function restoreHeapPointer(saved: usize): usize {
|
|
219
|
-
const old = heapPointer;
|
|
220
|
-
heapPointer = saved;
|
|
221
|
-
return old;
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// ============================================================================
|
|
225
|
-
// Pointer Utilities
|
|
226
|
-
// ============================================================================
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Align a pointer to the specified alignment boundary.
|
|
230
|
-
*
|
|
231
|
-
* @param ptr - Pointer to align
|
|
232
|
-
* @param alignment - Alignment boundary (must be a power of 2)
|
|
233
|
-
* @returns Aligned pointer
|
|
234
|
-
*/
|
|
235
|
-
export function alignPtr(ptr: usize, alignment: usize): usize {
|
|
236
|
-
return (ptr + alignment - 1) & ~(alignment - 1);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Check if a pointer is null (0).
|
|
241
|
-
*
|
|
242
|
-
* @param ptr - Pointer to check
|
|
243
|
-
* @returns true if pointer is 0, false otherwise
|
|
244
|
-
*/
|
|
245
|
-
export function isNullPtr(ptr: usize): bool {
|
|
246
|
-
return ptr == 0;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Check if a pointer is valid (non-null and aligned).
|
|
251
|
-
*
|
|
252
|
-
* @param ptr - Pointer to check
|
|
253
|
-
* @param alignment - Required alignment (default: 4 bytes)
|
|
254
|
-
* @returns true if pointer is valid, false otherwise
|
|
255
|
-
*/
|
|
256
|
-
export function isValidPtr(ptr: usize, alignment: usize = 4): bool {
|
|
257
|
-
if (ptr == 0) return false;
|
|
258
|
-
return (ptr & (alignment - 1)) == 0;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
// ============================================================================
|
|
262
|
-
// Buffer Access Helpers
|
|
263
|
-
// ============================================================================
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* Get the pointer to a schema hash field.
|
|
267
|
-
*
|
|
268
|
-
* @param basePtr - Base pointer of the buffer
|
|
269
|
-
* @returns Pointer to the schema hash field
|
|
270
|
-
*/
|
|
271
|
-
export function getSchemaHashPtr(basePtr: usize): usize {
|
|
272
|
-
return basePtr;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* Read a schema hash from a buffer.
|
|
277
|
-
*
|
|
278
|
-
* @param basePtr - Base pointer of the buffer
|
|
279
|
-
* @returns Schema hash as u64
|
|
280
|
-
*/
|
|
281
|
-
export function readSchemaHash(basePtr: usize): u64 {
|
|
282
|
-
return load<u64>(basePtr);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
/**
|
|
286
|
-
* Write a schema hash to a buffer.
|
|
287
|
-
*
|
|
288
|
-
* @param basePtr - Base pointer of the buffer
|
|
289
|
-
* @param hash - Schema hash to write
|
|
290
|
-
*/
|
|
291
|
-
export function writeSchemaHash(basePtr: usize, hash: u64): void {
|
|
292
|
-
store<u64>(basePtr, hash);
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Get the pointer to a field in a fixed-size buffer.
|
|
297
|
-
*
|
|
298
|
-
* @param bufferPtr - Base pointer of the buffer
|
|
299
|
-
* @param fieldOffset - Offset of the field from the buffer start
|
|
300
|
-
* @returns Pointer to the field
|
|
301
|
-
*/
|
|
302
|
-
export function getFieldPtr(bufferPtr: usize, fieldOffset: usize): usize {
|
|
303
|
-
return bufferPtr + fieldOffset;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// ============================================================================
|
|
307
|
-
// String Descriptor Helpers
|
|
308
|
-
// ============================================================================
|
|
309
|
-
|
|
310
|
-
/**
|
|
311
|
-
* Get the offset and length components of a string descriptor.
|
|
312
|
-
*
|
|
313
|
-
* String descriptor format: [offset (4 bytes)] [length (4 bytes)]
|
|
314
|
-
*
|
|
315
|
-
* @param descPtr - Pointer to the string descriptor
|
|
316
|
-
* @returns Object with offset and length
|
|
317
|
-
*/
|
|
318
|
-
export function readStringDesc(descPtr: usize): StringDesc {
|
|
319
|
-
return new StringDesc(load<u32>(descPtr), load<u32>(descPtr + 4));
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Write a string descriptor.
|
|
324
|
-
*
|
|
325
|
-
* @param descPtr - Pointer to the string descriptor
|
|
326
|
-
* @param offset - Offset to the string data
|
|
327
|
-
* @param length - Length of the string data
|
|
328
|
-
*/
|
|
329
|
-
export function writeStringDesc(descPtr: usize, offset: u32, length: u32): void {
|
|
330
|
-
store<u32>(descPtr, offset);
|
|
331
|
-
store<u32>(descPtr + 4, length);
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* String descriptor structure.
|
|
336
|
-
*/
|
|
337
|
-
export class StringDesc {
|
|
338
|
-
offset: u32;
|
|
339
|
-
length: u32;
|
|
340
|
-
|
|
341
|
-
constructor(offset: u32, length: u32) {
|
|
342
|
-
this.offset = offset;
|
|
343
|
-
this.length = length;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
isEmpty(): bool {
|
|
347
|
-
return this.length == 0;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// ============================================================================
|
|
352
|
-
// Array Descriptor Helpers
|
|
353
|
-
// ============================================================================
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Get the offset and length components of an array descriptor.
|
|
357
|
-
*
|
|
358
|
-
* Array descriptor format: [offset (4 bytes)] [length (4 bytes)]
|
|
359
|
-
*
|
|
360
|
-
* @param descPtr - Pointer to the array descriptor
|
|
361
|
-
* @returns Object with offset and length
|
|
362
|
-
*/
|
|
363
|
-
export function readArrayDesc(descPtr: usize): ArrayDesc {
|
|
364
|
-
return new ArrayDesc(load<u32>(descPtr), load<u32>(descPtr + 4));
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/**
|
|
368
|
-
* Write an array descriptor.
|
|
369
|
-
*
|
|
370
|
-
* @param descPtr - Pointer to the array descriptor
|
|
371
|
-
* @param offset - Offset to the array data
|
|
372
|
-
* @param length - Number of elements in the array
|
|
373
|
-
*/
|
|
374
|
-
export function writeArrayDesc(descPtr: usize, offset: u32, length: u32): void {
|
|
375
|
-
store<u32>(descPtr, offset);
|
|
376
|
-
store<u32>(descPtr + 4, length);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/**
|
|
380
|
-
* Array descriptor structure.
|
|
381
|
-
*/
|
|
382
|
-
export class ArrayDesc {
|
|
383
|
-
offset: u32;
|
|
384
|
-
length: u32;
|
|
385
|
-
|
|
386
|
-
constructor(offset: u32, length: u32) {
|
|
387
|
-
this.offset = offset;
|
|
388
|
-
this.length = length;
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
isEmpty(): bool {
|
|
392
|
-
return this.length == 0;
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
// ============================================================================
|
|
397
|
-
// Runtime Error Handling
|
|
398
|
-
// ============================================================================
|
|
399
|
-
|
|
400
|
-
// Error codes for runtime failures
|
|
401
|
-
export enum RuntimeErrorCode {
|
|
402
|
-
NONE = 0,
|
|
403
|
-
SCHEMA_MISMATCH = 1,
|
|
404
|
-
NULL_POINTER = 2,
|
|
405
|
-
INVALID_ACCESS = 3,
|
|
406
|
-
EVALUATION_ERROR = 4,
|
|
407
|
-
OUT_OF_MEMORY = 5,
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// Last error that occurred during evaluation
|
|
411
|
-
let lastErrorCode: RuntimeErrorCode = RuntimeErrorCode.NONE;
|
|
412
|
-
|
|
413
|
-
// Optional error message (allocated on heap for variable-length messages)
|
|
414
|
-
let errorMessagePtr: usize = 0;
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Check if an error code represents a critical error that should abort execution.
|
|
418
|
-
*
|
|
419
|
-
* Critical errors are unrecoverable conditions where continuing execution would
|
|
420
|
-
* likely lead to memory corruption, crashes, or incorrect results. These errors
|
|
421
|
-
* call abort() to immediately halt the WASM module.
|
|
422
|
-
*
|
|
423
|
-
* Critical errors:
|
|
424
|
-
* - OUT_OF_MEMORY: Memory allocation failed; continuing could corrupt state
|
|
425
|
-
* - NULL_POINTER: Null pointer dereference; memory safety violation
|
|
426
|
-
* - INVALID_ACCESS: Invalid memory access; memory safety violation
|
|
427
|
-
*
|
|
428
|
-
* Non-critical errors (set flag, caller must check hasError()):
|
|
429
|
-
* - SCHEMA_MISMATCH: Input doesn't match schema; recoverable
|
|
430
|
-
* - EVALUATION_ERROR: Logic error in decision evaluation; recoverable
|
|
431
|
-
*
|
|
432
|
-
* @param code - The error code to check
|
|
433
|
-
* @returns true if the error is critical and should abort
|
|
434
|
-
*/
|
|
435
|
-
export function isCriticalError(code: RuntimeErrorCode): bool {
|
|
436
|
-
return (
|
|
437
|
-
code === RuntimeErrorCode.OUT_OF_MEMORY ||
|
|
438
|
-
code === RuntimeErrorCode.NULL_POINTER ||
|
|
439
|
-
code === RuntimeErrorCode.INVALID_ACCESS
|
|
440
|
-
);
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
/**
|
|
444
|
-
* Get the last error code that occurred during evaluation.
|
|
445
|
-
*
|
|
446
|
-
* @returns The last error code
|
|
447
|
-
*/
|
|
448
|
-
export function getLastError(): RuntimeErrorCode {
|
|
449
|
-
return lastErrorCode;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/**
|
|
453
|
-
* Set the last error code and optional message.
|
|
454
|
-
*
|
|
455
|
-
* For critical errors (OUT_OF_MEMORY, NULL_POINTER, INVALID_ACCESS), this function
|
|
456
|
-
* calls abort() to immediately halt execution. Critical errors indicate unrecoverable
|
|
457
|
-
* conditions where continuing would lead to memory corruption or undefined behavior.
|
|
458
|
-
*
|
|
459
|
-
* For non-critical errors (SCHEMA_MISMATCH, EVALUATION_ERROR), callers MUST check
|
|
460
|
-
* hasError() after operations that can fail and handle the error appropriately.
|
|
461
|
-
* Failure to check error state may result in incorrect evaluation results.
|
|
462
|
-
*
|
|
463
|
-
* @param code - The error code
|
|
464
|
-
* @param message - Optional error message (allocated on heap)
|
|
465
|
-
*/
|
|
466
|
-
export function SetLastError(code: RuntimeErrorCode, message: usize = 0): void {
|
|
467
|
-
lastErrorCode = code;
|
|
468
|
-
errorMessagePtr = message;
|
|
469
|
-
|
|
470
|
-
// Critical errors abort immediately to prevent corrupted state propagation
|
|
471
|
-
if (isCriticalError(code)) {
|
|
472
|
-
abort();
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
/**
|
|
477
|
-
* Clear the last error (reset to NONE).
|
|
478
|
-
*/
|
|
479
|
-
export function clearLastError(): void {
|
|
480
|
-
lastErrorCode = RuntimeErrorCode.NONE;
|
|
481
|
-
errorMessagePtr = 0;
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Set an error with a string message.
|
|
486
|
-
*
|
|
487
|
-
* This is a convenience function that combines SetLastError() with writeString().
|
|
488
|
-
* The error message is allocated on the heap and will be freed by the next error.
|
|
489
|
-
*
|
|
490
|
-
* For critical errors (OUT_OF_MEMORY, NULL_POINTER, INVALID_ACCESS), this function
|
|
491
|
-
* will call abort() after setting the error, immediately halting execution.
|
|
492
|
-
*
|
|
493
|
-
* For non-critical errors (SCHEMA_MISMATCH, EVALUATION_ERROR), callers MUST check
|
|
494
|
-
* hasError() after operations that can fail.
|
|
495
|
-
*
|
|
496
|
-
* @param code - The error code
|
|
497
|
-
* @param message - The error message string
|
|
498
|
-
*/
|
|
499
|
-
export function SetLastErrorWithMessage(code: RuntimeErrorCode, message: string): void {
|
|
500
|
-
const messagePtr = writeString(message);
|
|
501
|
-
SetLastError(code, messagePtr);
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Get the pointer to the error message.
|
|
506
|
-
*
|
|
507
|
-
* @returns Pointer to error message (0 if no message)
|
|
508
|
-
*/
|
|
509
|
-
export function getErrorMessagePtr(): usize {
|
|
510
|
-
return errorMessagePtr;
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
/**
|
|
514
|
-
* Check if an error occurred.
|
|
515
|
-
*
|
|
516
|
-
* Callers MUST check this function after operations that can set non-critical errors
|
|
517
|
-
* (SCHEMA_MISMATCH, EVALUATION_ERROR). Critical errors (OUT_OF_MEMORY, NULL_POINTER,
|
|
518
|
-
* INVALID_ACCESS) abort immediately and never reach this check.
|
|
519
|
-
*
|
|
520
|
-
* Example usage:
|
|
521
|
-
* ```assemblyscript
|
|
522
|
-
* let result = someOperationThatCanFail();
|
|
523
|
-
* if (hasError()) {
|
|
524
|
-
* // Handle error - return early, propagate error, etc.
|
|
525
|
-
* return Value.Null();
|
|
526
|
-
* }
|
|
527
|
-
* // Continue with valid result
|
|
528
|
-
* ```
|
|
529
|
-
*
|
|
530
|
-
* @returns true if a non-critical error occurred, false otherwise
|
|
531
|
-
*/
|
|
532
|
-
export function hasError(): bool {
|
|
533
|
-
return lastErrorCode !== RuntimeErrorCode.NONE;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
// ============================================================================
|
|
537
|
-
// Memory Validation Helpers
|
|
538
|
-
// ============================================================================
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Check if a pointer is within the valid memory range.
|
|
542
|
-
*
|
|
543
|
-
* This is a basic check that can help catch out-of-bounds accesses.
|
|
544
|
-
* Note: In production, you may want to disable these checks for performance.
|
|
545
|
-
*
|
|
546
|
-
* @param ptr - Pointer to check
|
|
547
|
-
* @param size - Size of the region to check
|
|
548
|
-
* @return true if pointer is within valid range, false otherwise
|
|
549
|
-
*/
|
|
550
|
-
export function isValidMemoryRange(ptr: usize, size: usize): bool {
|
|
551
|
-
if (ptr == 0) return false;
|
|
552
|
-
|
|
553
|
-
// Get current memory size (AssemblyScript runtime provides this)
|
|
554
|
-
const memorySize: usize = memory.size() << 16; // 1 page = 64KB
|
|
555
|
-
|
|
556
|
-
return ptr + size <= memorySize;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
/**
|
|
560
|
-
* Check if a pointer is within the input buffer region.
|
|
561
|
-
*
|
|
562
|
-
* @param ptr - Pointer to check
|
|
563
|
-
* @return true if pointer is within input buffer, false otherwise
|
|
564
|
-
*/
|
|
565
|
-
export function isWithinInputBuffer(ptr: usize): bool {
|
|
566
|
-
return ptr >= INPUT_BUFFER_START && ptr < INPUT_VAR_START;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
/**
|
|
570
|
-
* Check if a pointer is within the input variable data region.
|
|
571
|
-
*
|
|
572
|
-
* @param ptr - Pointer to check
|
|
573
|
-
* @return true if pointer is within input variable data, false otherwise
|
|
574
|
-
*/
|
|
575
|
-
export function isWithinInputVar(ptr: usize): bool {
|
|
576
|
-
return ptr >= INPUT_VAR_START && ptr < OUTPUT_START;
|
|
577
|
-
}
|
|
578
|
-
|
|
579
|
-
/**
|
|
580
|
-
* Check if a pointer is within the output buffer region.
|
|
581
|
-
*
|
|
582
|
-
* @param ptr - Pointer to check
|
|
583
|
-
* @return true if pointer is within output buffer, false otherwise
|
|
584
|
-
*/
|
|
585
|
-
export function isWithinOutputBuffer(ptr: usize): bool {
|
|
586
|
-
return ptr >= OUTPUT_START && ptr < OUTPUT_VAR_START;
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
/**
|
|
590
|
-
* Check if a pointer is within the output variable data region.
|
|
591
|
-
*
|
|
592
|
-
* @param ptr - Pointer to check
|
|
593
|
-
* @return true if pointer is within output variable data, false otherwise
|
|
594
|
-
*/
|
|
595
|
-
export function isWithinOutputVar(ptr: usize): bool {
|
|
596
|
-
return ptr >= OUTPUT_VAR_START && ptr < HEAP_START;
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
/**
|
|
600
|
-
* Check if a pointer is within the heap region.
|
|
601
|
-
*
|
|
602
|
-
* @param ptr - Pointer to check
|
|
603
|
-
* @return true if pointer is within heap, false otherwise
|
|
604
|
-
*/
|
|
605
|
-
export function isWithinHeap(ptr: usize): bool {
|
|
606
|
-
return ptr >= HEAP_START;
|
|
607
|
-
}
|