[Checkins] SVN: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler. beginnings of adaptation based compilation

Adam Groszer agroszer at gmail.com
Tue Jul 1 14:21:21 EDT 2008


Log message for revision 87893:
  beginnings of adaptation based compilation

Changed:
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py
  U   Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.txt

-=-
Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py	2008-07-01 18:20:34 UTC (rev 87892)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.py	2008-07-01 18:21:20 UTC (rev 87893)
@@ -10,10 +10,14 @@
 
 from zope.component import adapts
 from zope.interface import implements
+from zope.component import provideAdapter
 
 from ocql.interfaces import IAlgebraCompiler
 from ocql.interfaces import IOptimizedAlgebraObject
+from ocql.interfaces import ICompiledAlgebraObject
 
+from ocql.rewriter.interfaces import *
+
 from ocql.compiler.runnablequery import RunnableQuery
 
 class AlgebraCompiler(object):
@@ -26,6 +30,33 @@
 
     def __call__(self, metadata, algebra):
         algebra = self.context
-        code = algebra.compile()
+        #code = algebra.compile()
+        code = IAlgebraCompiler(self.context)()
         run = RunnableQuery(metadata, algebra, code)
-        return run
\ No newline at end of file
+        return run
+
+class BaseCompiler(object):
+    def __init__(self, context):
+        #context becomes the adapted object
+        self.context = context
+
+class EmptyCompiler(BaseCompiler):
+    implements(IAlgebraCompiler)
+    adapts(IEmpty)
+
+    def __call__(self):
+        if self.context.klass == set:
+            return 'set()'
+        elif self.context.klass == list:
+            return '[]'
+
+class SingleCompiler(BaseCompiler):
+    def __call__(self):
+        if self.context.klass == set:
+            return 'set(['+IAlgebraCompiler(self.context.expr)()+'])'
+        elif self.context.klass == list:
+            return '['+IAlgebraCompiler(self.context.expr)()+']'
+
+def registerAdapters():
+    provideAdapter(EmptyCompiler)
+    provideAdapter(SingleCompiler)
\ No newline at end of file

Modified: Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.txt
===================================================================
--- Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.txt	2008-07-01 18:20:34 UTC (rev 87892)
+++ Sandbox/adamg/ocql/branches/alg-compiler/src/ocql/compiler/compiler.txt	2008-07-01 18:21:20 UTC (rev 87893)
@@ -11,6 +11,9 @@
 
     >>> from ocql.testing.database import TestMetadata
 
+    >>> from ocql.compiler.compiler import registerAdapters
+    >>> registerAdapters()
+
     >>> metadata = TestMetadata()
     >>> qo = QueryParser("set [ | 1 ]")(metadata)
     >>> opt = QueryOptimizer(qo)()



More information about the Checkins mailing list