view src/ploki/val.h @ 8427:1fc808cd5b1f

<b_jonas> learn can\'t is the most frequent word whose pronunciation varies between /\xc9\x91\xcb\x90/ and /\xc3\xa6/ depending on dialect. The list is: advance after answer ask aunt brass can\'t cast castle chance class command dance demand draft enhance example fast father glass graph grass half last laugh mask master nasty pass past path plant rather sample shan\'t staff task vast
author HackBot
date Thu, 09 Jun 2016 21:28:47 +0000
parents ac0403686959
children
line wrap: on
line source

#ifndef VAL_H_
#define VAL_H_

#include "config.h"
#include "IO.h"
#include "Str.h"
#include "kork.h"
#include "list.h"
#include "sub.h"

enum val_cont {
	V_UNDEF = 0,
	V_STR_K = 1,
	V_NUM_K = V_STR_K << 1,
	V_EXT_K = V_NUM_K << 1,
	V_SUB_K = V_EXT_K << 1,
	V_LIST_K = V_SUB_K << 1
};

struct val {
	enum val_cont type;
	union {
		IO *ext;
		struct sub *sub;
		struct list *list;
	} magic;
	struct kork *ko;
	double num;
};

void v_init(struct val *);
void v_end(struct val *);
int v_cmp_ls(struct val *, struct val *);
void v_ok_str(struct val *);
void v_ok_num(struct val *);
int v_true(const struct val *);
void v_iniset(struct val *, const struct val *);
void v_set(struct val *, const struct val *);
void v_set_n(struct val *, double);
void v_set_s(struct val *, const String *);
void v_set_m(struct val *, const void *, size_t);
void v_set_undef(struct val *);
void v_set_io(struct val *, IO *);
void v_set_sub(struct val *, struct sub *);
void v_cat(struct val *, struct val *);
void v_cat_s(struct val *, const String *);
void v_cat_m(struct val *, const void *, size_t);
void v_cat_c(struct val *, char);
struct val *v_undef(void);
void v_delete(struct val *);

const char *v_sptr(struct val *, size_t *);
struct kork *v_kork(struct val *);

#define V_STR_P(v) ((v)->type & V_STR_K)
#define V_NUM_P(v) ((v)->type & V_NUM_K)
#define V_EXT_P(v) ((v)->type & V_EXT_K)
#define V_SUB_P(v) ((v)->type & V_SUB_K)
#define V_LIST_P(v) ((v)->type & V_LIST_K)

#define V_STR(v) if (V_STR_P(v)); else v_ok_str(v)
#define V_NUM(v) if (V_NUM_P(v)); else v_ok_num(v)

#define V_xxx_OFF(v)                \
do {                                \
	if (V_EXT_P(v)) {               \
		io_decr((v)->magic.ext);    \
		(v)->type &= ~V_EXT_K;      \
	} else if (V_SUB_P(v)) {        \
		sub_decr((v)->magic.sub);   \
		(v)->type &= ~V_SUB_K;      \
	} else if (V_LIST_P(v)) {       \
		li_delete((v)->magic.list); \
		(v)->type &= ~V_LIST_K;     \
	}                               \
} while (0)

#define RINT(x) ((x) + ((x) < 0.0 ? -.5 : .5))

#endif /* VAL_H_ */