-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.h
More file actions
68 lines (53 loc) · 1.35 KB
/
Object.h
File metadata and controls
68 lines (53 loc) · 1.35 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
/*
* Copyright (c) 2020 Javier Pimas & LabWare
*
* This program and the accompanying materials are made available under
* the terms of the MIT license, see LICENSE file.
*
* SPDX-License-Identifier: MIT
*/
#ifndef _OBJECT_H_
#define _OBJECT_H_
#include "Util.h"
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;}
};
#endif /* _OBJECT_H_ */