-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.h
84 lines (68 loc) · 1.56 KB
/
structs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef __STRUCTS__
#define __STRUCTS__
#include <cstring>
#include <stdlib.h>
#define AVM_STACKSIZE 4096
#define AVM_TABLE_HASHSIZE 211
class Table;
namespace AVM_memcell_t {
enum AVM_memcell_t {
number_m,
string_m,
bool_m,
table_m,
userfunc_m,
libfunc_m,
nil_m,
undef_m
};
}
union data_t {
double numVal;
char *strVal;
unsigned char boolVar;
Table *tableVal;
unsigned funcVal;
char *libfuncVal;
};
struct AVM_memcell {
AVM_memcell_t::AVM_memcell_t type;
data_t data;
};
struct bucket {
AVM_memcell key;
AVM_memcell value;
struct bucket *next;
};
class Table {
public:
char *addr;
unsigned ref_counter;
unsigned total;
/* indexes */
bucket *str_indexed[AVM_TABLE_HASHSIZE];
bucket *num_indexed[AVM_TABLE_HASHSIZE];
bucket *tab_indexed[AVM_TABLE_HASHSIZE];
bucket *lib_indexed[AVM_TABLE_HASHSIZE];
bucket *usr_indexed[AVM_TABLE_HASHSIZE];
bucket *bol_indexed[AVM_TABLE_HASHSIZE];
Table();
void initBuckets(bucket **t);
void destroyBuckets(bucket **t);
AVM_memcell *getElem(AVM_memcell *key);
void setElem(AVM_memcell *key, AVM_memcell *value);
void incRefCounter();
void decRefCounter();
void destroy();
bucket **getTable(AVM_memcell *key);
/* hashing */
unsigned hash(AVM_memcell *key);
};
class AVMStack {
public:
//AVM_memcell xaxatoeftiaksa1[AVM_STACKSIZE];
AVM_memcell stack[AVM_STACKSIZE];
//AVM_memcell xaxatoeftiaksa2[AVM_STACKSIZE];
AVMStack();
};
#endif