virtual-machine.c 47.6 KB
Newer Older
kollo's avatar
kollo committed
1 2 3 4 5 6 7 8 9 10
/* VIRTUAL-MACHINE.C (c) Markus Hoffmann  */

/* This file is part of X11BASIC, the basic interpreter for Unix/X
 * ============================================================
 * X11BASIC is free software and comes with NO WARRANTY - read the file
 * COPYING for details
 */
 
#include <stdio.h>
#include <stdlib.h>
11
#include <stdint.h>
kollo's avatar
kollo committed
12
#include <stdarg.h>
kollo's avatar
kollo committed
13 14
#include <math.h>
#include <string.h>
kollo's avatar
kollo committed
15 16 17
#if defined(__CYGWIN__) || defined(__MINGW32__)
#include <windows.h>
#endif
kollo's avatar
kollo committed
18
#include "defs.h"
kollo's avatar
kollo committed
19 20
#include "x11basic.h"
#include "xbasic.h"
21
#include "memory.h"
kollo's avatar
kollo committed
22
#include "type.h"
kollo's avatar
kollo committed
23
#include "parser.h"
kollo's avatar
kollo committed
24
#include "variablen.h"
kollo's avatar
kollo committed
25
#include "parameter.h"
kollo's avatar
kollo committed
26
#include "functions.h"
kollo's avatar
kollo committed
27
#include "number.h"
kollo's avatar
kollo committed
28
#include "bytecode.h"
kollo's avatar
kollo committed
29 30
#include "array.h"
#include "io.h"
kollo's avatar
kollo committed
31
#include "virtual-machine.h"
kollo's avatar
kollo committed
32 33 34

extern int datapointer;

kollo's avatar
kollo committed
35 36 37 38 39 40 41 42 43 44 45 46 47 48


/* Aus Geschwindigkeitsgruenden kann der verbose mode abgeschaltet werden, wenn er keinen sinn
macht (z.B. beim Android) */
// #define USE_VERBODE

#ifdef USE_VERBOSE
extern int verbose;
#define  VERBOSE(...)  if(verbose) printf(__VA_ARGS__)
#else 
#define  VERBOSE(...) 
#endif

#define TYPEMISMATCH(...) printf("ERROR: type mismatch for %s.\n",__VA_ARGS__)
kollo's avatar
kollo committed
49
#define VMERROR(a,...) {printf("VM-ERROR: " a "\n",##__VA_ARGS__);batch=0;}
kollo's avatar
kollo committed
50 51 52 53 54 55 56 57 58 59 60 61 62

/*for every platform where no real compiler exists define some functions
  static --> higher performance */

#if defined ANDROID || defined WINDOWS
#define ISTATIC inline static
#define STATIC static
#else
#define ISTATIC
#define STATIC
#endif


kollo's avatar
kollo committed
63 64 65
char *rodata=NULL;


kollo's avatar
kollo committed
66

kollo's avatar
kollo committed
67 68 69 70 71

#define vm_x2f(a) cast_to_real(a-1)
#define vm_x2c(a) cast_to_complex(a-1)
#define vm_x2i(a) cast_to_int(a-1)
#define vm_x2ai(a) cast_to_arbint(a-1)
kollo's avatar
kollo committed
72

kollo's avatar
kollo committed
73 74
STATIC int vm_add(PARAMETER *sp) {    /* binaer addition */
  VERBOSE("vm_add ");
kollo's avatar
kollo committed
75
  sp--;
kollo's avatar
kollo committed
76 77 78 79 80 81 82 83 84 85
  int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
  cast_to_x(sp,rt);
  cast_to_x(sp-1,rt);
  switch(rt) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer+=sp->integer; break;
  case PL_COMPLEX: sp[-1].imag+=sp->imag;
  case PL_FLOAT:   sp[-1].real+=sp->real;       break;
  case PL_ARBINT:  mpz_add(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);  break;
  case PL_STRING: {
    STRING a;
kollo's avatar
kollo committed
86 87
    a.pointer=sp[-1].pointer;
    a.len=sp[-1].integer;
kollo's avatar
kollo committed
88 89
    sp[-1].pointer=malloc(a.len+sp->integer+1);
    sp[-1].integer=a.len+sp->integer;
kollo's avatar
kollo committed
90
    memcpy(sp[-1].pointer,a.pointer,a.len);
kollo's avatar
kollo committed
91
    memcpy(sp[-1].pointer+a.len,sp->pointer,sp->integer);
kollo's avatar
kollo committed
92
    free(a.pointer);
kollo's avatar
kollo committed
93 94 95 96
    }
    break;
  case PL_ARRAY: {
    ARRAY a;
kollo's avatar
kollo committed
97
    a=*((ARRAY *)&(sp[-1].integer));
kollo's avatar
kollo committed
98
    array_add(a,*((ARRAY *)&(sp->integer)));
kollo's avatar
kollo committed
99
    *((ARRAY *)&(sp[-1].integer))=a;
kollo's avatar
kollo committed
100 101 102 103 104 105 106 107 108 109 110 111
    }
    break;
  default: TYPEMISMATCH("ADD");
  }
  free_parameter(sp);
  return(-1);
}
STATIC int vm_and(PARAMETER *sp) {    /* binaer addition */
  VERBOSE("vm_and ");
  sp--;
  if(sp[-1].typ==PL_INT && sp[0].typ==PL_INT) {
    sp[-1].integer&=sp->integer;
kollo's avatar
kollo committed
112
  } else {
kollo's avatar
kollo committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
    cast_to_arbint(sp);
    cast_to_arbint(sp-1);
    mpz_and(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);
  }
  free_parameter(sp);
  return(-1);
}
STATIC int vm_or(PARAMETER *sp) {    /* binaer addition */
  VERBOSE("vm_or ");
  sp--;
  if(sp[-1].typ==PL_INT && sp[0].typ==PL_INT) {
    sp[-1].integer|=sp->integer;
  } else {
    cast_to_arbint(sp);
    cast_to_arbint(sp-1);
    mpz_ior(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);
kollo's avatar
kollo committed
129
  }
kollo's avatar
kollo committed
130
  free_parameter(sp);
kollo's avatar
kollo committed
131 132
  return(-1);
}
kollo's avatar
kollo committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
STATIC int vm_xor(PARAMETER *sp) {    /* binaer addition */
  VERBOSE("vm_xor ");
  sp--;
  if(sp[-1].typ==PL_INT && sp[0].typ==PL_INT) {
    sp[-1].integer^=sp->integer;
  } else {
    cast_to_arbint(sp);
    cast_to_arbint(sp-1);
    mpz_eor(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);
  }
  free_parameter(sp);
  return(-1);
}
STATIC int vm_not(PARAMETER *sp) {    /* binaer addition */
  VERBOSE("vm_not ");
  if(sp[-1].typ==PL_INT) {
    sp[-1].integer=~(sp[-1].integer);
  } else {
    cast_to_arbint(sp-1);
    mpz_com(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer);
  }
  return(0);
}
STATIC int vm_sub(PARAMETER *sp) {    /* binaer subtraktion */
kollo's avatar
kollo committed
157
  VERBOSE("vm_sub ");
kollo's avatar
kollo committed
158
  sp--;
kollo's avatar
kollo committed
159 160 161 162 163 164 165 166 167 168
  int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
  cast_to_x(sp,rt);
  cast_to_x(sp-1,rt);
  switch(rt) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer-=sp->integer; break;
  case PL_COMPLEX: sp[-1].imag-=sp->imag;
  case PL_FLOAT:   sp[-1].real-=sp->real;       break;
  case PL_ARBINT:  mpz_sub(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);  break;
  case PL_ARRAY: {
    ARRAY a;
kollo's avatar
kollo committed
169
    a=*((ARRAY *)&(sp[-1].integer));
kollo's avatar
kollo committed
170
    array_sub(a,*((ARRAY *)&(sp->integer)));
kollo's avatar
kollo committed
171
    *((ARRAY *)&(sp[-1].integer))=a;
kollo's avatar
kollo committed
172 173 174
    }
    break;
  default: TYPEMISMATCH("SUB");
kollo's avatar
kollo committed
175
  }
kollo's avatar
kollo committed
176
  free_parameter(sp);
kollo's avatar
kollo committed
177 178
  return(-1);
}
kollo's avatar
kollo committed
179
STATIC int vm_mul(PARAMETER *sp) {    /* binaer multiplikation */
kollo's avatar
kollo committed
180
  VERBOSE("vm_mul ");
kollo's avatar
kollo committed
181
  sp--;
kollo's avatar
kollo committed
182 183 184
  int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
  cast_to_x(sp,rt);
  cast_to_x(sp-1,rt);
185
 
kollo's avatar
kollo committed
186 187 188 189 190 191 192
  switch(rt) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer*=sp->integer; break;
  case PL_COMPLEX: *((COMPLEX *)&(sp[-1].real))=complex_mul(*((COMPLEX *)&(sp[-1].real)),*((COMPLEX *)&(sp[0].real)));break;
  case PL_FLOAT:   sp[-1].real*=sp->real;       break;
  case PL_ARBINT:  mpz_mul(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);  break;
  case PL_ARRAY: {
    ARRAY a;
kollo's avatar
kollo committed
193
    a=*((ARRAY *)&(sp[-1].integer));
kollo's avatar
kollo committed
194 195 196 197 198
    mul_array(a,*((ARRAY *)&(sp->integer)));
    *((ARRAY *)&(sp[-1].integer))=a;
    }
    break;
  default: TYPEMISMATCH("MUL");
kollo's avatar
kollo committed
199
  }
