1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-30 20:00:19 +02:00
Commit graph

44 commits

Author SHA1 Message Date
Andy Wingo
c4c098e355 procedure-properties for RTL functions
* module/system/vm/assembler.scm (link-procprops, link-objects): Arrange
  to write procedure property links out to a separate section.

* libguile/procprop.c (scm_procedure_properties):
* libguile/programs.h:
* libguile/programs.c (scm_i_rtl_program_properties):
* module/system/vm/debug.scm (find-program-properties): Wire up
  procedure-properties for RTL procedures.  Yeah!  Fistpumps!  :)

* module/system/vm/debug.scm (find-program-debug-info): Return #f if the
  string is "", as it is if we don't have a name.  Perhaps
  elf-symbol-name should return #f in that case...

* test-suite/tests/rtl.test: Add some tests.
2013-06-09 23:59:19 +02:00
Andy Wingo
bf8328ec16 procedure-documentation works on RTL procedures
* libguile/procprop.h:
* libguile/procprop.c (scm_procedure_documentation): Move here from
  procs.c, and to make the logic more similar to that of procedure-name,
  which allows RTL programs to dispatch to rtl-program-documentation.

* libguile/programs.c (scm_i_rtl_program_documentation):
* libguile/programs.h:
* module/system/vm/program.scm (rtl-program-documentation): New
  plumbing.

* module/system/vm/debug.scm (find-program-docstring): New interface to
  grovel ELF for a docstring.
2013-06-09 23:59:01 +02:00
Andy Wingo
eb2bc00fb3 Wire up ability to print RTL program arities
* libguile/procprop.c (scm_i_procedure_arity): Allow RTL programs to
  dispatch to scm_i_program_arity.

* libguile/programs.c (scm_i_program_print): Refactor reference to
  write-program.
  (scm_i_rtl_program_minimum_arity): New procedure, dispatches to
  Scheme.
  (scm_i_program_arity): Dispatch to scm_i_rtl_program_minimum_arity if
  appropriate.

* module/system/vm/debug.scm (program-minimum-arity): New export.

* module/system/vm/program.scm (rtl-program-minimum-arity): New internal
  function.
  (program-arguments-alists): New helper, implemented also for RTL
  procedures.
  (write-program): Refactor a bit, and call program-arguments-alists.

* test-suite/tests/rtl.test ("simply procedure arity"): Add tests that
  arities make it all the way to cold ELF and back to warm Guile.
2013-06-09 23:43:25 +02:00
Andy Wingo
e65f80af42 RTL programs print with their name
* libguile/print.c (iprin1): Use scm_i_program_print for RTL programs
  too.

* libguile/procprop.c (scm_procedure_name): For RTL programs, call
  scm_i_rtl_program_name if there is no override.

* libguile/programs.h:
* libguile/programs.c (scm_i_rtl_program_name): New helper, dispatches
  to (system vm program).
  (scm_i_program_print): For RTL programs, the fallback prints the code
  pointer too.

* module/system/vm/program.scm (rtl-program-name): Use the debug info to
  get an RTL program name.
  (write-program): Work with RTL programs too.

* test-suite/tests/rtl.test ("procedure name"): Add test.
2013-06-09 19:52:10 +02:00
Andy Wingo
510ca12687 add new rtl vm
* libguile/vm-engine.c (rtl_vm_engine): Add new VM.
  (vm_engine): Add support for calling RTL programs.

* libguile/tags.h (scm_tc7_rtl_program): New type for procedures that
  run on the new VM.
* libguile/evalext.c (scm_self_evaluating_p):
* libguile/goops.c (scm_class_of):
* libguile/print.c (iprin1):
* libguile/procprop.c (scm_i_procedure_arity):
* libguile/procs.c (scm_procedure_p): Add hooks for the new tc7.

* libguile/programs.h:
* libguile/programs.c (scm_make_rtl_program, scm_i_rtl_program_print)
  (scm_rtl_program_p, scm_rtl_program_code):
* module/system/vm/program.scm: Add constructors and accessors for the
  new "RTL programs".

* libguile/vm.c (rtl_boot_continuation): Define a boot program.
  (rtl_apply, rtl_values): New static RTL programs.

* libguile/frames.c (scm_frame_num_locals): Adapt for frames of RTL
  programs.

* libguile/frames.h: Add description of RTL frames.

