Repository navigation
Expand file tree
/
Copy pathtypes.ss
More file actions
254 lines (248 loc) · 9.28 KB
/
Copy pathtypes.ss
File metadata and controls
254 lines (248 loc) · 9.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
;;; SPDX-FileCopyrightText: 2026 hardenedlinux Linux Team and Contributors
;;;
;;; SPDX-License-Identifier: LGPL-2.1-or-later
;;; Shared Library declaration vocabulary. Types only: no objects, IO or Engine.
(import
:clan/poo/object
(only-in :clan/poo/mop Type Type. define-type element? raise-type-error)
(only-in :clan/poo/type Symbol String List Record Pair Exactly)
(only-in :clan/poo/recursive-validation close-validation closed? closed-ref)
(only-in :clan/poo/object-contract ObjectContract. refine)
(only-in :yuanxu/object-types/contracts YuanxuContract. yuanxu-predicate-type))
(export
LibraryDeclarationContract
LibraryDeclarationShape
LibraryReferenceContract
LibraryAssetContract
LibraryPremiseContract
LibraryClaimContract
LibraryMethodShape
LibraryMethodBindingShape
LibraryModelShape
LibraryMethodKind
LibraryDefinitionRole
LibraryStrength
LibraryNonemptyString
LibrarySymbolPair
LibrarySymbolTriple
LibraryScopeBinding
library-definition-contract
LibraryScopeType.)
(define-type
(LibraryNonemptyString @ Type.)
.element?:
(lambda (value) (and (string? value) (> (string-length value) 0))))
(define-type LibrarySymbolPair
(Pair Symbol (Pair Symbol (Exactly '()))))
(define-type LibrarySymbolTriple
(Pair Symbol LibrarySymbolPair))
;; Shared wire binding: selected usage, scope kind and nonempty basis reference.
;; This shape does not establish digest validity, currentness or authority.
(define-type LibraryScopeBinding
(Pair Symbol (Pair Symbol (Pair LibraryNonemptyString (Exactly '())))))
(def (finite-type identity-values choices)
(yuanxu-predicate-type identity-values (lambda (value) (and (memq value choices) #t))))
(def LibraryDefinitionRole
(finite-type
'library/definition-role
'(generic-model specialization integration organization policy method catalog mapping)))
(def LibraryMethodKind
(finite-type
'library/method-kind
'(application-reasoning
model-projection
content-observation
implementation-execution
model-verification
theorem-check)))
(def LibraryStrength
(finite-type
'library/strength
'(authored-conditional
finite-model
arithmetic
execution
language-validation
correspondence
research-hypothesis)))
(define-type
(LibraryReferenceContract
@
(Record
identity: [Symbol]
revision: [LibraryNonemptyString]
owner: [Symbol]))
sealed:
#t)
(define-type
(LibraryAssetContract
@
(Record [LibraryReferenceContract]
kind: [(finite-type 'library/asset-kind '(scheme quint lean rust sysml org mapping))]
relative-path: [LibraryNonemptyString]))
sealed:
#t)
(define-type
(LibraryPremiseContract
@
(Record
identity: [Symbol]
statement: [LibraryNonemptyString]
inputs: [(List Symbol)]))
sealed:
#t)
(define-type
(LibraryClaimContract
@
(Record
identity: [Symbol]
meaning: [LibraryNonemptyString]
premises: [(List Symbol)]
duties: [(List Symbol)]
strength: [LibraryStrength]))
sealed:
#t)
(def LibraryDeclarationShape
(.cc ObjectContract. 'identity 'library/declaration
'responsibilities (.o
identity: Symbol
family: Symbol
source-owner: Symbol
applicability: (List Symbol)
role-contracts: (List Type)
extension-expectations: (List Symbol))))
;; The sole authored Library contract generation. Family declarations inherit it;
;; definitions, Scope values, Profiles, Scenarios and views carry references.
(def LibraryDeclarationContract
(.cc YuanxuContract. 'identity 'library/declaration
'contract-version "V1" 'value-contract LibraryDeclarationShape))
(def LibraryModelShape
(.cc ObjectContract. 'identity 'library/model
'responsibilities
(.o
identity: Symbol
role: LibraryDefinitionRole
family: Symbol
declaration-contract: Type
contract: Type
parent: (yuanxu-predicate-type 'library/parent (lambda (value) (or (not value) (object? value))))
revision: LibraryNonemptyString
lifecycle: (List Symbol)
rules: (List LibrarySymbolTriple)
dependencies: (List LibrarySymbolPair)
input-demands: (List Symbol)
premises: (List LibraryPremiseContract)
claims: (List LibraryClaimContract)
limits: (List LibraryPremiseContract)
qualification: Symbol
assets: (List LibraryAssetContract)
capabilities: (List Symbol)
method-refs: (List LibraryReferenceContract))))
;; Ordinary descriptor construction, not a role registry or schema interpreter.
;; The expected descriptor comes from the source publication; submitted metadata
;; cannot select it. ObjectContract owns inherited shape and unknown-field checks.
(def (library-definition-contract identity-value role-value family-value declaration-value shape-value)
(.o (:: expected [YuanxuContract.])
identity: identity-value
role: role-value
family: family-value
declaration-contract: declaration-value
value-contract:
(refine
shape-value
(lambda (value location)
(if (and
(eq? (.ref value 'role) role-value)
(eq? (.ref value 'family) family-value)
(eq? (.ref value 'contract) expected)
(eq? (.ref value 'declaration-contract) declaration-value))
'()
(list (.o
kind: 'library/association-mismatch
path: location)))))))
;; Inert expectations are definitions, not execution receipts or issuer callbacks.
(def LibraryOptionalReference
(yuanxu-predicate-type
'library/optional-reference
(lambda (v) (or (not v) (element? LibraryReferenceContract v)))))
(def LibraryMethodShape
(.cc ObjectContract. 'identity 'library/method
'responsibilities
(.o
identity: Symbol
revision: LibraryNonemptyString
owner: Symbol
role: LibraryDefinitionRole
family: Symbol
declaration-contract: Type
contract: Type
kind: LibraryMethodKind
model-ids: (List Symbol)
policy-ids: (List Symbol)
claims: (List Symbol)
modes: (List Symbol)
strength: LibraryStrength
signature: Type
provider: Symbol
operation: Symbol
result-owner: Symbol
result-kinds: (List Symbol)
input-demands: (List Symbol)
assets: (List LibraryAssetContract)
premises: (List LibraryPremiseContract)
limits: (List LibraryPremiseContract)
program-ref: LibraryOptionalReference
catalog-ref: LibraryOptionalReference
mapping-ref: LibraryOptionalReference)))
;; Concrete owners specialize definition and operation with actual expected values.
(def LibraryMethodBindingShape
(.cc ObjectContract. 'identity 'library/method-binding
'responsibilities (.o
definition: LibraryMethodShape
provider: Symbol
operation-name: Symbol
operation: (yuanxu-predicate-type 'library/deferred-operation procedure?)
current!: (yuanxu-predicate-type 'library/deferred-currentness procedure?))))
;; One native Type prototype owns normalization of the shared three-node Scope.
;; Families supply their shapes and semantic contracts; no registry or issuer.
(def (library-closed-scope? shape value)
(and
(element? shape value)
(let (graph (.get value validation))
(and
(eq? (.get value entry) (closed-ref graph 'entry))
(eq? (.get value declaration) (closed-ref graph 'declaration))
(eq? (.get value config) (closed-ref graph 'config))))))
(define-type
(LibraryScopeType. @ Type. scope-shape closed-shape entry-type declaration-type)
.element?:
(lambda (value)
(if (and (object? value) (.slot? value 'validation))
(library-closed-scope? closed-shape value)
(element? scope-shape value)))
.validate:
(lambda (value)
(if (and (object? value) (.slot? value 'validation))
(begin (unless (library-closed-scope? closed-shape value) (raise-type-error @ value)) value)
(let ()
(unless (element? scope-shape value) (raise-type-error @ value))
(unless (and
(eq? (.get value entry) (.get value config entry))
(eq? (.get value declaration) (.get value config declaration)))
(error "Library Config associations diverged before Scope normalization"))
(def graph
(close-validation
(lambda (reference)
(def config-shape
(.cc ObjectContract. 'responsibilities
(.o
entry: (reference 'entry)
declaration: (reference 'declaration))))
(list
(list 'entry entry-type (.get value entry))
(list 'declaration declaration-type (.get value declaration))
(list 'config config-shape (.get value config))))
3))
(.cc value 'entry (closed-ref graph 'entry)
'declaration (closed-ref graph 'declaration)
'config (closed-ref graph 'config) 'validation graph)))))