A minimalistic programming language written in C89.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
966 B

#include "ink.h"
#include <stdio.h>
#include <time.h>
int main(int argc, char** argv) {
char read_buffer[2048];
clock_t begin, end;
double time_spent;
struct context* ctx;
char** end_argv;
ctx = ink_make_default_context();
end_argv = argv + argc;
for(argv+=1; argv != end_argv; argv++) {
FILE* file;
size_t cnt;
file = fopen(*argv, "r");
cnt = fread(read_buffer, 1, 2047, file);
if(cnt == 0) {
fprintf(stderr, "Can't read file !! -> %s\n", *argv);
}
read_buffer[cnt] = 0;
ink_compile(ctx, read_buffer);
if(ctx->panic) {
fprintf(stderr, "Panicked !! -> %d\n", ctx->panic);
}
fclose(file);
}
begin = clock();
while(ink_can_run(ctx)) {
ink_step_everyone(ctx);
}
ink_gc(ctx);
end = clock();
time_spent = ctx->steps/((double)(end - begin) / CLOCKS_PER_SEC);
printf("\nExecuted in %u steps\nCollected %u times\nExecution freq: %uHz\n", ctx->steps, ctx->collections, (unsigned int)time_spent);
return ctx->panic;
}