cb22561995-10-11Fredrik Hübinette (Hubbe) /*\
06983f1996-09-22Fredrik Hübinette (Hubbe) ||| This file a part of Pike, and is copyright by Fredrik Hubinette ||| Pike is distributed as GPL (General Public License)
cb22561995-10-11Fredrik Hübinette (Hubbe) ||| See the files COPYING and DISCLAIMER for more information. \*/
d0844b1999-09-19Henrik Grubbström (Grubba) /**/
f90e541995-08-17Fredrik Hübinette (Hubbe) #include "global.h"
6fd5172000-04-25Fredrik Hübinette (Hubbe) RCSID("$Id: docode.c,v 1.69 2000/04/25 09:32:45 hubbe Exp $");
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "las.h" #include "program.h" #include "language.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "pike_types.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "stralloc.h" #include "interpret.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "constants.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "array.h"
bb55f81997-03-16Fredrik Hübinette (Hubbe) #include "pike_macros.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "error.h"
d3fa6e1998-05-17Henrik Grubbström (Grubba) #include "pike_memory.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "svalue.h" #include "main.h" #include "lex.h"
06983f1996-09-22Fredrik Hübinette (Hubbe) #include "builtin_functions.h"
7a82f91996-04-13Fredrik Hübinette (Hubbe) #include "peep.h" #include "docode.h"
419fab1997-03-09Fredrik Hübinette (Hubbe) #include "operators.h"
6d22541998-01-28Fredrik Hübinette (Hubbe) #include "object.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
b079181998-04-27Fredrik Hübinette (Hubbe) static int do_docode2(node *n,int flags);
7a82f91996-04-13Fredrik Hübinette (Hubbe) INT32 current_break=-1; INT32 current_continue=-1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  static INT32 current_switch_case; static INT32 current_switch_default; static INT32 current_switch_values_on_stack; static INT32 *current_switch_jumptable =0;
7670902000-01-04Henrik Grubbström (Grubba) static struct pike_string *current_switch_type = NULL;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7a82f91996-04-13Fredrik Hübinette (Hubbe) void upd_int(int offset, INT32 tmp)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  MEMCPY(new_program->program+offset, (char *)&tmp,sizeof(tmp));
5267b71995-08-09Fredrik Hübinette (Hubbe) }
7a82f91996-04-13Fredrik Hübinette (Hubbe) INT32 read_int(int offset)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  return EXTRACT_INT(new_program->program+offset);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
7a82f91996-04-13Fredrik Hübinette (Hubbe) int store_linenumbers=1; static int label_no=0;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
be478c1997-08-30Henrik Grubbström (Grubba) int alloc_label(void) { return ++label_no; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a7622c1996-08-06Fredrik Hübinette (Hubbe) int do_jump(int token,INT32 lbl)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
7a82f91996-04-13Fredrik Hübinette (Hubbe)  if(lbl==-1) lbl=alloc_label();
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(token, lbl);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  return lbl;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
7a82f91996-04-13Fredrik Hübinette (Hubbe) #define ins_label(L) do_jump(F_LABEL, L)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a7622c1996-08-06Fredrik Hübinette (Hubbe) void do_pop(int x)
7a82f91996-04-13Fredrik Hübinette (Hubbe) { switch(x)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
7a82f91996-04-13Fredrik Hübinette (Hubbe)  case 0: return;
a96ce92000-04-19Fredrik Hübinette (Hubbe)  case 1: emit0(F_POP_VALUE); break; default: emit1(F_POP_N_ELEMS,x); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
66d51c1997-03-04Fredrik Hübinette (Hubbe) 
bdf5eb2000-03-07Fredrik Hübinette (Hubbe) #define DO_CODE_BLOCK(X) do_pop(do_docode((X),DO_NOT_COPY | DO_POP | DO_DEFER_POP))
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) int do_docode(node *n,INT16 flags)
5267b71995-08-09Fredrik Hübinette (Hubbe) { int i;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  int save_current_line=lex.current_line;
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!n) return 0;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  lex.current_line=n->line_number;
a2d5581999-11-11Henrik Grubbström (Grubba)  i=do_docode2(check_node_hash(n), flags);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  lex.current_line=save_current_line;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return i; }
419fab1997-03-09Fredrik Hübinette (Hubbe) 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; }
c64e8a1997-04-17Fredrik Hübinette (Hubbe) static void code_expression(node *n, int flags, char *err) {
a2d5581999-11-11Henrik Grubbström (Grubba)  switch(do_docode(check_node_hash(n), flags & ~ DO_POP))
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  { case 0: my_yyerror("Void expression for %s",err); case 1: return; case 2: fatal("Internal compiler error (%s), line %ld, file %s\n", err,
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  (long)lex.current_line, lex.current_file?lex.current_file->str:"Unknown");
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  } }
2d12341997-03-10Fredrik Hübinette (Hubbe) void do_cond_jump(node *n, int label, int iftrue, int flags)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
2d12341997-03-10Fredrik Hübinette (Hubbe)  iftrue=!!iftrue; if((flags & DO_POP) && node_is_tossable(n))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
2d12341997-03-10Fredrik Hübinette (Hubbe)  int t,f; t=!!node_is_true(n); f=!!node_is_false(n); if(t || f)
a7622c1996-08-06Fredrik Hübinette (Hubbe)  {
2d12341997-03-10Fredrik Hübinette (Hubbe)  if(t == iftrue) do_jump(F_BRANCH, label);
a7622c1996-08-06Fredrik Hübinette (Hubbe)  return; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
a7622c1996-08-06Fredrik Hübinette (Hubbe)  switch(n->token) {
419fab1997-03-09Fredrik Hübinette (Hubbe)  case F_LAND: case F_LOR:
2d12341997-03-10Fredrik Hübinette (Hubbe)  if(iftrue == (n->token==F_LAND))
a7622c1996-08-06Fredrik Hübinette (Hubbe)  {
2d12341997-03-10Fredrik Hübinette (Hubbe)  int tmp=alloc_label(); do_cond_jump(CAR(n), tmp, !iftrue, flags | DO_POP); do_cond_jump(CDR(n), label, iftrue, flags);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL,tmp);
2d12341997-03-10Fredrik Hübinette (Hubbe)  }else{ do_cond_jump(CAR(n), label, iftrue, flags); do_cond_jump(CDR(n), label, iftrue, flags);
a7622c1996-08-06Fredrik Hübinette (Hubbe)  }
2d12341997-03-10Fredrik Hübinette (Hubbe)  return;
419fab1997-03-09Fredrik Hübinette (Hubbe)  case F_APPLY:
2d12341997-03-10Fredrik Hübinette (Hubbe)  if(!is_efun(CAR(n), f_not)) break;
419fab1997-03-09Fredrik Hübinette (Hubbe) 
a7622c1996-08-06Fredrik Hübinette (Hubbe)  case F_NOT:
2d12341997-03-10Fredrik Hübinette (Hubbe)  if(!(flags & DO_POP)) break; do_cond_jump(CDR(n), label , !iftrue, flags | DO_NOT_COPY);
a7622c1996-08-06Fredrik Hübinette (Hubbe)  return; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(n, flags | DO_NOT_COPY, "condition");
2d12341997-03-10Fredrik Hübinette (Hubbe)  if(flags & DO_POP) { 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); }
5267b71995-08-09Fredrik Hübinette (Hubbe) }
2d12341997-03-10Fredrik Hübinette (Hubbe) #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)
5267b71995-08-09Fredrik Hübinette (Hubbe) static INT32 count_cases(node *n) { INT32 ret; if(!n) return 0; switch(n->token) { case F_DO: case F_FOR: case F_FOREACH: case F_INC_LOOP: case F_DEC_LOOP: case F_INC_NEQ_LOOP: case F_DEC_NEQ_LOOP: case F_SWITCH: case '?': return 0; case F_CASE: return !!CAR(n)+!!CDR(n); default: ret=0; if(car_is_node(n)) ret += count_cases(CAR(n)); if(cdr_is_node(n)) ret += count_cases(CDR(n)); return ret; } }
4218011999-01-31Fredrik Hübinette (Hubbe) static inline struct compiler_frame *find_local_frame(INT32 depth) { struct compiler_frame *f=compiler_frame; while(--depth>=0) f=f->previous; return f; }
6fd5172000-04-25Fredrik Hübinette (Hubbe) int do_lfun_call(int id,node *args) { #if 1 if(id == compiler_frame->current_function_number) { if(new_program->identifier_references[id].id_flags & ID_INLINE) { int n=count_args(args); if(n == count_arguments(ID_FROM_INT(new_program, id) -> type)) { emit0(F_MARK); do_docode(args,0); emit1(F_RECUR,0); /* 0 is label at beginning of function */ return 1; } } } #endif emit0(F_MARK); do_docode(args,0); emit1(F_CALL_LFUN, id); return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe) static int do_docode2(node *n,int flags) { INT32 tmp1,tmp2,tmp3; if(!n) return 0; if(flags & DO_LVALUE) { switch(n->token) {
2a32691998-01-31Fredrik Hübinette (Hubbe)  default: yyerror("Illegal lvalue.");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,0); emit1(F_NUMBER,0);
fb05b61998-02-27Fredrik Hübinette (Hubbe)  return 2;
19aaeb1998-05-25Fredrik Hübinette (Hubbe) 
2a32691998-01-31Fredrik Hübinette (Hubbe)  case F_ARRAY_LVALUE: case F_LVALUE_LIST: case F_LOCAL: case F_GLOBAL: case F_IDENTIFIER: case F_INDEX: case F_ARROW: case F_ARG_LIST:
3d78821999-11-06Henrik Grubbström (Grubba)  case F_COMMA_EXPR:
2a32691998-01-31Fredrik Hübinette (Hubbe)  case F_EXTERNAL:
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  break; } } if(flags & DO_LVALUE_IF_POSSIBLE) { flags|=DO_INDIRECT; flags &=~DO_LVALUE_IF_POSSIBLE; }else{ flags &=~DO_INDIRECT;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
f9abcf1999-09-16Fredrik Hübinette (Hubbe)  /* Stack check */ { long x_= ((char *)&x_) + STACK_DIRECTION * (32768) - stack_top ; x_*=STACK_DIRECTION; if(x_>0) {
d0844b1999-09-19Henrik Grubbström (Grubba)  yyerror("Too deep recursion in compiler. (please report this)");
f9abcf1999-09-16Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,0);
f9abcf1999-09-16Fredrik Hübinette (Hubbe)  if(flags & DO_LVALUE) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,0);
f9abcf1999-09-16Fredrik Hübinette (Hubbe)  return 2; } return 1; } }
5267b71995-08-09Fredrik Hübinette (Hubbe)  switch(n->token) {
624f571999-03-11Fredrik Hübinette (Hubbe)  case F_MAGIC_INDEX: case F_MAGIC_SET_INDEX:
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit2(n->token, n->u.node.b->u.sval.u.integer, n->u.node.a->u.sval.u.integer);
624f571999-03-11Fredrik Hübinette (Hubbe)  return 1;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  case F_EXTERNAL:
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit2(F_EXTERNAL_LVALUE, n->u.integer.b,n->u.integer.a);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  return 2; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit2(F_EXTERNAL, n->u.integer.b,n->u.integer.a);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  return 1; } break; case F_UNDEFINED: yyerror("Undefined identifier");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,0);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_PUSH_ARRAY:
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CAR(n), 0, "`@");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_PUSH_ARRAY);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return -0x7ffffff; case '?': {
2e4e451997-02-13Fredrik Hübinette (Hubbe)  INT32 *prev_switch_jumptable = current_switch_jumptable;
9d61521996-08-03Fredrik Hübinette (Hubbe)  int adroppings , bdroppings;
2e4e451997-02-13Fredrik Hübinette (Hubbe)  current_switch_jumptable=0;
9d61521996-08-03Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!CDDR(n)) {
a7622c1996-08-06Fredrik Hübinette (Hubbe)  tmp1=alloc_label(); do_jump_when_zero(CAR(n), tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CADR(n));
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL, tmp1);
2e4e451997-02-13Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } if(!CADR(n)) {
a7622c1996-08-06Fredrik Hübinette (Hubbe)  tmp1=alloc_label(); do_jump_when_non_zero(CAR(n), tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDDR(n));
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL,tmp1);
2e4e451997-02-13Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }
a7622c1996-08-06Fredrik Hübinette (Hubbe)  tmp1=alloc_label(); do_jump_when_zero(CAR(n),tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9d61521996-08-03Fredrik Hübinette (Hubbe)  adroppings=do_docode(CADR(n), flags);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  tmp3=emit1(F_POP_N_ELEMS,0);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9d61521996-08-03Fredrik Hübinette (Hubbe)  /* Else */ tmp2=do_jump(F_BRANCH,-1);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL, tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9d61521996-08-03Fredrik Hübinette (Hubbe)  bdroppings=do_docode(CDDR(n), flags); if(adroppings < bdroppings) { do_pop(bdroppings - adroppings); }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9d61521996-08-03Fredrik Hübinette (Hubbe)  if(adroppings > bdroppings) { update_arg(tmp3,adroppings-bdroppings); adroppings=bdroppings; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL, tmp2);
2e4e451997-02-13Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
9d61521996-08-03Fredrik Hübinette (Hubbe)  return adroppings;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } case F_AND_EQ: case F_OR_EQ: case F_XOR_EQ: case F_LSH_EQ: case F_RSH_EQ: case F_ADD_EQ: case F_SUB_EQ: case F_MULT_EQ: case F_MOD_EQ: case F_DIV_EQ: tmp1=do_docode(CAR(n),DO_LVALUE);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(tmp1 != 2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fatal("HELP! FATAL INTERNAL COMPILER ERROR (7)\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
f53bab1997-01-26Fredrik Hübinette (Hubbe)  if(match_types(CAR(n)->type,array_type_string) ||
ee37801999-02-09Fredrik Hübinette (Hubbe)  match_types(CAR(n)->type,string_type_string) || match_types(CAR(n)->type,object_type_string))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CDR(n), 0, "assignment");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_LTOSVAL2);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_LTOSVAL);
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CDR(n), 0, "assignment");
5267b71995-08-09Fredrik Hübinette (Hubbe)  } switch(n->token) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  case F_ADD_EQ: emit0(F_ADD); break; case F_AND_EQ: emit0(F_AND); break; case F_OR_EQ: emit0(F_OR); break; case F_XOR_EQ: emit0(F_XOR); break; case F_LSH_EQ: emit0(F_LSH); break; case F_RSH_EQ: emit0(F_RSH); break; case F_SUB_EQ: emit0(F_SUBTRACT); break; case F_MULT_EQ:emit0(F_MULTIPLY);break; case F_MOD_EQ: emit0(F_MOD); break; case F_DIV_EQ: emit0(F_DIVIDE); break;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } if(flags & DO_POP) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_ASSIGN_AND_POP);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_ASSIGN);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } case F_ASSIGN: switch(CAR(n)->token) { case F_AND: case F_OR: case F_XOR: case F_LSH: case F_RSH: case F_ADD: case F_MOD: case F_SUBTRACT: case F_DIVIDE: case F_MULTIPLY: if(node_is_eq(CDR(n),CAAR(n))) { tmp1=do_docode(CDR(n),DO_LVALUE);
f53bab1997-01-26Fredrik Hübinette (Hubbe)  if(match_types(CDR(n)->type,array_type_string) || match_types(CDR(n)->type,string_type_string))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CDAR(n), 0, "binary operand");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_LTOSVAL2);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_LTOSVAL);
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CDAR(n), 0, "binary operand");
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(CAR(n)->token);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(n->token);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return n->token==F_ASSIGN; } default: switch(CDR(n)->token) { case F_LOCAL:
4218011999-01-31Fredrik Hübinette (Hubbe)  if(CDR(n)->u.integer.a >= find_local_frame(CDR(n)->u.integer.b)->max_number_of_locals)
a8ef6e1996-12-03Fredrik Hübinette (Hubbe)  yyerror("Illegal to use local variable here.");
4218011999-01-31Fredrik Hübinette (Hubbe)  if(CDR(n)->u.integer.b) goto normal_assign;
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CAR(n), 0, "RHS");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(flags & DO_POP ? F_ASSIGN_LOCAL_AND_POP:F_ASSIGN_LOCAL,
4218011999-01-31Fredrik Hübinette (Hubbe)  CDR(n)->u.integer.a );
5267b71995-08-09Fredrik Hübinette (Hubbe)  break;
06983f1996-09-22Fredrik Hübinette (Hubbe)  case F_IDENTIFIER:
a2d5581999-11-11Henrik Grubbström (Grubba)  if(!IDENTIFIER_IS_VARIABLE( ID_FROM_INT(new_program, CDR(n)->u.id.number)->identifier_flags))
06983f1996-09-22Fredrik Hübinette (Hubbe)  {
d2c6081996-11-07Fredrik Hübinette (Hubbe)  yyerror("Cannot assign functions or constants.\n");
06983f1996-09-22Fredrik Hübinette (Hubbe)  }else{
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CAR(n), 0, "RHS");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(flags & DO_POP ? F_ASSIGN_GLOBAL_AND_POP:F_ASSIGN_GLOBAL,
a2d5581999-11-11Henrik Grubbström (Grubba)  CDR(n)->u.id.number);
06983f1996-09-22Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; default:
4218011999-01-31Fredrik Hübinette (Hubbe)  normal_assign:
06983f1996-09-22Fredrik Hübinette (Hubbe)  tmp1=do_docode(CDR(n),DO_LVALUE); if(do_docode(CAR(n),0)!=1) yyerror("RHS is void!");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(flags & DO_POP ? F_ASSIGN_AND_POP:F_ASSIGN);
5267b71995-08-09Fredrik Hübinette (Hubbe)  break; } return flags & DO_POP ? 0 : 1; } case F_LAND: case F_LOR:
2d12341997-03-10Fredrik Hübinette (Hubbe)  tmp1=alloc_label(); do_cond_jump(CAR(n), tmp1, n->token == F_LOR, 0);
e205e01998-07-30Fredrik Hübinette (Hubbe)  code_expression(CDR(n), flags, n->token == F_LOR ? "||" : "&&");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL,tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; case F_EQ: case F_NE: case F_ADD: case F_LT: case F_LE: case F_GT: case F_GE: case F_SUBTRACT: case F_MULTIPLY: case F_DIVIDE: case F_MOD: case F_LSH: case F_RSH: case F_XOR: case F_OR: case F_AND:
6930181996-02-25Fredrik Hübinette (Hubbe)  case F_NOT: case F_COMPL: case F_NEGATE:
d103cb1998-01-30Fredrik Hübinette (Hubbe)  fatal("Optimizer error.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_RANGE: tmp1=do_docode(CAR(n),DO_NOT_COPY); if(do_docode(CDR(n),DO_NOT_COPY)!=2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fatal("Compiler internal error (at %ld).\n",(long)lex.current_line);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(n->token);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return tmp1; case F_INC: case F_POST_INC: tmp1=do_docode(CAR(n),DO_LVALUE);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(tmp1 != 2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif if(flags & DO_POP) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_INC_AND_POP);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(n->token);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } case F_DEC: case F_POST_DEC: tmp1=do_docode(CAR(n),DO_LVALUE);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(tmp1 != 2)
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  fatal("HELP! FATAL INTERNAL COMPILER ERROR (2)\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif if(flags & DO_POP) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_DEC_AND_POP);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(n->token);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } case F_FOR: { INT32 *prev_switch_jumptable = current_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  INT32 break_save = current_break; INT32 continue_save = current_continue;
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable=0;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=alloc_label(); current_continue=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(CDR(n)) {
9d61521996-08-03Fredrik Hübinette (Hubbe)  do_jump_when_zero(CAR(n),current_break);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp2=ins_label(-1);
9d61521996-08-03Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CADR(n));
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_continue);
9d61521996-08-03Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDDR(n));
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
9d61521996-08-03Fredrik Hübinette (Hubbe)  tmp2=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } do_jump_when_non_zero(CAR(n),tmp2);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_break);
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=break_save; current_continue=continue_save;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } case ' ': return do_docode(CAR(n),0)+do_docode(CDR(n),DO_LVALUE); case F_FOREACH: {
a982301999-04-30Fredrik Hübinette (Hubbe)  node *arr;
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 *prev_switch_jumptable = current_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  INT32 break_save = current_break; INT32 continue_save = current_continue;
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable=0;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=alloc_label(); current_continue=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a982301999-04-30Fredrik Hübinette (Hubbe)  arr=CAR(n); if(arr->token==F_RANGE) {
a2d5581999-11-11Henrik Grubbström (Grubba)  node **a1=my_get_arg(&_CDR(n),0); node **a2=my_get_arg(&_CDR(n),1);
a982301999-04-30Fredrik Hübinette (Hubbe)  if(a1 && a2 && a2[0]->token==F_CONSTANT && a2[0]->u.sval.type==T_INT && a2[0]->u.sval.type==0x7fffffff && a1[0]->type == int_type_string) { tmp2=do_docode(CAR(arr),DO_NOT_COPY);
dc731d1999-06-19Fredrik Hübinette (Hubbe)  do_docode(*a1,DO_NOT_COPY);
a982301999-04-30Fredrik Hübinette (Hubbe)  goto foreach_arg_pushed; } }
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp2=do_docode(CAR(n),DO_NOT_COPY);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_CONST0);
a982301999-04-30Fredrik Hübinette (Hubbe)  foreach_arg_pushed:
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fe574a1998-11-16Fredrik Hübinette (Hubbe)  /* This is really ugly because there is always a chance that the bug * will disappear when new instructions are added to the code, but * think it is worth it. */ if(d_flag)
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_MARK);
fe574a1998-11-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp3=do_jump(F_BRANCH,-1);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp1=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDR(n));
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_continue);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL,tmp3);
5267b71995-08-09Fredrik Hübinette (Hubbe)  do_jump(n->token,tmp1);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_break);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fe574a1998-11-16Fredrik Hübinette (Hubbe)  if(d_flag)
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_POP_MARK);
fe574a1998-11-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=break_save; current_continue=continue_save;
f1c4941996-12-01Fredrik Hübinette (Hubbe)  do_pop(4);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } case F_INC_NEQ_LOOP: case F_DEC_NEQ_LOOP: case F_INC_LOOP: case F_DEC_LOOP: { INT32 *prev_switch_jumptable = current_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  INT32 break_save = current_break; INT32 continue_save = current_continue;
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable=0;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=alloc_label(); current_continue=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp2=do_docode(CAR(n),0);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fe574a1998-11-16Fredrik Hübinette (Hubbe)  /* This is really ugly because there is always a chance that the bug * will disappear when new instructions are added to the code, but * think it is worth it. */ if(d_flag)
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_MARK);
fe574a1998-11-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp3=do_jump(F_BRANCH,-1);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp1=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDR(n));
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_continue);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL,tmp3);
5267b71995-08-09Fredrik Hübinette (Hubbe)  do_jump(n->token,tmp1);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_break);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fe574a1998-11-16Fredrik Hübinette (Hubbe)  if(d_flag)
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_POP_MARK);
fe574a1998-11-16Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=break_save; current_continue=continue_save;
f1c4941996-12-01Fredrik Hübinette (Hubbe)  do_pop(3);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } case F_DO: { INT32 *prev_switch_jumptable = current_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  INT32 break_save = current_break; INT32 continue_save = current_continue;
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable=0;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=alloc_label(); current_continue=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp2=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CAR(n));
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_continue);
5267b71995-08-09Fredrik Hübinette (Hubbe)  do_jump_when_non_zero(CDR(n),tmp2);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_break);
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=break_save; current_continue=continue_save;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }
176d621999-11-18Henrik Grubbström (Grubba)  case F_POP_VALUE: { DO_CODE_BLOCK(CAR(n)); return 0; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_CAST: if(n->type==void_type_string) { DO_CODE_BLOCK(CAR(n)); return 0; }
98f2b11998-02-19Fredrik Hübinette (Hubbe)  tmp1=store_prog_string(n->type);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_STRING,tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),0);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  if(!tmp1) { emit0(F_CONST0); tmp1=1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(tmp1>1) do_pop(tmp1-1);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_CAST);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1;
1d480f1999-11-23Henrik Grubbström (Grubba)  case F_SOFT_CAST:
7d955e1999-12-13Henrik Grubbström (Grubba)  if (runtime_options & RUNTIME_CHECK_TYPES) {
dad12d1999-11-25Henrik Grubbström (Grubba)  tmp1 = store_prog_string(n->type);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_STRING, tmp1);
dad12d1999-11-25Henrik Grubbström (Grubba)  tmp1 = do_docode(CAR(n), 0);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  if (!tmp1) { emit0(F_CONST0); tmp1 = 1; }
dad12d1999-11-25Henrik Grubbström (Grubba)  if (tmp1 > 1) do_pop(tmp1 - 1);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_SOFT_CAST);
dad12d1999-11-25Henrik Grubbström (Grubba)  return 1; } tmp1 = do_docode(CAR(n), flags); if (tmp1 > 1) do_pop(tmp1 - 1); return !!tmp1;
1d480f1999-11-23Henrik Grubbström (Grubba) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_APPLY: if(CAR(n)->token == F_CONSTANT) {
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  if(CAR(n)->u.sval.type == T_FUNCTION)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
bdb5091996-09-25Fredrik Hübinette (Hubbe)  if(CAR(n)->u.sval.subtype == FUNCTION_BUILTIN) /* driver fun? */
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  { if(!CAR(n)->u.sval.u.efun->docode || !CAR(n)->u.sval.u.efun->docode(n)) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_MARK);
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  do_docode(CDR(n),0); tmp1=store_constant(& CAR(n)->u.sval,
454d541999-09-18Fredrik Hübinette (Hubbe)  !(CAR(n)->tree_info & OPT_EXTERNAL_DEPEND), CAR(n)->name);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_APPLY,tmp1);
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  }
044c621999-04-14Fredrik Hübinette (Hubbe)  if(n->type == void_type_string) return 0;
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  return 1; }else{
9e52381998-03-01Fredrik Hübinette (Hubbe)  if(CAR(n)->u.sval.u.object == fake_object)
6fd5172000-04-25Fredrik Hübinette (Hubbe)  return do_lfun_call(CAR(n)->u.sval.subtype,CDR(n));
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_MARK);
7bd0ea1996-02-19Fredrik Hübinette (Hubbe)  do_docode(CDR(n),0); tmp1=store_constant(& CAR(n)->u.sval,
454d541999-09-18Fredrik Hübinette (Hubbe)  !(CAR(n)->tree_info & OPT_EXTERNAL_DEPEND), CAR(n)->name);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_APPLY,tmp1);
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } else if(CAR(n)->token == F_IDENTIFIER &&
6fd5172000-04-25Fredrik Hübinette (Hubbe)  IDENTIFIER_IS_FUNCTION(ID_FROM_INT(new_program, CAR(n)->u.id.number)->identifier_flags))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
6fd5172000-04-25Fredrik Hübinette (Hubbe)  return do_lfun_call(CAR(n)->u.id.number,CDR(n));
5267b71995-08-09Fredrik Hübinette (Hubbe)  } else {
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *tmp;
5267b71995-08-09Fredrik Hübinette (Hubbe)  struct efun *fun;
f53bab1997-01-26Fredrik Hübinette (Hubbe)  node *foo;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_MARK);
5267b71995-08-09Fredrik Hübinette (Hubbe)  do_docode(CAR(n),0); do_docode(CDR(n),0);
f53bab1997-01-26Fredrik Hübinette (Hubbe)  tmp=findstring("call_function"); if(!tmp) yyerror("No call_function efun.");
2816052000-03-30Fredrik Hübinette (Hubbe)  foo=find_module_identifier(tmp,0);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  if(!foo || !foo->token==F_CONSTANT)
f53bab1997-01-26Fredrik Hübinette (Hubbe)  { yyerror("No call_function efun."); }else{
d103cb1998-01-30Fredrik Hübinette (Hubbe)  if(foo->u.sval.type == T_FUNCTION && foo->u.sval.subtype == FUNCTION_BUILTIN && foo->u.sval.u.efun->function == f_call_function) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_CALL_FUNCTION);
d103cb1998-01-30Fredrik Hübinette (Hubbe)  }else{
454d541999-09-18Fredrik Hübinette (Hubbe)  /* We might want to put "predef::"+foo->name here /Hubbe */ tmp1=store_constant(& foo->u.sval, 1, foo->name);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_APPLY, tmp1);
d103cb1998-01-30Fredrik Hübinette (Hubbe)  }
f53bab1997-01-26Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  free_node(foo);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } case F_ARG_LIST:
bdf5eb2000-03-07Fredrik Hübinette (Hubbe)  case F_COMMA_EXPR:
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),flags & ~WANT_LVALUE);
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp1+=do_docode(CDR(n),flags); return tmp1; /* Switch: * So far all switches are implemented with a binsearch lookup. * It stores the case values in the programs area for constants. * It also has a jump-table in the program itself, for every index in * the array of cases, there is 2 indexes in the jumptable, and one extra. * The first entry in the jumptable is used if you call switch with * a value that is ranked lower than all the indexes in the array of * cases. (Ranked by the binsearch that is) The second is used if it * is equal to the first index. The third if it is greater than the * first, but lesser than the second. The fourth if it is equal to * the second.... etc. etc. */ case F_SWITCH: { INT32 e,cases,*order; INT32 *jumptable; INT32 prev_switch_values_on_stack = current_switch_values_on_stack; INT32 prev_switch_case = current_switch_case; INT32 prev_switch_default = current_switch_default; INT32 *prev_switch_jumptable = current_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  INT32 break_save = current_break;
7670902000-01-04Henrik Grubbström (Grubba)  struct pike_string *prev_switch_type = current_switch_type;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
7af7d21997-08-03Fredrik Hübinette (Hubbe)  struct svalue *save_sp=sp; #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(do_docode(CAR(n),0)!=1) fatal("Internal compiler error, time to panic\n");
7670902000-01-04Henrik Grubbström (Grubba)  if (!(CAR(n) && (current_switch_type = CAR(n)->type))) { current_switch_type = mixed_type_string; }
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe)  cases=count_cases(CDR(n));
a96ce92000-04-19Fredrik Hübinette (Hubbe)  tmp1=emit1(F_SWITCH,0); emit1(F_ALIGN,sizeof(INT32));
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_values_on_stack=0;
4399511998-01-28Fredrik Hübinette (Hubbe)  current_switch_case=1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_default=-1;
52fcc81998-01-28Fredrik Hübinette (Hubbe)  current_switch_jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2)); jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2));
5267b71995-08-09Fredrik Hübinette (Hubbe) 
52fcc81998-01-28Fredrik Hübinette (Hubbe)  for(e=1; e<cases*2+2; e++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  jumptable[e]=emit1(F_POINTER, 0);
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable[e]=-1; } current_switch_jumptable[current_switch_case++]=-1; DO_CODE_BLOCK(CDR(n));
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
7af7d21997-08-03Fredrik Hübinette (Hubbe)  if(sp-save_sp != cases) fatal("Count cases is wrong!\n"); #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  f_aggregate(cases); order=get_switch_order(sp[-1].u.array);
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
7c95f12000-01-04Henrik Grubbström (Grubba)  if (!num_parse_error) { /* Check for cases inside a range */ for(e=0; e<cases-1; e++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
7c95f12000-01-04Henrik Grubbström (Grubba)  if(order[e] < cases-1)
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  {
7c95f12000-01-04Henrik Grubbström (Grubba)  int o1=order[e]*2+2; if(current_switch_jumptable[o1]==current_switch_jumptable[o1+1] && current_switch_jumptable[o1]==current_switch_jumptable[o1+2]) { if(order[e]+1 != order[e+1]) yyerror("Case inside range."); e++; }
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
7a82f91996-04-13Fredrik Hübinette (Hubbe)  if(current_switch_default < 0) current_switch_default = ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
52fcc81998-01-28Fredrik Hübinette (Hubbe)  for(e=1;e<cases*2+2;e++)
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(current_switch_jumptable[e]==-1) current_switch_jumptable[e]=current_switch_default;
61e9a01998-01-25Fredrik Hübinette (Hubbe)  order_array(sp[-1].u.array,order);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
52fcc81998-01-28Fredrik Hübinette (Hubbe)  reorder((void *)(current_switch_jumptable+2),cases,sizeof(INT32)*2,order);
5267b71995-08-09Fredrik Hübinette (Hubbe)  free((char *)order);
52fcc81998-01-28Fredrik Hübinette (Hubbe)  for(e=1; e<cases*2+2; e++)
7a82f91996-04-13Fredrik Hübinette (Hubbe)  update_arg(jumptable[e], current_switch_jumptable[e]);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
454d541999-09-18Fredrik Hübinette (Hubbe)  update_arg(tmp1, store_constant(sp-1,1,0));
5267b71995-08-09Fredrik Hübinette (Hubbe)  pop_stack(); free((char *)jumptable); free((char *)current_switch_jumptable); current_switch_jumptable = prev_switch_jumptable; current_switch_default = prev_switch_default; current_switch_case = prev_switch_case;
7670902000-01-04Henrik Grubbström (Grubba)  current_switch_values_on_stack = prev_switch_values_on_stack; current_switch_type = prev_switch_type;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LABEL, current_break);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=break_save;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
7af7d21997-08-03Fredrik Hübinette (Hubbe)  if(recoveries && sp-evaluator_stack < recoveries->sp) fatal("Stack error after F_SWITCH (underflow)\n"); #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } case F_CASE: { if(!current_switch_jumptable) { yyerror("Case outside switch."); }else{
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  node *lower=CAR(n); if(!lower) lower=CDR(n); if(!is_const(lower))
5267b71995-08-09Fredrik Hübinette (Hubbe)  yyerror("Case label isn't constant.");
7670902000-01-04Henrik Grubbström (Grubba)  if (lower && lower->type) { if (!pike_types_le(lower->type, current_switch_type)) { if (!match_types(lower->type, current_switch_type)) { yytype_error("Type mismatch in case.", current_switch_type, lower->type, 0); } else if (lex.pragmas & ID_STRICT_TYPES) { yytype_error("Type mismatch in case.", current_switch_type, lower->type, YYTE_IS_WARNING); } } }
b1bfe22000-01-04Henrik Grubbström (Grubba)  if (!num_parse_error) { tmp1=eval_low(lower); if(tmp1<1) { yyerror("Error in case label."); push_int(0); tmp1=1; } pop_n_elems(tmp1-1); current_switch_values_on_stack++; for(tmp1=current_switch_values_on_stack; tmp1 > 1; tmp1--) if(is_equal(sp-tmp1, sp-1)) yyerror("Duplicate case.");
271a6b2000-01-04Henrik Grubbström (Grubba)  } else { push_int(0); current_switch_values_on_stack++; } current_switch_jumptable[current_switch_case++]=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
271a6b2000-01-04Henrik Grubbström (Grubba)  if(CDR(n)) { current_switch_jumptable[current_switch_case]= current_switch_jumptable[current_switch_case-1]; current_switch_case++;
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
271a6b2000-01-04Henrik Grubbström (Grubba)  if(CAR(n))
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  {
271a6b2000-01-04Henrik Grubbström (Grubba)  if(!is_const(CDR(n))) yyerror("Case label isn't constant.");
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_switch_jumptable[current_switch_case]= current_switch_jumptable[current_switch_case-1];
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  current_switch_case++;
271a6b2000-01-04Henrik Grubbström (Grubba)  if (!num_parse_error) { tmp1=eval_low(CDR(n)); if(tmp1<1) { yyerror("Error in second half of case label."); push_int(0); tmp1=1;
b1bfe22000-01-04Henrik Grubbström (Grubba)  }
271a6b2000-01-04Henrik Grubbström (Grubba)  pop_n_elems(tmp1-1); current_switch_values_on_stack++; for(tmp1=current_switch_values_on_stack; tmp1 > 1; tmp1--) if(is_equal(sp-tmp1, sp-1)) yyerror("Duplicate case."); } else { push_int(0); current_switch_values_on_stack++;
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  } current_switch_jumptable[current_switch_case++]=-1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
271a6b2000-01-04Henrik Grubbström (Grubba)  }else{ current_switch_jumptable[current_switch_case++]=-1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } return 0; } case F_DEFAULT: if(!current_switch_jumptable) { yyerror("Default outside switch."); }else if(current_switch_default!=-1){ yyerror("Duplicate switch default."); }else{
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_switch_default = ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } return 0; case F_BREAK:
7a82f91996-04-13Fredrik Hübinette (Hubbe)  if(current_break == -1)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { yyerror("Break outside loop or switch."); }else{
7a82f91996-04-13Fredrik Hübinette (Hubbe)  do_jump(F_BRANCH, current_break);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } return 0; case F_CONTINUE:
7a82f91996-04-13Fredrik Hübinette (Hubbe)  if(current_continue == -1)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { yyerror("continue outside loop or switch."); }else{
7a82f91996-04-13Fredrik Hübinette (Hubbe)  do_jump(F_BRANCH, current_continue);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } return 0; case F_RETURN:
7a82f91996-04-13Fredrik Hübinette (Hubbe)  do_docode(CAR(n),0);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_RETURN);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; case F_SSCANF: tmp1=do_docode(CAR(n),DO_NOT_COPY); tmp2=do_docode(CDR(n),DO_NOT_COPY | DO_LVALUE);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_SSCANF,tmp1+tmp2);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; case F_CATCH: {
7a82f91996-04-13Fredrik Hübinette (Hubbe)  INT32 break_save = current_break; INT32 continue_save = current_continue;
5267b71995-08-09Fredrik Hübinette (Hubbe)  INT32 *prev_switch_jumptable = current_switch_jumptable;
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable=0;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=alloc_label(); current_continue=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp1=do_jump(F_CATCH,-1); DO_CODE_BLOCK(CAR(n));
7a82f91996-04-13Fredrik Hübinette (Hubbe)  ins_label(current_continue); ins_label(current_break);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_THROW_ZERO);
9d61521996-08-03Fredrik Hübinette (Hubbe)  ins_label(tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7a82f91996-04-13Fredrik Hübinette (Hubbe)  current_break=break_save; current_continue=continue_save;
5267b71995-08-09Fredrik Hübinette (Hubbe)  current_switch_jumptable = prev_switch_jumptable; return 1; } case F_LVALUE_LIST: return do_docode(CAR(n),DO_LVALUE)+do_docode(CDR(n),DO_LVALUE);
2a32691998-01-31Fredrik Hübinette (Hubbe)  case F_ARRAY_LVALUE: tmp1=do_docode(CAR(n),DO_LVALUE);
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
2a32691998-01-31Fredrik Hübinette (Hubbe)  if(tmp1 & 1) fatal("Very internal compiler error.\n"); #endif
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_ARRAY_LVALUE, tmp1>>1);
2a32691998-01-31Fredrik Hübinette (Hubbe)  return 2;
dffa011997-01-15Fredrik Hübinette (Hubbe)  case F_ARROW: if(CDR(n)->token != F_CONSTANT || CDR(n)->u.sval.type!=T_STRING) fatal("Bugg in F_ARROW, index not string.");
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE)
dffa011997-01-15Fredrik Hübinette (Hubbe)  {
9b08a21998-03-31Fredrik Hübinette (Hubbe)  /* FIXME!!!! ??? I wonder what needs fixing... /Hubbe */
dffa011997-01-15Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n), 0);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_ARROW_STRING, store_prog_string(CDR(n)->u.sval.u.string));
dffa011997-01-15Fredrik Hübinette (Hubbe)  return 2; }else{ tmp1=do_docode(CAR(n), DO_NOT_COPY);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_ARROW, store_prog_string(CDR(n)->u.sval.u.string));
dffa011997-01-15Fredrik Hübinette (Hubbe)  if(!(flags & DO_NOT_COPY)) { while(n && (n->token==F_INDEX || n->token==F_ARROW)) n=CAR(n); if(n->token==F_CONSTANT && !(n->node_info & OPT_EXTERNAL_DEPEND))
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_COPY_VALUE);
dffa011997-01-15Fredrik Hübinette (Hubbe)  } } return tmp1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_INDEX:
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  int mklval=CAR(n) && match_types(CAR(n)->type, string_type_string); tmp1=do_docode(CAR(n), mklval ? DO_LVALUE_IF_POSSIBLE : 0); if(tmp1==2) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(!mklval) fatal("Unwanted lvalue!\n"); #endif
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_INDIRECT);
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(do_docode(CDR(n),0) != 1) fatal("Internal compiler error, please report this (1).");
e82b301997-01-29Fredrik Hübinette (Hubbe)  if(CDR(n)->token != F_CONSTANT && match_types(CDR(n)->type, string_type_string))
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_CLEAR_STRING_SUBTYPE);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 2; }else{ tmp1=do_docode(CAR(n), DO_NOT_COPY);
99761f1998-10-09Fredrik Hübinette (Hubbe) 
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CDR(n), DO_NOT_COPY, "index");
99761f1998-10-09Fredrik Hübinette (Hubbe)  if(CDR(n)->token != F_CONSTANT && match_types(CDR(n)->type, string_type_string))
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_CLEAR_STRING_SUBTYPE);
19aaeb1998-05-25Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_INDEX);
19aaeb1998-05-25Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!(flags & DO_NOT_COPY)) {
dffa011997-01-15Fredrik Hübinette (Hubbe)  while(n && (n->token==F_INDEX || n->token==F_ARROW)) n=CAR(n);
5683de1995-11-06Fredrik Hübinette (Hubbe)  if(n->token==F_CONSTANT && !(n->node_info & OPT_EXTERNAL_DEPEND))
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_COPY_VALUE);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } return tmp1; case F_CONSTANT: switch(n->u.sval.type) { case T_INT:
ece3201999-08-02Fredrik Hübinette (Hubbe)  if(!n->u.sval.u.integer && n->u.sval.subtype==NUMBER_UNDEFINED) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_UNDEFINED);
ece3201999-08-02Fredrik Hübinette (Hubbe)  }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,n->u.sval.u.integer);
ece3201999-08-02Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; case T_STRING: tmp1=store_prog_string(n->u.sval.u.string);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_STRING,tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; case T_FUNCTION:
bdb5091996-09-25Fredrik Hübinette (Hubbe)  if(n->u.sval.subtype!=FUNCTION_BUILTIN)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
6d22541998-01-28Fredrik Hübinette (Hubbe)  if(n->u.sval.u.object == fake_object)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LFUN,n->u.sval.subtype);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; }
6d22541998-01-28Fredrik Hübinette (Hubbe)  if(n->u.sval.u.object->next == n->u.sval.u.object) { int x=0; struct object *o; for(o=fake_object->parent;o!=n->u.sval.u.object;o=o->parent) x++;
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit2(F_EXTERNAL, n->u.sval.subtype,x);
0894392000-03-09Fredrik Hübinette (Hubbe)  new_program->flags |= PROGRAM_USES_PARENT;
6d22541998-01-28Fredrik Hübinette (Hubbe)  return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
6d22541998-01-28Fredrik Hübinette (Hubbe) 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
6d22541998-01-28Fredrik Hübinette (Hubbe)  case T_OBJECT: if(n->u.sval.u.object->next == n->u.sval.u.object) fatal("Internal error: Pointer to parent cannot be a compile time constant!\n"); #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  default:
454d541999-09-18Fredrik Hübinette (Hubbe)  tmp1=store_constant(&(n->u.sval), !(n->tree_info & OPT_EXTERNAL_DEPEND), n->name);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_CONSTANT,tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; case T_ARRAY: case T_MAPPING:
06983f1996-09-22Fredrik Hübinette (Hubbe)  case T_MULTISET:
454d541999-09-18Fredrik Hübinette (Hubbe)  tmp1=store_constant(&(n->u.sval), !(n->tree_info & OPT_EXTERNAL_DEPEND), n->name);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_CONSTANT,tmp1);
5683de1995-11-06Fredrik Hübinette (Hubbe)  /* copy now or later ? */ if(!(flags & DO_NOT_COPY) && !(n->tree_info & OPT_EXTERNAL_DEPEND))
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_COPY_VALUE);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } case F_LOCAL:
4218011999-01-31Fredrik Hübinette (Hubbe)  if(n->u.integer.a >= find_local_frame(n->u.integer.b)->max_number_of_locals)
a8ef6e1996-12-03Fredrik Hübinette (Hubbe)  yyerror("Illegal to use local variable here.");
4218011999-01-31Fredrik Hübinette (Hubbe)  if(n->u.integer.b)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
4218011999-01-31Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit2(F_LEXICAL_LOCAL_LVALUE,n->u.id.number,n->u.integer.b);
4218011999-01-31Fredrik Hübinette (Hubbe)  return 2; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit2(F_LEXICAL_LOCAL,n->u.id.number,n->u.integer.b);
4218011999-01-31Fredrik Hübinette (Hubbe)  return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
4218011999-01-31Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE) {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LOCAL_LVALUE,n->u.id.number);
4218011999-01-31Fredrik Hübinette (Hubbe)  return 2; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LOCAL,n->u.id.number);
4218011999-01-31Fredrik Hübinette (Hubbe)  return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
4218011999-01-31Fredrik Hübinette (Hubbe)  case F_TRAMPOLINE:
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_TRAMPOLINE,n->u.id.number);
4218011999-01-31Fredrik Hübinette (Hubbe)  return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_IDENTIFIER:
a2d5581999-11-11Henrik Grubbström (Grubba)  if(IDENTIFIER_IS_FUNCTION(ID_FROM_INT(new_program, n->u.id.number)->identifier_flags))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { yyerror("Cannot assign functions.\n"); }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_LFUN,n->u.id.number);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }else{
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_GLOBAL_LVALUE,n->u.id.number);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 2; }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_GLOBAL,n->u.id.number);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } return 1; case F_VAL_LVAL: return do_docode(CAR(n),flags)+do_docode(CDR(n),flags | DO_LVALUE); default: fatal("Infernal compiler error (unknown parse-tree-token).\n"); return 0; /* make gcc happy */ } } void do_code_block(node *n) {
7a82f91996-04-13Fredrik Hübinette (Hubbe)  init_bytecode();
6fd5172000-04-25Fredrik Hübinette (Hubbe)  label_no=1; emit1(F_LABEL,0);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(n);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  assemble(); } int docode(node *n) { int tmp; int label_no_save = label_no; dynamic_buffer instrbuf_save = instrbuf; instrbuf.s.str=0;
6fd5172000-04-25Fredrik Hübinette (Hubbe)  label_no=1;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  init_bytecode(); tmp=do_docode(n,0); assemble(); instrbuf=instrbuf_save; label_no = label_no_save; return tmp;
5267b71995-08-09Fredrik Hübinette (Hubbe) }