Matches are usually desugared as calls to a dictionary
Underscore conditions in a match arm is treated as the default
If there are multiple default cases then panic is thrown.
For sqrtimport math is added to the top of a file if encountered, and for default dictionaries from collections import defaultdict is added.
Make Context a mutable reference in the desugar stage so we can modify it, for instance, we can now add imports. We should take care to discard it/refresh the context if need be, though currently there is no such situation where we do not want to propagate up the context.
If default dictionary is used then we add import;
from collections import defaultdict
Relevant issues
Resolves #98
Summary
Add desugar rules for match statements.
sqrt
import math
is added to the top of a file if encountered, and for default dictionariesfrom collections import defaultdict
is added.Context
a mutable reference in the desugar stage so we can modify it, for instance, we can now add imports. We should take care to discard it/refresh the context if need be, though currently there is no such situation where we do not want to propagate up the context.If default dictionary is used then we add import;
from collections import defaultdict