Branch: Tag:

1999-10-09

1999-10-09 23:29:02 by Fredrik Hübinette (Hubbe) <hubbe@hubbe.net>

some fixes for auto_bignum stuff

Rev: lib/master.pike.in:1.59
Rev: src/bignum.c:1.2
Rev: src/bignum.h:1.3
Rev: src/builtin_functions.c:1.184
Rev: src/language.yacc:1.125
Rev: src/main.c:1.77
Rev: src/operators.c:1.62
Rev: src/program.c:1.158

8:   #include "svalue.h"   #include "error.h"    - /* FIXME: Cache the mpz-function? */ - struct object *make_bignum_object(void) - { -  struct object *o; +     -  + struct svalue auto_bignum_program = { T_INT }; +  + static void resolve_auto_bignum_program(void) + { +  if(auto_bignum_program.type == T_INT) +  {    push_text("Gmp.mpz");    SAFE_APPLY_MASTER("resolv", 1);       if(sp[-1].type != T_FUNCTION)    error("Failed to resolv Gmp.mpz!\n");    -  stack_swap(); -  f_call_function(2); -  -  o = sp[-1].u.object; +  auto_bignum_program=sp[-1];    sp--; -  +  } + }    -  return o; + void exit_auto_bignum(void) + { +  free_svalue(&auto_bignum_program); +  auto_bignum_program.type=T_INT;   }    - #if 0 /* Hubbe's example. */ + void convert_stack_top_to_bignum(void) + { +  resolve_auto_bignum_program(); +  apply_svalue(&auto_bignum_program, 1);    - struct program *auto_bignum_program=0; +  if(sp[-1].type != T_OBJECT) +  error("Gmp.mpz conversion failed.\n"); + }    - void exit_auto_bignum(void) +  + struct object *make_bignum_object(void)   { -  if(auto_bignum_program) -  { -  free_program(auto_bignum_program); -  auto_bignum_program=0; +  convert_stack_top_to_bignum(); +  return (--sp)->u.object;   } - } +     - struct program *get_auto_bignum_program() + struct object *bignum_from_svalue(struct svalue *s)   { -  if(auto_bignum_program) -  return auto_bignum_program; +  push_svalue(s); +  convert_stack_top_to_bignum(); +  return (--sp)->u.object; + }    -  push_text("Gmp.mpz"); -  APPLY_MASTER("resolv",1); -  if(sp[-1].type != T_PROGRAM) -  error("Failed to resolv Gmp.mpz!\n"); -  auto_bignum_program=sp[-1].u.program; + void convert_svalue_to_bignum(struct svalue *s) + { +  push_svalue(s); +  convert_stack_top_to_bignum(); +  free_svalue(s); +  *s=sp[-1];    sp--;   } - #endif +       #endif /* AUTO_BIGNUM */