Skip to content

Commit

Permalink
Added patch for bogus argcount errors reported by compiler (ticket #743
Browse files Browse the repository at this point in the history
…).
  • Loading branch information
WillClinger committed Jul 1, 2017
1 parent efc40ae commit 0812c6e
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 9 deletions.
25 changes: 25 additions & 0 deletions src/Compiler/common.imp.sch
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,31 @@
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;; The common-compiler-macros defined below are responsible for
;;; rewriting many calls to integrable procedures that take a
;;; variable number of arguments into a composition of calls
;;; that take the standard number of arguments. This is done
;;; at a syntactic level, so it fails to rewrite things like
;;; ((if #t + -) 1 2 3 4). A later phase of the compiler turns
;;; that into (+ 1 2 3 4), which looks like a call to a primop
;;; with the wrong number of arguments. To tell pass4 it should
;;; generate a closed call instead of flagging that as an error,
;;; the following table names all of the primops for which pass4
;;; should generate a closed call if the number of arguments
;;; looks wrong.
;;;
;;; FIXME: This is a tedious and error-prone way to fix the
;;; problem reported by ticket #743.
;;;
;;; NOTE: fx+, fx-, and fx* are specified to accept exactly
;;; two arguments.

(define variable-arity-primops-that-allow-closed-calls
'(make-vector make-bytevector make-string make-ustring
= < > <= >=
+ * - /
char=? char<? char>? char<=? char>=?))

; The list of compiler macros has been rewritten to avoid the
; use of quasiquote on large structures. Larceny's quasiquote
; apparently takes quadratic time, so this rewrite improved
Expand Down
20 changes: 12 additions & 8 deletions src/Compiler/pass4p2.sch
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,18 @@
(gen! output $return)
'result)
(cg-move output frame regs 'result target)))
(if (negative? (entry.arity entry))
(cg-special output exp target regs frame env tail?)
(begin
(twobit-error "Wrong number of arguments to integrable procedure"
(make-readable exp))
(cg-special output
(make-call-to-TRAP p2error:wna)
target regs frame env tail?))))))
(cond ((negative? (entry.arity entry))
(cg-special output exp target regs frame env tail?))
((memq (variable.name (call.proc exp))
variable-arity-primops-that-allow-closed-calls)
(cg-unknown-call output exp target regs frame env tail? #f))
(else
(twobit-error
"Wrong number of arguments to integrable procedure"
(make-readable exp))
(cg-special output
(make-call-to-TRAP p2error:wna)
target regs frame env tail?))))))

(define (cg-integrable-call2 output entry args regs frame env)
(let ((op (entry.op entry)))
Expand Down
24 changes: 23 additions & 1 deletion test/Lib/regression.sch
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,29 @@
(test "Ticket #800" ; Bug in v0.99 (ARM only)
(fl<? +nan.0 1.0)
#f)
))

(test "Ticket #743" ; Bug in v0.99 and previous
(list
(vector-length ((if #t make-vector) 4))
(bytevector-length ((if #t make-bytevector) 4))
(string-length ((if #t make-string) 4))
(ustring-length ((if #t make-ustring) 4)) ; FIXME
((if #t =) 1 2 3 4)
((if #t <) 1 2 3 4)
((if #t >) 1 2 3 4)
((if #t <=) 1 2 3 4)
((if #t >=) 1 2 3 4)
((if #t +) 1 2 3 4)
((if #t -) 1 2 3 4)
((if #t *) 1 2 3 4)
((if #t /) 1 2 3 4)
((if #t char=?) #\a #\b #\c #\d)
((if #t char<?) #\a #\b #\c #\d)
((if #t char>?) #\a #\b #\c #\d)
((if #t char<=?) #\a #\b #\c #\d)
((if #t char>=?) #\a #\b #\c #\d))
'(4 4 4 4 #f #t #f #t #f 10 -8 24 1/24 #f #t #f #t #f))
))


(define (bug-105-test1)
Expand Down

0 comments on commit 0812c6e

Please sign in to comment.