Commit adac2175 authored by Fred Drake's avatar Fred Drake

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.
parent 2e7ac9cc
...@@ -88,7 +88,7 @@ Common definitions used by TAL and METAL compilation an transformation. ...@@ -88,7 +88,7 @@ Common definitions used by TAL and METAL compilation an transformation.
from types import ListType, TupleType 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 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 XMLNS_NS = "http://www.w3.org/2000/xmlns/" # URI for XML NS declarations
...@@ -201,7 +201,7 @@ def getProgramMode(program): ...@@ -201,7 +201,7 @@ def getProgramMode(program):
len(program[1]) == 2): len(program[1]) == 2):
opcode, mode = program[1] opcode, mode = program[1]
if opcode == "mode": if opcode == "mode":
return mode[0] return mode
return None return None
def getProgramVersion(program): def getProgramVersion(program):
...@@ -209,7 +209,7 @@ def getProgramVersion(program): ...@@ -209,7 +209,7 @@ def getProgramVersion(program):
isinstance(program[0], TupleType) and len(program[0]) == 2): isinstance(program[0], TupleType) and len(program[0]) == 2):
opcode, version = program[0] opcode, version = program[0]
if opcode == "version": if opcode == "version":
return version[0] return version
return None return None
import cgi import cgi
......
...@@ -149,7 +149,10 @@ class TALGenerator: ...@@ -149,7 +149,10 @@ class TALGenerator:
else: else:
output.append(("rawtextOffset", (text, len(text)))) output.append(("rawtextOffset", (text, len(text))))
if opcode != None: 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 rawseen = cursor+1
collect = [] collect = []
return output return output
......
...@@ -253,10 +253,10 @@ class TALInterpreter: ...@@ -253,10 +253,10 @@ class TALInterpreter:
if len(s) > 80: if len(s) > 80:
s = s[:76] + "...\n" s = s[:76] + "...\n"
sys.stderr.write(s) sys.stderr.write(s)
_apply(handlers[opcode], tup + args) handlers[opcode](self, args)
else: else:
for (opcode, args) in program: for (opcode, args) in program:
_apply(handlers[opcode], tup + args) handlers[opcode](self, args)
finally: finally:
self.level = self.level - 1 self.level = self.level - 1
del tup del tup
...@@ -278,11 +278,11 @@ class TALInterpreter: ...@@ -278,11 +278,11 @@ class TALInterpreter:
self.position = position self.position = position
bytecode_handlers["setPosition"] = do_setPosition bytecode_handlers["setPosition"] = do_setPosition
def do_startEndTag(self, name, attrList): def do_startEndTag(self, (name, attrList)):
self.do_startTag(name, attrList, self.endsep) self.do_startTag((name, attrList), self.endsep)
bytecode_handlers["startEndTag"] = do_startEndTag bytecode_handlers["startEndTag"] = do_startEndTag
def do_startTag(self, name, attrList, end=">"): def do_startTag(self, (name, attrList), end=">"):
if not attrList: if not attrList:
s = "<%s%s" % (name, end) s = "<%s%s" % (name, end)
self._stream_write(s) self._stream_write(s)
...@@ -386,12 +386,6 @@ class TALInterpreter: ...@@ -386,12 +386,6 @@ class TALInterpreter:
(i, what, macroName, slots and slots.keys())) (i, what, macroName, slots and slots.keys()))
sys.stderr.write("+--------------------------------------\n") 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): def do_beginScope(self, dict):
if self.tal: if self.tal:
engine = self.engine engine = self.engine
...@@ -402,24 +396,24 @@ class TALInterpreter: ...@@ -402,24 +396,24 @@ class TALInterpreter:
self.scopeLevel = self.scopeLevel + 1 self.scopeLevel = self.scopeLevel + 1
bytecode_handlers["beginScope"] = do_beginScope bytecode_handlers["beginScope"] = do_beginScope
def do_endScope(self): def do_endScope(self, notused=None):
self.engine.endScope() self.engine.endScope()
self.scopeLevel = self.scopeLevel - 1 self.scopeLevel = self.scopeLevel - 1
bytecode_handlers["endScope"] = do_endScope bytecode_handlers["endScope"] = do_endScope
def do_setLocal(self, name, expr): def do_setLocal(self, (name, expr)):
if self.tal: if self.tal:
value = self.engine.evaluateValue(expr) value = self.engine.evaluateValue(expr)
self.engine.setLocal(name, value) self.engine.setLocal(name, value)
bytecode_handlers["setLocal"] = do_setLocal bytecode_handlers["setLocal"] = do_setLocal
def do_setGlobal(self, name, expr): def do_setGlobal(self, (name, expr)):
if self.tal: if self.tal:
value = self.engine.evaluateValue(expr) value = self.engine.evaluateValue(expr)
self.engine.setGlobal(name, value) self.engine.setGlobal(name, value)
bytecode_handlers["setGlobal"] = do_setGlobal bytecode_handlers["setGlobal"] = do_setGlobal
def do_insertText(self, expr, block): def do_insertText(self, (expr, block)):
if not self.tal: if not self.tal:
self.interpret(block) self.interpret(block)
return return
...@@ -432,7 +426,7 @@ class TALInterpreter: ...@@ -432,7 +426,7 @@ class TALInterpreter:
self.stream_write(cgi.escape(text)) self.stream_write(cgi.escape(text))
bytecode_handlers["insertText"] = do_insertText bytecode_handlers["insertText"] = do_insertText
def do_insertStructure(self, expr, repldict, block): def do_insertStructure(self, (expr, repldict, block)):
if not self.tal: if not self.tal:
self.interpret(block) self.interpret(block)
return return
...@@ -474,7 +468,7 @@ class TALInterpreter: ...@@ -474,7 +468,7 @@ class TALInterpreter:
program, macros = gen.getCode() program, macros = gen.getCode()
self.interpret(program) self.interpret(program)
def do_loop(self, name, expr, block): def do_loop(self, (name, expr, block)):
if not self.tal: if not self.tal:
self.interpret(block) self.interpret(block)
return return
...@@ -483,22 +477,22 @@ class TALInterpreter: ...@@ -483,22 +477,22 @@ class TALInterpreter:
self.interpret(block) self.interpret(block)
bytecode_handlers["loop"] = do_loop bytecode_handlers["loop"] = do_loop
def do_rawtextColumn(self, s, col): def do_rawtextColumn(self, (s, col)):
self._stream_write(s) self._stream_write(s)
self.col = col self.col = col
bytecode_handlers["rawtextColumn"] = do_rawtextColumn bytecode_handlers["rawtextColumn"] = do_rawtextColumn
def do_rawtextOffset(self, s, offset): def do_rawtextOffset(self, (s, offset)):
self._stream_write(s) self._stream_write(s)
self.col = self.col + offset self.col = self.col + offset
bytecode_handlers["rawtextOffset"] = do_rawtextOffset 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): if not self.tal or self.engine.evaluateBoolean(condition):
self.interpret(block) self.interpret(block)
bytecode_handlers["condition"] = do_condition bytecode_handlers["condition"] = do_condition
def do_defineMacro(self, macroName, macro): def do_defineMacro(self, (macroName, macro)):
if not self.metal: if not self.metal:
self.interpret(macro) self.interpret(macro)
return return
...@@ -507,7 +501,7 @@ class TALInterpreter: ...@@ -507,7 +501,7 @@ class TALInterpreter:
self.popMacro() self.popMacro()
bytecode_handlers["defineMacro"] = do_defineMacro 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: if not self.metal:
self.interpret(block) self.interpret(block)
return return
...@@ -528,7 +522,7 @@ class TALInterpreter: ...@@ -528,7 +522,7 @@ class TALInterpreter:
self.popMacro() self.popMacro()
bytecode_handlers["useMacro"] = do_useMacro bytecode_handlers["useMacro"] = do_useMacro
def do_fillSlot(self, slotName, block): def do_fillSlot(self, (slotName, block)):
if not self.metal: if not self.metal:
self.interpret(block) self.interpret(block)
return return
...@@ -537,7 +531,7 @@ class TALInterpreter: ...@@ -537,7 +531,7 @@ class TALInterpreter:
self.popMacro() self.popMacro()
bytecode_handlers["fillSlot"] = do_fillSlot bytecode_handlers["fillSlot"] = do_fillSlot
def do_defineSlot(self, slotName, block): def do_defineSlot(self, (slotName, block)):
if not self.metal: if not self.metal:
self.interpret(block) self.interpret(block)
return return
...@@ -553,7 +547,7 @@ class TALInterpreter: ...@@ -553,7 +547,7 @@ class TALInterpreter:
self.popMacro() self.popMacro()
bytecode_handlers["defineSlot"] = do_defineSlot bytecode_handlers["defineSlot"] = do_defineSlot
def do_onError(self, block, handler): def do_onError(self, (block, handler)):
if not self.tal: if not self.tal:
self.interpret(block) self.interpret(block)
return return
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment