1 /* |
1 /* |
2 Copyright (c) 2013-2014, Santeri Piippo |
2 Copyright (c) 2012-2014, Santeri Piippo |
3 All rights reserved. |
3 All rights reserved. |
4 |
4 |
5 Redistribution and use in source and binary forms, with or without |
5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions are met: |
6 modification, are permitted provided that the following conditions are met: |
7 |
7 |
65 |
65 |
66 if (other->refs[u]) |
66 if (other->refs[u]) |
67 { |
67 { |
68 // Same for references |
68 // Same for references |
69 // TODO: add a g_NextRef system like here, akin to marks! |
69 // TODO: add a g_NextRef system like here, akin to marks! |
70 int r = AddMarkReference (other->refs[u]->num, false); |
70 int r = add_reference (other->refs[u]->num, false); |
71 refs[r]->pos = other->refs[u]->pos + oldsize; |
71 refs[r]->pos = other->refs[u]->pos + oldsize; |
72 } |
72 } |
73 } |
73 } |
74 |
74 |
75 delete other; |
75 delete other; |
107 return u; |
107 return u; |
108 } |
108 } |
109 |
109 |
110 // ============================================================================ |
110 // ============================================================================ |
111 // |
111 // |
112 int data_buffer::AddMarkReference (int marknum, bool placeholder) |
112 int data_buffer::add_reference (int marknum, bool placeholder) |
113 { |
113 { |
114 int u; |
114 int u; |
115 |
115 |
116 for (u = 0; u < MAX_MARKS; u++) |
116 for (u = 0; u < MAX_MARKS; u++) |
117 if (!refs[u]) |
117 if (!refs[u]) |
118 break; |
118 break; |
119 |
119 |
|
120 // TODO: get rid of this |
120 if (u == MAX_MARKS) |
121 if (u == MAX_MARKS) |
121 error ("mark reference quota exceeded, all goto-statements, if-structs and loops add refs\n"); |
122 error ("mark reference quota exceeded, all goto-statements, if-structs and loops add refs\n"); |
122 |
123 |
123 ScriptMarkReference* r = new ScriptMarkReference; |
124 ScriptMarkReference* r = new ScriptMarkReference; |
124 r->num = marknum; |
125 r->num = marknum; |
125 r->pos = writesize; |
126 r->pos = writesize; |
126 refs[u] = r; |
127 refs[u] = r; |
127 |
128 |
128 // Write a dummy placeholder for the reference |
129 // Write a dummy placeholder for the reference |
129 if (placeholder) |
130 if (placeholder) |
130 write (1234); |
131 write (0xBEEFCAFE); |
131 |
132 |
132 return u; |
133 return u; |
133 } |
134 } |
134 |
135 |
135 // ============================================================================ |
136 // ============================================================================ |
203 void data_buffer::write_float (string floatstring) |
204 void data_buffer::write_float (string floatstring) |
204 { |
205 { |
205 // TODO: Casting float to word causes the decimal to be lost. |
206 // TODO: Casting float to word causes the decimal to be lost. |
206 // Find a way to store the number without such loss. |
207 // Find a way to store the number without such loss. |
207 float val = atof (floatstring); |
208 float val = atof (floatstring); |
208 write (DH_PUSHNUMBER); |
209 write (dh_push_number); |
209 write (static_cast<word> ((val > 0) ? val : -val)); |
210 write (static_cast<word> (abs (val))); |
210 |
211 |
211 if (val < 0) |
212 if (val < 0) |
212 write (DH_UNARYMINUS); |
213 write (dh_unary_minus); |
213 } |
214 } |
214 |
215 |
215 // ============================================================================ |
216 // ============================================================================ |
216 // |
217 // |
217 void data_buffer::write_string (string a) |
218 void data_buffer::write_string (string a) |
218 { |
219 { |
219 write (DH_PUSHSTRINGINDEX); |
220 write (dh_push_string_index); |
220 write (get_string_table_index (a)); |
221 write (get_string_table_index (a)); |
221 } |
222 } |
222 |
223 |
223 // ============================================================================ |
224 // ============================================================================ |
224 // |
225 // |