summaryrefslogtreecommitdiff
path: root/src/vm_system.c
AgeCommit message (Collapse)AuthorFilesLines
2008-08-21merge guile-vm into libguile itselfAndy Wingo1-672/+0
* ice-9/boot-9.scm: Only define load-compiled as #f if it's not already defined, which won't normally be the case. * libguile/guile-vm.c: Removed, there's no more guile-vm binary. * libguile/frames.c: (with change frame? -> heap-frame?) * libguile/frames.h: * libguile/instructions.c: * libguile/instructions.h: * libguile/objcodes.c: * libguile/objcodes.h: * libguile/programs.c: * libguile/programs.h: * libguile/vm-bootstrap.h: (was bootstrap.h) * libguile/vm-engine.c: (was vm_engine.c) * libguile/vm-engine.h: (was vm_engine.h) * libguile/vm-expand.h: (was vm_expand.h) * libguile/vm-i-loader.c: (was vm_loader.c) * libguile/vm-i-scheme.c: (was vm_scheme.c) * libguile/vm-i-system.c: (was vm_system.c) * libguile/vm.c: * libguile/vm.h: These files moved here from src/, as guile-vm is now a part of libguile. * libguile/init.c: Bootstrap the VM. Yay! * libguile/Makefile.am: The necessary chicanery here. * module/system/vm/Makefile.am: * module/system/vm/bootstrap.scm: * module/system/vm/frame.scm: * module/system/vm/instruction.scm: * module/system/vm/objcode.scm: * module/system/vm/program.scm: * module/system/vm/vm.scm: * pre-inst-guile-env.in: Add builddirs to the load path; add module/ to the path in the empty-$GUILE_LOAD_PATH case as well. * src/Makefile.am: Moved out everything except guilec and guile-disasm, which probably should be moved to the scripts directory? * testsuite/Makefile.am: Update to find guile-vm in the right place. * module/system/vm/Makefile.am: * module/system/vm/bootstrap.scm: Removed bootstrap.scm, scm_init_guile handles the bootstrapping for us. * module/system/vm/frame.scm: * module/system/vm/instruction.scm: * module/system/vm/objcode.scm: * module/system/vm/program.scm: * module/system/vm/vm.scm: Call the init functions in libguile; should fix at some point to avoid the dlopen?
2008-08-20fix some compilation warnings, in anticipation of moving to libguile/Andy Wingo1-4/+7
* src/Makefile.am: Use standard guile CFLAGS, which has -Werror and -Wmissing-prototypes. * src/frames.h: * src/instructions.h: * src/objcodes.h: * src/programs.h: * src/vm.h: * src/vm.c: Fix warnings, mostly about prototypes. * src/vm_system.c: Fix a tricky x-is-not-initialized error. Thanks, GCC!
2008-08-11fix bug in compilation of `and' and `or'; more robust underflow detection.Andy Wingo1-0/+2
* module/system/il/compile.scm (codegen): Rewrite handling of `and' and `or' ghil compilation, because it was broken if drop was #t. Tricky bug, this one! Took me days to track down! * module/system/repl/repl.scm: Export call-with-backtrace, which probably should go in some other file. * src/vm.c (scm_vm_save_stack): Handle the fp==0 case for errors before we have a frame. * src/vm_engine.h (NEW_FRAME, FREE_FRAME): Stricter underflow checking, raising the stack base to the return address, in an attempt to prevent inadvertant stack smashing (the symptom of the and/or miscompilation bug). (CHECK_IP): A check that the current IP is within the bounds of the current program. Not normally compiled in. Perhaps it should be? * src/vm_system.c (halt): Set vp->ip to NULL. Paranoia, I know. (return): Call CHECK_IP(), if such a thing is compiled in. * testsuite/Makefile.am (vm_test_files): * testsuite/t-catch.scm: * testsuite/t-map.scm: * testsuite/t-or.scm: New tests.
2008-08-08improve source loc info in nonlocal exits and backtracesAndy Wingo1-2/+2
* module/system/il/compile.scm (codegen): The currently-executing instruction is actually the one right before the instruction pointer; so for purposes of assv to find a source location for an ip, put the source after the code, as it was before. * module/system/vm/debug.scm (vm-backtrace): Move more code to frame.scm. * module/system/vm/frame.scm (make-frame-chain): Include all frames, even the bootstrap one. For a reentrant backtrace we'll have boostrap programs anyway. Probably should check for objcode[2] == scm_op_halt, to not show those frames in the trace. (frame-line-number, frame-file): New helpers. (print-frame): Print out the line number too. (frame-call-representation): Code from print-frame-call moved here. (print-frame-chain-as-backtrace): A backtrace printer, yays. (program-name): Check link validity before calling frame-address on it. * module/system/vm/program.scm (source:addr, source:line, source:column) (source:file): New accessors for the elements of program-sources. * module/system/vm/vm.scm (vm:last-ip): New export. (vm-last-frame-chain): Use vm:last-ip in making the frame chain. * src/vm.h (struct scm_vm): * src/vm.c (make_vm, scm_vm_last_ip, scm_vm_save_stack): Save the last instruction pointer when saving the stack. Really though, we should be saving all of the stack data on a spaghetti stack. * src/vm_system.c (late-variable-ref): Pointless s/REGISTER/BEFORE_GC/.
2008-08-08fix bug in variable-set instruction; ,x prints out program metadataAndy Wingo1-1/+0
* module/system/vm/disasm.scm (disassemble-program, disassemble-meta): Disassemble program meta information too, if it's there. * src/vm_system.c (variable-set): Don't try to proxy name information; maybe we can do this later, but the code as it was was calling SCM_CAR on a variable, which is for the lose.
2008-08-07fix stack corruption on vm-save-stack; more robust with nonlocal exitsAndy Wingo1-0/+1
* module/system/repl/command.scm: Coerce rationals to floats. * module/system/vm/program.scm (program-documentation): Fix a typo, doh! * src/vm.c (vm_reset_stack, struct vm_unwind_data): Add unwind handler to reset vp->sp, vp->fp, and vp->this_frame when performing a nonlocal exit from a vm_run. (vm_heapify_frames_1): Don't repack the stack, it causes stack corruption. I think we need spaghetti stacks to handle continuations, not separate heap frames. I don't think call/cc is working now. (vm-save-stack): Don't call heapify_frames, that modifies the stack that we're copying. Instead call its helper, heapify_1. * src/vm_engine.c (vm_run): Set up the vm_reset_stack unwind handler. * src/vm_engine.h (IP_REG, SP_REG, FP_REG): If we got through all of the checks without having these macros defined, define them as empty. Happens on x86-64. * src/vm_system.c (halt): End the dynwind before we return from the VM. * src/vm_scheme.c (REL): Sync the regs before calling scm_lt_p et al, cause they can do a nonlocal exit.
2008-08-06sync registers before calling c functions, reallyAndy Wingo1-0/+2
* src/vm_loader.c: * src/vm_scheme.c: Use SYNC_REGISTER, although it's the same as SYNC_BEFORE_GC. A style issue? * src/vm_system.c (call, tail-call): Explicitly do a SYNC_REGISTER, not relying on POP_LIST to do it for us, because POP_LIST won't do it if there are 0 arguments. The way that this manifested itself to me was badness after the second (read) call in a repl session. I wish I understood more about this problem.
2008-08-05save vm's state before calling out to c proceduresAndy Wingo1-0/+2
* .gitignore: Ignore .go files. * src/vm_loader.c: * src/vm_scheme.c: * src/vm_system.c: Sync the VM's state before calling out to C procedures that might cons or cause a nonlocal exit.
2008-08-05disable trampoline "optimizations"Andy Wingo1-0/+6
* src/vm_system.c: Disable those trampoline "optimizations", as they actually slowed down benchmark/measure.scm '(fibo 30)'. They were edifying, in that now I have an appreciation of the need for SYNC_ALL().
2008-08-05re-enable computed goto; fix ,help in the repl; subr dispatch optimizationsAndy Wingo1-8/+91
* m4/labels-as-values.m4: New file, checks for computed goto. * configure.in: Use AC_C_LABELS_AS_VALUES. * module/system/repl/command.scm (procedure-documentation): Extend the core's procedure-documentation in an ad-hoc way, so that ,help works. * module/system/vm/core.scm (program-properties): New function. (program-documentation): New function. * src/vm_engine.h (DROP, DROPN): Decrement sp before checking for underflow. * src/vm_system.c (call, tail-call): Add some optimized dispatch for some C functions, so that we can avoid consing and the interpreter if possible. However currently it seems that I'm always getting the scm_call_* trampolines back.
2008-05-19bind all module-level variables lazilyAndy Wingo1-21/+20
comments in ghil-lookup are pertinent. * module/system/il/compile.scm (make-glil-var): Require that ghil vars have environments. Remove the 'unresolved case -- we'll treat all module-level variables as late bound. * module/system/il/ghil.scm (ghil-lookup): Treat all module level vars as late bound. * module/system/vm/assemble.scm: Instead of vlink and vlate-bound, have vlink-now and vlink-later. (codegen): Add a bunch of crap to get the various cases right. (object-assoc, dump-object!): Handle the new cases, remove the old cases. * src/vm_loader.c (link-now, link-later): Change from link and lazy-bind. Include the module in which the link is to be done, so that callers from other modules get the right behavior. * src/vm_system.c (late-variable-ref, late-variable-set): Instead of a sym, the unbound representation is a module name / symbol pair. * testsuite/run-vm-tests.scm (run-vm-tests): Remove some debugging.
2008-05-19Add instructions for doing very late bindingAndy Wingo1-0/+45
Fixes the mutually-recursive toplevel definitions case. This could be fixed by rewriting bodies as letrecs, as r6 does, but that's not really repl-compatible. * module/system/il/ghil.scm (ghil-lookup): Ok, if we can't locate a variable, mark it as unresolved. * module/system/il/compile.scm (make-glil-var): Compile unresolved variables as <glil-late-bound> objects. * module/system/il/glil.scm: Add <glil-late-bound> definition. * module/system/vm/assemble.scm (codegen): And, finally, when we see a <vlate-bound> object, allocate a slot for it in the object vector, setting it to a symbol. Add a new pair of instructions to resolve that symbol to a variable at the last minute. * src/vm_loader.c (load-number): Bugfix: the radix argument should be SCM_UNDEFINED in order to default to 10. (late-bind): Add an unresolved symbol to the object vector. Could be replaced with load-symbol I guess. * src/vm_system.c (late-variable-ref, late-variable-set): New instructions to do late symbol binding. * testsuite/Makefile.am (vm_test_files): * testsuite/t-mutual-toplevel-defines.scm: New test, failing for some reason involving the core even? and odd? definitions.
2008-04-25Encode the length of constant lists/vectors on 2 octets instead of 1.Ludovic Courtes1-6/+10
* module/system/vm/assemble.scm (dump-object!): New sub-procedure `too-long'. For `list' and `vector', encode the length on 2 octets instead of 1 and report an error if a list/vector is longer than 65535. * module/system/vm/disasm.scm (original-value): New sub-procedure `list-or-vector?'; when true, return the number of elements for that list/vector. * src/vm_system.c (list): Fetch the length as a two-octet integer. (vector): Likewise. * testsuite/t-basic-contructs.scm: New. * testsuite/Makefile.am (vm_test_files): Added the above file. * module/system/vm/core.scm (load-compiled): Added a bit of documentation. git-archimport-id: lcourtes@laas.fr--2005-mobile/guile-vm--mobile--0.6--patch-11
2008-04-25Started documenting the compiler.Ludovic Courtes1-1/+1
* doc/guile-vm.texi: Documented the compiler (node `The Compiler'). Removed a number of things that might have been relevant to Guile-VM 0.0. * module/system/il/compile.scm (optimize): Commented out the case using `<ghil-inst?>'. * src/vm_engine.c (vm_run)[objects_handle]: New variable. Before leaving the function, release OBJECTS_HANDLE. * src/vm_engine.h (CACHE_PROGRAM): Use `scm_vector_writable_elements' instead of `scm_vector_elements'; don't release the handle right away. * src/vm_loader.c (load-program): New commented out piece of code dealing with simple vectors. * src/vm_system.c (object-ref): Added the type of OBJNUM. git-archimport-id: lcourtes@laas.fr--2005-mobile/guile-vm--mobile--0.6--patch-3
2008-04-25* src/objcodes.c (make_objcode_by_mmap): Fixed the error type when theLudovic Courtes1-1/+3
object file is too small. * doc/guile-vm.texi: Documented `make-closure'. Improved the documentation of `load-program'. * testsuite: New directory. * configure.in: Added `testsuite/Makefile' to `AC_OUTPUT'. * Makefile.am (SUBDIRS): Added `testsuite'. * src/vm_engine.h (VM_CHECK_OBJECT): New option. (CHECK_OBJECT): New macro. * src/vm_system.c (object-ref): Use VM_CHECK_OBJECT. * module/system/vm/assemble.scm (preprocess): Commented out the debugging code. * benchmark/lib.scm (do-loop): New procedure. git-archimport-id: lcourtes@laas.fr--2005-mobile/guile-vm--mobile--0.6--patch-2
2008-04-25Playing with the procedure call mechanism.Ludovic Court`es1-0/+5
* src/objcodes.c (do-pair): New experiment. * src/vm_engine.h (ALIGN_AS_NON_IMMEDIATE): New macro. (POP_LIST_ON_STACK): New experimental macro. * src/vm_engine.c (call): In the procedure call case, I tried using the above macro. git-archimport-id: lcourtes@laas.fr--2004-libre/guile-vm--revival--0.6--patch-8
2008-04-25Fixed a stack leak. Now observing actual performance.Ludovic Court`es1-2/+7
* src/*.[ch]: Replaced `scm_mem2symbol' by `scm_from_locale_symboln' and `scm_ulong2num' by `scm_from_ulong'. * src/vm_system.c (tail-call): Fixed stack leak (SP lacked decrement by one more Scheme object in the tail-recursive case). * benchmark/measure.scm (measure): Make sure we are using the compiled procedure (i.e. a program object) when measuring. This yields better results than before. :-) * doc/guile-vm.texi: Augmented the instruction set documentation with branch instructions, `call' and `tail-call'. git-archimport-id: lcourtes@laas.fr--2004-libre/guile-vm--revival--0.6--patch-7
2008-04-25Improved the VM's efficiency. The VM is as fast as the interpreter. :-(Ludovic Court`es1-7/+11
* benchmark/lib.scm: New file. * benchmark/measure.scm: New file. * README: Added useful pointers to various threads. * doc/guile-vm.texi: Fixed the description of `load-program' (it now expects _immediate_ integers). * src/*.[ch]: Use immediate integers whereever possible, as in the original code. For `CONS', use `scm_cell' rather than `scm_cons'. git-archimport-id: lcourtes@laas.fr--2004-libre/guile-vm--revival--0.6--patch-6
2008-04-25Got the VM up and running! Augmented the documentation.Ludovic Court`es1-11/+17
* src/*.[ch]: Replaced the remaining `SCM_MAKINUM', and changed `SCM_VELTS' into `scm_vector_elements ()'. * src/vm_loader.c (link): Fixed so that it pushed a variable object on the stack. * src/vm_system.c (variable-ref): Fixed so that it uses `scm_variable_ref ()' and friends. * module/system/vm/assemble.scm (dump-object!): Fixed the string case. * src/vm_engine.h (CONS): Use `scm_cons' instead of `SCM_NEWCELL'. * doc/guile-vm.texi: Added actual instruction definitions, explanations of the program invocation mechanism, programs' object tables, etc., in the `Instruction Set' chapter. git-archimport-id: lcourtes@laas.fr--2004-libre/guile-vm--revival--0.6--patch-5
2001-05-02*** empty log message ***Keisuke Nishida1-0/+6
2001-04-25*** empty log message ***Keisuke Nishida1-13/+0
2001-04-23*** empty log message ***Keisuke Nishida1-2/+3
2001-04-23*** empty log message ***Keisuke Nishida1-6/+6
2001-04-22*** empty log message ***Keisuke Nishida1-4/+4
2001-04-20*** empty log message ***Keisuke Nishida1-1/+5
2001-04-20*** empty log message ***Keisuke Nishida1-1/+5
2001-04-19*** empty log message ***Keisuke Nishida1-1/+1
2001-04-19*** empty log message ***Keisuke Nishida1-13/+1
2001-04-19*** empty log message ***Keisuke Nishida1-16/+14
2001-04-16*** empty log message ***Keisuke Nishida1-1/+1
2001-04-15*** empty log message ***Keisuke Nishida1-1/+43
2001-04-11*** empty log message ***Keisuke Nishida1-0/+2
2001-04-11*** empty log message ***Keisuke Nishida1-13/+20
2001-04-09*** empty log message ***Keisuke Nishida1-1/+2
2001-04-07applyKeisuke Nishida1-2/+19
2001-04-07*** empty log message ***Keisuke Nishida1-30/+38
2001-04-06*** empty log message ***Keisuke Nishida1-9/+1
2001-04-06*** empty log message ***Keisuke Nishida1-3/+6
2001-04-06*** empty log message ***Keisuke Nishida1-21/+23
2001-04-05*** empty log message ***Keisuke Nishida1-6/+0
2001-04-05*** empty log message ***Keisuke Nishida1-75/+36
2001-04-05*** empty log message ***Keisuke Nishida1-43/+3
2001-04-01New VM.Keisuke Nishida1-308/+271
2000-09-29Create *.i from *.c and include them.Keisuke Nishida1-2/+0
2000-09-22* src/vm_system.c (call): Call return-hook before reinstating aKeisuke Nishida1-1/+2
continuation. (tail_call): Call return-hook before a proper tail call.
2000-09-20* src/vm_system.c (br_if_not_null): Set ac = SCM_BOOL_F if not null.Keisuke Nishida1-1/+4
2000-09-20* src/vm_system.c (name): New instruction.Keisuke Nishida1-1/+8
(savet): Don't set name.
2000-09-20* src/vm_scheme.c (cons): Bug fixed.Keisuke Nishida1-1/+4
* src/vm_system.c (br_if_null): Set ac = SCM_BOOL_T if null.
2000-09-10* src/vm_system.c (push_list): New instruction.Keisuke Nishida1-0/+8
* src/vm_engine.c (VM_NAME): Don\'t validate VM and PROGRAM. * src/vm.c (scm_vm_apply): New procedure. (apply_program): New function. (init_program_type): Set the apply function for the program type. * src/vm.c (lookup_variable): Use scm_eval_closure_lookup.
2000-09-04* src/vm_system.c (tail_call): Use SCM_TICK at the beginning.Keisuke Nishida1-6/+9