History

differentiate between args error and arity error; assert must use print not princ

Sigrid Solveig Haflínudóttir committed 1 year ago

Commit 10691411 parent c0140954 files · +22 −13Browse files

Unified · Split

4 files
  1. boot/sl.boot +5 −5
  2. src/sl.c +4 −1
  3. src/system.sl +7 −1
  4. test/unittest.sl +6 −6
boot/sl.boot+5−5
@@ -577,7 +577,7 @@ · 576 unmodified lines
577 #fn("n020A514F3:02122F62:q:" #(#fn(write)577 #fn("n020A514F3:02122F62:q:" #(#fn(write)
578 #fn(for-each) #fn("n1702151422061:" #(princ " " #fn(write)) 6)) 7)578 #fn(for-each) #fn("n1702151422061:" #(princ " " #fn(write)) 6)) 7)
579 #fn("n1A50420061:" #(#fn(raise)) 6)) print 11)579 #fn("n1A50420061:" #(#fn(raise)) 6)) print 11)
580 print-exception #fn("n1I2021?551472051;3N04720<51;3C04237405151;35040<863700=@30087;3G0487B;3?0487<R;360487<88;360487=863O0752686<512786T277886512956@30q4882:C\x840752;5147<89r252360q@A07589<2952489=?942=2>7?8951524752@89<2A2B89T51295548589T51@M1882CCH0752D89T2E5348589<51@01882FC@0752G89<2H53@\x1b0882ICB0752J5147589f2@\x040882KC?07L89<514I:@\xf00882MCB0752N5147589f2@\xd90882OCB0752P5147589f2@\xc20882QC>0752R89<52@\xaf0882SCR0752T89<513702U@402V5147W89<51@\x880882XCB0752Y5147589f2@q0882ZCB0752[5147589f2@Z0882\\Q;J804882]Q3;07589f2@?0752^5147W875147_60:" #(#0#580 print-exception #fn("n1I2021?551472051;3N04720<51;3C04237405151;35040<863700=@30087;3G0487B;3?0487<R;360487<88;360487=863O0752686<512786T277886512956@30q4882:C\x840752;5147<89r252360q@A07589<2952489=?942=2>7?8951524752@89<2A2B89T51295548589T51@\x841882CCH0752D89T2E5348589<51@g1882FC@0752G89<2H53@R1882ICB0752J5147589f2@;1882KC?07L89<514I:@'0882MCB0752N5147589f2@\x100882OCB0752P5147589f2@\xf90882QCb0752R89<2A89T5447?89513F07529514757?8951f2@30q@\xc20882SC>0752T89<52@\xaf0882UCR0752V89<513702W@402X5147Y89<51@\x880882ZCB0752[5147589f2@q0882\\CB0752]5147Y89f2@Z0882^Q;J804882_Q3;07589f2@?0752`5147Y875147a60:" #(#0#
581 #fn("n1707172;J50470w0473;J50474w14258586>2260>12787>1{87504:" #(*print-level* *print-length*581 #fn("n1707172;J50470w0473;J50474w14258586>2260>12787>1{87504:" #(*print-level* *print-length*
582 *exception-print-level*582 *exception-print-level*
583 *exception-print-length*583 *exception-print-length*
@@ -586,10 +586,10 @@ · 2 unmodified lines
586 list? #fn(io?) caar princ #fn(io-filename) ":" caddr ": " type-error "type error: " length= #fn(for-each)586 list? #fn(io?) caar princ #fn(io-filename) ":" caddr ": " type-error "type error: " length= #fn(for-each)
587 #fn("n17002162:" #(princ ": ") 7) cddr "expected " ", got " #fn(type-of) bounds-error "index " " out of bounds for "587 #fn("n17002162:" #(princ ": ") 7) cddr "expected " ", got " #fn(type-of) bounds-error "index " " out of bounds for "
588 unbound-error "eval: variable " " has no value" error "error: " load-error print-exception588 unbound-error "eval: variable " " has no value" error "error: " load-error print-exception
589 parse-error "parsing error: " arg-error "arguments error: " key-error "key not found: "589 parse-error "parsing error: " arg-error "arguments error: " arity-error "arity error: expected "
590 const-error #fn(keyword?) "keywords are read-only: "590 key-error "key not found: " const-error #fn(keyword?)
591 "tried to modify a constant: " print io-error "I/O error: " assert-failed "assertion failed: "591 "keywords are read-only: " "tried to modify a constant: " print io-error "I/O error: "
592 divide-error memory-error "*** Unhandled exception: " newline) print-exception 16)592 assert-failed "assertion failed: " divide-error memory-error "*** Unhandled exception: " newline) print-exception 16)
593 print-stack-trace #fn("n1IIb5b620852185>1_51420862285>1_5147374252627505252Eb82829868788>37:05162:" #(#0#593 print-stack-trace #fn("n1IIb5b620852185>1_51420862285>1_5147374252627505252Eb82829868788>37:05162:" #(#0#
594 #fn("n32005182P2105121151C?022232487e361:25051E76278851512888A187>4|:" #(#fn(fn-name)594 #fn("n32005182P2105121151C?022232487e361:25051E76278851512888A187>4|:" #(#fn(fn-name)
595 #fn(fn-code)595 #fn(fn-code)
src/sl.c+4−1
@@ -22,6 +22,8 @@ sl_v sl_errio, sl_errparse, sl_errtype, sl_errarg, sl_errmem, sl_errconst; · 21 unmodified lines
22sl_v sl_errdiv0, sl_errbounds, sl_err, sl_errkey, sl_errunbound, sl_erroom;22sl_v sl_errdiv0, sl_errbounds, sl_err, sl_errkey, sl_errunbound, sl_erroom;
23sl_v sl_emptyvec, sl_emptystr, sl_vecstructsym, sl_structsym;23sl_v sl_emptyvec, sl_emptystr, sl_vecstructsym, sl_structsym;
24 24
25static sl_v sl_errarity;
26
25sl_v sl_printwidthsym, sl_printreadablysym, sl_printprettysym, sl_printlengthsym;27sl_v sl_printwidthsym, sl_printreadablysym, sl_printprettysym, sl_printlengthsym;
26sl_v sl_printlevelsym;28sl_v sl_printlevelsym;
27sl_v sl_tablesym, sl_arrsym;29sl_v sl_tablesym, sl_arrsym;
@@ -198,7 +200,7 @@ unbound_error(sl_v sym) · 170 unmodified lines
198_Noreturn void200_Noreturn void
199arity_error(int nargs, int c)201arity_error(int nargs, int c)
200{202{
201 lerrorf(sl_errarg, "arity mismatch: wanted %d, got %d", c, nargs);203 sl_raise(mk_listn(3, sl_errarity, size_wrap(c), size_wrap(nargs)));
202}204}
203 205
204// safe cast operators --------------------------------------------------------206// safe cast operators --------------------------------------------------------
@@ -1399,6 +1401,7 @@ failed: · 1194 unmodified lines
1399 sl_errparse = mk_csym("parse-error");1401 sl_errparse = mk_csym("parse-error");
1400 sl_errtype = mk_csym("type-error");1402 sl_errtype = mk_csym("type-error");
1401 sl_errarg = mk_csym("arg-error");1403 sl_errarg = mk_csym("arg-error");
1404 sl_errarity = mk_csym("arity-error");
1402 sl_errunbound = mk_csym("unbound-error");1405 sl_errunbound = mk_csym("unbound-error");
1403 sl_errkey = mk_csym("key-error");1406 sl_errkey = mk_csym("key-error");
1404 sl_errmem = mk_csym("memory-error");1407 sl_errmem = mk_csym("memory-error");
src/system.sl+7−1
@@ -2704,6 +2704,12 @@ · 2703 unmodified lines
2704 (princ "arguments error: ")2704 (princ "arguments error: ")
2705 (apply princ a))2705 (apply princ a))
2706 2706
2707 ((eq? k 'arity-error)
2708 (princ "arity error: expected " (car a) ", got " (cadr a))
2709 (when (cddr a)
2710 (princ ": ")
2711 (apply princ (cddr a))))
2712
2707 ((eq? k 'key-error)2713 ((eq? k 'key-error)
2708 (princ "key not found: " (car a)))2714 (princ "key not found: " (car a)))
2709 2715
@@ -2719,7 +2725,7 @@ · 9 unmodified lines
2719 2725
2720 ((eq? k 'assert-failed)2726 ((eq? k 'assert-failed)
2721 (princ "assertion failed: ")2727 (princ "assertion failed: ")
2722 (apply princ a))2728 (apply print a))
2723 2729
2724 ((or (eq? k 'divide-error)2730 ((or (eq? k 'divide-error)
2725 (eq? k 'memory-error))2731 (eq? k 'memory-error))
test/unittest.sl+6−6
@@ -839,9 +839,9 @@ · 838 unmodified lines
839 839
840(assert (eq? (sym 'blah) 'blah))840(assert (eq? (sym 'blah) 'blah))
841(assert (eq? (sym "hi" "there" 'symbol 123) 'hitheresymbol123))841(assert (eq? (sym "hi" "there" 'symbol 123) 'hitheresymbol123))
842(assert-fail (sym) arg-error)842(assert-fail (sym) arity-error)
843 843
844(assert-fail (exit "error" 2) arg-error)844(assert-fail (exit "error" 2) arity-error)
845 845
846(assert (not (int-valued? T)))846(assert (not (int-valued? T)))
847(assert (not (int-valued? NIL)))847(assert (not (int-valued? NIL)))
@@ -991,7 +991,7 @@ · 143 unmodified lines
991; path-cwd991; path-cwd
992(assert (str? (path-cwd)))992(assert (str? (path-cwd)))
993(assert (path-cwd "."))993(assert (path-cwd "."))
994(assert-fail (path-cwd "." ".") arg-error)994(assert-fail (path-cwd "." ".") arity-error)
995(assert-fail (path-cwd "does/not/exist") io-error)995(assert-fail (path-cwd "does/not/exist") io-error)
996 996
997; path-exists? + delete-file997; path-exists? + delete-file
@@ -1014,9 +1014,9 @@ · 16 unmodified lines
1014(assert (os-setenv "thisvarisdefined" NIL))1014(assert (os-setenv "thisvarisdefined" NIL))
1015(assert (not (os-getenv "thisvarisdefined")))1015(assert (not (os-getenv "thisvarisdefined")))
1016(assert-fail (os-getenv))1016(assert-fail (os-getenv))
1017(assert-fail (os-getenv "abc" "def"))1017(assert-fail (os-getenv "abc" "def") arity-error)
1018(assert-fail (os-setenv))1018(assert-fail (os-setenv) arity-error)
1019(assert-fail (os-setenv "" "def"))1019(assert-fail (os-setenv "" "def") arg-error)
1020(if (equal? *os-name* "plan9")1020(if (equal? *os-name* "plan9")
1021 (begin (assert-fail (os-setenv ".." "def"))1021 (begin (assert-fail (os-setenv ".." "def"))
1022 (assert (not (os-getenv ".."))))1022 (assert (not (os-getenv ".."))))

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t