forked from alex-eg/sex
file methods, realizations and sums under what a typedef names
A typedef had the fields of its record but none of its methods, and a typedef of a sum was not a sum to match. A typedef that ends in a scalar still keeps its own, so (typedef meters float) does not lend its methods to every float.
This commit is contained in:
@@ -133,6 +133,33 @@
|
||||
(emits? (string-append "(defmacro (the a) a)"
|
||||
(ops-src "(var q float (. (the p) x))"))
|
||||
"p->x"))
|
||||
(test-assert "a typedef of the type has its methods"
|
||||
(emits? (string-append
|
||||
"(record w ((x int)))"
|
||||
"(typedef alias w)"
|
||||
"(ops w (fn get ((self (* const w))) int (return (. self x))))"
|
||||
"(fn f () int (var a alias #(alias : 1)) (return (.get a)))")
|
||||
"wːget(&a)"))
|
||||
(test-assert "and a method written on the typedef is the type's"
|
||||
(emits? (string-append
|
||||
"(record w ((x int)))"
|
||||
"(typedef alias w)"
|
||||
"(ops alias (fn get ((self (* const alias))) int (return 1)))"
|
||||
"(fn f () int (var a w #(w : 1)) (return (.get a)))")
|
||||
"aliasːget(&a)"))
|
||||
(test-assert "a typedef of a scalar keeps its own"
|
||||
(reports? (string-append
|
||||
"(typedef meters float)"
|
||||
"(ops meters (fn half ((self meters)) meters (return self)))"
|
||||
"(fn f () void (var x float 1.0) (.half x))")
|
||||
"no such method on"))
|
||||
(test-assert "which a typedef of it shares"
|
||||
(emits? (string-append
|
||||
"(typedef meters float)"
|
||||
"(typedef km meters)"
|
||||
"(ops meters (fn half ((self meters)) meters (return self)))"
|
||||
"(fn f () void (var x km 1.0) (var y km (.half x)))")
|
||||
"metersːhalf(x)"))
|
||||
(test-assert "an address cannot be taken of a call"
|
||||
(reports? (ops-src "(.length (mk))") "receiver is not an lvalue"))
|
||||
;; the inner call has to be typed to find the outer one's receiver
|
||||
@@ -208,6 +235,9 @@
|
||||
(test-assert "a spec is declared once"
|
||||
(reports? "(spec (p T) (fn s ((a T)) void))(spec (p T) (fn q ((a T)) void))"
|
||||
"spec is already declared"))
|
||||
(test-assert "a typedef realizes what its type does"
|
||||
(reports? (string-append (spec-src "") "(typedef alias v)(realize (p alias))")
|
||||
"spec is already realized for"))
|
||||
(test-assert "a type realizes a spec once"
|
||||
(reports? (string-append (spec-src "") "(realize (p v)"
|
||||
" (fn s ((a (* const v))) void (return)))")
|
||||
@@ -298,6 +328,13 @@
|
||||
(sum-src "(match (the s) ((circle (r)) (= out r))"
|
||||
" (else (= out 0.0)))"))
|
||||
"shape ƛm0 = s"))
|
||||
(test-assert "a typedef of a sum is matched as the sum"
|
||||
(emits? (string-append
|
||||
"(sum shape ((circle ((r int))) (empty ())))"
|
||||
"(typedef alias shape)"
|
||||
"(fn f () int (var s alias (shape/circle 1))"
|
||||
" (match s ((circle (r)) (return r)) ((empty ()) (return 0))))")
|
||||
"case shapeǂcircle"))
|
||||
(test-assert "else becomes default"
|
||||
(emits? (sum-src "(match s ((circle (r)) (= out r)) (else (= out 0.0)))")
|
||||
"default:"))
|
||||
|
||||
Reference in New Issue
Block a user