git @ Cat's Eye Technologies SixtyPical / f9c3b56
Work out routine-vector type compatibility, w/ one failing test. Chris Pressey 3 years ago
1 changed file(s) with 137 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
22222222 | }
22232223 ? ConstantConstraintError: foo
22242224
2225 You can copy the address of a routine into a vector, if that vector is
2226 declared appropriately.
2225 #### routine-vector type compatibility
2226
2227 You can copy the address of a routine into a vector, if that vector type
2228 is at least as "wide" as the type of the routine. More specifically,
2229
2230 - the vector must take _exactly_ the same inputs as the routine
2231 - the vector must make _exactly_ the same outputs as the routine
2232 - the vector must trash _at least_ what the routine trashes
2233
2234 If the vector and the routine have the very same signature, that's not an error.
2235
2236 | vector routine
2237 | inputs x, y
2238 | outputs x, y
2239 | trashes z, n
2240 | vec
2241 |
2242 | routine foo
2243 | inputs x, y
2244 | outputs x, y
2245 | trashes z, n
2246 | {
2247 | inc x
2248 | inc y
2249 | }
2250 |
2251 | routine main
2252 | outputs vec
2253 | trashes a, z, n
2254 | {
2255 | copy foo, vec
2256 | }
2257 = ok
2258
2259 If the vector takes an input that the routine doesn't take, that's not an error.
2260 (The interface requires that a parameter be specified before calling, but the
2261 implementation doesn't actually read it.)
2262
2263 | vector routine
2264 | inputs x, y, a
2265 | outputs x, y
2266 | trashes z, n
2267 | vec
2268 |
2269 | routine foo
2270 | inputs x, y
2271 | outputs x, y
2272 | trashes z, n
2273 | {
2274 | inc x
2275 | inc y
2276 | }
2277 |
2278 | routine main
2279 | outputs vec
2280 | trashes a, z, n
2281 | {
2282 | copy foo, vec
2283 | }
2284 = ok
2285
2286 If the vector fails to take an input that the routine takes, that's an error.
22272287
22282288 | vector routine
22292289 | inputs x
2230 | outputs x
2290 | outputs x, y
22312291 | trashes z, n
22322292 | vec
22332293 |
22342294 | routine foo
2235 | inputs x
2236 | outputs x
2295 | inputs x, y
2296 | outputs x, y
22372297 | trashes z, n
22382298 | {
22392299 | inc x
2300 | inc y
22402301 | }
22412302 |
22422303 | routine main
22452306 | {
22462307 | copy foo, vec
22472308 | }
2248 = ok
2249
2250 But not if the vector is declared inappropriately.
2309 ? IncompatibleConstraintsError
2310
2311 If the vector produces an output that the routine doesn't produce, that's an error.
22512312
22522313 | vector routine
2253 | inputs y
2254 | outputs y
2314 | inputs x, y
2315 | outputs x, y, a
22552316 | trashes z, n
22562317 | vec
22572318 |
22582319 | routine foo
2259 | inputs x
2260 | outputs x
2320 | inputs x, y
2321 | outputs x, y
22612322 | trashes z, n
22622323 | {
22632324 | inc x
2325 | inc y
22642326 | }
22652327 |
22662328 | routine main
22712333 | }
22722334 ? IncompatibleConstraintsError
22732335
2274 "Appropriately" means, if the routine affects no more than what is named
2275 in the input/output sets of the vector.
2336 If the vector fails to produce an output that the routine produces, that's an error.
22762337
22772338 | vector routine
2278 | inputs a, x
2279 | outputs x
2280 | trashes a, z, n
2339 | inputs x, y
2340 | outputs x
2341 | trashes z, n
22812342 | vec
22822343 |
22832344 | routine foo
2284 | inputs x
2285 | outputs x
2345 | inputs x, y
2346 | outputs x, y
22862347 | trashes z, n
22872348 | {
22882349 | inc x
2350 | inc y
22892351 | }
22902352 |
22912353 | routine main
22942356 | {
22952357 | copy foo, vec
22962358 | }
2297 = ok
2359 ? IncompatibleConstraintsError
2360
2361 If the vector fails to trash something the routine trashes, that's an error.
2362
2363 | vector routine
2364 | inputs x, y
2365 | outputs x, y
2366 | trashes z
2367 | vec
2368 |
2369 | routine foo
2370 | inputs x, y
2371 | outputs x, y
2372 | trashes z, n
2373 | {
2374 | inc x
2375 | inc y
2376 | }
2377 |
2378 | routine main
2379 | outputs vec
2380 | trashes a, z, n
2381 | {
2382 | copy foo, vec
2383 | }
2384 ? IncompatibleConstraintsError
2385
2386 If the vector trashes something the routine doesn't trash, that's not an error.
2387 (The implementation preserves something the interface doesn't guarantee is
2388 preserved. The caller gets no guarantee that it's preserved. It actually is,
2389 but it doesn't know that.)
2390
2391 | vector routine
2392 | inputs x, y
2393 | outputs x, y
2394 | trashes a, z, n
2395 | vec
2396 |
2397 | routine foo
2398 | inputs x, y
2399 | outputs x, y
2400 | trashes z, n
2401 | {
2402 | inc x
2403 | inc y
2404 | }
2405 |
2406 | routine main
2407 | outputs vec
2408 | trashes a, z, n
2409 | {
2410 | copy foo, vec
2411 | }
2412 = ok
2413
2414 #### other properties of routines
22982415
22992416 Routines are read-only.
23002417