kollo's avatar
kollo committed
200
  free_parameter(sp);
kollo's avatar
kollo committed
201 202
  return(-1);
}
kollo's avatar
kollo committed
203 204 205 206 207 208

/*  Hier kann man bei den arbint operationen noch optimieren: 
    der zweite Operand darf auch long sein....*/


STATIC int vm_pow(PARAMETER *sp) {    /* binaer potenzieren */
kollo's avatar
kollo committed
209
  VERBOSE("vm_pow ");
kollo's avatar
kollo committed
210
  sp--;
kollo's avatar
kollo committed
211
  int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
212 213 214 215 216
  if(rt!=PL_INT) { /* Bei Int sind exponent und operand beide int*/
    if(rt==PL_ARBINT) cast_to_x(sp,PL_INT);  /*  Hm ...*/
    else cast_to_x(sp,rt);
    cast_to_x(sp-1,rt);
  }
kollo's avatar
kollo committed
217 218 219
  switch(rt) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_COMPLEX: *((COMPLEX *)&(sp[-1].real))=complex_pow(*((COMPLEX *)&(sp[-1].real)),*((COMPLEX *)&(sp[0].real)));break;
  case PL_FLOAT:   sp[-1].real=pow((sp-1)->real,sp->real);       break;
220
  case PL_INT:   sp[-1].integer=(int)pow((sp-1)->integer,sp->integer);       break;
kollo's avatar
kollo committed
221 222
  case PL_ARBINT:  mpz_pow_ui(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,sp->integer);  break;
  default: TYPEMISMATCH("POW");
kollo's avatar
kollo committed
223
  }
kollo's avatar
kollo committed
224
  free_parameter(sp);
kollo's avatar
kollo committed
225 226
  return(-1);
}
kollo's avatar
kollo committed
227 228

STATIC int vm_div(PARAMETER *sp) {    /* binaer dividieren, ggf integer */
kollo's avatar
kollo committed
229
  VERBOSE("vm_div ");
kollo's avatar
kollo committed
230
  sp--;
kollo's avatar
kollo committed
231 232 233 234 235 236 237 238 239
  int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'/'));
  if(rt==ARBFLOATTYP || rt==ARBCOMPLEXTYP) rt=ARBINTTYP;
  cast_to_x(sp,rt);
  cast_to_x(sp-1,rt);
  switch(rt) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_COMPLEX: *((COMPLEX *)&(sp[-1].real))=complex_div(*((COMPLEX *)&(sp[-1].real)),*((COMPLEX *)&(sp[0].real)));break;
  case PL_FLOAT:   sp[-1].real/=sp->real;       break;
  case PL_ARBINT:  mpz_div(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);  break;
  default: TYPEMISMATCH("DIV");
kollo's avatar
kollo committed
240
  }
kollo's avatar
kollo committed
241
  free_parameter(sp);
kollo's avatar
kollo committed
242 243
  return(-1);
}
kollo's avatar
kollo committed
244 245 246 247 248




STATIC int vm_mod(PARAMETER *sp) {    /* binaer rest */
kollo's avatar
kollo committed
249
  VERBOSE("vm_mod ");
kollo's avatar
kollo committed
250
  sp--;
kollo's avatar
kollo committed
251 252 253 254 255 256 257 258
  int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
  cast_to_x(sp,rt);
  cast_to_x(sp-1,rt);
  switch(rt) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer%=sp->integer; break;
  case PL_FLOAT:   sp[-1].real=fmod(sp[-1].real,sp->real);       break;
  case PL_ARBINT:  mpz_mod(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer);  break;
  default: TYPEMISMATCH("MOD");
kollo's avatar
kollo committed
259
  }
kollo's avatar
kollo committed
260
  free_parameter(sp);
kollo's avatar
kollo committed
261 262
  return(-1);
}
kollo's avatar
kollo committed
263 264


kollo's avatar
kollo committed
265
STATIC int vm_equal(PARAMETER *sp) {    /* binaer vergleich */
kollo's avatar
kollo committed
266
  VERBOSE("vm_equal ");
kollo's avatar
kollo committed
267
  sp--;
kollo's avatar
kollo committed
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
  if(sp->typ!=(sp-1)->typ) {
    int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
    if(rt==PL_LEER) {  /*  Wenn die Typen inkompatibel sind, dann ungleich!*/
      free_parameter(sp);
      free_parameter(sp-1);
      (sp-1)->integer=0;
      (sp-1)->typ=PL_INT;
      return(-1);
    }
    cast_to_x(sp,rt);
    cast_to_x(sp-1,rt);
  }
  switch(sp->typ) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer=(sp[-1].integer==sp[0].integer)?-1:0; break;
  case PL_COMPLEX: sp[-1].integer=(sp[-1].real==sp[0].real && sp[-1].imag==sp[0].imag)?-1:0; break;
  case PL_FLOAT:   sp[-1].integer=(sp[-1].real==sp[0].real)?-1:0;  break;
  case PL_ARBINT:  sp[-1].integer=(mpz_cmp(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer)==0)?-1:0;  break;
  case PL_STRING: {
    int v=(sp[-1].integer-sp[0].integer);
    if(v==0) v=memcmp(sp[-1].pointer,sp[0].pointer,sp[-1].integer);
kollo's avatar
kollo committed
288
    sp[-1].integer=v?0:-1;
kollo's avatar
kollo committed
289 290 291
    }
    break;
  case PL_ARRAY:    /*   Array compare haben wir noch nicht .....*/
kollo's avatar
kollo committed
292
    
kollo's avatar
kollo committed
293 294 295
    xberror(9,"Compare ARRAY"); /*Function or command %s not implemented*/
    break;
  default: TYPEMISMATCH("EQUAL");
kollo's avatar
kollo committed
296
  }
kollo's avatar
kollo committed
297 298 299
  free_parameter(sp);
  free_parameter(sp-1);
  (sp-1)->typ=PL_INT;
kollo's avatar
kollo committed
300 301
  return(-1);
}
kollo's avatar
kollo committed
302 303 304 305



STATIC int vm_greater(PARAMETER *sp) {    /* binaer groesser vergleich */
kollo's avatar
kollo committed
306
  VERBOSE("vm_greater ");
kollo's avatar
kollo committed
307
  sp--;
kollo's avatar
kollo committed
308 309 310 311 312 313 314 315 316 317 318 319
  if(sp->typ!=(sp-1)->typ) {
    int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
    cast_to_x(sp,rt);
    cast_to_x(sp-1,rt);
  }
  switch(sp->typ) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer=(sp[-1].integer>sp[0].integer)?-1:0; break;
  case PL_COMPLEX: sp[-1].integer=(hypot(sp[-1].real,sp[-1].imag)>hypot(sp[0].real,sp[0].imag))?-1:0; break;
  case PL_FLOAT:   sp[-1].integer=(sp[-1].real>sp[0].real)?-1:0;  break;
  case PL_ARBINT:  sp[-1].integer=(mpz_cmp(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer)>0)?-1:0;  break;
  case PL_STRING: {
    int v=memcmp(sp[-1].pointer,sp[0].pointer,min(sp[-1].integer,sp->integer)+1);
kollo's avatar
kollo committed
320
    sp[-1].integer=(v>0)?-1:0;
kollo's avatar
kollo committed
321 322 323 324 325 326 327
    }
    break;
  case PL_ARRAY:    /*   Array compare haben wir noch nicht .....*/
    
    xberror(9,"Compare ARRAY"); /*Function or command %s not implemented*/
    break;
  default: TYPEMISMATCH("GREATER");
kollo's avatar
kollo committed
328
  }
kollo's avatar
kollo committed
329 330 331
  free_parameter(sp);
  free_parameter(sp-1);
  (sp-1)->typ=PL_INT;
kollo's avatar
kollo committed
332 333
  return(-1);
}
kollo's avatar
kollo committed
334 335 336


