[ZPT] CVS: Packages/TAL - TALDefs.py:1.21 TALGenerator.py:1.43 TALInterpreter.py:1.50

fred@digicool.com fred@digicool.com
Fri, 8 Jun 2001 18:59:34 -0400 (EDT)


Update of /cvs-repository/Packages/TAL
In directory korak.digicool.com:/tmp/cvs-serv20939

Modified Files:
	TALDefs.py TALGenerator.py TALInterpreter.py 
Log Message:
Yet another change to the bytecode format:

Each bytecode now carries exactly one argument, but the arg is only an
extra layer of tuple if the handler method needs more than one
parameter.

The handlers are also modified so that they require exactly one
argument, which is a tuple only if they need more than one argument
from the instruction.  This simplifies the dispatch code in
TALInterpreter.interpret() just slightly.

Changed the version number of the bytecode again, since Guido tells me
Evan calls this version 1.3.2.



--- Updated File TALDefs.py in package Packages/TAL --
--- TALDefs.py	2001/06/07 18:02:55	1.20
+++ TALDefs.py	2001/06/08 22:59:33	1.21
@@ -88,7 +88,7 @@
 
 from types import ListType, TupleType
 
-TAL_VERSION = "1.4"
+TAL_VERSION = "1.3.2"
 
 XML_NS = "http://www.w3.org/XML/1998/namespace" # URI for XML namespace
 XMLNS_NS = "http://www.w3.org/2000/xmlns/" # URI for XML NS declarations
@@ -201,7 +201,7 @@
         len(program[1]) == 2):
         opcode, mode = program[1]
         if opcode == "mode":
-            return mode[0]
+            return mode
     return None
 
 def getProgramVersion(program):
@@ -209,7 +209,7 @@
         isinstance(program[0], TupleType) and len(program[0]) == 2):
         opcode, version = program[0]
         if opcode == "version":
-            return version[0]
+            return version
     return None
 
 import cgi

--- Updated File TALGenerator.py in package Packages/TAL --
--- TALGenerator.py	2001/06/08 20:51:10	1.42
+++ TALGenerator.py	2001/06/08 22:59:33	1.43
@@ -149,7 +149,10 @@
                 else:
                     output.append(("rawtextOffset", (text, len(text))))
             if opcode != None:
-                output.append((opcode, tuple(item[1:])))
+                if len(item) == 2:
+                    output.append((opcode, item[1]))
+                else:
+                    output.append((opcode, tuple(item[1:])))
             rawseen = cursor+1
             collect = []
         return output

--- Updated File TALInterpreter.py in package Packages/TAL --
--- TALInterpreter.py	2001/06/08 20:55:46	1.49
+++ TALInterpreter.py	2001/06/08 22:59:33	1.50
@@ -253,10 +253,10 @@
                     if len(s) > 80:
                         s = s[:76] + "...\n"
                     sys.stderr.write(s)
-                    _apply(handlers[opcode], tup + args)
+                    handlers[opcode](self, args)
             else:
                 for (opcode, args) in program:
-                    _apply(handlers[opcode], tup + args)
+                    handlers[opcode](self, args)
         finally:
             self.level = self.level - 1
             del tup
@@ -278,11 +278,11 @@
         self.position = position
     bytecode_handlers["setPosition"] = do_setPosition
 
-    def do_startEndTag(self, name, attrList):
-        self.do_startTag(name, attrList, self.endsep)
+    def do_startEndTag(self, (name, attrList)):
+        self.do_startTag((name, attrList), self.endsep)
     bytecode_handlers["startEndTag"] = do_startEndTag
 
-    def do_startTag(self, name, attrList, end=">"):
+    def do_startTag(self, (name, attrList), end=">"):
         if not attrList:
             s = "<%s%s" % (name, end)
             self._stream_write(s)
@@ -386,12 +386,6 @@
                              (i, what, macroName, slots and slots.keys()))
         sys.stderr.write("+--------------------------------------\n")
 
