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.

91 rivejä
1.9 KiB

4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
4 kuukautta sitten
  1. #pragma once
  2. #include "stddef.h"
  3. #define INK_INTEGER 0
  4. #define INK_NATIVE_FUNCTION 1
  5. #define INK_FUNCTION 2
  6. #define INK_ROUTINE_CAN_REUSE 32
  7. #define INK_ROUTINE_SUCCESS 1
  8. struct elem {
  9. int type;
  10. int value;
  11. };
  12. struct stack_frame {
  13. struct elem executing;
  14. int index;
  15. };
  16. struct fn {
  17. char* name;
  18. struct elem* things;
  19. int size;
  20. };
  21. struct context;
  22. struct native_fn {
  23. char* name;
  24. void(*value)(struct context*);
  25. };
  26. struct ink_routine {
  27. int panic;
  28. struct elem* stack;
  29. int capacity;
  30. int top;
  31. struct stack_frame* function_stack;
  32. int function_stack_capacity;
  33. int function_stack_top;
  34. void* routine_userdata;
  35. };
  36. struct context {
  37. int panic;
  38. void*(*malloc)(size_t);
  39. void*(*realloc)(void*, size_t);
  40. void(*free)(void*);
  41. int(*putchar)(int);
  42. struct ink_routine* routines;
  43. int routines_capacity;
  44. int routines_top;
  45. int routine_current;
  46. struct native_fn* native_words;
  47. int native_words_capacity;
  48. int native_words_top;
  49. struct fn* words;
  50. int words_capacity;
  51. int words_top;
  52. char** lex_reserved_words;
  53. int lex_reserved_words_capacity;
  54. int lex_reserved_words_top;
  55. unsigned int steps;
  56. void* persistent_userdata;
  57. };
  58. int ink_make_routine(struct context* ctx);
  59. int ink_kill_routine(struct context* ctx, int routine);
  60. int ink_add_native(struct context* ctx, const char* name, void(*value)(struct context*));
  61. int ink_push(struct context* ctx, struct elem value);
  62. int ink_push_fn(struct context* ctx, struct stack_frame value);
  63. struct context* ink_make_context(void*(*malloc)(size_t), void*(*realloc)(void*, size_t), void(*free)(void*), int(*putchar)(int));
  64. #ifndef NOSTDLIB
  65. struct context* ink_make_default_context();
  66. #endif
  67. int ink_step(struct context *pContext);
  68. int ink_can_run(struct context *pContext);
  69. int ink_step_everyone(struct context* pContext);
  70. void ink_compile(struct context *pContext, char* buffer);
  71. int ink_std_library(struct context* ctx);
  72. void ink_pop_fn(struct context* ctx);
  73. void ink_pop(struct context* ctx);