bool_process.html


001| '''\
001| BOOL (again) -- Process Object.
001| 
001| * Binds a User and the WorkSpace.
001| * Contains the PStack.
001| 
001| Chris@Sonnack.com
001| December 2013
001| '''

002| ####################################################################################################
003| from sys import stdout, stderr, argv
004| from datetime import datetime
005| from logger import logger
006| from bool_os_ws import BoolWorkSpace
007| from bool_user import BoolRunTimeUser
008| ####################################################################################################
009| 
010| 
011| ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
012| class BoolPStack (object):
013|     '''\
013| BOOL Parameter Stack.
013| 
013| The Parameter Stack carries parameters into and out of Actions.
013| 
013| Usually, input parameters are references to Objects, but they
013| can be new Objects created on the fly (for pass by value).
013| 
013| Output parameters are often Objects created in the Action that
013| need to be transferred to the calling frame. This requirement,
013| and the pass by value ability, require the parameter stack be
013| capable of containing entire Objects like Address Space does.
013| This is in addition to holding references to Objects in the
013| usual Address Space.
013| '''

014|     Log = logger('PStack')
015| 
016|     def push (self, obj):
017|         '''BOOL PStack Push.'''
018|         BoolPStack.Log.trace('push')
019|         if obj:
020|             self.stack.append(obj)
021| 
022|     def pop (self):
023|         '''BOOL PStack Pop.'''
024|         BoolPStack.Log.trace('pop')
025|         if len(self):
026|             return self.stack.pop()
027|         raise BufferError('PStack is empty!')
028| 
029|     def __init__ (self):
030|         '''Create new Parameter Stack instance.'''
031|         BoolPStack.Log.trace('init')
032|         self.ts = datetime.now()
033|         self.stack = []
034| 
035|     def __len__ (self):
036|         '''Return count of items in stack.'''
037|         return len(self.stack)
038| 
039| 
040| 
041| ##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~##
042| class BoolRunTimeProcess (object):
043|     '''\
043| BOOL RTE Process class.
043| '''

044|     Log = logger('Process')
045| 
046|     def push (self, obj):
047|         '''Push. (Delegated to PStack)'''
048|         self.pstack.push(obj)
049| 
050|     def pop (self):
051|         '''Pop. (Delegated to PStack)'''
052|         return self.pstack.pop()
053| 
054|     def __init__ (self, name, user, work_spc):
055|         '''Create new RTE Process instance.'''
056|         self.name = name
057|         self.user = user
058|         self.ws = work_spc
059|         self.pstack = BoolPStack()
060| 
061|     def __str__ (self):
062|         '''String version.'''
063|         s = '[%s] %s::%s'
064|         t = (self.user, self.ws.name, self.name)
065|         return s % t
066| 
067| 
068| 
069| ##================================================================================================##
070| def main (args):
071|     '''Package Main.'''
072|     proc = BoolRunTimeProcess('test', BoolRunTimeUser('cjsonnack','us224353'), BoolWorkSpace('main'))
073|     return proc
074| 
075| ####################################################################################################
076| if __name__ == '__main__':
077|     print('autorun:',argv[0])
078|     obj = main(argv[1:])
079| 
080| ####################################################################################################
081| '''eof'''
082|