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.

65 lines
1.3 KiB

пре 4 месеци
пре 4 месеци
пре 4 месеци
  1. #pragma once
  2. #include "stddef.h"
  3. #define INK_INTEGER 0
  4. #define INK_NATIVE_FUNCTION 1
  5. #define INK_FUNCTION 2
  6. struct elem {
  7. int type;
  8. int value;
  9. };
  10. struct stack_frame {
  11. struct elem executing;
  12. int index;
  13. };
  14. struct fn {
  15. char* name;
  16. struct elem* things;
  17. int size;
  18. };
  19. struct context;
  20. struct native_fn {
  21. char* name;
  22. void(*value)(struct context*);
  23. };
  24. struct context {
  25. int panic;
  26. void*(*malloc)(size_t);
  27. void*(*realloc)(void*, size_t);
  28. void(*free)(void*);
  29. int(*putchar)(int);
  30. struct elem* stack;
  31. int capacity;
  32. int top;
  33. struct stack_frame* function_stack;
  34. int function_stack_capacity;
  35. int function_stack_top;
  36. struct native_fn* native_words;
  37. int native_words_capacity;
  38. int native_words_top;
  39. struct fn* words;
  40. int words_capacity;
  41. int words_top;
  42. char** lex_reserved_words;
  43. int lex_reserved_words_capacity;
  44. int lex_reserved_words_top;
  45. };
  46. void ink_add_native(struct context* ctx, const char* name, void(*value)(struct context*));
  47. void ink_push(struct context* ctx, struct elem value);
  48. void ink_push_fn(struct context* ctx, struct stack_frame value);
  49. struct context* ink_make_context(void*(*malloc)(size_t), void*(*realloc)(void*, size_t), void(*free)(void*), int(*putchar)(int));
  50. struct context* ink_make_default_context();
  51. int ink_step(struct context *pContext);
  52. void ink_run(struct context *pContext, char* buffer);