mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-16 16:50:21 +02:00
rework the vm support for wide strings
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump. * libguile/vm-engine.c (vm_error_bad_wide_string_length): New error case. * libguile/vm-i-loader.c (load-unsigned-integer, load-integer) (load-keyword): Remove these instructions. The former two are obsoleted by make-int64/make-uint64, the latter via make-keyword. (load-string): Only handle narrow strings. (load-symbol): Only handle narrow symbols. The wide case is handled via make-symbol. (load-wide-string): New instruction, for wide strings. * libguile/vm-i-system.c (define): Move here from loaders.c, as now it just takes a sym on the stack. (make-keyword, make-symbol): New instructions. * module/language/assembly.scm: Remove removed instructions. No more width byte in load-string etc. * module/language/assembly/compile-bytecode.scm (write-bytecode): Adapt to change in instruction set. * module/language/glil/compile-assembly.scm (glil->assembly): Compile define by pushing the sym then emitting (define). (dump-object): Dump narrow and wide strings differently. Use make-keyword and make-symbol as appropriate. * module/language/tree-il/compile-glil.scm (flatten): When compiling a ref to a primitive (not a call), first see if the primitive is actually bound in the root module. (That's not the case with e.g. bytevector-u8-ref). * module/system/xref.scm (program-callee-rev-vars): Don't parse out "nexts". * test-suite/tests/asm-to-bytecode.test ("compiler"): Adapt to bytecode format change.
This commit is contained in:
parent
6cf4830798
commit
94ff26b96b
11 changed files with 101 additions and 201 deletions
|
@ -20,42 +20,6 @@
|
|||
|
||||
/* This file is included in vm_engine.c */
|
||||
|
||||
VM_DEFINE_LOADER (80, load_unsigned_integer, "load-unsigned-integer")
|
||||
{
|
||||
size_t len;
|
||||
|
||||
FETCH_LENGTH (len);
|
||||
if (SCM_LIKELY (len <= 8))
|
||||
{
|
||||
scm_t_uint64 val = 0;
|
||||
while (len-- > 0)
|
||||
val = (val << 8U) + FETCH ();
|
||||
SYNC_REGISTER ();
|
||||
PUSH (scm_from_uint64 (val));
|
||||
NEXT;
|
||||
}
|
||||
else
|
||||
SCM_MISC_ERROR ("load-unsigned-integer: not implemented yet", SCM_EOL);
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (81, load_integer, "load-integer")
|
||||
{
|
||||
size_t len;
|
||||
|
||||
FETCH_LENGTH (len);
|
||||
if (SCM_LIKELY (len <= 4))
|
||||
{
|
||||
int val = 0;
|
||||
while (len-- > 0)
|
||||
val = (val << 8) + FETCH ();
|
||||
SYNC_REGISTER ();
|
||||
PUSH (scm_from_int (val));
|
||||
NEXT;
|
||||
}
|
||||
else
|
||||
SCM_MISC_ERROR ("load-integer: not implemented yet", SCM_EOL);
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (82, load_number, "load-number")
|
||||
{
|
||||
size_t len;
|
||||
|
@ -72,82 +36,24 @@ VM_DEFINE_LOADER (82, load_number, "load-number")
|
|||
VM_DEFINE_LOADER (83, load_string, "load-string")
|
||||
{
|
||||
size_t len;
|
||||
int width;
|
||||
SCM str;
|
||||
char *buf;
|
||||
|
||||
FETCH_LENGTH (len);
|
||||
FETCH_WIDTH (width);
|
||||
SYNC_REGISTER ();
|
||||
if (width == 1)
|
||||
{
|
||||
char *buf;
|
||||
str = scm_i_make_string (len, &buf);
|
||||
memcpy (buf, (char *) ip, len);
|
||||
}
|
||||
else if (width == 4)
|
||||
{
|
||||
scm_t_wchar *wbuf;
|
||||
str = scm_i_make_wide_string (len, &wbuf);
|
||||
memcpy ((char *) wbuf, (char *) ip, len * width);
|
||||
}
|
||||
else
|
||||
SCM_MISC_ERROR ("load-string: invalid character width", SCM_EOL);
|
||||
PUSH (str);
|
||||
ip += len * width;
|
||||
PUSH (scm_i_make_string (len, &buf));
|
||||
memcpy (buf, (char *) ip, len);
|
||||
ip += len;
|
||||
NEXT;
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (84, load_symbol, "load-symbol")
|
||||
{
|
||||
size_t len;
|
||||
int width;
|
||||
SCM str;
|
||||
FETCH_LENGTH (len);
|
||||
FETCH_WIDTH (width);
|
||||
SYNC_REGISTER ();
|
||||
if (width == 1)
|
||||
{
|
||||
char *buf;
|
||||
str = scm_i_make_string (len, &buf);
|
||||
memcpy (buf, (char *) ip, len);
|
||||
}
|
||||
else if (width == 4)
|
||||
{
|
||||
scm_t_wchar *wbuf;
|
||||
str = scm_i_make_wide_string (len, &wbuf);
|
||||
memcpy ((char *) wbuf, (char *) ip, len * width);
|
||||
}
|
||||
else
|
||||
SCM_MISC_ERROR ("load-symbol: invalid character width", SCM_EOL);
|
||||
PUSH (scm_string_to_symbol (str));
|
||||
ip += len * width;
|
||||
NEXT;
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (85, load_keyword, "load-keyword")
|
||||
{
|
||||
size_t len;
|
||||
int width;
|
||||
SCM str;
|
||||
FETCH_LENGTH (len);
|
||||
FETCH_WIDTH (width);
|
||||
SYNC_REGISTER ();
|
||||
if (width == 1)
|
||||
{
|
||||
char *buf;
|
||||
str = scm_i_make_string (len, &buf);
|
||||
memcpy (buf, (char *) ip, len);
|
||||
}
|
||||
else if (width == 4)
|
||||
{
|
||||
scm_t_wchar *wbuf;
|
||||
str = scm_i_make_wide_string (len, &wbuf);
|
||||
memcpy ((char *) wbuf, (char *) ip, len * width);
|
||||
}
|
||||
else
|
||||
SCM_MISC_ERROR ("load-keyword: invalid character width", SCM_EOL);
|
||||
PUSH (scm_symbol_to_keyword (scm_string_to_symbol (str)));
|
||||
ip += len * width;
|
||||
/* FIXME: should be scm_from_latin1_symboln */
|
||||
PUSH (scm_from_locale_symboln ((const char*)ip, len));
|
||||
ip += len;
|
||||
NEXT;
|
||||
}
|
||||
|
||||
|
@ -181,37 +87,6 @@ VM_DEFINE_INSTRUCTION (87, link_now, "link-now", 0, 1, 1)
|
|||
NEXT;
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (88, define, "define")
|
||||
{
|
||||
SCM str, sym;
|
||||
size_t len;
|
||||
|
||||
int width;
|
||||
FETCH_LENGTH (len);
|
||||
FETCH_WIDTH (width);
|
||||
SYNC_REGISTER ();
|
||||
if (width == 1)
|
||||
{
|
||||
char *buf;
|
||||
str = scm_i_make_string (len, &buf);
|
||||
memcpy (buf, (char *) ip, len);
|
||||
}
|
||||
else if (width == 4)
|
||||
{
|
||||
scm_t_wchar *wbuf;
|
||||
str = scm_i_make_wide_string (len, &wbuf);
|
||||
memcpy ((char *) wbuf, (char *) ip, len * width);
|
||||
}
|
||||
else
|
||||
SCM_MISC_ERROR ("load define: invalid character width", SCM_EOL);
|
||||
sym = scm_string_to_symbol (str);
|
||||
ip += len * width;
|
||||
|
||||
SYNC_REGISTER ();
|
||||
PUSH (scm_sym2var (sym, scm_current_module_lookup_closure (), SCM_BOOL_T));
|
||||
NEXT;
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (89, load_array, "load-array")
|
||||
{
|
||||
SCM type, shape;
|
||||
|
@ -225,6 +100,24 @@ VM_DEFINE_LOADER (89, load_array, "load-array")
|
|||
NEXT;
|
||||
}
|
||||
|
||||
VM_DEFINE_LOADER (90, load_wide_string, "load-wide-string")
|
||||
{
|
||||
size_t len;
|
||||
scm_t_wchar *wbuf;
|
||||
|
||||
FETCH_LENGTH (len);
|
||||
if (SCM_UNLIKELY (len % 4))
|
||||
{ finish_args = scm_list_1 (scm_from_size_t (len));
|
||||
goto vm_error_bad_wide_string_length;
|
||||
}
|
||||
|
||||
SYNC_REGISTER ();
|
||||
PUSH (scm_i_make_wide_string (len / 4, &wbuf));
|
||||
memcpy ((char *) wbuf, (char *) ip, len);
|
||||
ip += len;
|
||||
NEXT;
|
||||
}
|
||||
|
||||
/*
|
||||
(defun renumber-ops ()
|
||||
"start from top of buffer and renumber 'VM_DEFINE_FOO (\n' sequences"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue