1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-15 08:10:17 +02:00

Subrs are RTL programs

* libguile/gsubr.c: Define RTL stubs instead of stack VM stubs.
  (SUBR_STUB_CODE, get_subr_stub_code): Adapt to return a uint32_t*
  pointer instead of a SCM value.
  (create_subr): Create RTL procedures instead of stack VM procedures.
  For RTL procedures, the function pointer, name, and generic address
  pointer go inline to the procedure, as free variables.
  (scm_i_primitive_arity, scm_i_primitive_call_ip): New helpers.
  (scm_c_make_gsubr, scm_c_define_gsubr, scm_c_make_gsubr_with_generic)
  (scm_c_define_gsubr_with_generic): Adapt to create_gsubr being renamed
  to create_subr.

  Remove gsubr test code.

* libguile/gsubr.h (SCM_PRIMITIVE_P, SCM_PRIMITIVE_GENERIC_P): Only RTL
  programs can be primitives now.
  (SCM_SUBRF, SCM_SUBR_NAME, SCM_SUBR_GENERIC): These fields are now in
  the RTL free variables, not the object table.

* libguile/programs.c (scm_i_rtl_program_name):
  (scm_i_rtl_program_documentation):
  (scm_i_rtl_program_properties):
  (scm_i_rtl_program_minimum_arity): Implement these appropriately for
  primitives, which lack debugging information.
  (scm_primitive_p, scm_primitive_call_ip): New helpers.

* libguile/snarf.h: Remove static allocation for subrs.  Since there is
  nothing to allocate besides the program itself, which needs runtime
  relocation, static allocation is not a win.

* system/vm/program.scm: Fix up various arity-related things for
  primitives, which don't use ELF arity info.

* test-suite/tests/eval.test ("stack involving a primitive"): Add an
  XFAIL until we get just one VM.
This commit is contained in:
Andy Wingo 2013-10-18 10:03:26 +02:00
parent 9dff1df97f
commit 27337b6373
7 changed files with 227 additions and 748 deletions

View file

@ -198,7 +198,8 @@
;; returns list of list of bindings
;; (list-ref ret N) == bindings bound to the Nth local slot
(define (program-bindings-by-index prog)
(cond ((program-bindings prog) => collapse-locals)
(cond ((rtl-program? prog) '())
((program-bindings prog) => collapse-locals)
(else '())))
(define (program-bindings-for-ip prog ip)
@ -291,14 +292,29 @@
;; the name "program-arguments" is taken by features.c...
(define* (program-arguments-alist prog #:optional ip)
"Returns the signature of the given procedure in the form of an association list."
(if (rtl-program? prog)
(cond
((primitive? prog)
(match (procedure-minimum-arity prog)
(#f #f)
((nreq nopt rest?)
(let ((start (primitive-call-ip prog)))
;; Assume that there is only one IP for the call.
(and (or (not ip) (= start ip))
(arity->arguments-alist
prog
(list 0 0 nreq nopt rest? '(#f . ()))))))))
((rtl-program? prog)
(let ((pc (and ip (+ (rtl-program-code prog) ip))))
(or-map (lambda (arity)
(and #t
(and (or (not pc)
(and (<= (arity-low-pc arity) pc)
(< pc (arity-high-pc arity))))
(arity-arguments-alist arity)))
(or (find-program-arities (rtl-program-code prog)) '()))
(let ((arity (program-arity prog ip)))
(and arity
(arity->arguments-alist prog arity)))))
(or (find-program-arities (rtl-program-code prog)) '()))))
(else
(let ((arity (program-arity prog ip)))
(and arity
(arity->arguments-alist prog arity))))))
(define* (program-lambda-list prog #:optional ip)
"Returns the signature of the given procedure in the form of an argument list."
@ -325,6 +341,14 @@
(define (program-arguments-alists prog)
(cond
((primitive? prog)
(match (procedure-minimum-arity prog)
(#f '())
((nreq nopt rest?)
(list
(arity->arguments-alist
prog
(list 0 0 nreq nopt rest? '(#f . ())))))))
((rtl-program? prog)
(map arity-arguments-alist
(or (find-program-arities (rtl-program-code prog)) '())))