diff options
author | Keisuke Nishida <kxn30@po.cwru.edu> | 2001-04-16 03:43:48 +0000 |
---|---|---|
committer | Keisuke Nishida <kxn30@po.cwru.edu> | 2001-04-16 03:43:48 +0000 |
commit | 8f5cfc810fb19fdfbeaa55d59d47dc5ab50c416b (patch) | |
tree | b5435b4d55e8645240fdb0f555599ae3c4038491 /src | |
parent | 78591ef5c3c4dd44cac912704696cf77c2cbbf73 (diff) | |
download | guile-8f5cfc810fb19fdfbeaa55d59d47dc5ab50c416b.tar.gz |
*** empty log message ***
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 13 | ||||
-rw-r--r-- | src/envs.h | 6 | ||||
-rw-r--r-- | src/guile-vm.c | 2 | ||||
-rwxr-xr-x | src/guilec.in | 2 | ||||
-rw-r--r-- | src/instructions.c | 2 | ||||
-rw-r--r-- | src/instructions.h | 8 | ||||
-rw-r--r-- | src/objcodes.c | 225 | ||||
-rw-r--r-- | src/objcodes.h | 72 | ||||
-rw-r--r-- | src/programs.c | 2 | ||||
-rw-r--r-- | src/programs.h | 8 | ||||
-rw-r--r-- | src/vm.c | 33 | ||||
-rw-r--r-- | src/vm.h | 8 | ||||
-rw-r--r-- | src/vm_engine.c | 2 | ||||
-rw-r--r-- | src/vm_engine.h | 2 | ||||
-rw-r--r-- | src/vm_expand.h | 2 | ||||
-rw-r--r-- | src/vm_loader.c | 2 | ||||
-rw-r--r-- | src/vm_scheme.c | 2 | ||||
-rw-r--r-- | src/vm_system.c | 2 |
18 files changed, 335 insertions, 58 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index b62036f9b..dcdd6eee3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,12 +5,14 @@ guile_vm_LDADD = libguilevm.la guile_vm_LDFLAGS = $(GUILE_LDFLAGS) lib_LTLIBRARIES = libguilevm.la -libguilevm_la_SOURCES = envs.c instructions.c programs.c vm.c \ - envs.h instructions.h programs.h vm.h vm_engine.h vm_expand.h +libguilevm_la_SOURCES = \ + envs.c instructions.c objcodes.c programs.c vm.c \ + envs.h instructions.h objcodes.h programs.h vm.h \ + vm_engine.h vm_expand.h libguilevm_la_LDFLAGS = -version-info 0:0:0 -export-dynamic EXTRA_DIST = vm_engine.c vm_system.c vm_scheme.c vm_loader.c BUILT_SOURCES = vm_system.i vm_scheme.i vm_loader.i \ - envs.x instructions.x programs.x vm.x + envs.x instructions.x objcodes.x programs.x vm.x INCLUDES = $(GUILE_CFLAGS) DISTCLEANFILES = $(BUILT_SOURCES) @@ -27,4 +29,9 @@ SUFFIXES = .i .x $(SNARF) $< $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $< > $@ \ || { rm $@; false; } +GUILE = "$(bindir)/guile" +guilec: guilec.in + sed "s!@guile@!$(GUILE)!" guilec.in > guilec + @chmod 755 guilec + $(BUILT_SOURCES): config.h vm_expand.h diff --git a/src/envs.h b/src/envs.h index ddc5ea498..88884c1a3 100644 --- a/src/envs.h +++ b/src/envs.h @@ -39,8 +39,8 @@ * whether to permit this exception to apply to your modifications. * If you do not wish that, delete this exception notice. */ -#ifndef _ENVS_H_ -#define _ENVS_H_ +#ifndef _SCM_ENVS_H_ +#define _SCM_ENVS_H_ #include <libguile.h> #include "config.h" @@ -64,7 +64,7 @@ extern SCM scm_c_env_vcell (SCM env, SCM name, int intern); extern void scm_init_envs (void); -#endif /* _ENVS_H_ */ +#endif /* _SCM_ENVS_H_ */ /* Local Variables: diff --git a/src/guile-vm.c b/src/guile-vm.c index 581c30a88..1096b8abd 100644 --- a/src/guile-vm.c +++ b/src/guile-vm.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/guilec.in b/src/guilec.in index 74f793753..529886c87 100755 --- a/src/guilec.in +++ b/src/guilec.in @@ -1,4 +1,4 @@ -#!@bindir@/guile -*- scheme -*- +#!@guile@ -s !# (use-modules (system base compile)) diff --git a/src/instructions.c b/src/instructions.c index 9c22e21be..6cfdf636f 100644 --- a/src/instructions.c +++ b/src/instructions.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/instructions.h b/src/instructions.h index 2e62b9ed5..6b6757489 100644 --- a/src/instructions.h +++ b/src/instructions.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,8 +39,8 @@ * whether to permit this exception to apply to your modifications. * If you do not wish that, delete this exception notice. */ -#ifndef _INSTRUCTIONS_H_ -#define _INSTRUCTIONS_H_ +#ifndef _SCM_INSTRUCTIONS_H_ +#define _SCM_INSTRUCTIONS_H_ #include <libguile.h> #include "config.h" @@ -78,7 +78,7 @@ extern struct scm_instruction *scm_lookup_instruction (SCM name); extern void scm_init_instructions (void); -#endif /* _INSTRUCTIONS_H_ */ +#endif /* _SCM_INSTRUCTIONS_H_ */ /* Local Variables: diff --git a/src/objcodes.c b/src/objcodes.c new file mode 100644 index 000000000..0df3be0f3 --- /dev/null +++ b/src/objcodes.c @@ -0,0 +1,225 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * As a special exception, the Free Software Foundation gives permission + * for additional uses of the text contained in its release of GUILE. + * + * The exception is that, if you link the GUILE library with other files + * to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the GUILE library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the + * Free Software Foundation under the name GUILE. If you copy + * code from other Free Software Foundation releases into a copy of + * GUILE, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for GUILE, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. */ + +#include <string.h> +#include <fcntl.h> +#include <unistd.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <sys/types.h> + +#include "programs.h" +#include "objcodes.h" + +#define OBJCODE_COOKIE "GOOF-0.5" + + +/* + * Objcode type + */ + +scm_bits_t scm_tc16_objcode; + +static SCM +make_objcode (size_t size) +#define FUNC_NAME "make_objcode" +{ + struct scm_objcode *p = SCM_MUST_MALLOC (sizeof (struct scm_objcode)); + p->size = size; + p->base = SCM_MUST_MALLOC (size); + p->fd = -1; + SCM_RETURN_NEWSMOB (scm_tc16_objcode, p); +} +#undef FUNC_NAME + +static SCM +make_objcode_by_mmap (int fd) +#define FUNC_NAME "make_objcode_by_mmap" +{ + int ret; + char *addr; + struct stat st; + struct scm_objcode *p; + + ret = fstat (fd, &st); + if (ret < 0) SCM_SYSERROR; + + addr = mmap (0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (addr == MAP_FAILED) SCM_SYSERROR; + + p = SCM_MUST_MALLOC (sizeof (struct scm_objcode)); + p->size = st.st_size; + p->base = addr; + p->fd = fd; + SCM_RETURN_NEWSMOB (scm_tc16_objcode, p); +} +#undef FUNC_NAME + +static scm_sizet +objcode_free (SCM obj) +#define FUNC_NAME "objcode_free" +{ + size_t size = (sizeof (struct scm_objcode)); + struct scm_objcode *p = SCM_OBJCODE_DATA (obj); + + if (p->fd >= 0) + { + int rv; + rv = munmap (p->base, p->size); + if (rv < 0) SCM_SYSERROR; + rv = close (p->fd); + if (rv < 0) SCM_SYSERROR; + } + else + { + size += p->size; + scm_must_free (p->base); + } + + scm_must_free (p); + return size; +} +#undef FUNC_NAME + + +/* + * Scheme interface + */ + +SCM_DEFINE (scm_objcode_p, "objcode?", 1, 0, 0, + (SCM obj), + "") +#define FUNC_NAME s_scm_objcode_p +{ + return SCM_BOOL (SCM_OBJCODE_P (obj)); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_bytecode_to_objcode, "bytecode->objcode", 3, 0, 0, + (SCM bytecode, SCM nlocs, SCM nexts), + "") +#define FUNC_NAME s_scm_bytecode_to_objcode +{ + size_t size; + char *base; + SCM objcode; + + SCM_VALIDATE_STRING (1, bytecode); + SCM_VALIDATE_INUM (2, nlocs); + SCM_VALIDATE_INUM (3, nexts); + + size = SCM_STRING_LENGTH (bytecode) + 10; + objcode = make_objcode (size); + base = SCM_OBJCODE_BASE (objcode); + + memcpy (base, OBJCODE_COOKIE, 8); + base[8] = SCM_INUM (nlocs); + base[9] = SCM_INUM (nexts); + memcpy (base + 10, SCM_STRING_CHARS (bytecode), size - 10); + return objcode; +} +#undef FUNC_NAME + +SCM_DEFINE (scm_load_objcode, "load-objcode", 1, 0, 0, + (SCM file), + "") +#define FUNC_NAME s_scm_load_objcode +{ + int fd; + + SCM_VALIDATE_STRING (1, file); + + fd = open (SCM_STRING_CHARS (file), O_RDONLY); + if (fd < 0) SCM_SYSERROR; + + return make_objcode_by_mmap (fd); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_objcode_to_string, "objcode->string", 1, 0, 0, + (SCM objcode), + "") +#define FUNC_NAME s_scm_objcode_to_string +{ + SCM_VALIDATE_OBJCODE (1, objcode); + return scm_makfromstr (SCM_OBJCODE_BASE (objcode), + SCM_OBJCODE_SIZE (objcode), + 0); +} +#undef FUNC_NAME + +SCM_DEFINE (scm_objcode_to_program, "objcode->program", 1, 0, 0, + (SCM objcode), + "") +#define FUNC_NAME s_scm_objcode_to_program +{ + SCM prog; + size_t size; + char *base; + + SCM_VALIDATE_OBJCODE (1, objcode); + + base = SCM_OBJCODE_BASE (objcode); + size = SCM_OBJCODE_SIZE (objcode); + prog = scm_c_make_program (base + 10, size - 10, objcode); + SCM_PROGRAM_NLOCS (prog) = base[8]; + SCM_PROGRAM_NEXTS (prog) = base[9]; + return prog; +} +#undef FUNC_NAME + + +void +scm_init_objcodes (void) +{ + scm_tc16_objcode = scm_make_smob_type ("objcode", 0); + scm_set_smob_free (scm_tc16_objcode, objcode_free); + +#ifndef SCM_MAGIC_SNARFER +#include "objcodes.x" +#endif +} + +/* + Local Variables: + c-file-style: "gnu" + End: +*/ diff --git a/src/objcodes.h b/src/objcodes.h new file mode 100644 index 000000000..20afd042a --- /dev/null +++ b/src/objcodes.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2001 Free Software Foundation, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA + * + * As a special exception, the Free Software Foundation gives permission + * for additional uses of the text contained in its release of GUILE. + * + * The exception is that, if you link the GUILE library with other files + * to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the GUILE library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the + * Free Software Foundation under the name GUILE. If you copy + * code from other Free Software Foundation releases into a copy of + * GUILE, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for GUILE, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. */ + +#ifndef _SCM_OBJCODES_H_ +#define _SCM_OBJCODES_H_ + +#include <libguile.h> +#include "config.h" + +struct scm_objcode { + size_t size; /* objcode size */ + char *base; /* objcode base address */ + int fd; /* file descriptor when mmap'ed */ +}; + +extern scm_bits_t scm_tc16_objcode; + +#define SCM_OBJCODE_P(x) (SCM_SMOB_PREDICATE (scm_tc16_objcode, x)) +#define SCM_OBJCODE_DATA(x) ((struct scm_objcode *) SCM_SMOB_DATA (x)) +#define SCM_VALIDATE_OBJCODE(p,x) SCM_MAKE_VALIDATE (p, x, OBJCODE_P) + +#define SCM_OBJCODE_SIZE(x) (SCM_OBJCODE_DATA (x)->size) +#define SCM_OBJCODE_BASE(x) (SCM_OBJCODE_DATA (x)->base) +#define SCM_OBJCODE_FD(x) (SCM_OBJCODE_DATA (x)->fd) + +extern void scm_init_objcodes (void); + +#endif /* _SCM_OBJCODES_H_ */ + +/* + Local Variables: + c-file-style: "gnu" + End: +*/ diff --git a/src/programs.c b/src/programs.c index 406c00952..d6d7ab8e2 100644 --- a/src/programs.c +++ b/src/programs.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/programs.h b/src/programs.h index b8fa563fc..f5fa3be03 100644 --- a/src/programs.h +++ b/src/programs.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,8 +39,8 @@ * whether to permit this exception to apply to your modifications. * If you do not wish that, delete this exception notice. */ -#ifndef _PROGRAM_H_ -#define _PROGRAM_H_ +#ifndef _SCM_PROGRAMS_H_ +#define _SCM_PROGRAMS_H_ #include <libguile.h> #include "config.h" @@ -87,7 +87,7 @@ extern SCM scm_c_make_closure (SCM program, SCM external); extern void scm_init_programs (void); -#endif /* _PROGRAM_H_ */ +#endif /* _SCM_PROGRAMS_H_ */ /* Local Variables: @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,6 +42,7 @@ #include <string.h> #include "instructions.h" #include "programs.h" +#include "objcodes.h" #include "envs.h" #include "vm.h" @@ -598,35 +599,6 @@ SCM_DEFINE (scm_vm_fetch_stack, "vm-fetch-stack", 1, 0, 0, } #undef FUNC_NAME -SCM_DEFINE (scm_vm_load, "vm-load", 2, 0, 0, - (SCM vm, SCM bootcode), - "") -#define FUNC_NAME s_scm_vm_load -{ - SCM prog; - int len; - char *base; - - SCM_VALIDATE_VM (1, vm); - SCM_VALIDATE_STRING (2, bootcode); - - base = SCM_STRING_CHARS (bootcode); - len = SCM_STRING_LENGTH (bootcode); - - /* Check bootcode */ - if (strncmp (base, "\0GBC", 4) != 0) - SCM_MISC_ERROR ("Invalid bootcode: ~S", SCM_LIST1 (bootcode)); - - /* Create program */ - prog = scm_c_make_program (base + 10, len - 10, bootcode); - SCM_PROGRAM_NLOCS (prog) = base[8]; - SCM_PROGRAM_NEXTS (prog) = base[9]; - - /* Load it */ - return scm_vm_apply (vm, prog, SCM_EOL); -} -#undef FUNC_NAME - /* * Initialize @@ -637,6 +609,7 @@ scm_init_vm (void) { scm_init_instructions (); scm_init_programs (); + scm_init_objcodes (); scm_tc16_vm_heap_frame = scm_make_smob_type ("vm_frame", 0); scm_set_smob_mark (scm_tc16_vm_heap_frame, vm_heap_frame_mark); @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -39,8 +39,8 @@ * whether to permit this exception to apply to your modifications. * If you do not wish that, delete this exception notice. */ -#ifndef _VM_H_ -#define _VM_H_ +#ifndef _SCM_VM_H_ +#define _SCM_VM_H_ #include <libguile.h> #include "config.h" @@ -151,7 +151,7 @@ extern SCM scm_vm_current_frame (SCM vm); extern void scm_init_vm (void); -#endif /* _VM_H_ */ +#endif /* _SCM_VM_H_ */ /* Local Variables: diff --git a/src/vm_engine.c b/src/vm_engine.c index 1d6b53037..dc02f8fdf 100644 --- a/src/vm_engine.c +++ b/src/vm_engine.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/vm_engine.h b/src/vm_engine.h index 16f1b8585..37320d901 100644 --- a/src/vm_engine.h +++ b/src/vm_engine.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/vm_expand.h b/src/vm_expand.h index 911b1bd49..8124c0539 100644 --- a/src/vm_expand.h +++ b/src/vm_expand.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/vm_loader.c b/src/vm_loader.c index 02af7859e..5469fcef8 100644 --- a/src/vm_loader.c +++ b/src/vm_loader.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/vm_scheme.c b/src/vm_scheme.c index ac1c09c8c..bb552d948 100644 --- a/src/vm_scheme.c +++ b/src/vm_scheme.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/src/vm_system.c b/src/vm_system.c index 3ac1d6726..c0f14e444 100644 --- a/src/vm_system.c +++ b/src/vm_system.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 Free Software Foundation, Inc. +/* Copyright (C) 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by |