git @ Cat's Eye Technologies
Work out routine-vector type compatibility, w/ one failing test. Chris Pressey 4 years ago
1 changed file(s) with 137 addition(s) and 20 deletion(s).
 2222 2222 | } 2223 2223 ? ConstantConstraintError: foo 2224 2224 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. 2227 2287 2228 2288 | vector routine 2229 2289 | inputs x 2230 | outputs x 2290 | outputs x, y 2231 2291 | trashes z, n 2232 2292 | vec 2233 2293 | 2234 2294 | routine foo 2235 | inputs x 2236 | outputs x 2295 | inputs x, y 2296 | outputs x, y 2237 2297 | trashes z, n 2238 2298 | { 2239 2299 | inc x 2300 | inc y 2240 2301 | } 2241 2302 | 2242 2303 | routine main 2245 2306 | { 2246 2307 | copy foo, vec 2247 2308 | } 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. 2251 2312 2252 2313 | vector routine 2253 | inputs y 2254 | outputs y 2314 | inputs x, y 2315 | outputs x, y, a 2255 2316 | trashes z, n 2256 2317 | vec 2257 2318 | 2258 2319 | routine foo 2259 | inputs x 2260 | outputs x 2320 | inputs x, y 2321 | outputs x, y 2261 2322 | trashes z, n 2262 2323 | { 2263 2324 | inc x 2325 | inc y 2264 2326 | } 2265 2327 | 2266 2328 | routine main 2271 2333 | } 2272 2334 ? IncompatibleConstraintsError 2273 2335 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. 2276 2337 2277 2338 | 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 2281 2342 | vec 2282 2343 | 2283 2344 | routine foo 2284 | inputs x 2285 | outputs x 2345 | inputs x, y 2346 | outputs x, y 2286 2347 | trashes z, n 2287 2348 | { 2288 2349 | inc x 2350 | inc y 2289 2351 | } 2290 2352 | 2291 2353 | routine main 2294 2356 | { 2295 2357 | copy foo, vec 2296 2358 | } 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 2298 2415 2299 2416 Routines are read-only. 2300 2417