2026-02-26 19:44:21 +00:00
|
|
|
#include "ctx.h"
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-06 20:15:29 +00:00
|
|
|
if (!strcmp(name, "handle")) {
|
|
|
|
|
return ctx_get_builtin_type(ctx, TYPE_HANDLE);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-10 19:12:14 +00:00
|
|
|
if (!strcmp(name, "size")) {
|
|
|
|
|
return ctx_get_builtin_type(ctx, TYPE_SIZE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!strcmp(name, "buffer")) {
|
|
|
|
|
return ctx_get_builtin_type(ctx, TYPE_BUFFER);
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-26 19:44:21 +00:00
|
|
|
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];
|
|
|
|
|
}
|