* libguile/Makefile.am: Add rules to generate vm-operations.h.
* .gitignore: Ignore vm-operations.h.
* module/system/vm/instruction.scm:
* libguile/instructions.c:
* libguile/instructions.h: Use vm-operations.h to define enumerated
  values for the new RTL opcodes.  Define some helper macros to pack and
  unpack 32-bit instruction words.
  (rtl-instruction-list): New function, exported by (system vm
  instruction).

* libguile/objcodes.c: Wire up the bits needed to detect the new RTL
  bytecode and load it, as appropriate.
2013-05-31 09:48:16 -04:00
Andy Wingo
9f17d967c9 More procedure-arguments-alist documentation and a bugfix
* doc/ref/api-procedures.texi (Compiled Procedures): Expand
  program-arguments-alist and program-lambda-list documentation.

* module/system/vm/program.scm (arity->arguments-alist): Fix the rest
  arg if there are also keyword args, a bug found while documenting!

* test-suite/tests/session.test ("procedure-arguments"): Update.
2013-01-07 22:02:26 +01:00
Cedric Cellier
6fca8730f7 document program-arguments-alist and program-lambda-list 2013-01-07 20:37:07 +01:00
Andy Wingo
b262b74b51 add program-sources-pre-retire to core and define frame-next-source
* libguile/programs.h:
* libguile/programs.c (scm_program_source): Add an optional arg, the
  sources table to traverse. Defaults to the result of
  scm_program_sources.

* module/system/vm/program.scm (program-sources-pre-retire): Move
  definition here from (system vm traps), and export.

* module/system/vm/traps.scm: Adapt.

* module/system/vm/frame.scm (frame-next-source): New exported binding,
  returns the source line corresponding to the next instruction instead
  of the previous instruction.
2010-10-08 12:31:56 +02:00
Andy Wingo
e867d563a5 add source:line-for-user, returning a 1-indexed line number
* module/system/vm/program.scm (source:line-for-user): New exported
  procedure, returns a 1-indexed line, suitable for presentation to a
  user.
  (write-program): Use source:line-for-user when making fallback names.

* module/system/vm/coverage.scm (coverage-data->lcov):
* module/language/assembly/disassemble.scm (source->string):
* module/system/repl/debug.scm (print-frame): Use source:line-for-user.
2010-10-01 18:15:23 +02:00
Ludovic Courtès
f9a86f72a6 Add program-free-variables' to (system vm program)'.
* module/system/vm/program.scm (program-free-variables): New procedure.

* module/language/objcode/spec.scm (program-free-variables): Remove.
2010-05-07 13:47:52 +02:00
Andy Wingo
1e23b461ec remove program-name, program-documentation
* libguile/programs.h:
* libguile/programs.c (scm_program_name): Remove. procedure-name is
  sufficient.

* module/system/vm/program.scm (program-name): Remove from exports list.
  (program-documentation): Remove; procedure-documentation is
  sufficient.

* libguile/debug.c (scm_procedure_name): Remove special case for
  programs.

* module/language/tree-il/analyze.scm (validate-arity): Use
  procedure-name.

* module/ice-9/documentation.scm (object-documentation): Just use
  procedure-documentation, without special cases for programs.
2010-04-17 15:21:08 +02:00
Andy Wingo
07e424b753 scm_i_program_properties is internal; just use procedure-properties
* libguile/programs.h:
* libguile/programs.c (scm_i_program_properties): Make internal.
  (scm_program_name): Use scm_i_program_properties.

* libguile/procprop.c (scm_procedure_properties): Use
  scm_i_program_properties, for programs.

* libguile/procs.c (scm_procedure_documentation): Use procedure-property
  to get to 'documentation, not program-property.

* module/system/vm/program.scm (program-properties, program-property):
  Remove from the exports list.
  (program-documentation): Use procedure-property.

* module/texinfo/reflection.scm (macro-arguments)
  (macro-additional-stexi)
  (object-stexi-documentation): Use procedure-property, not
  program-property.
2010-04-17 15:21:08 +02:00
Andy Wingo
44602b0868 rename libguile to libguile-@EFFECTIVE_VERSION@, currently libguile-2.0
* libguile/Makefile.am (lib_LTLIBRARIES): Instead of just "libguile.la",
  make "libguile-@EFFECTIVE_VERSION@.la". This allows multiple versions
  of Guile to be installed at once. See
  http://www106.pair.com/rhp/parallel.html for a rationale.

  (libguile_@GUILE_EFFECTIVE_VERSION@_la_CFLAGS):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (EXTRA_libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_DEPENDENCIES):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_LIBADD):
  (libguile_@GUILE_EFFECTIVE_VERSION@_la_LDFLAGS): Fixup automake vars
  to include the effective version.
  (guile_LDADD): Fix up the spelling of libguile.

