Skip to content

Commit 6e3fbe3

Browse files
committed
Merge branch 'master' into asar_2_beta
2 parents 4ce602f + bf909eb commit 6e3fbe3

File tree

12 files changed

+144
-60
lines changed

12 files changed

+144
-60
lines changed

docs/changelog/index.html

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ <h3>Contributors:</h3>
7474
<ul>
7575
<li>RPG Hacker</li>
7676
<li>randomdude999</li>
77+
<li>p4plus2</li>
78+
<li>Atari2</li>
7779
</ul>
7880

7981
<h3>Notes:</h3>
@@ -86,6 +88,9 @@ <h3>New features:</h3>
8688
<li>The Asar test suite can now verify user-printable strings. (RPG Hacker)</li>
8789
<li>The <code>error</code>, <code>warn</code> and <code>assert</code> commands now support the same functions as the print command. (RPG Hacker)</li>
8890
<li>Static labels (i.e. labels that don't move between passes) can now be used in more places, including if statements. (RPG Hacker)</li>
91+
<li>Asar can be built as a static library. (Atari2)</li>
92+
<li>Asar now uses named warnings and errors instead of magic numbers as identifiers. (p4plus2, RPG Hacker)</li>
93+
<li>Variadic macro parameters now use the syntax <code class="65c816_asar">&lt;...[math]&gt;</code>, which makes them less ambiguous and helps prevent syntax parsing bugs. (RPG Hacker)</li>
8994
</ul>
9095

9196
<h3>Bug fixes:</h3>
@@ -95,12 +100,33 @@ <h3>Bug fixes:</h3>
95100
<li>Macro calls & definitions no longer break as easily from including whitespace. (RPG Hacker)</li>
96101
<li>For invalid table files, Asar now prints the line number of the first invalid entry. (RPG Hacker)</li>
97102
<li>When Asar generates addr-to-line mappings, it now includes multiple addresses for pseudo opcodes like &quot;asl #4&quot;. (RPG Hacker)</li>
98-
<li><code>'''</code> and <code>';'</code> can now be used without causing errors. (randomdude999, RPG Hacker)</li>
103+
<li><code>'''</code> and <code>';'</code> are now valid can now be used without causing errors. (randomdude999, RPG Hacker)</li>
104+
<li>Fixed some edge case bugs in Asar's virtual filesystem (usable via the DLL) on Windows. (Atari2)</li>
99105
</ul></div>
100106

101107
<h3>Deprecated features:</h3>
102108
<ul>
103-
<li>Warning and error IDs: Asar now uses named warnings and errors. (p4plus2, RPG Hacker)</li>
109+
<li>Warning and error IDs: Use new name strings instead.</li>
110+
<li><code>JMP.l</code>: Use <code>JML</code> instead.</li>
111+
<li>Quoted symbolic arguments to functions (e.g. <code>sizeof("my_struct")</code>): Remove the quotes (<code>sizeof(my_struct)</code>).</li>
112+
<li>Redefining previously defined functions.</li>
113+
<li><code>math round</code> and <code>math pri</code>: Use parentheses and explicit rounding where xkas-style math emulation is needed instead.</li>
114+
<li><code>.d</code> length specifier on opcodes.</li>
115+
<li><code>if !condition</code> to negate conditions: Use <code>if not(condition)</code> instead.</li>
116+
<li>While blocks ending with <code>endif</code>: Use <code>endwhile</code> instead.</li>
117+
<li><code>bankcheck on</code>: Use <code>bankcheck full</code> or <code>bankcheck half</code> instead.</li>
118+
<li><code>rep</code> to repeat commands: Use while loops or unrolled loops instead.</li>
119+
<li>Windows-specific paths (e.g. <code>incsrc dir\file.asm</code>): Use cross-platform paths instead (<code>incsrc dir/file.asm</code>).</li>
120+
<li><code>table</code> command: Assign characters directly instead, like <code>'a' = $00</code>.</li>
121+
<li>Labels in <code>padbyte</code> or <code>fillbyte</code> commands.</li>
122+
<li><code>spc700-raw</code> architecture: Use <code>spc700</code> with <code>norom</code> instead.</li>
123+
<li><code>fastrom</code>: Has never actually worked and can be removed.</li>
124+
<li><code>header</code>: Doesn't do anything and can be removed.</li>
125+
<li>Non-UTF-8 source files: Re-save your source files as UTF-8 in a text editor of choice.</li>
126+
<li><code>;@command</code> and <code>@command</code> notation: Use <code>command</code> instead.</li>
127+
<li>Wrapping defines to resolve in quotes (e.g. <code>db "!define"</code>): The quotes aren't needed (<code>db !define</code>).</li>
128+
<li>Single-line/inline if statements: Use full if blocks with an <code>if</code>/<code>endif</code> pair instead.</li>
129+
<li><code class="65c816_asar">&lt;math&gt;</code> syntax for variadic macro parameters: Use <code class="65c816_asar">&lt;...[math]&gt;</code> insread.</li>
104130
</ul></div>
105131

106132
<hr />

docs/manual/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,27 +2455,27 @@ <h4 id="built-in-defines">Built-in Defines</h4>
24552455
%use_x_safely("ldx $10 : stx $11 : ldx #10 : stx $12")
24562456
</code></pre>
24572457
<h4 id="variadic-macros">Variadic Macros</h4>
2458-
In addition to named substitutions, if the variadic token <code class="65c816_asar">...</code> is specified as the last parameter Asar will allow an arbitrary number of parameters after all prior parameters have been satisfied.
2459-
To access unnamed arguments of a variadic function they are declared numerically starting from 0 up to the number of provided parameters. To access the number of provided variadic arguments one may use <code class="65c816_asar">sizeof(...)</code>.
2460-
Lastly, it is important to note that while traditionally macros do not parse defines at their creation variadic macros will. This is to allow iteration of arguments by using defines.
2458+
In addition to named substitutions if the variadic token <code class="65c816_asar">...</code> is specified as the last parameter asar will allow an arbitrary number of parameters after all prior parameters have been satisfied.
2459+
To access unnamed parameters of a variadic macro, use the syntax <code class="65c816_asar">&lt;...[{math}]&gt;</code>, where <code class="65c816_asar">math</code> is any math expression evaluating to the index of a variadic parameter. These are declared numerically starting from 0 up to the number of provided parameters. To access the number of provided variadic arguments one may use <code class="65c816_asar">sizeof(...)</code>.
2460+
Lastly, it is important to note that while traditional macros do not parse defines inside parameters, variadic macros will. This is to allow iteration of arguments by using defines.
24612461

24622462
<pre><code class="65c816_asar">
24632463
macro example0(...)
2464-
db sizeof(...), &lt;0&gt; ;04 01
2464+
db sizeof(...), &lt;...[0]&gt; ;04 01
24652465
endmacro
24662466

24672467
macro example1(...)
24682468
!a #= 0
24692469
while !a &lt; sizeof(...)
2470-
db &lt;!a&gt; ;01 02 03
2470+
db &lt;...[!a]&gt; ;01 02 03
24712471
!a #= !a+1
24722472
endif
24732473
endmacro
24742474

24752475
macro example2(named_parameter, ...)
24762476
!a #= 0
24772477
while !a &lt; sizeof(...)
2478-
db &lt;!a&gt; ;02 03 04 05 06 07
2478+
db &lt;...[!a]&gt; ;02 03 04 05 06 07
24792479
!a #= !a+1
24802480
endif
24812481
db &lt;named_parameter&gt; ;01
@@ -2484,7 +2484,7 @@ <h4 id="variadic-macros">Variadic Macros</h4>
24842484
macro macro_with_optional_arguments(required, ...)
24852485
db &lt;required&gt;
24862486
if sizeof(...) &gt; 0
2487-
db &lt;0&gt;
2487+
db &lt;...[0]&gt;
24882488
end
24892489
end
24902490

src/asar-tests/test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ int main(int argc, char * argv[])
845845
{ "cmddefined", nullptr },
846846
{ "!cmddefined2", "" },
847847
{ " !cmddefined3 ", " $10,$F0,$E0 "},
848-
// RPG Hacker: 日本語🇯🇵 in UTF-8
848+
// RPG Hacker: 日本語������ǵ in UTF-8
849849
{ "cmdl_define_utf8", "\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e\xf0\x9f\x87\xaf\xf0\x9f\x87\xb5" },
850850
};
851851

