Files
rosetta/toolchain/ifc/ctx.c
Max Wash b631fca0fd toolchain: add a program for compiling ipc interface definitions
ifc can be used to compile .if files into self-contained header-only C
libraries, which can be used to send/receive messages that conform
to the described interface.
2026-02-26 19:44:32 +00:00

53 lines
836 B
C

#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);
}
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];
}