STATIC int vm_less(PARAMETER *sp) {    /* binaer kleiner vergleich */
kollo's avatar
kollo committed
337
  VERBOSE("vm_less ");
kollo's avatar
kollo committed
338
  sp--;
kollo's avatar
kollo committed
339 340 341 342
  if(sp->typ!=(sp-1)->typ) {
    int rt=(PL_CONSTGROUP|combine_type(sp[-1].typ&PL_BASEMASK,sp[0].typ&PL_BASEMASK,'+'));
    cast_to_x(sp,rt);
    cast_to_x(sp-1,rt);
kollo's avatar
kollo committed
343
  }
kollo's avatar
kollo committed
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
  switch(sp->typ) {   /* Jetzt gibt es nur noch zwei gleiche typen.*/
  case PL_INT:     sp[-1].integer=(sp[-1].integer<sp[0].integer)?-1:0; break;
  case PL_COMPLEX: sp[-1].integer=(hypot(sp[-1].real,sp[-1].imag)<hypot(sp[0].real,sp[0].imag))?-1:0; break;
  case PL_FLOAT:   sp[-1].integer=(sp[-1].real<sp[0].real)?-1:0;  break;
  case PL_ARBINT:  sp[-1].integer=(mpz_cmp(*(ARBINT *)(sp-1)->pointer,*(ARBINT *)sp->pointer)<0)?-1:0;  break;
  case PL_STRING: {
    int v=memcmp(sp[-1].pointer,sp[0].pointer,min(sp[-1].integer,sp->integer)+1);
    sp[-1].integer=(v<0)?-1:0;
    }
    break;
  case PL_ARRAY:    /*   Array compare haben wir noch nicht .....*/
    
    xberror(9,"Compare ARRAY"); /*Function or command %s not implemented*/
    break;
  default: TYPEMISMATCH("GREATER");
  }
  free_parameter(sp);
  free_parameter(sp-1);
  (sp-1)->typ=PL_INT;
kollo's avatar
kollo committed
363 364
  return(-1);
}
kollo's avatar
kollo committed
365

kollo's avatar
kollo committed
366
STATIC int vm_sysvar(PARAMETER *sp,int n) {    /*  */
kollo's avatar
kollo committed
367 368 369
  VERBOSE("vm_%s ",sysvars[n].name);
  int typ=sysvars[n].opcode&TYPMASK;
  if(typ==INTTYP) {
kollo's avatar
kollo committed
370 371
    sp->integer=((int (*)())sysvars[n].routine)();
    sp->typ=PL_INT;
kollo's avatar
kollo committed
372
  } else if(typ==FLOATTYP) {
kollo's avatar
kollo committed
373 374 375 376 377 378 379 380
    sp->real=(sysvars[n].routine)();
    sp->typ=PL_FLOAT;
  } else {
    sp->real=0;
    sp->typ=PL_FLOAT;
  }
  return(1);
}
kollo's avatar
kollo committed
381 382
ISTATIC int vm_ssysvar(PARAMETER *sp,int n) {    /*  */
  VERBOSE("vm_%s ",syssvars[n].name);
kollo's avatar
kollo committed
383 384 385 386 387 388
  STRING a=(syssvars[n].routine)();
  sp->integer=a.len;
  sp->pointer=a.pointer;
  sp->typ=PL_STRING;
  return(1);
}
kollo's avatar
kollo committed
389 390
ISTATIC int vm_asysvar(PARAMETER *sp,int n) {    /*  */
  VERBOSE("vm_%s ",sysvars[n].name);
kollo's avatar
kollo committed
391
  VMERROR("#####Sysvar ARRAY: %s not implemented.",sysvars[n].name);
kollo's avatar
kollo committed
392 393 394 395
  xberror(9,"Sysvar ARRAY"); /*Function or command %s not implemented*/
  sp->real=4711;
  sp->typ=PL_FLOAT;
  return(1);
kollo's avatar
kollo committed
396
}
kollo's avatar
kollo committed
397
STATIC int vm_dup(PARAMETER *sp) {    /* dupliziere Parameter */
kollo's avatar
kollo committed
398
  VERBOSE("vm_dup ");
kollo's avatar
kollo committed
399 400 401 402
  sp[0]=sp[-1];
  switch(sp->typ) {
  case PL_KEY:
  case PL_STRING:
kollo's avatar
kollo committed
403 404
    sp[0].pointer=malloc(sp[0].integer+1);
    memcpy(sp[0].pointer,sp[-1].pointer,sp[0].integer+1);
kollo's avatar
kollo committed
405 406
    break;
  case PL_ARBINT:
407
    sp->pointer=malloc(sizeof(ARBINT));
kollo's avatar
kollo committed
408 409 410 411 412
    mpz_init(*(ARBINT *)sp->pointer);
    mpz_set(*(ARBINT *)sp->pointer,*(ARBINT *)(sp-1)->pointer);
    break;
  case PL_ARRAY:
    *(ARRAY *)&(sp->integer)=double_array((ARRAY *)&(sp[-1].integer));
kollo's avatar
kollo committed
413
  }
kollo's avatar
kollo committed
414 415
  return(1);
}
kollo's avatar
kollo committed
416 417
inline static int vm_exch(PARAMETER *sp) {    /*  */
  VERBOSE("vm_exch ");
kollo's avatar
kollo committed
418
  *sp=sp[-1];   
kollo's avatar
kollo committed
419
  sp[-1]=sp[-2];   
kollo's avatar
kollo committed
420
  sp[-2]=*sp;   
kollo's avatar
kollo committed
421 422
  return(0);
}
kollo's avatar
kollo committed
423 424
ISTATIC int vm_neg(PARAMETER *sp) {    /*  */
  VERBOSE("vm_neg ");
kollo's avatar
kollo committed
425 426 427 428 429 430
  switch(sp[-1].typ) {
  case PL_INT:          sp[-1].integer=-sp[-1].integer; break;
  case PL_COMPLEX:      sp[-1].imag=-sp[-1].imag;
  case PL_FLOAT:        sp[-1].real=-sp[-1].real; break;
  case PL_ARBINT:       mpz_neg(*(ARBINT *)sp[-1].pointer,*(ARBINT *)sp[-1].pointer);break;
  default: TYPEMISMATCH("NEG");
kollo's avatar
kollo committed
431
  }
kollo's avatar
kollo committed
432
  return(0);
kollo's avatar
kollo committed
433
}
kollo's avatar
kollo committed
434 435
STATIC int vm_sfunc(PARAMETER *sp,int i, int anzarg) {    /*  */
  VERBOSE("vm_%s(%d) ",psfuncs[i].name,anzarg);
kollo's avatar
kollo committed
436
  if(anzarg<psfuncs[i].pmin) {
kollo's avatar
kollo committed
437
    xberror(42,(char *)psfuncs[i].name); /* Zu wenig Parameter  */
kollo's avatar
kollo committed
438 439 440
    return 1-anzarg;
  }
  if(anzarg>psfuncs[i].pmax && !(psfuncs[i].pmax==-1)) {
kollo's avatar
kollo committed
441
    xberror(45,(char *)psfuncs[i].name); /* Zu viele Parameter  */
kollo's avatar
kollo committed
442 443 444 445 446
    return 1-anzarg;
  } 
  sp-=anzarg;
  if((psfuncs[i].opcode&FM_TYP)==F_SIMPLE || psfuncs[i].pmax==0) {
    STRING s=(psfuncs[i].routine)();
kollo's avatar
kollo committed
447 448 449
    sp->pointer=s.pointer;
    sp->integer=s.len;
    sp->typ=PL_STRING;
kollo's avatar
kollo committed
450 451 452
    return 1-anzarg;
  }  
  if((psfuncs[i].opcode&FM_TYP)==F_ARGUMENT) {
kollo's avatar
kollo committed
453 454 455 456 457 458
    if(sp->typ==PL_KEY) {
      STRING s=(psfuncs[i].routine)(sp->pointer);
      free(sp->pointer);
      sp->pointer=s.pointer;
      sp->integer=s.len;
      sp->typ=PL_STRING;
kollo's avatar
kollo committed
459 460
      return 1-anzarg;
    } else {
kollo's avatar
kollo committed
461
      VMERROR("SFUNC");
kollo's avatar
kollo committed
462 463 464
      return 1-anzarg;
    }
  }
kollo's avatar
kollo committed
465
  if((psfuncs[i].opcode&FM_TYP)==F_PLISTE) {
kollo's avatar
kollo committed
466 467
    PARAMETER *plist;
    STRING s;
kollo's avatar
kollo committed
468 469
    int e=make_pliste3(psfuncs[i].pmin,psfuncs[i].pmax,(unsigned short *)psfuncs[i].pliste,
                 &sp[0],&plist,anzarg);
kollo's avatar
kollo committed
470
    s=(psfuncs[i].routine)(plist,anzarg);
471
    free_pliste(e,plist);
kollo's avatar
kollo committed
472 473
    e=anzarg;
    while(--e>=0) free_parameter(&sp[e]);
kollo's avatar
kollo committed
474 475 476 477 478 479 480 481 482 483 484
    sp[0].pointer=s.pointer;
    sp[0].integer=s.len;
    sp[0].typ=PL_STRING;
    return 1-anzarg;
  }
  if((psfuncs[i].opcode&FM_TYP)==F_SQUICK) {
    STRING a;
    if(sp[0].typ==PL_STRING) {
      a.len=sp[0].integer;
      a.pointer=sp[0].pointer;
    } else 
485
      xberror(47,(char *)psfuncs[i].name); /*  Parameter %s falsch, kein String */
kollo's avatar
kollo committed
486 487
    
    STRING s=(psfuncs[i].routine)(a);
kollo's avatar
kollo committed
488
    free_parameter(sp);
kollo's avatar
kollo committed
489 490 491 492 493 494
    sp[0].pointer=s.pointer;
    sp[0].integer=s.len;
    sp[0].typ=PL_STRING;
    return 1-anzarg;
  }
  if((psfuncs[i].opcode&FM_TYP)==F_IQUICK) {
kollo's avatar
kollo committed
495
    int a=0;
kollo's avatar
kollo committed
496 497
    if(sp[0].typ==PL_INT)        a=sp[0].integer;
    else if(sp[0].typ==PL_FLOAT) a=(int)sp[0].real;
kollo's avatar
kollo committed
498 499
    else TYPEMISMATCH("Funktion");
    
kollo's avatar
kollo committed
500
    STRING s=(psfuncs[i].routine)(a);
kollo's avatar
kollo committed
501
    free_parameter(sp);
kollo's avatar
kollo committed
502 503 504 505 506 507
    sp[0].pointer=s.pointer;
    sp[0].integer=s.len;
    sp[0].typ=PL_STRING;
    return 1-anzarg;
  }

kollo's avatar
kollo committed
508 509
  VMERROR("INCOMPLETE"
       ", this function does not get its parameters.");
kollo's avatar
kollo committed
510 511
  return 1-anzarg;
}
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
STATIC int vm_afunc(PARAMETER *sp,int i, int anzarg) {    /*  */
  VERBOSE("vm_%s(%d) ",psfuncs[i].name,anzarg);
  if(anzarg<pafuncs[i].pmin) {
    xberror(42,(char *)pafuncs[i].name); /* Zu wenig Parameter  */
    return 1-anzarg;
  }
  if(anzarg>pafuncs[i].pmax && !(pafuncs[i].pmax==-1)) {
    xberror(45,(char *)pafuncs[i].name); /* Zu viele Parameter  */
    return 1-anzarg;
  } 
  sp-=anzarg;
  if((pafuncs[i].opcode&FM_TYP)==F_SIMPLE || pafuncs[i].pmax==0) {
    ARRAY arr=(pafuncs[i].routine)();
    *((ARRAY *)&(sp->integer))=arr;
    sp->typ=PL_ARRAY;
    return 1-anzarg;
  }  
  if((pafuncs[i].opcode&FM_TYP)==F_ARGUMENT) {
    if(sp->typ==PL_KEY) {
      ARRAY arr=(pafuncs[i].routine)(sp->pointer);
      free(sp->pointer);
      *((ARRAY *)&(sp->integer))=arr;
      sp->typ=PL_ARRAY;
      return 1-anzarg;
    } else {
      VMERROR("SFUNC");
      return 1-anzarg;
    }
  }
  if((psfuncs[i].opcode&FM_TYP)==F_PLISTE) {
    PARAMETER *plist;
    ARRAY arr;
    int e=make_pliste3(pafuncs[i].pmin,pafuncs[i].pmax,(unsigned short *)pafuncs[i].pliste,
                 &sp[0],&plist,anzarg);
    arr=(pafuncs[i].routine)(plist,anzarg);
    free_pliste(e,plist);
    e=anzarg;
    while(--e>=0) free_parameter(&sp[e]);
    *((ARRAY *)&(sp->integer))=arr;
    sp->typ=PL_ARRAY;
    return 1-anzarg;
  }
  if((pafuncs[i].opcode&FM_TYP)==F_SQUICK) {
    STRING s;
    if(sp->typ==PL_STRING) {
      s.len=sp[0].integer;
      s.pointer=sp[0].pointer;
    } else 
      xberror(47,(char *)pafuncs[i].name); /*  Parameter %s falsch, kein String */
    
    ARRAY arr=(pafuncs[i].routine)(s);
    free_parameter(sp);
    *((ARRAY *)&(sp->integer))=arr;
    sp[0].typ=PL_ARRAY;
    return 1-anzarg;
  }
  if((pafuncs[i].opcode&FM_TYP)==F_AQUICK) {
    ARRAY s;
    if(sp->typ==PL_ARRAY) {
      s=*((ARRAY *)&(sp->integer));
    } else 
      xberror(78,(char *)pafuncs[i].name); /*  Parameter %s falsch, kein Array */
    
    ARRAY arr=(pafuncs[i].routine)(s);
    free_parameter(sp);
    *((ARRAY *)&(sp->integer))=arr;
    sp[0].typ=PL_ARRAY;
    return 1-anzarg;
  }

  VMERROR("INCOMPLETE"
       ", this function does not get its parameters.");
  return 1-anzarg;
}
kollo's avatar
kollo committed
586

