Created
June 27, 2013 11:42
-
-
Save orian/5875825 to your computer and use it in GitHub Desktop.
simple script to generate 31 possible loops in Dart (http://dartlang.org)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from string import Template | |
import itertools | |
def GenerateOne(name, initializer, test, update, use_break, use_continue): | |
if not test and not use_break: | |
return | |
tmpl = Template(""" | |
$name() { | |
$before_loop for ($init; $test; $update) { | |
$loop }$after_loop | |
} | |
""") | |
def_values = { | |
'name': name, | |
'before_loop': '', | |
'init': '', | |
'test': '', | |
'update': '', | |
'loop': '', | |
'after_loop': '' | |
} | |
# i must be initialized in or before loop | |
if initializer: | |
def_values['init'] = 'var i = 0' | |
else: | |
def_values['before_loop'] = ' var i = 0\n' | |
if test: | |
def_values['test'] = 'i < 5' | |
if use_break: | |
def_values['loop'] += ''' if (i > 3) { | |
break; | |
}\n''' | |
if update: | |
def_values['update'] = '++i' | |
else: | |
def_values['loop'] += ' ++i;\n' | |
if use_continue: | |
def_values['loop'] += ''' if (i>2) { | |
continue; | |
}\n''' | |
print(tmpl.substitute(def_values)) | |
def GenerateAll(): | |
num = 0 | |
for vals in itertools.product([True, False], repeat=5): | |
GenerateOne('f_%s' % num, *vals) | |
num+=1 | |
if __name__ == '__main__': | |
GenerateAll() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f_0() { | |
for (var i = 0; i < 5; ++i) { | |
if (i > 3) { | |
break; | |
} | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_1() { | |
for (var i = 0; i < 5; ++i) { | |
if (i > 3) { | |
break; | |
} | |
} | |
} | |
f_2() { | |
for (var i = 0; i < 5; ++i) { | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_3() { | |
for (var i = 0; i < 5; ++i) { | |
} | |
} | |
f_4() { | |
for (var i = 0; i < 5; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_5() { | |
for (var i = 0; i < 5; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
} | |
} | |
f_6() { | |
for (var i = 0; i < 5; ) { | |
++i; | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_7() { | |
for (var i = 0; i < 5; ) { | |
++i; | |
} | |
} | |
f_8() { | |
for (var i = 0; ; ++i) { | |
if (i > 3) { | |
break; | |
} | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_9() { | |
for (var i = 0; ; ++i) { | |
if (i > 3) { | |
break; | |
} | |
} | |
} | |
f_12() { | |
for (var i = 0; ; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_13() { | |
for (var i = 0; ; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
} | |
} | |
f_16() { | |
var i = 0 | |
for (; i < 5; ++i) { | |
if (i > 3) { | |
break; | |
} | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_17() { | |
var i = 0 | |
for (; i < 5; ++i) { | |
if (i > 3) { | |
break; | |
} | |
} | |
} | |
f_18() { | |
var i = 0 | |
for (; i < 5; ++i) { | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_19() { | |
var i = 0 | |
for (; i < 5; ++i) { | |
} | |
} | |
f_20() { | |
var i = 0 | |
for (; i < 5; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_21() { | |
var i = 0 | |
for (; i < 5; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
} | |
} | |
f_22() { | |
var i = 0 | |
for (; i < 5; ) { | |
++i; | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_23() { | |
var i = 0 | |
for (; i < 5; ) { | |
++i; | |
} | |
} | |
f_24() { | |
var i = 0 | |
for (; ; ++i) { | |
if (i > 3) { | |
break; | |
} | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_25() { | |
var i = 0 | |
for (; ; ++i) { | |
if (i > 3) { | |
break; | |
} | |
} | |
} | |
f_28() { | |
var i = 0 | |
for (; ; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
if (i>2) { | |
continue; | |
} | |
} | |
} | |
f_29() { | |
var i = 0 | |
for (; ; ) { | |
if (i > 3) { | |
break; | |
} | |
++i; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment