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.

64 lines
1.3 KiB

4 months ago
  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. struct elem* stack;
  30. int capacity;
  31. int top;
  32. struct stack_frame* function_stack;
  33. int function_stack_capacity;
  34. int function_stack_top;
  35. struct native_fn* native_words;
  36. int native_words_capacity;
  37. int native_words_top;
  38. struct fn* words;
  39. int words_capacity;
  40. int words_top;
  41. char** lex_reserved_words;
  42. int lex_reserved_words_capacity;
  43. int lex_reserved_words_top;
  44. };
  45. void ink_add_native(struct context* ctx, const char* name, void(*value)(struct context*));
  46. void ink_push(struct context* ctx, struct elem value);
  47. void ink_push_fn(struct context* ctx, struct stack_frame value);
  48. struct context* ink_make_context(void*(*malloc)(size_t), void*(*realloc)(void*, size_t), void(*free)(void*));
  49. struct context* ink_make_default_context();
  50. int ink_step(struct context *pContext);
  51. void ink_run(struct context *pContext, char* buffer);