pike.git
/
src
/
docode.c
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/docode.c:1:
/*\ ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License) ||| See the files COPYING and DISCLAIMER for more information. \*/ #include "global.h"
-
RCSID("$Id: docode.c,v 1.
13
1997/03/
09
09
:
11
:
10
hubbe Exp $");
+
RCSID("$Id: docode.c,v 1.
14
1997/03/
11
03
:
36
:
39
hubbe Exp $");
#include "las.h" #include "program.h" #include "language.h" #include "pike_types.h" #include "stralloc.h" #include "interpret.h" #include "constants.h" #include "array.h" #include "macros.h" #include "error.h"
pike.git/src/docode.c:151:
int save_current_line=current_line; if(!n) return 0; current_line=n->line_number; i=do_docode2(n, flags); current_line=save_current_line; return i; }
-
void do_jump_when_zero(node *n,int j);
-
+
static int is_efun(node *n, c_fun fun) { return n && n->token == F_CONSTANT && n->u.sval.subtype == FUNCTION_BUILTIN && n->u.sval.u.efun->function == fun; }
-
void do_
jump
_
when_non_zero
(node *n,int
j
)
+
void do_
cond_
jump(node *n,
int
label, int iftrue, int flags
)
{
-
if(
!
node_is_tossable(n))
+
iftrue=!!iftrue;
+
if(
(flags & DO_POP) &&
node_is_tossable(n))
{
-
if(
node_is_true(n))
+
int t,f;
+
t=!!
node_is_true(n)
;
+
f=!!node_is_false(n
)
;
+
if(t || f)
{
-
do_jump(F_BRANCH,
j
);
+
if(t == iftrue)
do_jump(F_BRANCH,
label
);
return; }
-
-
if(node_is_false(n))
-
return;
+
} switch(n->token) {
-
case F_APPLY:
-
if(is_efun(CAR(n), f_not))
-
{
-
do_jump_when_zero(CDR(n), j);
-
return;
-
}
-
break;
-
-
case F_NOT:
-
do_jump_when_zero(CAR(n), j);
-
return;
-
+
case F_LAND:
-
+
case F_LOR:
+
if(iftrue == (n->token==F_LAND))
{ int tmp=alloc_label();
-
do_
jump
_
when_zero
(CAR(n), tmp);
-
do_
jump
_
when_non_zero
(CDR(n),
j
);
+
do_
cond_
jump(CAR(n), tmp
, !iftrue, flags | DO_POP
);
+
do_
cond_
jump(CDR(n),
label, iftrue, flags
);
emit(F_LABEL,tmp);
-
return
;
+
}else{
+
do_cond_jump(CAR(n), label, iftrue, flags)
;
+
do_cond_jump(CDR(n), label, iftrue, flags);
}
-
-
case F_LOR:
-
do_jump_when_non_zero(CAR(n), j);
-
do_jump_when_non_zero(CDR(n), j);
+
return;
-
}
+
-
if(do_docode(n, DO_NOT_COPY)!=1)
-
fatal("Infernal compiler skiterror.\n");
-
do_jump(F_BRANCH_WHEN_NON_ZERO,j);
-
}
-
-
void do_jump_when_zero(node *n,int j)
-
{
-
if(!node_is_tossable(n))
-
{
-
if(node_is_true(n))
-
return;
-
-
if(node_is_false(n))
-
{
-
do_jump(F_BRANCH,j);
-
return;
-
}
-
}
-
-
switch(n->token)
-
{
+
case F_APPLY:
-
if(is_efun(CAR(n), f_not))
-
{
-
do_jump_when_non_zero(CDR(n), j);
-
return;
-
}
-
break;
+
if(
!
is_efun(CAR(n), f_not)) break;
case F_NOT:
-
do_
jump
_
when_non_zero
(
CAR
(n),
j
);
+
if(!(flags & DO_POP)) break;
+
do_
cond_
jump(
CDR
(n),
label , !iftrue, flags | DO_NOT_COPY
);
return;
-
+
}
-
case
F
_
LOR:
+
if(do_docode(n,
flags&DO
_
NOT_COPY)!=1)
+
fatal("Infernal compiler skiterror.\n");
+
+
if(flags & DO_POP)
{
-
int tmp=alloc_label
()
;
-
do_jump_
when
_
non
_
zero(CAR(n)
,
tmp
);
-
do_jump_
when
_
zero(CDR(n)
,
j
);
-
emit
(F_
LABEL
,
tmp
);
-
return
;
+
if
(
iftrue
)
+
do_jump
(F
_
BRANCH
_
WHEN
_
NON_ZERO
,
label
);
+
else
+
do_jump
(F
_
BRANCH
_
WHEN_ZERO
,
label
);
+
}else{
+
if
(
iftrue)
+
do_jump(
F_
LOR
,
label
);
+
else
+
do_jump(F_LAND, label)
;
}
-
-
case F_LAND:
-
do_jump_when_zero(CAR(n), j);
-
do_jump_when_zero(CDR(n), j);
-
return;
+
}
-
if(
do_
docode
(
n
, DO_NOT_COPY)
!=1)
-
fatal
(
"Infernal compiler skiterror.\n"
)
;
-
do_jump(
F
_
BRANCH
_
WHEN
_
ZERO,j
)
;
-
}
+
#define
do_jump_when_zero(N,L)
do_
cond_jump
(
N
,
L,0,
DO_
POP|DO_
NOT_COPY)
+
#define
do_jump_when_non_zero
(
N,L
) do_
cond_
jump(
N,L,1,DO
_
POP|DO
_
NOT
_
COPY
)
static INT32 count_cases(node *n) { INT32 ret; if(!n) return 0; switch(n->token) { case F_DO: case F_FOR: case F_FOREACH:
pike.git/src/docode.c:496:
tmp1=do_docode(CDR(n),DO_LVALUE); if(do_docode(CAR(n),0)!=1) yyerror("RHS is void!"); emit2(flags & DO_POP ? F_ASSIGN_AND_POP:F_ASSIGN); break; } return flags & DO_POP ? 0 : 1; } case F_LAND: case F_LOR:
-
if(do
_
docode
(
CAR(n
)
,0)!=1)
-
fatal("Compiler internal error.\n")
;
-
tmp1=
do_jump(n->token,
-1
);
-
if(do_docode(CDR(n),0)!=1)
-
fatal("Compiler internal error.\n");
+
tmp1=alloc
_
label
();
+
do_
cond_
jump(
CAR(
n
), tmp1, n
->token
== F_LOR
,
0
);
+
if(do_docode(CDR(n),0)!=1) fatal("Compiler internal error.\n");
emit(F_LABEL,tmp1); return 1; case F_EQ: case F_NE: case F_ADD: case F_LT: case F_LE: case F_GT: case F_GE: