-
Notifications
You must be signed in to change notification settings - Fork 1
/
Objects.h
72 lines (47 loc) · 2.02 KB
/
Objects.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
#pragma once
#include <minmax.h>
#include <memory.h>
#include <stddef.h>
typedef unsigned char byte;
// typedef short int integer;
typedef int integer;
#pragma pack(push,1)
typedef void* (*CodeAddress)();
struct _Word; // forward declaration
typedef struct _Object
{
union
{
integer i;
struct _Object* Ptr;
struct _Word* Word;
CodeAddress CA;
byte* NativePtr; // this is used for direct native memory access and variable Object* manipulation
};
} Object;
typedef struct _Word
{
char Name[10];
byte Flags;
struct _Word* Next;
#pragma warning(suppress:4200)
Object CodeBody[];
} Word;
#pragma pack(pop)
#define MAX_OBJECT_SIZE (sizeof(Object))
inline int GetObjectSize(Object* Object) { return sizeof(Object); }
inline int GetPreviousObjectSize(Object* Object) { return sizeof(Object); }
inline void CopyObject(Object* Source, Object* Dest) { memcpy(Dest, Source, GetObjectSize(Source)); }
inline void LocalCopyObject(Object* Source, Object* Dest) { memcpy(Dest, Source, sizeof(Object)); }
inline void SetNULLObject(Object* Object) { Object->NativePtr = NULL; }
inline void SetIntObject(Object* Object, integer Value) { Object->i = Value; }
inline void SetObjectPtr(Object* ObjectPtr, Object* Object) { ObjectPtr->Ptr = Object; }
inline void SetWordRefObject(Object* Object, Word* Word) { Object->Word = Word; }
inline void SetCodeAddressObject(Object* Object, CodeAddress CA) { Object->CA = CA; }
inline void MakeNULLObject(Object* Object) { Object->NativePtr = NULL; }
inline void MakeIntObject(Object* Object, integer Value) { SetIntObject(Object, Value); }
inline void MakeObjectPtr(Object* ObjectPtr, Object* Object) { SetObjectPtr(ObjectPtr, Object); }
inline void MakeWordRefObject(Object* Object, Word* Word) { SetWordRefObject(Object, Word); }
inline void MakeCodeAddressObject(Object* Object, CodeAddress CA) { SetCodeAddressObject(Object, CA); }
inline void IncPtr(Object* Ptr) { Ptr->NativePtr += GetObjectSize(Ptr->Ptr); }
inline void DecPtr(Object* Ptr) { Ptr->NativePtr -= GetPreviousObjectSize(Ptr->Ptr); }