home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v941.tgz / icon.v941src.tar / icon.v941src / ipl / cfuncs / internal.c < prev    next >
C/C++ Source or Header  |  2000-07-29  |  2KB  |  80 lines

  1. /*
  2. ############################################################################
  3. #
  4. #    File:     internal.c
  5. #
  6. #    Subject:  Functions to access Icon internals
  7. #
  8. #    Author:   Gregg M. Townsend
  9. #
  10. #    Date:     October 3, 1995
  11. #
  12. ############################################################################
  13. #
  14. #   This file is in the public domain.
  15. #
  16. ############################################################################
  17. #
  18. #  These functions provide some access to the internal machinery of the
  19. #  Icon interpreter.  Some knowledge of the interpreter is needed to use
  20. #  these profitably; misuse can lead to memory violations.
  21. #
  22. #  dword(x)        return d-word of descriptor
  23. #  vword(x)        return v-word of descriptor
  24. #  descriptor(d,v)    construct descriptor from d-word and v-word
  25. #  peek(addr,n)        return contents of memory as n-character string
  26. #            (if n is omitted, return Icon integer at addr)
  27. #  spy(addr,n)        return string pointer to memory, without copying
  28. #
  29. ############################################################################
  30. #
  31. #  Requires:  Dynamic loading
  32. #
  33. ############################################################################
  34. */
  35.  
  36. #include "icall.h"
  37.  
  38. int dword(int argc, descriptor argv[])        /*: return descriptor d-word */
  39.    {
  40.    if (argc == 0)
  41.       Fail;
  42.    else
  43.       RetInteger(argv[1].dword);
  44.    }
  45.  
  46. int vword(int argc, descriptor argv[])        /*: return descriptor v-word */
  47.    {
  48.    if (argc == 0)
  49.       Fail;
  50.    else
  51.       RetInteger(argv[1].vword);
  52.    }
  53.  
  54. int icon_descriptor(int argc, descriptor argv[])  /*: construct descriptor */
  55.    {
  56.    ArgInteger(1);
  57.    ArgInteger(2);
  58.    argv[0].dword = argv[1].vword;
  59.    argv[0].vword = argv[2].vword;
  60.    Return;
  61.    }
  62.  
  63. int peek(int argc, descriptor argv[])        /*: load value from memory */
  64.    {
  65.    ArgInteger(1);
  66.    if (argc > 1) {
  67.       ArgInteger(2);
  68.       RetStringN((void *)IntegerVal(argv[1]), IntegerVal(argv[2]));
  69.       }
  70.    else
  71.       RetInteger(*(word *)IntegerVal(argv[1]));
  72.    }
  73.  
  74. int spy(int argc, descriptor argv[])        /*: create spy-port to memory */
  75.    {
  76.    ArgInteger(1);
  77.    ArgInteger(2);
  78.    RetConstStringN((void *)IntegerVal(argv[1]), IntegerVal(argv[2]));
  79.    }
  80.