'exit()' builtin: use 'code' argument as exit code.

'exit' had a hard-coded exit value of 10, fix it to use the 'code'
argument; add default value of '0' for 'code' argument.

* da/sim.py(DistProcess.exit): add default value of '0' for 'code'
  argument; pass 'code' as parameter to 'SystemExit'.
Parser: fix typos in 'Pattern2Constant'.

* da/compiler/parser.py(Pattern2Constant.visit_TuplePattern,
  Pattern2Constant.visit_ListPattern): Fix missing 'dast' package in
  references to 'TupleExpr' and 'ListExpr'; change 'push' to 'append'.
da/common.py: Guard APIs against uninitialized global state.

* da/common.py(api): Check whether 'GlobalOptions' has been initialized,
  throw 'RuntimeError' if not.
da/api.py: Cleanup unused variable.

* da/api.py(TotalUnits): Removed.
Parser: Fix 'PatternParser.is_bound()'.

Using 'name.reads' is inaccurate because the name could have been used
in a non-pattern context inside the 'current_query'.

* da/compiler/parser.py(PatternParser.is_bound): Check against
  'current_query.boundvars' instead of using 'name.reads'.
Comprehensions: remove 'has=' keyword, combine domains and conditions.

This patch changes the DistAlgo comprehensions so that the conditions
and domains can be interleaved, and the 'has=' keyword is removed. The
user can now simply specify comprehensions as an 'element' and a list of
conditions:

    setof(ELEM, COND1, ...)

At compilation time, a condition can be treated as either a
'domainspec', which must conform to a specific syntactical form and can
introduce new variable bindings, or a 'condition', which is any boolean
expression. A 'domainspec' is an expression of the form 'PATTERN in
DOMAIN', where 'PATTERN' is any tuple pattern, and is translated into
a Python comprehension: 'for TUPLE in DOMAIN if CONSTRAINTS'.

Evaluation of comprehensions follows simple left-to-right order, similar
to Python comprehensions, except in the case where conditions appear to
the left of the leftmost 'domainspec', in which case those conditions
are reordered to the right of the leftmost 'domainspec'. A DistAlgo
comprehension that contains no 'domainspec's degenerates to a Python
if-expression:

    {PYELEM} if (PYCOND1 and ...) else {}

* da/compiler/dast.py:

  -(QueryExpr): new expression type.

  -(ComprehensionExpr, QuantifiedExpr): extend 'QueryExpr'.

  -(ComprehensionExpr.domains): removed, combined into 'conditions'.

* da/compiler/parser.py:

  -(PatternParser): fix scoping rules: remove property 'out_scope', use
   'parser.current_scope' for all name lookups.

  -(Pattern2Constant): signal error if 'FreePattern' encountered.

  -(Parser.current_query, Parser.current_query_scope): now properties
   inferred from the node stack, instead of concrete values.

  -(Parser.leave_query): remove redundant 'node' argument, since current
   node is always top of node stack; new argument 'merge', if True,
   merges current scope into the query scope; new argument 'audit', if
   True, performs query auditing if current node is the top-level query.

  -(Parser.parse_comprehension): update to parse new DistAlgo
   comprehension style.

* da/compiler/pygen.py:

  -(propagate_attributes): allow argument 'from_nodes' to be single
   node.

  -(propagate_subexprs): not used, removed.

  -(propagate_fields): new function, given a 'node', propagates
   attributes from its children (as specified by 'node._fields').

  -(PythonGenerator.visit_ComprehensionExpr): update to support new
   comprehension style.

  -(PythonGenerator.visit_DomainSpec): changed traversal order: visit
   domain first.

* examples/*: update to new comprehension style.
Parser: fix missing 'SimpleExpr' node in Pattern2Constant.

* da/compiler/parser.py(Pattern2Constant.visit_BoundPattern): create a
  'SimpleExpr' node to wrap the 'NamedVar' instance.
AST: add type checks for 'DomainSpec'.

* da/compiler/dast.py:

  -(DomainSpec.ordered_boundvars, DomainSpec.ordered_freevars): check
   whether 'self.pattern' is PatternExpr.
Compiler: improve ui.

* da/compiler/incgen.py(to_source): moved to 'utils' module.

* da/compiler/ui.py:

  - Doc improvements.

  -(daast_from_str, dastr_to_pyast, dastr_to_pystr): new functions.

* da/compiler/utils.py(to_source): new function, moved here from
  'incgen' module.
Parser: fix free variable resolution for patterns.

Currently, free variables in sub-queries scopes are always given new
NamedVar instances. This breaks the semantics when they need to be
unified with free variables in outer queries. This patch implements
proper lookup of free variables in outer query scopes.

* da/compiler/parser.py:

 -(PatternParser.is_free): new method.

 -(PatternParser.visit_Name): fix NamedVar instancing for free names.
incgen: only generate 'reset' stub for processes actually using 'reset'.

This cuts down the LOC of inc file after incrementalization.

* da/compiler/incgen.py:
  -(NodetypeFinder): new visitor class.
  -(gen_reset_stub): check whether process contains 'ResetStmt' before
  generating the 'reset' stub.
Runtime: better safeguards against corrupted messages.

Drop malformed messages in the Comm thread. For process with
"config(clock='lamport')", drop incoming messages with invalid logical
clocks and log a warning.

  -(DistProcess.Comm.run): guard against ValueError when unpacking
   incoming messages.

  -(DistProcess._process_event): guard against events with invalid
   timestamp and output a warning.
pygen: fix free pattern unification.

Fixes a bug where free variables in outer queries were wrongly unified
with free variables in inner comprehensions.

* da/compiler/pygen.py:

  -(PythonGenerator): rename 'query_generator' to 'pattern_generator'.

  -(PythonGenerator.visit_ComprehensionExpr): save and restore
   'pattern_generator' state, since comprehensions have their own nested
   scope and do not bind variables in outer scope.

  -(PatternComprehensionGenerator): new field 'state_stack', stores a
   stack of pattern states, for implementing nested scopes.

  -(PatternComprehensionGenerator.push_state,
   PatternComprehensionGenerator.pop_state): new methods, save and
   restore the pattern state, respectively.
Parser: fix missing 'pop_state()' call.

* da/compiler/parser.py(Parser.parse_comprehension): fix missing
  'pop_state()' call for 'create_expr'.
Parser: remove query scope merge on 'leave_query'.

* da/compiler/parser.py:

  -(Parser.level_query): remove 'merge' argument.

  -(Parser.parse_comprehension): adjust for 'leave_query' signature
   change.
Parser: fix 'current_query' property.

* da/compiler/parser.py(Parser.current_query): return current query node
  instead of 'top_level_query'; caller can easily find top-level query
  if he so desire.
incgen: fix bugs and adjust for recent changes.

* da/compiler/incgen.py:

  -(combine_not_comparison, apply_demorgan_rule): properly set '_parent'
   field for newly created DistAlgo nodes.

  -(domain_for_condition): flatten target tuple if only one element.

  -(optimize_tuple): new method, renamed from
   'IncInterfaceGenerator.jb_tuple_optimize'.

  -(QueryExtractor.visit_ComplexExpr): extract outer-most QueryExpr node
   instead of Expression.

  -(IncInterfaceGenerator.visit_ComprehensionExpr): adjusted to reuse
   parent code.

  -(IncInterfaceGenerator.do_table4_transformation): save and restore
   current pattern state on each iterative try; properly set '_parent'
   property on created DistAlgo nodes.

  -(IncInterfaceGenerator.do_table3_transformation): normalize target
   element and pattern tuples.
Merge branch 'hotfix' into master.