vm-i-loader.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Copyright (C) 2001,2008,2009 Free Software Foundation, Inc.
  2. *
  3. * This library is free software; you can redistribute it and/or
  4. * modify it under the terms of the GNU Lesser General Public License
  5. * as published by the Free Software Foundation; either version 3 of
  6. * the License, or (at your option) any later version.
  7. *
  8. * This library is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public
  14. * License along with this library; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. * 02110-1301 USA
  17. */
  18. /* FIXME! Need to check that the fetch is within the current program */
  19. /* This file is included in vm_engine.c */
  20. VM_DEFINE_LOADER (82, load_number, "load-number")
  21. {
  22. size_t len;
  23. FETCH_LENGTH (len);
  24. SYNC_REGISTER ();
  25. PUSH (scm_string_to_number (scm_from_locale_stringn ((char *)ip, len),
  26. SCM_UNDEFINED /* radix = 10 */));
  27. /* Was: scm_istring2number (ip, len, 10)); */
  28. ip += len;
  29. NEXT;
  30. }
  31. VM_DEFINE_LOADER (83, load_string, "load-string")
  32. {
  33. size_t len;
  34. char *buf;
  35. FETCH_LENGTH (len);
  36. SYNC_REGISTER ();
  37. PUSH (scm_i_make_string (len, &buf));
  38. memcpy (buf, (char *) ip, len);
  39. ip += len;
  40. NEXT;
  41. }
  42. VM_DEFINE_LOADER (84, load_symbol, "load-symbol")
  43. {
  44. size_t len;
  45. FETCH_LENGTH (len);
  46. SYNC_REGISTER ();
  47. /* FIXME: should be scm_from_latin1_symboln */
  48. PUSH (scm_from_locale_symboln ((const char*)ip, len));
  49. ip += len;
  50. NEXT;
  51. }
  52. VM_DEFINE_LOADER (86, load_program, "load-program")
  53. {
  54. scm_t_uint32 len;
  55. SCM objs, objcode;
  56. POP (objs);
  57. SYNC_REGISTER ();
  58. if (scm_is_vector (objs) && scm_is_false (scm_c_vector_ref (objs, 0)))
  59. scm_c_vector_set_x (objs, 0, scm_current_module ());
  60. objcode = scm_c_make_objcode_slice (SCM_PROGRAM_OBJCODE (fp[-1]), ip);
  61. len = sizeof (struct scm_objcode) + SCM_OBJCODE_TOTAL_LEN (objcode);
  62. PUSH (scm_make_program (objcode, objs, SCM_BOOL_F));
  63. ip += len;
  64. NEXT;
  65. }
  66. VM_DEFINE_INSTRUCTION (87, link_now, "link-now", 0, 1, 1)
  67. {
  68. SCM what;
  69. POP (what);
  70. SYNC_REGISTER ();
  71. PUSH (resolve_variable (what, scm_current_module ()));
  72. NEXT;
  73. }
  74. VM_DEFINE_LOADER (89, load_array, "load-array")
  75. {
  76. SCM type, shape;
  77. size_t len;
  78. FETCH_LENGTH (len);
  79. POP (shape);
  80. POP (type);
  81. SYNC_REGISTER ();
  82. PUSH (scm_from_contiguous_typed_array (type, shape, ip, len));
  83. ip += len;
  84. NEXT;
  85. }
  86. VM_DEFINE_LOADER (90, load_wide_string, "load-wide-string")
  87. {
  88. size_t len;
  89. scm_t_wchar *wbuf;
  90. FETCH_LENGTH (len);
  91. if (SCM_UNLIKELY (len % 4))
  92. { finish_args = scm_list_1 (scm_from_size_t (len));
  93. goto vm_error_bad_wide_string_length;
  94. }
  95. SYNC_REGISTER ();
  96. PUSH (scm_i_make_wide_string (len / 4, &wbuf));
  97. memcpy ((char *) wbuf, (char *) ip, len);
  98. ip += len;
  99. NEXT;
  100. }
  101. /*
  102. (defun renumber-ops ()
  103. "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
  104. (interactive "")
  105. (save-excursion
  106. (let ((counter 79)) (goto-char (point-min))
  107. (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
  108. (replace-match
  109. (number-to-string (setq counter (1+ counter)))
  110. t t nil 1)))))
  111. */
  112. /*
  113. Local Variables:
  114. c-file-style: "gnu"
  115. End:
  116. */