@@ -992,7 +992,7 @@ int main(int argc, char * argv[])
992992
// randomdude999: temp workaround: using $ in command line is unsafe on linux, so use dec representation instead (for !cmddefined3)
993993
snprintf(cmd, sizeof(cmd),
994994
"\"%s\" -I\"%s\" -Dcli_only=\\$1 -Dcmddefined -D!cmddefined2= --define \" !cmddefined3 = 16,240,224 \""
995-
// RPG Hacker: 日本語🇯🇵 in UTF-8
995+
// RPG Hacker: 日本語������ǵ in UTF-8
996996
" -Dcmdl_define_utf8=\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e\xf0\x9f\x87\xaf\xf0\x9f\x87\xb5"
997997
" \"%s\" \"%s\"",
998998
asar_exe_path, base_path, fname, out_rom_name);

src/asar/errors.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static asar_error_mapping asar_errors[] =
282282
{ ERR(pushns_without_pullns), "pushns without matching pullns." },
283283
{ ERR(pullns_without_pushns), "pullns without matching pushns." },
284284

285-
{ ERR(label_forward), "The use of forward labels is not allowed in this context" },
285+
{ ERR(label_forward), "The use of forward labels is not allowed in this context." },
286286
{ ERR(undefined_char), "'%s' is not defined in the character table" },
287287

