summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLudovic Court`es <ludovic.courtes@laas.fr>2005-04-27 09:36:52 +0000
committerLudovic Courtès <ludo@gnu.org>2008-04-25 19:09:30 +0200
commitfa19602c28cf4a6d54860e98b3c4379b3a058d37 (patch)
treec33383692afb4b7ded15137b759f0b608647dcf7 /src
parent054599f117f12ea183167c46b62c18cd590181c4 (diff)
downloadguile-fa19602c28cf4a6d54860e98b3c4379b3a058d37.tar.gz
Fixed the compiler, got the disassembler working.
* doc/guile-vm.texi: Texified and cleaned up. * src/vm.c: Use `scm_from_locale_string ()' instead of `scm_makfrom0str ()'. * src/vm_engine.c: Likewise. * src/programs.c (scm_program_bytecode): Return a u8vector instead of a string. * module/system/vm/conv.scm (make-byte-decoder): Fixed a few things wrt. to the string to u8vector transition. * src/objcodes.c (bytecode->objcode): Fixed a bug where the last 10 bytes of the bytecode where ignored. * module/system/vm/assemble.scm (dump-object!): Don't convert everything to a u8vector, keep strings where it makes sense. * module/system/vm/conv.scm (code->bytes): Accordingly, convert strings to u8vectors when needed. (make-byte-decoder): Accordingly too, when decoding instructions, return variable-length instructions' argument as strings except for `load-program'. * module/system/vm/disasm.scm: Export `disassemble-bytecode'. git-archimport-id: lcourtes@laas.fr--2004-libre/guile-vm--revival--0.6--patch-4
Diffstat (limited to 'src')
-rw-r--r--src/instructions.c4
-rw-r--r--src/objcodes.c2
-rw-r--r--src/programs.c17
-rw-r--r--src/vm.c2
-rw-r--r--src/vm_engine.c16
5 files changed, 27 insertions, 14 deletions
diff --git a/src/instructions.c b/src/instructions.c
index 93115de91..df557b264 100644
--- a/src/instructions.c
+++ b/src/instructions.c
@@ -87,7 +87,7 @@ SCM_DEFINE (scm_instruction_list, "instruction-list", 0, 0, 0,
SCM list = SCM_EOL;
struct scm_instruction *ip;
for (ip = scm_instruction_table; ip->opcode != scm_op_last; ip++)
- list = scm_cons (scm_str2symbol (ip->name), list);
+ list = scm_cons (scm_from_locale_symbol (ip->name), list);
return scm_reverse_x (list, SCM_EOL);
}
#undef FUNC_NAME
@@ -150,7 +150,7 @@ SCM_DEFINE (scm_opcode_to_instruction, "opcode->instruction", 1, 0, 0,
SCM_VALIDATE_INUM (1, op);
i = scm_to_int (op);
SCM_ASSERT_RANGE (1, op, 0 <= i && i < scm_op_last);
- return scm_str2symbol (scm_instruction_table[i].name);
+ return scm_from_locale_symbol (scm_instruction_table[i].name);
}
#undef FUNC_NAME
diff --git a/src/objcodes.c b/src/objcodes.c
index 00b3b66ee..efb9eb65f 100644
--- a/src/objcodes.c
+++ b/src/objcodes.c
@@ -153,6 +153,8 @@ SCM_DEFINE (scm_bytecode_to_objcode, "bytecode->objcode", 3, 0, 0,
c_bytecode = scm_u8vector_elements (bytecode, &handle, &size, &increment);
assert (increment == 1);
+ /* Account for the 10 byte-long header. */
+ size += 10;
objcode = make_objcode (size);
base = SCM_OBJCODE_BASE (objcode);
diff --git a/src/programs.c b/src/programs.c
index 5c1cb49c4..111f87f66 100644
--- a/src/programs.c
+++ b/src/programs.c
@@ -188,15 +188,26 @@ SCM_DEFINE (scm_program_external, "program-external", 1, 0, 0,
SCM_DEFINE (scm_program_bytecode, "program-bytecode", 1, 0, 0,
(SCM program),
- "")
+ "Return a u8vector containing @var{program}'s bytecode.")
#define FUNC_NAME s_scm_program_bytecode
{
+ size_t size;
+ char *c_bytecode;
+
SCM_VALIDATE_PROGRAM (1, program);
- return scm_makfromstr (SCM_PROGRAM_DATA (program)->base,
- SCM_PROGRAM_DATA (program)->size, 0);
+
+ size = SCM_PROGRAM_DATA (program)->size;
+ c_bytecode = malloc (size);
+ if (!c_bytecode)
+ return SCM_BOOL_F;
+
+ memcpy (c_bytecode, SCM_PROGRAM_DATA (program)->base, size);
+
+ return scm_take_u8vector (c_bytecode, size);
}
#undef FUNC_NAME
+
void
scm_init_programs (void)
diff --git a/src/vm.c b/src/vm.c
index 8a4fa1789..36bd9e6ee 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -301,7 +301,7 @@ SCM_DEFINE (scm_vm_version, "vm-version", 0, 0, 0,
"")
#define FUNC_NAME s_scm_vm_version
{
- return scm_makfrom0str (VERSION);
+ return scm_from_locale_string (VERSION);
}
#undef FUNC_NAME
diff --git a/src/vm_engine.c b/src/vm_engine.c
index d0fdb7296..c275cfb02 100644
--- a/src/vm_engine.c
+++ b/src/vm_engine.c
@@ -123,44 +123,44 @@ vm_run (SCM vm, SCM program, SCM args)
/* Errors */
{
vm_error_unbound:
- err_msg = scm_makfrom0str ("VM: Unbound variable: ~A");
+ err_msg = scm_from_locale_string ("VM: Unbound variable: ~A");
goto vm_error;
vm_error_wrong_type_arg:
- err_msg = scm_makfrom0str ("VM: Wrong type argument");
+ err_msg = scm_from_locale_string ("VM: Wrong type argument");
err_args = SCM_EOL;
goto vm_error;
vm_error_wrong_num_args:
- err_msg = scm_makfrom0str ("VM: Wrong number of arguments");
+ err_msg = scm_from_locale_string ("VM: Wrong number of arguments");
err_args = SCM_EOL;
goto vm_error;
vm_error_wrong_type_apply:
- err_msg = scm_makfrom0str ("VM: Wrong type to apply: ~S");
+ err_msg = scm_from_locale_string ("VM: Wrong type to apply: ~S");
err_args = SCM_LIST1 (program);
goto vm_error;
vm_error_stack_overflow:
- err_msg = scm_makfrom0str ("VM: Stack overflow");
+ err_msg = scm_from_locale_string ("VM: Stack overflow");
err_args = SCM_EOL;
goto vm_error;
vm_error_stack_underflow:
- err_msg = scm_makfrom0str ("VM: Stack underflow");
+ err_msg = scm_from_locale_string ("VM: Stack underflow");
err_args = SCM_EOL;
goto vm_error;
#if VM_CHECK_IP
vm_error_invalid_address:
- err_msg = scm_makfrom0str ("VM: Invalid program address");
+ err_msg = scm_from_locale_string ("VM: Invalid program address");
err_args = SCM_EOL;
goto vm_error;
#endif
#if VM_CHECK_EXTERNAL
vm_error_external:
- err_msg = scm_makfrom0str ("VM: Invalid external access");
+ err_msg = scm_from_locale_string ("VM: Invalid external access");
err_args = SCM_EOL;
goto vm_error;
#endif