home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / ZVMEM2.C < prev   
C/C++ Source or Header  |  1994-07-27  |  4KB  |  144 lines

  1. /* Copyright (C) 1992, 1993, 1994 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* zvmem2.c */
  20. /* Level 2 "Virtual memory" operators */
  21. #include "ghost.h"
  22. #include "errors.h"
  23. #include "oper.h"
  24. #include "estack.h"
  25. #include "ialloc.h"            /* for ivmspace.h */
  26. #include "ivmspace.h"
  27. #include "store.h"
  28.  
  29. /* Garbage collector control parameters. */
  30. #if arch_ints_are_short
  31. #  define default_vm_threshold 20000
  32. #else
  33. #  define default_vm_threshold 250000
  34. #endif
  35. #define min_vm_threshold 1
  36. #define max_vm_threshold max_long
  37.  
  38. /* ------ Local/global VM control ------ */
  39.  
  40. /* <bool> setglobal/setshared - */
  41. int
  42. zsetglobal(register os_ptr op)
  43. {    check_type(*op, t_boolean);
  44.     ialloc_set_local(idmemory, !op->value.boolval);
  45.     pop(1);
  46.     return 0;
  47. }
  48.  
  49. /* <bool> currentglobal/currentshared - */
  50. int
  51. zcurrentglobal(register os_ptr op)
  52. {    push(1);
  53.     make_bool(op, !ialloc_is_local(idmemory));
  54.     return 0;
  55. }
  56.  
  57. /* <any> gcheck/scheck <bool> */
  58. int
  59. zgcheck(register os_ptr op)
  60. {    make_bool(op, (r_is_global(op) ? 1 : 0));
  61.     return 0;
  62. }
  63.  
  64. /* ------ Garbage collector control ------ */
  65.  
  66. /* These routines are exported for setuserparams. */
  67.  
  68. /* <int> setvmthreshold - */
  69. int
  70. set_vm_threshold(long val)
  71. {    gs_memory_gc_status_t stat;
  72.     if ( val < -1 )
  73.         return_error(e_rangecheck);
  74.     else if ( val == -1 )
  75.         val = default_vm_threshold;
  76.     else if ( val < min_vm_threshold )
  77.         val = min_vm_threshold;
  78.     else if ( val > max_vm_threshold )
  79.         val = max_vm_threshold;
  80.     gs_memory_gc_status(idmemory->global, &stat);
  81.     stat.vm_threshold = val;
  82.     gs_memory_set_gc_status(idmemory->global, &stat);
  83.     gs_memory_gc_status(idmemory->local, &stat);
  84.     stat.vm_threshold = val;
  85.     gs_memory_set_gc_status(idmemory->local, &stat);
  86.     return 0;
  87. }
  88. int
  89. zsetvmthreshold(register os_ptr op)
  90. {    int code;
  91.     check_type(*op, t_integer);
  92.     code = set_vm_threshold(op->value.intval);
  93.     if ( code >= 0 )
  94.         pop(1);
  95.     return code;
  96. }
  97.  
  98. /* <int> vmreclaim - */
  99. int
  100. set_vm_reclaim(long val)
  101. {    if ( val >= -2 && val <= 0 )
  102.     {    gs_memory_gc_status_t stat;
  103.         gs_memory_gc_status(idmemory->global, &stat);
  104.         stat.enabled = val >= -1;
  105.         gs_memory_set_gc_status(idmemory->global, &stat);
  106.         gs_memory_gc_status(idmemory->local, &stat);
  107.         stat.enabled = val == 0;
  108.         gs_memory_set_gc_status(idmemory->local, &stat);
  109.         return 0;
  110.     }
  111.     else
  112.         return_error(e_rangecheck);
  113. }    
  114. int
  115. zvmreclaim(register os_ptr op)
  116. {    check_type(*op, t_integer);
  117.     if ( op->value.intval == 1 || op->value.intval == 2 )
  118.       {    /* Force the interpreter to store its state and exit. */
  119.         /* The interpreter's caller will do the actual GC. */
  120.         return_error(e_VMreclaim);
  121.       }
  122.     else
  123.       {    int code = set_vm_reclaim(op->value.intval);
  124.         if ( code >= 0 )
  125.           pop(1);
  126.         return code;
  127.       }
  128. }
  129.  
  130. /* ------ Initialization procedure ------ */
  131.  
  132. /* The VM operators are defined even if the initial language level is 1, */
  133. /* because we need them during initialization. */
  134. op_def zvmem2_op_defs[] = {
  135.     {"0.currentglobal", zcurrentglobal},
  136.     {"1.gcheck", zgcheck},
  137.     {"1.setglobal", zsetglobal},
  138.         /* The rest of the operators are defined only in Level 2. */
  139.         op_def_begin_level2(),
  140.     {"1setvmthreshold", zsetvmthreshold},
  141.     {"1vmreclaim", zvmreclaim},
  142.     op_def_end(0)
  143. };
  144.