2020-12-26 03:32:21 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "kuroko.h"
|
|
|
|
|
|
|
|
typedef struct Obj KrkObj;
|
|
|
|
typedef struct ObjString KrkString;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
VAL_NONE,
|
2020-12-26 08:33:34 +03:00
|
|
|
VAL_BOOLEAN,
|
2020-12-26 03:32:21 +03:00
|
|
|
VAL_INTEGER,
|
|
|
|
VAL_FLOATING,
|
2020-12-29 05:00:12 +03:00
|
|
|
VAL_HANDLER,
|
2020-12-26 03:32:21 +03:00
|
|
|
VAL_OBJECT,
|
2021-01-03 06:09:41 +03:00
|
|
|
VAL_KWARGS,
|
2020-12-26 03:32:21 +03:00
|
|
|
/* More here later */
|
|
|
|
} KrkValueType;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
KrkValueType type;
|
|
|
|
union {
|
2020-12-28 10:32:40 +03:00
|
|
|
char boolean;
|
|
|
|
long integer;
|
2020-12-26 03:32:21 +03:00
|
|
|
double floating;
|
2020-12-29 05:00:12 +03:00
|
|
|
long handler;
|
2020-12-26 03:32:21 +03:00
|
|
|
KrkObj * object;
|
|
|
|
} as;
|
|
|
|
} KrkValue;
|
|
|
|
|
|
|
|
#define BOOLEAN_VAL(value) ((KrkValue){VAL_BOOLEAN, {.boolean = value}})
|
|
|
|
#define NONE_VAL(value) ((KrkValue){VAL_NONE, {.integer = 0}})
|
|
|
|
#define INTEGER_VAL(value) ((KrkValue){VAL_INTEGER, {.integer = value}})
|
|
|
|
#define FLOATING_VAL(value) ((KrkValue){VAL_FLOATING,{.floating = value}})
|
2020-12-29 05:00:12 +03:00
|
|
|
#define HANDLER_VAL(value) ((KrkValue){VAL_HANDLER, {.handler = value}})
|
2020-12-26 03:32:21 +03:00
|
|
|
#define OBJECT_VAL(value) ((KrkValue){VAL_OBJECT, {.object = (KrkObj*)value}})
|
2021-01-03 06:09:41 +03:00
|
|
|
#define KWARGS_VAL(value) ((KrkValue){VAL_KWARGS, {.integer = value}})
|
2020-12-26 03:32:21 +03:00
|
|
|
|
|
|
|
#define AS_BOOLEAN(value) ((value).as.boolean)
|
|
|
|
#define AS_INTEGER(value) ((value).as.integer)
|
|
|
|
#define AS_FLOATING(value) ((value).as.floating)
|
2020-12-29 05:00:12 +03:00
|
|
|
#define AS_HANDLER(value) ((value).as.handler)
|
2020-12-26 03:32:21 +03:00
|
|
|
#define AS_OBJECT(value) ((value).as.object)
|
|
|
|
|
|
|
|
#define IS_BOOLEAN(value) ((value).type == VAL_BOOLEAN)
|
|
|
|
#define IS_NONE(value) ((value).type == VAL_NONE)
|
|
|
|
#define IS_INTEGER(value) ((value).type == VAL_INTEGER)
|
|
|
|
#define IS_FLOATING(value) ((value).type == VAL_FLOATING)
|
2020-12-29 05:00:12 +03:00
|
|
|
#define IS_HANDLER(value) ((value).type == VAL_HANDLER)
|
2020-12-26 03:32:21 +03:00
|
|
|
#define IS_OBJECT(value) ((value).type == VAL_OBJECT)
|
2021-01-03 06:09:41 +03:00
|
|
|
#define IS_KWARGS(value) ((value).type == VAL_KWARGS)
|
2020-12-26 03:32:21 +03:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
size_t capacity;
|
|
|
|
size_t count;
|
|
|
|
KrkValue * values;
|
|
|
|
} KrkValueArray;
|
|
|
|
|
|
|
|
extern void krk_initValueArray(KrkValueArray * array);
|
|
|
|
extern void krk_writeValueArray(KrkValueArray * array, KrkValue value);
|
|
|
|
extern void krk_freeValueArray(KrkValueArray * array);
|
|
|
|
extern void krk_printValue(FILE * f, KrkValue value);
|
2021-01-01 10:01:58 +03:00
|
|
|
extern void krk_printValueSafe(FILE * f, KrkValue value);
|
2020-12-26 03:32:21 +03:00
|
|
|
extern int krk_valuesEqual(KrkValue a, KrkValue b);
|
|
|
|
|