lama_byterun/runtime/runtime_common.h

75 lines
2.3 KiB
C
Raw Normal View History

#ifndef __LAMA_RUNTIME_COMMON__
#define __LAMA_RUNTIME_COMMON__
#include <stddef.h>
// this flag makes GC behavior a bit different for testing purposes.
//#define DEBUG_VERSION
//#define FULL_INVARIANT_CHECKS
2023-05-31 11:01:11 +02:00
#define STRING_TAG 0x00000001
#define ARRAY_TAG 0x00000003
#define SEXP_TAG 0x00000005
#define CLOSURE_TAG 0x00000007
#define UNBOXED_TAG 0x00000009 // Not actually a data_header; used to return from LkindOf
2024-01-26 18:45:03 +01:00
#define LEN(x) (long)(((int)x & 0xFFFFFFF8) >> 3)
2023-05-31 11:01:11 +02:00
#define TAG(x) (x & 0x00000007)
2023-08-09 20:16:51 +02:00
#define SEXP_ONLY_HEADER_SZ (sizeof(int))
#ifndef DEBUG_VERSION
2024-01-26 18:45:03 +01:00
// # define DATA_HEADER_SZ (sizeof(size_t) + sizeof(int))
# define DATA_HEADER_SZ (sizeof(size_t) + sizeof(long))
2023-05-31 11:01:11 +02:00
#else
# define DATA_HEADER_SZ (sizeof(size_t) + sizeof(size_t) + sizeof(int))
#endif
2024-01-30 18:16:44 +01:00
#define MEMBER_SIZE sizeof(long)
2023-05-31 11:01:11 +02:00
#define TO_DATA(x) ((data *)((char *)(x)-DATA_HEADER_SZ))
2023-08-09 20:16:51 +02:00
#define TO_SEXP(x) ((sexp *)((char *)(x)-DATA_HEADER_SZ))
2024-01-26 18:45:03 +01:00
#define UNBOXED(x) (((long)(x)) & 0x0001)
#define UNBOX(x) (((long)(x)) >> 1)
#define BOX(x) ((((long)(x)) << 1) | 0x0001)
2023-05-31 11:01:11 +02:00
#define BYTES_TO_WORDS(bytes) (((bytes)-1) / sizeof(size_t) + 1)
#define WORDS_TO_BYTES(words) ((words) * sizeof(size_t))
// CAREFUL WITH DOUBLE EVALUATION!
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
typedef struct {
2023-05-31 11:01:11 +02:00
// store tag in the last three bits to understand what structure this is, other bits are filled with
// other utility info (i.e., size for array, number of fields for s-expression)
2024-01-26 18:45:03 +01:00
long data_header;
#ifdef DEBUG_VERSION
2023-05-31 11:01:11 +02:00
size_t id;
#endif
2023-05-31 11:01:11 +02:00
// last bit is used as MARK-BIT, the rest are used to store address where object should move
// last bit can be used because due to alignment we can assume that last two bits are always 0's
size_t forward_address;
char contents[0];
} data;
typedef struct {
2023-08-09 20:16:51 +02:00
// store tag in the last three bits to understand what structure this is, other bits are filled with
// other utility info (i.e., size for array, number of fields for s-expression)
2024-01-26 18:45:03 +01:00
long data_header;
2023-08-09 20:16:51 +02:00
#ifdef DEBUG_VERSION
2023-08-09 20:16:51 +02:00
size_t id;
#endif
// last bit is used as MARK-BIT, the rest are used to store address where object should move
// last bit can be used because due to alignment we can assume that last two bits are always 0's
size_t forward_address;
int tag;
2024-01-30 18:16:44 +01:00
long contents[0];
} sexp;
2023-05-31 11:01:11 +02:00
#endif