summaryrefslogtreecommitdiff
path: root/libguile/vm-i-system.c
AgeCommit message (Collapse)AuthorFilesLines
2009-07-22vm support for display closuresAndy Wingo1-0/+88
* libguile/vm-i-system.c (box, empty-box): Boxing values and storing them in local variables. (local-boxed-ref, local-boxed-set): A combination of local-ref then variable-ref/set. (make-closure2, closure-ref, closure-boxed-ref, closure-boxed-set): New ops. The idea is to migrate Guile over to using flat dispay closures. See the paper "Three Implementation Models for Scheme" by Kent Dybvig for more details; this is the "stack-based" model. * libguile/vm-engine.c: * libguile/vm-engine.h: Add the necessary infrastructure to keep track of a "closure" variable, like our "externals" in semantics, but minimal, flat, and O(1) in implementation.
2009-07-21renumber vm ops (objcode cookie bumped)Andy Wingo1-95/+96
* libguile/objcodes.c (OBJCODE_COOKIE): Bump. * libguile/vm-i-loader.c: * libguile/vm-i-scheme.c: * libguile/vm-i-system.c: Renumber instructions, so I can have a bit more space to work.
2009-06-29Added make-nil instruction to VM and use it for Emacs' nil in the compiler.Daniel Kraft1-0/+6
* doc/ref/vm.texi: Document new instruction. * libguile/vm-i-system.c: Add it to the VM. * module/language/assembly.scm: Compile (const %nil) to (make-nil) assembly. * module/language/glil/decompile-assembly.scm: Handle (make-nil) * module/language/elisp/compile-tree-il.scm: Use (const %nil) for nil.
2009-06-17Change Guile license to LGPLv3+Neil Jerram1-6/+7
(Not quite finished, the following will be done tomorrow. module/srfi/*.scm module/rnrs/*.scm module/scripts/*.scm testsuite/*.scm guile-readline/* )
2009-06-07new instructions: make-int64, make-uint64Andy Wingo1-0/+30
* doc/ref/vm.texi (Loading Instructions): Remove references to load-integer and load-unsigned-integer -- they're still in the VM but will be removed at some point. (Data Control Instructions): Add make-int64 and make-uint64. * libguile/vm-i-loader.c (load-unsigned-integer): Allow 8-byte values. But this instruction is on its way out, yo. * libguile/vm-i-system.c (make-int64, make-uint64): New instructions. * module/language/assembly.scm (object->assembly): Write out make-int64 and make-uint64 instructions, using bytevectors to do the endianness conversion. (assembly->object): And pretty-print them back, for disassembly. * module/language/glil/compile-assembly.scm: Don't generate load-integer / load-unsigned-integer instructions.
2009-06-05add long-object-ref, long-toplevel-ref, long-toplevel-setAndy Wingo1-0/+56
* libguile/vm-i-system.c (long-object-ref, long-toplevel-ref) (long-toplevel-set): Add new instructions, for accessing the object table with a 16-bit offset. HTMLprag defines a test program that has more than 256 constants, necessitating this addition. * doc/ref/vm.texi: Mention the new instructions. * module/language/glil/compile-assembly.scm: Emit long refs for object tables bigger than 256 entries.
2009-06-05refactoring for toplevel-ref, toplevel-set, link-nowAndy Wingo1-71/+2
* libguile/vm-i-system.c (toplevel-ref, toplevel-set) * libguile/vm-i-loader.c (link-now): * libguile/vm.c (resolve_variable): Factor out common code to a static method. The compiler can still inline it, so it shouldn't have a significant performance effect. * libguile/vm-engine.c (vm_error_no_such_module): Remove now-unused label.
2009-05-24update docs, clean up VM vestiges, macro docs, fix (/ a b c)Andy Wingo1-6/+0
* doc/ref/api-procedures.texi (Compiled Procedures): Fix for API changes. * doc/ref/compiler.texi (Compiling to the Virtual Machine): Replace GHIL docs with Tree-IL docs. Update the bits about the Scheme compiler to talk about Tree-IL and the expander instead of GHIL. Remove <glil-argument>. Add placeholder sections for assembly and bytecode. * doc/ref/vm.texi: Update examples with what currently happens. Reword some things. Fix a couple errors. * libguile/vm-i-system.c (externals): Remove this instruction, it's not used. * module/ice-9/documentation.scm (object-documentation): If the object is a macro, try to return documentation on the macro transformer. * module/language/assembly/disassemble.scm (disassemble-load-program): Fix problem in which we skipped the first element of the object vector, because of changes to procedure layouts a few months ago. * module/language/scheme/spec.scm (read-file): Remove read-file definition. * module/language/tree-il.scm: Reorder exports. Remove <lexical>, it was a compat shim to something that was never released. Fix `location'. * module/language/tree-il/primitives.scm (/): Fix expander for more than two args to /. * module/system/base/compile.scm (read-file-in): Remove unused definition. * module/system/base/language.scm (system): Remove language-read-file. * module/language/ecmascript/spec.scm (ecmascript): Remove read-file definition.
2009-05-20and, or, cond etc use syntax-rules, compile scheme through tree-ilAndy Wingo1-0/+2
* libguile/vm-i-system.c: * libguile/vm-engine.h (ASSERT_BOUND): New assertion, that a value is bound. Used by local-ref and external-ref in paranoid mode. * module/ice-9/boot-9.scm (and, or, cond, case, do): Since we are switching to use psyntax as the first pass of the compiler, and perhaps soon of the interpreter too, we need to make sure it expands out all forms to primitive expressions. So define expanders for these derived syntax forms, as in the R5RS report. * module/ice-9/psyntax-pp.scm: Regenerate, with core forms fully expanded. * module/ice-9/psyntax.scm (build-void): New constructor, for making undefined values. (build-primref): Add in a hack so that primitive refs in the boot module expand out to toplevel refs, not module refs. (chi-void): Use build-void. (if): Define an expander for if that calls build-conditional. * module/language/scheme/compile-tree-il.scm (compile-tree-il): Use let* so as not to depend on binding order for the result of (current-module). * module/language/scheme/spec.scm (scheme): Switch over to tree-il as the primary intermediate language. Not yet fully tested, but at least it can compile psyntax-pp.scm. * module/language/tree-il/analyze.scm (analyze-lexicals): Arguments don't count towards a function's nlocs. * module/language/tree-il/compile-glil.scm (*comp-module*, compile-glil): Define a "compilation module" fluid. (flatten-lambda): Fix a call to make-glil-argument. Fix bug in heapifying arguments. (flatten): Fix number of arguments passed to apply instruction. Add a special case for `(values ...)'. If inlining primitive-refs fails, try expanding into toplevel-refs if the comp-module's variable is the same as the root variable. * module/language/tree-il/optimize.scm (resolve-primitives!): Add missing src variable for <module-ref>. * test-suite/tests/tree-il.test ("lambda"): Fix nlocs counts. Add a closure test case.
2009-04-17fix handling of pre-modules errors in the vmAndy Wingo1-2/+14
* libguile/vm-i-system.c (toplevel-ref, toplevel-set): Correct situation whereby we would not throw when toplevel vars were unbound, before modules had booted.
2009-04-05Avoid uses of deprecated forms in the VM code.Ludovic Courtès1-4/+4
Reported by Daniel Kraft <d@domob.eu>. * libguile/frames.c, libguile/vm.c: Include <stdlib.h>, use `size_t' instead of `scm_sizet'. * libguile/objcodes.c, libguile/programs.c, libguile/vm-engine.c, libguile/vm-i-loader.c, libguile/vm-i-system.c: Use `scm_list_X ()' instead of the deprecated `SCM_LISTX ()'.
2009-04-04fix nondeterminism in vm-i-system.cAndy Wingo1-2/+4
* libguile/vm-i-system.c (br-if-eq, br-if-not-eq): Fix some nondeterminism caught by GCC 4.4.
2009-02-25fix variable not initialized spurious warningsAndy Wingo1-2/+2
* libguile/vm-i-system.c: Work around some spurious "variable not initialized" messages on Etch's gcc.
2009-02-21implement break and continue, work around overly recursive pmatch expansionAndy Wingo1-0/+4
* libguile/vm-i-system.c (goto/args): On a tail call to a different procedure, init the locals to valid scheme values. Shouldn't matter for well-compiled scheme, but inspecting uninitialized locals could give garbage, or badly-compiled code could cause a crash. * module/language/Makefile.am (NOCOMP_SOURCES): For the moment, don't compile compile-ghil.scm. I need to fix this. * module/language/ecmascript/compile-ghil.scm (load-toplevel): Sigh, and disable stack checking in the evaluator too. Grr. (comp): Implement (unnamed) break and continue. * module/language/ecmascript/parse.scm (parse-ecmascript): Fix var statements in `for' -- though it still doesn't work.
2009-02-19further ecmascript workAndy Wingo1-2/+2
* libguile/vm-i-system.c (drop, return): Declare drop and return as popping one arg from the stack. * module/language/ghil/compile-glil.scm: * module/language/glil/compile-assembly.scm (make-meta): Adjust so that we declare 'drop and 'return calls as popping one arg from the stack. * module/language/ecmascript/compile-ghil.scm (comp, comp-body): Flesh out a bit more. Most significantly, scoping within functions obeys javascript semantics better, modulo bits about with() forms. * module/language/ecmascript/impl.scm: Define some runtime helper routines. * module/language/Makefile.am (SOURCES): Add impl.scm. * module/language/ecmascript/parse.scm (parse-ecmascript): Minor tweaks. * module/language/ecmascript/tokenize.scm (read-identifier): Identifiers now read as symbols, not strings.
2009-02-05in debug mode, make sure that calls to the vm can be captured via make-stackAndy Wingo1-12/+11
* libguile/vm-engine.c (VM_PUSH_DEBUG_FRAMES): New knob, if true we much with the scm_i_last_debug_frame when entering the VM, because sometimes the evaluator doesn't do it for us. (VM_ENGINE): Plug through debug frame fondling. Now, program exit comes back to the main text. Rename err_args to finish_args, and reuse for the return value. * libguile/vm-engine.h (PUSH_LIST): * libguile/vm-i-loader.c: * libguile/vm-i-scheme.c: * libguile/vm-i-system.c: Update for finish_args. (halt): goto vm_done, now, instead of returning directly.
2009-02-05inline call to scm_make_program when making closuresAndy Wingo1-3/+2
* libguile/programs.c (scm_make_program): Add a comment. * libguile/vm-engine.h (INIT_ARGS): Add a couple of UNLIKELY notes. * libguile/vm-i-system.c (make-closure): Inline the call to scm_make_program, which avoids some redundant checks.
2009-02-04make catch cache and restore vm regs, not the vm itself -- speedy speedyAndy Wingo1-1/+0
* libguile/throw.c (scm_c_catch): Stash away the current vm's regs, and restore them if there's a nonlocal exit. There is a terrible case we have to handle if we catch from when the vm smob type isn't registered but the throw has the vm registered, but I think we handle this fine. * libguile/vm-engine.c (vm_run): * libguile/vm-i-system.c (halt): Don't make a dynwind context, so that entering the VM doesn't cons at all, except for the arg list. Maybe we can fix that bit too. * libguile/vm.c (vm_reset_stack): Remove, as there is no more dynwind. (make_vm): Return #f if the tc16 hasn't yet been registered.
2009-02-03inline dispatch to program cmethods, tick in return, remove old goops methodsAndy Wingo1-0/+2
* libguile/objects.c (scm_apply_generic): Inline the case when the generic is a program. * libguile/vm-i-system.c (return): Tick when functions return. * module/oop/goops.scm (object-eqv?, object-equal?): Remove these historical methods.
2009-02-02tick in calls, procedure-name works on compiled proceduresAndy Wingo1-0/+3
* module/system/vm/program.scm: * libguile/programs.h: * libguile/programs.c (scm_program_bindings, scm_program_bindings) (scm_program_properties, scm_program_name): Unfortunately, implement more procs in C, so that C can use them more easily. * libguile/debug.c (scm_procedure_name): Dispatch to scm_program_name as appropriate. * libguile/vm-i-system.c (call): Tick in a call.
2009-02-01don't make intermediate garbage when making vectors in the vmAndy Wingo1-2/+9
* libguile/vm-i-system.c (vector): Don't cons up a list just to make a vector. Saves a couple percent in total cell allocation when loading syncase. Probably not worth it, but foo!
2009-01-29static opcodes; refactor program/objcode division; use new assembly pipelineAndy Wingo1-93/+82
* gdbinit: Untested attempts to get the stack fondling macros to deal with the new program representation. * libguile/frames.c (scm_vm_frame_arguments, scm_vm_frame_source) (scm_vm_frame_local_ref, scm_vm_frame_local_set_x): SCM_PROGRAM_DATA is a struct scm_objcode*. * libguile/instructions.h: * libguile/instructions.c: Hide the instruction table and the struct scm_instruction structure; all access to instructions now goes through procedures. This is because instructions are no longer in a packed array indexed by opcode. Also, declare a mask that all instructions should fit in. * libguile/objcodes.h: * libguile/objcodes.c: Rewrite so that object code directly maps its arity and length from its bytecode. This makes it unnecessary to keep this information in programs, allowing programs to be simple conses between the code (objcodes) and data (the object table and the closure variables). * libguile/programs.c (scm_make_program): Rework so that make-program takes objcode, an object table, and externals as arguments. It's much clearer this way, and we avoid malloc(). * libguile/stacks.c (is_vm_bootstrap_frame): Update for program/objcode changes. * libguile/vm-engine.c (vm_run): Initialize the jump table on the first run, with the opcodes declared in the instruction sources, and with bad instructions raising an error instead of wandering off into the Unknown. * libguile/vm-engine.h (FETCH_LENGTH): Always represent lengths as 3 bytes. The old code was too error-prone. (NEXT_JUMP): Mask the instruction with SCM_VM_INSTRUCTION_MASK. (NEW_FRAME): Update for program/objcode changes. * libguile/vm-expand.h (VM_DEFINE_FUNCTION, VM_DEFINE_INSTRUCTION) (VM_DEFINE_LOADER): Update so that we explicitly specify opcodes, so that we have a stable bytecode API. * libguile/vm-i-loader.c: Update license to LGPLv2+. Explicitly declare opcodes. (load-integer): Use an int instead of a long as the accumulator; still need to revisit this code at some point, I think. (load-program): Simplify, thankfully!! Just creates the objcode slice and rolls with it. * libguile/vm-i-scheme.c: Number the opcodes explicitly. * libguile/vm-i-system.c: Update license to LGPLv2+. Explicitly declare opcodes. (make-closure): Update for new program API. * libguile/vm.c (vm_make_boot_program): Update for new program/objcode API. Still a bit ugly. (scm_load_compiled_with_vm): Update for new program/objcode API. * module/language/assembly.scm (byte-length): Fix byte-length calculation for loaders, and load-program. (code-pack, code-unpack): Start to move things from (system vm conv) here. (object->code, code->object): More things from conv.scm. * module/language/glil.scm (<glil-program>): Add a new field, closure-level. (make-glil-program, compute-closure-level): Calculate the "closure level" when making a glil program. This is the maximum depth of external binding refs in this closure. (unparse-glil): Fix label serialization. * module/language/glil/compile-assembly.scm (make-meta): Prepend #f for the meta's object table, though maybe in the future we can avoid creating assembly in the first place. (assoc-ref-or-acons, object-index-and-alist): GRRR! Caught again by the different sets of arguments to assoc and assoc-ref! (glil->assembly): Attempt to make the <glil-program> case more readable, and fix the bugs. Sorry I don't know how to comment this change any more than this. (glil->assembly): For <glil-module> serialize the whole key, not just the name. (dump-object): subprogram-code is already a list. Serialize integers as strings, not u8vectors. Fix the order of lists and vectors. * module/language/glil/spec.scm (glil): Switch orders, so we prefer glil -> assembly -> objcode. Actually glil->objcode doesn't work any more, needs to be removed I think. * module/language/objcode/spec.scm (objcode->value): s/objcode->program/make-program/. * module/language/scheme/inline.scm: Add acons inline. * module/system/vm/conv.scm (make-byte-decoder): Skip the first 8 bytes, they are header. Handle subprograms properly. Still needs help though. (decode-length): Lengths are always 3 bytes now. * module/system/vm/disasm.scm: Superficial changes to keep things working. I'd like to fix this better in the future. * module/system/vm/frame.scm (bootstrap-frame?): Fixes for program-bytecode. * module/system/vm/program.scm: Export make-program. It's program-objcode now, no more program-bytecode. * module/system/vm/vm.scm (vm-load): Use make-program. * test-suite/tests/asm-to-bytecode.test: New test, very minimal. * module/system/vm/objcode.scm: Export word-size, byte-order, and write-objcode.
2009-01-17move module and meta inside programs' object tablesAndy Wingo1-4/+6
* libguile/programs.h (struct scm_program): Remove the module and meta fields. * libguile/programs.c (scm_c_make_program): Add a new argument, `objs'. If it's a vector, we'll look for the module and the metadata in there, instead of having them in the scm_program structure. (scm_c_make_closure, program_mark, scm_program_meta) (scm_c_program_source, scm_program_module): Adapt to the new program representation. * libguile/objcodes.c (scm_objcode_to_program): Pass #f as the object table when making the program. * libguile/vm-engine.h (CACHE_PROGRAM): * libguile/vm-engine.c (vm_run): Rework to use the simple vector API for getting the current object table. Call the helper, vm_make_boot_program, to make the boot program. * libguile/vm-i-loader.c (load-program): Set the current module and the meta in the object vector, which we pass to scm_c_make_program. * libguile/vm-i-system.c (toplevel-ref, toplevel-set): Adapt to the new program representation. * module/language/glil/compile-objcode.scm (codegen): Clarify.
2009-01-04allow `apply' on %nil-terminated listsAndy Wingo1-6/+10
* libguile/vm-engine.h (PUSH_LIST): Add a parameter to check that the list was proper. * libguile/vm-i-system.c: Adapt PUSH_LIST callsites to pass SCM_NULLP or SCM_NULL_OR_NIL_P, as appropriate. Add a check to return/values*. * libguile/vm.c: Add lang.h header for SCM_NULL_OR_NIL_P. * test-suite/tests/elisp.test: Fix XFAIL for elisp + apply.
2008-12-26remove heap links in VM frames, incorporate vm frames into normal backtracesAndy Wingo1-16/+15
* doc/ref/vm.texi (Stack Layout): Update to remove references to the "heap link". * gdbinit: Update for "heap link" removal. * libguile/frames.c: * libguile/frames.h: Update macros and diagram for removal of "heap link". As part of this, we also remove "heap frames", replacing them with "vm frames", which are much like the interpreter's debug objects, but for VM stacks. That is to say, they don't actually hold the stack themselves, just the pointers into stack that's held by a continuation (either captured or current). * libguile/stacks.c (stack_depth, read_frames): Since a "stack" object is really a copy of information that comes from somewhere else, it makes sense to copy over info from the VM, just as `make-stack' does from the evaluator. The tricky bit is to figure out how to interleave VM and interpreter frames. We do that by starting in the interpreter, and whenever the current frame's procedure is actually a program, we switch to the VM stack, switching back when we reach a "bootstrap frame". The last bit is hacky, but it does work... (is_vm_bootstrap_frame): Hacky predicate to see if a VM frame is a bootstrap frame. (scm_make_stack): Accept a VM frame in addition to debug frames. Probably has some bugs in this case. But in the case that the arg is #t (a common case), do the right thing, capturing the top VM frame as well, and interleaving those frames appropriately on the stack. As an accident, we lost the ability to limit the number of frames in the backtrace. We could add that back, but personally I always want *all* frames in the trace... Narrowing still works fine, though there are some hiccups sometimes -- e.g. an outer cut to a procedure that does a tail-call in VM code will never find the cut, as it no longer exists in the continuation. * libguile/vm.h (struct scm_vm): So! Now that we have switched to save stacks in the normal make-stack, there's no more need for `this_frame' or `last_frame'. On the other hand, we can take this opportunity to fix tracing: when we're in a trace hook, we set `trace_frame' on the VM, so we know not to fire hooks when we're already in a hook. (struct scm_vm_cont): Expose this, as make-stack needs it to make VM frames from VM continuations. * libguile/vm.c (scm_vm_trace_frame): New function, gets the current trace frame. (vm_mark, make_vm): Hook up the trace frame. (vm_dispatch_hook): New hook dispatcher, with a dynwind so it does the right thing if the hook exits nonlocally. * libguile/vm-engine.c (vm_run): No more this_frame in the wind data. * libguile/vm-engine.h (RUN_HOOK): Run hooks through the dispatcher. (ALIGN_AS_NON_IMMEDIATE, POP_LIST_ON_STACK): Remove unused code. (NEW_FRAME): Adapt for no HL in the frame. * libguile/vm-i-system.c (goto/args, mv-call, return, return/values): Adapt for no HL in the frame. * module/system/vm/frame.scm: * module/system/vm/vm.scm: Beginnings of some reworkings, needs more thought.
2008-11-20late-variable-{ref,set} -> toplevel-{ref,set}Andy Wingo1-2/+2
* benchmark/lib.scm: * libguile/vm-i-system.c (toplevel-ref, toplevel-set): * module/system/vm/assemble.scm (codegen): * module/system/vm/disasm.scm (code-annotation): s/late-variable/toplevel/. It's just a better name.
2008-11-01fix for (apply values '(1))Andy Wingo1-1/+1
* libguile/vm-i-system.c (return/values): In the multiple-values-to-a-single-value-continuation (or MV but where N=1), null out the correct number of values from the stack. Fixes aborts on (apply values '(1)). * testsuite/t-values.scm (call-with-values): Add a test.
2008-11-01fix multiple values coming from interpreted or C proceduresAndy Wingo1-2/+20
* libguile/vm-i-system.c (call, goto/args): Handle the case in which a non-program (i.e. interpreted program or a subr) returns multiple values. * testsuite/t-values.scm: Add test case that exhibited this problem.
2008-10-30recompiling with compile environments, fluid languages, cleanupsAndy Wingo1-0/+6
* ice-9/boot-9.scm (compile-time-environment): Remove definition from boot-9 -- instead, autoload it and `compile' from (system base compile). * libguile/objcodes.h: * libguile/objcodes.c (scm_objcode_to_program): Add an optional argument, `external', the external list to set on the returned program. * libguile/vm-i-system.c (externals): New instruction, returns the external list. Only used by (compile-time-environment). * libguile/vm.c (scm_load_compiled_with_vm): Adapt to scm_objcode_to_program change. * module/language/scheme/translate.scm (translate): Actually pay attention to the environment passed as an argument. (custom-transformer-table): Expand out (compile-time-environment) to something that can be passed to `compile'. * module/system/base/compile.scm (*current-language*): Instead of hard-coding `scheme' in various places, use a current language fluid, initialized to `scheme'. (compile-file, load-source-file): Adapt to *current-language*. (load-source-file): Ada (scheme-eval): Removed, no one used this. (compiled-file-name): Don't hard-code "scm" and "go"; instead use the %load-extensions and %load-compiled-extensions. (cenv-module, cenv-ghil-env, cenv-externals): Some accessors for compile-time environments. (compile-time-environment): Here we define (compile-time-environment) to something that will return #f; the compiler however produces different code as noted above. (compile): New function, compiles an expression into a thunk, then runs the thunk to get the value. Useful for procedures. The optional second argument can be either a module or a compile-time-environment; in the latter case, we can recompile even with lexical bindings. (compile-in): If the env specifies a module, set that module for the duration of the compilation. * module/system/base/syntax.scm (%compute-initargs): Fix a bug where the default value for a field would always replace a user-supplied value. Whoops. * module/system/il/ghil.scm (ghil-env-dereify): New function, takes the result of ghil-env-reify and turns it back into a GHIL environment. * scripts/compile (compile): Remove some of the tricky error handling, as the library procedures handle this for us. * test-suite/tests/compiler.test: Add a test for the dynamic compilation bits.
2008-10-18fix bug in self-tail-recursion with "external" variables; other sundriesAndy Wingo1-1/+7
* gdbinit (pp, inst): New commands. * libguile/vm-engine.c (vm_error_not_a_pair): New error case. * libguile/vm-i-scheme.c (VM_VALIDATE_CONS): New macro -- use this instead of SCM_VALIDATE_* because SCM_VALIDATE will exit nonlocally before we have a chance to sync the regs. (car, cdr, set-car, set-cdr): Use VM_VALIDATE_CONS. * libguile/vm-i-system.c (goto/args): Bugfix: when doing a self-tail-recursion, allocate fresh externals. Fixes use of match.go. * module/system/vm/assemble.scm (dump-object!): Add some checks that we aren't dumping out values that the VM can't handle. * module/system/vm/disasm.scm (disassemble-externals): Fix rotten call to `print-info'. * oop/goops/dispatch.scm: Add a FIXME. * testsuite/Makefile.am (vm_test_files): * testsuite/t-closure4.scm (extract-symbols): New test, distilled with much effort out of match.scm. * ice-9/Makefile.am (NOCOMP_SOURCES): Re-enable compilation of match.scm. Yay!
2008-10-16ensure that lists pushed onto the stack are properAndy Wingo1-10/+5
I saw this problem when running elisp.test -- it tries to apply a function to an arglist ending in nil, which obviously is not null. * libguile/vm-engine.h (PUSH_LIST): New helper macro, pushes the elements of a list onto the stack. Checks to make sure that the list is proper. * libguile/vm-i-system.c (list-break, mv-call, apply, goto/apply) (goto/cc): Use LIST_BREAK. * libguile/vm-engine.c (vm_error_improper_list): New error case.
2008-10-16fix asyncs running in the vm; re-enable popen.scm compilationAndy Wingo1-0/+1
* libguile/vm-i-system.c (goto/args): Sync the registers before doing the SCM_TICK. We probably need a different SCM_TICK that saves the regs only if necessary. This fixes GC problems with a compiled popen.scm. * ice-9/Makefile.am: Re-enable popen.scm compilation.
2008-10-11relax an assertion -- the test suite completes without aborting, wheeAndy Wingo1-2/+0
* libguile/vm-i-system.c (call/cc, goto/cc): Don't assert that ip matches vp->ip, because vp->ip is not restored by vm_reset_stack, and indeed it's re-set to 0 by `halt'. But still, perhaps reset_stack and halt should indeed reset vp->ip.
2008-10-09NULLSTACK fixes for nonlocal exits in reentrant pre-wind handlersAndy Wingo1-0/+6
* libguile/vm-i-system.c (goto/cc): Add some asserts here. * libguile/vm.c (capture_vm_cont): Add some asserts here too. (reinstate_vm_cont): Null the correct number of bytes. Add a FIXME. (vm_reset_stack): Make the code a bit clearer. Null the correct number of bytes. * libguile/vm-engine.h (NULLSTACK_FOR_NONLOCAL_EXIT): New macro, handles a very tricky case that took me days to find! Amply commented. Expands to nothing in the normal case. * libguile/vm-i-system.c (call, goto/args, mv-call): Call NULLSTACK_FOR_NONLOCAL_EXIT in the right places. Fixes continuations.test.
2008-10-03precise stack marking, fix some missed references, still imperfectAndy Wingo1-28/+45
* libguile/vm-engine.h (CHECK_STACK_LEAK, NULLSTACK): Add a new mode, VM_ENABLE_STACK_NULLING, that tries to ensure that all stack data past the top of the stack is NULL. This helps to verify the VM's consistency. If VM_ENABLE_STACK_NULLING is not defined, there is no overhead. (DROP, DROPN): Hook into NULLSTACK. (POP_LIST): Hoo, fix a good bug: if CONS triggered a GC, the elements of the list that had not yet been consed would not be marked, because the sp was already below them. (NEXT): Hook into CHECK_STACK_LEAK. (INIT_ARGS): Add a note that consing the rest arg can cause GC. (NEW_FRAME): Cons up the external data after initializing the frame, so that if GC is triggered, the precise marker sees a well-formed frame. * libguile/vm-i-loader.c (load-program): In the four-integers case, use the POP macro so that we can hook into NULLSTACK (if necessary). * libguile/vm-i-scheme.c (ARGS2, ARGS3): Hook into NULLSTACK. * libguile/vm-i-system.c (halt): Null the nvalues. Rework some asserts into using ASSERT, and null the stack when we free the frame. (variable-set): Use DROPN instead of sp -= 2. (BR): Hook into NULLSTACK. (goto/args): Hook into NULLSTACK. In the non-self case, delay updating the frame until after INIT_ARGS so that GC sees a well-formed frame. Delay consing the externals until after the frame is set up, as in NEW_FRAME. (call/cc): Add some asserts. (return): Rework some asserts into ASSERT, and hook into NULLSTACK. (return/values): Hook into NULLSTACK, and use ASSERT. (return/values*) Use ASSERT. * libguile/vm.c (VM_ENABLE_ASSERTIONS, VM_ENABLE_STACK_NULLING): These are the variables that control assertions and nulling. Perhaps we can do these per-engine when we start compiling the debug engine separate from a speedy engine. (vm_mark_stack): Add a precise stack marker. Yay! (vm_cont_mark): Mark the continuation stack precisely. (capture_vm_cont): Record the difference from the vp's stack_base too, so that we can translate the dynamic links when marking the continuation stack. Memset the stack to NULL if we are doing nulling. (reinstate_vm_cont): If we are nulling, null out the relevant part of the stack. (vm_reset_stack): When resetting sp due to a nonlocal exit, null out the stack too. (vm_mark): If we are nulling, assert that there are no extra values on the stack. Mark the stack precisely.
2008-10-02be more like the interpreter in signalling wrong-num-argsAndy Wingo1-5/+3
* libguile/vm-engine.c: Call scm_wrong_num_args in the wrong-num-args case, to be more like the interpreter. * libguile/vm-engine.h (ASSERT): New macro. * libguile/vm-i-system.c (apply, goto/apply): Assert that nargs >= 2, because the compiler should always feed us correct instructions. (call/cc): If no values are returned to the continuation, signal no_values instead of wrong_num_args.
2008-09-30fix compilation of quasiquote with splicing and improper listsAndy Wingo1-0/+6
* libguile/vm-engine.h (POP_CONS_MARK): New macro, analagous to POP_LIST_MARK; used in quasiquote on improper lists. * libguile/vm-i-system.c (cons-mark): New instruction. You know the drill, remove all your .go files please. * module/system/il/compile.scm (codegen): Compile quasiquoted improper lists with splices correctly. Additionally check that we don't have slices in the CDR of an improper list. * testsuite/t-quasiquote.scm: Add a test for unquote-splicing in improper lists.
2008-09-30fix some missed references when calling C functionsAndy Wingo1-9/+7
* gdbinit: Update to be a bit more useful. * libguile/vm-i-system.c: Make sure that arguments to C procedures are visible on the stack so they get marked. Could be a source for the missed references.
2008-09-30compile @ and @@Andy Wingo1-20/+56
* libguile/vm-engine.c (vm_run): Add new error case for resolving @ or @@ references, but there is no such module. Possible if module-public-interface returns #f. * libguile/vm-i-loader.c (link-now): Allow the stack arg to be a sym, as before, or a list, indicating an absolute reference. Could be two separate instructions, but I'm lazy. * libguile/vm-i-system.c (late-variable-ref, late-variable-set): As in link-now, allow the lazy reference to be a list, for @ and @@. * module/language/scheme/translate.scm (custom-transformer-table): Compile @ and @@, and set! forms for both of them. This will ease the non-hygienic pain for exported macros. * module/system/il/compile.scm (make-glil-var): Translate public and private module variable references into glil-module variables. * module/system/il/ghil.scm (ghil-var-at-module!): New function, resolves a variable for @ or @@. * module/system/il/glil.scm (<glil-module>): Revival of <glil-module>, this time with the semantics that it really links to a particular module. * module/system/vm/assemble.scm (<vlink-now>, <vlink-later>): Redefine as taking a "key" as the argument, which may be a sym or a list; see the notes on link-now for more details. (codegen): Compile <glil-module> appropriately. Some duplication here, probably could use some cleanup later.
2008-09-28revert part of 7ff017002ddc980 that caused missed referencesAndy Wingo1-0/+3
* libguile/programs.c (scm_c_make_closure): If the program is actually not a program, abort. This can happen if GC misses a reference, as currently seems to happen. * libguile/vm.c (vm_mark): Revert part of 7ff017002ddc980f684120653549a10c6c7cde5c, which changed the call to scm_mark_locations. I'm 99% *sure* this is wrong, but it seems to prevent missed references when recompiling the .go files in guile itself. Needs revisiting soon, but for the time being we can go back to where we were a couple of days ago. * libguile/vm-i-system.c (halt, vector, vector-mark): Sync the registers before calling into C, as it may GC.
2008-09-25fix handling of multiple values from c functionsAndy Wingo1-2/+2
* libguile/vm-i-system.c (mv-call, goto/cc): Fix handling of values returns from C or interpreted functions.
2008-09-25compile call/cc, yee haAndy Wingo1-10/+59
* libguile/vm-i-system.c (call, goto/args): Add a FIXME for handling the case in which a call to the interpreter returns a values object. (call/cc, goto/cc): Flesh out, and handle full continuations (with the C stack also). * module/language/scheme/translate.scm (custom-transformer-table): Compile call-with-current-continuation. This is necessary so that the called procedure is called in tail position. * module/system/il/compile.scm (codegen): Translate apply to goto/apply, call/cc to goto/cc, etc when in tail position.
2008-09-18lambda-lifting for (lambda () ...) as consumer of call-with-valuesAndy Wingo1-0/+25
* libguile/vm-engine.c (vm_run): Add new error case, vm_error_not_enough_values. * libguile/vm-i-system.c (goto/nargs, call/nargs): So, in these cases, if we get too many values, we don't truncate the values like we do in the single-value continuation case, or in the mvbind case. What to do? I guess we either truncate them here, or only allow the correct number of values. Dunno. Mark the code as a fixme. (truncate-values): New instruction, for mv-bind: checks that the number of values on the stack is compatible with the number of bindings we have arranged for them, truncating if necessary. * module/language/scheme/translate.scm (custom-transformer-table): Compile receive as a primary form -- not so much because it is a primary form, but more to test the mv-bind machinery. Also it's more efficient, I think. * module/system/il/compile.scm (lift-variables!): New helper, factored out of `optimize'. (optimize): Add a few more cases. Adapt `lambda' optimization, which isn't much. I'm not happy with ghil as a mungeable language. Add a case for call-with-values with the second argument is a lambda: lift the lambda. Untested. (codegen): Refactor the push-bindings! code. Compile mv-bind. * module/system/il/ghil.scm (<ghil-mv-bind>): Add mv-bind construct, along with its procedures. * module/system/il/glil.scm (<glil-mv-bind>): Add mv-bind construct, different from the high-level one. It makes sense in the source, I think. * module/system/vm/assemble.scm (codegen): Assemble glil-mv-bind by pushing onto the bindings list, and actually push some code to truncate the values.
2008-09-16compile call-with-values, woot!Andy Wingo1-5/+28
* libguile/vm-engine.c (vm_run): Add another byte onto the bootstrap program, as the offset passed to mv-call now takes two bytes. * module/system/vm/frame.scm (bootstrap-frame?): Update for the new bootstrap length. Really we should just check for 'halt though. * libguile/vm-i-system.c (FETCH_OFFSET): New helper, used in BR(). (goto/nargs, call/nargs): Versions of goto/args and call, respectively, that take the number of arguments from a value on the top of the stack. (mv-call): Call FETCH_OFFSET to get the offset. * module/language/scheme/translate.scm (custom-transformer-table): Compile call-with-values to <ghil-mv-call>. There is some trickery because of the r4rs.scm call-with-values trampolines. * module/system/il/ghil.scm: Add <ghil-mv-call> and accessors. * module/system/il/compile.scm (codegen): Compile <ghil-mv-call>. * module/system/il/glil.scm: Add <glil-mv-call>, which needs some special assembly because of the label. Fix some typos. * module/system/vm/assemble.scm (byte-length): New helper, factored out and made more general. (codegen): Assemble mv-call, including the label. (check-length): New helper, makes sure that the addressing is consistent within the produced object code. (stack->bytes): Rewrite to be more generic -- now `br' instructions aren't the only ones jumping around in the instruction stream. * module/system/vm/conv.scm (make-byte-decoder): Return two values in the #f case. * module/system/vm/disasm.scm (disassemble-bytecode): Rewrite, because the previous implementation depended on a guile interpreter quirk: namely, that multiple values could be represented within one value, and destructured later.
2008-09-15add special case for (apply values ...)Andy Wingo1-41/+64
* libguile/vm-engine.c (vm_run): Move nvalues to the top level, to avoid (spurious, it seems) gcc warnings about it being used uninitialized. * libguile/vm-i-system.c (halt, return/values): Adapt to gcc silliness. Deindent some of return/values. (return/values*): New instruction, does what (apply values . args) would do. * module/language/scheme/translate.scm (custom-transformer-table): Move the apply and @apply cases here from inline.scm, because we need some more cleverness when dealing with cases like (apply values . args). (lookup-apply-transformer): Define an eval transformer for `values', turning it into ghil-values*. * module/system/il/compile.scm (codegen): Compile <ghil-values*> into return/values*. * module/system/il/ghil.scm: Add <ghil-values*> and accessors. (ghil-lookup): Add optional argument, define?, which if false tells us not to actually cache the binding if it is not found in the toplevel. * module/system/il/inline.scm: Remove apply clauses. * module/system/vm/frame.scm (bootstrap-frame?): Update heuristic for bootstrap-frame?, as the bootstrap frame is now 5 bytes since it accepts multiple values.
2008-09-14add multiple values support to the vmAndy Wingo1-1/+133
* libguile/vm-engine.c (vm_run): The bootstrap program now uses mv_call, so as to allow multiple values out of the VM. (It did before, because multiple values were represented internally as single scm_values objects, but now that values go on the stack, we need to note the boot frame as accepting multiple values.) (vm_error_no_values): New error, happens if you pass no values into a single-value continuation. Passing more than one is OK though, it just takes the first one. * libguile/vm-i-system.c (halt): Assume that someone has pushed the number of values onto the stack, and package up that number of values as a scm_values() object, for communication with the interpreter. (mv-call): New instruction, calls a procedure with a multiple-value continuation, even handling calls out to the interpreter. (return/values): New instruction, returns multiple values to the continuation. If the continuation is single-valued, takes the first value or errors if there are no values. Otherwise it returns to the multiple-value return address, pushing the number of values on top of the values. * module/system/il/compile.scm (codegen): Compile <ghil-values> forms. * module/system/il/ghil.scm (<ghil-values>) Add new GHIL data structure and associated procedures. * module/language/scheme/translate.scm (custom-transformer-table): Compile (values .. ) forms into <ghil-values>.
2008-09-13rename tail-call to goto/args, add some more tail instructionsAndy Wingo1-4/+34
* libguile/vm-i-system.c (call): Rename continuation invocation from `vm_call_cc' to `vm_call_continuation', because that's what it really does. Add a note that it doesn't handle multiple values at the moment. (goto/arg): Renamed from tail-call, in deference to the progenitors, on Dale Smith's suggestion. (goto/apply): New instruction, for `apply' in a tail context. Not yet used, or vetted for that matter. (call/cc): No need to pop the program, I don't think; although this isn't tested either. (goto/cc): New instruction, for call/cc in a tail context. * module/language/scheme/translate.scm (*forbidden-primitives*): Rename from %forbidden-primitives. * module/system/il/compile.scm (codegen): Adapt to goto/args instead of tail-call. * module/system/il/inline.scm: Start inlining some macros used in r4rs.scm -- not yet fully tested. * ice-9/boot-9.scm: Allow load of a compiled r4rs file.
2008-09-13add a multiple values return address to stack framesAndy Wingo1-5/+7
* libguile/frames.c (frame-mv-return-address): New accessor. * libguile/frames.h: Update frame diagram. (SCM_FRAME_UPPER_ADDRESS): Update for data area growing by one pointer. (SCM_FRAME_MV_RETURN_ADDRESS): New macro. * libguile/vm-engine.h (NEW_FRAME): Update for frame getting bigger by a pointer. In a normal NEW_FRAME, set the MV return address to NULL, to indicate that this continuation does not accept multiple values. * libguile/vm-i-system.c (tail-call): Update frame replacement code to understand the MV return address. (return): Make room for the MVRA.
2008-09-13inline frame replacement in tail-callAndy Wingo1-5/+47
* libguile/programs.c (program_print): Only try to lookup write-program if the module system is booted. * libguile/vm-engine.h (FREE_FRAME): Remove, it's now inlined everywhere. * libguile/vm-i-system.c (tail-call): Inline FREE_FRAME, and implement the calling bits here. Will make things more hackable.
2008-09-13inline FREE_FRAME in haltAndy Wingo1-2/+13
* libguile/vm-i-system.c (halt): Inline FREE_FRAME, specialized for the halt case.