vessel/old/temple.h
2025-06-13 17:58:13 +03:00

82 lines
2.6 KiB
C

#ifndef _VESSEL_TEMPLE_H
#define _VESSEL_TEMPLE_H
#include "conf.h"
#include <vessel/def.h>
#include <vessel/hmap.h>
#include <vessel/file.h>
#include <vessel/thread.h>
#define TEMPLE_STACK_MAX 4096
#define TEMPLE_FLAG_NONE ((uint32_t)(0x0))
#define TEMPLE_FLAG_ALLOW_PARTIAL ((uint32_t)(0x80000000))
#define TEMPLE_FLAG_ALLOW_STACK ((uint32_t)(0x40000000))
#define TEMPLE_FLAG_ALLOW_LABELS ((uint32_t)(0x20000000))
#define TEMPLE_FLAG_ALLOW_VARS_READ ((uint32_t)(0x10000000))
#define TEMPLE_FLAG_ALLOW_VARS_WRITE ((uint32_t)(0x8000000))
#define TEMPLE_FLAG_ALLOW_TIME ((uint32_t)(0x4000000))
#define TEMPLE_FLAG_ALLOW_ARGS ((uint32_t)(0x2000000))
#define TEMPLE_FLAG_PERFORM_SANITY_CHECKS ((uint32_t)(0x1000000))
#define TEMPLE_FLAG_ALLOW_EXTERNAL_TEMPLATES ((uint32_t)(0x800000))
#define TEMPLE_FLAG_ALLOW_EXTERNAL_CALLS ((uint32_t)(0x400000))
#define TEMPLE_FLAG_ALLOW_BINARY ((uint32_t)(0x200000))
#define TEMPLE_FLAG_ALLOW_RUNTIME_TEMPLATES ((uint32_t)(0x100000))
#define TEMPLE_FLAG_ALLOW_CACHING ((uint32_t)(0x80000))
#define TEMPLE_FLAG_ALLOW_L10N ((uint32_t)(0x40000))
#define TEMPLE_FLAG_ALLOW_HMAP_OPERATIONS ((uint32_t)(0x20000))
#define TEMPLE_FLAG_ALLOW_ARRAY_OPERATIONS ((uint32_t)(0x10000))
#define TEMPLE_FLAG_ALLOW_STRUCT_OPERATIONS ((uint32_t)(0x8000))
#define TEMPLE_FLAG_ALLOW_TAMPERING ((uint32_t)(0x4000))
typedef enum {
TempleType_bin = 0x0,
TempleType_str = 0x1,
TempleType_ustr = 0x2,
TempleType_i8 = 0x3,
TempleType_u8 = 0x4,
TempleType_i16 = 0x5,
TempleType_u16 = 0x6,
TempleType_i32 = 0x7,
TempleType_u32 = 0x8,
TempleType_i64 = 0x9,
TempleType_u64 = 0xa,
TempleType_array = 0xb,
TempleType_hmap = 0xc,
TempleType_struct = 0xd,
} TempleType;
typedef struct {
TempleType type;
uint32_t value_size;
void *value;
} TempleItem;
typedef struct {
Bool render;
double start;
HMap vars;
TempleItem *stack;
uint16_t sdx;
uint64_t cdx, old_cdx;
Lock lock;
} TempleState;
typedef struct {
File f;
uint8_t magic[6];
uint8_t digest[32];
uint16_t version;
uint32_t flags;
uint64_t code_start;
} Temple;
Bool Temple_init(Temple *temple);
Bool Temple_open(Temple *temple, const char *path);
Bool Temple_destroy(Temple *temple);
Bool TempleState_init(TempleState *state, Temple *temple);
Bool TempleState_destroy(TempleState *state, const Temple *temple);
#endif /* _VESSEL_TEMPLE_H */