-
Notifications
You must be signed in to change notification settings - Fork 18
Information for Developers
- Use virtualenv to manage your project
- PyCharm is a good choice for developing and debugging Cozy
The tests
folder contains tests written with Python's
unittest library. Run them
with
$ python3 -m unittest -b tests/*.py
(The -b
flag "buffers" output so that Python only shows output from failing
tests.)
The cozy/codegen
folder implements source code generation for C++ and Java.
A pre-commit hook is a script that runs when you run git commit
. The commit aborts if the script fails. This pre-commit hook runs a linter and all the unit tests:
$ cat .git/hooks/pre-commit
#!/bin/bash
./lint.sh && python3 -m unittest -fb tests/*.py
$ cat lint.sh
#!/bin/bash
cd "$(dirname "$0")"
if [[ "$1" == "" ]]; then
ARGS="$(find cozy tests -name '*.py' -not -name 'parsetab.py')"
else
ARGS="$@"
fi
# http://flake8.pycqa.org/en/latest/user/error-codes.html
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
echo "Running flake8..."
exec flake8 \
$(fgrep -- '--select' .travis.yml) \
$ARGS
echo "Done!"
There are multiple notions of "equality" between values and between expressions in Cozy. They are documented in value_types.py
.
Expressions have three different kinds of equality: syntactic equality, alpha equivalence, and semantic equality.
- syntactic equality means they are the same expression, right down to the names of variables
- alpha equivalence means they are the same expression, but variables can be renamed if it doesn't affect the meaning of the expression
- semantic equivalence means the expressions produce the same output on all inputs
e1 | e2 | syntactically equal? | alpha equivalent? | semantically equal? |
---|---|---|---|---|
x |
x |
yes | yes | yes |
argmin {x -> -x} list |
argmin {y -> -y} list |
no | yes | yes |
argmin {x -> -x} list |
max list |
no | no | yes |
x |
y |
no | no | no |
In Python, ==
on Exp
objects implements syntactic equality (but ignores type information). alpha_equivalent
tests for alpha equivalence (but also ignores type information). valid
can be used as a partial decision procedure for semantic equality (the task is undecidable, unfortunately). Usually this is written valid(EDeepEq(e1, e2))
. For expressions with non-collection types, valid(EEq(e1, e2))
accomplishes the same thing.