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
577577 #fn("n020A514F3:02122F62:q:" #(#fn(write)
578578 #fn(for-each) #fn("n1702151422061:" #(princ " " #fn(write)) 6)) 7)
579579 #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#
581581 #fn("n1707172;J50470w0473;J50474w14258586>2260>12787>1{87504:" #(*print-level* *print-length*
582582 *exception-print-level*
583583 *exception-print-length*
@@ -586,10 +586,10 @@ · 2 unmodified lines
586586 list? #fn(io?) caar princ #fn(io-filename) ":" caddr ": " type-error "type error: " length= #fn(for-each)
587587 #fn("n17002162:" #(princ ": ") 7) cddr "expected " ", got " #fn(type-of) bounds-error "index " " out of bounds for "
588588 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: "
590− const-error #fn(keyword?) "keywords are read-only: "
591− "tried to modify a constant: " print io-error "I/O error: " assert-failed "assertion failed: "
592− divide-error memory-error "*** Unhandled exception: " newline) print-exception 16)
589+ parse-error "parsing error: " arg-error "arguments error: " arity-error "arity error: expected "
590+ key-error "key not found: " const-error #fn(keyword?)
591+ "keywords are read-only: " "tried to modify a constant: " print io-error "I/O error: "
592+ assert-failed "assertion failed: " divide-error memory-error "*** Unhandled exception: " newline) print-exception 16)
593593 print-stack-trace #fn("n1IIb5b620852185>1_51420862285>1_5147374252627505252Eb82829868788>37:05162:" #(#0#
594594 #fn("n32005182P2105121151C?022232487e361:25051E76278851512888A187>4|:" #(#fn(fn-name)
595595 #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
2222 sl_v sl_errdiv0, sl_errbounds, sl_err, sl_errkey, sl_errunbound, sl_erroom;
2323 sl_v sl_emptyvec, sl_emptystr, sl_vecstructsym, sl_structsym;
2424
25+static sl_v sl_errarity;
26+
2527 sl_v sl_printwidthsym, sl_printreadablysym, sl_printprettysym, sl_printlengthsym;
2628 sl_v sl_printlevelsym;
2729 sl_v sl_tablesym, sl_arrsym;
@@ -198,7 +200,7 @@ unbound_error(sl_v sym) · 170 unmodified lines
198200 _Noreturn void
199201 arity_error(int nargs, int c)
200202 {
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)));
202204 }
203205
204206 // safe cast operators --------------------------------------------------------
@@ -1399,6 +1401,7 @@ failed: · 1194 unmodified lines
13991401 sl_errparse = mk_csym("parse-error");
14001402 sl_errtype = mk_csym("type-error");
14011403 sl_errarg = mk_csym("arg-error");
1404+ sl_errarity = mk_csym("arity-error");
14021405 sl_errunbound = mk_csym("unbound-error");
14031406 sl_errkey = mk_csym("key-error");
14041407 sl_errmem = mk_csym("memory-error");
src/system.sl+7−1
@@ -2704,6 +2704,12 @@ · 2703 unmodified lines
27042704 (princ "arguments error: ")
27052705 (apply princ a))
27062706
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+
27072713 ((eq? k 'key-error)
27082714 (princ "key not found: " (car a)))
27092715
@@ -2719,7 +2725,7 @@ · 9 unmodified lines
27192725
27202726 ((eq? k 'assert-failed)
27212727 (princ "assertion failed: ")
2722− (apply princ a))
2728+ (apply print a))
27232729
27242730 ((or (eq? k 'divide-error)
27252731 (eq? k 'memory-error))
test/unittest.sl+6−6
@@ -839,9 +839,9 @@ · 838 unmodified lines
839839
840840 (assert (eq? (sym 'blah) 'blah))
841841 (assert (eq? (sym "hi" "there" 'symbol 123) 'hitheresymbol123))
842−(assert-fail (sym) arg-error)
842+(assert-fail (sym) arity-error)
843843
844−(assert-fail (exit "error" 2) arg-error)
844+(assert-fail (exit "error" 2) arity-error)
845845
846846 (assert (not (int-valued? T)))
847847 (assert (not (int-valued? NIL)))
@@ -991,7 +991,7 @@ · 143 unmodified lines
991991 ; path-cwd
992992 (assert (str? (path-cwd)))
993993 (assert (path-cwd "."))
994−(assert-fail (path-cwd "." ".") arg-error)
994+(assert-fail (path-cwd "." ".") arity-error)
995995 (assert-fail (path-cwd "does/not/exist") io-error)
996996
997997 ; path-exists? + delete-file
@@ -1014,9 +1014,9 @@ · 16 unmodified lines
10141014 (assert (os-setenv "thisvarisdefined" NIL))
10151015 (assert (not (os-getenv "thisvarisdefined")))
10161016 (assert-fail (os-getenv))
1017−(assert-fail (os-getenv "abc" "def"))
1018−(assert-fail (os-setenv))
1019−(assert-fail (os-setenv "" "def"))
1017+(assert-fail (os-getenv "abc" "def") arity-error)
1018+(assert-fail (os-setenv) arity-error)
1019+(assert-fail (os-setenv "" "def") arg-error)
10201020 (if (equal? *os-name* "plan9")
10211021 (begin (assert-fail (os-setenv ".." "def"))
10221022 (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