| 1 |
#ifndef CARYLL_BK_BLOCK_H |
| 2 |
#define CARYLL_BK_BLOCK_H |
| 3 |
|
| 4 |
#include <stdint.h> |
| 5 |
#include <stdarg.h> |
| 6 |
#include <stdbool.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <limits.h> |
| 9 |
#include "caryll/ownership.h" |
| 10 |
#include "support/otfcc-alloc.h" |
| 11 |
#include "caryll/buffer.h" |
| 12 |
|
| 13 |
struct __caryll_bkblock; |
| 14 |
typedef enum { |
| 15 |
bkover = 0, // nothing |
| 16 |
b8 = 1, // byte |
| 17 |
b16 = 2, // short |
| 18 |
b32 = 3, // long |
| 19 |
p16 = 0x10, // 16-bit offset, p = pointer to block |
| 20 |
p32 = 0x11, // 32-bit offset, p = pointer to block |
| 21 |
sp16 = 0x80, // 16-bit offset, p = pointer to block, marked as compact |
| 22 |
sp32 = 0x81, // 32-bit offset, p = pointer to block, marked as compact |
| 23 |
bkcopy = 0xFE, // Embed another block |
| 24 |
bkembed = 0xFF // Embed another block |
| 25 |
} bk_CellType; |
| 26 |
typedef enum { VISIT_WHITE, VISIT_GRAY, VISIT_BLACK } bk_cell_visit_state; |
| 27 |
|
| 28 |
typedef struct { |
| 29 |
bk_CellType t; |
| 30 |
union { |
| 31 |
uint32_t z; |
| 32 |
struct __caryll_bkblock *p; |
| 33 |
}; |
| 34 |
} bk_Cell; |
| 35 |
|
| 36 |
typedef struct __caryll_bkblock { |
| 37 |
bk_cell_visit_state _visitstate; |
| 38 |
uint32_t _index; |
| 39 |
uint32_t _height; |
| 40 |
uint32_t _depth; |
| 41 |
uint32_t length; |
| 42 |
uint32_t free; |
| 43 |
bk_Cell *cells; |
| 44 |
} bk_Block; |
| 45 |
|
| 46 |
bk_Block *_bkblock_init(void); |
| 47 |
bk_Block *bk_new_Block(int type0, ...); |
| 48 |
bk_Block *bk_push(bk_Block *b, int type0, ...); |
| 49 |
bk_Block *bk_newBlockFromStringLen(size_t len, const char *str); |
| 50 |
bk_Block *bk_newBlockFromBuffer(MOVE caryll_Buffer *buf); |
| 51 |
bk_Block *bk_newBlockFromBufferCopy(OBSERVE caryll_Buffer *buf); |
| 52 |
bool bk_cellIsPointer(bk_Cell *cell); |
| 53 |
void bk_printBlock(bk_Block *b); |
| 54 |
|
| 55 |
#endif |