-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.hpp
61 lines (46 loc) · 1.27 KB
/
util.hpp
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
#ifndef UTIL_HPP
#define UTIL_HPP
#include <stddef.h>
#include <stdint.h>
class Object;
class Handle;
namespace Util {
template<int Bits>
intptr_t align(intptr_t orig) {
uintptr_t mask = -1,
unmasked;
mask <<= Bits;
mask = ~mask;
if ((unmasked = orig & mask)) {
orig += (1 << Bits) - unmasked;
}
return orig;
}
void logObj(const char *wat, Object *x, int fd = 2);
void logPtr(const char *wat, void *x, int fd = 2);
template<int Bits>
bool isAligned(intptr_t orig) {
return align<Bits>(orig) == orig;
}
// AssocList and growable array
enum EqFunc {
kSymbolEq,
kPtrEq
};
Object *newAssocList();
Object *assocLookup(const Handle &assoc, const Handle &key,
EqFunc eqf, bool *ok = NULL);
Object *assocLookupKey(const Handle &assoc, const Handle &key,
EqFunc eqf, bool *ok = NULL);
Object *assocInsert(const Handle &assoc, const Handle &key,
const Handle &val, EqFunc eqf);
intptr_t assocLength(const Handle &assoc);
Object *newGrowableArray();
void arrayAppend(const Handle &arr, const Handle &item);
// Can use negative index
Object *&arrayAt(const Handle &arr, intptr_t ix);
intptr_t arrayLength(const Handle &arr);
// Trim unused parts
Object *arrayToVector(const Handle &arr);
}
#endif