Mercurial > lcfOS
comparison python/c3/scope.py @ 164:e023d3ce1d63
Fix to loc of assignment
author | Windel Bouwman |
---|---|
date | Mon, 18 Mar 2013 22:15:57 +0100 |
parents | 8104fc8b5e90 |
children | 8b2e5f3cd579 |
comparison
equal
deleted
inserted
replaced
163:8104fc8b5e90 | 164:e023d3ce1d63 |
---|---|
4 """ A scope contains all symbols in a scope """ | 4 """ A scope contains all symbols in a scope """ |
5 def __init__(self, parent=None): | 5 def __init__(self, parent=None): |
6 self.symbols = {} | 6 self.symbols = {} |
7 self.parent = parent | 7 self.parent = parent |
8 def __iter__(self): | 8 def __iter__(self): |
9 return iter(self.symbols.values()) | 9 # Iterate in a deterministic manner: |
10 return iter(self.Constants + self.Variables + self.Functions) | |
11 @property | |
12 def Syms(self): | |
13 syms = self.symbols.values() | |
14 return sorted(syms, key=lambda v: v.name) | |
15 @property | |
16 def Constants(self): | |
17 return [s for s in self.Syms if type(s) is astnodes.Constant] | |
18 @property | |
19 def Variables(self): | |
20 return [s for s in self.Syms if type(s) is astnodes.Variable] | |
21 @property | |
22 def Functions(self): | |
23 return [s for s in self.Syms if type(s) is astnodes.Function] | |
10 def getSymbol(self, name): | 24 def getSymbol(self, name): |
11 if name in self.symbols: | 25 if name in self.symbols: |
12 return self.symbols[name] | 26 return self.symbols[name] |
13 # Look for symbol: | 27 # Look for symbol: |
14 if self.parent: | 28 if self.parent: |
25 | 39 |
26 # buildin types: | 40 # buildin types: |
27 intType = astnodes.BaseType('int') | 41 intType = astnodes.BaseType('int') |
28 doubleType = astnodes.BaseType('double') | 42 doubleType = astnodes.BaseType('double') |
29 voidType = astnodes.BaseType('void') | 43 voidType = astnodes.BaseType('void') |
30 boolType = astnodes.BaseType('void') | 44 boolType = astnodes.BaseType('bool') |
45 stringType = astnodes.BaseType('string') | |
46 byteType = astnodes.BaseType('byte') | |
31 | 47 |
32 def createBuiltins(scope): | 48 def createBuiltins(scope): |
33 for tn in ['u64', 'u32', 'u16', 'u8']: | 49 for tn in ['u64', 'u32', 'u16', 'u8']: |
34 scope.addSymbol(astnodes.BaseType(tn)) | 50 scope.addSymbol(astnodes.BaseType(tn)) |
35 for t in [intType, doubleType, voidType, boolType]: | 51 for t in [intType, doubleType, voidType, boolType, stringType, byteType]: |
36 scope.addSymbol(t) | 52 scope.addSymbol(t) |
37 | 53 |
38 topScope = Scope() | 54 topScope = Scope() |
39 createBuiltins(topScope) | 55 createBuiltins(topScope) |
40 | 56 |