Changeset 552

Show
Ignore:
Timestamp:
06/19/08 10:37:38 (5 months ago)
Author:
weyrick
Message:

add optional readline support to php interactive mode

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/pcc/compiler/Makefile

    r468 r552  
    22include $(PCC_ROOT)/bigloo-rules.mk 
    33 
    4 BCOMMONFLAGS    = -L ../libs -I ../libs  
     4BCOMMONFLAGS    = $(READLINE_SRFI) -L ../libs -I ../libs  
    55CCOMMONFLAGS    = -I. -I$(BGL_DEFAULT_LIB_DIR)  
    66 
     
    5353 
    5454pcc_$(SU): $(PHPEVAL_LIBS) $(C_POPULATION)  commandline_$(SU).o 
    55         bigloo $(SAFETY) $(PCC_LINK_OPTIONS) $(BCOMMONFLAGS) -o pcc_$(SU) commandline_$(SU).o -library php-runtime -library profiler -library webconnect -library phpeval  
     55        bigloo $(SAFETY) $(PCC_LINK_OPTIONS) $(BCOMMONFLAGS) -o pcc_$(SU) commandline_$(SU).o -library php-runtime -library profiler -library webconnect -library phpeval $(READLINE_BL_LIB) 
    5656 
    5757pcc: pcc_$(SU) 
     
    116116        cp pdb_$(SU) pdb 
    117117 
    118 # we have to override these to add in READLINE_BL_LIB if it's available, since we can't do it 
    119 # conditionally in the module clause 
    120 pdb_s.o: pdb.scm 
    121         $(BIGLOO) $(BSAFEFLAGS) $(READLINE_BL_LIB) $(READLINE_SRFI) $(BIGLOO_PIC)  -c pdb.scm -o pdb_s.o 
    122 pdb_u.o: pdb.scm 
    123         $(BIGLOO) $(BUNSAFEFLAGS) $(READLINE_BL_LIB) $(READLINE_SRFI) $(BIGLOO_PIC)  -c pdb.scm -o pdb_u.o 
  • trunk/pcc/compiler/commandline.scm

    r518 r552  
    2323   (include "php-runtime.sch") 
    2424   (library profiler) 
     25   (cond-expand 
     26      (HAVE_LIBREADLINE (library pcc-rl))) 
    2527   (import (driver "driver.scm") 
    2628           (declare "declare.scm") 
     
    137139        (if (maybe-add-script-argv "-a") 
    138140            (begin 
     141               (cond-expand (HAVE_LIBREADLINE (history-init))) 
     142               (add-target-option! pcc-prompt-display: pcc-prompt-display) 
     143               (add-target-option! pcc-readline: pcc-readline) 
    139144               (widen!::php-repl-target *current-target*)))) 
    140145        
     
    497502        (exit 1))))) 
    498503 
     504; used in interactive mode 
     505(define (pcc-prompt-display) 
     506   (cond-expand (HAVE_LIBREADLINE #f) 
     507                (else 
     508                 (display "\npcc > ")))) 
     509 
     510(define (pcc-readline) 
     511   (let ((cmd (cond-expand (HAVE_LIBREADLINE 
     512                            (readline "pcc > ")) 
     513                           (else 
     514                            (read-line))))) 
     515      (cond-expand (HAVE_LIBREADLINE 
     516                    (when (string? cmd) 
     517                       (history-add cmd)))) 
     518      cmd)) 
     519; 
    499520 
    500521(define (usage-header) 
     
    503524           "Usage: pcc [options] <input-files> [-- script args]" 
    504525           "see pcc -h for help with command line options")) 
    505  
    506526 
    507527 
  • trunk/pcc/compiler/pdb.scm

    r531 r552  
    2222(module pcc-debugger 
    2323   (library php-runtime) 
     24   (cond-expand 
     25      (HAVE_LIBREADLINE (library pcc-rl))) 
    2426   (include "php-runtime.sch") 
    2527   (library profiler) 
  • trunk/pcc/compiler/target.scm

    r551 r552  
    140140(define-method (build-target target::php-repl-target) 
    141141   (with-access::php-repl-target target (options) 
    142       (fluid-let ((*dynamic-load-path* (append (or (target-option library-paths:) '()) 
     142      (let ((pcc-prompt-display (car (target-option pcc-prompt-display:))) 
     143            (pcc-readline (car (target-option pcc-readline:)))) 
     144       (fluid-let ((*dynamic-load-path* (append (or (target-option library-paths:) '()) 
    143145                                               *dynamic-load-path*))) 
    144                 (setup-library-paths) 
    145                 (load-runtime-libs (or (target-option default-libs:) '())) 
    146                 (load-runtime-libs (or (target-option commandline-libs:) '())) 
    147                 (init-php-argv (if (target-option script-argv:) 
    148                                    (reverse (target-option script-argv:)) 
    149                                    '())) 
    150                 (run-startup-functions) 
    151                 (set! *PHP-FILE* "Interactive shell") 
    152                 (set! *PHP-LINE* 0) 
    153                 (print "Interactive shell") 
    154                 (let loop () 
    155                    (display* "pcc > "
    156                    (let ((input (read-line))) 
    157                       (unless (or (eof-object? input) 
    158                                   (string=? input "quit") 
    159                                   (string=? input "exit")) 
    160                          (try 
    161                           (begin 
    162                              (php-repl-eval input) 
    163                              (print)) 
    164                           (lambda (e p m o) 
    165                              (print m) 
    166                              (e #f))) 
    167                          (loop)))) 
    168                 (print)))) 
     146        (setup-library-paths) 
     147        (load-runtime-libs (or (target-option default-libs:) '())) 
     148        (load-runtime-libs (or (target-option commandline-libs:) '())) 
     149        (init-php-argv (if (target-option script-argv:) 
     150                            (reverse (target-option script-argv:)) 
     151                            '())) 
     152        (run-startup-functions) 
     153        (set! *PHP-FILE* "Interactive shell") 
     154        (set! *PHP-LINE* 0) 
     155        (print "Interactive shell") 
     156        (let loop () 
     157            (pcc-prompt-display
     158            (let ((input (pcc-readline))) 
     159               (unless (or (eof-object? input) 
     160                           (string=? input "quit") 
     161                           (string=? input "exit")) 
     162                  (try 
     163                   (begin 
     164                      (php-repl-eval input) 
     165                      (print)) 
     166                   (lambda (e p m o) 
     167                      (print m) 
     168                      (e #f))) 
     169                  (loop)))) 
     170        (print))))) 
    169171 
    170172(define-method (build-target target::scheme-repl-target)