summaryrefslogtreecommitdiff
path: root/module/system/vm/program.scm
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2013-10-18 10:03:26 +0200
committerAndy Wingo <wingo@pobox.com>2013-10-18 11:39:35 +0200
commit27337b6373954e1a975d97d0bf06b5c03d65b64d (patch)
tree33dba0fa3b9c0c7121e5c106556a6a6116efb37f /module/system/vm/program.scm
parent9dff1df97f7021b1d2edd5dd73d1ca426def943b (diff)
downloadguile-27337b6373954e1a975d97d0bf06b5c03d65b64d.tar.gz
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.
Diffstat (limited to 'module/system/vm/program.scm')
-rw-r--r--module/system/vm/program.scm38
1 files changed, 31 insertions, 7 deletions
diff --git a/module/system/vm/program.scm b/module/system/vm/program.scm
index 86db41180..4466504de 100644
--- a/module/system/vm/program.scm
+++ b/module/system/vm/program.scm
@@ -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)) '())))