Wed, 12 Feb 2014 06:15:11 +0200
- refactored enums, macros split from Main.h to Macros.h
88 | 1 | /* |
2 | Copyright 2012-2014 Santeri Piippo | |
3 | All rights reserved. | |
4 | ||
5 | Redistribution and use in source and binary forms, with or without | |
6 | modification, are permitted provided that the following conditions | |
7 | are met: | |
8 | ||
9 | 1. Redistributions of source code must retain the above copyright | |
10 | notice, this list of conditions and the following disclaimer. | |
11 | 2. Redistributions in binary form must reproduce the above copyright | |
12 | notice, this list of conditions and the following disclaimer in the | |
13 | documentation and/or other materials provided with the distribution. | |
14 | 3. The name of the author may not be used to endorse or promote products | |
15 | derived from this software without specific prior written permission. | |
16 | ||
17 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
18 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
19 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
20 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
21 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
22 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
23 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
24 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
26 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
27 | */ | |
28 | ||
29 | #ifndef BOTC_DATABUFFER_H | |
30 | #define BOTC_DATABUFFER_H | |
31 | ||
32 | #include <stdio.h> | |
33 | #include <string.h> | |
34 | #include "Main.h" | |
35 | #include "StringTable.h" | |
36 | ||
37 | #define MAX_MARKS 512 | |
38 | ||
39 | // ============================================================================ | |
40 | // data_buffer: A dynamic data buffer. | |
41 | // | |
42 | // Notes: | |
43 | // | |
44 | // - A mark is a "pointer" to a particular position in the bytecode. The actual | |
45 | // permanent position cannot be predicted in any way or form, thus these things | |
46 | // are used to "mark" a position like that for future use. | |
47 | // | |
48 | // - A reference is another "mark" that references a mark. When the bytecode | |
49 | // is written to file, they are changed into their marks' current | |
50 | // positions. Marks themselves are never written to files, only refs are | |
51 | // | |
52 | class DataBuffer | |
53 | { | |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
96
diff
changeset
|
54 | PROPERTY (private, char*, Buffer, NO_OPS, STOCK_WRITE) |
88 | 55 | PROPERTY (private, int, AllocatedSize, NUM_OPS, STOCK_WRITE) |
108
6409ece8297c
- refactored enums, macros split from Main.h to Macros.h
Teemu Piippo <crimsondusk64@gmail.com>
parents:
96
diff
changeset
|
56 | PROPERTY (private, char*, Position, NO_OPS, STOCK_WRITE) |
88 | 57 | PROPERTY (private, List<ByteMark*>, Marks, LIST_OPS, STOCK_WRITE) |
58 | PROPERTY (private, List<MarkReference*>, References, LIST_OPS, STOCK_WRITE) | |
59 | ||
60 | public: | |
61 | DataBuffer (int size = 128); | |
62 | ~DataBuffer(); | |
63 | ||
64 | // ==================================================================== | |
65 | // Merge another data buffer into this one. | |
66 | // Note: @other is destroyed in the process! | |
67 | void MergeAndDestroy (DataBuffer* other); | |
68 | ||
69 | ByteMark* AddMark (String name); | |
91
427eb377d53e
- committed work so far done on expressions
Teemu Piippo <crimsondusk64@gmail.com>
parents:
88
diff
changeset
|
70 | MarkReference* AddReference (ByteMark* mark); |
88 | 71 | void CheckSpace (int bytes); |
96
3384d7aa036a
- ternary operator now works properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
72 | DataBuffer* Clone(); |
88 | 73 | void DeleteMark (int marknum); |
74 | void AdjustMark (ByteMark* mark); | |
75 | void OffsetMark (ByteMark* mark, int offset); | |
76 | ByteMark* FindMarkByName (const String& target); | |
77 | void Dump(); | |
96
3384d7aa036a
- ternary operator now works properly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
91
diff
changeset
|
78 | void TransferMarks (DataBuffer* other); |
88 | 79 | void WriteStringIndex (const String& a); |
80 | void WriteString (const String& a); | |
81 | void WriteByte (int8_t data); | |
82 | void WriteWord (int16_t data); | |
83 | void WriteDWord (int32_t data); | |
84 | void CopyBuffer (const DataBuffer* buf); | |
85 | ||
86 | inline int GetWrittenSize() const | |
87 | { | |
88 | return GetPosition() - GetBuffer(); | |
89 | } | |
90 | }; | |
91 | ||
92 | #endif // BOTC_DATABUFFER_H |