kollo's avatar
kollo committed
587 588
STATIC int vm_func(PARAMETER *sp,int i, int anzarg) {    /*  */
  VERBOSE("vm_.%s(%d) ",pfuncs[i].name,anzarg);
kollo's avatar
kollo committed
589
  if(anzarg<pfuncs[i].pmin) {
kollo's avatar
kollo committed
590
    xberror(42,(char *)pfuncs[i].name); /* Zu wenig Parameter  */
kollo's avatar
kollo committed
591 592 593
    return 1-anzarg;
  }
  if((anzarg>pfuncs[i].pmax && !(pfuncs[i].pmax==-1))) {
kollo's avatar
kollo committed
594
    xberror(45,(char *)pfuncs[i].name); /* Zu viele Parameter  */
kollo's avatar
kollo committed
595 596 597 598
    return 1-anzarg;
  } 	      
  sp-=anzarg;
  if((pfuncs[i].opcode&FM_TYP)==F_SIMPLE || pfuncs[i].pmax==0) {
kollo's avatar
kollo committed
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
    switch(pfuncs[i].opcode&FM_RET) {
    case F_IRET: 
       sp->integer=((int (*)())pfuncs[i].routine)();
       sp->typ=PL_INT;
       break;
    case F_CRET:
       *((COMPLEX *)&(sp->real))=((COMPLEX (*)())pfuncs[i].routine)();
       sp->typ=PL_COMPLEX;
       break;
    case F_DRET:
       sp->real=(pfuncs[i].routine)();
       sp->typ=PL_FLOAT;
       break;
    case F_AIRET: 
       sp->pointer=malloc(sizeof(ARBINT));
       mpz_init(*(ARBINT *)sp->pointer);
       ((void (*)())pfuncs[i].routine)(*(ARBINT *)sp->pointer);
       sp->typ=PL_ARBINT;
       break;
    case F_ANYRET:
    case F_NRET:
    case F_ANYIRET:  {
       *sp=((ppfunc)(pfuncs[i].routine))();
       break;
     }
    default: xberror(13,"");  /* Type mismatch */
kollo's avatar
kollo committed
625 626
    }
    return 1-anzarg;
kollo's avatar
kollo committed
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
  } else if((pfuncs[i].opcode&FM_TYP)==F_ARGUMENT) {
    switch(pfuncs[i].opcode&FM_RET) {
    case F_IRET: 
       sp->integer=((int (*)())pfuncs[i].routine)(sp->pointer);
       sp->typ=PL_INT;
       free(sp->pointer);
       break;
    case F_CRET:
       *((COMPLEX *)&(sp->real))=((COMPLEX (*)())pfuncs[i].routine)(sp->pointer);
       sp->typ=PL_COMPLEX;
       free(sp->pointer);
       break;
    case F_DRET:
       sp->real=(pfuncs[i].routine)(sp->pointer);
       sp->typ=PL_FLOAT;
       free(sp->pointer);
       break;
    case F_AIRET: {
       ARBINT b;
       mpz_init(b);
       ((void (*)())pfuncs[i].routine)(b,sp->pointer);
       free_parameter(sp);
       sp->pointer=malloc(sizeof(ARBINT));
       mpz_init(*(ARBINT *)sp->pointer);
       mpz_set(*(ARBINT *)sp->pointer,b);
       mpz_clear(b);
       sp->typ=PL_ARBINT;
       }
       break;
    case F_ANYRET: 
    case F_NRET:
    case F_ANYIRET: {
       PARAMETER b=((ppfunc)(pfuncs[i].routine))(sp->pointer);
       free_parameter(sp);
       *sp=b;
       break;
     }
    default: xberror(13,"");  /* Type mismatch */
       free(sp->pointer);
    }
    return 1-anzarg;
  } else if((pfuncs[i].opcode&FM_TYP)==F_PLISTE) {
    PARAMETER *plist;
kollo's avatar
kollo committed
670
    PARAMETER *rpar=calloc(1,sizeof(PARAMETER));
kollo's avatar
kollo committed
671 672 673
    int e=make_pliste3(pfuncs[i].pmin,pfuncs[i].pmax,(unsigned short *)pfuncs[i].pliste,sp,&plist,anzarg);
    switch(pfuncs[i].opcode&FM_RET) {
    case F_IRET: 
kollo's avatar
kollo committed
674 675
      rpar->integer=((int (*)())pfuncs[i].routine)(plist,anzarg);
      rpar->typ=PL_INT;
kollo's avatar
kollo committed
676 677
      break;
    case F_CRET:
kollo's avatar
kollo committed
678 679
      *((COMPLEX *)&(rpar->real))=((COMPLEX (*)())pfuncs[i].routine)(plist,anzarg);
      rpar->typ=PL_COMPLEX;
kollo's avatar
kollo committed
680 681
      break;
    case F_DRET:
kollo's avatar
kollo committed
682 683
      rpar->real=(pfuncs[i].routine)(plist,anzarg);
      rpar->typ=PL_FLOAT;
kollo's avatar
kollo committed
684 685
      break;
    case F_AIRET: 
kollo's avatar
kollo committed
686 687 688 689
       rpar->typ=PL_ARBINT;
       rpar->pointer=malloc(sizeof(ARBINT));
       mpz_init(*(ARBINT *)rpar->pointer);
       ((void (*)())pfuncs[i].routine)(*(ARBINT *)rpar->pointer,plist,anzarg);
kollo's avatar
kollo committed
690 691 692 693
       break;
    case F_ANYRET:
    case F_NRET:
    case F_ANYIRET:
kollo's avatar
kollo committed
694
       *rpar=((ppfunc)(pfuncs[i].routine))(plist,anzarg);
kollo's avatar
kollo committed
695 696
       break;
    default: xberror(13,"");  /* Type mismatch */
kollo's avatar
kollo committed
697
    }
698
    free_pliste(e,plist);
kollo's avatar
kollo committed
699 700
    e=anzarg;
    while(--e>=0) free_parameter(&sp[e]);
kollo's avatar
kollo committed
701
    *sp=*rpar;free(rpar);
kollo's avatar
kollo committed
702 703
    return 1-anzarg;
  }
kollo's avatar
kollo committed
704
 
kollo's avatar
kollo committed
705
  if(pfuncs[i].pmax==1 && (pfuncs[i].opcode&FM_TYP)==F_DQUICK) {
kollo's avatar
kollo committed
706
    if(anzarg>0) cast_to_real(&sp[0]);
kollo's avatar
kollo committed
707
    if((pfuncs[i].opcode&FM_RET)==F_IRET) {
kollo's avatar
kollo committed
708 709
      sp[0].integer=((int (*)())pfuncs[i].routine)(sp[0].real);
      sp[0].typ=PL_INT;
kollo's avatar
kollo committed
710 711 712
    } else if((pfuncs[i].opcode&FM_RET)==F_CRET) {
      *((COMPLEX *)&(sp[0].real))=((COMPLEX (*)())pfuncs[i].routine)(sp[0].real);
      sp->typ=PL_COMPLEX;
kollo's avatar
kollo committed
713 714 715 716 717 718 719
    } else {
      sp[0].real=(pfuncs[i].routine)(sp[0].real);
      sp[0].typ=PL_FLOAT;
    }   
    return 1-anzarg;
  }
  if(pfuncs[i].pmax==2 && (pfuncs[i].opcode&FM_TYP)==F_DQUICK) {
kollo's avatar
kollo committed
720 721
    if(anzarg>0) cast_to_real(&sp[0]);
    if(anzarg>1) cast_to_real(&sp[1]);
kollo's avatar
kollo committed
722
    if((pfuncs[i].opcode&FM_RET)==F_IRET) {
kollo's avatar
kollo committed
723 724
      sp[0].integer=((int (*)())pfuncs[i].routine)(sp[0].real,sp[1].real);
      sp[0].typ=PL_INT;
kollo's avatar
kollo committed
725 726 727
    } else if((pfuncs[i].opcode&FM_RET)==F_CRET) {
      *((COMPLEX *)&(sp[0].real))=((COMPLEX (*)())pfuncs[i].routine)(sp[0].real,sp[1].real);
      sp->typ=PL_COMPLEX;
kollo's avatar
kollo committed
728 729 730 731 732 733 734
    } else {
      sp[0].real=(pfuncs[i].routine)(sp[0].real,sp[1].real);
      sp[0].typ=PL_FLOAT;
    }   
    return 1-anzarg;
  }
  if(pfuncs[i].pmax==1 && (pfuncs[i].opcode&FM_TYP)==F_IQUICK) {
kollo's avatar
kollo committed
735
    if(anzarg>0) cast_to_int(&sp[0]);
kollo's avatar
kollo committed
736
    if((pfuncs[i].opcode&FM_RET)==F_IRET) {
kollo's avatar
kollo committed
737 738
      sp[0].integer=((int (*)())pfuncs[i].routine)(sp[0].integer);
      sp[0].typ=PL_INT;
kollo's avatar
kollo committed
739 740 741
    } else if((pfuncs[i].opcode&FM_RET)==F_CRET) {
      *((COMPLEX *)&(sp[0].real))=((COMPLEX (*)())pfuncs[i].routine)(sp[0].integer);
      sp->typ=PL_COMPLEX;
kollo's avatar
kollo committed
742 743 744 745 746 747 748
    } else {
      sp[0].real=(pfuncs[i].routine)(sp[0].integer);
      sp[0].typ=PL_FLOAT;
    }   
    return 1-anzarg;
  }
  if(pfuncs[i].pmax==2 && (pfuncs[i].opcode&FM_TYP)==F_IQUICK) {
kollo's avatar
kollo committed
749 750
    if(anzarg>0) cast_to_int(&sp[0]);
    if(anzarg>1) cast_to_int(&sp[1]);
kollo's avatar
kollo committed
751
    if((pfuncs[i].opcode&FM_RET)==F_IRET) {
kollo's avatar
kollo committed
752 753
      sp[0].integer=((int (*)())pfuncs[i].routine)(sp[0].integer,sp[1].integer);
      sp[0].typ=PL_INT;
kollo's avatar
kollo committed
754 755 756
    } else if((pfuncs[i].opcode&FM_RET)==F_CRET) {
      *((COMPLEX *)&(sp[0].real))=((COMPLEX (*)())pfuncs[i].routine)(sp[0].integer,sp[1].integer);
      sp->typ=PL_COMPLEX;
kollo's avatar
kollo committed
757
    } else {
kollo's avatar
kollo committed
758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773
      sp->real=(pfuncs[i].routine)(sp[0].integer,sp[1].integer);
      sp->typ=PL_FLOAT;
    }   
    return 1-anzarg;
  }
  if(pfuncs[i].pmax==1 && (pfuncs[i].opcode&FM_TYP)==F_CQUICK) {
    if(anzarg>0) cast_to_complex(sp);
    COMPLEX *a=(COMPLEX *)(&(sp[0].real));
    if((pfuncs[i].opcode&FM_RET)==F_IRET) {
      sp[0].integer=((int (*)())pfuncs[i].routine)(*a);
      sp[0].typ=PL_INT;
    } else if((pfuncs[i].opcode&FM_RET)==F_CRET) {
      *((COMPLEX *)&(sp[0].real))=((COMPLEX (*)())pfuncs[i].routine)(*a);
      sp->typ=PL_COMPLEX;
    } else {
      sp[0].real=(pfuncs[i].routine)(*a);
kollo's avatar
kollo committed
774 775 776 777 778 779
      sp[0].typ=PL_FLOAT;
    }   
    return 1-anzarg;
  }
  if(pfuncs[i].pmax==1 && (pfuncs[i].opcode&FM_TYP)==F_SQUICK) {
    STRING a;
kollo's avatar
kollo committed
780 781 782
    if(sp->typ==PL_STRING) {
      a.len=sp->integer;
      a.pointer=sp->pointer;
783 784 785 786 787
    } else {
      a.len=0;
      a.pointer=NULL;
      xberror(47,(char *)pfuncs[i].name); /*  Parameter %s falsch, kein String */
    }
kollo's avatar
kollo committed
788
//    printf("Got a string: <%s>\n",a.pointer);
kollo's avatar
kollo committed
789
    if((pfuncs[i].opcode&FM_RET)==F_IRET) {
kollo's avatar
kollo committed
790 791
      sp->integer=((int (*)())pfuncs[i].routine)(a);
      sp->typ=PL_INT;
kollo's avatar
kollo committed
792 793 794 795
    } else if((pfuncs[i].opcode&FM_RET)==F_CRET) {
      sp->real=(double)((int (*)())pfuncs[i].routine)(a);
      sp->imag=0;
      sp->typ=PL_COMPLEX;
kollo's avatar
kollo committed
796
    } else {
kollo's avatar
kollo committed
797 798
      sp->real=(pfuncs[i].routine)(a);
      sp->typ=PL_FLOAT;
kollo's avatar
kollo committed
799
    }
kollo's avatar
kollo committed
800
    free(a.pointer);
kollo's avatar
kollo committed
801 802
    return 1-anzarg;
  }
kollo's avatar
kollo committed
803 804
  VMERROR("INCOMPLETE"
       ", this function does not get its parameters.");
kollo's avatar
kollo committed
805 806
  return 1-anzarg;
}
kollo's avatar
kollo committed
807

kollo's avatar
kollo committed
808 809
STATIC int vm_comm(PARAMETER *sp,int i, int anzarg) {    /*  */
  VERBOSE("vm_%s(%d)_%d\n",comms[i].name,anzarg,i);
kollo's avatar
kollo committed
810
// printf("SP=%p\n",sp);
kollo's avatar
kollo committed
811 812 813 814 815 816 817 818 819 820
#ifdef EXTRACHECK
  if(anzarg<comms[i].pmin) {
    xberror(42,comms[i].name); /* Zu wenig Parameter  */
    return -anzarg;
  }
  if((anzarg>comms[i].pmax && !(comms[i].pmax==-1)) || (anzarg && (comms[i].opcode&PM_TYP)==P_SIMPLE)) {
    xberror(45,comms[i].name); /* Zu viele Parameter  */
    return -anzarg;
  }  
#endif
kollo's avatar
kollo committed
821 822 823 824
  switch(comms[i].opcode&PM_TYP) {
  case P_IGNORE: return -anzarg;
  case P_ARGUMENT: {
    char *w2=sp[-1].pointer;
kollo's avatar
kollo committed
825
    (comms[i].routine)(w2);    
kollo's avatar
kollo committed
826
    free_parameter(&sp[-1]);
kollo's avatar
kollo committed
827
    }
kollo's avatar
kollo committed
828
    return -anzarg;
kollo's avatar
kollo committed
829
  case P_SIMPLE:
kollo's avatar
kollo committed
830 831
    (comms[i].routine)();
    return -anzarg;
kollo's avatar
kollo committed
832
  case P_PLISTE: {
kollo's avatar
kollo committed
833
    PARAMETER *plist;
kollo's avatar
kollo committed
834 835
    int e=make_pliste3(comms[i].pmin,comms[i].pmax,(unsigned short *)comms[i].pliste,
                 &sp[-anzarg],&plist,anzarg);
836 837
    if(e>=0) (comms[i].routine)(plist,e);
    free_pliste(e,plist);
kollo's avatar
kollo committed
838 839 840 841
    e=anzarg;
  //  printf("Parameters to clear:  (%d)\n",e);
  //  dump_parameterlist(&sp[-e],e);
    while(--e>=0) free_parameter(&sp[-e-1]);
kollo's avatar
kollo committed
842
    }
kollo's avatar
kollo committed
843 844
    return -anzarg;
  } 
kollo's avatar
kollo committed
845 846
  VMERROR("INCOMPLETE"
       ", this function does not get its parameters.");
kollo's avatar
kollo committed
847 848
  return -anzarg;
}
kollo's avatar
kollo committed
849 850 851

ISTATIC int vm_pushvv(int vnr,PARAMETER *sp) {    /*  */
    VERBOSE("vm_pushvv_%d\n",vnr);
kollo's avatar
kollo committed
852 853
    sp->integer=vnr;
    sp->pointer=varptr_indexliste(&variablen[vnr],NULL,0);
kollo's avatar
kollo committed
854 855 856
    int typ=variablen[vnr].typ;
    if(typ==ARRAYTYP) typ|=variablen[vnr].pointer.a->typ;
    sp->typ=(PL_VARGROUP|variablen[vnr].typ);
kollo's avatar
kollo committed
857 858
    return(1);
}
kollo's avatar
kollo committed
859

kollo's avatar
kollo committed
860 861

static void make_indexliste_plist(int dim, PARAMETER *p, int *index) {
kollo's avatar
kollo committed
862
  while(--dim>=0) index[dim]=p2int(&p[dim]);
kollo's avatar
kollo committed
863 864 865 866 867
}




kollo's avatar
kollo committed
868
STATIC int vm_pushvvi(int vnr,PARAMETER *sp,int dim) {    /*  */
kollo's avatar
kollo committed
869 870 871
  int *indexliste=NULL;
  PARAMETER *p=&sp[-dim];
  //dump_parameterlist(p,dim);
kollo's avatar
kollo committed
872
  VERBOSE("vm_pushvvi_%d\n",vnr);
kollo's avatar
kollo committed
873 874 875 876 877

  if(dim) {
    indexliste=(int *)malloc(dim*sizeof(int));
    make_indexliste_plist(dim,p,indexliste);
 //   printf("Index=%d\n",*indexliste); 
kollo's avatar
kollo committed
878
  }
kollo's avatar
kollo committed
879 880 881
  int e=dim;
  while(--e>=0) free_parameter(&p[e]);
  bzero(p,sizeof(PARAMETER));
kollo's avatar
kollo committed
882 883 884
  p->integer=vnr;
  p->pointer=varptr_indexliste(&variablen[vnr],indexliste,dim);
 // printf("Pointer=%x\n",(int)p->pointer);
kollo's avatar
kollo committed
885
  p->typ=(PL_VARGROUP|variablen[vnr].pointer.a->typ);
kollo's avatar
kollo committed
886
  if(indexliste) free(indexliste);
kollo's avatar
kollo committed
887
  return(-dim+1);
kollo's avatar
kollo committed
888
}
kollo's avatar
kollo committed
889 890


kollo's avatar
kollo committed
891 892 893
ISTATIC int vm_zuweis(int vnr,PARAMETER *sp) {    /*  */
  VERBOSE("vm_zuweis_%d\n",vnr);
  zuweis_v_parameter(&variablen[vnr],&sp[-1]);
kollo's avatar
kollo committed
894
  free_parameter(sp-1);
kollo's avatar
kollo committed
895 896 897 898
  return(-1);
}

STATIC int vm_zuweisindex(int vnr,PARAMETER *sp,int dim) {    /*  */
kollo's avatar
kollo committed
899
  int *indexliste=NULL;
kollo's avatar
kollo committed
900
  VERBOSE("vm_zuweisindex_%d_%d \n",vnr,dim);
kollo's avatar
kollo committed
901 902 903 904
//printf("ZUWEISINDEX: vnr=%d dim=%d",vnr,dim);
//dump_parameterlist(&sp[-dim],dim);
//printf("value: ");
//dump_parameterlist(&sp[-dim-1],1);
kollo's avatar
kollo committed
905

kollo's avatar
kollo committed
906 907 908 909 910
//printf("vdim=%d\n",variablen[vnr].opcode);

  if(dim) {
    indexliste=(int *)malloc(dim*sizeof(int));
    make_indexliste_plist(dim,&sp[-dim],indexliste); 
kollo's avatar
kollo committed
911
  }
kollo's avatar
kollo committed
912 913
  zuweispbyindex(vnr,indexliste,dim,&sp[-dim-1]);
  free(indexliste);
kollo's avatar
kollo committed
914
  free_parameter(&sp[-dim-1]);
kollo's avatar
kollo committed
915
  return(-dim-1);
kollo's avatar
kollo committed
916 917
}

kollo's avatar
kollo committed
918
STATIC int vm_pusharrayelem(int vnr, PARAMETER *sp, int dim) {    /*  */
kollo's avatar
kollo committed
919 920 921
  int typ;
  int *indexliste;
  typ=variablen[vnr].typ;
kollo's avatar
kollo committed
922
  VERBOSE("vm_pusharrayelem_%d_%d ",vnr,dim);
kollo's avatar
kollo committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942

//printf("\nPUSHARRAYELEM: vnr=%d dim=%d\n",vnr,dim);
//dump_parameterlist(&sp[-dim],dim);

  if(typ==ARRAYTYP) {

    if(dim>0) {
      char *varptr;
      int subtyp=variablen[vnr].pointer.a->typ;
      PARAMETER *p=&sp[-dim];
      indexliste=(int *)malloc(dim*sizeof(int));
      make_indexliste_plist(dim,&sp[-dim],indexliste); 
      varptr=varptr_indexliste(&variablen[vnr],indexliste,dim);
      free_parameter(p);
      if(subtyp==INTTYP) {
        p->typ=PL_INT;
	p->integer=*((int *)varptr);
      } else if(subtyp==FLOATTYP) {
        p->typ=PL_FLOAT;
	p->real=*((double *)varptr);
kollo's avatar
kollo committed
943 944 945 946 947 948 949 950
      } else if(subtyp==COMPLEXTYP) {
        p->typ=PL_COMPLEX;
	*(COMPLEX *)&p->real=*((COMPLEX *)varptr);
      } else if(subtyp==ARBINTTYP) {
        p->typ=PL_ARBINT;
	p->pointer=malloc(sizeof(ARBINT));
	mpz_init(*(ARBINT *)p->pointer);
	mpz_set(*(ARBINT *)p->pointer,*((ARBINT *)varptr));
kollo's avatar
kollo committed
951 952 953 954 955 956
      } else if(subtyp==STRINGTYP) {
        p->typ=PL_STRING;
	p->integer=((STRING *)varptr)->len;
	p->pointer=malloc(p->integer+1);
	memcpy(p->pointer,((STRING *)varptr)->pointer,p->integer);
	((char *)p->pointer)[p->integer]=0;
kollo's avatar
kollo committed
957
      } else VMERROR("pusharrayelem"); 
kollo's avatar
kollo committed
958
      free(indexliste);
kollo's avatar
kollo committed
959 960
    } else VMERROR("ARRAYELEM"); 
  } else VMERROR("ARRAYELEM"); 
kollo's avatar
kollo committed
961 962

  return(-dim+1);
kollo's avatar
kollo committed
963
}
kollo's avatar
kollo committed
964

kollo's avatar
kollo committed
965
STATIC void  push_v(PARAMETER *p, const VARIABLE *v) {
kollo's avatar
kollo committed
966
  p->panzahl=0;
kollo's avatar
kollo committed
967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
  p->typ=(PL_CONSTGROUP|v->typ);
  switch(v->typ) {
  case INTTYP:   p->integer=*(v->pointer.i); return;
  case FLOATTYP: p->real=*(v->pointer.f);    return;
  case COMPLEXTYP: *((COMPLEX *)&(p->real))=*(v->pointer.c); return;
  case STRINGTYP: *((STRING *)&(p->integer))=double_string(v->pointer.s); return;
  case ARRAYTYP:  *((ARRAY *)&(p->integer))=double_array(v->pointer.a);   return;
  case ARBINTTYP: 
    p->pointer=malloc(sizeof(ARBINT));
    mpz_init(*(ARBINT *)p->pointer);   
    mpz_set(*(ARBINT *)p->pointer,*(v->pointer.ai));
    return;
  default: 
    printf("pushv: Something is wrong, var <%s> typ=$%x cannot push.\n",v->name,v->typ);
  }
kollo's avatar
kollo committed
982 983
}

kollo's avatar
kollo committed
984
inline static int vm_pushv(unsigned short vnr,PARAMETER *sp) {    /*  */
kollo's avatar
kollo committed
985 986 987 988
  VERBOSE("vm_pushv_%d ",vnr);
  push_v(sp,&variablen[vnr]);
  return(1);
}
kollo's avatar
kollo committed
989 990 991



kollo's avatar
kollo committed
992 993
static int vm_eval(PARAMETER *sp) {    /*  */
  VERBOSE("vm_eval ");
kollo's avatar
kollo committed
994
  if(sp[-1].typ==PL_STRING) {
kollo's avatar
kollo committed
995
    VERBOSE("vm_eval_<%s>\n",(char *)sp[-1].pointer);
kollo's avatar
kollo committed
996 997
    kommando(sp[-1].pointer);
    free(sp[-1].pointer);
kollo's avatar
kollo committed
998
  } else {
kollo's avatar
kollo committed
999
    TYPEMISMATCH("EVAL:no string");
kollo's avatar
kollo committed
1000
    free_parameter(&sp[-1]);
kollo's avatar
kollo committed
1001 1002 1003 1004 1005
  }
  return(-1);  
}


kollo's avatar
kollo committed
1006
int program_adr=0;
kollo's avatar
kollo committed
1007
PARAMETER *virtual_machine(const STRING bcpc, int offset, int *npar, const PARAMETER *plist, int inpar) {
kollo's avatar
kollo committed
1008
  PARAMETER *opstack=calloc(BC_STACKLEN,sizeof(PARAMETER));
kollo's avatar
kollo committed
1009
  PARAMETER *osp=opstack;
kollo's avatar
kollo committed
1010
  register unsigned char cmd;
kollo's avatar
kollo committed
1011
  register int i=offset;
kollo's avatar
kollo committed
1012 1013
  int j;
  
kollo's avatar
kollo committed
1014
  int a,n;
kollo's avatar
kollo committed
1015
  short ss,ss2;
kollo's avatar
kollo committed
1016 1017
  double d;
  char *buf;
kollo's avatar
kollo committed
1018 1019 1020 1021 1022
  
  if(plist && inpar>0) {
    memcpy(osp,plist,sizeof(PARAMETER)*inpar);
    opstack+=inpar;
  }
kollo's avatar
kollo committed
1023

kollo's avatar
kollo committed
1024 1025 1026
#ifdef ANDROID
  backlog("enter virtual machine.");
#endif
kollo's avatar
kollo committed
1027
  while(batch && i<bcpc.len && (cmd=bcpc.pointer[i])) {
kollo's avatar
kollo committed
1028
    program_adr=i;
kollo's avatar
kollo committed
1029
    i++;
kollo's avatar
kollo committed
1030
    switch(cmd) {
kollo's avatar
kollo committed
1031
    case BC_NOOP:  
kollo's avatar
kollo committed
1032
      VERBOSE("vm_noop ");
kollo's avatar
kollo committed
1033 1034
      break;
    case BC_JSR:
kollo's avatar
kollo committed
1035
      CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1036
      VERBOSE("vm_jsr_%d\n",a);
kollo's avatar
kollo committed
1037
      stack[sp]=i;
kollo's avatar
kollo committed
1038
      i=a;
kollo's avatar
kollo committed
1039
      // dump_parameterlist(opstack-8,8);
kollo's avatar
kollo committed
1040 1041
      break;
    case BC_JMP:
kollo's avatar
kollo committed
1042
      CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1043
      i=a;
kollo's avatar
kollo committed
1044
      VERBOSE("vm_jmp_%d\n",a);
kollo's avatar
kollo committed
1045 1046
      break;
    case BC_JEQ:
kollo's avatar
kollo committed
1047
      if((--opstack)->integer==0) {
kollo's avatar
kollo committed
1048
        CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1049 1050 1051 1052 1053 1054
	i=a;
        VERBOSE("vm_jeq_%d ",a);
      } else {
        i+=sizeof(int);
        VERBOSE("vm_jeq_** ");
      }
kollo's avatar
kollo committed
1055 1056
      break;
    case BC_BRA:
kollo's avatar
kollo committed
1057
      CP2(&ss,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1058
      VERBOSE("vm_bra_%d \n",ss);
kollo's avatar
kollo committed
1059 1060 1061
      i+=ss;
      break;
    case BC_BEQ:
kollo's avatar
kollo committed
1062
      CP2(&ss,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1063
      VERBOSE("vm_beq_%d ",ss);
kollo's avatar
kollo committed
1064
      if((--opstack)->integer==0) i+=ss;
kollo's avatar
kollo committed
1065 1066
      break;
    case BC_BSR:
kollo's avatar
kollo committed
1067
      CP2(&ss,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1068
      VERBOSE("vm_bsr_%d \n",ss);
kollo's avatar
kollo committed
1069
      stack[sp]=i;
kollo's avatar
kollo committed
1070
      i+=ss;
kollo's avatar
kollo committed
1071
      break;
kollo's avatar
kollo committed
1072
    case BC_BLKSTART:
kollo's avatar
kollo committed
1073
      VERBOSE("vm_{ ");
kollo's avatar
kollo committed
1074 1075 1076
      sp++;
      break;
    case BC_BLKEND:
kollo's avatar
kollo committed
1077
      VERBOSE("vm_} \n");
kollo's avatar
kollo committed
1078 1079
      restore_locals(sp--);
      break;
kollo's avatar
kollo committed
1080
    case BC_RTS:
kollo's avatar
kollo committed
1081
      VERBOSE("vm_rts \n");
kollo's avatar
kollo committed
1082
      i=stack[sp];
kollo's avatar
kollo committed
1083 1084
      break;
    case BC_BRAs:
kollo's avatar
kollo committed
1085
      VERBOSE("vm_bra.s_%d \n",bcpc.pointer[i]); 
kollo's avatar
kollo committed
1086 1087
      i+=bcpc.pointer[i];
      i++;
kollo's avatar
kollo committed
1088 1089 1090
      break;
    case BC_BEQs:
      ss=bcpc.pointer[i++];
kollo's avatar
kollo committed
1091
      VERBOSE("vm_beqs_%d ",ss);
kollo's avatar
kollo committed
1092
      if((--opstack)->integer==0) i+=ss;
kollo's avatar
kollo committed
1093
      break;
kollo's avatar
kollo committed
1094 1095 1096 1097 1098 1099 1100 1101 1102
    case BC_PUSHC:
      CP8(&d,&bcpc.pointer[i],i);
      opstack->real=d;
      CP8(&d,&bcpc.pointer[i],i);
      opstack->imag=d;
      opstack->typ=PL_COMPLEX;
      opstack++;
      VERBOSE("(%g+%gi)",opstack->real,opstack->imag);
      break;
kollo's avatar
kollo committed
1103
    case BC_PUSHF:
kollo's avatar
kollo committed
1104
      CP8(&d,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1105 1106 1107
      opstack->real=d;
      opstack->typ=PL_FLOAT;
      opstack++;
kollo's avatar
kollo committed
1108
      VERBOSE("%g ",d);
kollo's avatar
kollo committed
1109 1110
      break;
    case BC_PUSHI:
kollo's avatar
kollo committed
1111
      CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1112 1113 1114
      opstack->integer=a;
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1115
      VERBOSE("%d ",a);
kollo's avatar
kollo committed
1116
      break;
kollo's avatar
kollo committed
1117
    case BC_LOADi:
kollo's avatar
kollo committed
1118
      CP4(&a,&bcpc.pointer[i],i);
1119
      opstack->integer=*((int *)INT2POINTER(a));
kollo's avatar
kollo committed
1120 1121
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1122
      VERBOSE("[$%x].i ",a);
kollo's avatar
kollo committed
1123 1124
      break;
    case BC_LOADf:
kollo's avatar
kollo committed
1125
      CP4(&a,&bcpc.pointer[i],i);
1126
      opstack->real=*((double *)INT2POINTER(a));
kollo's avatar
kollo committed
1127 1128
      opstack->typ=PL_FLOAT;
      opstack++;
kollo's avatar
kollo committed
1129
      VERBOSE("[$%x].d ",a);
kollo's avatar
kollo committed
1130
      break;
kollo's avatar
kollo committed
1131 1132
    case BC_LOADc:
      CP4(&a,&bcpc.pointer[i],i);
1133
      opstack->real=*((double *)INT2POINTER(a));
kollo's avatar
kollo committed
1134 1135 1136 1137 1138
      opstack->imag=0;
      opstack->typ=PL_COMPLEX;
      opstack++;
      VERBOSE("[$%x].d ",a);
      break;
kollo's avatar
kollo committed
1139
    case BC_PUSHW:
kollo's avatar
kollo committed
1140
      CP2(&ss,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1141 1142 1143
      opstack->integer=ss;
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1144
      VERBOSE("%d ",ss);
kollo's avatar
kollo committed
1145
      break;
kollo's avatar
kollo committed
1146 1147 1148 1149
    case BC_PUSHB:
      opstack->integer=bcpc.pointer[i++];
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1150
      VERBOSE("%d ",opstack[-1].integer);
kollo's avatar
kollo committed
1151 1152 1153 1154
      break;
    case BC_PUSHLEER:
      opstack->typ=PL_LEER;
      opstack++;
kollo's avatar
kollo committed
1155
      VERBOSE("<empty> ");
kollo's avatar
kollo committed
1156 1157 1158 1159 1160
      break;
    case BC_PUSH0:
      opstack->integer=0;
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1161
      VERBOSE("0 ");
kollo's avatar
kollo committed
1162 1163 1164 1165 1166
      break;
    case BC_PUSH1:
      opstack->integer=1;
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1167
      VERBOSE("1 ");
kollo's avatar
kollo committed
1168 1169 1170 1171 1172
      break;
    case BC_PUSH2:
      opstack->integer=2;
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1173
      VERBOSE("2 ");
kollo's avatar
kollo committed
1174 1175 1176 1177 1178
      break;
    case BC_PUSHM1:
      opstack->integer=-1;
      opstack->typ=PL_INT;
      opstack++;
kollo's avatar
kollo committed
1179
      VERBOSE("-1 ");
kollo's avatar
kollo committed
1180
      break;
kollo's avatar
kollo committed
1181 1182
    case BC_PUSHS:  /*String konstante auf STack....*/
      { int len;
kollo's avatar
kollo committed
1183 1184
      CP4(&len,&bcpc.pointer[i],i);
      CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1185
      opstack->integer=len;
kollo's avatar
kollo committed
1186
      opstack->typ=PL_STRING;
kollo's avatar
kollo committed
1187 1188 1189
      opstack->pointer=malloc(len+1);
      memcpy(opstack->pointer,rodata+a,len);
      ((char *)(opstack->pointer))[len]=0;
kollo's avatar
kollo committed
1190
      opstack++;
kollo's avatar
kollo committed
1191
      VERBOSE("\"%s\" ",(char *)opstack[-1].pointer);
kollo's avatar
kollo committed
1192
      }
kollo's avatar
kollo committed
1193
      break;
kollo's avatar
kollo committed
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
    case BC_PUSHAI:  /*Big int Konstante auf STack....*/
      { int len;
      CP4(&len,&bcpc.pointer[i],i);
      CP4(&a,&bcpc.pointer[i],i);
      opstack->typ=PL_ARBINT;
      char *buf=malloc(len+1);
      memcpy(buf,rodata+a,len);
      buf[len]=0;
      opstack->pointer=malloc(sizeof(ARBINT));
      mpz_init(*(ARBINT *)opstack->pointer);
      mpz_set_str(*(ARBINT *)opstack->pointer,buf,32);
      free(buf);
      buf=mpz_get_str(NULL,10,*(ARBINT *)opstack->pointer);
      opstack++;
      VERBOSE("\"%s\" ",buf);
      free(buf);
      }
      break;
kollo's avatar
kollo committed
1212 1213 1214
    case BC_PUSHA:  /*Array konstante auf STack....*/
      { int len;
        STRING str;
kollo's avatar
kollo committed
1215 1216
      CP4(&len,&bcpc.pointer[i],i);
      CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1217 1218 1219 1220 1221 1222 1223 1224
      str.len=len;
      str.pointer=(char *)(rodata+a);
      opstack->typ=PL_ARRAY;
      *((ARRAY *)&(opstack->integer))=string_to_array(str);
      opstack++;
      VERBOSE("array ");
      }
      break;
kollo's avatar
kollo committed
1225 1226 1227
    case BC_PUSHFUNC:
      a=bcpc.pointer[i++]&0xff;
      n=bcpc.pointer[i++]&0xff;
kollo's avatar
kollo committed
1228
      opstack+=vm_func(opstack,a,n);
kollo's avatar
kollo committed
1229
    //  dump_parameterlist(opstack,n);
kollo's avatar
kollo committed
1230 1231 1232 1233
      break;
    case BC_PUSHSFUNC:
      a=bcpc.pointer[i++]&0xff;
      n=bcpc.pointer[i++]&0xff;
kollo's avatar
kollo committed
1234
      opstack+=vm_sfunc(opstack,a,n);
kollo's avatar
kollo committed
1235
      break;
1236 1237 1238 1239 1240
    case BC_PUSHAFUNC:
      a=bcpc.pointer[i++]&0xff;
      n=bcpc.pointer[i++]&0xff;
      opstack+=vm_afunc(opstack,a,n);
      break;
kollo's avatar
kollo committed
1241 1242 1243
    case BC_PUSHCOMM:
      a=bcpc.pointer[i++]&0xff;
      n=bcpc.pointer[i++]&0xff;
kollo's avatar
kollo committed
1244
      opstack+=vm_comm(opstack,a,n);
kollo's avatar
kollo committed
1245
      VERBOSE("SP=%d\n",((int)opstack-(int)osp)/sizeof(PARAMETER));  
kollo's avatar
kollo committed
1246 1247
      break;
    case BC_PUSHSYS:
kollo's avatar
kollo committed
1248
      a=bcpc.pointer[i++]&0xff;
kollo's avatar
kollo committed
1249
      opstack+=vm_sysvar(opstack,a);
kollo's avatar
kollo committed
1250 1251
      break;
    case BC_PUSHSSYS:
kollo's avatar
kollo committed
1252
      a=bcpc.pointer[i++]&0xff;
kollo's avatar
kollo committed
1253
      opstack+=vm_ssysvar(opstack,a);
kollo's avatar
kollo committed
1254 1255
      break;
    case BC_PUSHASYS:
kollo's avatar
kollo committed
1256
      a=bcpc.pointer[i++]&0xff;
kollo's avatar
kollo committed
1257
      opstack+=vm_asysvar(opstack,a);
kollo's avatar
kollo committed
1258 1259
      break;
    case BC_PUSHX:
kollo's avatar
kollo committed
1260
      { int len=bcpc.pointer[i++];
kollo's avatar
kollo committed
1261
        CP4(&a,&bcpc.pointer[i],i);
kollo's avatar
kollo committed
1262 1263 1264 1265
        buf=malloc(len+1);
        memcpy(buf,rodata+a,len);
        buf[len]=0;
        opstack->integer=len;
kollo's avatar
kollo committed
1266 1267
        opstack->typ=PL_KEY;    /*  Kann auch EVAL oder P_ARGUMENT sein */
	opstack->arraytyp=KEYW_UNKNOWN; 
kollo's avatar
kollo committed
1268 1269
        opstack->pointer=buf;
        opstack++;
kollo's avatar
kollo committed
1270
        VERBOSE("%s ",buf);
kollo's avatar
kollo committed
1271
      }
kollo's avatar
kollo committed
1272
      break;
kollo's avatar
kollo committed
1273 1274 1275 1276 1277 1278 1279 1280
    case BC_PUSHK:
      opstack->arraytyp=bcpc.pointer[i++];
      opstack->typ=PL_KEY;
      opstack->integer=0;
      opstack->pointer=NULL;
      opstack++;
      VERBOSE("%s ",keywords[opstack[-1].arraytyp]);
      break;
kollo's avatar
kollo committed
1281 1282 1283 1284 1285
    case BC_COMMENT:
      a=bcpc.pointer[i++];
      buf=malloc(a+1);
      memcpy(buf,&bcpc.pointer[i],a);
      buf[a]=0;
kollo's avatar
kollo committed
1286
      VERBOSE("%s ",buf);
kollo's avatar
kollo committed
1287 1288 1289 1290
      i+=a;
      free(buf);
      break;
    case BC_ADD:
kollo's avatar
kollo committed
1291
      opstack+=vm_add(opstack);
kollo's avatar
kollo committed
1292
      break;
kollo's avatar
kollo committed
1293
    case BC_ADDi:
kollo's avatar
kollo committed
1294
      VERBOSE("ADDi ");
kollo's avatar
kollo committed
1295 1296 1297
      opstack--;(opstack-1)->integer+=opstack->integer;
      break;
    case BC_ADDf:
kollo's avatar
kollo committed
1298
      VERBOSE("ADDf ");
kollo's avatar
kollo committed
1299 1300
      opstack--;(opstack-1)->real+=opstack->real;
      break;
kollo's avatar
kollo committed
1301 1302 1303 1304 1305 1306 1307 1308
    case BC_ADDc:
      VERBOSE("ADDc ");
      opstack--;(opstack-1)->real+=opstack->real;(opstack-1)->imag+=opstack->imag;
      break;
    case BC_SUBc:
      VERBOSE("SUBc ");
      opstack--;(opstack-1)->real-=opstack->real;(opstack-1)->imag-=opstack->imag;
      break;
kollo's avatar
kollo committed
1309
    case BC_ADDs:
kollo's avatar
kollo committed