Files
fz-lang/src/compiler/fzl_token.c
T
2026-10-09 23:01:19 +03:00

29 lines
642 B
C

#include <compiler/fzl_token.h>
#include <stdlib.h>
#include <string.h>
fzl_token_t *fzl_mktoken(const fzl_toktype_t type, uint16_t from, uint16_t to,
void *value, size_t value_len)
{
void *valholder = malloc(value_len);
memcpy(valholder, value, value_len);
fzl_token_t *token = malloc(sizeof(fzl_token_t));
token->type = type;
token->i0 = from;
token->i1 = to;
token->store_value = value_len > 0;
token->value = valholder;
token->value_sz = value_len;
return token;
}
// Free allocated token
void fzl_freetoken(fzl_token_t *tok)
{
if (tok->store_value)
free(tok->value);
free(tok);
}