Wed, 02 Jan 2013 23:57:46 +0200
test
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * botc source code |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2012 Santeri `Dusk` Piippo |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * All rights reserved. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright notice, |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * this list of conditions and the following disclaimer. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * this list of conditions and the following disclaimer in the documentation |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * and/or other materials provided with the distribution. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * 3. Neither the name of the developer nor the names of its contributors may |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * be used to endorse or promote products derived from this software without |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * specific prior written permission. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | * 4. Redistributions in any form must be accompanied by information on how to |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | * obtain complete source code for the software and any accompanying |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | * software that uses the software. The source code must either be included |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | * in the distribution or be available for no more than the cost of |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | * distribution plus a nominal fee, and must be freely redistributable |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | * under reasonable conditions. For an executable file, complete source |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | * code means the source code for all modules it contains. It does not |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | * include source code for modules or files that typically accompany the |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | * major components of the operating system on which the executable file |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | * runs. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | * |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | * POSSIBILITY OF SUCH DAMAGE. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | */ |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | #ifndef __DATABUFFER_H__ |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | #define __DATABUFFER_H__ |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | #include <stdio.h> |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | #include <string.h> |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | #include "common.h" |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
46 | #include "stringtable.h" |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
50
2e333a3ca49a
Added default label for switch
Teemu Piippo <crimsondusk64@gmail.com>
parents:
49
diff
changeset
|
48 | #define MAX_MARKS 512 |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
49 | |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
50 | extern int g_NextMark; |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
51 | |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | // ============================================================================ |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | // DataBuffer: A dynamic data buffer. |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | class DataBuffer { |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | public: |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | // The actual buffer |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
57 | byte* buffer; |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | // Allocated size of the buffer |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | unsigned int allocsize; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | // Written size of the buffer |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | unsigned int writesize; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
65 | // Marks and references |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
66 | ScriptMark* marks[MAX_MARKS]; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
67 | ScriptMarkReference* refs[MAX_MARKS]; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
68 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
69 | // ==================================================================== |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | // METHODS |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
71 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
72 | // ==================================================================== |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
73 | // Constructor |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | DataBuffer (unsigned int size=128) { |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | writesize = 0; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | buffer = new unsigned char[size]; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | allocsize = size; |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
79 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
80 | // Clear the marks table out |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
81 | for (unsigned int u = 0; u < MAX_MARKS; u++) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
82 | marks[u] = NULL; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
83 | refs[u] = NULL; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
84 | } |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
85 | } |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
87 | // ==================================================================== |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | ~DataBuffer () { |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | delete buffer; |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
90 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
91 | // Delete any marks and references |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
92 | for (unsigned int u = 0; u < MAX_MARKS; u++) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
93 | if (marks[u]) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
94 | delete marks[u]; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
95 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
96 | if (refs[u]) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
97 | delete refs[u]; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
98 | } |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | } |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
101 | // ==================================================================== |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
102 | // Write stuff to the buffer |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
103 | template<class T> void DoWrite (const char* func, T stuff) { |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
104 | // printf ("DoWrite: called from %s\n", func); |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
105 | if (writesize + sizeof (T) >= allocsize) { |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
106 | // We don't have enough space in the buffer to write |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
107 | // the stuff - thus resize. First, store the old |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
108 | // buffer temporarily: |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | char* copy = new char[allocsize]; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | memcpy (copy, buffer, allocsize); |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
112 | // Remake the buffer with the new size. Have enough space |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
113 | // for the stuff we're going to write, as well as a bit |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
114 | // of leeway so we don't have to resize immediately again. |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | size_t newsize = allocsize + sizeof (T) + 128; |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
116 | |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | delete buffer; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | buffer = new unsigned char[newsize]; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | allocsize = newsize; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
121 | // Now, copy the stuff back. |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
122 | memcpy (buffer, copy, allocsize); |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | delete copy; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | } |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
126 | // Buffer is now guaranteed to have enough space. |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
127 | // Write the stuff one byte at a time. |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
128 | union_t<T> uni; |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
129 | uni.val = stuff; |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | for (unsigned int x = 0; x < sizeof (T); x++) { |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
131 | if (writesize >= allocsize) // should NEVER happen because resizing is done above |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | error ("DataBuffer: written size exceeds allocated size!\n"); |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
133 | |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
134 | buffer[writesize] = uni.b[x]; |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | writesize++; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | } |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | } |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
139 | // ==================================================================== |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
140 | // Merge another data buffer into this one. |
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
141 | void Merge (DataBuffer* other) { |
36
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
142 | if (!other) |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
143 | return; |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
144 | int oldsize = writesize; |
36
a8838b5f1213
Parser can now read expressions 100% properly and can perform variable assignment. I'd call this a milestone!
Teemu Piippo <crimsondusk64@gmail.com>
parents:
34
diff
changeset
|
145 | |
40
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
146 | for (unsigned int x = 0; x < other->writesize; x++) |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
147 | Write (*(other->buffer+x)); |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
148 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
149 | // Merge its marks and references |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
150 | unsigned int u = 0; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
151 | for (u = 0; u < MAX_MARKS; u++) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
152 | if (other->marks[u]) { |
49
8e2f7a031410
rename ObjWriter::RecordBuffer to SwitchBuffer, as it is designed specifically for switch and will break if used genericly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
153 | // Merge the mark and offset its position. |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
154 | if (marks[u]) |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
155 | error ("DataBuffer: duplicate mark %d!\n"); |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
156 | |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
157 | marks[u] = other->marks[u]; |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
158 | marks[u]->pos += oldsize; |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
159 | |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
160 | // The original mark becomes NULL so that the deconstructor |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
161 | // will not delete it prematurely. (should it delete any |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
162 | // marks in the first place since there is no such thing |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
163 | // as at temporary mark?) |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
164 | other->marks[u] = NULL; |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
165 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
166 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
167 | if (other->refs[u]) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
168 | // Same for references |
49
8e2f7a031410
rename ObjWriter::RecordBuffer to SwitchBuffer, as it is designed specifically for switch and will break if used genericly
Teemu Piippo <crimsondusk64@gmail.com>
parents:
48
diff
changeset
|
169 | // TODO: add a g_NextRef system like here, akin to marks! |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
170 | unsigned int r = AddMarkReference (other->refs[u]->num, false); |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
171 | refs[r]->pos = other->refs[u]->pos + oldsize; |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
172 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
173 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
174 | |
34
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
175 | delete other; |
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
176 | } |
0a9a5902beaa
Expression parser mostly up and running!! Still work to do on it though.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
32
diff
changeset
|
177 | |
40
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
178 | // Clones this databuffer to a new one and returns it. |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
179 | DataBuffer* Clone () { |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
180 | DataBuffer* other = new DataBuffer; |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
181 | for (unsigned int x = 0; x < writesize; x++) |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
182 | other->Write (*(buffer+x)); |
40
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
183 | return other; |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
184 | } |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
185 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
186 | // ==================================================================== |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
187 | // Adds a mark to the buffer. A mark is a "pointer" to a particular |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
188 | // position in the bytecode. The actual permanent position cannot |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
189 | // be predicted in any way or form, thus these things will be used |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
190 | // to "mark" a position like that for future use. |
45
e1d3b7ea975c
Removed mark types as they served absolutely zero purpose
Teemu Piippo <crimsondusk64@gmail.com>
parents:
43
diff
changeset
|
191 | unsigned int AddMark (str name) { |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
192 | // Find a free slot for the mark |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
193 | unsigned int u = g_NextMark++; |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
194 | |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
195 | if (marks[u]) |
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
196 | error ("DataBuffer: attempted to re-create mark %u!\n", u); |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
197 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
198 | if (u >= MAX_MARKS) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
199 | error ("mark quota exceeded, all labels, if-structs and loops add marks\n"); |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
200 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
201 | ScriptMark* m = new ScriptMark; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
202 | m->name = name; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
203 | m->pos = writesize; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
204 | marks[u] = m; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
205 | return u; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
206 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
207 | |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
208 | // ==================================================================== |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
209 | // A ref is another "mark" that references a mark. When the bytecode |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
210 | // is written to file, they are changed into their marks' current |
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
211 | // positions. Marks themselves are never written to files, only refs are |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
212 | unsigned int AddMarkReference (unsigned int marknum, bool placeholder = true) { |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
213 | unsigned int u; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
214 | for (u = 0; u < MAX_MARKS; u++) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
215 | if (!refs[u]) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
216 | break; |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
217 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
218 | if (u == MAX_MARKS) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
219 | error ("mark reference quota exceeded, all goto-statements, if-structs and loops add refs\n"); |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
220 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
221 | ScriptMarkReference* r = new ScriptMarkReference; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
222 | r->num = marknum; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
223 | r->pos = writesize; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
224 | refs[u] = r; |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
225 | |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
226 | // Write a dummy placeholder for the reference |
48
976c57f153b3
Added switch support... fixed more problems with marks in the process
Teemu Piippo <crimsondusk64@gmail.com>
parents:
45
diff
changeset
|
227 | if (placeholder) |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
228 | Write (1234); |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
229 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
230 | return u; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
231 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
232 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
233 | // Delete a mark and all references to it. |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
234 | void DeleteMark (unsigned int marknum) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
235 | if (!marks[marknum]) |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
236 | return; |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
237 | |
37
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
238 | // Delete the mark |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
239 | delete marks[marknum]; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
240 | marks[marknum] = NULL; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
241 | |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
242 | // Delete its references |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
243 | for (unsigned int u = 0; u < MAX_MARKS; u++) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
244 | if (refs[u]->num == marknum) { |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
245 | delete refs[u]; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
246 | refs[u] = NULL; |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
247 | } |
c349dca807f9
Added mark/reference system to be able to refer to positions in the buffered bytecode. Labels and go-to support.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
36
diff
changeset
|
248 | } |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
249 | } |
38 | 250 | |
251 | // Adjusts a mark to the current position | |
42
5cd91fd1526c
FINALLY, marks and references work smoothly without hacks. if and while work properly.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
41
diff
changeset
|
252 | void MoveMark (unsigned int mark, int offset = -1) { |
38 | 253 | if (!marks[mark]) |
254 | return; | |
39
07b7ab8080cf
Fixed mark positioning - multiple if statements should work properly now
Teemu Piippo <crimsondusk64@gmail.com>
parents:
38
diff
changeset
|
255 | marks[mark]->pos = writesize; |
38 | 256 | } |
40
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
257 | |
41
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
258 | void OffsetMark (unsigned int mark, size_t offset) { |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
259 | if (!marks[mark]) |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
260 | return; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
261 | marks[mark]->pos += offset; |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
262 | } |
47e686c96d8f
Added while loop support. However, script marks keep getting wrong position numbers..
Teemu Piippo <crimsondusk64@gmail.com>
parents:
40
diff
changeset
|
263 | |
40
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
264 | // Dump the buffer (for debugging purposes) |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
265 | void Dump() { |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
266 | for (unsigned int x = 0; x < writesize; x++) |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
267 | printf ("%d. [%d]\n", x, *(buffer+x)); |
9e4f785501db
Committed the other changes done during a failed attempt of else
Teemu Piippo <crimsondusk64@gmail.com>
parents:
39
diff
changeset
|
268 | } |
43
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
269 | |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
270 | // Count the amount of marks |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
271 | unsigned int CountMarks () { |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
272 | unsigned int count = 0; |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
273 | for (unsigned int u = 0; u < MAX_MARKS; u++) |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
274 | count += !!marks[u]; |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
275 | return count; |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
276 | } |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
277 | |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
278 | // Count the amount of refs |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
279 | unsigned int CountReferences () { |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
280 | unsigned int count = 0; |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
281 | for (unsigned int u = 0; u < MAX_MARKS; u++) |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
282 | count += !!refs[u]; |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
283 | return count; |
1b35c9985989
Added for-loop support
Teemu Piippo <crimsondusk64@gmail.com>
parents:
42
diff
changeset
|
284 | } |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
285 | |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
286 | // Write a float into the buffer |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
287 | void WriteFloat (str floatstring) { |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
288 | // TODO: Casting float to word causes the decimal to be lost. |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
289 | // Find a way to store the number without such loss. |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
290 | float val = atof (floatstring); |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
291 | Write (DH_PUSHNUMBER); |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
292 | Write (static_cast<word> ((val > 0) ? val : -val)); |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
293 | if (val < 0) |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
294 | Write (DH_UNARYMINUS); |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
295 | } |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
296 | |
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
297 | void WriteString (str string) { |
69
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
298 | Write (DH_PUSHSTRINGINDEX); |
29a3e669d648
So it turns out that the functions I thought were taking float are actually taking int. So, with the only reason for float removed, the float type is removed as well. I'd rather have fixed point anyway.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
68
diff
changeset
|
299 | Write (PushToStringTable (string)); |
68
588cc27e84bb
Added constants, these are defined with const, take their value immediately and are replaced out with their value when used. The strlen operator can be used to get a string constant's length.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
63
diff
changeset
|
300 | } |
32
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
301 | }; |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
302 | |
d11a034aabfd
- The output cmd-line argument is now optional - one is generated from the input file if not given.
Teemu Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
303 | #endif // __DATABUFFER_H__ |