1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-03 13:20:26 +02:00

*** empty log message ***

This commit is contained in:
Keisuke Nishida 2001-04-19 03:09:27 +00:00
parent 8f5cfc810f
commit f21dfea659
12 changed files with 93 additions and 59 deletions

View file

@ -45,9 +45,21 @@
(if (eq? x y) (if (eq? x y)
(trans-pair e (or (location x) l) (car x) (cdr x)) (trans-pair e (or (location x) l) (car x) (cdr x))
(trans e l y)))) (trans e l y))))
((symbol? x) (make-<ghil-ref> e l (ghil-lookup e x))) ((symbol? x)
(let ((y (expand-symbol x)))
(if (eq? x y)
(make-<ghil-ref> e l (ghil-lookup e x))
(trans e l y))))
(else (make-<ghil-quote> e l x)))) (else (make-<ghil-quote> e l x))))
(define (expand-symbol x)
(let loop ((s (symbol->string x)))
(let ((i (string-rindex s #\.)))
(if i
`(slot ,(loop (substring s 0 i))
(quote ,(string->symbol (substring s (1+ i)))))
(string->symbol s)))))
(define (trans-pair e l head tail) (define (trans-pair e l head tail)
(define (trans:x x) (trans e l x)) (define (trans:x x) (trans e l x))
(define (trans:pair x) (trans-pair e l (car x) (cdr x))) (define (trans:pair x) (trans-pair e l (car x) (cdr x)))

View file

@ -68,20 +68,21 @@
(uniform-array-write (objcode->string objcode) port)))) (uniform-array-write (objcode->string objcode) port))))
(format #t "Wrote ~A\n" comp)))) (format #t "Wrote ~A\n" comp))))
(lambda (key . args) (lambda (key . args)
(format #t "ERROR: In ~A:\n" file) (format #t "ERROR: During compiling ~A:\n" file)
(display "ERROR: ") (display "ERROR: ")
(format #t (cadr args) (caddr args)) (apply format #t (cadr args) (caddr args))
(newline) (newline)
(format #t "ERROR: ~A ~A ~A\n" key (car args) (cadddr args))
(delete-file comp))))) (delete-file comp)))))
(define-public (load-source-file file . opts) (define-public (load-source-file file . opts)
(let ((source (read-file-in file scheme))) (let ((source (read-file-in file scheme)))
(vm-load (the-vm) (apply compile-in source (current-module) scheme opts)))) (apply compile-in source (current-module) scheme opts)))
(define-public (load-file file . opts) (define-public (load-file file . opts)
(let ((comp (compiled-file-name file))) (let ((comp (compiled-file-name file)))
(if (file-exists? comp) (if (file-exists? comp)
(vm-load (the-vm) (load-objcode comp)) (load-objcode comp)
(apply load-source-file file opts)))) (apply load-source-file file opts))))
(define-public (compiled-file-name file) (define-public (compiled-file-name file)

View file

@ -24,7 +24,7 @@
:use-module (ice-9 match) :use-module (ice-9 match)
:use-module (ice-9 receive) :use-module (ice-9 receive)
:use-module (ice-9 and-let-star) :use-module (ice-9 and-let-star)
:export (match and-let* receive)) :export (match syntax-error and-let* receive))
;;; ;;;

View file

@ -26,7 +26,7 @@
:use-module (system vm core) :use-module (system vm core)
:autoload (system il glil) (pprint-glil) :autoload (system il glil) (pprint-glil)
:autoload (system vm disasm) (disassemble-program disassemble-objcode) :autoload (system vm disasm) (disassemble-program disassemble-objcode)
:autoload (system vm trace) (vm-trace) :autoload (system vm trace) (vm-trace vm-trace-on vm-trace-off)
:autoload (system vm profile) (vm-profile) :autoload (system vm profile) (vm-profile)
:use-module (ice-9 format) :use-module (ice-9 format)
:use-module (ice-9 session) :use-module (ice-9 session)
@ -45,7 +45,7 @@
(disassemble x) (disassemble-file xx)) (disassemble x) (disassemble-file xx))
(profile (time t) (profile pr)) (profile (time t) (profile pr))
(debug (backtrace bt) (debugger db) (trace r) (step st)) (debug (backtrace bt) (debugger db) (trace r) (step st))
(system (gc) (statistics st)))) (system (gc) (statistics stat))))
(define (group-name g) (car g)) (define (group-name g) (car g))
(define (group-commands g) (cdr g)) (define (group-commands g) (cdr g))
@ -109,7 +109,7 @@
(if c (if c
(cond ((memq :h opts) (display-command c)) (cond ((memq :h opts) (display-command c))
(else (apply (command-procedure c) (else (apply (command-procedure c)
repl (append! args opts)))) repl (append! args (reverse! opts)))))
(user-error "Unknown meta command: ~A" key)))))))) (user-error "Unknown meta command: ~A" key))))))))
@ -159,7 +159,22 @@ Show description/documentation."
(define (option repl . args) (define (option repl . args)
"option [KEY VALUE] "option [KEY VALUE]
List/show/set options." List/show/set options."
(display "Not implemented yet\n")) (match args
(()
(for-each (lambda (key+val)
(format #t "~A\t~A\n" (car key+val) (cdr key+val)))
repl.options))
((key)
(display (repl-option-ref repl key))
(newline))
((key val)
(repl-option-set! repl key val)
(case key
((trace)
(let ((opts (repl-option-ref repl 'trace-options)))
(if val
(apply vm-trace-on repl.env.vm opts)
(vm-trace-off repl.env.vm))))))))
(define (quit repl) (define (quit repl)
"quit "quit
@ -221,15 +236,12 @@ Import modules / List those imported."
"load FILE "load FILE
Load a file in the current module. Load a file in the current module.
-f Load source file (see `compile') -f Load source file (see `compile')"
-r Trace loading (see `trace')"
(let* ((file (->string file)) (let* ((file (->string file))
(objcode (if (memq :f opts) (objcode (if (memq :f opts)
(apply load-source-file file opts) (apply load-source-file file opts)
(apply load-file file opts)))) (apply load-file file opts))))
(if (memq :r opts) (vm-load repl.env.vm objcode)))
(apply vm-trace repl.env.vm objcode opts)
(vm-load repl.env.vm objcode))))
(define (binding repl . opts) (define (binding repl . opts)
"binding "binding
@ -267,10 +279,11 @@ Generate compiled code.
((memq :c opts) (pprint-glil x)) ((memq :c opts) (pprint-glil x))
(else (disassemble-objcode x))))) (else (disassemble-objcode x)))))
(define guile:compile-file compile-file)
(define (compile-file repl file . opts) (define (compile-file repl file . opts)
"compile-file FILE "compile-file FILE
Compile a file." Compile a file."
(apply repl-compile-file repl (->string file) opts)) (apply guile:compile-file (->string file) opts))
(define (disassemble repl prog) (define (disassemble repl prog)
"disassemble PROGRAM "disassemble PROGRAM

View file

@ -32,7 +32,11 @@
;;; Repl type ;;; Repl type
;;; ;;;
(define-vm-class <repl> () env tm-stats vm-stats gc-stats) (define-vm-class <repl> () env options tm-stats gc-stats vm-stats)
(define repl-default-options
'((trace . #f)
(trace-options . (:s))))
(define-public (make-repl lang) (define-public (make-repl lang)
(let ((cenv (make-cenv :vm (the-vm) (let ((cenv (make-cenv :vm (the-vm)
@ -40,9 +44,10 @@
:module (current-module)))) :module (current-module))))
(make <repl> (make <repl>
:env cenv :env cenv
:options repl-default-options
:tm-stats (times) :tm-stats (times)
:vm-stats (vm-stats cenv.vm) :gc-stats (gc-stats)
:gc-stats (gc-stats)))) :vm-stats (vm-stats cenv.vm))))
(define-public (repl-welcome repl) (define-public (repl-welcome repl)
(format #t "~A interpreter ~A on Guile ~A\n" (format #t "~A interpreter ~A on Guile ~A\n"
@ -73,6 +78,12 @@
(repl.env.language.printer val) (repl.env.language.printer val)
(newline)))) (newline))))
(define-public (repl-option-ref repl key)
(assq-ref repl.options key))
(define-public (repl-option-set! repl key val)
(set! repl.options (assq-set! repl.options key val)))
;;; ;;;
;;; Utilities ;;; Utilities

View file

@ -23,6 +23,7 @@
:use-syntax (system base syntax) :use-syntax (system base syntax)
:use-module (system repl common) :use-module (system repl common)
:use-module (system repl command) :use-module (system repl command)
:use-module (system vm core)
:use-module (ice-9 rdelim) :use-module (ice-9 rdelim)
:export (start-repl)) :export (start-repl))
@ -60,10 +61,10 @@
error-handler)) error-handler))
(define (error-handler key . args) (define (error-handler key . args)
;; (case key (case key
;; ((vm-error) ((vm-error)
;; (write (frame->call (cadddr args))) (write (frame->call (cadddr args)))
;; (newline))) (newline)))
(display "ERROR: ") (display "ERROR: ")
(apply format #t (cadr args) (caddr args)) (apply format #t (cadr args) (caddr args))
(newline)) (newline))

View file

@ -83,7 +83,6 @@
(('load-string s) s) (('load-string s) s)
(('load-symbol s) (string->symbol s)) (('load-symbol s) (string->symbol s))
(('load-keyword s) (make-keyword-from-dash-symbol (string->symbol s))) (('load-keyword s) (make-keyword-from-dash-symbol (string->symbol s)))
(('link s) (cons (string->symbol s) '???))
(else #f))) (else #f)))
(define (code->bytes code) (define (code->bytes code)

View file

@ -57,8 +57,9 @@
((= i nargs) (cons (program-name prog) (reverse! r)))))) ((= i nargs) (cons (program-name prog) (reverse! r))))))
(define (program-name x) (define (program-name x)
(or (object-property x 'name)
(hash-fold (lambda (s v d) (if (eq? x (variable-ref v)) s d)) x (hash-fold (lambda (s v d) (if (eq? x (variable-ref v)) s d)) x
(module-obarray (current-module)))) (module-obarray (current-module)))))
;;; ;;;

View file

@ -134,3 +134,11 @@
(if extra (if extra
(format #t "~4@A ~32A;; ~A\n" addr info extra) (format #t "~4@A ~32A;; ~A\n" addr info extra)
(format #t "~4@A ~A\n" addr info))) (format #t "~4@A ~A\n" addr info)))
(define (simplify x)
(cond ((string? x)
(cond ((string-index x #\newline) =>
(lambda (i) (set! x (substring x 0 i)))))
(cond ((> (string-length x) 16)
(set! x (string-append (substring x 0 13) "..."))))))
x)

View file

@ -328,7 +328,7 @@ vm_mark (SCM obj)
if (SCM_NIMP (*sp)) if (SCM_NIMP (*sp))
scm_gc_mark (*sp); scm_gc_mark (*sp);
fp = SCM_VM_STACK_ADDRESS (sp[-1]); /* dynamic link */ fp = SCM_VM_STACK_ADDRESS (sp[-1]); /* dynamic link */
/* Mark frame variables + program */ /* Mark external link, frame variables, and program */
for (sp -= 2; sp >= lower; sp--) for (sp -= 2; sp >= lower; sp--)
if (SCM_NIMP (*sp)) if (SCM_NIMP (*sp))
scm_gc_mark (*sp); scm_gc_mark (*sp);

View file

@ -135,16 +135,6 @@
objects = SCM_VELTS (bp->objs); \ objects = SCM_VELTS (bp->objs); \
} }
#define CACHE_EXTERNAL() \
{ \
external = fp[bp->nargs + bp->nlocs]; \
}
#define SYNC_EXTERNAL() \
{ \
fp[bp->nargs + bp->nlocs] = external; \
}
#define SYNC_BEFORE_GC() \ #define SYNC_BEFORE_GC() \
{ \ { \
SYNC_REGISTER (); \ SYNC_REGISTER (); \
@ -305,16 +295,16 @@ do { \
CHECK_OVERFLOW (); \ CHECK_OVERFLOW (); \
sp[0] = ra; \ sp[0] = ra; \
sp[-1] = dl; \ sp[-1] = dl; \
sp[-2] = bp->external; \ sp[-2] = external; \
} }
#define FREE_FRAME() \ #define FREE_FRAME() \
{ \ { \
SCM *new_sp = fp - 2; \ SCM *p = fp + bp->nargs + bp->nlocs; \
sp = fp + bp->nargs + bp->nlocs; \ sp = fp - 2; \
ip = SCM_VM_BYTE_ADDRESS (sp[2]); \ ip = SCM_VM_BYTE_ADDRESS (p[2]); \
fp = SCM_VM_STACK_ADDRESS (sp[1]); \ fp = SCM_VM_STACK_ADDRESS (p[1]); \
sp = new_sp; \ external = p[0]; \
} }
/* /*

View file

@ -351,10 +351,9 @@ VM_DEFINE_INSTRUCTION (call, "call", 1, -1, 1)
LOCAL_SET (i, SCM_UNDEFINED); LOCAL_SET (i, SCM_UNDEFINED);
/* Create external variables */ /* Create external variables */
CACHE_EXTERNAL (); external = bp->external;
for (i = 0; i < bp->nexts; i++) for (i = 0; i < bp->nexts; i++)
CONS (external, SCM_UNDEFINED, external); CONS (external, SCM_UNDEFINED, external);
SYNC_EXTERNAL ();
ENTER_HOOK (); ENTER_HOOK ();
APPLY_HOOK (); APPLY_HOOK ();
@ -365,9 +364,10 @@ VM_DEFINE_INSTRUCTION (call, "call", 1, -1, 1)
*/ */
if (!SCM_FALSEP (scm_procedure_p (x))) if (!SCM_FALSEP (scm_procedure_p (x)))
{ {
SCM args;
POP_LIST (nargs); POP_LIST (nargs);
sp[-1] = scm_apply (x, *sp, SCM_EOL); POP (args);
sp--; *sp = scm_apply (x, args, SCM_EOL);
NEXT; NEXT;
} }
/* /*
@ -406,18 +406,16 @@ VM_DEFINE_INSTRUCTION (tail_call, "tail-call", 1, -1, 1)
*/ */
if (SCM_EQ_P (x, program)) if (SCM_EQ_P (x, program))
{ {
INIT_ARGS (); int i;
/* Move arguments */ /* Move arguments */
if (bp->nargs) INIT_ARGS ();
{
int i;
sp -= bp->nargs - 1; sp -= bp->nargs - 1;
for (i = 0; i < bp->nargs; i++) for (i = 0; i < bp->nargs; i++)
LOCAL_SET (i, sp[i]); LOCAL_SET (i, sp[i]);
sp -= 2; sp--;
}
/* Call itself */
ip = bp->base; ip = bp->base;
APPLY_HOOK (); APPLY_HOOK ();
NEXT; NEXT;
@ -447,9 +445,10 @@ VM_DEFINE_INSTRUCTION (tail_call, "tail-call", 1, -1, 1)
*/ */
if (!SCM_FALSEP (scm_procedure_p (x))) if (!SCM_FALSEP (scm_procedure_p (x)))
{ {
SCM args;
POP_LIST (nargs); POP_LIST (nargs);
sp[-1] = scm_apply (x, *sp, SCM_EOL); POP (args);
sp--; *sp = scm_apply (x, args, SCM_EOL);
goto vm_return; goto vm_return;
} }
/* /*
@ -504,7 +503,6 @@ VM_DEFINE_INSTRUCTION (return, "return", 0, 0, 1)
/* Restore the last program */ /* Restore the last program */
program = SCM_VM_FRAME_PROGRAM (fp); program = SCM_VM_FRAME_PROGRAM (fp);
CACHE_PROGRAM (); CACHE_PROGRAM ();
CACHE_EXTERNAL ();
PUSH (ret); PUSH (ret);
NEXT; NEXT;
} }