* libguile/bytevectors.c (scm_bootstrap_bytevectors):
* libguile/foreign.c (scm_register_foreign):
* libguile/i18n.c (scm_bootstrap_i18n):
* libguile/instructions.c (scm_bootstrap_instructions):
* libguile/objcodes.c (scm_bootstrap_objcodes):
* libguile/programs.c (scm_bootstrap_programs):
* libguile/vm.c (scm_bootstrap_vm): Register extensions using e.g.
  "libguile-2.0" as the libname -- i.e., including the effective version
  in the libname.

* module/ice-9/i18n.scm:
* module/rnrs/bytevector.scm:
* module/rnrs/io/ports.scm:
* module/system/foreign.scm:
* module/system/vm/instruction.scm:
* module/system/vm/objcode.scm:
* module/system/vm/program.scm:
* module/system/vm/vm.scm: When doing a load-extension for something in
  Guile, use the effective version also.

* meta/guile-2.0-uninstalled.pc.in (Libs):
* meta/guile-2.0.pc.in (Libs): Use -lguile-@EFFECTIVE_VERSION@. This
  change should mean that code built against Guile should not be
  affected by the libguile rename.

* guile-readline/Makefile.am (libguilereadline_v_@LIBGUILEREADLINE_MAJOR@_la_LIBADD):
* srfi/Makefile.am
  (libguile_srfi_srfi_1_v_@LIBGUILE_SRFI_SRFI_1_MAJOR@_la_LIBADD):
  (libguile_srfi_srfi_4_v_@LIBGUILE_SRFI_SRFI_4_MAJOR@_la_LIBADD):
  (libguile_srfi_srfi_13_14_v_@LIBGUILE_SRFI_SRFI_13_14_MAJOR@_la_LIBADD):
  (libguile_srfi_srfi_60_v_@LIBGUILE_SRFI_SRFI_60_MAJOR@_la_LIBADD):
* test-suite/standalone/Makefile.am (test_num2integral_LDADD):
  (test_round_LDADD):
  (libtest_asmobs_la_LIBADD):
  (libtest_ffi_la_LIBADD):
  (test_list_LDADD):
  (test_unwind_LDADD):
  (test_conversion_LDADD):
  (test_loose_ends_LDADD):
  (test_scm_c_read_LDADD):
  (test_scm_take_locale_symbol_LDADD):
  (test_scm_take_u8vector_LDADD):
  (libtest_extensions_la_LIBADD):
  (test_with_guile_module_LDADD):
  (test_scm_with_guile_LDADD): Fix up the spelling of libguile.la.
2010-03-16 21:20:34 +01:00
Andy Wingo
8470b3f45b fix texinfo reflection for procedures
* module/system/vm/program.scm (program-arguments-alist): Rename from
  program-arguments, a name shadowed by features.c
  (arglist->arguments-alist, arity->arguments-alist)
  (arguments-alist->lambda-list, program-lambda-list, write-program):
  Adapt callers.

* module/system/vm/frame.scm (frame-lookup-binding): Return #f if the
  binding is not found, not an error.
  (frame-binding-set!, frame-binding-ref): Adapt to error appropriately.
  (frame-arguments): Dispatch to frame-call-representation.
  (frame-call-representation): Refactor a bit.

* module/ice-9/session.scm (procedure-arguments): Adapt to
  program-arguments name change.

* module/texinfo/reflection.scm (get-proc-args): Refactor to actually
  work with VM procedures.
2010-01-12 22:50:10 +01:00
Andy Wingo
136b5494d1 programs print as #<procedure ...>
* module/system/vm/program.scm (write-program): Print as #<procedure
  ...>. Fix stdin printing.

* doc/ref/vm.texi: Update a little bit.
2010-01-12 00:19:18 +01:00
Andy Wingo
6f16379e9a allocate free variables inline to closures
* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/programs.h (SCM_PROGRAM_FREE_VARIABLES)
  (SCM_PROGRAM_FREE_VARIABLE_REF, SCM_PROGRAM_FREE_VARIABLE_SET)
  (SCM_PROGRAM_NUM_FREE_VARIABLES):
* libguile/programs.c (scm_make_program, scm_program_num_free_variables)
  (scm_program_free_variable_ref, scm_program_free_variable_set_x):
  Allocate free variables inline with programs, instead of being in a
  vect. Should improve locality, and require fewer local variables in
  the VM.

