comparison python/c3/scope.py @ 288:a747a45dcd78

Various styling work
author Windel Bouwman
date Thu, 21 Nov 2013 14:26:13 +0100
parents e64bae57cda8
children
comparison
equal deleted inserted replaced
287:1c7c1e619be8 288:a747a45dcd78
1 from . import astnodes 1 from . import astnodes
2
2 3
3 class Scope: 4 class Scope:
4 """ A scope contains all symbols in a scope """ 5 """ A scope contains all symbols in a scope """
5 def __init__(self, parent=None): 6 def __init__(self, parent=None):
6 self.symbols = {} 7 self.symbols = {}
47 48
48 def __repr__(self): 49 def __repr__(self):
49 return 'Scope with {} symbols'.format(len(self.symbols)) 50 return 'Scope with {} symbols'.format(len(self.symbols))
50 51
51 52
53 def createBuiltins(scope):
54 for tn in ['u64', 'u32', 'u16', 'u8']:
55 scope.addSymbol(astnodes.BaseType(tn))
56 for t in [intType, doubleType, voidType, boolType, stringType, byteType]:
57 scope.addSymbol(t)
58
52 # buildin types: 59 # buildin types:
53 intType = astnodes.BaseType('int') 60 intType = astnodes.BaseType('int')
54 intType.bytesize = 4 61 intType.bytesize = 4
55 doubleType = astnodes.BaseType('double') 62 doubleType = astnodes.BaseType('double')
56 voidType = astnodes.BaseType('void') 63 voidType = astnodes.BaseType('void')
57 boolType = astnodes.BaseType('bool') 64 boolType = astnodes.BaseType('bool')
58 stringType = astnodes.BaseType('string') 65 stringType = astnodes.BaseType('string')
59 byteType = astnodes.BaseType('byte') 66 byteType = astnodes.BaseType('byte')
60 67
61 def createBuiltins(scope): 68 # Create top level scope:
62 for tn in ['u64', 'u32', 'u16', 'u8']:
63 scope.addSymbol(astnodes.BaseType(tn))
64 for t in [intType, doubleType, voidType, boolType, stringType, byteType]:
65 scope.addSymbol(t)
66
67 topScope = Scope() 69 topScope = Scope()
68 createBuiltins(topScope) 70 createBuiltins(topScope)
69