summaryrefslogtreecommitdiff
path: root/module/system/vm/program.scm
Commit message (Collapse)AuthorAgeFilesLines
...
* remove "externals" from the vmAndy Wingo2009-07-231-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * libguile/frames.c (scm_frame_external_link): Removed. * libguile/frames.h: No need to have the "external link" in the stack frame -- update macros to take the new situation into account. * libguile/objcodes.h (struct scm_objcode): Rename the nexts field to "unused". In the future we can use it for nlocs, I think. (SCM_OBJCODE_NEXTS): removed. * libguile/programs.h: * libguile/programs.c (scm_make_program): Expect the third argument to be a vector of free variables, not a list of free variables. SCM_BOOL_F indicates no free variables, not SCM_EOL. (program_mark): Adapt. (scm_program_arity): No more nexts. (scm_program_free_vars): Replaces scm_program_externals. * libguile/vm-engine.c (VM_CHECK_EXTERNAL) (vm_engine): No need for the "external" var. * libguile/vm-engine.h (CACHE_PROGRAM): Update for SCM_PROGRAM_FREE_VARS instead of SCM_PROGRAM_EXTERNALS. (NEW_FRAME): Update for new frame size, and no need to cons up externals. Yay :) * libguile/vm-i-loader.c (load-program): Update for scm_make_program. * libguile/vm-i-system.c (external-ref, external-set): No more. (make-closure): No more. (goto/args): No need to re-cons externals here. Update for new stack frame size. (mv-call, return, return/values): Update for new frame size. No need to reinstate externals on return. * libguile/vm.c (really_make_boot_program, scm_load_compiled_with_vm): Update for scm_make_program. * module/language/objcode/spec.scm (objcode-env-externals): Treat '() as #f, for the externals. Need to clean this up later... * module/system/vm/program.scm (arity:nexts): Remove. Rename program-external to program-free-vars.
* Switch remaining GPLv2+ Guile-VM headers to LGPLv3+.Ludovic Courtès2009-07-151-11/+10
| | | | | | | | * module/system/base/compile.scm, module/system/base/syntax.scm, module/system/repl/common.scm, module/system/repl/describe.scm, module/system/vm/instruction.scm, module/system/vm/objcode.scm, module/system/vm/profile.scm, module/system/vm/program.scm, module/system/vm/trace.scm: Switch header from GPLv2+ to LGPLv3+.
* frame, program, objcode, etc inits use load-extensionAndy Wingo2009-03-271-1/+1
| | | | | | | | | | | | | | | | | | * libguile/extensions.h: Define a scm_t_extension_init_func. * libguile/frames.c: * libguile/instructions.c: * libguile/objcodes.c: * libguile/programs.c: * libguile/vm.c: Register extension init funcs. Should play nicer with a static Guile, in addition to working on Darwin with non-default installation prefixes without munging DYLD_LIBRARY_PATH. * 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: Use load-extension.
* export procedure-arguments from ice-9 sessionAndy Wingo2009-02-251-1/+13
| | | | | | | | * module/system/vm/program.scm (program-arguments): New function, used by procedure-arguments. * module/ice-9/session.scm (procedure-arguments): New exported function, returns an alist describing the given procedure.
* propagate much more source info through compilationAndy Wingo2009-02-101-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * module/language/ghil/compile-glil.scm (codegen): Record source location for offset 0 into a lambda, if we can. * module/language/scheme/compile-ghil.scm (translate-1) (define-scheme-translator): In the retrans procedures, propagate the location information from the enclosing expression if the subexpression has no location information. Gives source information to many more expressions. (location): Just propagate the source properties as they are, the glil->assembly compiler will interpret them. * module/language/glil.scm (<glil>): Change glil-source to take "props" and not "loc", as it's the source properties that we're interested in. * module/language/glil/compile-assembly.scm (limn-sources): New function, takes a list of addr-source property pairs and "compresses" them for serialization to disk. (glil->assembly): Limn the sources before writing them to disk. Avoid non-tail recursion when determining total byte length of code. * module/system/vm/program.scm (source:file, source:line, source:column): Update for new source representation. (program-source): Export. (write-program): Nicer pretty-printing of anonymous procedures. * libguile/backtrace.c (display_backtrace_get_file_line): Update for the new VM source representation. * libguile/programs.h: * libguile/programs.c (scm_program_sources): Update for the new serialized source representation, where the filename is not in the stream unless it changes. (scm_program_source): New exported function, looks up the source for a given ip offset. (scm_c_program_source): Update to return the last source information that was <= the given IP, because we only serialize source info when it changes.
* tick in calls, procedure-name works on compiled proceduresAndy Wingo2009-02-021-18/+0
| | | | | | | | | | | | | * 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.
* static opcodes; refactor program/objcode division; use new assembly pipelineAndy Wingo2009-01-291-8/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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.
* proper printing of thunks, reduced disasm verbosityAndy Wingo2008-11-021-1/+1
| | | | | | | | * module/system/vm/disasm.scm (disassemble-program): Don't print the nargs= nrest= etc line, it's redundant. * module/system/vm/program.scm (program-bindings-as-lambda-list): If the program bindings is null, then that's that.
* fix use of `binding' data abstractionAndy Wingo2008-10-161-7/+11
| | | | | | | | | | | | | * module/system/vm/assemble.scm (make-temp-binding, btemp:name) (btemp:extp, btemp:index): Don't abuse program.scm's make-binding to make something that actually isn't a binding. (codegen): Do use program.scm's make-binding to make something that actually is a binding. * module/system/vm/program.scm (binding:start, binding:end): New accessors. (make-binding): Expand to have the start and end arguments in the constructor.
* make disassembly better -- a more woven text.Andy Wingo2008-10-121-3/+3
| | | | | | | | | | | | | | | | | | | | * module/system/vm/assemble.scm (pop): Define a pop here too. (codegen): Rework how bindings are represented in a program's meta-info, so they declare their range in the binding list instead of you having to figure out when they end. * module/system/vm/conv.scm (make-byte-decoder): Return the end-address as well; requires a change to callers. * module/system/vm/disasm.scm (disassemble-objcode, disassemble-program) (disassemble-bytecode, disassemble-objects, disassemble-externals) (disassemble-meta, source->string, make-int16, code-annotation) (print-info): Rework to display my domination of `format', and, more seriously, start to integrate the "subsections" of the disassembly into the main disassembly text. * module/system/vm/program.scm (program-bindings-as-lambda-list): Update for new bindings format; should be more correct.
* tweaks for printing programsAndy Wingo2008-09-131-1/+3
| | | | | | | | | | | | * module/system/vm/program.scm (program-bindings-as-lambda-list): Handle the bindings-is-null case too -- not sure how it comes about, though. A thunk with no let, perhaps. (write-program): Another default for the name: the source location at which it was defined. * libguile/programs.c (program_print): Add some "logic" to stop doing detailed prints if one print had a nonlocal exit -- preventing exceptions in backtraces.
* programs can now get at their names, and print nicelyAndy Wingo2008-09-131-1/+21
| | | | | | | | | | | | | | | * module/system/vm/frame.scm (frame-call-representation) (frame-program-name): Rename program-name to frame-program-name, and use the program-name if it is available. * module/system/vm/program.scm (program-bindings): Return #f if there are no bindings. (program-name): New public procedure. (program-bindings-as-lambda-list, write-program): A more useful writer for programs. * libguile/programs.c (scm_bootstrap_programs, program_print): Add a smob printer for programs, which dispatches to `write-program'.
* rework late binding resolution to be simpler and more efficientAndy Wingo2008-09-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | * libguile/programs.h (struct scm_program): * libguile/programs.c (scm_c_make_program): Record the current module when making a program. This replaces the per-late binding recorded module in the generated code, which should be more efficient, both in terms of garbage, and in not calling resolve-module. (program-module): New accessor. * module/system/vm/program.scm: Add program-module to exports. * libguile/vm-i-loader.c (link-later): Remove this instruction, since now the entry in the object table is just a symbol, and can be loaded with load-symbol. * libguile/vm-i-system.c (late-variable-ref, late-variable-set): Rework so as to look up in the module of the current program. The logic could be condensed quite a bit if scm_module_lookup () knew what to do with mod==#f. * module/system/vm/assemble.scm (dump-object!): Dump <vlink-later> just as load-symbol, as mentioned in the note on link-later. * module/system/il/ghil.scm: Update comment to reflect the new reality.
* use #:keywords in module/*.scm, not :keywordsAndy Wingo2008-09-091-1/+1
| | | | | | | | | * module/system/base/syntax.scm (keywords): Don't enable :keywords, it breaks code that may assume that ':foo is a symbol, like boot-9. * module/*.scm: Don't use :keywords, use #:keywords. The user can decide if she wants #:keywords in their .guile, and :keywords might make us compile modules differently.
* lazily load meta info, for less consageAndy Wingo2008-09-081-3/+6
| | | | | | | | | | | | | | * module/system/vm/assemble.scm (make-meta, codegen): Hide the "meta" information -- the names of the bindings, source info, procedure properties, etc -- behind a lambda. This way, loading up a program conses less, because the metadata stays as mmap'd code until it is needed. * libguile/vm-i-loader.c (load-program): Adjust load-program to expect the metadata to be a program. * module/system/vm/program.scm (program-bindings, program-sources) (program-properties): Adjust to new meta format.
* merge guile-vm into libguile itselfAndy Wingo2008-08-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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?
* improve source loc info in nonlocal exits and backtracesAndy Wingo2008-08-081-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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/.
* fix stack corruption on vm-save-stack; more robust with nonlocal exitsAndy Wingo2008-08-071-1/+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.
* big reorg of scheme modules -- e.g. programs.c -> (system vm program)Andy Wingo2008-08-071-0/+63
This reorganization kills the ugly module-export-all hacks in bootstrap.scm and core.scm. In fact, it gets rid of core.scm entirely, breaking out its functionality into separate files. * module/system/vm/trace.scm: * module/system/vm/profile.scm: * module/system/vm/disasm.scm: * module/system/vm/debug.scm: * module/system/vm/conv.scm: * module/system/vm/assemble.scm: * module/system/repl/repl.scm: * module/system/repl/common.scm: * module/system/base/compile.scm: * module/system/repl/command.scm: Update for changes, and fix a bug in procedure-documentation. * module/system/vm/bootstrap.scm: Just call scm_bootstrap_vm, which handles setting load-compiled for us. * module/system/vm/core.scm: Removed, functionality folded into other modules. * module/system/vm/frame.scm: Export the C frame procedures here; also move scheme functions from core.scm here. * module/system/vm/instruction.scm: New file, exports procedures from instructions.c. * module/system/vm/objcode.scm: New file, exports procedures from objcodes.c. * module/system/vm/program.scm: New file, exports procedures from programs.c, and some scheme functions originally from core.scm. * module/system/vm/vm.scm: New file, from vm.c and core.scm. * src/Makefile.am (libguile_vm_la_SOURCES): Add bootstrap.h. * src/bootstrap.h: New file, prototypes scm_bootstrap_vm (), which the scm_init_* functions call. * src/frames.h: * src/frames.c (scm_init_frames): * src/frames.c (scm_bootstrap_frames): * src/vm.h: * src/instructions.h: * src/instructions.c (scm_init_instructions): * src/instructions.c (scm_bootstrap_instructions): * src/objcodes.h: * src/objcodes.c (scm_bootstrap_objcodes): * src/objcodes.c (scm_init_objcodes): * src/programs.h: * src/programs.c (scm_bootstrap_programs): * src/programs.c (scm_init_programs): * src/vm.c (scm_bootstrap_vm): * src/vm.c (scm_init_vm): Call scm_bootstrap_vm() before doing anything in an init function. Bootstrap_vm will call bootstrap_instructions(), etc to initialize types, then set load-compiled to point to load-compiled/vm. * src/vm.c (scm_load_compiled_with_vm): Code to load .go files, if they're present.