* libguile/vm-engine.c (vm_engine): Remove free_vars and free_vars_count
  variables.

* libguile/vm-engine.h (CACHE_PROGRAM): No need to muck with free_vars
  and free_vars_count.
  (CHECK_FREE_VARIABLE): Update for inline free vars.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Update for inline free
  vars.
  (make-closure, fix-closure): Take the closure vals as separate stack
  args, and copy or fix them inline into the appropriate closure.

* module/language/objcode/spec.scm (program-free-variables): Define a
  local version of this removed function.

* module/language/tree-il/compile-glil.scm (flatten): Adjust to not make
  a vector when making closures.

* module/system/vm/program.scm: Export program-num-free-variables,
  program-free-variable-ref, program-free-variable-set!, and remove
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update to not make vectors
  when making closures.
2010-01-09 16:43:26 +01:00
Andy Wingo
08d7492cf0 add gbt macro to gdbinit, and fix a bug in program-arity
* gdbinit: Add gbt macro, to make a Guile backtrace whenever you want.
* module/system/vm/program.scm (program-arity): If ip is #f, just take
  the first arity.
2009-12-10 16:03:23 +01:00
Andy Wingo
9a5ee564fa better printing of procedures with keyword arguments
* module/system/vm/program.scm (arguments->lambda-list): Print keyword
  arguments more sensibly.
2009-11-21 19:03:22 +01:00
Andy Wingo
b8187a71cb fix printing-programs bug
* module/system/vm/program.scm (write-program): Fix a bug if we couldn't
  get a procedure's arity.
2009-11-15 20:28:12 +01:00
Andy Wingo
f916cbc4b1 update procedure docs for programs, lambda*, case-lambda
* module/system/vm/program.scm: Export the arity things again, and
  program-arity. Why not.

* doc/ref/api-procedures.texi (Compiled Procedures): Update for current
  API.
  (Optional Arguments): Update to assume lambda* and define* are always
  available, and (ice-9 optargs) is now the ghetto.
  (Case-lambda): Now here, moved from SRFI-16 docs. Also docs
  case-lambda*.

* doc/ref/srfi-modules.texi: Point to core case-lambda docs.
2009-10-27 00:08:20 +01:00
Andy Wingo
df435c8307 arities can have noncontiguous starts and ends
* module/language/glil/compile-assembly.scm (open-arity, close-arity)
  (begin-arity, glil->assembly): Refactor so that arities can have
  noncontiguous starts and ends. So within a prelude there is no arity
  -- only before (the previous arity) or after (the new arity).

* module/system/vm/program.scm (arity:end): Add this private accessor.
  Arities are expected to be in the new format. While not a change in
  objcode format, it is an incompatible change, so I'll bump the objcode
  cookie.
  (program-arity): Check that the ip is within both bounds of the arity.

* libguile/_scm.h (SCM_OBJCODE_MINOR_VERSION): Bump.

* libguile/programs.c (scm_i_program_arity): Update for new arity format.

* module/system/vm/frame.scm (vm-frame-arguments): Avoid throwing an
  error in this function, which is called from the backtrace code.
2009-10-25 13:12:27 +01:00
Andy Wingo
6c6a44390b runtime and debugging support for callee-parsed procedure args
* libguile/objcodes.h: Bump for metadata format change.

* libguile/frames.h: Rework so we don't frob the program's nargs, nlocs,
  etc at runtime. Instead we don't really know what's a local var, an
  argument, or an intermediate value. It's a little unfortunate, but
  this will allow for case-lambda, and eventually for good polymorphic
  generic dispatch; and the nlocs etc can be heuristically
  reconstructed. Such a reconstruction would be better done at the
  Scheme level, though.
  (SCM_FRAME_STACK_ADDRESS): New macro, the pointer to the base of the
  stack elements (not counting the program).
  (SCM_FRAME_UPPER_ADDRESS): Repurpose to be the address of the last
  element in the bookkeeping part of the stack -- i.e. to point to the
  return address.

* libguile/vm-engine.h:
* libguile/vm-i-system.c: Adapt to removal of stack_base. Though we
  still detect stack-smashing underflow, we don't do so as precisely as
  we did before, because now we only detect overwriting of the frame
  metadata.

* libguile/vm-engine.c (vm_engine): Remove the stack_base variable. It
  is unnecessary, and difficult to keep track of in the face of
  case-lambda. Also fix miscommented "ra" and "mvra" pushes. Push the
  vp->ip as the first ra...
