X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kll_lib%2Fcontainers.py;h=fe00f842369ca9bb9a82bdd4eb1e566b138baed8;hb=5696fc5dfb407e43ad2aa1ed5fb12ff90dfdf374;hp=d54ff1029e8d7e3a5b5c8a244ba59c93056c0d44;hpb=bbf2c3ffaf4d579a5865c36c986720202d11f04a;p=kiibohd-kll.git diff --git a/kll_lib/containers.py b/kll_lib/containers.py index d54ff10..fe00f84 100644 --- a/kll_lib/containers.py +++ b/kll_lib/containers.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # KLL Compiler Containers # -# Copyright (C) 2014 by Jacob Alexander +# Copyright (C) 2014-2015 by Jacob Alexander # # This file is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,7 +31,9 @@ ERROR = '\033[5;1;31mERROR\033[0m:' ### Parsing ### + ## Containers + class Capabilities: # Container for capabilities dictionary and convenience functions def __init__( self ): @@ -99,6 +101,7 @@ class Macros: self.triggersIndexSorted = [] self.triggerList = [] self.maxScanCode = [] + self.firstScanCode = [] # USBCode Assignment Cache self.assignmentCache = [] @@ -143,7 +146,8 @@ class Macros: self.macros[ self.layer ][ trigger ] = [ result ] # Mark layer scan code, so it won't be removed later - if not self.baseLayout is None: + # Also check to see if it hasn't already been removed before + if not self.baseLayout is None and trigger in self.layerLayoutMarkers[ self.layer ]: del self.layerLayoutMarkers[ self.layer ][ trigger ] # Return a list of ScanCode triggers with the given USB Code trigger @@ -252,9 +256,90 @@ class Macros: # Shrink triggerList to actual max size self.triggerList[ layer ] = self.triggerList[ layer ][ : self.maxScanCode[ layer ] + 1 ] + # Calculate first scan code for layer, useful for uC implementations trying to save RAM + firstScanCode = 0 + for triggerList in range( 0, len( self.triggerList[ layer ] ) ): + firstScanCode = triggerList + + # Break if triggerList has items + if len( self.triggerList[ layer ][ triggerList ] ) > 0: + break; + self.firstScanCode.append( firstScanCode ) + # Determine overall maxScanCode self.overallMaxScanCode = 0x00 for maxVal in self.maxScanCode: if maxVal > self.overallMaxScanCode: self.overallMaxScanCode = maxVal + +class Variables: + # Container for variables + # Stores three sets of variables, the overall combined set, per layer, and per file + def __init__( self ): + # Dictionaries of variables + self.baseLayout = dict() + self.fileVariables = dict() + self.layerVariables = [ dict() ] + self.overallVariables = dict() + self.defines = dict() + + self.currentFile = "" + self.currentLayer = 0 + self.baseLayoutEnabled = True + + def baseLayoutFinished( self ): + self.baseLayoutEnabled = False + + def setCurrentFile( self, name ): + # Store using filename and current layer + self.currentFile = name + self.fileVariables[ name ] = dict() + + # If still processing BaseLayout + if self.baseLayoutEnabled: + if '*LayerFiles' in self.baseLayout.keys(): + self.baseLayout['*LayerFiles'] += [ name ] + else: + self.baseLayout['*LayerFiles'] = [ name ] + # Set for the current layer + else: + if '*LayerFiles' in self.layerVariables[ self.currentLayer ].keys(): + self.layerVariables[ self.currentLayer ]['*LayerFiles'] += [ name ] + else: + self.layerVariables[ self.currentLayer ]['*LayerFiles'] = [ name ] + + def incrementLayer( self ): + # Store using layer index + self.currentLayer += 1 + self.layerVariables.append( dict() ) + + def assignVariable( self, key, value ): + # Overall set of variables + self.overallVariables[ key ] = value + + # The Name variable is a special accumulation case + if key == 'Name': + # BaseLayout still being processed + if self.baseLayoutEnabled: + if '*NameStack' in self.baseLayout.keys(): + self.baseLayout['*NameStack'] += [ value ] + else: + self.baseLayout['*NameStack'] = [ value ] + # Layers + else: + if '*NameStack' in self.layerVariables[ self.currentLayer ].keys(): + self.layerVariables[ self.currentLayer ]['*NameStack'] += [ value ] + else: + self.layerVariables[ self.currentLayer ]['*NameStack'] = [ value ] + + # If still processing BaseLayout + if self.baseLayoutEnabled: + self.baseLayout[ key ] = value + # Set for the current layer + else: + self.layerVariables[ self.currentLayer ][ key ] = value + + # File context variables + self.fileVariables[ self.currentFile ][ key ] = value +