-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathObject.h
More file actions
71 lines (55 loc) · 1.38 KB
/
Object.h
File metadata and controls
71 lines (55 loc) · 1.38 KB
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
/*
Copyright (c) 2019-2023 Javier Pimás, Jan Vrany, Labware.
See (MIT) license in root directory.
*/
#ifndef _OBJECT_H_
#define _OBJECT_H_
#include "Util.h"
#include <string>
namespace Egg {
struct HeapObject;
struct SmallInteger;
/**
* Class `Object` represents an opaque object. It is meant to always
* be used as a pointer, as it provides no direct access to its
* contents.
* It could refer to an object heap or to an immediate object, and
* must be cast to a particular type to use its actual value.
*/
struct Object
{
/**
* Return `true` if this object is a SmallInteger instance,
* `false` otherwise.
*/
bool isSmallInteger() { return (uintptr_t)this & 1 ? true : false; }
/**
* Cast into SmallInteger type
*/
operator SmallInteger*()
{
ASSERT(isSmallInteger());
return (SmallInteger*)(void*)this;
}
/**
* Cast into SmallInteger type
*/
SmallInteger* asSmallInteger() {return (SmallInteger*)this;}
/**
* Cast into a HeapObject type
*/
operator HeapObject*()
{
ASSERT(!isSmallInteger());
return (HeapObject*)(void*)this;
}
/**
* Cast into a HeapObject type
*/
HeapObject* asHeapObject() {return (HeapObject*)this;}
// debugging
std::string printString();
std::string printContents();
};
} // namespace Egg
#endif /* _OBJECT_H_ */