288288
{ ERR(invalid_utf8), "Invalid text encoding detected. Asar expects UTF-8-encoded text. Please re-save this file in a text editor of choice using UTF-8 encoding." },
@@ -293,6 +293,9 @@ static asar_error_mapping asar_errors[] =
293293

294294
{ ERR(oob), "Operation out of bounds: Requested index %d for object of size %d" },
295295

296+
{ ERR(unclosed_vararg), "Variadic macro parameter wasn't closed properly." },
297+
{ ERR(invalid_vararg), "Trying to use variadic macro parameter syntax to resolve a non variadic argument." },
298+
296299
{ ERR(macro_param_outside_macro), "Reference to macro parameter outside of macro" },
297300
{ ERR(invalid_depth_resolve), "Invalid %s resolution depth: Trying to backwards-resolve a %s using %i '^', but current scope only supports up to %i '^'." },
298301
};

src/asar/errors.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ enum asar_error_id : int
267267
error_id_phantom_error,
268268

269269
error_id_oob,
270+
271+
error_id_unclosed_vararg,
272+
error_id_invalid_vararg,
270273

271274
error_id_macro_param_outside_macro,
272275
error_id_invalid_depth_resolve,

src/asar/macro.cpp

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "assembleblock.h"
33
#include "macro.h"
44
#include "asar_math.h"
5+
#include "warnings.h"
56

