git @ Cat's Eye Technologies SixtyPical / b29716f
Constraints for `vector` come immediately after the type expression. Chris Pressey 3 years ago
6 changed file(s) with 63 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
55
66 * Each table has a specified size now (although, bounds checking is not performed.)
77 * Initialized `byte table` values need not have all 256 bytes initialized.
8 * Constraints for `vector` type come immediately after the type, not the variable.
89
910 0.10
1011 ----
8080 name = self.scanner.token
8181 self.scanner.scan()
8282
83 (inputs, outputs, trashes) = self.constraints()
84 if type_ == 'vector':
85 type_ = VectorType(inputs=inputs, outputs=outputs, trashes=trashes)
86 elif inputs or outputs or trashes:
87 raise SyntaxError("Cannot apply constraints to non-vector type")
88
8983 initial = None
9084 if self.scanner.consume(':'):
9185 if isinstance(type_, TableType) and self.scanner.on_type('string literal'):
128122 return TableType(TYPE_WORD, size)
129123 return TYPE_WORD
130124 elif self.scanner.consume('vector'):
131 return 'vector' # will be resolved to a Type by caller
125 (inputs, outputs, trashes) = self.constraints()
126 return VectorType(inputs=inputs, outputs=outputs, trashes=trashes)
132127 elif self.scanner.consume('buffer'):
133128 size = self.defn_size()
134129 return BufferType(size)
15531553 Routines are constants. You need not, and in fact cannot, specify a constant
15541554 as an input to, an output of, or as a trashed value of a routine.
15551555
1556 | vector vec
1557 | inputs x
1558 | outputs x
1559 | trashes z, n
1556 | vector
1557 | inputs x
1558 | outputs x
1559 | trashes z, n
1560 | vec
15601561 |
15611562 | routine foo
15621563 | inputs x
15751576 | }
15761577 ? ConstantConstraintError: foo in main
15771578
1578 | vector vec
1579 | inputs x
1580 | outputs x
1581 | trashes z, n
1579 | vector
1580 | inputs x
1581 | outputs x
1582 | trashes z, n
1583 | vec
15821584 |
15831585 | routine foo
15841586 | inputs x
15961598 | }
15971599 ? ConstantConstraintError: foo in main
15981600
1599 | vector vec
1600 | inputs x
1601 | outputs x
1602 | trashes z, n
1601 | vector
1602 | inputs x
1603 | outputs x
1604 | trashes z, n
1605 | vec
16031606 |
16041607 | routine foo
16051608 | inputs x
16201623 You can copy the address of a routine into a vector, if that vector is
16211624 declared appropriately.
16221625
1623 | vector vec
1624 | inputs x
1625 | outputs x
1626 | trashes z, n
1626 | vector
1627 | inputs x
1628 | outputs x
1629 | trashes z, n
1630 | vec
16271631 |
16281632 | routine foo
16291633 | inputs x
16431647
16441648 But not if the vector is declared inappropriately.
16451649
1646 | vector vec
1650 | vector
16471651 | inputs y
16481652 | outputs y
16491653 | trashes z, n
1654 | vec
16501655 |
16511656 | routine foo
16521657 | inputs x
16671672 "Appropriately" means, if the routine affects no more than what is named
16681673 in the input/output sets of the vector.
16691674
1670 | vector vec
1675 | vector
16711676 | inputs a, x
16721677 | outputs x
16731678 | trashes a, z, n
1679 | vec
16741680 |
16751681 | routine foo
16761682 | inputs x
16901696
16911697 Routines are read-only.
16921698
1693 | vector vec
1694 | inputs x
1695 | outputs x
1696 | trashes z, n
1699 | vector
1700 | inputs x
1701 | outputs x
1702 | trashes z, n
1703 | vec
16971704 |
16981705 | routine foo
16991706 | inputs x
17131720
17141721 Indirect call.
17151722
1716 | vector foo outputs x trashes z, n
1723 | vector outputs x trashes z, n foo
17171724 |
17181725 | routine bar outputs x trashes z, n {
17191726 | ld x, 200
17271734
17281735 Calling the vector does indeed trash the things the vector says it does.
17291736
1730 | vector foo trashes x, z, n
1737 | vector trashes x, z, n foo
17311738 |
17321739 | routine bar trashes x, z, n {
17331740 | ld x, 200
18271834
18281835 Indirect goto.
18291836
1830 | vector foo outputs x trashes a, z, n
1837 | vector outputs x trashes a, z, n foo
18311838 |
18321839 | routine bar outputs x trashes a, z, n {
18331840 | ld x, 200
18421849 Jumping through the vector does indeed trash, or output, the things the
18431850 vector says it does.
18441851
1845 | vector foo
1852 | vector
18461853 | trashes a, x, z, n
1854 | foo
18471855 |
18481856 | routine bar
18491857 | trashes a, x, z, n {
18651873 | }
18661874 ? UnmeaningfulReadError: x in main
18671875
1868 | vector foo
1869 | outputs x
1870 | trashes a, z, n
1876 | vector
1877 | outputs x
1878 | trashes a, z, n
1879 | foo
18711880 |
18721881 | routine bar
18731882 | outputs x
567567
568568 Indirect call.
569569
570 | vector foo outputs x trashes z, n
570 | vector outputs x
571 | trashes z, n
572 | foo
571573 |
572574 | routine bar outputs x trashes z, n {
573575 | ld x, 200
452452
453453 Indirect call.
454454
455 | vector foo outputs x trashes z, n
455 | vector outputs x trashes z, n foo
456456 |
457457 | routine bar outputs x trashes z, n {
458458 | ld x, 200
312312
313313 Declaring and calling a vector.
314314
315 | vector cinv
315 | vector
316316 | inputs a
317317 | outputs x
318318 | trashes a, x, z, n
319 | @ 788
319 | cinv @ 788
320320 |
321321 | routine foo {
322322 | ld a, 0
331331
332332 Only vectors can be decorated with constraints like that.
333333
334 | byte cinv
334 | byte
335335 | inputs a
336336 | outputs x
337337 | trashes a, x, z, n
338 | @ 788
338 | cinv @ 788
339339 |
340340 | routine main {
341341 | }
343343
344344 Constraints set may only contain labels.
345345
346 | vector cinv
346 | vector
347347 | inputs a
348348 | outputs 200
349349 | trashes a, x, z, n
350 | @ 788
350 | cinv @ 788
351351 |
352352 | routine foo {
353353 | ld a, 0
362362
363363 A vector can name itself in its inputs, outputs, and trashes.
364364
365 | vector cinv
365 | vector
366366 | inputs cinv, a
367367 | outputs cinv, x
368368 | trashes a, x, z, n
369 | @ 788
369 | cinv @ 788
370370 |
371371 | routine foo {
372372 | ld a, 0
382382 A routine can be copied into a vector before the routine appears in the program,
383383 *however*, it must be marked as such with the keyword `forward`.
384384
385 | vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
385 | vector
386 | inputs cinv, a
387 | outputs cinv, x
388 | trashes a, x, z, n
389 | cinv @ 788
386390 | routine main {
387391 | with interrupts off {
388392 | copy foo, cinv
394398 | }
395399 ? SyntaxError: Undefined symbol
396400
397 | vector cinv inputs cinv, a outputs cinv, x trashes a, x, z, n @ 788
401 | vector
402 | inputs cinv, a
403 | outputs cinv, x
404 | trashes a, x, z, n
405 | cinv @ 788
398406 | routine main {
399407 | with interrupts off {
400408 | copy forward foo, cinv