git @ Cat's Eye Technologies SixtyPical / 3814d26
Improve tests. Chris Pressey 3 years ago
2 changed file(s) with 38 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
31043104 | }
31053105 = ok
31063106
3107 It is, however, important that the type context at every
3108 `goto` is compatible with the type context at the end of
3109 the routine.
3110
3111 | define bar routine
3112 | inputs x
3113 | trashes x, z, n
3114 | {
3107 Even though `goto` can only appear at the end of a block,
3108 you can still wind up with dead code; the analysis detects
3109 this.
3110
3111 | define bar routine trashes x, z, n {
31153112 | ld x, 200
31163113 | }
31173114 |
31223119 | goto bar
31233120 | } else {
31243121 | ld x, 0
3122 | goto bar
3123 | }
3124 | ld x, 100
3125 | }
3126 ? TerminatedContextError
3127
3128 It is important that the type context at every
3129 `goto` is compatible with the type context at the end of
3130 the routine.
3131
3132 | define bar routine
3133 | inputs x
3134 | trashes x, z, n
3135 | {
3136 | ld x, 200
3137 | }
3138 |
3139 | define main routine trashes x, z, n {
3140 | ld x, 0
3141 | if z {
3142 | ld x, 1
3143 | goto bar
3144 | } else {
3145 | ld x, 0
31253146 | }
31263147 | ld x, 1
31273148 | }
31283149 = ok
31293150
3130 Here, we try to trash x before gotoing a routine that inputs x.
3151 Here, we try to trash `x` before `goto`ing a routine that inputs `x`.
31313152
31323153 | define bar routine
31333154 | inputs x
31513172 | }
31523173 ? UnmeaningfulReadError: x
31533174
3154 Here, we declare that main outputs a, but we goto a routine that does not output a.
3175 Here, we declare that main outputs `a`, but we `goto` a routine that does not output `a`.
31553176
31563177 | define bar routine
31573178 | inputs x
550550 | }
551551 = ok
552552
553 The label doesn't have to be defined yet at the point
554 in the program text where it is `goto`d.
555
553556 | define main routine {
554557 | goto foo
555558 | }
558561 | }
559562 = ok
560563
564 Syntactically, you can `goto` a vector.
565
561566 | vector routine foo
562567 |
563568 | define main routine {
564569 | goto foo
565570 | }
566571 = ok
572
573 But you can't `goto` a label that never gets defined.
567574
568575 | define main routine {
569576 | goto foo