Skip to content

Commit f5e0383

Browse files
authored
Merge pull request #26 from Snektron/master
Add Pareas
2 parents 9124dd7 + 8f6544c commit f5e0383

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ compilers. Supported languages are:
1818
- [V](https://vlang.io/) (using `v`),
1919
- [Vox](https://github.com/MrSmith33/vox) (using `vox`),
2020
- [C3](https://github.com/c3lang/c3c) (using `c3c`),
21+
- [Pareas](https://github.com/Snektron/pareas) (using `pareas`),
2122

2223
## Languages with Bytecode Compilers:
2324

benchmark

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ from timeit import default_timer as timer
2121
from process_timer import ProcessTimer
2222

2323

24-
SUPPORTED_LANGUAGES = ['C', 'C++', 'Ada', 'C#', 'Swift', 'Java', 'D', 'Vox', 'Rust', 'Nim', 'Zig', 'Go', 'V', 'C3', 'Julia', 'OCaml']
24+
SUPPORTED_LANGUAGES = ['C', 'C++', 'Ada', 'C#', 'Swift', 'Java', 'D', 'Vox', 'Rust', 'Nim', 'Zig', 'Go', 'V', 'C3', 'Julia', 'OCaml', 'Pareas']
2525
TEMPLATED_SUPPORTED_LANGUAGES = ['C++', 'Java', 'D', 'Swift', 'Vox', 'Rust', 'Zig', 'V', 'C3', 'Julia']
2626
SUPPORTED_OPERATIONS = ['Check', 'Compile', 'Build']
2727
DEFAULT_PROGRAM_NAME = 'main'
@@ -408,6 +408,12 @@ def main():
408408
if 'Build' in args.operations:
409409
benchmark_Java(results=results, code_paths=code_paths, args=args, op='Build', templated=False)
410410

411+
if 'Pareas' in args.languages:
412+
if 'Check' in args.operations:
413+
benchmark_Pareas(results=results, code_paths=code_paths, args=args, op='Check', templated=False)
414+
if 'Build' in args.operations:
415+
benchmark_Pareas(results=results, code_paths=code_paths, args=args, op='Build', templated=False)
416+
411417
# Julia and Ocaml take too long otherwise. So let them participate by
412418
# truncating size because ops/function are measured
413419
function_count = args.function_count
@@ -974,6 +980,22 @@ def benchmark_Java(results, code_paths, args, op, templated):
974980
templated=templated,
975981
results=results)
976982

983+
def benchmark_Pareas(results, code_paths, args, op, templated):
984+
lang = 'Pareas'
985+
exe = match_lang(args, lang, 'pareas')
986+
if exe:
987+
compile_file(code_paths,
988+
out_flag_and_exe=['-o', out_binary(lang)],
989+
exe=exe,
990+
runner=False,
991+
exe_flags=['--check'] if op == 'Check' else [],
992+
args=args,
993+
op=op,
994+
compiler_version='unknown',
995+
lang=lang,
996+
templated=templated,
997+
results=results)
998+
977999

9781000
def benchmark_Julia(results, code_paths, args, op, templated):
9791001
lang = 'Julia'
@@ -1154,6 +1176,8 @@ def long_types_of_lang(lang):
11541176
return ['float']
11551177
elif lang == 'ada':
11561178
return ['Long_Integer'] # gnat
1179+
elif lang == 'pareas':
1180+
return ['int']
11571181
else:
11581182
return None
11591183

@@ -1171,6 +1195,8 @@ def language_file_extension(lang):
11711195
return 'vx'
11721196
elif lang == 'ada':
11731197
return 'adb'
1198+
elif lang == 'pareas':
1199+
return 'par'
11741200
else:
11751201
return lang
11761202

@@ -1236,6 +1262,8 @@ def generate_test_function_call(lang, findex, typ, f, templated):
12361262
X='[' + typ + ']' if templated else ''))
12371263
elif lang == 'swift':
12381264
f.write(Tm(' ${T}_sum += add_${T}_n${N}(x: ${N})').substitute(T=typ, N=str(findex)))
1265+
elif lang == 'pareas':
1266+
f.write(Tm(' ${T}_sum = ${T}_sum + add_${T}_n${N}[${N}]').substitute(T=typ, N=str(findex)))
12391267
else:
12401268
f.write(Tm(' ${T}_sum += add_${T}_n${N}(${N})').substitute(T=typ, N=str(findex)))
12411269

@@ -1302,6 +1330,8 @@ def generate_test_language_specific_postfix(lang, types, f):
13021330
f.write(Tm('\n\n').substitute(T=types[0]))
13031331
elif lang == 'c3':
13041332
f.write(Tm(' return (int)(${T}_sum);\n}\n').substitute(T=types[0]))
1333+
elif lang == 'pareas':
1334+
f.write(Tm(' return ${T}_sum;\n}\n').substitute(T=types[0]))
13051335
elif lang == 'julia':
13061336
f.write(Tm(''' return ${T}_sum;
13071337
end
@@ -1386,6 +1416,8 @@ def generate_test_function_definition(args, lang, typ, findex, fheight, f,
13861416
expr = 'x +. (' + function_name(typ, findex, fheight - 1) + xtarg + ' x) +. ' + nconst + '.0'
13871417
elif lang == 'swift':
13881418
expr = 'x + ' + function_name(typ, findex, fheight - 1) + '(x: ' + xtarg + 'x) + ' + nconst
1419+
elif lang == 'pareas':
1420+
expr = 'x + ' + function_name(typ, findex, fheight - 1) + '[x] + ' + nconst
13891421
else:
13901422
expr = 'x + ' + function_name(typ, findex, fheight - 1) + '(' + xtarg + 'x) + ' + nconst
13911423

@@ -1475,6 +1507,8 @@ def generate_test_function_definition(args, lang, typ, findex, fheight, f,
14751507
elif lang == 'julia':
14761508
f.write(Tm('function ${F}(x${QT})${QT}\n return ${X}\nend;\n').substitute(QT=('' if templated else ('::' + typ)),
14771509
F=str(fname), N=nconst, H=str(fheight), X=expr))
1510+
elif lang == 'pareas':
1511+
f.write(Tm('fn ${F}[x: ${T}]: ${T} { return ${X}; }\n').substitute(T=typ, F=str(fname), X=expr))
14781512

14791513

14801514
def generate_test_main_header(lang, types, f, templated):
@@ -1510,6 +1544,8 @@ def generate_test_main_header(lang, types, f, templated):
15101544
f.write('let () = \n')
15111545
elif lang == 'nim':
15121546
f.write('when isMainModule:\n')
1547+
elif lang == 'pareas':
1548+
f.write('fn main[]: int {\n')
15131549
else:
15141550
assert False
15151551

@@ -1544,6 +1580,8 @@ def generate_main_test_function_variable(lang, typ, f, templated):
15441580
f.write(Tm(' ${T}_sum${QT} = 0;\n').substitute(T=typ, QT=(('::' + typ) if templated else '')))
15451581
elif lang == 'ocaml':
15461582
f.write(Tm(' let ${T}_sum = 0.0 in\n').substitute(T=typ))
1583+
elif lang == 'pareas':
1584+
f.write(Tm(' var ${T}_sum: ${T} = 0;\n').substitute(T=typ))
15471585
else:
15481586
assert False
15491587

@@ -1628,6 +1666,8 @@ def generate_test_program_2(function_count, lang, templated):
16281666
end;
16291667
''').substitute(QT=('' if templated else ('::' + typ)), N=str(findex)))
16301668
f.write('\n')
1669+
elif lang == 'pareas':
1670+
f.write(Tm('fn add_${T}_n${N}[x: ${T}]: ${T} { return x + ${N}; }').substitute(T=typ, N=str(findex)))
16311671

16321672
# MAIN HEADER
16331673
if lang in ['c', 'c++']:
@@ -1653,6 +1693,8 @@ end;
16531693
elif lang == 'julia':
16541694
f.write(Tm('''function main()::${T}
16551695
''').substitute(T=types[0]))
1696+
elif lang == 'pareas':
1697+
f.write(Tm('fn main[]: ${T} {\n').substitute(T=types[0]))
16561698
else:
16571699
assert False
16581700

@@ -1676,11 +1718,16 @@ end;
16761718
elif lang == 'julia':
16771719
f.write(Tm(''' ${T}_sum${QT} = 0;
16781720
''').substitute(QT=('' if templated else ('::' + typ))))
1721+
elif lang == 'pareas':
1722+
f.write(Tm(' var ${T}_sum: ${T} = 0;\n').substitute(T=typ))
16791723
else:
16801724
assert False
16811725

1682-
for findex in range(0, function_count):
1683-
f.write(Tm(''' ${T}_sum += add_${T}_n${N}(${N});
1726+
if lang == 'pareas':
1727+
f.write(Tm(' ${T}_sum += add_${T}_n${N}[${N}];').substitute(T=typ, N=str(findex)))
1728+
else:
1729+
for findex in range(0, function_count):
1730+
f.write(Tm(''' ${T}_sum += add_${T}_n${N}(${N});
16841731
''').substitute(T=typ, N=str(findex)))
16851732

16861733
if lang == 'rust':

0 commit comments

Comments
 (0)