Author: leo
Date: Fri Sep 16 00:24:10 2005
New Revision: 9203
Modified:
branches/leo-ctx5/classes/eval.pmc
branches/leo-ctx5/config/gen/makefiles.pl
branches/leo-ctx5/include/parrot/packfile.h
branches/leo-ctx5/languages/bc/bc.py
branches/leo-ctx5/languages/bc/grammar/bc_python.g
branches/leo-ctx5/languages/bc/python/lib/bc/BcLexer.py
branches/leo-ctx5/languages/bc/python/lib/bc/BcLexerTokenTypes.txt
branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py
branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
branches/leo-ctx5/languages/bc/t/basic.t
branches/leo-ctx5/src/embed.c
branches/leo-ctx5/src/exec_start.c
branches/leo-ctx5/src/packfile.c
Log:
merge -r9198:9202 from trunk
Modified: branches/leo-ctx5/classes/eval.pmc
==============================================================================
--- branches/leo-ctx5/classes/eval.pmc (original)
+++ branches/leo-ctx5/classes/eval.pmc Fri Sep 16 00:24:10 2005
@@ -204,6 +204,7 @@ Final code fixup after thawing.
if (!PackFile_unpack(INTERP, pf, packed->strstart, packed->strlen))
real_exception(INTERP, NULL, E_IOError,
"couldn't unpack packfile");
+ fixup_subs(INTERP, pf->cur_cs, PBC_PBC);
for (i = 0; i < pf->directory.num_segments; ++i) {
seg = pf->directory.segments[i];
if (seg->type == PF_BYTEC_SEG) {
Modified: branches/leo-ctx5/config/gen/makefiles.pl
==============================================================================
--- branches/leo-ctx5/config/gen/makefiles.pl (original)
+++ branches/leo-ctx5/config/gen/makefiles.pl Fri Sep 16 00:24:10 2005
@@ -39,8 +39,8 @@ sub cflags {
if (Configure::Data->get('cpuarch') =~ /sun4|sparc64/) {
# CFLAGS entries must be left-aligned.
print CFLAGS <<"EOF";
-jit_cpu.c -{-Wcast-align} # lots of noise!
-nci.c -{-Wstrict-prototypes} # lots of noise!
+src/jit_cpu.c -{-Wcast-align} # lots of noise!
+src/nci.c -{-Wstrict-prototypes} # lots of noise!
EOF
}
Modified: branches/leo-ctx5/include/parrot/packfile.h
==============================================================================
--- branches/leo-ctx5/include/parrot/packfile.h (original)
+++ branches/leo-ctx5/include/parrot/packfile.h Fri Sep 16 00:24:10 2005
@@ -242,6 +242,7 @@ typedef enum {
} pbc_action_enum_t;
void PackFile_fixup_subs(Interp *interpreter, pbc_action_enum_t);
+void fixup_subs(Interp *interpreter, struct PackFile_ByteCode *self, int
action);
/*
* directory functions
*/
Modified: branches/leo-ctx5/languages/bc/bc.py
==============================================================================
--- branches/leo-ctx5/languages/bc/bc.py (original)
+++ branches/leo-ctx5/languages/bc/bc.py Fri Sep 16 00:24:10 2005
@@ -22,9 +22,6 @@ class Visitor(antlr.ASTVisitor):
return
assert 0
- def tabs(self):
- print " " * self.level
-
def printf(self,fmt,*args):
if not args:
sys.stdout.write(fmt)
@@ -92,32 +89,39 @@ def main():
###show tree
print ""
- print "=for comment\n"
+ print "=begin comment"
print ""
print "AST after parsing " + bc_filenames[0]
print ""
print "toStringList: " + ast.toStringList()
+ print ""
print "visit>>"
print ""
visitor.visit(ast);
print "visit<<"
print ""
- print "=cut"
+ print "=end comment"
print ""
W = bc.BcTreeWalker.Walker();
W.gen_pir(ast);
pir_ast = W.getAST()
- print "\n"
- print "=for comment\n"
- print "AST processed by TreeParser\n"
- print "toStringList: " + pir_ast.toStringList()
+ print ""
+ print "=begin comment"
+ print ""
+ print "AST after being processed by TreeParser"
+ print ""
+ print "pir_ast.toStringList:"
+ print pir_ast.toStringList()
+ print ""
print "visit>>\n"
visitor.visit(pir_ast);
print "visit<<"
- print "\n"
- print "=cut\n"
+ print ""
+ print "=end comment"
+ print ""
+ print "=cut"
print """
#!/usr/bin/env parrot
Modified: branches/leo-ctx5/languages/bc/grammar/bc_python.g
==============================================================================
--- branches/leo-ctx5/languages/bc/grammar/bc_python.g (original)
+++ branches/leo-ctx5/languages/bc/grammar/bc_python.g Fri Sep 16 00:24:10 2005
@@ -18,7 +18,8 @@
header "BcTreeWalker.__init__"
{
- self.reg_num = 0; // counter for unlimited number of PMC registers
+ self.reg_num = 0; // counter for unlimited number of PMC registers
+ self.label_num = 0; // counter for generation jump labels
}
header "BcParser.__init__"
@@ -113,9 +114,10 @@ DECR : "--" ;
Quit : "quit";
Define : "define";
Auto : "auto";
+If : "if";
KEYWORDS: "break" | "length" |
- "return" | "for" | "if" | "while" | "sqrt" |
+ "return" | "for" | "while" | "sqrt" |
"scale" | "ibase" | "obase";
// See 4.3.7.2 item (16)
@@ -214,6 +216,7 @@ statement
pir += "end\n # ";
#statement = #( [ PIR_OP, pir ] )
}
+ | If^ LPAREN! relational_expression RPAREN! statement
| LCURLY! statement_list RCURLY!
;
@@ -256,7 +259,7 @@ argument_list
//TODO
relational_expression
- : expression
+ : expression ( REL_OP expression )?
;
//TODO
@@ -459,6 +462,12 @@ expr_line!
lex_name + " = " + lex_name + " - 1 \n # "
#expr_line = #( [ PIR_NOOP, "noop" ], [PIR_OP, pir], [PIR_OP, "\nprint
"], [PIR_OP,lex_name], [PIR_NEWLINE, "\nprint \"\\n\" # "] )
}
+ | #( If reg_name=E3:expr p2:expr_line )
+ {
+ pir = "\n" + \
+ "unless " + reg_name + " goto LABEL_%d\n#" % self.label_num
+ #expr_line = #( [ PIR_NOOP, "noop" ], #E3, [PIR_OP, pir], #p2,
[PIR_OP,"\nLABEL_0:\n#"] )
+ }
| p:PIR_OP
{
#expr_line = #p
Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcLexer.py
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcLexer.py (original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcLexer.py Fri Sep 16
00:24:10 2005
@@ -43,29 +43,30 @@ DECR = 16
Quit = 17
Define = 18
Auto = 19
-KEYWORDS = 20
-LPAREN = 21
-RPAREN = 22
-COMMA = 23
-PLUS = 24
-MINUS = 25
-SEMICOLON = 26
-LBRACKET = 27
-RBRACKET = 28
-CARET = 29
-LCURLY = 30
-RCURLY = 31
-WS = 32
-ML_COMMENT = 33
-PIR_OP = 34
-UNARY_MINUS = 35
-PIR_PRINT_PMC = 36
-PIR_FUNCTION_DEF = 37
-PIR_FOOTER = 38
-PIR_HEADER = 39
-PIR_NOOP = 40
-PIR_COMMENT = 41
-PIR_NEWLINE = 42
+If = 20
+KEYWORDS = 21
+LPAREN = 22
+RPAREN = 23
+COMMA = 24
+PLUS = 25
+MINUS = 26
+SEMICOLON = 27
+LBRACKET = 28
+RBRACKET = 29
+CARET = 30
+LCURLY = 31
+RCURLY = 32
+WS = 33
+ML_COMMENT = 34
+PIR_OP = 35
+UNARY_MINUS = 36
+PIR_PRINT_PMC = 37
+PIR_FUNCTION_DEF = 38
+PIR_FOOTER = 39
+PIR_HEADER = 40
+PIR_NOOP = 41
+PIR_COMMENT = 42
+PIR_NEWLINE = 43
class Lexer(antlr.CharScanner) :
### user action >>>
@@ -169,6 +170,10 @@ class Lexer(antlr.CharScanner) :
pass
self.mAuto(True)
theRetToken = self._returnToken
+ elif (self.LA(1)==u'i') and (self.LA(2)==u'f'):
+ pass
+ self.mIf(True)
+ theRetToken = self._returnToken
elif (_tokenSet_0.member(self.LA(1))) and
(_tokenSet_1.member(self.LA(2))):
pass
self.mKEYWORDS(True)
@@ -466,6 +471,16 @@ class Lexer(antlr.CharScanner) :
self.match("auto")
self.set_return_token(_createToken, _token, _ttype, _begin)
+ def mIf(self, _createToken):
+ _ttype = 0
+ _token = None
+ _begin = self.text.length()
+ _ttype = If
+ _saveIndex = 0
+ pass
+ self.match("if")
+ self.set_return_token(_createToken, _token, _ttype, _begin)
+
def mKEYWORDS(self, _createToken):
_ttype = 0
_token = None
@@ -490,22 +505,19 @@ class Lexer(antlr.CharScanner) :
elif la1 and la1 in u'w':
pass
self.match("while")
+ elif la1 and la1 in u'i':
+ pass
+ self.match("ibase")
elif la1 and la1 in u'o':
pass
self.match("obase")
else:
- if (self.LA(1)==u'i') and (self.LA(2)==u'f'):
- pass
- self.match("if")
- elif (self.LA(1)==u's') and (self.LA(2)==u'q'):
+ if (self.LA(1)==u's') and (self.LA(2)==u'q'):
pass
self.match("sqrt")
elif (self.LA(1)==u's') and (self.LA(2)==u'c'):
pass
self.match("scale")
- elif (self.LA(1)==u'i') and (self.LA(2)==u'b'):
- pass
- self.match("ibase")
else:
self.raise_NoViableAlt(self.LA(1))
@@ -688,7 +700,7 @@ _tokenSet_0 = antlr.BitSet(mk_tokenSet_0
### generate bit set
def mk_tokenSet_1():
### var1
- data = [ 0L, 1831150716715008L, 0L, 0L]
+ data = [ 0L, 1830875838808064L, 0L, 0L]
return data
_tokenSet_1 = antlr.BitSet(mk_tokenSet_1())
Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcLexerTokenTypes.txt
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcLexerTokenTypes.txt
(original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcLexerTokenTypes.txt Fri Sep
16 00:24:10 2005
@@ -16,26 +16,27 @@ DECR=16
Quit=17
Define=18
Auto=19
-KEYWORDS=20
-LPAREN=21
-RPAREN=22
-COMMA=23
-PLUS=24
-MINUS=25
-SEMICOLON=26
-LBRACKET=27
-RBRACKET=28
-CARET=29
-LCURLY=30
-RCURLY=31
-WS=32
-ML_COMMENT=33
-PIR_OP=34
-UNARY_MINUS=35
-PIR_PRINT_PMC=36
-PIR_FUNCTION_DEF=37
-PIR_FOOTER=38
-PIR_HEADER=39
-PIR_NOOP=40
-PIR_COMMENT=41
-PIR_NEWLINE=42
+If=20
+KEYWORDS=21
+LPAREN=22
+RPAREN=23
+COMMA=24
+PLUS=25
+MINUS=26
+SEMICOLON=27
+LBRACKET=28
+RBRACKET=29
+CARET=30
+LCURLY=31
+RCURLY=32
+WS=33
+ML_COMMENT=34
+PIR_OP=35
+UNARY_MINUS=36
+PIR_PRINT_PMC=37
+PIR_FUNCTION_DEF=38
+PIR_FOOTER=39
+PIR_HEADER=40
+PIR_NOOP=41
+PIR_COMMENT=42
+PIR_NEWLINE=43
Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py (original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcParser.py Fri Sep 16
00:24:10 2005
@@ -40,29 +40,30 @@ DECR = 16
Quit = 17
Define = 18
Auto = 19
-KEYWORDS = 20
-LPAREN = 21
-RPAREN = 22
-COMMA = 23
-PLUS = 24
-MINUS = 25
-SEMICOLON = 26
-LBRACKET = 27
-RBRACKET = 28
-CARET = 29
-LCURLY = 30
-RCURLY = 31
-WS = 32
-ML_COMMENT = 33
-PIR_OP = 34
-UNARY_MINUS = 35
-PIR_PRINT_PMC = 36
-PIR_FUNCTION_DEF = 37
-PIR_FOOTER = 38
-PIR_HEADER = 39
-PIR_NOOP = 40
-PIR_COMMENT = 41
-PIR_NEWLINE = 42
+If = 20
+KEYWORDS = 21
+LPAREN = 22
+RPAREN = 23
+COMMA = 24
+PLUS = 25
+MINUS = 26
+SEMICOLON = 27
+LBRACKET = 28
+RBRACKET = 29
+CARET = 30
+LCURLY = 31
+RCURLY = 32
+WS = 33
+ML_COMMENT = 34
+PIR_OP = 35
+UNARY_MINUS = 36
+PIR_PRINT_PMC = 37
+PIR_FUNCTION_DEF = 38
+PIR_FOOTER = 39
+PIR_HEADER = 40
+PIR_NOOP = 41
+PIR_COMMENT = 42
+PIR_NEWLINE = 43
class Parser(antlr.LLkParser):
### user action >>>
@@ -93,9 +94,9 @@ class Parser(antlr.LLkParser):
else:
break
- tmp12_AST = None
- tmp12_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp12_AST)
+ tmp13_AST = None
+ tmp13_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp13_AST)
self.match(EOF_TYPE)
program_AST = currentAST.root
@@ -115,7 +116,7 @@ class Parser(antlr.LLkParser):
la1 = self.LA(1)
if False:
pass
- elif la1 and la1 in
[NEWLINE,STRING,LETTER,NUMBER,INCR,DECR,Quit,LPAREN,MINUS,LCURLY]:
+ elif la1 and la1 in
[NEWLINE,STRING,LETTER,NUMBER,INCR,DECR,Quit,If,LPAREN,MINUS,LCURLY]:
pass
self.semicolon_list()
self.addASTChild(currentAST, self.returnAST)
@@ -147,7 +148,7 @@ class Parser(antlr.LLkParser):
la1 = self.LA(1)
if False:
pass
- elif la1 and la1 in
[STRING,LETTER,NUMBER,INCR,DECR,Quit,LPAREN,MINUS,LCURLY]:
+ elif la1 and la1 in
[STRING,LETTER,NUMBER,INCR,DECR,Quit,If,LPAREN,MINUS,LCURLY]:
pass
self.statement()
self.addASTChild(currentAST, self.returnAST)
@@ -181,39 +182,39 @@ class Parser(antlr.LLkParser):
function_AST = None
try: ## for error handling
pass
- tmp15_AST = None
- tmp15_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp15_AST)
- self.match(Define)
tmp16_AST = None
tmp16_AST = self.astFactory.create(self.LT(1))
self.addASTChild(currentAST, tmp16_AST)
- self.match(LETTER)
+ self.match(Define)
tmp17_AST = None
tmp17_AST = self.astFactory.create(self.LT(1))
self.addASTChild(currentAST, tmp17_AST)
- self.match(LPAREN)
- self.opt_parameter_list()
- self.addASTChild(currentAST, self.returnAST)
+ self.match(LETTER)
tmp18_AST = None
tmp18_AST = self.astFactory.create(self.LT(1))
self.addASTChild(currentAST, tmp18_AST)
- self.match(RPAREN)
+ self.match(LPAREN)
+ self.opt_parameter_list()
+ self.addASTChild(currentAST, self.returnAST)
tmp19_AST = None
tmp19_AST = self.astFactory.create(self.LT(1))
self.addASTChild(currentAST, tmp19_AST)
- self.match(LCURLY)
+ self.match(RPAREN)
tmp20_AST = None
tmp20_AST = self.astFactory.create(self.LT(1))
self.addASTChild(currentAST, tmp20_AST)
+ self.match(LCURLY)
+ tmp21_AST = None
+ tmp21_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp21_AST)
self.match(NEWLINE)
self.opt_auto_define_list()
self.addASTChild(currentAST, self.returnAST)
self.statement_list()
self.addASTChild(currentAST, self.returnAST)
- tmp21_AST = None
- tmp21_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp21_AST)
+ tmp22_AST = None
+ tmp22_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp22_AST)
self.match(RCURLY)
function_AST = currentAST.root
function_AST =
antlr.make(self.astFactory.create(PIR_FUNCTION_DEF,"function definition"))
@@ -267,9 +268,9 @@ class Parser(antlr.LLkParser):
statement_AST = currentAST.root
elif la1 and la1 in [Quit]:
pass
- tmp22_AST = None
- tmp22_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp22_AST)
+ tmp23_AST = None
+ tmp23_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp23_AST)
self.match(Quit)
statement_AST = currentAST.root
pir += "end\n # ";
@@ -281,6 +282,19 @@ class Parser(antlr.LLkParser):
currentAST.child = statement_AST
currentAST.advanceChildToEnd()
statement_AST = currentAST.root
+ elif la1 and la1 in [If]:
+ pass
+ tmp24_AST = None
+ tmp24_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp24_AST)
+ self.match(If)
+ self.match(LPAREN)
+ self.relational_expression()
+ self.addASTChild(currentAST, self.returnAST)
+ self.match(RPAREN)
+ self.statement()
+ self.addASTChild(currentAST, self.returnAST)
+ statement_AST = currentAST.root
elif la1 and la1 in [LCURLY]:
pass
self.match(LCURLY)
@@ -311,7 +325,7 @@ class Parser(antlr.LLkParser):
la1 = self.LA(1)
if False:
pass
- elif la1 and la1 in
[STRING,LETTER,NUMBER,INCR,DECR,Quit,LPAREN,MINUS,LCURLY]:
+ elif la1 and la1 in
[STRING,LETTER,NUMBER,INCR,DECR,Quit,If,LPAREN,MINUS,LCURLY]:
pass
self.statement()
self.addASTChild(currentAST, self.returnAST)
@@ -368,6 +382,40 @@ class Parser(antlr.LLkParser):
self.returnAST = printable_expression_AST
+ def relational_expression(self):
+
+ self.returnAST = None
+ currentAST = antlr.ASTPair()
+ relational_expression_AST = None
+ try: ## for error handling
+ pass
+ self.expression()
+ self.addASTChild(currentAST, self.returnAST)
+ la1 = self.LA(1)
+ if False:
+ pass
+ elif la1 and la1 in [REL_OP]:
+ pass
+ tmp30_AST = None
+ tmp30_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp30_AST)
+ self.match(REL_OP)
+ self.expression()
+ self.addASTChild(currentAST, self.returnAST)
+ elif la1 and la1 in [RPAREN]:
+ pass
+ else:
+ raise antlr.NoViableAltException(self.LT(1),
self.getFilename())
+
+ relational_expression_AST = currentAST.root
+
+ except antlr.RecognitionException, ex:
+ self.reportError(ex)
+ self.consume()
+ self.consumeUntil(_tokenSet_7)
+
+ self.returnAST = relational_expression_AST
+
def opt_parameter_list(self):
self.returnAST = None
@@ -408,9 +456,9 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [Auto]:
pass
- tmp26_AST = None
- tmp26_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp26_AST)
+ tmp31_AST = None
+ tmp31_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp31_AST)
self.match(Auto)
self.define_list()
self.addASTChild(currentAST, self.returnAST)
@@ -419,20 +467,20 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [NEWLINE]:
pass
- tmp27_AST = None
- tmp27_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp27_AST)
+ tmp32_AST = None
+ tmp32_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp32_AST)
self.match(NEWLINE)
elif la1 and la1 in [SEMICOLON]:
pass
- tmp28_AST = None
- tmp28_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp28_AST)
+ tmp33_AST = None
+ tmp33_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp33_AST)
self.match(SEMICOLON)
else:
raise antlr.NoViableAltException(self.LT(1),
self.getFilename())
- elif la1 and la1 in
[NEWLINE,STRING,LETTER,NUMBER,INCR,DECR,Quit,LPAREN,MINUS,LCURLY,RCURLY]:
+ elif la1 and la1 in
[NEWLINE,STRING,LETTER,NUMBER,INCR,DECR,Quit,If,LPAREN,MINUS,LCURLY,RCURLY]:
pass
else:
raise antlr.NoViableAltException(self.LT(1),
self.getFilename())
@@ -471,20 +519,20 @@ class Parser(antlr.LLkParser):
define_list_AST = None
try: ## for error handling
pass
- tmp29_AST = None
- tmp29_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp29_AST)
+ tmp34_AST = None
+ tmp34_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp34_AST)
self.match(LETTER)
while True:
if (self.LA(1)==COMMA):
pass
- tmp30_AST = None
- tmp30_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp30_AST)
+ tmp35_AST = None
+ tmp35_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp35_AST)
self.match(COMMA)
- tmp31_AST = None
- tmp31_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp31_AST)
+ tmp36_AST = None
+ tmp36_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp36_AST)
self.match(LETTER)
else:
break
@@ -552,14 +600,14 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [ASSIGN_OP]:
pass
- tmp32_AST = None
- tmp32_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp32_AST)
+ tmp37_AST = None
+ tmp37_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp37_AST)
self.match(ASSIGN_OP)
self.expression()
self.addASTChild(currentAST, self.returnAST)
self.do_print = 0
- elif la1 and la1 in
[EOF,NEWLINE,STRING,LETTER,NUMBER,INCR,DECR,Quit,LPAREN,MINUS,SEMICOLON,LCURLY,RCURLY]:
+ elif la1 and la1 in
[EOF,NEWLINE,STRING,LETTER,NUMBER,REL_OP,INCR,DECR,Quit,If,LPAREN,RPAREN,MINUS,SEMICOLON,LCURLY,RCURLY]:
pass
else:
raise antlr.NoViableAltException(self.LT(1),
self.getFilename())
@@ -567,9 +615,9 @@ class Parser(antlr.LLkParser):
expression_AST = currentAST.root
elif la1 and la1 in [INCR]:
pass
- tmp33_AST = None
- tmp33_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp33_AST)
+ tmp38_AST = None
+ tmp38_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp38_AST)
self.match(INCR)
self.named_expression()
self.addASTChild(currentAST, self.returnAST)
@@ -577,9 +625,9 @@ class Parser(antlr.LLkParser):
expression_AST = currentAST.root
elif la1 and la1 in [DECR]:
pass
- tmp34_AST = None
- tmp34_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp34_AST)
+ tmp39_AST = None
+ tmp39_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp39_AST)
self.match(DECR)
self.named_expression()
self.addASTChild(currentAST, self.returnAST)
@@ -601,24 +649,6 @@ class Parser(antlr.LLkParser):
self.returnAST = expression_AST
- def relational_expression(self):
-
- self.returnAST = None
- currentAST = antlr.ASTPair()
- relational_expression_AST = None
- try: ## for error handling
- pass
- self.expression()
- self.addASTChild(currentAST, self.returnAST)
- relational_expression_AST = currentAST.root
-
- except antlr.RecognitionException, ex:
- self.reportError(ex)
- self.consume()
- self.consumeUntil(_tokenSet_1)
-
- self.returnAST = relational_expression_AST
-
def return_expression(self):
self.returnAST = None
@@ -644,9 +674,9 @@ class Parser(antlr.LLkParser):
named_expression_AST = None
try: ## for error handling
pass
- tmp35_AST = None
- tmp35_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp35_AST)
+ tmp40_AST = None
+ tmp40_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp40_AST)
self.match(LETTER)
named_expression_AST = currentAST.root
@@ -674,15 +704,15 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [PLUS]:
pass
- tmp36_AST = None
- tmp36_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp36_AST)
+ tmp41_AST = None
+ tmp41_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp41_AST)
self.match(PLUS)
elif la1 and la1 in [MINUS]:
pass
- tmp37_AST = None
- tmp37_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp37_AST)
+ tmp42_AST = None
+ tmp42_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp42_AST)
self.match(MINUS)
else:
raise antlr.NoViableAltException(self.LT(1),
self.getFilename())
@@ -697,7 +727,7 @@ class Parser(antlr.LLkParser):
except antlr.RecognitionException, ex:
self.reportError(ex)
self.consume()
- self.consumeUntil(_tokenSet_11)
+ self.consumeUntil(_tokenSet_9)
self.returnAST = adding_expression_AST
@@ -718,21 +748,21 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [MUL]:
pass
- tmp38_AST = None
- tmp38_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp38_AST)
+ tmp43_AST = None
+ tmp43_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp43_AST)
self.match(MUL)
elif la1 and la1 in [DIV]:
pass
- tmp39_AST = None
- tmp39_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp39_AST)
+ tmp44_AST = None
+ tmp44_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp44_AST)
self.match(DIV)
elif la1 and la1 in [MOD]:
pass
- tmp40_AST = None
- tmp40_AST = self.astFactory.create(self.LT(1))
- self.makeASTRoot(currentAST, tmp40_AST)
+ tmp45_AST = None
+ tmp45_AST = self.astFactory.create(self.LT(1))
+ self.makeASTRoot(currentAST, tmp45_AST)
self.match(MOD)
else:
raise antlr.NoViableAltException(self.LT(1),
self.getFilename())
@@ -747,7 +777,7 @@ class Parser(antlr.LLkParser):
except antlr.RecognitionException, ex:
self.reportError(ex)
self.consume()
- self.consumeUntil(_tokenSet_12)
+ self.consumeUntil(_tokenSet_11)
self.returnAST = multiplying_expression_AST
@@ -764,8 +794,8 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [MINUS]:
pass
- tmp41_AST = None
- tmp41_AST = self.astFactory.create(self.LT(1))
+ tmp46_AST = None
+ tmp46_AST = self.astFactory.create(self.LT(1))
self.match(MINUS)
self.paren_expression()
i1_AST = self.returnAST
@@ -796,7 +826,7 @@ class Parser(antlr.LLkParser):
except antlr.RecognitionException, ex:
self.reportError(ex)
self.consume()
- self.consumeUntil(_tokenSet_13)
+ self.consumeUntil(_tokenSet_12)
self.returnAST = sign_expression_AST
@@ -811,9 +841,9 @@ class Parser(antlr.LLkParser):
pass
elif la1 and la1 in [NUMBER]:
pass
- tmp42_AST = None
- tmp42_AST = self.astFactory.create(self.LT(1))
- self.addASTChild(currentAST, tmp42_AST)
+ tmp47_AST = None
+ tmp47_AST = self.astFactory.create(self.LT(1))
+ self.addASTChild(currentAST, tmp47_AST)
self.match(NUMBER)
paren_expression_AST = currentAST.root
elif la1 and la1 in [LPAREN]:
@@ -830,7 +860,7 @@ class Parser(antlr.LLkParser):
except antlr.RecognitionException, ex:
self.reportError(ex)
self.consume()
- self.consumeUntil(_tokenSet_13)
+ self.consumeUntil(_tokenSet_12)
self.returnAST = paren_expression_AST
@@ -859,6 +889,7 @@ _tokenNames = [
"Quit",
"Define",
"Auto",
+ "If",
"KEYWORDS",
"LPAREN",
"RPAREN",
@@ -888,7 +919,7 @@ _tokenNames = [
### generate bit set
def mk_tokenSet_0():
### var1
- data = [ 1109885552L, 0L]
+ data = [ 2220327536L, 0L]
return data
_tokenSet_0 = antlr.BitSet(mk_tokenSet_0())
@@ -902,7 +933,7 @@ _tokenSet_1 = antlr.BitSet(mk_tokenSet_1
### generate bit set
def mk_tokenSet_2():
### var1
- data = [ 1109885554L, 0L]
+ data = [ 2220327538L, 0L]
return data
_tokenSet_2 = antlr.BitSet(mk_tokenSet_2())
@@ -916,70 +947,63 @@ _tokenSet_3 = antlr.BitSet(mk_tokenSet_3
### generate bit set
def mk_tokenSet_4():
### var1
- data = [ 3324215920L, 0L]
+ data = [ 6649250416L, 0L]
return data
_tokenSet_4 = antlr.BitSet(mk_tokenSet_4())
### generate bit set
def mk_tokenSet_5():
### var1
- data = [ 3257107056L, 0L]
+ data = [ 6515032688L, 0L]
return data
_tokenSet_5 = antlr.BitSet(mk_tokenSet_5())
### generate bit set
def mk_tokenSet_6():
### var1
- data = [ 2147483648L, 0L]
+ data = [ 4294967296L, 0L]
return data
_tokenSet_6 = antlr.BitSet(mk_tokenSet_6())
### generate bit set
def mk_tokenSet_7():
### var1
- data = [ 4194304L, 0L]
+ data = [ 8388608L, 0L]
return data
_tokenSet_7 = antlr.BitSet(mk_tokenSet_7())
### generate bit set
def mk_tokenSet_8():
### var1
- data = [ 71303184L, 0L]
+ data = [ 142606352L, 0L]
return data
_tokenSet_8 = antlr.BitSet(mk_tokenSet_8())
### generate bit set
def mk_tokenSet_9():
### var1
- data = [ 3324215922L, 0L]
+ data = [ 6657655410L, 0L]
return data
_tokenSet_9 = antlr.BitSet(mk_tokenSet_9())
### generate bit set
def mk_tokenSet_10():
### var1
- data = [ 3324224114L, 0L]
+ data = [ 6657663602L, 0L]
return data
_tokenSet_10 = antlr.BitSet(mk_tokenSet_10())
### generate bit set
def mk_tokenSet_11():
### var1
- data = [ 3328410226L, 0L]
+ data = [ 6691209842L, 0L]
return data
_tokenSet_11 = antlr.BitSet(mk_tokenSet_11())
### generate bit set
def mk_tokenSet_12():
### var1
- data = [ 3345187442L, 0L]
+ data = [ 6691217010L, 0L]
return data
_tokenSet_12 = antlr.BitSet(mk_tokenSet_12())
-
-### generate bit set
-def mk_tokenSet_13():
- ### var1
- data = [ 3345194610L, 0L]
- return data
-_tokenSet_13 = antlr.BitSet(mk_tokenSet_13())
Modified: branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
==============================================================================
--- branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py
(original)
+++ branches/leo-ctx5/languages/bc/python/lib/bc/BcTreeWalker.py Fri Sep
16 00:24:10 2005
@@ -37,29 +37,30 @@ DECR = 16
Quit = 17
Define = 18
Auto = 19
-KEYWORDS = 20
-LPAREN = 21
-RPAREN = 22
-COMMA = 23
-PLUS = 24
-MINUS = 25
-SEMICOLON = 26
-LBRACKET = 27
-RBRACKET = 28
-CARET = 29
-LCURLY = 30
-RCURLY = 31
-WS = 32
-ML_COMMENT = 33
-PIR_OP = 34
-UNARY_MINUS = 35
-PIR_PRINT_PMC = 36
-PIR_FUNCTION_DEF = 37
-PIR_FOOTER = 38
-PIR_HEADER = 39
-PIR_NOOP = 40
-PIR_COMMENT = 41
-PIR_NEWLINE = 42
+If = 20
+KEYWORDS = 21
+LPAREN = 22
+RPAREN = 23
+COMMA = 24
+PLUS = 25
+MINUS = 26
+SEMICOLON = 27
+LBRACKET = 28
+RBRACKET = 29
+CARET = 30
+LCURLY = 31
+RCURLY = 32
+WS = 33
+ML_COMMENT = 34
+PIR_OP = 35
+UNARY_MINUS = 36
+PIR_PRINT_PMC = 37
+PIR_FUNCTION_DEF = 38
+PIR_FOOTER = 39
+PIR_HEADER = 40
+PIR_NOOP = 41
+PIR_COMMENT = 42
+PIR_NEWLINE = 43
### user code>>>
@@ -72,7 +73,8 @@ class Walker(antlr.TreeParser):
antlr.TreeParser.__init__(self, *args, **kwargs)
self.tokenNames = _tokenNames
### __init__ header action >>>
- self.reg_num = 0; # counter for unlimited number of PMC registers
+ self.reg_num = 0; # counter for unlimited number of PMC registers
+ self.label_num = 0; # counter for generation jump labels
### __init__ header action <<<
### user action >>>
@@ -92,12 +94,12 @@ class Walker(antlr.TreeParser):
right = None
try: ## for error handling
pass
- _t81 = _t
+ _t83 = _t
tmp1_AST = None
tmp1_AST_in = None
tmp1_AST = self.astFactory.create(_t)
tmp1_AST_in = _t
- _currentAST81 = currentAST.copy()
+ _currentAST83 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,PLUS)
@@ -110,8 +112,8 @@ class Walker(antlr.TreeParser):
reg_name_right=self.expr(_t)
_t = self._retTree
right_AST = self.returnAST
- currentAST = _currentAST81
- _t = _t81
+ currentAST = _currentAST83
+ _t = _t83
_t = _t.getNextSibling()
plus_AST = currentAST.root
reg_name = "$P%d" % self.reg_num
@@ -221,12 +223,12 @@ class Walker(antlr.TreeParser):
right = None
try: ## for error handling
pass
- _t83 = _t
+ _t85 = _t
tmp2_AST = None
tmp2_AST_in = None
tmp2_AST = self.astFactory.create(_t)
tmp2_AST_in = _t
- _currentAST83 = currentAST.copy()
+ _currentAST85 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,MINUS)
@@ -239,8 +241,8 @@ class Walker(antlr.TreeParser):
reg_name_right=self.expr(_t)
_t = self._retTree
right_AST = self.returnAST
- currentAST = _currentAST83
- _t = _t83
+ currentAST = _currentAST85
+ _t = _t85
_t = _t.getNextSibling()
minus_AST = currentAST.root
reg_name = "$P%d" % self.reg_num
@@ -280,12 +282,12 @@ class Walker(antlr.TreeParser):
right = None
try: ## for error handling
pass
- _t85 = _t
+ _t87 = _t
tmp3_AST = None
tmp3_AST_in = None
tmp3_AST = self.astFactory.create(_t)
tmp3_AST_in = _t
- _currentAST85 = currentAST.copy()
+ _currentAST87 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,MUL)
@@ -298,8 +300,8 @@ class Walker(antlr.TreeParser):
reg_name_right=self.expr(_t)
_t = self._retTree
right_AST = self.returnAST
- currentAST = _currentAST85
- _t = _t85
+ currentAST = _currentAST87
+ _t = _t87
_t = _t.getNextSibling()
mul_AST = currentAST.root
reg_name = "$P%d" % self.reg_num
@@ -339,12 +341,12 @@ class Walker(antlr.TreeParser):
right = None
try: ## for error handling
pass
- _t87 = _t
+ _t89 = _t
tmp4_AST = None
tmp4_AST_in = None
tmp4_AST = self.astFactory.create(_t)
tmp4_AST_in = _t
- _currentAST87 = currentAST.copy()
+ _currentAST89 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,DIV)
@@ -357,8 +359,8 @@ class Walker(antlr.TreeParser):
reg_name_right=self.expr(_t)
_t = self._retTree
right_AST = self.returnAST
- currentAST = _currentAST87
- _t = _t87
+ currentAST = _currentAST89
+ _t = _t89
_t = _t.getNextSibling()
div_AST = currentAST.root
reg_name = "$P%d" % self.reg_num
@@ -398,12 +400,12 @@ class Walker(antlr.TreeParser):
right = None
try: ## for error handling
pass
- _t89 = _t
+ _t91 = _t
tmp5_AST = None
tmp5_AST_in = None
tmp5_AST = self.astFactory.create(_t)
tmp5_AST_in = _t
- _currentAST89 = currentAST.copy()
+ _currentAST91 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,MOD)
@@ -416,8 +418,8 @@ class Walker(antlr.TreeParser):
reg_name_right=self.expr(_t)
_t = self._retTree
right_AST = self.returnAST
- currentAST = _currentAST89
- _t = _t89
+ currentAST = _currentAST91
+ _t = _t91
_t = _t.getNextSibling()
mod_AST = currentAST.root
reg_name = "$P%d" % self.reg_num
@@ -521,13 +523,13 @@ class Walker(antlr.TreeParser):
signExpression_AST = currentAST.root
elif la1 and la1 in [UNARY_MINUS]:
pass
- _t92 = _t
+ _t94 = _t
tmp6_AST = None
tmp6_AST_in = None
tmp6_AST = self.astFactory.create(_t)
tmp6_AST_in = _t
self.addASTChild(currentAST, tmp6_AST)
- _currentAST92 = currentAST.copy()
+ _currentAST94 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,UNARY_MINUS)
@@ -537,8 +539,8 @@ class Walker(antlr.TreeParser):
_t = self._retTree
i2_AST = self.returnAST
self.addASTChild(currentAST, self.returnAST)
- currentAST = _currentAST92
- _t = _t92
+ currentAST = _currentAST94
+ _t = _t94
_t = _t.getNextSibling()
signExpression_AST = currentAST.root
pir = "\n" + \
@@ -607,6 +609,10 @@ class Walker(antlr.TreeParser):
E1 = None
E2_AST = None
E2 = None
+ E3_AST = None
+ E3 = None
+ p2_AST = None
+ p2 = None
p = None
p_AST = None
try: ## for error handling
@@ -617,12 +623,12 @@ class Walker(antlr.TreeParser):
pass
elif la1 and la1 in [PIR_PRINT_PMC]:
pass
- _t96 = _t
+ _t98 = _t
tmp7_AST = None
tmp7_AST_in = None
tmp7_AST = self.astFactory.create(_t)
tmp7_AST_in = _t
- _currentAST96 = currentAST.copy()
+ _currentAST98 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,PIR_PRINT_PMC)
@@ -631,8 +637,8 @@ class Walker(antlr.TreeParser):
reg_name=self.expr(_t)
_t = self._retTree
E1_AST = self.returnAST
- currentAST = _currentAST96
- _t = _t96
+ currentAST = _currentAST98
+ _t = _t98
_t = _t.getNextSibling()
expr_line_AST = currentAST.root
expr_line_AST =
antlr.make(self.astFactory.create(PIR_NOOP,"noop"), E1_AST,
self.astFactory.create(PIR_OP,"\nprint "),
self.astFactory.create(PIR_OP,reg_name),
self.astFactory.create(PIR_NEWLINE,"\nprint \"\\n\" # "))
@@ -644,12 +650,12 @@ class Walker(antlr.TreeParser):
currentAST.advanceChildToEnd()
elif la1 and la1 in [ASSIGN_OP]:
pass
- _t97 = _t
+ _t99 = _t
tmp8_AST = None
tmp8_AST_in = None
tmp8_AST = self.astFactory.create(_t)
tmp8_AST_in = _t
- _currentAST97 = currentAST.copy()
+ _currentAST99 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,ASSIGN_OP)
@@ -660,8 +666,8 @@ class Walker(antlr.TreeParser):
reg_name=self.expr(_t)
_t = self._retTree
E2_AST = self.returnAST
- currentAST = _currentAST97
- _t = _t97
+ currentAST = _currentAST99
+ _t = _t99
_t = _t.getNextSibling()
expr_line_AST = currentAST.root
pir = "\n" + \
@@ -675,20 +681,20 @@ class Walker(antlr.TreeParser):
currentAST.advanceChildToEnd()
elif la1 and la1 in [INCR]:
pass
- _t98 = _t
+ _t100 = _t
tmp9_AST = None
tmp9_AST_in = None
tmp9_AST = self.astFactory.create(_t)
tmp9_AST_in = _t
- _currentAST98 = currentAST.copy()
+ _currentAST100 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,INCR)
_t = _t.getFirstChild()
lex_name=self.namedExpression(_t)
_t = self._retTree
- currentAST = _currentAST98
- _t = _t98
+ currentAST = _currentAST100
+ _t = _t100
_t = _t.getNextSibling()
expr_line_AST = currentAST.root
pir = "\n" + \
@@ -702,20 +708,20 @@ class Walker(antlr.TreeParser):
currentAST.advanceChildToEnd()
elif la1 and la1 in [DECR]:
pass
- _t99 = _t
+ _t101 = _t
tmp10_AST = None
tmp10_AST_in = None
tmp10_AST = self.astFactory.create(_t)
tmp10_AST_in = _t
- _currentAST99 = currentAST.copy()
+ _currentAST101 = currentAST.copy()
currentAST.root = currentAST.child
currentAST.child = None
self.match(_t,DECR)
_t = _t.getFirstChild()
lex_name=self.namedExpression(_t)
_t = self._retTree
- currentAST = _currentAST99
- _t = _t99
+ currentAST = _currentAST101
+ _t = _t101
_t = _t.getNextSibling()
expr_line_AST = currentAST.root
pir = "\n" + \
@@ -727,6 +733,39 @@ class Walker(antlr.TreeParser):
else:
currentAST.child = expr_line_AST
currentAST.advanceChildToEnd()
+ elif la1 and la1 in [If]:
+ pass
+ _t102 = _t
+ tmp11_AST = None
+ tmp11_AST_in = None
+ tmp11_AST = self.astFactory.create(_t)
+ tmp11_AST_in = _t
+ _currentAST102 = currentAST.copy()
+ currentAST.root = currentAST.child
+ currentAST.child = None
+ self.match(_t,If)
+ _t = _t.getFirstChild()
+ E3 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+ reg_name=self.expr(_t)
+ _t = self._retTree
+ E3_AST = self.returnAST
+ p2 = antlr.ifelse(_t == antlr.ASTNULL, None, _t)
+ self.expr_line(_t)
+ _t = self._retTree
+ p2_AST = self.returnAST
+ currentAST = _currentAST102
+ _t = _t102
+ _t = _t.getNextSibling()
+ expr_line_AST = currentAST.root
+ pir = "\n" + \
+ "unless " + reg_name + " goto LABEL_%d\n#" %
self.label_num
+ expr_line_AST =
antlr.make(self.astFactory.create(PIR_NOOP,"noop"), E3_AST,
self.astFactory.create(PIR_OP,pir), p2_AST,
self.astFactory.create(PIR_OP,"\nLABEL_0:\n#"))
+ currentAST.root = expr_line_AST
+ if (expr_line_AST != None) and (expr_line_AST.getFirstChild()
!= None):
+ currentAST.child = expr_line_AST.getFirstChild()
+ else:
+ currentAST.child = expr_line_AST
+ currentAST.advanceChildToEnd()
elif la1 and la1 in [PIR_OP]:
pass
p = _t
@@ -764,32 +803,32 @@ class Walker(antlr.TreeParser):
expr_list_AST = None
try: ## for error handling
pass
- _cnt102= 0
+ _cnt105= 0
while True:
if not _t:
_t = antlr.ASTNULL
la1 = _t.getType()
if False:
pass
- elif la1 and la1 in [ASSIGN_OP,INCR,DECR,PIR_OP,PIR_PRINT_PMC]:
+ elif la1 and la1 in
[ASSIGN_OP,INCR,DECR,If,PIR_OP,PIR_PRINT_PMC]:
pass
self.expr_line(_t)
_t = self._retTree
self.addASTChild(currentAST, self.returnAST)
elif la1 and la1 in [PIR_FUNCTION_DEF]:
pass
- tmp11_AST = None
- tmp11_AST_in = None
- tmp11_AST = self.astFactory.create(_t)
- tmp11_AST_in = _t
- self.addASTChild(currentAST, tmp11_AST)
+ tmp12_AST = None
+ tmp12_AST_in = None
+ tmp12_AST = self.astFactory.create(_t)
+ tmp12_AST_in = _t
+ self.addASTChild(currentAST, tmp12_AST)
self.match(_t,PIR_FUNCTION_DEF)
_t = _t.getNextSibling()
else:
break
- _cnt102 += 1
- if _cnt102 < 1:
+ _cnt105 += 1
+ if _cnt105 < 1:
raise antlr.NoViableAltException(_t)
expr_list_AST = currentAST.root
@@ -856,6 +895,7 @@ _tokenNames = [
"Quit",
"Define",
"Auto",
+ "If",
"KEYWORDS",
"LPAREN",
"RPAREN",
Modified: branches/leo-ctx5/languages/bc/t/basic.t
==============================================================================
--- branches/leo-ctx5/languages/bc/t/basic.t (original)
+++ branches/leo-ctx5/languages/bc/t/basic.t Fri Sep 16 00:24:10 2005
@@ -16,7 +16,7 @@ use FindBin;
use lib "$FindBin::Bin/../../lib", "$FindBin::Bin/../../../../lib";
use Test::More;
-use Parrot::Test tests => 51;
+use Parrot::Test tests => 53;
sub run_tests
{
@@ -105,6 +105,9 @@ my @tests =
# increment and decrement
[ "a; a = 1; a; ++a; a", [0,1,2,2], 'increment' ],
[ "a; a = 1; a; --a; a", [0,1,0,0], 'decrement' ],
+ # If
+ [ "1; if ( 1 ) 2; 3", [1,2,3], 'if with a true condition' ],
+ [ "1; if ( 0 ) 2; 3", [1,3], 'if with a true condition' ],
);
my @todo_tests =
Modified: branches/leo-ctx5/src/embed.c
==============================================================================
--- branches/leo-ctx5/src/embed.c (original)
+++ branches/leo-ctx5/src/embed.c Fri Sep 16 00:24:10 2005
@@ -408,6 +408,15 @@ again:
return NULL;
}
+ /*
+ * fixup constant subroutine objects
+ */
+ fixup_subs(interpreter, pf->cur_cs, PBC_PBC);
+ /*
+ * JITting and/or prederefing the sub/the bytecode is done
+ * in switch_to_cs before actual usage of the segment
+ */
+
#ifdef PARROT_HAS_HEADER_SYSMMAN
if (fd >= 0) {
Modified: branches/leo-ctx5/src/exec_start.c
==============================================================================
--- branches/leo-ctx5/src/exec_start.c (original)
+++ branches/leo-ctx5/src/exec_start.c Fri Sep 16 00:24:10 2005
@@ -128,6 +128,7 @@ main(int argc, char **argv) {
printf( "Can't unpack.\n" );
return 1;
}
+ fixup_subs(interpreter, pf->cur_cs, PBC_PBC);
Parrot_loadbc(interpreter, pf);
setup_argv(interpreter, argc, argv);
Modified: branches/leo-ctx5/src/packfile.c
==============================================================================
--- branches/leo-ctx5/src/packfile.c (original)
+++ branches/leo-ctx5/src/packfile.c Fri Sep 16 00:24:10 2005
@@ -439,7 +439,7 @@ B<PBC_PBC>, B<PBC_LOADED>, or B<PBC_MAIN
*/
-static void
+void
fixup_subs(Interp *interpreter, struct PackFile_ByteCode *self, int action)
{
opcode_t i, ci;
@@ -661,14 +661,6 @@ PackFile_unpack(Interp *interpreter, str
cursor = PackFile_Segment_unpack(interpreter,
&self->directory.base, cursor);
Parrot_unblock_DOD(interpreter);
- /*
- * fixup constant subroutine objects
- */
- fixup_subs(interpreter, self->cur_cs, PBC_PBC);
- /*
- * JITting and/or prederefing the sub/the bytecode is done
- * in switch_to_cs before actual usage of the segment
- */
#ifdef PARROT_HAS_HEADER_SYSMMAN
if (self->is_mmap_ped && (