zayac / eq Goto Github PK
View Code? Open in Web Editor NEWA stream-based functional language
A stream-based functional language
Eq is a stream-based functional language designed for solving numerical tasks. The syntax of the Eq programming language is based on a document preparation system LaTeX. It follows that source files of the Eq can be interpreted by any LaTeX conversion tool (i.e. pdflatex, latex2html, etc.). The current version uses Python as a backend language. Version: 0.1.1 Contribution: Pavel Zaichenkov <[email protected]> Artem Shinkarov <[email protected]> In order to build the compiler do the following: $ cd build/ $ cmake .. $ make CMake cache variables can be defined: -DBUILD_LEXER=[ON|<OFF>] = Select either to build the lexer only. -DBACKEND_LANG=[<python>|sac] = Select compiler's backend. -DFIRST_CLASS_FUNCTIONS=[<ON>|OFF] = Enable or disable functions as a first-class objects. -DCFG_OUTPUT=[<ON>|OFF] = Enable a flow graph output in graphviz notation. -DRELEASE=[<ON>|<OFF>] = Build compiler with highest optimisations enabled. In case you want to run a test bundle: $ ctest or $ make test A verbose output of the build is supported: $ make VERBOSE=1 It's possible to execute tests separately: $ ctest -R run_test | Tests compilation of a correct syntax on | different stages (parser, type checking | and code generating). $ ctest -R error_test | Tests invalid syntax processing and error | handing. $ ctest -R cfg_test | Validates a cfg tree generated by the | compiler. Needs -DCFG_OUTPUT option to be | turned on. $ ctest -R exec_test | Validates the output of the compiler. $ ctest -R memory_test | Looks for memory leaks in the compiler.
When there is an incorrect number of variables in the assignment, it causes SEGFAULT.
Test case:
\begin{eqcode}{\alpha}{\ }{\ }{\type{Z}, \type{Z}}
\return {1, 2} \lend
\end{eqcode}
\begin{eqcode}{\mu}{\ }{\ }{\type{Z}}
a \in \overline{\type{Z}} \lend
a^{[0]} \gets \call{\alpha}{\ } \lend
\return {a^{[0]}} \lend
\end{eqcode}
Need to fix
To reproduce, run: /usr/bin/ctest -j5 -R '^exec'
which produces loads of output and:
24% tests passed, 19 tests failed out of 25
Total Test time (real) = 0.78 sec
The following tests FAILED:
102 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/b.tex (Failed)
103 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/function_assign1.tex (Failed)
104 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/sqrt.tex (Failed)
105 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/function1.tex (Failed)
106 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/streams-first-class.tex (Failed)
107 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/filter2.tex (Failed)
109 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/fibonacci.tex (Failed)
112 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/filter.tex (Failed)
113 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/d.tex (Failed)
114 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/function_assign3.tex (Failed)
117 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/rsa.tex (Failed)
118 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/streams-first-class2.tex (Failed)
119 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/function_assign2.tex (Failed)
120 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/genarray.tex (Failed)
121 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/print.tex (Failed)
122 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/a.tex (Failed)
123 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/c.tex (Failed)
124 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/gcd.tex (Failed)
125 - exec_test_/home/tema/src/eq/tests/codegen_tests_python/iter.tex (Failed)
whereas running without -j5
passes all of them:
/usr/bin/ctest -R '^exec'
...
100% tests passed, 0 tests failed out of 25
My assumption is that it doesn't like the fact that output file is always called out.txt
. Hopefully naming it differently would resolve the issue.
By some reason greek variable names survive until the code generation and kill the python interpreter. Example:
\begin{eqcode}{foo}{\tau}{\type{Z}}{\type{Z}}
\return {\tau + 1} \lend
\end{eqcode}
\begin{eqcode}{\mu}{\ }{\ }{\type{Z}}
\return {\call{foo}{42}} \lend
\end{eqcode}
results in the following python code:
def foo(foo_\tau):
return((foo_\tau + 1))
def __main():
return(foo(42))
May be the last ssa did it? Dunno.
The current version causes some memory tests to fail:
95% tests passed, 10 tests failed out of 204
Total Test time (real) = 66.15 sec
The following tests FAILED:
125 - memory_test_/home/zayac/code/eq/tests/codegen_tests_python/streams-first-class2.tex (Failed)
129 - memory_test_/home/zayac/code/eq/tests/codegen_tests_python/fail_tests/d.tex (Failed)
136 - memory_test_/home/zayac/code/eq/tests/codegen_tests_python/print.tex (Failed)
137 - memory_test_/home/zayac/code/eq/tests/codegen_tests_python/d.tex (Failed)
139 - memory_test_/home/zayac/code/eq/tests/codegen_tests_python/streams-first-class.tex (Failed)
144 - memory_test_/home/zayac/code/eq/tests/parser_tests/md5.tex (Failed)
154 - memory_test_/home/zayac/code/eq/tests/parser_tests/3.tex (Failed)
155 - memory_test_/home/zayac/code/eq/tests/parser_tests/print.tex (Failed)
189 - memory_test_/home/zayac/code/eq/tests/type_tests/fail_tests/print.tex (Failed)
201 - memory_test_/home/zayac/code/eq/tests/type_tests/print.tex (Failed)
Need to find out invalid read/write memory accesses.
Another bug was introduced by SSA implementation in 98e170e. For example, the following test causes segmentation fault in malloc_consolidate()
function.
\begin{eqcode}{\mu}{\ }{\ }{\type{Z}}
a \gets 1 \lend
b \in \overline{\type{Z}} \lend
a \gets a \lend
b^{[0]} \gets 1 \lend
b^{[\iter]} \gets b^{[\iter - 1]} \lend
\return {b^{[a]}} \lend
\end{eqcode}
Earlier compiler version handles this properly.
There is a reoccurring pattern in various valgrind tests: "Conditional jump or move depends on uninitialised value(s)". The calling stack is mostly the same. May be cmake macro should catch similar errors -- not sure.
153/221 Testing: memory_test_/home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex
153/221 Test: memory_test_/home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex
Command: "/usr/bin/valgrind" "/home/tema/src/eq/build/eq" "/home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex"
Directory: /home/tema/src/eq/build
"memory_test_/home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex" start time: Nov 07 01:13 GMT
Output:
----------------------------------------------------------
==19296== Memcheck, a memory error detector
==19296== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==19296== Using Valgrind-3.8.1 and LibVEX; rerun with -h for copyright info
==19296== Command: /home/tema/src/eq/build/eq /home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex
==19296==
==19296== Conditional jump or move depends on uninitialised value(s)
==19296== at 0x4017626: index (in /lib64/ld-2.16.so)
==19296== by 0x4007892: expand_dynamic_string_token (in /lib64/ld-2.16.so)
==19296== by 0x400814F: _dl_map_object (in /lib64/ld-2.16.so)
==19296== by 0x40019BD: map_doit (in /lib64/ld-2.16.so)
==19296== by 0x400E3D5: _dl_catch_error (in /lib64/ld-2.16.so)
==19296== by 0x400101E: do_preload (in /lib64/ld-2.16.so)
==19296== by 0x40046DF: dl_main (in /lib64/ld-2.16.so)
==19296== by 0x4014756: _dl_sysdep_start (in /lib64/ld-2.16.so)
==19296== by 0x4004F68: _dl_start (in /lib64/ld-2.16.so)
==19296== by 0x40017E7: ??? (in /lib64/ld-2.16.so)
==19296== by 0x1: ???
==19296== by 0x7FEFFFE76: ???
==19296==
==19296== Conditional jump or move depends on uninitialised value(s)
==19296== at 0x401762B: index (in /lib64/ld-2.16.so)
==19296== by 0x4007892: expand_dynamic_string_token (in /lib64/ld-2.16.so)
==19296== by 0x400814F: _dl_map_object (in /lib64/ld-2.16.so)
==19296== by 0x40019BD: map_doit (in /lib64/ld-2.16.so)
==19296== by 0x400E3D5: _dl_catch_error (in /lib64/ld-2.16.so)
==19296== by 0x400101E: do_preload (in /lib64/ld-2.16.so)
==19296== by 0x40046DF: dl_main (in /lib64/ld-2.16.so)
==19296== by 0x4014756: _dl_sysdep_start (in /lib64/ld-2.16.so)
==19296== by 0x4004F68: _dl_start (in /lib64/ld-2.16.so)
==19296== by 0x40017E7: ??? (in /lib64/ld-2.16.so)
==19296== by 0x1: ???
==19296== by 0x7FEFFFE76: ???
==19296==
==19296== Conditional jump or move depends on uninitialised value(s)
==19296== at 0x42135F: typecheck_expression (typecheck.c:1766)
==19296== by 0x42104A: typecheck_expression (typecheck.c:1714)
==19296== by 0x41CA1E: typecheck_stmt_assign_right (typecheck.c:296)
==19296== by 0x41D44D: typecheck_stmt (typecheck.c:502)
==19296== by 0x41C2AE: typecheck_stmt_list (typecheck.c:125)
==19296== by 0x41EF54: typecheck_function (typecheck.c:1007)
==19296== by 0x41BE75: typecheck (typecheck.c:81)
==19296== by 0x40451D: main (main.c:186)
==19296==
error:5:17: [line=648] it is forbidden to define several different recurrent expressions in one statement. `c' and `a' variables conflict occured.
note: finished parsing.
note: finished typechecking [ok].
Control flow graph:
digraph \mu { 0; }
note: finished generating CFG.
note: finished generating code.
note: finished compiling.
==19296==
==19296== HEAP SUMMARY:
==19296== in use at exit: 0 bytes in 0 blocks
==19296== total heap usage: 347 allocs, 347 frees, 17,998 bytes allocated
==19296==
==19296== All heap blocks were freed -- no leaks are possible
==19296==
==19296== For counts of detected and suppressed errors, rerun with: -v
==19296== Use --track-origins=yes to see where uninitialised values come from
==19296== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)
<end of output>
Test time = 0.66 sec
----------------------------------------------------------
Test Pass Reason:
Required regular expression found.Regex=[no leaks are possible
]
"memory_test_/home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex" end time: Nov 07 01:13 GMT
"memory_test_/home/tema/src/eq/tests/codegen_tests_python/fail_tests/d.tex" time elapsed: 00:00:00
----------------------------------------------------------
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.