A minimalistic programming language written in C89.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

104 lignes
2.0 KiB

il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
il y a 4 mois
  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. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. struct elem {
  12. int type;
  13. int value;
  14. };
  15. struct stack_frame {
  16. struct elem executing;
  17. int index;
  18. };
  19. struct fn {
  20. char *name;
  21. struct elem *things;
  22. int size;
  23. };
  24. struct context;
  25. struct native_fn {
  26. char *name;
  27. void (*value)(struct context *);
  28. };
  29. struct ink_routine {
  30. int panic;
  31. struct elem *stack;
  32. int capacity;
  33. int top;
  34. struct stack_frame *function_stack;
  35. int function_stack_capacity;
  36. int function_stack_top;
  37. void *routine_userdata;
  38. };
  39. struct context {
  40. int panic;
  41. void *(*malloc)(size_t);
  42. void *(*realloc)(void *, size_t);
  43. void (*free)(void *);
  44. int (*putchar)(int);
  45. struct ink_routine *routines;
  46. int routines_capacity;
  47. int routines_top;
  48. int routine_current;
  49. struct native_fn *native_words;
  50. int native_words_capacity;
  51. int native_words_top;
  52. struct fn *words;
  53. int words_capacity;
  54. int words_top;
  55. char **lex_reserved_words;
  56. int lex_reserved_words_capacity;
  57. int lex_reserved_words_top;
  58. unsigned int steps;
  59. void *persistent_userdata;
  60. };
  61. int ink_make_routine(struct context *ctx);
  62. int ink_kill_routine(struct context *ctx, int routine);
  63. int ink_add_native(struct context *ctx, const char *name, void(*value)(struct context *));
  64. int ink_push(struct context *ctx, struct elem value);
  65. int ink_push_fn(struct context *ctx, struct stack_frame value);
  66. struct context* ink_make_context(void *(*malloc)(size_t), void *(*realloc)(void *, size_t), void(*free)(void *), int(*putchar)(int));
  67. #ifndef NOSTDLIB
  68. struct context* ink_make_default_context();
  69. #endif
  70. int ink_step(struct context *pContext);
  71. int ink_can_run(struct context *pContext);
  72. int ink_step_everyone(struct context *pContext);
  73. void ink_compile(struct context *pContext, char *buffer);
  74. int ink_std_library(struct context *ctx);
  75. void ink_pop_fn(struct context *ctx);
  76. void ink_pop(struct context *ctx);
  77. #ifdef __cplusplus
  78. };
  79. #endif