2
This module deals with interpreting the parse tree as Python
3
would have done, in the compiler.
5
For now this only covers parse tree to value conversion of
10
from .ExprNodes import DictNode
11
from .Errors import CompileError
15
def lookup(self, name):
18
empty_scope = EmptyScope()
20
def interpret_compiletime_options(optlist, optdict, type_env=None, type_args=()):
22
Tries to interpret a list of compile time option nodes.
23
The result will be a tuple (optlist, optdict) but where
24
all expression nodes have been interpreted. The result is
25
in the form of tuples (value, pos).
27
optlist is a list of nodes, while optdict is a DictNode (the
28
result optdict is a dict)
30
If type_env is set, all type nodes will be analysed and the resulting
31
type set. Otherwise only interpretateable ExprNodes
32
are allowed, other nodes raises errors.
34
A CompileError will be raised if there are problems.
37
def interpret(node, ix):
40
type = node.analyse_as_type(type_env)
42
raise CompileError(node.pos, "Invalid type.")
43
return (type, node.pos)
45
raise CompileError(node.pos, "Type not allowed here.")
46
return (node.compile_time_value(empty_scope), node.pos)
49
optlist = [interpret(x, ix) for ix, x in enumerate(optlist)]
51
assert isinstance(optdict, DictNode)
53
for item in optdict.key_value_pairs:
54
new_key, dummy = interpret(item.key, None)
55
new_optdict[new_key] = interpret(item.value, item.key.value)
57
return (optlist, new_optdict)