#include <perms.h>
// Edinburgh IMP77 Compiler - Version 8.4
//
// 1 %begin
int main(int argc, char **argv) { /*%begin*/
_imp_enter(main);
_imp_initialise(argc, argv);
// 2 %string (15) smaller
_imp_string15 SMALLER;
// 3 %string (63) larger
_imp_string63 LARGER;
// 4
// 5 ! The assignment below should be checked at runtime but not fail
// 6 larger="A string"
_imp_strcpy(&LARGER, _imp_strp(_imp_str_literal("A string")), /*max:*/ 63);
// 7 smaller = larger
_imp_strcpy(&SMALLER, _imp_strp(LARGER), /*max:*/ 15);
// 8
// 9 ! This should not need to be checked:
// 10 larger = smaller
_imp_strcpy(&LARGER, _imp_strp(SMALLER), /*max:*/ 63);
// 11
// 12 ! The assignment below should fail at run time
// 13 larger="A string that is longer than 15 but less than 63"
_imp_strcpy(&LARGER, _imp_strp(_imp_str_literal("A string that is longer than 15 but less than 63")), /*max:*/ 63);
// 14 smaller = larger
_imp_strcpy(&SMALLER, _imp_strp(LARGER), /*max:*/ 15);
// 15
// 16 ! This construct should (erroneously) allow the assignment, but maybe C's Undefined Behaviour checks will catch it at runtime...
// 17 ! the STRING map which is declared as %string(*) is treated as if it were a %string(255).
// 18
// 19 ! STRING(ADDR(smaller)) = larger { however for the moment, this type of assignment is not being typecast properly in genc.c and so issues an error from C }
// 20
// 21 %endofprogram
_imp_stop(0);
end_0:;
_imp_begin_backtrace(main);
_imp_diagf("\n\nArguments:\n\n");
_imp_diagf("ARGC = %d\n", argc);
_imp_diagf("ARGV @[%p]\n", argv);
for (int i = 0; i < argc; i++) {
_imp_diagf(" ARGV(%d) = \"%s\"\n", i, argv[i]);
}
if (argv[argc] == 0) {
_imp_diagf(" ARGV(%d) = NULL\n", argc);
} else {
_imp_diagf(" ARGV(%d) = \"%s\"\n", argc, argv[argc]);
}
_imp_diagf("\nLocal Variables:\n\n");
_imp_diagf("SMALLER = \"%.*s\"\n", SMALLER.cstr.len, SMALLER.cstr.s);
_imp_diagf("LARGER = \"%.*s\"\n", LARGER.cstr.len, LARGER.cstr.s);
_imp_end_backtrace();
_imp_stop(0);
}