e576bb2002-10-11Martin Nilsson /* || This file is part of Pike. For copyright information see COPYRIGHT. || Pike is distributed under GPL, LGPL and MPL. See the file COPYING || for more information.
1a26b22004-12-30Henrik Grubbström (Grubba) || $Id: docode.c,v 1.183 2004/12/30 13:41:08 grubba Exp $
e576bb2002-10-11Martin Nilsson */
aedfb12002-10-09Martin Nilsson 
f90e541995-08-17Fredrik Hübinette (Hubbe) #include "global.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "las.h" #include "program.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"
b2d3e42000-12-01Fredrik Hübinette (Hubbe) #include "pike_error.h"
d3fa6e1998-05-17Henrik Grubbström (Grubba) #include "pike_memory.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) #include "svalue.h"
1a26b22004-12-30Henrik Grubbström (Grubba) #include "pike_embed.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"
f76b4c2000-05-11Henrik Grubbström (Grubba) #include "opcodes.h" #include "lex.h"
5e44422001-02-25Fredrik Hübinette (Hubbe) #include "mapping.h" #include "multiset.h"
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7e877a2003-04-02Martin Stjernholm static int do_docode2(node *n, int flags);
b079181998-04-27Fredrik Hübinette (Hubbe) 
6c8ada2001-01-14Martin Stjernholm typedef void (*cleanup_func)(void *); struct cleanup_frame { struct cleanup_frame *prev; cleanup_func cleanup; void *cleanup_arg;
7acaf12001-01-15Martin Stjernholm  int stack_depth;
6c8ada2001-01-14Martin Stjernholm };
5a0fd52001-01-10Martin Stjernholm struct statement_label_name { struct statement_label_name *next; struct pike_string *str;
6c8ada2001-01-14Martin Stjernholm  unsigned int line_number;
5a0fd52001-01-10Martin Stjernholm }; struct statement_label { struct statement_label *prev; struct statement_label_name *name;
6c8ada2001-01-14Martin Stjernholm  /* -2 in break_label is used to flag "open" statement_label entries. * If an open entry is on top of the stack, it's used instead of a * new one. That's used to associate statement labels to the * following statement. */
5a0fd52001-01-10Martin Stjernholm  INT32 break_label, continue_label;
6c8ada2001-01-14Martin Stjernholm  int emit_break_label;
7acaf12001-01-15Martin Stjernholm  int stack_depth;
6c8ada2001-01-14Martin Stjernholm  struct cleanup_frame *cleanups;
5a0fd52001-01-10Martin Stjernholm };
6c8ada2001-01-14Martin Stjernholm  static struct statement_label top_statement_label_dummy =
7acaf12001-01-15Martin Stjernholm  {0, 0, -1, -1, 0, -1, 0};
6c8ada2001-01-14Martin Stjernholm static struct statement_label *current_label = &top_statement_label_dummy;
7acaf12001-01-15Martin Stjernholm #ifdef PIKE_DEBUG static int current_stack_depth = -4711; #else static int current_stack_depth = 0; #endif
6c8ada2001-01-14Martin Stjernholm  #define PUSH_CLEANUP_FRAME(func, arg) do { \ struct cleanup_frame cleanup_frame__; \ cleanup_frame__.cleanup = (cleanup_func) (func); \ cleanup_frame__.cleanup_arg = (void *)(ptrdiff_t) (arg); \
7acaf12001-01-15Martin Stjernholm  cleanup_frame__.stack_depth = current_stack_depth; \
6c8ada2001-01-14Martin Stjernholm  DO_IF_DEBUG( \ if (current_label->cleanups == (void *)(ptrdiff_t) -1) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("current_label points to an unused statement_label.\n"); \
6c8ada2001-01-14Martin Stjernholm  ) \ if (current_label->break_label == -2) { \ DO_IF_DEBUG( \ if (current_label->prev->break_label == -2) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Found two open statement_label entries in a row.\n"); \
6c8ada2001-01-14Martin Stjernholm  ) \ cleanup_frame__.prev = current_label->prev->cleanups; \ current_label->prev->cleanups = &cleanup_frame__; \ } \ else { \ cleanup_frame__.prev = current_label->cleanups; \ current_label->cleanups = &cleanup_frame__; \ } #define POP_AND_DONT_CLEANUP \ if (current_label->cleanups == &cleanup_frame__) \ current_label->cleanups = cleanup_frame__.prev; \ else { \ DO_IF_DEBUG( \ if (current_label->prev->cleanups != &cleanup_frame__) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Cleanup frame lost from statement_label cleanup list.\n");\
6c8ada2001-01-14Martin Stjernholm  ) \ current_label->prev->cleanups = cleanup_frame__.prev; \ } \ } while (0) #define POP_AND_DO_CLEANUP \
7acaf12001-01-15Martin Stjernholm  do_pop(current_stack_depth - cleanup_frame__.stack_depth); \
6c8ada2001-01-14Martin Stjernholm  cleanup_frame__.cleanup(cleanup_frame__.cleanup_arg); \ POP_AND_DONT_CLEANUP
5a0fd52001-01-10Martin Stjernholm 
1544fd2001-01-31Martin Stjernholm /* A block in the following sense is a region of code where: * o Execution always enters at the beginning. * o All stack nesting is left intact on exit (both normally and * through jumps, but not through exceptions). This includes the * svalue and mark stacks, and the catch block nesting. */ #ifdef PIKE_DEBUG #define BLOCK_BEGIN \ PUSH_CLEANUP_FRAME(do_cleanup_synch_mark, 0); \ if (d_flag > 2) emit0(F_SYNCH_MARK); #define BLOCK_END \ if (current_stack_depth != cleanup_frame__.stack_depth) { \ print_tree(n); \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack not in synch after block: is %d, should be %d.\n", \
1544fd2001-01-31Martin Stjernholm  current_stack_depth, cleanup_frame__.stack_depth); \ } \ if (d_flag > 2) emit0(F_POP_SYNCH_MARK); \ POP_AND_DONT_CLEANUP #else #define BLOCK_BEGIN #define BLOCK_END #endif
5a0fd52001-01-10Martin Stjernholm #define PUSH_STATEMENT_LABEL do { \ struct statement_label new_label__; \ new_label__.prev = current_label; \
6c8ada2001-01-14Martin Stjernholm  if (current_label->break_label != -2) { \ /* Only cover the current label if it's closed. */ \
5a0fd52001-01-10Martin Stjernholm  new_label__.name = 0; \ new_label__.break_label = new_label__.continue_label = -1; \
e9ebb72001-01-15Martin Stjernholm  new_label__.emit_break_label = 0; \
6c8ada2001-01-14Martin Stjernholm  new_label__.cleanups = 0; \
7acaf12001-01-15Martin Stjernholm  new_label__.stack_depth = current_stack_depth; \
5a0fd52001-01-10Martin Stjernholm  current_label = &new_label__; \ } \
7acaf12001-01-15Martin Stjernholm  else { \ DO_IF_DEBUG( \ new_label__.cleanups = (void *)(ptrdiff_t) -1; \ new_label__.stack_depth = current_stack_depth; \ ) \ current_label->stack_depth = current_stack_depth; \ }
5a0fd52001-01-10Martin Stjernholm  #define POP_STATEMENT_LABEL \ current_label = new_label__.prev; \
6c8ada2001-01-14Martin Stjernholm  DO_IF_DEBUG( \ if (new_label__.cleanups && \ new_label__.cleanups != (void *)(ptrdiff_t) -1) \
5aad932002-08-15Marcus Comstedt  Pike_fatal("Cleanup frames still left in statement_label.\n")); \
5a0fd52001-01-10Martin Stjernholm } while (0)
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm struct switch_data { INT32 index; INT32 less_label, greater_label, default_label; INT32 values_on_stack; INT32 *jumptable; struct pike_type *type; }; static struct switch_data current_switch = {0, 0, 0, 0, 0, NULL, NULL};
3958992001-06-23Fredrik Hübinette (Hubbe) static int in_catch=0;
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) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  MEMCPY(Pike_compiler->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) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  return EXTRACT_INT(Pike_compiler->new_program->program+offset);
5267b71995-08-09Fredrik Hübinette (Hubbe) }
7a82f91996-04-13Fredrik Hübinette (Hubbe) 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) }
928f952000-11-30Fredrik Hübinette (Hubbe)  #define LBLCACHESIZE 4711 #define CURRENT_INSTR ((long)instrbuf.s.len / (long)sizeof(p_instr)) #define MAX_UNWIND 100 static int lbl_cache[LBLCACHESIZE];
f181de2001-01-11Martin Stjernholm int do_branch(INT32 lbl)
928f952000-11-30Fredrik Hübinette (Hubbe) { if(lbl==-1) { lbl=alloc_label(); }else{ INT32 last,pos=lbl_cache[lbl % LBLCACHESIZE]; if(pos < (last=CURRENT_INSTR) && (CURRENT_INSTR - pos) < MAX_UNWIND) { #define BUF ((p_instr *)instrbuf.s.str) if(BUF[pos].opcode == F_LABEL && BUF[pos].arg == lbl) { for(;pos < last;pos++) { if(BUF[pos].opcode != F_LABEL) { insert_opcode2(BUF[pos].opcode, BUF[pos].arg, BUF[pos].arg2, BUF[pos].line, BUF[pos].file); } } } } } emit1(F_BRANCH, lbl); return lbl; } void low_insert_label(int lbl) { lbl_cache[ lbl % LBLCACHESIZE ] = CURRENT_INSTR; emit1(F_LABEL, lbl); } int ins_label(int lbl) { if(lbl==-1) lbl=alloc_label(); low_insert_label(lbl); return lbl; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a7622c1996-08-06Fredrik Hübinette (Hubbe) void do_pop(int x)
7a82f91996-04-13Fredrik Hübinette (Hubbe) {
6c8ada2001-01-14Martin Stjernholm #ifdef PIKE_DEBUG
5aad932002-08-15Marcus Comstedt  if (x < 0) Pike_fatal("Cannot do pop of %d args.\n", x);
6c8ada2001-01-14Martin Stjernholm #endif
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)  }
7acaf12001-01-15Martin Stjernholm  current_stack_depth -= x;
5267b71995-08-09Fredrik Hübinette (Hubbe) }
66d51c1997-03-04Fredrik Hübinette (Hubbe) 
09991f2001-04-15Martin Stjernholm void do_pop_mark(void *ignored)
7acaf12001-01-15Martin Stjernholm { emit0(F_POP_MARK); }
986b522001-03-17Henrik Grubbström (Grubba) void do_pop_to_mark(void *ignored)
7acaf12001-01-15Martin Stjernholm { emit0(F_POP_TO_MARK); }
9d6f3e2001-03-09Henrik Grubbström (Grubba) void do_cleanup_synch_mark(void)
1544fd2001-01-31Martin Stjernholm { if (d_flag > 2) emit0(F_CLEANUP_SYNCH_MARK); }
9d6f3e2001-03-09Henrik Grubbström (Grubba) void do_escape_catch(void)
f181de2001-01-11Martin Stjernholm { emit0(F_ESCAPE_CATCH); }
1544fd2001-01-31Martin Stjernholm #define DO_CODE_BLOCK(X) do_pop(do_docode((X),DO_NOT_COPY | DO_POP ))
5267b71995-08-09Fredrik Hübinette (Hubbe) 
7e877a2003-04-02Martin Stjernholm int do_docode(node *n, int flags)
5267b71995-08-09Fredrik Hübinette (Hubbe) { int i;
7acaf12001-01-15Martin Stjernholm  int stack_depth_save = current_stack_depth;
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;
7acaf12001-01-15Martin Stjernholm #ifdef PIKE_DEBUG
5aad932002-08-15Marcus Comstedt  if (current_stack_depth == -4711) Pike_fatal("do_docode() used outside docode().\n");
7acaf12001-01-15Martin Stjernholm #endif
a2d5581999-11-11Henrik Grubbström (Grubba)  i=do_docode2(check_node_hash(n), flags);
7acaf12001-01-15Martin Stjernholm  current_stack_depth = stack_depth_save + i;
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; }
7e877a2003-04-02Martin Stjernholm static void code_expression(node *n, int flags, char *err)
c64e8a1997-04-17Fredrik Hübinette (Hubbe) {
7e877a2003-04-02Martin Stjernholm  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:
5aad932002-08-15Marcus Comstedt  Pike_fatal("Internal compiler error (%s), line %ld, file %s\n",
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  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)  {
f181de2001-01-11Martin Stjernholm  if(t == iftrue) do_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);
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_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) 
7e877a2003-04-02Martin Stjernholm  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);
7acaf12001-01-15Martin Stjernholm  current_stack_depth--;
2d12341997-03-10Fredrik Hübinette (Hubbe)  }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:
cb76e82001-01-14Henrik Grubbström (Grubba)  case F_LOOP:
5267b71995-08-09Fredrik Hübinette (Hubbe)  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:
9abda42002-03-02Martin Stjernholm  return 1; case F_CASE_RANGE:
5267b71995-08-09Fredrik Hübinette (Hubbe)  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; } }
4f20e92001-01-25Fredrik Hübinette (Hubbe)  int generate_call_function(node *n) { emit0(F_MARK); PUSH_CLEANUP_FRAME(do_pop_mark, 0); do_docode(CDR(n),DO_NOT_COPY); emit0(F_CALL_FUNCTION); POP_AND_DONT_CLEANUP; return 1; }
54a1302004-06-02Martin Nilsson static INLINE struct compiler_frame *find_local_frame(INT32 depth)
4218011999-01-31Fredrik Hübinette (Hubbe) {
bad5162000-06-23Fredrik Hübinette (Hubbe)  struct compiler_frame *f=Pike_compiler->compiler_frame;
4218011999-01-31Fredrik Hübinette (Hubbe)  while(--depth>=0) f=f->previous; return f; }
5e5a592002-11-14Henrik Grubbström (Grubba) /* Emit code for a function call to the identifier reference #id, * with the arguments specified by args. */ int do_lfun_call(int id, node *args)
6fd5172000-04-25Fredrik Hübinette (Hubbe) { #if 1
5e5a592002-11-14Henrik Grubbström (Grubba)  struct reference *ref = Pike_compiler->new_program->identifier_references + id;
1918542002-11-22Henrik Grubbström (Grubba)  /* Test description: * * * Test if we have a valid current function. * * * Quick check if id is the current function. * * * Check if id is an alternate reference to the current function.
f5cfc32002-11-23Martin Stjernholm  * * * Check that the function isn't varargs.
1918542002-11-22Henrik Grubbström (Grubba)  */
055a0b2002-11-15Henrik Grubbström (Grubba)  if((Pike_compiler->compiler_frame->current_function_number >= 0) && ((id == Pike_compiler->compiler_frame->current_function_number) || ((!ref->inherit_offset) && (ref->identifier_offset == Pike_compiler->new_program-> identifier_references[Pike_compiler->compiler_frame->
f5cfc32002-11-23Martin Stjernholm  current_function_number].identifier_offset))) && (!(Pike_compiler->new_program-> identifiers[ref->identifier_offset].identifier_flags & IDENTIFIER_VARARGS)))
6fd5172000-04-25Fredrik Hübinette (Hubbe)  {
873ceb2000-04-30Fredrik Hübinette (Hubbe)  int n=count_args(args);
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(n == Pike_compiler->compiler_frame->num_args)
6fd5172000-04-25Fredrik Hübinette (Hubbe)  {
2ac9502001-08-14Fredrik Hübinette (Hubbe)  do_docode(args,0);
5e5a592002-11-14Henrik Grubbström (Grubba)  if(Pike_compiler->compiler_frame->is_inline || (ref->id_flags & ID_INLINE))
6fd5172000-04-25Fredrik Hübinette (Hubbe)  {
5e5a592002-11-14Henrik Grubbström (Grubba)  /* Identifier is declared inline/local * or in inlining pass. */
ec1d4d2002-11-14Henrik Grubbström (Grubba)  if ((ref->id_flags & ID_INLINE) && (!Pike_compiler->compiler_frame->is_inline)) { /* Explicit local:: reference in first pass. * * RECUR directly to label 0. *
055a0b2002-11-15Henrik Grubbström (Grubba)  * Note that we in this case don't know if we are overloaded or * not, and thus can't RECUR to the recur_label.
ec1d4d2002-11-14Henrik Grubbström (Grubba)  */ do_jump(F_RECUR, 0); } else { Pike_compiler->compiler_frame-> recur_label=do_jump(F_RECUR, Pike_compiler->compiler_frame->recur_label); }
5e5a592002-11-14Henrik Grubbström (Grubba)  } else { /* Recur if not overloaded. */
873ceb2000-04-30Fredrik Hübinette (Hubbe)  emit1(F_COND_RECUR,id);
5e5a592002-11-14Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame-> recur_label=do_jump(F_POINTER, Pike_compiler->compiler_frame->recur_label);
6fd5172000-04-25Fredrik Hübinette (Hubbe)  }
2ac9502001-08-14Fredrik Hübinette (Hubbe)  return 1;
6fd5172000-04-25Fredrik Hübinette (Hubbe)  } }
69202f2001-01-17Henrik Grubbström (Grubba) #endif
2ac9502001-08-14Fredrik Hübinette (Hubbe)  emit0(F_MARK); PUSH_CLEANUP_FRAME(do_pop_mark, 0); do_docode(args,0); emit1(F_CALL_LFUN, id);
7acaf12001-01-15Martin Stjernholm  POP_AND_DONT_CLEANUP;
6fd5172000-04-25Fredrik Hübinette (Hubbe)  return 1; }
8bef1b2001-09-27Fredrik Hübinette (Hubbe) /* * FIXME: this can be optimized, but is not really used * enough to be worth it yet. */ static void emit_apply_builtin(char *func) { INT32 tmp1; struct pike_string *n1=make_shared_string(func); node *n=find_module_identifier(n1,0); free_string(n1); switch(n?n->token:0) { case F_CONSTANT: tmp1=store_constant(&n->u.sval,
515bcf2002-07-02Henrik Grubbström (Grubba)  !(n->tree_info & OPT_EXTERNAL_DEPEND),
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  n->name); if(n->u.sval.type == T_FUNCTION && n->u.sval.subtype == FUNCTION_BUILTIN) emit1(F_CALL_BUILTIN, DO_NOT_WARN((INT32)tmp1)); else emit1(F_APPLY, DO_NOT_WARN((INT32)tmp1)); break; default: my_yyerror("docode: Failed to make call to %s",func); } free_node(n); } static int do_encode_automap_arg_list(node *n,
7e877a2003-04-02Martin Stjernholm  int flags)
8bef1b2001-09-27Fredrik Hübinette (Hubbe) { int stack_depth_save = current_stack_depth; if(!n) return 0; switch(n->token) { default: return do_docode(n, flags); case F_ARG_LIST: { int ret; ret=do_encode_automap_arg_list(CAR(n), flags); current_stack_depth=stack_depth_save + ret; ret+=do_encode_automap_arg_list(CDR(n), flags); current_stack_depth=stack_depth_save + ret; return ret; } case F_AUTO_MAP_MARKER: { int depth=0; while(n->token == F_AUTO_MAP_MARKER) { n=CAR(n); depth++; } emit0(F_MARK); code_expression(n, 0, "[*]"); emit1(F_NUMBER, depth); emit_apply_builtin("__builtin.automap_marker"); return 1; } } }
005bf42001-09-29Fredrik Hübinette (Hubbe) static void emit_builtin_svalue(char *func) { INT32 tmp1; struct pike_string *n1=make_shared_string(func); node *n=find_module_identifier(n1,0); free_string(n1); switch(n?n->token:0) { case F_CONSTANT: tmp1=store_constant(&n->u.sval,
515bcf2002-07-02Henrik Grubbström (Grubba)  (!(n->tree_info & OPT_EXTERNAL_DEPEND)) && (n->u.sval.type != T_TYPE),
005bf42001-09-29Fredrik Hübinette (Hubbe)  n->name); emit1(F_CONSTANT, DO_NOT_WARN((INT32)tmp1)); break; default: my_yyerror("docode: Failed to make svalue for builtin %s",func); } free_node(n); }
8bef1b2001-09-27Fredrik Hübinette (Hubbe) 
408a1e2004-10-30Martin Stjernholm static void emit_range (node *n DO_IF_DEBUG (COMMA int num_args)) { node *low = CADR (n), *high = CDDR (n); int bound_types; switch (low->token) { case F_RANGE_FROM_BEG: bound_types = RANGE_LOW_FROM_BEG; break; case F_RANGE_FROM_END: bound_types = RANGE_LOW_FROM_END; break; case F_RANGE_OPEN: bound_types = RANGE_LOW_OPEN; break; #ifdef PIKE_DEBUG default: Pike_fatal ("Unexpected node %d as range lower bound.\n", low->token); #endif } switch (high->token) { case F_RANGE_FROM_BEG: bound_types |= RANGE_HIGH_FROM_BEG; break; case F_RANGE_FROM_END: bound_types |= RANGE_HIGH_FROM_END; break; case F_RANGE_OPEN: bound_types |= RANGE_HIGH_OPEN; break; #ifdef PIKE_DEBUG default: Pike_fatal ("Unexpected node %d as range upper bound.\n", high->token); #endif } #ifdef PIKE_DEBUG { int expected_args; switch (bound_types & (RANGE_LOW_OPEN|RANGE_HIGH_OPEN)) { case 0: expected_args = 2; break; case RANGE_LOW_OPEN: case RANGE_HIGH_OPEN: expected_args = 1; break; case RANGE_LOW_OPEN|RANGE_HIGH_OPEN: expected_args = 0; break; } if (num_args != expected_args) Pike_fatal ("Wrong number of args to o_range opcode. Expected %d, got %d.\n", expected_args, num_args); } #endif emit1 (F_RANGE, bound_types); }
7e877a2003-04-02Martin Stjernholm static int do_docode2(node *n, int flags)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
e0755c2000-08-15Henrik Grubbström (Grubba)  ptrdiff_t tmp1,tmp2,tmp3;
57c2872003-09-19Henrik Grubbström (Grubba)  int ret;
5267b71995-08-09Fredrik Hübinette (Hubbe)  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:
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  case F_AUTO_MAP_MARKER:
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 */ {
c7241b2000-08-10Henrik Grubbström (Grubba)  ptrdiff_t x_= ((char *)&x_) + STACK_DIRECTION * (32768) - Pike_interpreter.stack_top ;
f9abcf1999-09-16Fredrik Hübinette (Hubbe)  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:
cbe1132001-12-16Martin Stjernholm  case F_MAGIC_INDICES: case F_MAGIC_VALUES:
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: {
ff88db2000-07-12Henrik Grubbström (Grubba)  int level = 0;
342fef2000-08-23Fredrik Hübinette (Hubbe)  struct program_state *state = Pike_compiler;
ff88db2000-07-12Henrik Grubbström (Grubba)  while (state && (state->new_program->id != n->u.integer.a)) { state = state->previous; level++; } if (!state) { my_yyerror("Program parent %d lost during compiling.", n->u.integer.a); emit1(F_NUMBER,0); return 1; }
342fef2000-08-23Fredrik Hübinette (Hubbe)  if(level)
ff88db2000-07-12Henrik Grubbström (Grubba)  {
342fef2000-08-23Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE) {
5d642e2003-08-03Martin Stjernholm  if (n->u.integer.b == IDREF_MAGIC_THIS) yyerror ("Cannot assign to this.");
342fef2000-08-23Fredrik Hübinette (Hubbe)  emit2(F_EXTERNAL_LVALUE, n->u.integer.b, level); return 2; }else{ emit2(F_EXTERNAL, n->u.integer.b, level); return 1; }
ff88db2000-07-12Henrik Grubbström (Grubba)  }else{
342fef2000-08-23Fredrik Hübinette (Hubbe)  if(flags & WANT_LVALUE) {
57306e2004-12-18Henrik Grubbström (Grubba)  if (n->u.integer.b == IDREF_MAGIC_THIS) { my_yyerror("this is not an lvalue."); }
342fef2000-08-23Fredrik Hübinette (Hubbe)  emit1(F_GLOBAL_LVALUE, n->u.integer.b); return 2; }else{
5d642e2003-08-03Martin Stjernholm  if (n->u.integer.b == IDREF_MAGIC_THIS) emit1(F_THIS_OBJECT, 0); else { struct identifier *id = ID_FROM_INT(state->new_program,n->u.integer.b); if(IDENTIFIER_IS_FUNCTION(id->identifier_flags) && id->identifier_flags & IDENTIFIER_HAS_BODY) { /* Only use this opcode when it's certain that the result * can't zero, i.e. when we know the function isn't just a * prototype. */ emit1(F_LFUN, n->u.integer.b); }else{ emit1(F_GLOBAL, n->u.integer.b); }
342fef2000-08-23Fredrik Hübinette (Hubbe)  } return 1; }
ff88db2000-07-12Henrik Grubbström (Grubba)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  } break;
57306e2004-12-18Henrik Grubbström (Grubba)  case F_THIS: { int level = 0; struct program_state *state = Pike_compiler; int inh = n->u.integer.b; while (state && (state->new_program->id != n->u.integer.a)) { state = state->previous; level++; } if (!state) { my_yyerror("Program parent %d lost during compiling.", n->u.integer.a); emit1(F_NUMBER,0); } else if (!level && !inh) { emit1(F_THIS_OBJECT, 0); } else { emit2(F_THIS, level, inh); } return 1; } break;
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  case F_UNDEFINED: yyerror("Undefined identifier");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,0);
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  return 1;
7acaf12001-01-15Martin Stjernholm  case F_PUSH_ARRAY: { if (current_label != &top_statement_label_dummy || current_label->cleanups) { /* Might not have a surrounding apply node if evaluated as a * constant by the optimizer. */ #ifdef PIKE_DEBUG if (!current_label->cleanups || (current_label->cleanups->cleanup != do_pop_mark && current_label->cleanups->cleanup != do_pop_to_mark))
5aad932002-08-15Marcus Comstedt  Pike_fatal("F_PUSH_ARRAY unexpected in this context.\n");
7acaf12001-01-15Martin Stjernholm #endif current_label->cleanups->cleanup = do_pop_to_mark; }
c64e8a1997-04-17Fredrik Hübinette (Hubbe)  code_expression(CAR(n), 0, "`@");
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_PUSH_ARRAY);
7acaf12001-01-15Martin Stjernholm  return 0; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case '?': {
9abda42002-03-02Martin Stjernholm  INT32 *prev_switch_jumptable = current_switch.jumptable;
9d61521996-08-03Fredrik Hübinette (Hubbe)  int adroppings , bdroppings;
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
2e4e451997-02-13Fredrik Hübinette (Hubbe) 
9d61521996-08-03Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(!CDDR(n)) {
a7622c1996-08-06Fredrik Hübinette (Hubbe)  tmp1=alloc_label();
393a592000-08-16Henrik Grubbström (Grubba)  do_jump_when_zero(CAR(n), DO_NOT_WARN((INT32)tmp1));
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CADR(n));
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_label( DO_NOT_WARN((INT32)tmp1));
9abda42002-03-02Martin Stjernholm  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();
393a592000-08-16Henrik Grubbström (Grubba)  do_jump_when_non_zero(CAR(n), DO_NOT_WARN((INT32)tmp1));
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDDR(n));
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_label( DO_NOT_WARN((INT32)tmp1));
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }
a7622c1996-08-06Fredrik Hübinette (Hubbe)  tmp1=alloc_label();
393a592000-08-16Henrik Grubbström (Grubba)  do_jump_when_zero(CAR(n), DO_NOT_WARN((INT32)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 */
f181de2001-01-11Martin Stjernholm  tmp2=do_branch(-1);
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_label( DO_NOT_WARN((INT32)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) {
393a592000-08-16Henrik Grubbström (Grubba)  update_arg(DO_NOT_WARN((INT32)tmp3), adroppings - bdroppings);
9d61521996-08-03Fredrik Hübinette (Hubbe)  adroppings=bdroppings; }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_label( DO_NOT_WARN((INT32)tmp2));
2e4e451997-02-13Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  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:
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  if(CAR(n)->token == F_AUTO_MAP_MARKER || CDR(n)->token == F_AUTO_MAP_MARKER)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  char *opname;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  if(CAR(n)->token == F_AUTO_MAP_MARKER) { int depth=0; node *tmp=CAR(n); while(tmp->token == F_AUTO_MAP_MARKER)
a2b70a2000-04-30Fredrik Hübinette (Hubbe)  {
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  depth++; tmp=CAR(tmp);
a2b70a2000-04-30Fredrik Hübinette (Hubbe)  }
005bf42001-09-29Fredrik Hübinette (Hubbe)  tmp1=do_docode(tmp,DO_LVALUE); emit0(F_MARK);
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  emit0(F_MARK); emit0(F_LTOSVAL); emit1(F_NUMBER,depth); emit_apply_builtin("__builtin.automap_marker"); }else{
005bf42001-09-29Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),DO_LVALUE);
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  emit0(F_LTOSVAL); } switch(n->token) { case F_ADD_EQ: opname="`+"; break; case F_AND_EQ: opname="`&"; break; case F_OR_EQ: opname="`|"; break; case F_XOR_EQ: opname="`^"; break; case F_LSH_EQ: opname="`<<"; break; case F_RSH_EQ: opname="`>>"; break; case F_SUB_EQ: opname="`-"; break; case F_MULT_EQ:opname="`*"; break; case F_MOD_EQ: opname="`%"; break; case F_DIV_EQ: opname="`/"; break; default:
5aad932002-08-15Marcus Comstedt  Pike_fatal("Really???\n");
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  opname="`make gcc happy"; }
005bf42001-09-29Fredrik Hübinette (Hubbe)  emit_builtin_svalue(opname); emit2(F_REARRANGE,1,1);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  if(CDR(n)->token == F_AUTO_MAP) { do_encode_automap_arg_list(CDR(n), 0); }else{ code_expression(CDR(n), 0, "assignment"); } emit_apply_builtin("__automap__"); }else{
005bf42001-09-29Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),DO_LVALUE); #ifdef PIKE_DEBUG if(tmp1 != 2)
5aad932002-08-15Marcus Comstedt  Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (7)\n");
005bf42001-09-29Fredrik Hübinette (Hubbe) #endif
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  if(n->token == F_ADD_EQ && (flags & DO_POP)) { code_expression(CDR(n), 0, "assignment"); emit0(F_ADD_TO_AND_POP); return 0; } if(CAR(n)->token != F_AUTO_MAP && (match_types(CAR(n)->type, array_type_string) || match_types(CAR(n)->type, string_type_string) || match_types(CAR(n)->type, mapping_type_string) || match_types(CAR(n)->type, object_type_string))) { code_expression(CDR(n), 0, "assignment"); emit0(F_LTOSVAL2); }else{ emit0(F_LTOSVAL); code_expression(CDR(n), 0, "assignment"); } switch(n->token) { case F_ADD_EQ: if(CAR(n)->type == int_type_string && CDR(n)->type == int_type_string) { emit0(F_ADD_INTS); } else if(CAR(n)->type == float_type_string && CDR(n)->type == float_type_string) { emit0(F_ADD_FLOATS); }else{ 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) {
b99ff82001-06-07Fredrik Hübinette (Hubbe)  case F_RANGE:
5267b71995-08-09Fredrik Hübinette (Hubbe)  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))) {
408a1e2004-10-30Martin Stjernholm  int num_args;
5267b71995-08-09Fredrik Hübinette (Hubbe)  tmp1=do_docode(CDR(n),DO_LVALUE);
babd872001-02-23Henrik Grubbström (Grubba)  if(match_types(CDR(n)->type, array_type_string) ||
c87cfa2001-06-07Fredrik Hübinette (Hubbe)  match_types(CDR(n)->type, string_type_string) ||
ab952d2001-06-07Fredrik Hübinette (Hubbe)  match_types(CDR(n)->type, object_type_string) ||
c87cfa2001-06-07Fredrik Hübinette (Hubbe)  match_types(CDR(n)->type, multiset_type_string) || match_types(CDR(n)->type, mapping_type_string))
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
408a1e2004-10-30Martin Stjernholm  num_args = do_docode(check_node_hash(CDAR(n)), 0); switch (num_args)
b99ff82001-06-07Fredrik Hübinette (Hubbe)  {
408a1e2004-10-30Martin Stjernholm  case 0: emit0(F_LTOSVAL1); break;
b99ff82001-06-07Fredrik Hübinette (Hubbe)  case 1: emit0(F_LTOSVAL2); break; case 2: emit0(F_LTOSVAL3); break; #ifdef PIKE_DEBUG default:
5aad932002-08-15Marcus Comstedt  Pike_fatal("Arglebargle glop-glyf?\n");
b99ff82001-06-07Fredrik Hübinette (Hubbe) #endif }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_LTOSVAL);
408a1e2004-10-30Martin Stjernholm  num_args = do_docode(check_node_hash(CDAR(n)), 0);
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
408a1e2004-10-30Martin Stjernholm  if (CAR (n)->token == F_RANGE) emit_range (CAR (n) DO_IF_DEBUG (COMMA num_args)); else 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;
342fef2000-08-23Fredrik Hübinette (Hubbe)  /* FIXME: Make special case for F_EXTERNAL */
06983f1996-09-22Fredrik Hübinette (Hubbe)  case F_IDENTIFIER:
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(!IDENTIFIER_IS_VARIABLE( ID_FROM_INT(Pike_compiler->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;
57f3162001-06-29Fredrik Hübinette (Hubbe)  case F_EXTERNAL: /* Check that it is in this context */ if(Pike_compiler ->new_program->id == CDR(n)->u.integer.a) { /* Check that it is a variable */
5d642e2003-08-03Martin Stjernholm  if(CDR(n)->u.integer.b != IDREF_MAGIC_THIS && IDENTIFIER_IS_VARIABLE( ID_FROM_INT(Pike_compiler->new_program, CDR(n)->u.integer.b)->identifier_flags))
57f3162001-06-29Fredrik Hübinette (Hubbe)  { code_expression(CAR(n), 0, "RHS"); emit1(flags & DO_POP ? F_ASSIGN_GLOBAL_AND_POP:F_ASSIGN_GLOBAL, CDR(n)->u.integer.b); break; } } /* fall through */
5267b71995-08-09Fredrik Hübinette (Hubbe)  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();
0811472001-07-02Fredrik Hübinette (Hubbe)  if(flags & DO_POP) { do_cond_jump(CAR(n), DO_NOT_WARN((INT32)tmp1), n->token == F_LOR, DO_POP); DO_CODE_BLOCK(CDR(n)); low_insert_label( DO_NOT_WARN((INT32)tmp1)); return 0; }else{ do_cond_jump(CAR(n), DO_NOT_WARN((INT32)tmp1), n->token == F_LOR, 0); code_expression(CDR(n), flags, n->token == F_LOR ? "||" : "&&"); low_insert_label( DO_NOT_WARN((INT32)tmp1)); return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  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:
5aad932002-08-15Marcus Comstedt  Pike_fatal("Optimizer error.\n");
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_RANGE:
5e44422001-02-25Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),DO_NOT_COPY_TOPLEVEL);
408a1e2004-10-30Martin Stjernholm  { #ifdef PIKE_DEBUG int num_args = #endif do_docode (CDR (n), DO_NOT_COPY); emit_range (n DO_IF_DEBUG (COMMA num_args)); return DO_NOT_WARN((INT32)tmp1); } /* The special bound type nodes are simply ignored when the * arglist to the range operator is coded. emit_range looks at * them later on instead. */ case F_RANGE_FROM_BEG: case F_RANGE_FROM_END: return do_docode (CAR (n), flags); case F_RANGE_OPEN: return 0;
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_INC: case F_POST_INC:
005bf42001-09-29Fredrik Hübinette (Hubbe)  if(CAR(n)->token == F_AUTO_MAP_MARKER) { int depth=0; int ret=0; node *tmp=CAR(n); while(tmp->token == F_AUTO_MAP_MARKER) { depth++; tmp=CAR(tmp); } tmp1=do_docode(tmp,DO_LVALUE); if(n->token == F_POST_INC) { emit0(F_LTOSVAL); emit2(F_REARRANGE,1,2); ret++; flags|=DO_POP; }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
005bf42001-09-29Fredrik Hübinette (Hubbe)  if(tmp1 != 2)
5aad932002-08-15Marcus Comstedt  Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
005bf42001-09-29Fredrik Hübinette (Hubbe)  emit0(F_MARK); emit0(F_MARK); emit0(F_LTOSVAL); emit1(F_NUMBER, depth); emit_apply_builtin("__builtin.automap_marker"); emit_builtin_svalue("`+"); emit2(F_REARRANGE,1,1); emit1(F_NUMBER, 1); emit_apply_builtin("__automap__"); if(flags & DO_POP) { emit0(F_ASSIGN_AND_POP); }else{ emit0(F_ASSIGN); ret++; } return ret;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
005bf42001-09-29Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),DO_LVALUE); #ifdef PIKE_DEBUG if(tmp1 != 2)
5aad932002-08-15Marcus Comstedt  Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");
005bf42001-09-29Fredrik Hübinette (Hubbe) #endif if(flags & DO_POP) { emit0(F_INC_AND_POP); return 0; }else{ emit0(n->token); return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } case F_DEC: case F_POST_DEC:
005bf42001-09-29Fredrik Hübinette (Hubbe)  if(CAR(n)->token == F_AUTO_MAP_MARKER) { int depth=0; int ret=0; node *tmp=CAR(n); while(tmp->token == F_AUTO_MAP_MARKER) { depth++; tmp=CAR(tmp); } tmp1=do_docode(tmp,DO_LVALUE); if(n->token == F_POST_DEC) { emit0(F_LTOSVAL); emit2(F_REARRANGE,1,2); ret++; flags|=DO_POP; }
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
005bf42001-09-29Fredrik Hübinette (Hubbe)  if(tmp1 != 2)
5aad932002-08-15Marcus Comstedt  Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (1)\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) #endif
005bf42001-09-29Fredrik Hübinette (Hubbe)  emit0(F_MARK); emit0(F_MARK); emit0(F_LTOSVAL); emit1(F_NUMBER, depth); emit_apply_builtin("__builtin.automap_marker"); emit_builtin_svalue("`-"); emit2(F_REARRANGE,1,1); emit1(F_NUMBER, 1); emit_apply_builtin("__automap__"); if(flags & DO_POP) { emit0(F_ASSIGN_AND_POP); }else{ emit0(F_ASSIGN); ret++; } return ret;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }else{
005bf42001-09-29Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(n),DO_LVALUE); #ifdef PIKE_DEBUG if(tmp1 != 2)
5aad932002-08-15Marcus Comstedt  Pike_fatal("HELP! FATAL INTERNAL COMPILER ERROR (2)\n");
005bf42001-09-29Fredrik Hübinette (Hubbe) #endif if(flags & DO_POP) { emit0(F_DEC_AND_POP); return 0; }else{ emit0(n->token); return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } case F_FOR: {
9abda42002-03-02Martin Stjernholm  INT32 *prev_switch_jumptable = current_switch.jumptable;
1544fd2001-01-31Martin Stjernholm  BLOCK_BEGIN;
6c8ada2001-01-14Martin Stjernholm  PUSH_STATEMENT_LABEL;
5a0fd52001-01-10Martin Stjernholm 
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
5a0fd52001-01-10Martin Stjernholm  current_label->break_label=alloc_label(); current_label->continue_label=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(CDR(n)) {
5a0fd52001-01-10Martin Stjernholm  do_jump_when_zero(CAR(n),current_label->break_label);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp2=ins_label(-1);
9d61521996-08-03Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CADR(n));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->continue_label);
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)  }
393a592000-08-16Henrik Grubbström (Grubba)  do_jump_when_non_zero(CAR(n), DO_NOT_WARN((INT32)tmp2));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->break_label);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
6c8ada2001-01-14Martin Stjernholm  POP_STATEMENT_LABEL;
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } case ' ':
57c2872003-09-19Henrik Grubbström (Grubba)  ret = do_docode(CAR(n),0); return ret + do_docode(CDR(n),DO_LVALUE);
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_FOREACH: {
a982301999-04-30Fredrik Hübinette (Hubbe)  node *arr;
9abda42002-03-02Martin Stjernholm  INT32 *prev_switch_jumptable = current_switch.jumptable;
a982301999-04-30Fredrik Hübinette (Hubbe)  arr=CAR(n);
4cdb802001-02-23Fredrik Hübinette (Hubbe)  if(CDR(arr) && CDR(arr)->token == ':') { BLOCK_BEGIN; /* New-style */
5e44422001-02-25Fredrik Hübinette (Hubbe)  tmp1=do_docode(CAR(arr), DO_NOT_COPY_TOPLEVEL);
4cdb802001-02-23Fredrik Hübinette (Hubbe)  emit0(F_MAKE_ITERATOR); if(CADR(arr)) { do_docode(CADR(arr), DO_LVALUE); }else{ emit0(F_CONST0); emit0(F_CONST0); current_stack_depth+=2; } if(CDDR(arr)) { do_docode(CDDR(arr), DO_LVALUE); }else{ emit0(F_CONST0); emit0(F_CONST0); current_stack_depth+=2; } PUSH_CLEANUP_FRAME(do_pop, 5); PUSH_STATEMENT_LABEL;
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
4cdb802001-02-23Fredrik Hübinette (Hubbe)  current_label->break_label=alloc_label(); current_label->continue_label=alloc_label();
f139182003-09-05Martin Stjernholm  /* Doubt it's necessary to use a label separate from * current_label->break_label, but I'm playing safe. /mast */ tmp3 = alloc_label(); do_jump(F_FOREACH_START, DO_NOT_WARN((INT32) tmp3));
4cdb802001-02-23Fredrik Hübinette (Hubbe)  tmp1=ins_label(-1); DO_CODE_BLOCK(CDR(n)); ins_label(current_label->continue_label);
f139182003-09-05Martin Stjernholm  do_jump(F_FOREACH_LOOP, DO_NOT_WARN((INT32)tmp1));
4cdb802001-02-23Fredrik Hübinette (Hubbe)  ins_label(current_label->break_label);
f139182003-09-05Martin Stjernholm  low_insert_label( DO_NOT_WARN((INT32)tmp3));
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
4cdb802001-02-23Fredrik Hübinette (Hubbe)  POP_STATEMENT_LABEL; POP_AND_DO_CLEANUP; BLOCK_END; return 0; }
a982301999-04-30Fredrik Hübinette (Hubbe) 
4cdb802001-02-23Fredrik Hübinette (Hubbe)  BLOCK_BEGIN; if(CAR(arr) && CAR(arr)->token==F_RANGE)
a982301999-04-30Fredrik Hübinette (Hubbe)  {
2d74b42004-10-28Martin Stjernholm  node *range = CAR(arr);
408a1e2004-10-30Martin Stjernholm  node *low = CADR(range); node *high = CDDR(range); if(high->token == F_RANGE_OPEN && low->token == F_RANGE_FROM_BEG && match_types (low->type, int_type_string))
a982301999-04-30Fredrik Hübinette (Hubbe)  {
85f3722003-09-05Henrik Grubbström (Grubba)  /* Optimize foreach(x[start..],y). */
2d74b42004-10-28Martin Stjernholm  do_docode (CAR(range), DO_NOT_COPY_TOPLEVEL); do_docode (CDR(arr), DO_NOT_COPY|DO_LVALUE);
408a1e2004-10-30Martin Stjernholm  do_docode (CAR(low), DO_NOT_COPY);
a982301999-04-30Fredrik Hübinette (Hubbe)  goto foreach_arg_pushed; } }
2d74b42004-10-28Martin Stjernholm  do_docode(arr,DO_NOT_COPY);
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_CONST0);
7acaf12001-01-15Martin Stjernholm  current_stack_depth++;
a982301999-04-30Fredrik Hübinette (Hubbe)  foreach_arg_pushed:
1544fd2001-01-31Martin Stjernholm  PUSH_CLEANUP_FRAME(do_pop, 4);
7acaf12001-01-15Martin Stjernholm  PUSH_STATEMENT_LABEL;
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
7acaf12001-01-15Martin Stjernholm  current_label->break_label=alloc_label(); current_label->continue_label=alloc_label();
f181de2001-01-11Martin Stjernholm  tmp3=do_branch(-1);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp1=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDR(n));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->continue_label);
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_label( DO_NOT_WARN((INT32)tmp3));
393a592000-08-16Henrik Grubbström (Grubba)  do_jump(n->token, DO_NOT_WARN((INT32)tmp1));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->break_label);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
6c8ada2001-01-14Martin Stjernholm  POP_STATEMENT_LABEL; POP_AND_DO_CLEANUP;
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
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: {
9abda42002-03-02Martin Stjernholm  INT32 *prev_switch_jumptable = current_switch.jumptable;
1544fd2001-01-31Martin Stjernholm  BLOCK_BEGIN;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
1544fd2001-01-31Martin Stjernholm  do_docode(CAR(n),0); PUSH_CLEANUP_FRAME(do_pop, 3);
7acaf12001-01-15Martin Stjernholm  PUSH_STATEMENT_LABEL;
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
7acaf12001-01-15Martin Stjernholm  current_label->break_label=alloc_label(); current_label->continue_label=alloc_label();
f181de2001-01-11Martin Stjernholm  tmp3=do_branch(-1);
7a82f91996-04-13Fredrik Hübinette (Hubbe)  tmp1=ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDR(n));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->continue_label);
928f952000-11-30Fredrik Hübinette (Hubbe)  low_insert_label( DO_NOT_WARN((INT32)tmp3));
393a592000-08-16Henrik Grubbström (Grubba)  do_jump(n->token, DO_NOT_WARN((INT32)tmp1));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->break_label);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
6c8ada2001-01-14Martin Stjernholm  POP_STATEMENT_LABEL; POP_AND_DO_CLEANUP;
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }
cb76e82001-01-14Henrik Grubbström (Grubba)  case F_LOOP: { /* FIXME: No support for break or continue. */ PUSH_STATEMENT_LABEL;
f70c402001-01-14Henrik Grubbström (Grubba)  tmp1 = do_docode(CAR(n), 0);
cb76e82001-01-14Henrik Grubbström (Grubba)  if (tmp1 > 0) { do_pop(tmp1-1); tmp2 = do_branch(-1); tmp3 = ins_label(-1);
f70c402001-01-14Henrik Grubbström (Grubba)  DO_CODE_BLOCK(CDR(n));
cb76e82001-01-14Henrik Grubbström (Grubba)  ins_label(tmp2); emit1(F_LOOP, tmp3); } POP_STATEMENT_LABEL; return 0; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_DO: {
9abda42002-03-02Martin Stjernholm  INT32 *prev_switch_jumptable = current_switch.jumptable;
1544fd2001-01-31Martin Stjernholm  BLOCK_BEGIN;
6c8ada2001-01-14Martin Stjernholm  PUSH_STATEMENT_LABEL;
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
5a0fd52001-01-10Martin Stjernholm  current_label->break_label=alloc_label(); current_label->continue_label=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));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->continue_label);
393a592000-08-16Henrik Grubbström (Grubba)  do_jump_when_non_zero(CDR(n), DO_NOT_WARN((INT32)tmp2));
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->break_label);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
6c8ada2001-01-14Martin Stjernholm  POP_STATEMENT_LABEL;
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; }
176d621999-11-18Henrik Grubbström (Grubba)  case F_POP_VALUE: {
1544fd2001-01-31Martin Stjernholm  BLOCK_BEGIN;
176d621999-11-18Henrik Grubbström (Grubba)  DO_CODE_BLOCK(CAR(n));
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
176d621999-11-18Henrik Grubbström (Grubba)  return 0; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_CAST: if(n->type==void_type_string) { DO_CODE_BLOCK(CAR(n)); return 0;
0232d22001-06-17Henrik Grubbström (Grubba)  } else if (n->type == int_type_string) { tmp1 = do_docode(CAR(n), 0);
7f94c22001-06-17Henrik Grubbström (Grubba)  if(!tmp1) emit0(F_CONST0);
0232d22001-06-17Henrik Grubbström (Grubba)  else {
7f94c22001-06-17Henrik Grubbström (Grubba)  if(tmp1>1) do_pop(DO_NOT_WARN((INT32)(tmp1-1)));
0232d22001-06-17Henrik Grubbström (Grubba)  emit0(F_CAST_TO_INT); } return 1;
7f94c22001-06-17Henrik Grubbström (Grubba)  } else if (n->type == string_type_string) { tmp1 = do_docode(CAR(n), 0); if(!tmp1) emit0(F_CONST0); else if(tmp1>1) do_pop(DO_NOT_WARN((INT32)(tmp1-1))); emit0(F_CAST_TO_STRING); return 1;
0232d22001-06-17Henrik Grubbström (Grubba)  } else if (compile_type_to_runtime_type(n->type) == PIKE_T_MIXED) { tmp1 = do_docode(CAR(n), 0); if(!tmp1) emit0(F_CONST0); else if(tmp1>1) do_pop(DO_NOT_WARN((INT32)(tmp1-1))); return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
d68a072001-02-20Henrik Grubbström (Grubba)  { struct svalue sv; sv.type = T_TYPE; sv.subtype = 0; sv.u.type = n->type;
515bcf2002-07-02Henrik Grubbström (Grubba)  tmp1 = store_constant(&sv, 0, n->name);
d68a072001-02-20Henrik Grubbström (Grubba)  emit1(F_CONSTANT, DO_NOT_WARN((INT32)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; }
393a592000-08-16Henrik Grubbström (Grubba)  if(tmp1>1) do_pop(DO_NOT_WARN((INT32)(tmp1-1)));
5267b71995-08-09Fredrik Hübinette (Hubbe) 
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) {
d68a072001-02-20Henrik Grubbström (Grubba)  { struct svalue sv; sv.type = T_TYPE; sv.subtype = 0; sv.u.type = n->type;
515bcf2002-07-02Henrik Grubbström (Grubba)  tmp1 = store_constant(&sv, 0, n->name);
d68a072001-02-20Henrik Grubbström (Grubba)  emit1(F_CONSTANT, DO_NOT_WARN((INT32)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; }
393a592000-08-16Henrik Grubbström (Grubba)  if (tmp1 > 1) do_pop(DO_NOT_WARN((INT32)(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);
393a592000-08-16Henrik Grubbström (Grubba)  if (tmp1 > 1) do_pop(DO_NOT_WARN((INT32)(tmp1 - 1)));
dad12d1999-11-25Henrik Grubbström (Grubba)  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)) {
d9a93b2001-07-01Fredrik Hübinette (Hubbe)  if(count_args(CDR(n))==1) { do_docode(CDR(n),0); tmp1=store_constant(& CAR(n)->u.sval, !(CAR(n)->tree_info & OPT_EXTERNAL_DEPEND), CAR(n)->name); emit1(F_CALL_BUILTIN1, DO_NOT_WARN((INT32)tmp1)); }else{ emit0(F_MARK); PUSH_CLEANUP_FRAME(do_pop_mark, 0); do_docode(CDR(n),0); tmp1=store_constant(& CAR(n)->u.sval, !(CAR(n)->tree_info & OPT_EXTERNAL_DEPEND), CAR(n)->name); emit1(F_CALL_BUILTIN, DO_NOT_WARN((INT32)tmp1)); POP_AND_DONT_CLEANUP; }
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{
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(CAR(n)->u.sval.u.object == Pike_compiler->fake_object)
5e5a592002-11-14Henrik Grubbström (Grubba)  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);
7acaf12001-01-15Martin Stjernholm  PUSH_CLEANUP_FRAME(do_pop_mark, 0);
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);
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_APPLY, DO_NOT_WARN((INT32)tmp1));
7acaf12001-01-15Martin Stjernholm  POP_AND_DONT_CLEANUP;
7bd0ea1996-02-19Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; }
7411302001-08-30Fredrik Hübinette (Hubbe)  else if(CAR(n)->token == F_IDENTIFIER)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
5e5a592002-11-14Henrik Grubbström (Grubba)  return do_lfun_call(CAR(n)->u.id.number, CDR(n));
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
342fef2000-08-23Fredrik Hübinette (Hubbe)  else if(CAR(n)->token == F_EXTERNAL &&
5d642e2003-08-03Martin Stjernholm  CAR(n)->u.integer.a == Pike_compiler->new_program->id && CAR(n)->u.integer.b != IDREF_MAGIC_THIS)
342fef2000-08-23Fredrik Hübinette (Hubbe)  {
5e5a592002-11-14Henrik Grubbström (Grubba)  return do_lfun_call(CAR(n)->u.integer.b, CDR(n));
342fef2000-08-23Fredrik Hübinette (Hubbe)  }
a8aed22001-08-15Fredrik Hübinette (Hubbe)  else if(CAR(n)->token == F_ARROW) { emit0(F_MARK); PUSH_CLEANUP_FRAME(do_pop_mark, 0); do_docode(CAAR(n),0); /* object */ do_docode(CDR(n),0); /* args */ emit1(F_CALL_OTHER, store_prog_string(CDAR(n)->u.sval.u.string)); POP_AND_DONT_CLEANUP; return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  else {
06983f1996-09-22Fredrik Hübinette (Hubbe)  struct pike_string *tmp;
f53bab1997-01-26Fredrik Hübinette (Hubbe)  node *foo;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit0(F_MARK);
7acaf12001-01-15Martin Stjernholm  PUSH_CLEANUP_FRAME(do_pop_mark, 0);
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);
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_APPLY, DO_NOT_WARN((INT32)tmp1));
d103cb1998-01-30Fredrik Hübinette (Hubbe)  }
f53bab1997-01-26Fredrik Hübinette (Hubbe)  }
b1f4eb1998-01-13Fredrik Hübinette (Hubbe)  free_node(foo);
7acaf12001-01-15Martin Stjernholm  POP_AND_DONT_CLEANUP;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1; } case F_ARG_LIST:
bdf5eb2000-03-07Fredrik Hübinette (Hubbe)  case F_COMMA_EXPR:
408a1e2004-10-30Martin Stjernholm  case ':':
83c60c2001-06-13Henrik Grubbström (Grubba)  { node *root = n; node *parent = n->parent; /* Avoid a bit of recursion by traversing the graph... */ n->parent = NULL; tmp1 = 0; next_car: while (CAR(n) && ((CAR(n)->token == F_ARG_LIST) || (CAR(n)->token == F_COMMA_EXPR))) { CAR(n)->parent = n; n = CAR(n); } /* CAR(n) is not F_ARG_LIST or F_COMMA_EXPR */
7e877a2003-04-02Martin Stjernholm  tmp1 += do_docode(CAR(n), flags & ~WANT_LVALUE);
83c60c2001-06-13Henrik Grubbström (Grubba)  do { if (CDR(n)) { if ((CDR(n)->token == F_ARG_LIST) || (CDR(n)->token == F_COMMA_EXPR)) { /* Note: Parent points to the closest preceding CAR node * on the way to the root. */ CDR(n)->parent = n->parent; n = CDR(n); goto next_car; } /* CDR(n) is not F_ARG_LIST or F_COMMA_EXPR */ if (n->parent) {
7e877a2003-04-02Martin Stjernholm  tmp1 += do_docode(CDR(n), flags & ~WANT_LVALUE);
83c60c2001-06-13Henrik Grubbström (Grubba)  } else { tmp1 += do_docode(CDR(n), flags); } } /* Retrace */ /* Note: n->parent is always a visited CAR node on the * way to the root. */ n = n->parent; } while (n); /* Restore root->parent. */ root->parent = parent; }
393a592000-08-16Henrik Grubbström (Grubba)  return DO_NOT_WARN((INT32)tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  /* 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;
9abda42002-03-02Martin Stjernholm  struct switch_data prev_switch = current_switch;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fc26f62000-07-06Fredrik Hübinette (Hubbe)  struct svalue *save_sp=Pike_sp;
7af7d21997-08-03Fredrik Hübinette (Hubbe) #endif
1544fd2001-01-31Martin Stjernholm  BLOCK_BEGIN;
6c8ada2001-01-14Martin Stjernholm  PUSH_STATEMENT_LABEL;
5267b71995-08-09Fredrik Hübinette (Hubbe)  if(do_docode(CAR(n),0)!=1)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Internal compiler error, time to panic\n");
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  if (!(CAR(n) && (current_switch.type = CAR(n)->type))) { current_switch.type = mixed_type_string;
7670902000-01-04Henrik Grubbström (Grubba)  }
5a0fd52001-01-10Martin Stjernholm  current_label->break_label=alloc_label();
5267b71995-08-09Fredrik Hübinette (Hubbe)  cases=count_cases(CDR(n));
a96ce92000-04-19Fredrik Hübinette (Hubbe)  tmp1=emit1(F_SWITCH,0);
7acaf12001-01-15Martin Stjernholm  current_stack_depth--;
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_ALIGN,sizeof(INT32));
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch.values_on_stack=0; current_switch.index=2; current_switch.less_label=-1; current_switch.greater_label=-1; current_switch.default_label=-1; current_switch.jumptable=(INT32 *)xalloc(sizeof(INT32)*(cases*2+2));
52fcc81998-01-28Fredrik Hübinette (Hubbe)  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)  {
e0755c2000-08-15Henrik Grubbström (Grubba)  jumptable[e] = DO_NOT_WARN((INT32)emit1(F_POINTER, 0));
9abda42002-03-02Martin Stjernholm  current_switch.jumptable[e]=-1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
928f952000-11-30Fredrik Hübinette (Hubbe)  emit0(F_NOTREACHED);
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CDR(n));
1544fd2001-01-31Martin Stjernholm 
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(Pike_sp-save_sp != cases)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Count cases is wrong!\n");
7af7d21997-08-03Fredrik Hübinette (Hubbe) #endif
b1f4eb1998-01-13Fredrik Hübinette (Hubbe) 
5267b71995-08-09Fredrik Hübinette (Hubbe)  f_aggregate(cases);
49398c2000-11-08Fredrik Hübinette (Hubbe)  /* FIXME: get_switch_order might possibly be able to * throw errors, add a catch around this! -Hubbe */
fc26f62000-07-06Fredrik Hübinette (Hubbe)  order=get_switch_order(Pike_sp[-1].u.array);
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (!Pike_compiler->num_parse_error) {
7c95f12000-01-04Henrik Grubbström (Grubba)  /* Check for cases inside a range */
9abda42002-03-02Martin Stjernholm  if (cases && ((current_switch.less_label >= 0 && current_switch.jumptable[order[0]*2+2] != current_switch.less_label) || (current_switch.greater_label >= 0 && current_switch.jumptable[order[cases-1]*2+2] != current_switch.greater_label))) yyerror("Case inside range.");
7c95f12000-01-04Henrik Grubbström (Grubba)  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;
9abda42002-03-02Martin Stjernholm  if(current_switch.jumptable[o1]==current_switch.jumptable[o1+1] && current_switch.jumptable[o1]==current_switch.jumptable[o1+2])
7c95f12000-01-04Henrik Grubbström (Grubba)  { if(order[e]+1 != order[e+1]) yyerror("Case inside range."); e++; }
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } }
fc26f62000-07-06Fredrik Hübinette (Hubbe)  order_array(Pike_sp[-1].u.array,order);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  reorder((void *)(current_switch.jumptable+2),cases,sizeof(INT32)*2,order);
5267b71995-08-09Fredrik Hübinette (Hubbe)  free((char *)order);
9abda42002-03-02Martin Stjernholm  current_switch.jumptable[1] = current_switch.less_label; current_switch.jumptable[current_switch.index - 1] = current_switch.greater_label; if(current_switch.default_label < 0) current_switch.default_label = ins_label(-1); for(e=1;e<cases*2+2;e++) if(current_switch.jumptable[e]==-1) current_switch.jumptable[e]=current_switch.default_label;
52fcc81998-01-28Fredrik Hübinette (Hubbe)  for(e=1; e<cases*2+2; e++)
9abda42002-03-02Martin Stjernholm  update_arg(jumptable[e], current_switch.jumptable[e]);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
393a592000-08-16Henrik Grubbström (Grubba)  update_arg(DO_NOT_WARN((INT32)tmp1), store_constant(Pike_sp-1,1,0));
5267b71995-08-09Fredrik Hübinette (Hubbe)  pop_stack(); free((char *)jumptable);
9abda42002-03-02Martin Stjernholm  free((char *)current_switch.jumptable);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  current_switch = prev_switch;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm  low_insert_label( current_label->break_label);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
6c8ada2001-01-14Martin Stjernholm  POP_STATEMENT_LABEL;
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(Pike_interpreter.recoveries && Pike_sp-Pike_interpreter.evaluator_stack < Pike_interpreter.recoveries->stack_pointer)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Stack error after F_SWITCH (underflow)\n");
7af7d21997-08-03Fredrik Hübinette (Hubbe) #endif
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; } case F_CASE:
9abda42002-03-02Martin Stjernholm  case F_CASE_RANGE:
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
9abda42002-03-02Martin Stjernholm  if(!current_switch.jumptable)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { yyerror("Case outside switch."); }else{
9abda42002-03-02Martin Stjernholm  INT32 label = ins_label(-1); int i;
7670902000-01-04Henrik Grubbström (Grubba) 
9abda42002-03-02Martin Stjernholm  for (i = 0; i < 2; i++) { node *case_val = i == 0 ? CAR(n) : CDR(n);
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
9abda42002-03-02Martin Stjernholm  if (case_val) { if(!is_const(case_val))
271a6b2000-01-04Henrik Grubbström (Grubba)  yyerror("Case label isn't constant.");
9abda42002-03-02Martin Stjernholm  if (case_val->type && !TEST_COMPAT(0,6)) { if (!pike_types_le(case_val->type, current_switch.type)) { if (!match_types(case_val->type, current_switch.type)) { yytype_error("Type mismatch in case.", current_switch.type, case_val->type, 0); } else if (lex.pragmas & ID_STRICT_TYPES) { yytype_error("Type mismatch in case.", current_switch.type, case_val->type, YYTE_IS_WARNING); } } }
ba62cf1997-09-18Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if (!Pike_compiler->num_parse_error) {
9f85c32002-10-25Marcus Comstedt  tmp1=eval_low(case_val,1);
271a6b2000-01-04Henrik Grubbström (Grubba)  if(tmp1<1) {
9abda42002-03-02Martin Stjernholm  yyerror("Error in case label.");
271a6b2000-01-04Henrik Grubbström (Grubba)  push_int(0); tmp1=1;
b1bfe22000-01-04Henrik Grubbström (Grubba)  }
271a6b2000-01-04Henrik Grubbström (Grubba)  pop_n_elems(tmp1-1);
9abda42002-03-02Martin Stjernholm  current_switch.values_on_stack++; for(tmp1=current_switch.values_on_stack; tmp1 > 1; tmp1--)
fc26f62000-07-06Fredrik Hübinette (Hubbe)  if(is_equal(Pike_sp-tmp1, Pike_sp-1))
9abda42002-03-02Martin Stjernholm  yyerror("Duplicate case label.");
271a6b2000-01-04Henrik Grubbström (Grubba)  } else { push_int(0);
9abda42002-03-02Martin Stjernholm  current_switch.values_on_stack++;
ba62cf1997-09-18Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
9abda42002-03-02Martin Stjernholm  } if (n->token == F_CASE) { current_switch.jumptable[current_switch.index++] = label; current_switch.jumptable[current_switch.index++] = -1; } else { if (!CAR(n)) current_switch.less_label = label; if (!CDR(n)) current_switch.greater_label = label; if (CAR(n) && CDR(n)) { current_switch.jumptable[current_switch.index++] = label; current_switch.jumptable[current_switch.index++] = label; current_switch.jumptable[current_switch.index++] = label; current_switch.jumptable[current_switch.index++] = -1; } else { current_switch.jumptable[current_switch.index++] = label; current_switch.jumptable[current_switch.index++] = -1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  } } return 0; } case F_DEFAULT:
9abda42002-03-02Martin Stjernholm  if(!current_switch.jumptable)
5267b71995-08-09Fredrik Hübinette (Hubbe)  { yyerror("Default outside switch.");
9abda42002-03-02Martin Stjernholm  }else if(current_switch.default_label!=-1){
5267b71995-08-09Fredrik Hübinette (Hubbe)  yyerror("Duplicate switch default."); }else{
9abda42002-03-02Martin Stjernholm  current_switch.default_label = ins_label(-1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  } return 0; case F_BREAK:
f181de2001-01-11Martin Stjernholm  case F_CONTINUE: { struct statement_label *label, *p;
5a0fd52001-01-10Martin Stjernholm  if (CAR(n)) { struct pike_string *name = CAR(n)->u.sval.u.string; struct statement_label_name *lbl_name; for (label = current_label; label; label = label->prev) for (lbl_name = label->name; lbl_name; lbl_name = lbl_name->next) if (lbl_name->str == name)
7acaf12001-01-15Martin Stjernholm  goto label_found_1;
ce060e2004-06-30Martin Nilsson  my_yyerror("No surrounding statement labeled %S.", name);
5a0fd52001-01-10Martin Stjernholm  return 0;
7acaf12001-01-15Martin Stjernholm  label_found_1:
f181de2001-01-11Martin Stjernholm  if (n->token == F_CONTINUE && label->continue_label < 0) { my_yyerror("Cannot continue the non-loop statement on line %d.", lbl_name->line_number); return 0;
5a0fd52001-01-10Martin Stjernholm  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
5a0fd52001-01-10Martin Stjernholm 
7acaf12001-01-15Martin Stjernholm  else {
5a0fd52001-01-10Martin Stjernholm  if (n->token == F_BREAK) {
7acaf12001-01-15Martin Stjernholm  for (label = current_label; label; label = label->prev)
e9ebb72001-01-15Martin Stjernholm  if (label->break_label >= 0 && !label->emit_break_label)
7acaf12001-01-15Martin Stjernholm  goto label_found_2; yyerror("Break outside loop or switch."); return 0;
5a0fd52001-01-10Martin Stjernholm  } else { for (label = current_label; label; label = label->prev)
f181de2001-01-11Martin Stjernholm  if (label->continue_label >= 0)
7acaf12001-01-15Martin Stjernholm  goto label_found_2;
5a0fd52001-01-10Martin Stjernholm  yyerror("Continue outside loop.");
f181de2001-01-11Martin Stjernholm  return 0;
5a0fd52001-01-10Martin Stjernholm  }
7acaf12001-01-15Martin Stjernholm  label_found_2: ; }
f181de2001-01-11Martin Stjernholm 
6c8ada2001-01-14Martin Stjernholm  for (p = current_label; 1; p = p->prev) { struct cleanup_frame *q;
7acaf12001-01-15Martin Stjernholm  for (q = p->cleanups; q; q = q->prev) { do_pop(current_stack_depth - q->stack_depth);
6c8ada2001-01-14Martin Stjernholm  q->cleanup(q->cleanup_arg);
7acaf12001-01-15Martin Stjernholm  } do_pop(current_stack_depth - p->stack_depth);
6c8ada2001-01-14Martin Stjernholm  if (p == label) break; }
f181de2001-01-11Martin Stjernholm  if (n->token == F_BREAK) { if (label->break_label < 0) label->emit_break_label = 1; label->break_label = do_branch(label->break_label); } else do_branch(label->continue_label);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0;
f181de2001-01-11Martin Stjernholm  }
5267b71995-08-09Fredrik Hübinette (Hubbe) 
5a0fd52001-01-10Martin Stjernholm  case F_NORMAL_STMT_LABEL:
6c8ada2001-01-14Martin Stjernholm  case F_CUSTOM_STMT_LABEL: { struct statement_label *label; struct statement_label_name name;
1544fd2001-01-31Martin Stjernholm  BLOCK_BEGIN;
6c8ada2001-01-14Martin Stjernholm  PUSH_STATEMENT_LABEL; name.str = CAR(n)->u.sval.u.string; name.line_number = n->line_number; for (label = current_label; label; label = label->prev) { struct statement_label_name *lbl_name; for (lbl_name = label->name; lbl_name; lbl_name = lbl_name->next) if (lbl_name->str == name.str) { INT32 save_line = lex.current_line; lex.current_line = name.line_number; my_yyerror("Duplicate nested labels, previous one on line %d.", lbl_name->line_number); lex.current_line = save_line; goto label_check_done; } } label_check_done: name.next = current_label->name; current_label->name = &name; if (!name.next) { if (n->token == F_CUSTOM_STMT_LABEL) /* The statement we precede has custom label handling; leave * the statement_label "open" so the statement will use it * instead of covering it. */ current_label->break_label = -2; else current_label->break_label = -1; } DO_CODE_BLOCK(CDR(n)); if (!name.next && current_label->emit_break_label) low_insert_label(current_label->break_label); POP_STATEMENT_LABEL;
1544fd2001-01-31Martin Stjernholm  BLOCK_END;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0;
6c8ada2001-01-14Martin Stjernholm  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_RETURN:
7a82f91996-04-13Fredrik Hübinette (Hubbe)  do_docode(CAR(n),0);
3958992001-06-23Fredrik Hübinette (Hubbe)  emit0(in_catch ? F_VOLATILE_RETURN : 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);
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_SSCANF, DO_NOT_WARN((INT32)(tmp1+tmp2)));
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1;
6c8ada2001-01-14Martin Stjernholm  case F_CATCH: {
9abda42002-03-02Martin Stjernholm  INT32 *prev_switch_jumptable = current_switch.jumptable;
1544fd2001-01-31Martin Stjernholm 
7acaf12001-01-15Martin Stjernholm  tmp1=do_jump(F_CATCH,-1); PUSH_CLEANUP_FRAME(do_escape_catch, 0);
7a82f91996-04-13Fredrik Hübinette (Hubbe) 
461e0a2002-11-06Henrik Grubbström (Grubba)  /* Entry point called by eval_instruction() via o_catch(). */ emit0(F_ENTRY);
7acaf12001-01-15Martin Stjernholm  PUSH_STATEMENT_LABEL;
9abda42002-03-02Martin Stjernholm  current_switch.jumptable=0;
5a0fd52001-01-10Martin Stjernholm  current_label->break_label=alloc_label(); if (TEST_COMPAT(7,0))
1544fd2001-01-31Martin Stjernholm  current_label->continue_label = current_label->break_label;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
3958992001-06-23Fredrik Hübinette (Hubbe)  in_catch++;
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(CAR(n));
3958992001-06-23Fredrik Hübinette (Hubbe)  in_catch--;
5a0fd52001-01-10Martin Stjernholm  ins_label(current_label->break_label);
9307b42002-09-23Martin Stjernholm  emit0(F_EXIT_CATCH);
7acaf12001-01-15Martin Stjernholm  POP_STATEMENT_LABEL;
9abda42002-03-02Martin Stjernholm  current_switch.jumptable = prev_switch_jumptable;
7acaf12001-01-15Martin Stjernholm 
393a592000-08-16Henrik Grubbström (Grubba)  ins_label(DO_NOT_WARN((INT32)tmp1));
7acaf12001-01-15Martin Stjernholm  current_stack_depth++;
5267b71995-08-09Fredrik Hübinette (Hubbe) 
6c8ada2001-01-14Martin Stjernholm  POP_AND_DONT_CLEANUP;
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1;
6c8ada2001-01-14Martin Stjernholm  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_LVALUE_LIST:
57c2872003-09-19Henrik Grubbström (Grubba)  ret = do_docode(CAR(n),DO_LVALUE); return ret + do_docode(CDR(n),DO_LVALUE);
5267b71995-08-09Fredrik Hübinette (Hubbe) 
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)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Very internal compiler error.\n");
2a32691998-01-31Fredrik Hübinette (Hubbe) #endif
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_ARRAY_LVALUE, DO_NOT_WARN((INT32)(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)
6de0852004-01-23Martin Nilsson  Pike_fatal("Bugg in F_ARROW, index not string.\n");
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{
286afb2001-02-05Henrik Grubbström (Grubba)  tmp1 = do_docode(CAR(n), DO_NOT_COPY); if ((tmp2 = lfun_lookup_id(CDR(n)->u.sval.u.string)) != -1) { emit1(F_LOOKUP_LFUN, tmp2); } else { 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)  } }
393a592000-08-16Henrik Grubbström (Grubba)  return DO_NOT_WARN((INT32)tmp1);
dffa011997-01-15Fredrik Hübinette (Hubbe) 
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);
a309212000-09-11Henrik Grubbström (Grubba)  tmp1 = do_docode(CAR(n),
7e877a2003-04-02Martin Stjernholm  mklval ? DO_LVALUE_IF_POSSIBLE : 0);
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(tmp1==2) {
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
19aaeb1998-05-25Fredrik Hübinette (Hubbe)  if(!mklval)
5aad932002-08-15Marcus Comstedt  Pike_fatal("Unwanted lvalue!\n");
19aaeb1998-05-25Fredrik Hübinette (Hubbe) #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)
6de0852004-01-23Martin Nilsson  Pike_fatal("Internal compiler error, please report this (1).\n");
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)  } }
393a592000-08-16Henrik Grubbström (Grubba)  return DO_NOT_WARN((INT32)tmp1);
5267b71995-08-09Fredrik Hübinette (Hubbe)  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{
648a8c2003-01-26Mirar (Pontus Hagland) #if SIZEOF_INT_TYPE > 4 INT_TYPE i=n->u.sval.u.integer; if (i != (INT32)i) {
cf84382003-01-26Mirar (Pontus Hagland)  unsigned INT_TYPE ip=(unsigned INT_TYPE)i;
648a8c2003-01-26Mirar (Pontus Hagland)  INT32 a,b; a=(INT32)(ip>>32); b=(INT32)(ip&0xffffffff); emit2(F_NUMBER64,a,b); } else emit1(F_NUMBER,i); #else
a96ce92000-04-19Fredrik Hübinette (Hubbe)  emit1(F_NUMBER,n->u.sval.u.integer);
648a8c2003-01-26Mirar (Pontus Hagland) #endif
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);
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_STRING, DO_NOT_WARN((INT32)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)  {
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(n->u.sval.u.object == Pike_compiler->fake_object)
5267b71995-08-09Fredrik Hübinette (Hubbe)  {
98cf2a2003-02-24Martin Stjernholm  /* When does this occur? /mast */ emit1(F_GLOBAL,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;
f3c7152001-04-14Fredrik Hübinette (Hubbe) #if 0
6d22541998-01-28Fredrik Hübinette (Hubbe)  struct object *o;
ff88db2000-07-12Henrik Grubbström (Grubba) 
342fef2000-08-23Fredrik Hübinette (Hubbe)  for(o=Pike_compiler->fake_object;o!=n->u.sval.u.object;o=o->parent)
6d22541998-01-28Fredrik Hübinette (Hubbe)  x++;
f3c7152001-04-14Fredrik Hübinette (Hubbe) #else struct program_state *state=Pike_compiler; for(;state->fake_object!=n->u.sval.u.object;state=state->previous) x++; #endif
ff88db2000-07-12Henrik Grubbström (Grubba)  emit2(F_EXTERNAL, n->u.sval.subtype, x);
22d7992001-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->new_program->flags |= PROGRAM_USES_PARENT | PROGRAM_NEEDS_PARENT;
6d22541998-01-28Fredrik Hübinette (Hubbe)  return 1; }
5267b71995-08-09Fredrik Hübinette (Hubbe)  }
515bcf2002-07-02Henrik Grubbström (Grubba)  /* FALL_THROUGH */
fb5b3f2002-11-18Henrik Grubbström (Grubba)  default:
71f3a21998-11-22Fredrik Hübinette (Hubbe) #ifdef PIKE_DEBUG
bfdc442002-11-22Henrik Grubbström (Grubba)  if((n->u.sval.type == T_OBJECT) &&
fb5b3f2002-11-18Henrik Grubbström (Grubba)  (n->u.sval.u.object->next == n->u.sval.u.object))
5aad932002-08-15Marcus Comstedt  Pike_fatal("Internal error: Pointer to parent cannot be a compile time constant!\n");
6d22541998-01-28Fredrik Hübinette (Hubbe) #endif
454d541999-09-18Fredrik Hübinette (Hubbe)  tmp1=store_constant(&(n->u.sval), !(n->tree_info & OPT_EXTERNAL_DEPEND), n->name);
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_CONSTANT, DO_NOT_WARN((INT32)tmp1));
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 1;
515bcf2002-07-02Henrik Grubbström (Grubba)  case T_TYPE: tmp1 = store_constant(&(n->u.sval), 0, n->name); emit1(F_CONSTANT, DO_NOT_WARN((INT32)tmp1)); return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  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);
393a592000-08-16Henrik Grubbström (Grubba)  emit1(F_CONSTANT, DO_NOT_WARN((INT32)tmp1));
5683de1995-11-06Fredrik Hübinette (Hubbe)  /* copy now or later ? */ if(!(flags & DO_NOT_COPY) && !(n->tree_info & OPT_EXTERNAL_DEPEND))
5e44422001-02-25Fredrik Hübinette (Hubbe)  { if(flags & DO_NOT_COPY_TOPLEVEL) { switch(n->u.sval.type) { case T_ARRAY:
2575242004-05-14Martin Nilsson  if(array_fix_type_field(n->u.sval.u.array) & BIT_COMPLEX)
5e44422001-02-25Fredrik Hübinette (Hubbe)  emit0(F_COPY_VALUE); break; case T_MAPPING: mapping_fix_type_field(n->u.sval.u.mapping); if((n->u.sval.u.mapping->data->ind_types | n->u.sval.u.mapping->data->val_types) & BIT_COMPLEX) emit0(F_COPY_VALUE); break; case T_MULTISET:
5b15bb2001-12-10Martin Stjernholm  multiset_fix_type_field(n->u.sval.u.multiset); if(multiset_ind_types(n->u.sval.u.multiset) & BIT_COMPLEX)
5e44422001-02-25Fredrik Hübinette (Hubbe)  emit0(F_COPY_VALUE); break; } }else{ 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:
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  { struct compiler_frame *f; int depth=0; for(f=Pike_compiler->compiler_frame; f!=n->u.trampoline.frame;f=f->previous) depth++; emit2(F_TRAMPOLINE,n->u.trampoline.ident,depth);
4218011999-01-31Fredrik Hübinette (Hubbe)  return 1;
8c70ba2001-09-28Fredrik Hübinette (Hubbe)  }
4218011999-01-31Fredrik Hübinette (Hubbe) 
98cf2a2003-02-24Martin Stjernholm  case F_IDENTIFIER: { struct identifier *id = ID_FROM_INT(Pike_compiler->new_program, n->u.id.number); if(IDENTIFIER_IS_FUNCTION(id->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{
98cf2a2003-02-24Martin Stjernholm  if (id->identifier_flags & IDENTIFIER_HAS_BODY) /* Only use this opcode when it's certain that the result * can't zero, i.e. when we know the function isn't just a * prototype. */ emit1(F_LFUN,n->u.id.number); else emit1(F_GLOBAL,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;
98cf2a2003-02-24Martin Stjernholm  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  case F_VAL_LVAL:
c3823f2003-09-19Henrik Grubbström (Grubba)  ret = do_docode(CAR(n),flags); return ret + do_docode(CDR(n), flags | DO_LVALUE);
8bef1b2001-09-27Fredrik Hübinette (Hubbe)  case F_AUTO_MAP: emit0(F_MARK); code_expression(CAR(n), 0, "automap function"); do_encode_automap_arg_list(CDR(n),0); emit_apply_builtin("__automap__"); return 1; case F_AUTO_MAP_MARKER: yyerror("[*] not supported here.\n"); emit0(F_CONST0); return 1;
5267b71995-08-09Fredrik Hübinette (Hubbe)  default:
5aad932002-08-15Marcus Comstedt  Pike_fatal("Infernal compiler error (unknown parse-tree-token %d).\n", n->token);
5267b71995-08-09Fredrik Hübinette (Hubbe)  return 0; /* make gcc happy */ } }
ee6a782003-11-19Henrik Grubbström (Grubba) /* Used to generate code for functions. */
852c152001-07-23Fredrik Hübinette (Hubbe) INT32 do_code_block(node *n)
5267b71995-08-09Fredrik Hübinette (Hubbe) {
ee6a782003-11-19Henrik Grubbström (Grubba)  INT32 entry_point;
7acaf12001-01-15Martin Stjernholm #ifdef PIKE_DEBUG
5aad932002-08-15Marcus Comstedt  if (current_stack_depth != -4711) Pike_fatal("Reentrance in do_code_block().\n");
7acaf12001-01-15Martin Stjernholm  current_stack_depth = 0; #endif
7a82f91996-04-13Fredrik Hübinette (Hubbe)  init_bytecode();
6fd5172000-04-25Fredrik Hübinette (Hubbe)  label_no=1;
873ceb2000-04-30Fredrik Hübinette (Hubbe) 
5e5a592002-11-14Henrik Grubbström (Grubba)  /* NOTE: This is no ordinary label... */ low_insert_label(0);
bad5162000-06-23Fredrik Hübinette (Hubbe)  emit1(F_BYTE,Pike_compiler->compiler_frame->max_number_of_locals); emit1(F_BYTE,Pike_compiler->compiler_frame->num_args);
a468a02001-07-24Henrik Grubbström (Grubba)  emit0(F_ENTRY);
873ceb2000-04-30Fredrik Hübinette (Hubbe)  emit0(F_START_FUNCTION);
b1aa472001-10-05Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->current_function_number >= 0 && (Pike_compiler->new_program->identifier_references[ Pike_compiler->compiler_frame->current_function_number].id_flags & ID_INLINE))
873ceb2000-04-30Fredrik Hübinette (Hubbe)  {
ec1d4d2002-11-14Henrik Grubbström (Grubba)  Pike_compiler->compiler_frame->recur_label=0;
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->is_inline=1;
873ceb2000-04-30Fredrik Hübinette (Hubbe)  }
5267b71995-08-09Fredrik Hübinette (Hubbe)  DO_CODE_BLOCK(n);
873ceb2000-04-30Fredrik Hübinette (Hubbe) 
bad5162000-06-23Fredrik Hübinette (Hubbe)  if(Pike_compiler->compiler_frame->recur_label > 0)
873ceb2000-04-30Fredrik Hübinette (Hubbe)  { #ifdef PIKE_DEBUG if(l_flag) { fprintf(stderr,"Generating inline recursive function.\n"); } #endif /* generate code again, but this time it is inline */
bad5162000-06-23Fredrik Hübinette (Hubbe)  Pike_compiler->compiler_frame->is_inline=1;
873ceb2000-04-30Fredrik Hübinette (Hubbe) 
4686dd2002-11-12Henrik Grubbström (Grubba)  /* NOTE: This is no ordinary label... */ low_insert_label(Pike_compiler->compiler_frame->recur_label);
bad5162000-06-23Fredrik Hübinette (Hubbe)  emit1(F_BYTE,Pike_compiler->compiler_frame->max_number_of_locals); emit1(F_BYTE,Pike_compiler->compiler_frame->num_args);
4686dd2002-11-12Henrik Grubbström (Grubba)  emit0(F_ENTRY);
873ceb2000-04-30Fredrik Hübinette (Hubbe)  emit0(F_START_FUNCTION); DO_CODE_BLOCK(n); }
ee6a782003-11-19Henrik Grubbström (Grubba)  entry_point = assemble(1);
7acaf12001-01-15Martin Stjernholm  #ifdef PIKE_DEBUG current_stack_depth = -4711; #endif
ee6a782003-11-19Henrik Grubbström (Grubba)  return entry_point;
7a82f91996-04-13Fredrik Hübinette (Hubbe) }
ee6a782003-11-19Henrik Grubbström (Grubba) /* Used by eval_low() to build code for constant expressions. */ INT32 docode(node *n)
7a82f91996-04-13Fredrik Hübinette (Hubbe) {
ee6a782003-11-19Henrik Grubbström (Grubba)  INT32 entry_point;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  int label_no_save = label_no; dynamic_buffer instrbuf_save = instrbuf;
7acaf12001-01-15Martin Stjernholm  int stack_depth_save = current_stack_depth; struct statement_label *label_save = current_label; struct cleanup_frame *top_cleanups_save = top_statement_label_dummy.cleanups;
7a82f91996-04-13Fredrik Hübinette (Hubbe)  instrbuf.s.str=0;
6fd5172000-04-25Fredrik Hübinette (Hubbe)  label_no=1;
7acaf12001-01-15Martin Stjernholm  current_stack_depth = 0; current_label = &top_statement_label_dummy; /* Fix these two to */ top_statement_label_dummy.cleanups = 0; /* please F_PUSH_ARRAY. */
7a82f91996-04-13Fredrik Hübinette (Hubbe)  init_bytecode();
ee6a782003-11-19Henrik Grubbström (Grubba)  insert_opcode0(F_ENTRY, n->line_number, n->current_file); /* FIXME: Should we check that do_docode() returns 1? */ do_docode(n,0); insert_opcode0(F_DUMB_RETURN, n->line_number, n->current_file); entry_point = assemble(0); /* Don't store linenumbers. */
7a82f91996-04-13Fredrik Hübinette (Hubbe)  instrbuf=instrbuf_save; label_no = label_no_save;
7acaf12001-01-15Martin Stjernholm  current_stack_depth = stack_depth_save; current_label = label_save; top_statement_label_dummy.cleanups = top_cleanups_save;
ee6a782003-11-19Henrik Grubbström (Grubba)  return entry_point;
5267b71995-08-09Fredrik Hübinette (Hubbe) }