Convert remainder of routine declarations in this file.
Chris Pressey
6 years ago
1423 | 1423 | Calling an extern is just the same as calling a defined routine with the |
1424 | 1424 | same constraints. |
1425 | 1425 | |
1426 | | routine chrout | |
1426 | | define chrout routine | |
1427 | 1427 | | inputs a |
1428 | 1428 | | trashes a |
1429 | 1429 | | @ 65490 |
1436 | 1436 | | } |
1437 | 1437 | = ok |
1438 | 1438 | |
1439 | | routine chrout | |
1439 | | define chrout routine | |
1440 | 1440 | | inputs a |
1441 | 1441 | | trashes a |
1442 | 1442 | | @ 65490 |
1448 | 1448 | | } |
1449 | 1449 | ? UnmeaningfulReadError: a |
1450 | 1450 | |
1451 | | routine chrout | |
1451 | | define chrout routine | |
1452 | 1452 | | inputs a |
1453 | 1453 | | trashes a |
1454 | 1454 | | @ 65490 |
2263 | 2263 | | inc x |
2264 | 2264 | | } |
2265 | 2265 | | |
2266 | | routine other | |
2266 | | define other routine | |
2267 | 2267 | | trashes bar, a, n, z |
2268 | 2268 | | { |
2269 | 2269 | | ld a, 0 |
2883 | 2883 | |
2884 | 2884 | | vector routine trashes x, z, n foo |
2885 | 2885 | | |
2886 | | routine bar trashes x, z, n { | |
2886 | | define bar routine trashes x, z, n { | |
2887 | 2887 | | ld x, 200 |
2888 | 2888 | | } |
2889 | 2889 | | |
2890 | | routine main outputs x, foo trashes z, n { | |
2890 | | define main routine outputs x, foo trashes z, n { | |
2891 | 2891 | | ld x, 0 |
2892 | 2892 | | copy bar, foo |
2893 | 2893 | | call foo |
2896 | 2896 | |
2897 | 2897 | `goto`, if present, must be in tail position (the final instruction in a routine.) |
2898 | 2898 | |
2899 | | routine bar trashes x, z, n { | |
2899 | | define bar routine trashes x, z, n { | |
2900 | 2900 | | ld x, 200 |
2901 | 2901 | | } |
2902 | 2902 | | |
2903 | | routine main trashes x, z, n { | |
2903 | | define main routine trashes x, z, n { | |
2904 | 2904 | | ld x, 0 |
2905 | 2905 | | goto bar |
2906 | 2906 | | } |
2907 | 2907 | = ok |
2908 | 2908 | |
2909 | | routine bar trashes x, z, n { | |
2909 | | define bar routine trashes x, z, n { | |
2910 | 2910 | | ld x, 200 |
2911 | 2911 | | } |
2912 | 2912 | | |
2913 | | routine main trashes x, z, n { | |
2913 | | define main routine trashes x, z, n { | |
2914 | 2914 | | goto bar |
2915 | 2915 | | ld x, 0 |
2916 | 2916 | | } |
2917 | 2917 | ? IllegalJumpError |
2918 | 2918 | |
2919 | | routine bar trashes x, z, n { | |
2919 | | define bar routine trashes x, z, n { | |
2920 | 2920 | | ld x, 200 |
2921 | 2921 | | } |
2922 | 2922 | | |
2923 | | routine main trashes x, z, n { | |
2923 | | define main routine trashes x, z, n { | |
2924 | 2924 | | ld x, 0 |
2925 | 2925 | | if z { |
2926 | 2926 | | ld x, 1 |
2929 | 2929 | | } |
2930 | 2930 | = ok |
2931 | 2931 | |
2932 | | routine bar trashes x, z, n { | |
2932 | | define bar routine trashes x, z, n { | |
2933 | 2933 | | ld x, 200 |
2934 | 2934 | | } |
2935 | 2935 | | |
2936 | | routine main trashes x, z, n { | |
2936 | | define main routine trashes x, z, n { | |
2937 | 2937 | | ld x, 0 |
2938 | 2938 | | if z { |
2939 | 2939 | | ld x, 1 |
2943 | 2943 | | } |
2944 | 2944 | ? IllegalJumpError |
2945 | 2945 | |
2946 | | routine bar trashes x, z, n { | |
2946 | | define bar routine trashes x, z, n { | |
2947 | 2947 | | ld x, 200 |
2948 | 2948 | | } |
2949 | 2949 | | |
2950 | | routine main trashes x, z, n { | |
2950 | | define main routine trashes x, z, n { | |
2951 | 2951 | | ld x, 0 |
2952 | 2952 | | if z { |
2953 | 2953 | | ld x, 1 |
2959 | 2959 | | } |
2960 | 2960 | = ok |
2961 | 2961 | |
2962 | | routine bar trashes x, z, n { | |
2962 | | define bar routine trashes x, z, n { | |
2963 | 2963 | | ld x, 200 |
2964 | 2964 | | } |
2965 | 2965 | | |
2966 | | routine main trashes x, z, n { | |
2966 | | define main routine trashes x, z, n { | |
2967 | 2967 | | ld x, 0 |
2968 | 2968 | | if z { |
2969 | 2969 | | ld x, 1 |
2976 | 2976 | |
2977 | 2977 | For the purposes of `goto`, the end of a loop is never tail position. |
2978 | 2978 | |
2979 | | routine bar trashes x, z, n { | |
2979 | | define bar routine trashes x, z, n { | |
2980 | 2980 | | ld x, 200 |
2981 | 2981 | | } |
2982 | 2982 | | |
2983 | | routine main trashes x, z, n { | |
2983 | | define main routine trashes x, z, n { | |
2984 | 2984 | | ld x, 0 |
2985 | 2985 | | repeat { |
2986 | 2986 | | inc x |
2991 | 2991 | |
2992 | 2992 | Can't `goto` a routine that outputs or trashes more than the current routine. |
2993 | 2993 | |
2994 | | routine bar trashes x, y, z, n { | |
2994 | | define bar routine trashes x, y, z, n { | |
2995 | 2995 | | ld x, 200 |
2996 | 2996 | | ld y, 200 |
2997 | 2997 | | } |
2998 | 2998 | | |
2999 | | routine main trashes x, z, n { | |
2999 | | define main routine trashes x, z, n { | |
3000 | 3000 | | ld x, 0 |
3001 | 3001 | | goto bar |
3002 | 3002 | | } |
3003 | 3003 | ? IncompatibleConstraintsError |
3004 | 3004 | |
3005 | | routine bar outputs y trashes z, n { | |
3005 | | define bar routine outputs y trashes z, n { | |
3006 | 3006 | | ld y, 200 |
3007 | 3007 | | } |
3008 | 3008 | | |
3009 | | routine main trashes x, z, n { | |
3009 | | define main routine trashes x, z, n { | |
3010 | 3010 | | ld x, 0 |
3011 | 3011 | | goto bar |
3012 | 3012 | | } |
3014 | 3014 | |
3015 | 3015 | Can `goto` a routine that outputs or trashes less than the current routine. |
3016 | 3016 | |
3017 | | routine bar trashes x, z, n { | |
3017 | | define bar routine trashes x, z, n { | |
3018 | 3018 | | ld x, 1 |
3019 | 3019 | | } |
3020 | 3020 | | |
3021 | | routine main trashes a, x, z, n { | |
3021 | | define main routine trashes a, x, z, n { | |
3022 | 3022 | | ld a, 0 |
3023 | 3023 | | ld x, 0 |
3024 | 3024 | | goto bar |
3029 | 3029 | |
3030 | 3030 | | vector routine outputs x trashes a, z, n foo |
3031 | 3031 | | |
3032 | | routine bar outputs x trashes a, z, n { | |
3032 | | define bar routine outputs x trashes a, z, n { | |
3033 | 3033 | | ld x, 200 |
3034 | 3034 | | } |
3035 | 3035 | | |
3036 | | routine main outputs x trashes foo, a, z, n { | |
3036 | | define main routine outputs x trashes foo, a, z, n { | |
3037 | 3037 | | copy bar, foo |
3038 | 3038 | | goto foo |
3039 | 3039 | | } |
3046 | 3046 | | trashes a, x, z, n |
3047 | 3047 | | foo |
3048 | 3048 | | |
3049 | | routine bar | |
3049 | | define bar routine | |
3050 | 3050 | | trashes a, x, z, n { |
3051 | 3051 | | ld x, 200 |
3052 | 3052 | | } |
3053 | 3053 | | |
3054 | | routine sub | |
3054 | | define sub routine | |
3055 | 3055 | | trashes foo, a, x, z, n { |
3056 | 3056 | | ld x, 0 |
3057 | 3057 | | copy bar, foo |
3058 | 3058 | | goto foo |
3059 | 3059 | | } |
3060 | 3060 | | |
3061 | | routine main | |
3061 | | define main routine | |
3062 | 3062 | | outputs a |
3063 | 3063 | | trashes foo, x, z, n { |
3064 | 3064 | | call sub |