* libguile/vm-i-system.c (halt): ...because here we can restore the
  vp->ip instead of setting ip to 0. Allows us to introspect ips all
  down the stack, including in recursive VM invocations.

* libguile/frames.h:
* libguile/frames.c (scm_vm_frame_stack): Removed, because it's getting
  more difficult to tell what's an argument and what's a temporary stack
  element.
  (scm_vm_frame_num_locals): New accessor.
  (scm_vm_frame_instruction_pointer): New accessor.
  (scm_vm_frame_arguments): Defer to an implementation in Scheme.
  (scm_vm_frame_num_locals scm_vm_frame_local_ref)
  (scm_vm_frame_local_set_x): Since we can get not-yet-active frames on
  the stack now, with our current calling convention, we have to add a
  heuristic here to jump over those frames -- because frames have
  pointers in them, not Scheme values.

* libguile/programs.h:
* libguile/programs.c (scm_program_arity): Remove, in favor of..
  (scm_program_arities): ...this, which a list of arities, in a new
  format, occupying a slot in the metadata.

* module/language/assembly/decompile-bytecode.scm (decode-load-program):
  Fix mv-call decompilation.

* module/system/vm/frame.scm (vm-frame-bindings, vm-frame-binding-ref)
  (vm-frame-binding-set!): New functions, to access bindings by name in
  a frame.
  (vm-frame-arguments): Function now implemented in Scheme. Commented
  fairly extensively.

* module/system/vm/program.scm (program-bindings-by-index)
  (program-bindings-for-ip): New accessors, parsing the program bindings
  metadata into something more useful.
  (program-arities, program-arguments): In a case-lambda world, we have
  to assume that programs can have multiple arities. But it's tough to
  detect this algorithmically; instead we're going to require that the
  program metadata include information about the arities, and the parts
  of the program that that metadata applies to.
  (program-lambda-list): New accessor.
  (write-program): Show multiple arities.

* module/language/glil/compile-assembly.scm (glil->assembly): Add
  "arities" to the state of the compiler, and add arities entries as
  appropriate.
2009-10-23 14:51:17 +02:00
Ludovic Courtès
84012ef4b1 Fix typos leading to unbound variable references.
* module/ice-9/session.scm (help): Fix unbound reference to `env'.

* module/system/vm/program.scm (program-property): Fix typo.

* module/system/vm/frame.scm: Add missing `#:use-module (system vm
  objcode)'.

* module/system/repl/command.scm (guile:load): New.
  (load): Use either `primitive-load' or `load'.

* module/srfi/srfi-18.scm (thread-sleep!): Fix typo.

* module/srfi/srfi-19.scm: Use `(ice-9 rdelim)'.
  (date->broken-down-time, priv:year-day, priv:char->int): Fix typo.
  (time-*->time-*, time-*->time-*!): Fix reference to unbound variable
  `caller'.

* module/oop/goops.scm (bound-check-get): Fix typo.

* module/language/glil/compile-assembly.scm (glil->assembly): Fix typo.

* module/language/glil.scm (parse-glil): Fix typo.

* module/language/ecmascript/base.scm (object->value/string,
  object->value/number, ->number): Fix typos.

* module/language/assembly/disassemble.scm (disassemble-free-vars): Fix
  typo.
2009-10-22 22:57:25 +02:00
Andy Wingo
476e357281 remove all mentions of "external" from the compiler and related code
With this, GHIL is effectively bitrotten. I need to port the ECMAScript
compiler to tree-il, then I'll remove it.

* module/language/assembly.scm (byte-length):
* module/language/assembly/compile-bytecode.scm (write-bytecode):
* module/language/assembly/decompile-bytecode.scm (decode-load-program):
* module/language/assembly/disassemble.scm (disassemble-load-program):
  (disassemble-free-vars, code-annotation):
* module/language/glil.scm (<glil-program>, <glil-local>)
  (<glil-exteral>, parse-glil, unparse-glil):
* module/language/glil/compile-assembly.scm (make-meta):
  (compile-assembly, glil->assembly):
* module/language/glil/decompile-assembly.scm (decompile-toplevel):
  (decompile-load-program):
* module/language/objcode/spec.scm (decompile-value):
* module/language/tree-il/compile-glil.scm (flatten-lambda):
* module/system/vm/frame.scm (frame-binding-ref):
  (frame-binding-set!):
