Codebase list cafeobj / d58fb4f
After reducing a term, system re-arranges it structure if it has associative operator on top. In this case, there can be a possibility of further reduction. System has been recognize this, but treatment was wrong. This fixes this problem. tswd 8 years ago
3 changed file(s) with 27 addition(s) and 31 deletion(s). Raw diff Collapse all Expand all
633633 (values (or null t)))
634634 (labels ((apply-rules-internal ()
635635 (let ((top nil))
636 (unless (term-is-lowest-parsed? term) (update-lowest-parse term))
636 ;; (unless (term-is-lowest-parsed? term) (update-lowest-parse term))
637637 (setq top (term-head term))
638638 ;; apply same top rules
639639 (apply-rules-with-same-top term (method-rules-with-same-top top))
855855 (cond ((null strategy)
856856 ;; no strat, or exhausted.
857857 (unless (term-is-lowest-parsed? term)
858 (update-lowest-parse term)
859 (unless (method= (term-method term) top)
860 (when *rewrite-debug*
861 (with-output-msg ()
862 (format t "- resetting reduced flag ...")))
858 (multiple-value-bind (xterm assoc?)
859 (update-lowest-parse term)
860 (when (or assoc?
861 (not (method= (term-method term) top)))
862 (when *rewrite-debug*
863 (with-output-msg ()
864 (format t "- resetting reduced flag ...")))
863865 (reset-reduced-flag term)
864 (return-from reduce-term (normalize-term term))))
866 (return-from reduce-term (normalize-term term)))))
865867 (unless (or *rewrite-semantic-reduce*
866868 *beh-rewrite*)
867869 (mark-term-as-reduced term)))
10121014 (defun normalize-term (term)
10131015 (declare (type term term)
10141016 (values (or null t)))
1015 (unless (term-is-lowest-parsed? term)
1016 (update-lowest-parse term))
1017 ;; (unless (term-is-lowest-parsed? term)
1018 ;; (update-lowest-parse term))
10171019 (when *rewrite-debug*
10181020 (with-output-simple-msg ()
10191021 (format t "[normalize-term]:(NF=~A,LP=~A,OD=~A) "
515515 open-mod)
516516 (setf (%module-decl-kind *module-open-form*) (module-kind mod))
517517 (setq open-mod (eval-ast *module-open-form*))
518 (import-module open-mod :using mod)
518 (import-module open-mod :using (compile-module mod))
519519 (compile-module open-mod)
520520 (change-context *last-before-open* open-mod)
521521 open-mod)))
252252 (defun update-lowest-parse (term)
253253 (declare (type term term)
254254 (values t))
255 (let ((body (term-body term)))
255 (let ((body (term-body term))
256 (assoc-applied nil))
256257 (unless (or (term$is-variable? body) (term$is-psuedo-constant? body)
257258 (term-is-an-error term))
258259 ;;
344345 (when *term-debug*
345346 (format t "~&[ULP] head operator was changed =======")))
346347 ;;
347 #||
348 (if (eq (term-head term) *bool-if*)
349 (progn
350 (set-if-then-else-sort term)
351 ;; (setq sort (term-sort term))
352 )
353 ;; (setq sort (setf (term$sort body) (method-coarity (term$head body))))
354 )
355 ||#
356 ;;
357348 (setq head new-head)
358349 (when (method-is-associative head)
359350 ;; &&&& the following transformation tends to put
375366 ;; s' s s s
376367 ;; so:
377368 (setf (term$subterms body)
378 (list (term$arg-1 son)
379 (update-lowest-parse (make-term-with-sort-check-bin head (list t1 t2))))))
380 ; (make-applform (method-coarity head) head (list t1 t2))
369 (list (term$arg-1 son)
370 (update-lowest-parse (make-term-with-sort-check-bin head (list t1 t2)))))
371 (setq assoc-applied t))
372
381373 ;; would only like to do the following if the
382374 ;; sort really decreases
383375 (when (and (not (or (term$is-variable? (setq son (term-body
387379 (sort= (term-sort (setq t1 (term$arg-1 body)))
388380 (term-sort (setq t2 (term$arg-1 son))))
389381 (sort< (term-sort t1) (term-sort (term$arg-2 son)) sort-order))
390 (when *term-debug*
391 (format t "~&[ULP] ASSOCIATIVITY 2"))
382
392383 ;; we are in the following configuration
393384 ;; fs' -> fs'
394385 ;; s fs' fs s'
398389 (list (update-lowest-parse
399390 ;(make-applform (method-coarity head) head (list t1 t2))
400391 (make-term-with-sort-check-bin head (list t1 t2)))
401 (term$arg-2 son)))))
392 (term$arg-2 son)))
393 (when *term-debug*
394 (format t "~&[ULP] ASSOCIATIVITY 2~%=> ")
395 (term-print-with-sort term))
396 ;; we mark
397 (setf assoc-applied t)))
402398
403399 ;; necesary to have true lowest parse
404400
408404 (alt-op (lowest-method head
409405 (list (term-sort t2) (term-sort t1)))))
410406 (when (not (eq alt-op head))
411 (term-replace term ;(make-applform (method-coarity alt-op) alt-op (list t2 t1))
407 (term-replace term
412408 (make-term-with-sort-check-bin alt-op (list t2 t1))))))
413409 (mark-term-as-lowest-parsed term)
414 term)))))
410 (values term assoc-applied))))))
415411
416412 #||
417413 (defun update-lowest-parse (term)
458454 ;;; (setf (term$sort body) (method-coarity (term$head body)))
459455 (setf (term-sort term) (method-coarity (term-head term)))
460456
461 ;; ;;;;; FOR NOW;;;;;;;;;;;;;
462 ;; (return-from update-lowest-parse term)
463457 ;; extensions for associativity: if s and s' are sorts s.t. s < s' then
464458 (when (method-is-associative head)
465459 ;; &&&& the following transformation tends to put