67
assocarr<macrodata*> macros;
78
string defining_macro_name;
@@ -339,7 +340,9 @@ string replace_macro_args(const char* line) {
339340

340341
if (depth != in_macro_def)
341342
{
342-
out+=*(in++);
343+
string temp(in, end-in+1);
344+
out+=temp;
345+
in=end+1;
343346
if (depth > in_macro_def)
344347
{
345348
if (in_macro_def > 0) asar_throw_error(0, error_type_line, error_id_invalid_depth_resolve, "macro parameter", "macro parameter", depth, in_macro_def-1);
@@ -349,18 +352,29 @@ string replace_macro_args(const char* line) {
349352
}
350353

351354
if (depth > 0 && !inmacro) asar_throw_error(0, error_type_line, error_id_invalid_depth_resolve, "macro parameter", "macro parameter", depth, in_macro_def-1);
355+
in += depth+1;
356+
357+
bool proper_variadic = false;
358+
if (in[0] == '.' && in[1] == '.' && in[2] == '.' && in[3] == '[')
359+
{
360+
if (end[-1] != ']')
361+
asar_throw_error(0, error_type_block, error_id_unclosed_vararg);
362+
363+
proper_variadic = true;
364+
in += 4;
365+
end--;
366+
}
352367

353368
if(!inmacro) asar_throw_error(0, error_type_block, error_id_macro_param_outside_macro);
354369
//*end=0;
355-
in += depth+1;
356370
string param;
357371
string temp(in, end-in);
358372
resolvedefines(param, temp);
359373
in = param.data();
360374
bool valid_named_param = confirmname(in);
361375
if (!valid_named_param && !current_macro->variadic) asar_throw_error(0, error_type_block, error_id_invalid_macro_param_name);
362376
bool found=false;
363-
for (int j=0;current_macro->arguments[j];j++)
377+
for (int j=0;current_macro->arguments[j]&&!proper_variadic;j++)
364378
{
365379
if (!strcmp(in, current_macro->arguments[j]))
366380
{
@@ -372,8 +386,17 @@ string replace_macro_args(const char* line) {
372386
if (!found)
373387
{
374388
snes_label ret;
375-
if(valid_named_param && !current_macro->variadic) asar_throw_error(0, error_type_block, error_id_macro_param_not_found, generate_macro_arg_string(in, depth).raw(), generate_macro_hint_string(in, current_macro, depth).raw());
376-
if(current_macro->variadic && valid_named_param && !labelval(in, &ret, false)) asar_throw_error(0, error_type_block, error_id_macro_param_not_found, generate_macro_arg_string(in, depth).raw(), generate_macro_hint_string(in, current_macro, depth).raw());
389+
if(valid_named_param && !current_macro->variadic)
390+
{
391+
if (proper_variadic) asar_throw_error(0, error_type_block, error_id_invalid_vararg, in);
392+
else asar_throw_error(0, error_type_block, error_id_macro_param_not_found, generate_macro_arg_string(in, depth).raw(), generate_macro_hint_string(in, current_macro, depth).raw());
393+
}
394+
if(current_macro->variadic && valid_named_param && !labelval(in, &ret, false))
395+
{
396+
if (proper_variadic) asar_throw_error(0, error_type_block, error_id_invalid_vararg, in);
397+
else asar_throw_error(0, error_type_block, error_id_macro_param_not_found, generate_macro_arg_string(in, depth).raw(), generate_macro_hint_string(in, current_macro, depth).raw());
398+
}
399+
if(!proper_variadic) asar_throw_warning(0, warning_id_feature_deprecated, "'<math>' syntax for variadic macro parameters", "Use '<...[math]>' instead.");
377400
int arg_num = getnum(in);
378401

379402
if(forwardlabel) asar_throw_error(0, error_type_block, error_id_label_forward);
@@ -383,6 +406,7 @@ string replace_macro_args(const char* line) {
383406
out+=current_macro_args[arg_num+current_macro->numargs-1];
384407
}
385408
in=end+1;
409+
if (proper_variadic) in++;
386410
}
387411
else out+=*(in++);
388412
}

tests/include/macro_fuckery_include.asm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ db <the_fun_part>
33
macro recursive_macro(...)
44
!temp_i #= 0
55
while !temp_i < sizeof(...)
6-
db $<!temp_i>
6+
db $<...[!temp_i]>
77
8-
!test_<!temp_i>_test = !temp_i
8+
!test_<...[!temp_i]>_test = !temp_i
99
10-
if !test_<!temp_i>_test == 0
10+
if !test_<...[!temp_i]>_test == 0
1111
db $EF
12-
elseif !test_<!temp_i>_test == 1
12+
elseif !test_<...[!temp_i]>_test == 1
1313
db $EE
1414
endif
1515
@@ -26,15 +26,15 @@ if 0
2626
macro recursive_macro_2(...)
2727
!temp_i #= 0
2828
while !temp_i < sizeof(...)
29-
db $<!temp_i>
30-
%recursive_macro(<!temp_i>)
31-
!recursive_macro(<!temp_i>)
29+
db $<...[!temp_i]>
30+
%recursive_macro(<...[!temp_i]>)
31+
!recursive_macro(<...[!temp_i]>)
3232
33-
!test_<!temp_i>_test = 1
33+
!test_<...[!temp_i]>_test = 1
3434
35-
if !test_<!temp_i>_test == 0
35+
if !test_<...[!temp_i]>_test == 0
3636
db $10
37-
elseif !test_<!temp_i>_test == 1
37+
elseif !test_<...[!temp_i]>_test == 1
3838
db $11
3939
endif
4040

tests/macro_fuckery_fail.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ macro wrong_layer_parent(parent_arg, ...)
5151
endmacro
5252

5353
macro wrong_layer_child_4(...)
54-
db <0>+<1>
54+
db <...[0]>+<...[1]>
5555
endmacro
5656

5757
macro wrong_layer_inbeteen(unused, ...)
5858
macro wrong_layer_grand_child(child_arg, ...)
5959
db <parent_arg>
6060
db <^parent_arg>
6161
db <^^child_arg>
62-
db <2>
62+
db <...[2]>
6363
endmacro
6464
endmacro
6565
endmacro

tests/macro_fuckery_pass.asm

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ org $008000
3333
macro new_macro(...)
3434
!temp_i #= 0
3535
while !temp_i < sizeof(...)
36-
db <!temp_i>
36+
db <...[!temp_i]>
3737
38-
!test_<!temp_i>_test = !temp_i
38+
!test_<...[!temp_i]>_test = !temp_i
3939
40-
if !test_<!temp_i>_test == 0
40+
if !test_<...[!temp_i]>_test == 0
4141
db $FF
42-
elseif !test_<!temp_i>_test == 1
42+
elseif !test_<...[!temp_i]>_test == 1
4343
db $FE
4444
endif
4545
@@ -56,15 +56,15 @@ if 0
5656
macro new_macro_2(...)
5757
!temp_i #= 0
5858
while !temp_i < sizeof(...)
59-
<!temp_i>
60-
%new_macro(<!temp_i>)
61-
!new_macro(<!temp_i>)
59+
<...[!temp_i]>
60+
%new_macro(<...[!temp_i]>)
61+
!new_macro(<...[!temp_i]>)
6262
63-
!test_<!temp_i>_test = 1
63+
!test_<...[!temp_i]>_test = 1
6464
65-
if !test_<!temp_i>_test == 0
65+
if !test_<...[!temp_i]>_test == 0
6666
db $00
67-
elseif !test_<!temp_i>_test == 1
67+
elseif !test_<...[!temp_i]>_test == 1
6868
db $01
6969
endif
7070
@@ -119,16 +119,16 @@ macro define_variadic_macros(...)
119119
!temp_i #= 0
120120

121121
while !temp_i < sizeof(...)
122-
macro <!temp_i>(<!temp_i+1>, ...)
123-
print "<^!^temp_i>"
124-
print "<^!^temp_i+1>"
122+
macro <...[!temp_i]>(<...[!temp_i+1]>, ...)
123+
print "<^...[!^temp_i]>"
124+
print "<^...[!^temp_i+1]>"
125125

126-
db <<^!^temp_i+1>>
126+
db <<^...[!^temp_i+1]>>
127127

128128
!temp_j #= 0
129129

130130
while !temp_j < sizeof(...)
131-
db <!temp_j>
131+
db <...[!temp_j]>
132132
!temp_j #= !temp_j+1
133133
endwhile
134134

@@ -164,7 +164,7 @@ macro insanely_define_macro(...)
164164
!temp_arg_usage = "db "
165165

166166
while !temp_i < sizeof(...)
167-
!temp_arg := "<!temp_i>"
167+
!temp_arg := "<...[!temp_i]>"
168168
!temp_arg_list += !temp_arg
169169
!temp_arg_usage += "<"
170170
!temp_arg_usage += "!temp_arg"
@@ -180,7 +180,7 @@ macro insanely_define_macro(...)
180180
!temp_i #= !temp_i+1
181181
endwhile
182182

183-
macro <0>(!temp_arg_list)
183+
macro <...[0]>(!temp_arg_list)
184184
!^temp_arg_usage
185185
endmacro
186186

0 commit comments

Comments
 (0)