* module/system/vm/program.scm (binding:boxed?):
* module/system/vm/trace.scm (trace-next):
* test-suite/tests/asm-to-bytecode.test ("compiler"):
* test-suite/tests/tree-il.test: Remove all mentions of "external", and
  of <glil-local>. Docs updates will come soon.
2009-07-23 17:15:17 +02:00
Andy Wingo
57ab0671d7 rename "closure-ref" to "free-ref"; s/vars/variables/ in some names
* libguile/programs.h:
* libguile/programs.c: (SCM_PROGRAM_FREE_VARIABLES): Rename from
  SCM_PROGRAM_FREE_VARS. Callers changed.
* libguile/programs.c (scm_make_program): Rename arg to
  "free_variables".
  (scm_program_free_variables): Rename from program-free-vars.

* libguile/vm-engine.h:
* libguile/vm-engine.c (VM_CHECK_FREE_VARIABLES): Rename from
  VM_CHECK_CLOSURE.
  (vm_engine, CACHE_PROGRAM): Rename closure and closure_count to free_vars and
  free_vars_vount.

* libguile/vm-i-system.c (FREE_VARIABLE_REF): Rename from CLOSURE_REF.
  (free-ref, free-boxed-ref, free-boxed-set): Rename from closure-ref,
  closure-boxed-ref, closure-boxed-set.
  (make-closure): Renamed from make-closure2.

* module/language/glil/compile-assembly.scm (glil->assembly): Hack to
  never write out the the old "make-closure" instruction. Will fix
  better later. Change to emit free-ref etc instead of closure-ref.

* module/language/tree-il/compile-glil.scm (flatten): Emit make-closure
  instead of make-closure2, now that the old make-closure is gone.

* module/system/vm/program.scm (system): Rename program-free-vars to
  program-free-variables.

* test-suite/tests/tree-il.test ("lambda"): Update for make-closure.
2009-07-23 17:15:17 +02:00
Andy Wingo
20d47c3915 remove "externals" from the vm
* 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.
2009-07-23 17:15:13 +02:00
Ludovic Courtès
e1203ea00f Switch remaining GPLv2+ Guile-VM headers to LGPLv3+.
* 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+.
2009-07-15 22:46:54 +02:00
Andy Wingo
60ae5ca2a3 frame, program, objcode, etc inits use load-extension
* 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.
2009-03-27 18:40:15 -07:00
Andy Wingo
0704c81395 export procedure-arguments from ice-9 session
* 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.
2009-02-25 00:07:10 +01:00
Andy Wingo
028e3d0666 propagate much more source info through compilation
* 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.
2009-02-10 11:53:23 +01:00
Andy Wingo
e311f5fa04 tick in calls, procedure-name works on compiled procedures
* 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-02 23:00:36 +01:00
Andy Wingo
53e28ed9b2 static opcodes; refactor program/objcode division; use new assembly pipeline
* 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-29 21:12:00 +01:00
Andy Wingo
2651e3c412 proper printing of thunks, reduced disasm verbosity
* 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.
2008-11-02 01:37:00 +01:00
Andy Wingo
f580ec0f56 fix use of `binding' data abstraction
* 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.
2008-10-16 13:49:57 +02:00
Andy Wingo
02b1883e56 make disassembly better -- a more woven text.
* 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.
2008-10-12 22:49:24 +02:00
Andy Wingo
0ba8bb7143 tweaks for printing programs
* 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.
2008-09-13 14:19:30 +02:00
Andy Wingo
e6fea61823 programs can now get at their names, and print nicely
* 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'.
2008-09-13 14:19:30 +02:00
Andy Wingo
8e3670748f rework late binding resolution to be simpler and more efficient
* 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.
2008-09-09 07:15:01 +02:00
Andy Wingo
1a1a10d3a5 use #:keywords in module/*.scm, not :keywords
* 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.
2008-09-09 06:58:25 +02:00
Andy Wingo
13906f976e lazily load meta info, for less consage
* 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.
2008-09-08 01:03:34 +02:00
Andy Wingo
83495480e8 merge guile-vm into libguile itself
* 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-21 18:39:30 -07:00
Andy Wingo
d0168f3da8 improve source loc info in nonlocal exits and backtraces
* 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-08 12:55:57 +02:00
Andy Wingo
17d1b4bffd fix stack corruption on vm-save-stack; more robust with nonlocal exits
* 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-07 19:04:25 +02:00
Andy Wingo
07e56b27a1 big reorg of scheme modules -- e.g. programs.c -> (system vm program)
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.
2008-08-07 13:11:27 +02:00