Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/gravity
Path: blob/master/src/shared/gravity_value.h
1218 views
1
//
2
// gravity_value.h
3
// gravity
4
//
5
// Created by Marco Bambini on 11/12/14.
6
// Copyright (c) 2014 CreoLabs. All rights reserved.
7
//
8
9
#ifndef __GRAVITY_VALUES__
10
#define __GRAVITY_VALUES__
11
12
#include "gravity_memory.h"
13
#include "gravity_utils.h"
14
#include "gravity_array.h"
15
#include "gravity_json.h"
16
#include "debug_macros.h"
17
18
// Gravity is a dynamically typed language so a variable (gravity_value_t) can hold a value of any type.
19
20
// The representation of values in a dynamicly typed language is very important since it can lead to a big
21
// difference in terms of performance. Such representation has several contraints:
22
// - fast access
23
// - must represent several kind of values
24
// - be able to cope with the gargabe collector
25
// - low memory overhead (when allocating a lot of small values)
26
27
// In modern 64bit processor with OS that always returns aligned allocated memory blocks that means that each ptr is 8 bytes.
28
// That means that passing a value as an argument or storing it involves copying these bytes around (requiring 2/4 machine words).
29
// Values are not pointers but structures.
30
31
// The built-in types for booleans, numbers, floats, null, undefs are unboxed: their value is stored directly into gravity_value_t.
32
// Other types like classes, instances, functions, lists, and strings are all reference types. They are stored on the heap and
33
// the gravity_value_t just stores a pointer to it.
34
35
// So each value is a pointer to a FIXED size block of memory (16 bytes). Having all values of the same size greatly reduce the complexitly
36
// of a memory pool and since allocating a large amount of values is very commond is a dynamicly typed language like Gravity.
37
// In a future update I could introduce NaN tagging and squeeze value size to 8 bytes (that would mean nearly double performance).
38
39
// Internal settings to set integer and float size.
40
// Default is to have both int and float as 64bit.
41
42
// In a 64bit OS:
43
// sizeof(float) => 4 bytes
44
// sizeof(double) => 8 bytes
45
// sizeof(void*) => 8 bytes
46
// sizeof(int64_t) => 8 bytes
47
//
48
// sizeof various structs in a 64bit OS:
49
// STRUCT BYTES
50
// ====== =====
51
// gravity_function_t 104
52
// gravity_value_t 16
53
// gravity_upvalue_t 56
54
// gravity_closure_t 40
55
// gravity_list_t 48
56
// gravity_map_t 32
57
// gravity_callframe_t 48
58
// gravity_fiber_t 112
59
// gravity_class_t 88
60
// gravity_module_t 40
61
// gravity_instance_t 40
62
// gravity_string_t 48
63
// gravity_range_t 40
64
65
#define GRAVITY_VERSION "0.2.5"
66
#define GRAVITY_VERSION_NUMBER 0x000205
67
#define GRAVITY_BUILD_DATE __DATE__
68
69
#define GRAVITY_ENABLE_DOUBLE 1 // if 1 enable gravity_float_t to be a double (instead of a float)
70
#define GRAVITY_ENABLE_INT64 1 // if 1 enable gravity_int_t to be a 64bit int (intead of a 32bit int)
71
#define GRAVITY_COMPUTED_GOTO 1 // if 1 enable faster computed goto (instead of switch) for compilers that support it
72
#define GRAVITY_NULL_SILENT 1 // if 1 then messages sent to null does not produce any runtime error
73
#define GRAVITY_MAP_DOTSUGAR 0 // if 1 then map objects can be accessed with both map[key] and map.key
74
75
#define MAIN_FUNCTION "main"
76
#define ITERATOR_INIT_FUNCTION "iterate"
77
#define ITERATOR_NEXT_FUNCTION "next"
78
#define INITMODULE_NAME "$moduleinit"
79
#define CLASS_INTERNAL_INIT_NAME "$init"
80
#define CLASS_CONSTRUCTOR_NAME "init"
81
#define CLASS_DESTRUCTOR_NAME "deinit"
82
#define SELF_PARAMETER_NAME "self"
83
#define OUTER_IVAR_NAME "outer"
84
#define GETTER_FUNCTION_NAME "get"
85
#define SETTER_FUNCTION_NAME "set"
86
#define SETTER_PARAMETER_NAME "value"
87
88
#define GLOBALS_DEFAULT_SLOT 4096
89
#define CPOOL_INDEX_MAX 4096 // 2^12
90
#define CPOOL_VALUE_SUPER CPOOL_INDEX_MAX+1
91
#define CPOOL_VALUE_NULL CPOOL_INDEX_MAX+2
92
#define CPOOL_VALUE_UNDEFINED CPOOL_INDEX_MAX+3
93
#define CPOOL_VALUE_ARGUMENTS CPOOL_INDEX_MAX+4
94
#define CPOOL_VALUE_TRUE CPOOL_INDEX_MAX+5
95
#define CPOOL_VALUE_FALSE CPOOL_INDEX_MAX+6
96
#define CPOOL_VALUE_FUNC CPOOL_INDEX_MAX+7
97
98
#define MAX_INSTRUCTION_OPCODE 64 // 2^6
99
#define MAX_REGISTERS 256 // 2^8
100
#define MAX_LOCALS 200 // maximum number of local variables
101
#define MAX_UPVALUES 200 // maximum number of upvalues
102
#define MAX_INLINE_INT 131072 // 32 - 6 (OPCODE) - 8 (register) - 1 bit sign = 17
103
#define MAX_FIELDSxFLUSH 64 // used in list/map serialization
104
#define MAX_IVARS 768 // 2^10 - 2^8
105
106
#define DEFAULT_CONTEXT_SIZE 256 // default VM context entries (can grow)
107
#define DEFAULT_MINSTRING_SIZE 64 // minimum string allocation size
108
#define DEFAULT_MINSTACK_SIZE 256 // sizeof(gravity_value_t) * 256 = 16 * 256 => 4 KB
109
#define DEFAULT_MINCFRAME_SIZE 32 // sizeof(gravity_callframe_t) * 48 = 32 * 48 => 1.5 KB
110
#define DEFAULT_CG_THRESHOLD 5*1024*1024 // 5MB
111
#define DEFAULT_CG_MINTHRESHOLD 1024*1024 // 1MB
112
#define DEFAULT_CG_RATIO 0.5 // 50%
113
114
#define MAXNUM(a,b) ((a) > (b) ? a : b)
115
#define MINNUM(a,b) ((a) < (b) ? a : b)
116
#define EPSILON 0.000001
117
118
#define GRAVITY_DATA_REGISTER UINT32_MAX
119
#define GRAVITY_FIBER_REGISTER UINT32_MAX-1
120
#define GRAVITY_MSG_REGISTER UINT32_MAX-2
121
122
#define GRAVITY_BRIDGE_INDEX UINT16_MAX
123
#define GRAVITY_COMPUTED_INDEX UINT16_MAX-1
124
125
// MARK: - STRUCT -
126
127
#if GRAVITY_ENABLE_DOUBLE
128
typedef double gravity_float_t;
129
#else
130
typedef float gravity_float_t;
131
#endif
132
133
#if GRAVITY_ENABLE_INT64
134
typedef int64_t gravity_int_t;
135
#else
136
typedef int32_t gravity_int_t;
137
#endif
138
139
// Forward references (an object ptr is just its isa pointer)
140
typedef struct gravity_class_s gravity_class_t;
141
typedef struct gravity_class_s gravity_object_t;
142
143
// Everything inside Gravity VM is a gravity_value_t struct
144
typedef struct {
145
gravity_class_t *isa; // EVERY object must have an ISA pointer (8 bytes on a 64bit system)
146
union { // union takes 8 bytes on a 64bit system
147
gravity_int_t n; // integer slot
148
gravity_float_t f; // float/double slot
149
gravity_object_t *p; // ptr to object slot
150
};
151
} gravity_value_t;
152
153
// All VM shares the same foundation classes
154
extern gravity_class_t *gravity_class_object;
155
extern gravity_class_t *gravity_class_bool;
156
extern gravity_class_t *gravity_class_null;
157
extern gravity_class_t *gravity_class_undefined;
158
extern gravity_class_t *gravity_class_int;
159
extern gravity_class_t *gravity_class_float;
160
extern gravity_class_t *gravity_class_function;
161
extern gravity_class_t *gravity_class_closure;
162
extern gravity_class_t *gravity_class_fiber;
163
extern gravity_class_t *gravity_class_class;
164
extern gravity_class_t *gravity_class_string;
165
extern gravity_class_t *gravity_class_instance;
166
extern gravity_class_t *gravity_class_list;
167
extern gravity_class_t *gravity_class_map;
168
extern gravity_class_t *gravity_class_module;
169
extern gravity_class_t *gravity_class_range;
170
extern gravity_class_t *gravity_class_upvalue;
171
172
typedef marray_t(gravity_value_t) gravity_value_r; // array of values
173
typedef struct gravity_hash_t gravity_hash_t; // forward declaration
174
typedef struct gravity_vm gravity_vm; // vm is an opaque data type
175
typedef bool (*gravity_c_internal)(gravity_vm *vm, gravity_value_t *args, uint16_t nargs, uint32_t rindex);
176
177
typedef enum {
178
EXEC_TYPE_SPECIAL_GETTER = 0, // index inside special gravity_function_t union to represent getter func
179
EXEC_TYPE_SPECIAL_SETTER = 1, // index inside special gravity_function_t union to represent setter func
180
} gravity_special_index;
181
182
typedef enum {
183
EXEC_TYPE_NATIVE, // native gravity code (can change stack)
184
EXEC_TYPE_INTERNAL, // c internal code (can change stack)
185
EXEC_TYPE_BRIDGED, // external code to be executed by delegate (can change stack)
186
EXEC_TYPE_SPECIAL // special execution like getter and setter (can be NATIVE, INTERNAL)
187
} gravity_exec_type;
188
189
typedef struct {
190
bool isdark; // flag to check if object is reachable
191
gravity_object_t *next; // to track next object in the linked list
192
} gravity_gc_t;
193
194
typedef struct {
195
gravity_class_t *isa; // to be an object
196
gravity_gc_t gc; // to be collectable by the garbage collector
197
198
void *xdata; // extra bridged data
199
const char *identifier; // function name
200
uint16_t nparams; // number of formal parameters
201
uint16_t nlocals; // number of local variables
202
uint16_t ntemps; // number of temporary values used
203
uint16_t nupvalues; // number of up values (if any)
204
gravity_exec_type tag; // can be EXEC_TYPE_NATIVE (default), EXEC_TYPE_INTERNAL, EXEC_TYPE_BRIDGED or EXEC_TYPE_SPECIAL
205
union {
206
// tag == EXEC_TYPE_NATIVE
207
struct {
208
gravity_value_r cpool; // constant pool
209
uint32_t ninsts; // number of instructions in the bytecode
210
uint32_t *bytecode; // bytecode as array of 32bit values
211
float purity; // experimental value
212
bool useargs; // flag set by the compiler to optimize the creation of the arguments array only if needed
213
};
214
215
// tag == EXEC_TYPE_INTERNAL
216
gravity_c_internal internal; // function callback
217
218
// tag == EXEC_TYPE_SPECIAL
219
struct {
220
uint16_t index; // property index to speed-up default getter and setter
221
void *special[2]; // getter/setter functions
222
};
223
};
224
} gravity_function_t;
225
226
typedef struct upvalue_s {
227
gravity_class_t *isa; // to be an object
228
gravity_gc_t gc; // to be collectable by the garbage collector
229
230
gravity_value_t *value; // ptr to open value on the stack or to closed value on this struct
231
gravity_value_t closed; // copy of the value once has been closed
232
struct upvalue_s *next; // ptr to the next open upvalue
233
} gravity_upvalue_t;
234
235
typedef struct {
236
gravity_class_t *isa; // to be an object
237
gravity_gc_t gc; // to be collectable by the garbage collector
238
239
gravity_function_t *f; // function prototype
240
gravity_upvalue_t **upvalue; // upvalue array
241
} gravity_closure_t;
242
243
typedef struct {
244
gravity_class_t *isa; // to be an object
245
gravity_gc_t gc; // to be collectable by the garbage collector
246
247
gravity_value_r array; // dinamic array of values
248
} gravity_list_t;
249
250
typedef struct {
251
gravity_class_t *isa; // to be an object
252
gravity_gc_t gc; // to be collectable by the garbage collector
253
254
gravity_hash_t *hash; // hash table
255
} gravity_map_t;
256
257
// Call frame used for function call
258
typedef struct {
259
uint32_t *ip; // instruction pointer
260
uint32_t dest; // destination register that will receive result
261
uint16_t nargs; // number of effective arguments passed to the function
262
gravity_list_t *args; // implicit special _args array
263
gravity_closure_t *closure; // closure being executed
264
gravity_value_t *stackstart; // first stack slot used by this call frame (receiver, plus parameters, locals and temporaries)
265
bool outloop; // special case for events or native code executed from C that must be executed separately
266
} gravity_callframe_t;
267
268
// Fiber is the core executable model
269
typedef struct fiber_s {
270
gravity_class_t *isa; // to be an object
271
gravity_gc_t gc; // to be collectable by the garbage collector
272
273
gravity_value_t *stack; // stack buffer (grown as needed and it holds locals and temps)
274
gravity_value_t *stacktop; // current stack ptr
275
uint32_t stackalloc; // number of allocated values
276
277
gravity_callframe_t *frames; // callframes buffer (grown as needed but never shrinks)
278
uint32_t nframes; // number of frames currently in use
279
uint32_t framesalloc; // number of allocated frames
280
281
gravity_upvalue_t *upvalues; // linked list used to keep track of open upvalues
282
283
char *error; // runtime error message
284
bool trying; // set when the try flag is set by the user
285
struct fiber_s *caller; // optional caller fiber
286
gravity_value_t result; // end result of the fiber
287
} gravity_fiber_t;
288
289
typedef struct gravity_class_s {
290
gravity_class_t *isa; // to be an object
291
gravity_gc_t gc; // to be collectable by the garbage collector
292
293
gravity_class_t *objclass; // meta class
294
const char *identifier; // class name
295
bool has_outer; // flag used to automatically set ivar 0 to outer class (if any)
296
bool is_struct; // flag to mark class as a struct
297
bool is_inited; // flag used to mark already init meta-classes (to be improved)
298
bool unused; // unused padding byte
299
void *xdata; // extra bridged data
300
struct gravity_class_s *superclass; // reference to the super class
301
gravity_hash_t *htable; // hash table
302
uint32_t nivars; // number of instance variables
303
//cstring_r debug; // ivar index to name debug info
304
gravity_value_t *ivars; // static variables
305
} gravity_class_t;
306
307
typedef struct {
308
gravity_class_t *isa; // to be an object
309
gravity_gc_t gc; // to be collectable by the garbage collector
310
311
const char *identifier; // module name
312
gravity_hash_t *htable; // hash table
313
} gravity_module_t;
314
315
typedef struct {
316
gravity_class_t *isa; // to be an object
317
gravity_gc_t gc; // to be collectable by the garbage collector
318
319
gravity_class_t *objclass; // real instance class
320
void *xdata; // extra bridged data
321
gravity_value_t ivars[]; // instance variables (MUST BE LAST in the struct!)
322
} gravity_instance_t;
323
324
typedef struct {
325
gravity_class_t *isa; // to be an object
326
gravity_gc_t gc; // to be collectable by the garbage collector
327
328
char *s; // pointer to NULL terminated string
329
uint32_t hash; // string hash (type to be keeped in sync with gravity_hash_size_t)
330
uint32_t len; // actual string length
331
uint32_t alloc; // bytes allocated for string
332
} gravity_string_t;
333
334
typedef struct {
335
gravity_class_t *isa; // to be an object
336
gravity_gc_t gc; // to be collectable by the garbage collector
337
338
gravity_int_t from; // range start
339
gravity_int_t to; // range end
340
} gravity_range_t;
341
342
typedef void (*code_dump_function) (void *code);
343
typedef marray_t(gravity_function_t*) gravity_function_r; // array of functions
344
typedef marray_t(gravity_class_t*) gravity_class_r; // array of classes
345
typedef marray_t(gravity_object_t*) gravity_object_r; // array of objects
346
347
// MARK: - MODULE -
348
gravity_module_t *gravity_module_new (gravity_vm *vm, const char *identifier);
349
void gravity_module_free (gravity_vm *vm, gravity_module_t *m);
350
void gravity_module_blacken (gravity_vm *vm, gravity_module_t *m);
351
uint32_t gravity_module_size (gravity_vm *vm, gravity_module_t *m);
352
353
// MARK: - FUNCTION -
354
gravity_function_t *gravity_function_new (gravity_vm *vm, const char *identifier, uint16_t nparams, uint16_t nlocals, uint16_t ntemps, void *code);
355
gravity_function_t *gravity_function_new_internal (gravity_vm *vm, const char *identifier, gravity_c_internal exec, uint16_t nparams);
356
gravity_function_t *gravity_function_new_special (gravity_vm *vm, const char *identifier, uint16_t index, void *getter, void *setter);
357
gravity_function_t *gravity_function_new_bridged (gravity_vm *vm, const char *identifier, void *xdata);
358
uint16_t gravity_function_cpool_add (gravity_vm *vm, gravity_function_t *f, gravity_value_t v);
359
gravity_value_t gravity_function_cpool_get (gravity_function_t *f, uint16_t i);
360
void gravity_function_dump (gravity_function_t *f, code_dump_function codef);
361
void gravity_function_setouter (gravity_function_t *f, gravity_object_t *outer);
362
void gravity_function_setxdata (gravity_function_t *f, void *xdata);
363
void gravity_function_serialize (gravity_function_t *f, json_t *json);
364
uint32_t *gravity_bytecode_deserialize (const char *buffer, size_t len, uint32_t *ninst);
365
gravity_function_t *gravity_function_deserialize (gravity_vm *vm, json_value *json);
366
void gravity_function_free (gravity_vm *vm, gravity_function_t *f);
367
void gravity_function_blacken (gravity_vm *vm, gravity_function_t *f);
368
uint32_t gravity_function_size (gravity_vm *vm, gravity_function_t *f);
369
370
// MARK: - CLOSURE -
371
gravity_closure_t *gravity_closure_new (gravity_vm *vm, gravity_function_t *f);
372
void gravity_closure_free (gravity_vm *vm, gravity_closure_t *closure);
373
uint32_t gravity_closure_size (gravity_vm *vm, gravity_closure_t *closure);
374
void gravity_closure_blacken (gravity_vm *vm, gravity_closure_t *closure);
375
376
// MARK: - UPVALUE -
377
gravity_upvalue_t *gravity_upvalue_new (gravity_vm *vm, gravity_value_t *value);
378
uint32_t gravity_upvalue_size (gravity_vm *vm, gravity_upvalue_t *upvalue);
379
void gravity_upvalue_blacken (gravity_vm *vm, gravity_upvalue_t *upvalue);
380
void gravity_upvalue_free(gravity_vm *vm, gravity_upvalue_t *upvalue);
381
382
// MARK: - CLASS -
383
void gravity_class_bind (gravity_class_t *c, const char *key, gravity_value_t value);
384
gravity_class_t *gravity_class_getsuper (gravity_class_t *c);
385
bool gravity_class_grow (gravity_class_t *c, uint32_t n);
386
bool gravity_class_setsuper (gravity_class_t *subclass, gravity_class_t *superclass);
387
gravity_class_t *gravity_class_new_single (gravity_vm *vm, const char *identifier, uint32_t nfields);
388
gravity_class_t *gravity_class_new_pair (gravity_vm *vm, const char *identifier, gravity_class_t *superclass, uint32_t nivar, uint32_t nsvar);
389
gravity_class_t *gravity_class_get_meta (gravity_class_t *c);
390
bool gravity_class_is_meta (gravity_class_t *c);
391
uint32_t gravity_class_count_ivars (gravity_class_t *c);
392
void gravity_class_dump (gravity_class_t *c);
393
void gravity_class_setxdata (gravity_class_t *c, void *xdata);
394
int16_t gravity_class_add_ivar (gravity_class_t *c, const char *identifier);
395
void gravity_class_serialize (gravity_class_t *c, json_t *json);
396
gravity_class_t *gravity_class_deserialize (gravity_vm *vm, json_value *json);
397
void gravity_class_free (gravity_vm *vm, gravity_class_t *c);
398
void gravity_class_free_core (gravity_vm *vm, gravity_class_t *c);
399
gravity_object_t *gravity_class_lookup (gravity_class_t *c, gravity_value_t key);
400
gravity_closure_t *gravity_class_lookup_closure (gravity_class_t *c, gravity_value_t key);
401
gravity_closure_t *gravity_class_lookup_constructor (gravity_class_t *c, uint32_t nparams);
402
void gravity_class_blacken (gravity_vm *vm, gravity_class_t *c);
403
uint32_t gravity_class_size (gravity_vm *vm, gravity_class_t *c);
404
405
// MARK: - FIBER -
406
gravity_fiber_t *gravity_fiber_new (gravity_vm *vm, gravity_closure_t *closure, uint32_t nstack, uint32_t nframes);
407
void gravity_fiber_reassign (gravity_fiber_t *fiber, gravity_closure_t *closure, uint16_t nargs);
408
void gravity_fiber_seterror (gravity_fiber_t *fiber, const char *error);
409
void gravity_fiber_free (gravity_vm *vm, gravity_fiber_t *fiber);
410
void gravity_fiber_blacken (gravity_vm *vm, gravity_fiber_t *fiber);
411
uint32_t gravity_fiber_size (gravity_vm *vm, gravity_fiber_t *fiber);
412
413
// MARK: - INSTANCE -
414
gravity_instance_t *gravity_instance_new (gravity_vm *vm, gravity_class_t *c);
415
gravity_instance_t *gravity_instance_dup (gravity_vm *vm, gravity_instance_t *src);
416
void gravity_instance_setivar (gravity_instance_t *instance, uint32_t idx, gravity_value_t value);
417
void gravity_instance_setxdata (gravity_instance_t *i, void *xdata);
418
void gravity_instance_free (gravity_vm *vm, gravity_instance_t *i);
419
gravity_closure_t *gravity_instance_lookup_event (gravity_instance_t *i, const char *name);
420
void gravity_instance_blacken (gravity_vm *vm, gravity_instance_t *i);
421
uint32_t gravity_instance_size (gravity_vm *vm, gravity_instance_t *i);
422
423
// MARK: - VALUE -
424
bool gravity_value_equals (gravity_value_t v1, gravity_value_t v2);
425
uint32_t gravity_value_hash (gravity_value_t value);
426
gravity_class_t *gravity_value_getclass (gravity_value_t v);
427
gravity_class_t *gravity_value_getsuper (gravity_value_t v);
428
void gravity_value_free (gravity_vm *vm, gravity_value_t v);
429
void gravity_value_serialize (gravity_value_t v, json_t *json);
430
void gravity_value_dump (gravity_value_t v, char *buffer, uint16_t len);
431
bool gravity_value_isobject (gravity_value_t v);
432
void *gravity_value_xdata (gravity_value_t value);
433
void gravity_value_blacken (gravity_vm *vm, gravity_value_t v);
434
uint32_t gravity_value_size (gravity_vm *vm, gravity_value_t v);
435
436
// MARK: - OBJECT -
437
void gravity_object_serialize (gravity_object_t *obj, json_t *json);
438
bool gravity_object_deserialize (gravity_vm *vm, json_value *entry, gravity_object_t **obj);
439
void gravity_object_free (gravity_vm *vm, gravity_object_t *obj);
440
void gravity_object_blacken (gravity_vm *vm, gravity_object_t *obj);
441
uint32_t gravity_object_size (gravity_vm *vm, gravity_object_t *obj);
442
const char *gravity_object_debug (gravity_object_t *obj);
443
444
// MARK: - LIST -
445
gravity_list_t *gravity_list_new (gravity_vm *vm, uint32_t n);
446
gravity_list_t *gravity_list_from_array (gravity_vm *vm, uint32_t n, gravity_value_t *p);
447
void gravity_list_free (gravity_vm *vm, gravity_list_t *list);
448
void gravity_list_append_list (gravity_vm *vm, gravity_list_t *list1, gravity_list_t *list2);
449
void gravity_list_blacken (gravity_vm *vm, gravity_list_t *list);
450
uint32_t gravity_list_size (gravity_vm *vm, gravity_list_t *list);
451
452
// MARK: - MAP -
453
gravity_map_t *gravity_map_new (gravity_vm *vm, uint32_t n);
454
void gravity_map_free (gravity_vm *vm, gravity_map_t *map);
455
void gravity_map_append_map (gravity_vm *vm, gravity_map_t *map1, gravity_map_t *map2);
456
void gravity_map_insert (gravity_vm *vm, gravity_map_t *map, gravity_value_t key, gravity_value_t value);
457
void gravity_map_blacken (gravity_vm *vm, gravity_map_t *map);
458
uint32_t gravity_map_size (gravity_vm *vm, gravity_map_t *map);
459
460
// MARK: - RANGE -
461
gravity_range_t *gravity_range_new (gravity_vm *vm, gravity_int_t from, gravity_int_t to, bool inclusive);
462
void gravity_range_free (gravity_vm *vm, gravity_range_t *range);
463
void gravity_range_blacken (gravity_vm *vm, gravity_range_t *range);
464
uint32_t gravity_range_size (gravity_vm *vm, gravity_range_t *range);
465
466
/// MARK: - STRING -
467
gravity_value_t gravity_string_to_value (gravity_vm *vm, const char *s, uint32_t len);
468
gravity_string_t *gravity_string_new (gravity_vm *vm, char *s, uint32_t len, uint32_t alloc);
469
inline void gravity_string_set (gravity_string_t *obj, char *s, uint32_t len);
470
void gravity_string_free (gravity_vm *vm, gravity_string_t *value);
471
void gravity_string_blacken (gravity_vm *vm, gravity_string_t *string);
472
uint32_t gravity_string_size (gravity_vm *vm, gravity_string_t *string);
473
474
// MARK: - CALLBACKS -
475
// HASH FREE CALLBACK FUNCTION
476
void gravity_hash_keyvaluefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
477
void gravity_hash_keyfree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
478
void gravity_hash_valuefree (gravity_hash_t *table, gravity_value_t key, gravity_value_t value, void *data);
479
480
#endif
481
482