A minimalistic programming language written in C89.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. #include "ink.h"
  2. #include <stdio.h>
  3. #include <time.h>
  4. int main(int argc, char** argv) {
  5. char read_buffer[2048];
  6. struct timespec start_time, end_time;
  7. clock_t begin, end;
  8. double time_spent;
  9. double s_total = 0;
  10. struct context* ctx;
  11. char** end_argv;
  12. ctx = ink_make_default_context();
  13. end_argv = argv + argc;
  14. for(argv+=1; argv != end_argv; argv++) {
  15. FILE* file;
  16. size_t cnt;
  17. file = fopen(*argv, "r");
  18. cnt = fread(read_buffer, 1, 2047, file);
  19. if(cnt == 0) {
  20. fprintf(stderr, "Can't read file !! -> %s\n", *argv);
  21. }
  22. read_buffer[cnt] = 0;
  23. ink_compile(ctx, read_buffer);
  24. if(ctx->panic) {
  25. fprintf(stderr, "Panicked !! -> %d\n", ctx->panic);
  26. }
  27. fclose(file);
  28. }
  29. ink_compile(ctx, read_buffer);
  30. ink_compile(ctx, read_buffer);
  31. ink_compile(ctx, read_buffer);
  32. ink_compile(ctx, read_buffer);
  33. ink_compile(ctx, read_buffer);
  34. ink_compile(ctx, read_buffer);
  35. ink_compile(ctx, read_buffer);
  36. ink_compile(ctx, read_buffer);
  37. ink_compile(ctx, read_buffer);
  38. ink_compile(ctx, read_buffer);
  39. ink_compile(ctx, read_buffer);
  40. ink_compile(ctx, read_buffer);
  41. ink_compile(ctx, read_buffer);
  42. ink_compile(ctx, read_buffer);
  43. ink_compile(ctx, read_buffer);
  44. ink_compile(ctx, read_buffer);
  45. ink_compile(ctx, read_buffer);
  46. ink_compile(ctx, read_buffer);
  47. ink_compile(ctx, read_buffer);
  48. int increment = 1 << 16;
  49. int counter = increment;
  50. int c;
  51. begin = clock();
  52. clock_gettime(CLOCK_MONOTONIC, &start_time);
  53. while(ink_can_run(ctx)) {
  54. for(c = 0; c < 64; ++c)
  55. ink_step_everyone(ctx);
  56. if(ctx->steps < counter) {
  57. ink_gc(ctx);
  58. counter += increment;
  59. }
  60. }
  61. clock_gettime(CLOCK_MONOTONIC, &end_time);
  62. end = clock();
  63. time_spent = ctx->steps/(double)((end - begin) / CLOCKS_PER_SEC);
  64. s_total += (end_time.tv_sec - start_time.tv_sec) + (end_time.tv_nsec - start_time.tv_nsec) / 1.0e9;
  65. s_total = ctx->steps / s_total;
  66. printf("\nExecuted in %u steps\nCollected %u times\nExecution freq: %lfHz\n", ctx->steps, ctx->collections, s_total);
  67. return ctx->panic;
  68. }