2279 | 2279 |
| }
|
2280 | 2280 |
? TypeMismatchError
|
2281 | 2281 |
|
2282 | |
A `goto` cannot appear within a `save` block, even if it is otherwise in tail position.
|
|
2282 |
A `goto` cannot appear within a `save` block.
|
2283 | 2283 |
|
2284 | 2284 |
| define other routine
|
2285 | 2285 |
| trashes a, z, n
|
|
2324 | 2324 |
| }
|
2325 | 2325 |
= ok
|
2326 | 2326 |
|
2327 | |
A `goto` cannot appear within a `with interrupts` block, even if it is
|
2328 | |
otherwise in tail position.
|
|
2327 |
A `goto` cannot appear within a `with interrupts` block.
|
2329 | 2328 |
|
2330 | 2329 |
| vector routine
|
2331 | 2330 |
| inputs x
|
|
2972 | 2971 |
| }
|
2973 | 2972 |
? UnmeaningfulOutputError: x
|
2974 | 2973 |
|
2975 | |
`goto`, if present, must be in tail position (the final instruction in a routine.)
|
|
2974 |
For now at least, you cannot have a `goto` inside a loop.
|
|
2975 |
|
|
2976 |
| define bar routine trashes x, z, n {
|
|
2977 |
| ld x, 200
|
|
2978 |
| }
|
|
2979 |
|
|
|
2980 |
| define main routine trashes x, z, n {
|
|
2981 |
| ld x, 0
|
|
2982 |
| repeat {
|
|
2983 |
| inc x
|
|
2984 |
| goto bar
|
|
2985 |
| } until z
|
|
2986 |
| }
|
|
2987 |
? IllegalJumpError
|
|
2988 |
|
|
2989 |
`goto`, as a matter of syntax, can only appear at the end
|
|
2990 |
of a block; but it need not be the final instruction in a
|
|
2991 |
routine. It is only important that the type context at every
|
|
2992 |
`goto` is compatible with the type context at the end of
|
|
2993 |
the routine.
|
2976 | 2994 |
|
2977 | 2995 |
| define bar routine trashes x, z, n {
|
2978 | 2996 |
| ld x, 200
|
|
2994 | 3012 |
| ld x, 1
|
2995 | 3013 |
| goto bar
|
2996 | 3014 |
| }
|
2997 | |
| ld x, 0
|
2998 | |
| }
|
2999 | |
? IllegalJumpError
|
|
3015 |
| }
|
|
3016 |
= ok
|
3000 | 3017 |
|
3001 | 3018 |
| define bar routine trashes x, z, n {
|
3002 | 3019 |
| ld x, 200
|
|
3008 | 3025 |
| ld x, 1
|
3009 | 3026 |
| goto bar
|
3010 | 3027 |
| }
|
|
3028 |
| goto bar
|
3011 | 3029 |
| }
|
3012 | 3030 |
= ok
|
3013 | 3031 |
|
|
3023 | 3041 |
| }
|
3024 | 3042 |
| ld x, 0
|
3025 | 3043 |
| }
|
3026 | |
? IllegalJumpError
|
|
3044 |
= ok
|
3027 | 3045 |
|
3028 | 3046 |
| define bar routine trashes x, z, n {
|
3029 | 3047 |
| ld x, 200
|
|
3056 | 3074 |
| }
|
3057 | 3075 |
= ok
|
3058 | 3076 |
|
3059 | |
For the purposes of `goto`, the end of a loop is never tail position.
|
3060 | |
|
3061 | 3077 |
| define bar routine trashes x, z, n {
|
3062 | 3078 |
| ld x, 200
|
3063 | 3079 |
| }
|
3064 | 3080 |
|
|
3065 | 3081 |
| define main routine trashes x, z, n {
|
3066 | 3082 |
| ld x, 0
|
3067 | |
| repeat {
|
3068 | |
| inc x
|
|
3083 |
| if z {
|
|
3084 |
| ld x, 1
|
3069 | 3085 |
| goto bar
|
3070 | |
| } until z
|
3071 | |
| }
|
3072 | |
? IllegalJumpError
|
|
3086 |
| } else {
|
|
3087 |
| ld x, 0
|
|
3088 |
| }
|
|
3089 |
| ld x, 0
|
|
3090 |
| }
|
|
3091 |
= ok
|
|
3092 |
|
|
3093 |
| define bar routine trashes x, z, n {
|
|
3094 |
| ld x, 200
|
|
3095 |
| }
|
|
3096 |
|
|
|
3097 |
| define main routine trashes x, z, n {
|
|
3098 |
| ld x, 0
|
|
3099 |
| if z {
|
|
3100 |
| ld x, 1
|
|
3101 |
| goto bar
|
|
3102 |
| } else {
|
|
3103 |
| ld x, 0
|
|
3104 |
| }
|
|
3105 |
| goto bar
|
|
3106 |
| }
|
|
3107 |
= ok
|
3073 | 3108 |
|
3074 | 3109 |
Can't `goto` a routine that outputs or trashes more than the current routine.
|
3075 | 3110 |
|