diff --git a/books/bookvol9.pamphlet b/books/bookvol9.pamphlet index b18757e..8bb8134 100644 --- a/books/bookvol9.pamphlet +++ b/books/bookvol9.pamphlet @@ -1921,7 +1921,7 @@ nothing (see boot2Lisp) yet still allow function call (lisp2BootAndComp). (cond ((stringp (second x)) x) ((eqcar (second x) 'quote) (list 'makestring (stringimage (cadadr x)))) - ((list 'makestring (deftran (second x)) )) )) + ((list 'makestring (deftran (second x)))))) ((eq op 'quote) (if (stringp (setq y (second x))) (list 'makestring y) (if (and (identp y) (char= (elt (pname y) 0) #\.)) @@ -1992,6 +1992,129 @@ nothing (see boot2Lisp) yet still allow function call (lisp2BootAndComp). @ +\defun{def-insert-let}{def-insert-let} +\calls{def-insert-let}{def-insert-let} +\calls{def-insert-let}{deftran} +\calls{def-insert-let}{def-let} +\calls{def-insert-let}{errhuh} +<>= +(defun def-insert-let (x) + (labels ( + (insert-let1 (y) + (declare (special $body)) + (if (and (consp y) (eq (qcar y) 'spadlet)) + (cond + ((identp (second y)) + (setq $body (cons 'progn (list (def-let (third y) (second y)) $body))) + (setq y (second y))) + ((identp (third y)) + (setq $body (cons 'progn (list (deftran y) $body))) (setq y (third y))) + ((errhuh))) + y))) + (if (atom x) + x + (cons (insert-let1 (first x)) (def-insert-let (cdr x)))))) + +@ + +\defun{def-let}{def-let} +\calls{def-let}{deftran} +\calls{def-let}{defLET} +<>= +(defun def-let (form rhs) + (let (f1 f2) + (unless (and (consp form) (eq (qcar form) '\:)) + (setq form (macroexpand form))) + (cond + ((and (consp form) (eq (qcar form) '\:)) + (setq f1 (deftran form)) + (setq f2 (deftran (list 'spadlet (second form) rhs))) + (if (and (eq (car f2) 'spadlet) (equal (second f2) (second form))) + (list 'spadlet (second f1) (third f2)) + (list 'progn f1 f2))) + ((and (consp form) (eq (qcar form) 'elt)) + (deftran (list 'setelt (second form) (third form) rhs))) + (t + (|defLET| form (deftran rhs)))))) + +@ + +\defun{defLET}{defLET} +\calls{defLET}{defLET1} +\usesdollar{defLET}{letGenVarCounter} +\usesdollar{defLET}{inDefLET} +<>= +(defun |defLET| (lhs rhs) + (let (|$letGenVarCounter| |$inDefLET|) + (declare (special |$letGenVarCounter| |$inDefLET|)) + (setq |$letGenVarCounter| 1) + (setq |$inDefLET| t) + (|defLET1| lhs rhs))) + +@ + +\defun{defLET1}{defLET1} +\calls{defLET1}{identp} +\calls{defLET1}{defLetForm} +\calls{defLET1}{contained} +\calls{defLET1}{defLet2} +\calls{defLET1}{mkprogn} +\calls{defLET1}{defLET1} +\calls{defLET1}{strconc} +\calls{defLET1}{stringimage} +\usesdollar{defLET1}{let} +\usesdollar{defLET1}{letGenVarCounter} +<>= +(defun |defLET1| (lhs rhs) + (let (name l1 l2 g rhsprime letprime) + (declare (special $let |$letGenVarCounter|)) + (cond + ((identp lhs) (|defLetForm| lhs rhs)) + ((and (pairp lhs) (eq (qcar lhs) 'fluid) + (pairp (qcdr lhs)) (eq (qcdr (qcdr lhs)) nil)) + (|defLetForm| lhs rhs)) + ((and (identp rhs) (null (contained rhs lhs))) + (setq rhsprime (|defLET2| lhs rhs)) + (cond + ((and (consp rhsprime) (eql (qcar rhsprime) $let)) + (mkprogn (list rhsprime rhs))) + ((and (consp rhsprime) (eq (qcar rhsprime) 'progn)) + (append rhsprime (list rhs))) + (t + (when (identp (car rhsprime)) (setq rhsprime (list rhsprime))) + (mkprogn (append rhsprime (list rhs)))))) + ((and (pairp rhs) (eqcar rhs $let) (identp (setq name (cadr rhs)))) + (setq l1 (|defLET1| name (third rhs))) + (setq l2 (|defLET1| lhs name)) + (if (and (consp l2) (eq (qcar l2) 'progn)) + (mkprogn (cons l1 (cdr l2))) + (progn + (when (identp (car l2)) (setq l2 (list l2))) + (mkprogn (cons l1 (append l2 (list name))))))) + (t + (setq g (intern (strconc "LETTMP#" (stringimage |$letGenVarCounter|)))) + (setq |$letGenVarCounter| (1+ |$letGenVarCounter|)) + (setq rhsprime (list $let g rhs)) + (setq letprime (|defLET1| lhs g)) + (if (and (consp letprime) (eq (qcar letprime) 'progn)) + (mkprogn (cons rhsprime (cdr letprime))) + (progn + (when (identp (car letprime)) (setq letprime (list letprime))) + (mkprogn (cons rhsprime (append letprime (list g)))))))))) + + +@ + +\defun{defLetForm}{defLetForm} +\usesdollar{defLetForm}{let} +<>= +(defun |defLetForm| (lhs rhs) + (declare (special $let)) + (list $let lhs rhs)) + +@ + + ;unTuple x == ; x is ['Tuple,:y] => y ; LIST x @@ -5115,6 +5238,11 @@ if \verb|$InteractiveMode| then use a null outputstream <> <> <> +<> +<> +<> +<> +<> <> <> <> diff --git a/changelog b/changelog index e9a6ea5..a957695 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,7 @@ +20101012 tpd src/axiom-website/patches.html 20101012.01.tpd.patch +20101012 tpd src/interp/parsing.lisp treeshake compiler +20101012 tpd src/interp/g-boot.lisp treeshake compiler +20101012 tpd books/bookvol9 treeshake compiler 20101008 tpd src/axiom-website/patches.html 20101008.01.tpd.patch 20101008 tpd src/interp/parsing.lisp treeshake compiler 20101008 tpd books/bookvol9 treeshake compiler diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index 44c54f3..b56e9f7 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -3204,5 +3204,7 @@ books/bookvol9 treeshake compiler
books/bookvol9 treeshake compiler
20101008.01.tpd.patch books/bookvol9 treeshake compiler
+20101012.01.tpd.patch +books/bookvol9 treeshake compiler
diff --git a/src/interp/g-boot.lisp.pamphlet b/src/interp/g-boot.lisp.pamphlet index f76235f..b6d5e49 100644 --- a/src/interp/g-boot.lisp.pamphlet +++ b/src/interp/g-boot.lisp.pamphlet @@ -994,91 +994,6 @@ ;--% LET ; -;defLetForm(lhs,rhs) == -;--if functionp lhs then -;-- sayMSG ['"Danger: Reassigning value to LISP function:",:bright lhs] -; [$LET,lhs,rhs] - -;;; *** |defLetForm| REDEFINED - -(DEFUN |defLetForm| (|lhs| |rhs|) - (DECLARE (SPECIAL $LET)) - (CONS $LET (CONS |lhs| (CONS |rhs| NIL)))) - -;defLET1(lhs,rhs) == -; IDENTP lhs => defLetForm(lhs,rhs) -; lhs is ['FLUID,id] => defLetForm(lhs,rhs) -; IDENTP rhs and not CONTAINED(rhs,lhs) => -; rhs' := defLET2(lhs,rhs) -; EQCAR(rhs',$LET) => MKPROGN [rhs',rhs] -; EQCAR(rhs','PROGN) => APPEND(rhs',[rhs]) -; if IDENTP CAR rhs' then rhs' := CONS(rhs',NIL) -; MKPROGN [:rhs',rhs] -; PAIRP(rhs) and EQCAR(rhs, $LET) and IDENTP(name := CADR rhs) => -; -- handle things like [a] := x := foo -; l1 := defLET1(name,CADDR rhs) -; l2 := defLET1(lhs,name) -; EQCAR(l2,'PROGN) => MKPROGN [l1,:CDR l2] -; if IDENTP CAR l2 then l2 := cons(l2,nil) -; MKPROGN [l1,:l2,name] -; g := INTERN STRCONC('"LETTMP#",STRINGIMAGE $letGenVarCounter) -; $letGenVarCounter := $letGenVarCounter + 1 -; rhs' := [$LET,g,rhs] -; let' := defLET1(lhs,g) -; EQCAR(let','PROGN) => MKPROGN [rhs',:CDR let'] -; if IDENTP CAR let' then let' := CONS(let',NIL) -; MKPROGN [rhs',:let',g] - -;;; *** |defLET1| REDEFINED - -(DEFUN |defLET1| (|lhs| |rhs|) - (PROG (|ISTMP#1| |id| |name| |l1| |l2| |g| |rhs'| |let'|) - (DECLARE (SPECIAL $LET |$letGenVarCounter|)) - (RETURN - (COND - ((IDENTP |lhs|) (|defLetForm| |lhs| |rhs|)) - ((AND (PAIRP |lhs|) (EQ (QCAR |lhs|) 'FLUID) - (PROGN - (SPADLET |ISTMP#1| (QCDR |lhs|)) - (AND (PAIRP |ISTMP#1|) (EQ (QCDR |ISTMP#1|) NIL) - (PROGN (SPADLET |id| (QCAR |ISTMP#1|)) 'T)))) - (|defLetForm| |lhs| |rhs|)) - ((AND (IDENTP |rhs|) (NULL (CONTAINED |rhs| |lhs|))) - (SPADLET |rhs'| (|defLET2| |lhs| |rhs|)) - (COND - ((EQCAR |rhs'| $LET) - (MKPROGN (CONS |rhs'| (CONS |rhs| NIL)))) - ((EQCAR |rhs'| 'PROGN) (APPEND |rhs'| (CONS |rhs| NIL))) - ('T - (COND - ((IDENTP (CAR |rhs'|)) - (SPADLET |rhs'| (CONS |rhs'| NIL)))) - (MKPROGN (APPEND |rhs'| (CONS |rhs| NIL)))))) - ((AND (PAIRP |rhs|) (EQCAR |rhs| $LET) - (IDENTP (SPADLET |name| (CADR |rhs|)))) - (SPADLET |l1| (|defLET1| |name| (CADDR |rhs|))) - (SPADLET |l2| (|defLET1| |lhs| |name|)) - (COND - ((EQCAR |l2| 'PROGN) (MKPROGN (CONS |l1| (CDR |l2|)))) - ('T - (COND - ((IDENTP (CAR |l2|)) (SPADLET |l2| (CONS |l2| NIL)))) - (MKPROGN (CONS |l1| (APPEND |l2| (CONS |name| NIL))))))) - ('T - (SPADLET |g| - (INTERN (STRCONC "LETTMP#" - (STRINGIMAGE |$letGenVarCounter|)))) - (SPADLET |$letGenVarCounter| (PLUS |$letGenVarCounter| 1)) - (SPADLET |rhs'| (CONS $LET (CONS |g| (CONS |rhs| NIL)))) - (SPADLET |let'| (|defLET1| |lhs| |g|)) - (COND - ((EQCAR |let'| 'PROGN) (MKPROGN (CONS |rhs'| (CDR |let'|)))) - ('T - (COND - ((IDENTP (CAR |let'|)) - (SPADLET |let'| (CONS |let'| NIL)))) - (MKPROGN (CONS |rhs'| (APPEND |let'| (CONS |g| NIL))))))))))) - ;defLET2(lhs,rhs) == ; IDENTP lhs => defLetForm(lhs,rhs) ; NULL lhs => NIL @@ -1254,22 +1169,6 @@ ('T (|defIS| |rhs| |lhs|)))) (CONS 'COND (CONS (CONS |isPred| (CONS |rhs| NIL)) NIL))))))) -;defLET(lhs,rhs) == -; $letGenVarCounter : local := 1 -; $inDefLET : local := true -; defLET1(lhs,rhs) - -;;; *** |defLET| REDEFINED - -(DEFUN |defLET| (|lhs| |rhs|) - (PROG (|$letGenVarCounter| |$inDefLET|) - (DECLARE (SPECIAL |$letGenVarCounter| |$inDefLET|)) - (RETURN - (PROGN - (SPADLET |$letGenVarCounter| 1) - (SPADLET |$inDefLET| 'T) - (|defLET1| |lhs| |rhs|))))) - ;addCARorCDR(acc,expr) == ; NULL PAIRP expr => [acc,expr] ; acc = 'CAR and EQCAR(expr,'REVERSE) => diff --git a/src/interp/parsing.lisp.pamphlet b/src/interp/parsing.lisp.pamphlet index 4cbf209..d0c7126 100644 --- a/src/interp/parsing.lisp.pamphlet +++ b/src/interp/parsing.lisp.pamphlet @@ -1333,23 +1333,6 @@ foo defined inside of fum gets renamed as fum,foo.") (ARGLP (DEF-STRINGTOQUOTE ARGL))) (COMP (SUBLIS $OPASSOC `((,$OP (LAM ,ARGLP ,$BODY)))))))) -(defun DEF-INSERT-LET (X) - (if (ATOM X) X - (CONS (DEF-INSERT-LET1 (FIRST X)) (DEF-INSERT-LET (CDR X))))) - -(defun DEF-INSERT-LET1 (Y) - (if (EQCAR Y 'SPADLET) - (COND ((IDENTP (SECOND Y)) - (setq $BODY - (MKPROGN - (LIST (DEF-LET (THIRD Y) (SECOND Y)) $BODY))) - (setq Y (SECOND Y))) - ((IDENTP (THIRD Y)) - (setq $BODY - (MKPROGN (LIST (DEFTRAN Y) $BODY))) (setq Y (THIRD Y))) - ((ERRHUH))) - Y)) - (defun MKPROGN (L) (MKPF L 'PROGN)) (defun DEF-STRINGTOQUOTE (X) @@ -1493,19 +1476,6 @@ foo defined inside of fum gets renamed as fum,foo.") (COND ((NOT L) NIL) ((CONS (MAPCAR #'DEFTRAN (FIRST L)) (DEF-COND (CDR L)))))) -(defun DEF-LET (FORM RHS) - (setq FORM (if (EQCAR FORM '\:) FORM (macroexpand FORM))) - (prog (F1 F2) - (COND ((EQCAR FORM '\:) - (SPADLET F1 (DEFTRAN FORM)) - (SPADLET F2 (DEFTRAN (LIST 'SPADLET (CADR FORM) RHS))) - (COND ((AND (EQ (CAR F2) 'SPADLET) (EQUAL (CADR F2) (CADR FORM))) - (RETURN (LIST 'SPADLET (CADR F1) (CADDR F2)) )) - ('T (RETURN (LIST 'PROGN F1 F2)) )) ) - ((EQCAR FORM 'ELT) (RETURN - (DEFTRAN (LIST 'SETELT (CADR FORM) (CADDR FORM) RHS)) ))) - (RETURN (|defLET| FORM (DEFTRAN RHS))))) - (defun MK_LEFORM (U) (COND ((IDENTP U) (PNAME U)) ((STRINGP U) U)