vm-i-loader.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /* Copyright (C) 2001,2008,2009,2010,2011,2012 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 (101, 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 (102, 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, 1));
  38. memcpy (buf, (char *) ip, len);
  39. ip += len;
  40. NEXT;
  41. }
  42. VM_DEFINE_LOADER (103, 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_latin1_symboln ((const char*)ip, len));
  49. ip += len;
  50. NEXT;
  51. }
  52. VM_DEFINE_LOADER (104, 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 (105, 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 (106, load_array, "load-array")
  75. {
  76. SCM type, shape;
  77. size_t len;
  78. FETCH_LENGTH (len);
  79. POP2 (shape, type);
  80. SYNC_REGISTER ();
  81. PUSH (scm_from_contiguous_typed_array (type, shape, ip, len));
  82. ip += len;
  83. NEXT;
  84. }
  85. VM_DEFINE_LOADER (107, load_wide_string, "load-wide-string")
  86. {
  87. size_t len;
  88. scm_t_wchar *wbuf;
  89. FETCH_LENGTH (len);
  90. VM_ASSERT ((len % 4) == 0,
  91. vm_error_bad_wide_string_length (len));
  92. SYNC_REGISTER ();
  93. PUSH (scm_i_make_wide_string (len / 4, &wbuf, 1));
  94. memcpy ((char *) wbuf, (char *) ip, len);
  95. ip += len;
  96. NEXT;
  97. }
  98. /*
  99. (defun renumber-ops ()
  100. "start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
  101. (interactive "")
  102. (save-excursion
  103. (let ((counter 100)) (goto-char (point-min))
  104. (while (re-search-forward "^VM_DEFINE_[^ ]+ (\\([^,]+\\)," (point-max) t)
  105. (replace-match
  106. (number-to-string (setq counter (1+ counter)))
  107. t t nil 1)))))
  108. */
  109. /*
  110. Local Variables:
  111. c-file-style: "gnu"
  112. End:
  113. */