mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Add test case sort-algorithms.asm
This combines 0.5.0 and post-0.5.0 features:
print and println, strfmt, for loops,
def assignments, redef equs, {interpolation},
new macro syntax, and \<bracketed macro args>
This commit is contained in:
47
test/asm/sort-algorithms.asm
Normal file
47
test/asm/sort-algorithms.asm
Normal file
@@ -0,0 +1,47 @@
|
||||
MACRO sort_recursive
|
||||
if _NARG > 0
|
||||
def min_i = 1
|
||||
for i, 2, _NARG + 1
|
||||
if \<i> < \<min_i>
|
||||
def min_i = i
|
||||
endc
|
||||
endr
|
||||
print strfmt("%d", \<min_i>)
|
||||
endc
|
||||
if _NARG > 1
|
||||
print ", "
|
||||
redef _subsort equs "sort_recursive "
|
||||
for i, 1, _NARG + 1
|
||||
if i != min_i
|
||||
redef _subsort equs "{_subsort}\<i>,"
|
||||
endc
|
||||
endr
|
||||
{_subsort}
|
||||
else
|
||||
println
|
||||
endc
|
||||
ENDM
|
||||
|
||||
MACRO sort_iterative
|
||||
for i, 1, _NARG + 1
|
||||
def got_{d:i} = 0
|
||||
endr
|
||||
for n, 1, _NARG + 1
|
||||
def min_i = 1
|
||||
for i, 2, _NARG + 1
|
||||
if (\<i> < \<min_i> && !got_{d:i}) || got_{d:min_i}
|
||||
def min_i = i
|
||||
endc
|
||||
endr
|
||||
def got_{d:min_i} = 1
|
||||
print strfmt("%d", \<min_i>)
|
||||
if n < _NARG
|
||||
print ", "
|
||||
else
|
||||
println
|
||||
endc
|
||||
endr
|
||||
ENDM
|
||||
|
||||
sort_recursive 16, 0, 16, 5, 1, 18, 3, 14, 19, 4, 6, 13, 17, 7, 11, 8, 15, 10, 12, 9, 2
|
||||
sort_iterative 16, 0, 16, 5, 1, 18, 3, 14, 19, 4, 6, 13, 17, 7, 11, 8, 15, 10, 12, 9, 2
|
||||
Reference in New Issue
Block a user