-    def do_endTag(self, name):
-        s = "</%s>" % name
-        self._stream_write(s)
-        self.col = self.col + len(s)
-    bytecode_handlers["endTag"] = do_endTag
-
     def do_beginScope(self, dict):
         if self.tal:
             engine = self.engine
@@ -402,24 +396,24 @@
         self.scopeLevel = self.scopeLevel + 1
     bytecode_handlers["beginScope"] = do_beginScope
 
-    def do_endScope(self):
+    def do_endScope(self, notused=None):
         self.engine.endScope()
         self.scopeLevel = self.scopeLevel - 1
     bytecode_handlers["endScope"] = do_endScope
 
-    def do_setLocal(self, name, expr):
+    def do_setLocal(self, (name, expr)):
         if self.tal:
             value = self.engine.evaluateValue(expr)
             self.engine.setLocal(name, value)
     bytecode_handlers["setLocal"] = do_setLocal
 
-    def do_setGlobal(self, name, expr):
+    def do_setGlobal(self, (name, expr)):
         if self.tal:
             value = self.engine.evaluateValue(expr)
             self.engine.setGlobal(name, value)
     bytecode_handlers["setGlobal"] = do_setGlobal
 
-    def do_insertText(self, expr, block):
+    def do_insertText(self, (expr, block)):
         if not self.tal:
             self.interpret(block)
             return
@@ -432,7 +426,7 @@
         self.stream_write(cgi.escape(text))
     bytecode_handlers["insertText"] = do_insertText
 
-    def do_insertStructure(self, expr, repldict, block):
+    def do_insertStructure(self, (expr, repldict, block)):
         if not self.tal:
             self.interpret(block)
             return
@@ -474,7 +468,7 @@
         program, macros = gen.getCode()
         self.interpret(program)
 
-    def do_loop(self, name, expr, block):
+    def do_loop(self, (name, expr, block)):
         if not self.tal:
             self.interpret(block)
             return
@@ -483,22 +477,22 @@
             self.interpret(block)
     bytecode_handlers["loop"] = do_loop
 
-    def do_rawtextColumn(self, s, col):
+    def do_rawtextColumn(self, (s, col)):
         self._stream_write(s)
         self.col = col
     bytecode_handlers["rawtextColumn"] = do_rawtextColumn
 
-    def do_rawtextOffset(self, s, offset):
+    def do_rawtextOffset(self, (s, offset)):
         self._stream_write(s)
         self.col = self.col + offset
     bytecode_handlers["rawtextOffset"] = do_rawtextOffset
 
-    def do_condition(self, condition, block):
+    def do_condition(self, (condition, block)):
         if not self.tal or self.engine.evaluateBoolean(condition):
             self.interpret(block)
     bytecode_handlers["condition"] = do_condition
 
-    def do_defineMacro(self, macroName, macro):
+    def do_defineMacro(self, (macroName, macro)):
         if not self.metal:
             self.interpret(macro)
             return
@@ -507,7 +501,7 @@
         self.popMacro()
     bytecode_handlers["defineMacro"] = do_defineMacro
 
-    def do_useMacro(self, macroName, macroExpr, compiledSlots, block):
+    def do_useMacro(self, (macroName, macroExpr, compiledSlots, block)):
         if not self.metal:
             self.interpret(block)
             return
@@ -528,7 +522,7 @@
         self.popMacro()
     bytecode_handlers["useMacro"] = do_useMacro
 
-    def do_fillSlot(self, slotName, block):
+    def do_fillSlot(self, (slotName, block)):
         if not self.metal:
             self.interpret(block)
             return
@@ -537,7 +531,7 @@
         self.popMacro()
     bytecode_handlers["fillSlot"] = do_fillSlot
 
-    def do_defineSlot(self, slotName, block):
+    def do_defineSlot(self, (slotName, block)):
         if not self.metal:
             self.interpret(block)
             return
@@ -553,7 +547,7 @@
         self.popMacro()
     bytecode_handlers["defineSlot"] = do_defineSlot
 
-    def do_onError(self, block, handler):
+    def do_onError(self, (block, handler)):
         if not self.tal:
             self.interpret(block)
             return