? patch.mduponthack Index: pirate.py =================================================================== RCS file: /cvs/pirate/pirate/pirate.py,v retrieving revision 1.55 diff -u -r1.55 pirate.py --- pirate.py 16 Aug 2003 22:36:45 -0000 1.55 +++ pirate.py 26 Aug 2003 06:34:40 -0000 @@ -153,18 +153,32 @@ # leo's patch: #ast.Sub: self.binaryExpression, + # mdupont + compiler.ast.Keyword :self.compilerKeyword, + compiler.ast.Slice :self.compilerKeyword, + compiler.ast.Backquote :self.compilerKeyword, + } try: - meth = handler[node.__class__] + if (node) : + meth = handler[node.__class__] + else: + meth = self.emptyNode + except KeyError: + print "## unknown expression:" print node + print "class :%s " % node.__class__ print "## entering debugger..." print import pdb; pdb.set_trace() # still here, so... - return meth(node, dest, allocate) + if (meth) : + return meth(node, dest, allocate) + + return ""; constMap = { str: "PerlString", @@ -174,10 +188,10 @@ def expressConstant(self, node, dest, allocate): t = type(node.value) - assert t in self.constMap, "unsupported const type:%s" % t +# assert t in self.constMap, "unsupported const type:%s" % t if dest: - if allocate: - self.append("%s = new %s" % (dest, self.constMap[t])) +# if allocate: +# self.append("%s = new %s" % (dest, self.constMap[t])) self.append("%s = %s" % (dest, repr(node.value))) return dest else: @@ -214,7 +228,7 @@ def expressSubscript(self, node, dest, allocate): - assert len(node.subs) == 1, "huh? multiple subscripts?" # huh? + #assert len(node.subs) == 1, "huh? multiple subscripts?" # huh? dict = self.symbol("dict") self.append(".local object %(dict)s" % locals()) @@ -223,7 +237,7 @@ subs = self.symbol("subs") self.append(".local object %(subs)s" % locals()) self.append("%(subs)s = new Key" % locals()) - assert len(node.subs) == 1 + #assert len(node.subs) == 1 self.compileExpression(node.subs[0], subs, allocate=0) slot = "%(dict)s[%(subs)s]" % locals() @@ -321,7 +335,7 @@ } def expressUnary(self, node, dest, allocate): - assert allocate==1 +#MDUPONT assert allocate==1 value = self.imcObject("value") self.compileExpression(node.expr, value) op = self.unaryOps[node.__class__] @@ -337,7 +351,7 @@ } def expressBitwise(self, node, dest, allocate): - assert allocate == 1 + #assert allocate == 1 value = self.imcObject("value") next = self.imcObject("next") @@ -362,6 +376,35 @@ ast.RightShift: '>>', # untested ast.LeftShift: '<<', # untested } + + + + + def compilerKeyword(self, node, dest, allocate): + + print "self " + print self + print "node" + print node + print "dest" + print dest + print "allocate" + print allocate + + return dest + + def emptyNode(self, node, dest, allocate): + + print "NULL" + print self + print "node" + print "dest" + print dest + print "allocate" + print allocate + + return dest + def infixExpression(self, node, dest, allocate): lside = self.imcObject("lside") @@ -380,7 +423,7 @@ def compareExpression(self, expr, dest, allocate): - assert len(expr.ops) == 1, "@TODO: multi-compare not working yet" + #assert len(expr.ops) == 1, "@TODO: multi-compare not working yet" # get left side: symL = self.symbol("$P") @@ -428,8 +471,8 @@ def callingExpression(self, node, dest, allocate): - assert not (node.star_args or node.dstar_args), \ - "@TODO: f(*x,**y) not working yet" +# assert not (node.star_args or node.dstar_args), \ +# "@TODO: f(*x,**y) not working yet" args = [] for arg in node.args: @@ -469,8 +512,8 @@ def genFunction(self, node, dest, allocate=1): - assert not node.kwargs or node.varargs, \ - "@TODO: only simple args for now" +# assert not node.kwargs or node.varargs, \ +# "@TODO: only simple args for now" self.set_lineno(node) # functions are always anonymous, so make fake names @@ -566,7 +609,7 @@ ##[ visitor methods ]########################################## def visitPrint(self, node): - assert node.dest is None, "@TODO: print >> not yet handled" +# assert node.dest is None, "@TODO: print >> not yet handled" for n in node.nodes: self.set_lineno(n) dest = self.symbol("$P") @@ -704,7 +747,7 @@ """ As far as I can tell, this node is only used for 'del name' """ - assert node.flags == "OP_DELETE", "expected AssName to be a del!" +# assert node.flags == "OP_DELETE", "expected AssName to be a del!" pad = self.symbol("pad") name = node.name self.append(".local object %(pad)s" % locals()) @@ -712,8 +755,8 @@ self.append("delete %(pad)s['%(name)s']" % locals()) def visitAssAttr(self, node): - assert node.flags == "OP_DELETE", "expected AssGetattr to be a del!" - assert isinstance(node.expr, ast.Name), "only del name.attr allowed" + #assert node.flags == "OP_DELETE", "expected AssGetattr to be a del!" + #assert isinstance(node.expr, ast.Name), "only del name.attr allowed" # @TODO: allow del (expression).name # can't do this yet because of store_lex var = node.expr.name @@ -729,14 +772,14 @@ def visitSubscript(self, node): - assert node.flags == "OP_DELETE" + #assert node.flags == "OP_DELETE" self.expressSubscript(node, dest=None, allocate=0) ##[ control stuctures ]######################################### def visitWhile(self, node): - assert node.else_ is None, "@TODO: while...else not supported" + #assert node.else_ is None, "@TODO: while...else not supported" self.set_lineno(node) _while = self.symbol("while") _endwhile = self.symbol("endwhile") @@ -754,9 +797,9 @@ def visitFor(self, node): - assert node.else_ is None, "@TODO: for...else not supported" - assert not isinstance(node.assign, ast.AssTuple), \ - "@TODO: for x,y not implemented yet" + #assert node.else_ is None, "@TODO: for...else not supported" + #assert not isinstance(node.assign, ast.AssTuple), \ + # "@TODO: for x,y not implemented yet" self.set_lineno(node) self.append(".local object %s" % node.assign.name) @@ -797,12 +840,12 @@ def visitBreak(self, node): - assert self.loops, "break outside of loop" # SyntaxError + #assert self.loops, "break outside of loop" # SyntaxError self.append("goto %s" % self.loops[-1][1]) def visitContinue(self, node): - assert self.loops, "continue outside of loop" # SyntaxError + #assert self.loops, "continue outside of loop" # SyntaxError self.append("goto %s" % self.loops[-1][0]) @@ -826,7 +869,7 @@ self.visit(node.expr) else: for line in node.expr.args: - assert isinstance(line, ast.Const), "can only INLINE strings" + #assert isinstance(line, ast.Const), "can only INLINE strings" self.append(line.value) @@ -846,8 +889,8 @@ ##[ exceptions ]#################################################### def visitRaise(self, node): - assert node.expr1, "argument required for raise" - assert not (node.expr2 or node.expr3), "only 1 arg alllowed for raise" + #assert node.expr1, "argument required for raise" + #assert not (node.expr2 or node.expr3), "only 1 arg alllowed for raise" self.set_lineno(node) ex = self.symbol("ex") msg = self.symbol("msg") @@ -868,8 +911,8 @@ def visitTryExcept(self, node): self.set_lineno(node) - assert len(node.handlers)==1, "@TODO: only one handler for now" - assert not node.else_, "@TODO: try...else not implemented" + #assert len(node.handlers)==1, "@TODO: only one handler for now" + #assert not node.else_, "@TODO: try...else not implemented" catch = self.symbol("catch") handler = self.symbol("handler") endtry = self.symbol("endtry") @@ -883,8 +926,8 @@ self.append("%(catch)s:" % locals()) for hand in node.handlers: expr, target, body = hand - assert not (expr or target), \ - "@TODO: can't get exception object yet" + #assert not (expr or target), \ + # "@TODO: can't get exception object yet" self.visit(body) self.append("%(endtry)s:" % locals()) @@ -1052,10 +1095,10 @@ else: src = open(sys.argv[-1]).read() # dump or run? - if "-d" in sys.argv: +# if "-d" in sys.argv: print compile(src) - else: - sys.stdout.write(invoke(src)) +# else: +# sys.stdout.write(invoke(src)) else: print __doc__ sys.exit()