#include "ctx.h" #include #include static void init_builtin_types(struct ctx *ctx) { for (size_t i = 0; i < TYPE_OTHER; i++) { ctx->ctx_builtin_types[i].ty_id = i; } } struct ctx *ctx_create(void) { struct ctx *out = malloc(sizeof *out); if (!out) { return NULL; } memset(out, 0x0, sizeof *out); init_builtin_types(out); return out; } void ctx_destroy(struct ctx *ctx) { free(ctx); } const struct type *ctx_get_type(struct ctx *ctx, const char *name) { if (!strcmp(name, "string")) { return ctx_get_builtin_type(ctx, TYPE_STRING); } if (!strcmp(name, "int")) { return ctx_get_builtin_type(ctx, TYPE_INT); } if (!strcmp(name, "handle")) { return ctx_get_builtin_type(ctx, TYPE_HANDLE); } return NULL; } const struct type *ctx_get_builtin_type(struct ctx *ctx, enum type_id id) { if (id >= TYPE_OTHER) { return NULL; } return &ctx->ctx_builtin_types[id]; }