A minimalistic programming language written in C89.
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

122 linhas
3.5 KiB

  1. #include "ink.h"
  2. int main(int argc, char** argv) {
  3. struct context* ctx;
  4. ctx = ink_make_default_context();
  5. ink_compile(
  6. ctx,
  7. "fn encrypt do\n"
  8. " 3 pluck array.size\n"
  9. " # array add_key modulo_key index\n"
  10. " loop:\n"
  11. " 1 - dup 5 pluck\n"
  12. " # array add_key modulo_key index index array\n"
  13. " array.index \n"
  14. " # array add_key modulo_key index v\n"
  15. " 4 pluck +\n"
  16. " # array add_key modulo_key index (v + add_key)\n"
  17. " 3 pluck %\n"
  18. " # array add_key modulo_key index ((v + add_key) % modulo_key)\n"
  19. " 2 pluck\n"
  20. " # array add_key modulo_key index ((v + add_key) % modulo_key) index\n"
  21. " 6 pluck\n"
  22. " # array add_key modulo_key index ((v + add_key) % modulo_key) index array\n"
  23. " array.set\n"
  24. " # array add_key modulo_key index\n"
  25. " dup 0 != loop jump_if drop drop drop drop\n"
  26. "end\n"
  27. "fn string.dump do\n"
  28. " dup array.size 0\n"
  29. " # array end it\n"
  30. " 91 print_utf8\n"
  31. " 32 print_utf8\n"
  32. " loop:\n"
  33. " dup\n"
  34. " # array end it it\n"
  35. " 4 pluck\n"
  36. " # array end it it array\n"
  37. " array.index print_int\n"
  38. " 32 print_utf8\n"
  39. " 1 +\n"
  40. " # array end it\n"
  41. " 2 pluck 2 pluck > loop jump_if\n"
  42. " # array end it\n"
  43. " 93 print_utf8\n"
  44. " drop drop drop\n"
  45. "end\n"
  46. "fn string.print do\n"
  47. " dup array.size 0\n"
  48. " # array end it\n"
  49. " loop:\n"
  50. " dup\n"
  51. " # array end it it\n"
  52. " 4 pluck\n"
  53. " # array end it it array\n"
  54. " array.index print_utf8\n"
  55. " 1 +\n"
  56. " # array end it\n"
  57. " 2 pluck 2 pluck > loop jump_if\n"
  58. " # array end it\n"
  59. " drop drop drop\n"
  60. "end"
  61. );
  62. ink_compile(
  63. ctx,
  64. "# Clones an array, creating a new array\n"
  65. "#\n"
  66. "# @param array The array to clone into a new array\n"
  67. "# @return a new array that contains the same elements as the source array\n"
  68. "#\n"
  69. "# array -> new_array\n"
  70. "fn array.clone do\n"
  71. " array.new 2 pluck array.size 0\n"
  72. " # array new_array end it\n"
  73. " 2 pluck 2 pluck == l jump_if\n"
  74. " # array new_array end it\n"
  75. " loop:\n"
  76. " dup 5 pluck\n"
  77. " # array new_array end it it array\n"
  78. " array.index 4 pluck\n"
  79. " # array new_array end it v new_array\n"
  80. " array.push\n"
  81. " # array new_array end it\n"
  82. " 1 +\n"
  83. " 2 pluck 2 pluck > loop jump_if\n"
  84. " l: drop drop swap drop\n"
  85. " # new_array\n"
  86. "end"
  87. );
  88. ink_compile(
  89. ctx,
  90. "[ 72 101 108 108 111 32 87 111 114 108 100 10 ] dup dup dup string.print\n"
  91. "32 131 encrypt string.dump\n"
  92. "[ 72 101 108 108 111 32 87 111 114 108 100 10 ] dup dup dup string.print\n"
  93. "32 131 encrypt string.dump\n"
  94. "[ 72 101 108 108 111 32 87 111 114 108 100 10 ] dup dup dup string.print\n"
  95. "32 131 encrypt string.dump\n"
  96. "[ 72 101 108 108 111 32 87 111 114 108 100 10 ] dup dup dup string.print\n"
  97. "32 131 encrypt string.dump\n"
  98. "[ 72 101 108 108 111 32 87 111 114 108 100 10 ] dup dup dup string.print\n"
  99. "32 131 encrypt string.dump\n"
  100. );
  101. //ctx->routines[coro].panic = 0;
  102. int increment = 16;
  103. int counter = increment;
  104. int c;
  105. while(ink_can_run(ctx)) {
  106. ink_step_everyone(ctx);
  107. if(ctx->steps > counter) {
  108. ink_gc(ctx);
  109. counter += increment;
  110. }
  111. }
  112. //return ctx->routines[coro].panic != INK_ROUTINE_SUCCESS && ctx->routines[coro].panic != INK_ROUTINE_CAN_REUSE;
  113. }