#include <perms.h>
// Edinburgh IMP77 Compiler - Version 8.4
//
// 1
// 2 %begin
int main(int argc, char **argv) { /*%begin*/
_imp_initialise(argc, argv);
// 3 %routine Tabulate (%longrealfn func(%longreal x),%longreal from,to,
void TABULATE(double (*FUNC)(double X), double FROM, double TO, int STEPS) {
// 4+ %integer steps)
// 5 ! func(x) is the dummy formal function
// 6 %real value,inc
float VALUE;
float INC;
// 7 %integer i
int I;
// 8 !
// 9 inc=(to-from)/steps
INC = (double)((TO - FROM) / STEPS);
// 10 !
// 11 value=from
VALUE = FROM;
// 12 %for i=0,1,steps %cycle
// %for I = 0, 1, STEPS %cycle
{
int _final = STEPS;
if (invalid_for_loop(0, 1, _final)) _imp_signal(5, 1, 0, "Illegal cycle I = 0, 1, STEPS");
I = -1;
L_0001:
if (I == _final) goto L_0002;
I += 1;
// 13 print(value,4,2) ; print(func(value),10,4) ; newline
_imp_PRINT(VALUE, 4, 2);
_imp_PRINT(FUNC(VALUE), 10, 4);
_imp_NEWLINE();
// 14 value=value+inc
VALUE = VALUE + INC;
// 15 %repeat
goto L_0001;
}
L_0002:;
// 16 %end ;! of routine tabulate
return;
} /* end of TABULATE */
// 17 !
// 18 ! now call with some functions....
// 19 printstring("
_imp_PRINTSTRING(_imp_str_literal("\n x sine(x)\n"));
// 20+ x sine(x)
// 21+ ")
// 22 tabulate ( sin, 0.0,pi/2,10)
TABULATE(_imp_SIN, 0.0, (double)(_imp_PI() / 2), 10);
// 23 ! note that the function name appears WITHOUT parameters in the call
// 24 !
// 25 printstring("
_imp_PRINTSTRING(_imp_str_literal("\n x squareroot(x)\n"));
// 26+ x squareroot(x)
// 27+ ")
// 28 tabulate( sqrt, 0.0,10.0,5)
TABULATE(_imp_SQRT, 0.0, 10.0, 5);
// 29 !
// 30 %endofprogram
_imp_stop(0);
return 0;
end_0:;
}