Go to the documentation of this file.
6 import org.junit.Ignore;
9 import java.util.function.Function;
13 import static org.junit.Assert.*;
39 testerr(
"x=1+y",
"Unknown ref 'y'",4);
42 test_ptr(
"x=@{n:=1;v:=2}; x.n := 3; x",
"@{n:=3; v:=2}");
44 testerr(
"sq={x -> x*x}; sq(\"abc\")",
"*\"abc\" is none of (flt64,int64)",9);
45 test(
"fun:{int str -> int}={x y -> x+2}; fun(2,3)",
TypeInt.
con(4));
46 testerr(
"math_rand(1)?x=2: 3 ;y=x+2;y",
"'x' not defined on false arm of trinary",20);
47 testerr(
"{+}(1,2,3)",
"Passing 3 arguments to {+} which takes 2 arguments",3);
49 testerr(
"dist={p->p.x*p.x+p.y*p.y}; dist(@{x=1})",
"Unknown field '.y' in @{x=1}",19);
50 testerr(
"Point=:@{x;y}; Point((0,1))",
"*(0, 1) is not a *Point:@{x:=; y:=}",21);
52 test(
"x=@{a:=1;noinline_b= {a=a+1;b=0}}; x.noinline_b(); x.a",
TypeInt.
NINT8);
54 test(
"f0 = { f x -> x ? f(f0(f,x-1),1) : 0 }; f0({&},2)",
Type.
XNIL);
55 test(
"fact = { x -> x <= 1 ? x : x*fact(x-1) }; fact(1)",
TypeInt.
con(1));
56 test(
"fact = { x -> x <= 1 ? x : x*fact(x-1) }; fact(3)",
TypeInt.
con(6));
57 test(
"is_even = { n -> n ? is_odd(n-1) : 1}; is_odd = {n -> n ? is_even(n-1) : 0}; is_even(99)",
TypeInt.
BOOL );
58 test(
"fib = { x -> x <= 1 ? 1 : fib(x-1)+fib(x-2) }; fib(1)",
TypeInt.
con(1));
59 test(
"fib = { x -> x <= 1 ? 1 : fib(x-1)+fib(x-2) }; fib(4)",
TypeInt.
con(5));
60 test(
"A= :@{n=A?; v=flt}; f={x:A? -> x ? A(f(x.n),x.v*x.v) : 0}; f(A(0,1.2)).v;",
TypeFlt.
con(1.2*1.2));
61 testerr(
"fact = { x -> x <= 1 ? x : x*fact(x-1) }; fact(0);(1,);(1,).0;@{x;y];",
"Expected closing '}' but found ']' instead",63);
112 testerr(
"+",
"Syntax error; trailing junk",0);
113 testerr(
"!",
"Syntax error; trailing junk",0);
121 testerr(
"{!}() ",
"Passing 0 arguments to {!} which takes 1 arguments",3);
122 testerr(
"math_pi(1)",
"A function is being called, but 3.141592653589793 is not a function",10);
123 testerr(
"{+}(1,2,3)",
"Passing 3 arguments to {+} which takes 2 arguments",3);
140 testerr(
"-1== --",
"Missing term after '=='",5);
147 testerr(
"x=y=",
"Missing ifex after assignment of 'y'",4);
148 testerr(
"x=z" ,
"Unknown ref 'z'",2);
149 testerr(
"x=1+y",
"Unknown ref 'y'",4);
150 testerr(
"x=y; x=y",
"Unknown ref 'y'",2);
154 testerr(
"x=(1+(x=2)+x); x",
"Cannot re-assign final val 'x'",0);
167 testerr(
"math_rand(1)?x=2: 3 ;x",
"'x' not defined on false arm of trinary",20);
168 testerr(
"math_rand(1)?x=2: 3 ;y=x+2;y",
"'x' not defined on false arm of trinary",20);
169 testerr(
"0 ? x=2 : 3;x",
"'x' not defined on false arm of trinary",11);
172 testerr(
"x=1;2?(x=2):(x=3);x",
"Cannot re-assign final val 'x'",7);
175 testerr(
"math_rand(1)?1: :2:int",
"missing expr after ':'",16);
176 testerr(
"math_rand(1)?1::2:int",
"missing expr after ':'",15);
177 testerr(
"math_rand(1)?1:\"a\"",
"Cannot mix GC and non-GC types",18);
181 testerr(
"a.b.c();",
"Unknown ref 'a'",0);
194 test_obj(
"x:=y:=0; z=x++ && y++;(x,y,z)",
196 test_obj(
"x:=y:=0; x++ && y++; z=x++ && y++; (x,y,z)",
200 testerr(
"1 && (x=2;0) || x+3 && x+4",
"'x' not defined prior to the short-circuit",5);
201 testerr(
"0 && (x=2;0) || x+3 && x+4",
"'x' not defined prior to the short-circuit",5);
219 testerr(
"plus2={x -> x+2}; x",
"Unknown ref 'x'",18);
220 testerr(
"fun={x -> }; fun(0)",
"Missing function body",10);
221 testerr(
"fun(2)",
"Unknown ref 'fun'", 0);
226 test(
"x=3; mul2={x -> x*2}; mul2(2.1)+mul2(x)",
TypeFlt.
con(2.1*2.0+3*2));
228 testerr(
"sq={x -> x&x}; sq(\"abc\")",
"*\"abc\" is not a int64",9);
229 testerr(
"sq={x -> x*x}; sq(\"abc\")",
"*\"abc\" is none of (flt64,int64)",9);
230 testerr(
"f0 = { f x -> f0(x-1) }; f0({+},2)",
"Passing 1 arguments to f0 which takes 2 arguments",16);
232 test(
"fact = { x -> x <= 1 ? x : x*fact(x-1) }; fact(3)",
TypeInt.
con(6));
233 test(
"fib = { x -> x <= 1 ? 1 : fib(x-1)+fib(x-2) }; fib(4)",
TypeInt.
con(5));
234 test(
"f0 = { x -> x ? {+}(f0(x-1),1) : 0 }; f0(2)",
TypeInt.
con(2));
235 testerr(
"fact = { x -> x <= 1 ? x : x*fact(x-1) }; fact()",
"Passing 0 arguments to fact which takes 1 arguments",46);
236 test_obj(
"fact = { x -> x <= 1 ? x : x*fact(x-1) }; (fact(0),fact(1),fact(2))",
240 test(
"is_even = { n -> n ? is_odd(n-1) : 1}; is_odd = {n -> n ? is_even(n-1) : 0}; is_even(4)",
TypeInt.
con(1) );
241 test(
"is_even = { n -> n ? is_odd(n-1) : 1}; is_odd = {n -> n ? is_even(n-1) : 0}; is_even(99)",
TypeInt.
BOOL );
244 testerr(
"(math_rand(1) ? {+} : {*})(2,3)",
"Unable to resolve call",26);
253 testerr(
"x:flt32 = 123456789",
"123456789 is not a flt32",1);
254 testerr(
"1:",
"Syntax error; trailing junk",1);
255 testerr(
"2:x",
"Syntax error; trailing junk", 1);
256 testerr(
"(2:)",
"Syntax error; trailing junk", 2);
259 testerr(
"(-1):int1",
"-1 is not a int1",4);
260 testerr(
"\"abc\":int",
"*\"abc\" is not a int64",5);
261 testerr(
"1:str",
"1 is not a *str",1);
264 testerr(
"{x:str -> x}(1)",
"1 is not a *str", 13);
267 test (
"fun:{int str -> int}={x y -> x+2}; fun(2,3)",
TypeInt.
con(4));
268 testerr(
"fun:{int str -> int}={x y -> x+y}; fun(2,3)",
"3 is not a *str",41);
270 test_obj(
"fun={x y -> x*2}; bar:{int str -> int} = fun; baz:{int @{x;y} -> int} = fun; (fun(2,3),bar(2,\"abc\"))",
272 testerr(
"fun={x y -> x+y}; baz:{int @{x;y} -> int} = fun; (fun(2,3), baz(2,3))",
273 "3 is not a *@{x:=; y:=; ...}", 66);
274 testerr(
"fun={x y -> x+y}; baz={x:int y:@{x;y} -> foo(x,y)}; (fun(2,3), baz(2,3))",
275 "Unknown ref 'foo'", 41);
280 testerr(
"fun={x y -> x+y}; baz={x:int y:@{x;y} -> fun(x,y)}; (fun(2,3), baz(2,3))",
281 "3 is not a *@{x:=; y:=; ...}", 69);
283 testerr(
"x=3; fun:{int->int}={x -> x*2}; fun(2.1)+fun(x)",
"2.1 is not a int64",36);
284 test(
"x=3; fun:{real->real}={x -> x*2}; fun(2.1)+fun(x)",
TypeFlt.
con(2.1*2+3*2));
286 test(
"fun:{real->flt32}={x -> x}; fun(0.125)",
TypeFlt.
con(0.125));
287 testerr(
"fun:{real->flt32}={x -> x}; fun(123456789)",
"123456789 is not a flt32",3);
297 test_ptr(
"A= :(str?, int); A( \"abc\",2 )",
"A:(*\"abc\", 2)");
298 test_ptr(
"A= :(str?, int); A( (\"abc\",2) )",
"A:(*\"abc\", 2)");
299 testerr(
"A= :(str?, int)?",
"Named types are never nil",16);
304 testerr(
"a=@{x=1.2;y}; x",
"Unknown ref 'x'",14);
305 testerr(
"a=@{x=1;x=2}.x",
"Cannot re-assign final field '.x' in @{x=1}",8);
307 test_ptr(
"x=@{n:=1;v:=2}; x.n := 3; x",
"@{n:=3; v:=2}");
308 testerr(
"(a=@{x=0;y=0}; a.)",
"Missing field name after '.'",17);
309 testerr(
"a=@{x=0;y=0}; a.x=1; a",
"Cannot re-assign final field '.x' in @{x=0; y=0}",16);
310 test (
"a=@{x=0;y=1}; b=@{x=2} ; c=math_rand(1)?a:b; c.x",
TypeInt.
INT8);
311 testerr(
"a=@{x=0;y=1}; b=@{x=2}; c=math_rand(1)?a:b; c.y",
"Unknown field '.y' in @{x=int8}",46);
312 testerr(
"dist={p->p.x*p.x+p.y*p.y}; dist(@{x=1})",
"Unknown field '.y' in @{x=1}",19);
313 test (
"dist={p->p.x*p.x+p.y*p.y}; dist(@{x=1;y=2})",
TypeInt.
con(5));
314 test (
"dist={p->p.x*p.x+p.y*p.y}; dist(@{x=1;y=2;z=3})",
TypeInt.
con(5));
315 test (
"dist={p:@{x;y} -> p.x*p.x+p.y*p.y}; dist(@{x:=1;y:=2})",
TypeInt.
con(5));
318 testerr(
"a=@{x=(b=1.2)*b;y=b}; b",
"Unknown ref 'b'",22);
319 test (
"t=@{n=0;val=1.2}; u=math_rand(1) ? t : @{n=t;val=2.3}; u.val",
TypeFlt.
NFLT64);
321 test (
"dist={p->p//qqq\n.//qqq\nx*p.x+p.y*p.y}; dist(//qqq\n@{x//qqq\n=1;y=2})",
TypeInt.
con(5));
322 testerr(
"@{x;y]",
"Expected closing '}' but found ']' instead",1);
328 test(
"x=@{a:=1;b=@{a=a+1;c=a}}; x.a*10+x.b.c",
TypeInt.
con(1*10+2));
347 testerr (
"gal=:flt; tank:gal = gal(2)+1",
"3 is not a gal:flt64",14);
349 test (
"Point=:@{x;y}; dist={p:Point -> p.x*p.x+p.y*p.y}; dist(Point(1,2))",
TypeInt.
con(5));
350 test (
"Point=:@{x;y}; dist={p -> p.x*p.x+p.y*p.y}; dist(Point(1,2))",
TypeInt.
con(5));
351 testerr (
"Point=:@{x;y}; dist={p:Point -> p.x*p.x+p.y*p.y}; dist((@{x=1;y=2}))",
"*@{x=1; y=2} is not a *Point:@{x:=; y:=}",55);
352 testerr (
"Point=:@{x;y}; Point((0,1))",
"*(0, 1) is not a *Point:@{x:=; y:=}",21);
353 testerr(
"x=@{n: =1;}",
"Missing type after ':'",7);
354 testerr(
"x=@{n=;}",
"Missing ifex after assignment of 'n'",6);
362 testerr(
"x:str = 0",
"0 is not a *str", 1);
364 testerr(
"(math_rand(1)?0 : @{x=1}).x",
"Struct might be nil when reading field '.x'", 26);
370 test (
"a = math_rand(1) ? 0 : @{x=1}; // a is nil or a struct\n"+
371 "b = math_rand(1) ? 0 : @{c=a}; // b is nil or a struct\n"+
372 "b ? (b.c ? b.c.x : 0) : 0 // Nil-safe field load",
TypeInt.
BOOL);
378 test_ptr(
"A= :(str?, int); A(0,2)",
"A:(0, 2)");
381 test_ptr(
"A= :(A?, int); A(0,2)",
"A:(0, 2)");
382 test (
"A= :@{n=A?; v=flt}; A(@{n=0;v=1.2}).v;",
TypeFlt.
con(1.2));
383 test_ptr(
"A= :(A?, int); A(A(0,2),3)",
"A:(*A:(0, 2), 3)");
387 if( te3.
_errs !=
null ) System.err.println(te3.
_errs.toString());
388 assertNull(te3.
_errs);
390 assertEquals(
"A:", tt3._name);
394 assertEquals(
"n",tt3.
fld(1).
_fld);
395 assertEquals(
"v",tt3.
fld(2).
_fld);
411 "B= :@{n=A?; v=flt}; "+
413 "C= :@{n=B?; v=str};"+
421 test(
"f0 = { f x -> x ? f(f0(f,x-1),1) : 0 }; f0({&},2)",
Type.
XNIL);
422 test(
"f0 = { f x -> x ? f(f0(f,x-1),1) : 0 }; f0({+},2)",
TypeInt.
con(2));
424 test (
"A= :@{n=A?; v=flt}; f={x:A? -> x ? A(f(x.n),x.v*x.v) : 0}; f(A(0,1.2)).v;",
TypeFlt.
con(1.2*1.2));
425 test(
"tmp=((0,1.2),2.3); sq={x->x*x}; map={f t -> t ? (map(f,t.0),f t.1) : 0}; map(sq,tmp).1",
TypeFlt.
con(2.3*2.3));
427 test(
"noinline_x={@{a}}; x0=noinline_x(); x1=noinline_x(); x0.a:=2; x1.a",
TypeInt.
INT8);
432 test_obj_isa(
"map={x -> x ? @{nn=map(x.n);vv=x.v&x.v} : 0};"+
433 "map(@{n=math_rand(1)?0:@{n=math_rand(1)?0:@{n=math_rand(1)?0:@{n=0;v=1};v=2};v=3};v=4})",
436 test(
"sum={x -> x ? sum(x.n) + x.v : 0};"+
437 "sum(@{n=math_rand(1)?0:@{n=math_rand(1)?0:@{n=math_rand(1)?0:@{n=0;v=1};v=2};v=3};v=4})",
441 String ll_def =
"List=:@{next;val};";
442 String ll_con =
"tmp=List(List(0,1.2),2.3);";
443 String ll_map =
"map = {fun list -> list ? List(map(fun,list.next),fun(list.val)) : 0};";
444 String ll_fun =
"sq = {x -> x*x};";
445 String ll_apl =
"map(sq,tmp);";
454 if( te4.
_errs !=
null ) System.err.println(te4.
_errs.toString());
455 assertNull(te4.
_errs);
457 assertEquals(
"List:", tt4._name);
459 assertEquals(2.3*2.3,tt4.
at(2).
getd(),1e-6);
460 assertEquals(
"next",tt4.
fld(1).
_fld);
461 assertEquals(
"val" ,tt4.
fld(2).
_fld);
464 test_struct(
"map={x:@{n=;v=flt}? -> x ? @{nn=map(x.n);vv=x.v*x.v} : 0}; map(@{n=0;v=1.2})",
471 test_struct(
"map={x -> x ? @{nn=map(x.n);vv=x.v*x.v} : 0}; map(@{n=0;v=1.2})",
478 test_obj_isa(
"map={x -> x ? @{nn=map(x.n);vv=x.v*x.v} : 0};"+
479 "map(@{n=math_rand(1)?0:@{n=math_rand(1)?0:@{n=math_rand(1)?0:@{n=0;v=1.2};v=2.3};v=3.4};v=4.5})",
486 test_ptr(
"map={x -> x ? (map(x.0),x.1*x.1) : 0}; map((0,1.2))",
490 "map((math_rand(1)?0: (math_rand(1)?0: (math_rand(1)?0: (0,1.2), 2.3), 3.4), 4.5))",
498 test_ptr(
"tmp=@{val=2;nxt=@{val=1;nxt=0}}; noinline_map={tree -> tree ? @{vv=tree.val&tree.val;nn=noinline_map(tree.nxt)} : 0}; noinline_map(tmp)",
499 "@{vv=int8; nn=*$?}");
504 " l=@{ l=0; r=0; v=3 };"+
505 " r=@{ l=0; r=0; v=7 };"+
509 " l=@{ l=0; r=0; v=15 };"+
510 " r=@{ l=0; r=0; v=22 };"+
516 " ? @{ll=map(tree.l);rr=map(tree.r);vv=tree.v&tree.v}"+
519 "@{ll=*$?; rr=$; vv=int8}");
533 " ? @{ll=map(tree.l);vv=tree.v}"+
536 "Cannot re-assign final field '.l' in @{l=*use; v:=0}",36);
541 " l=@{ l=0; r=0; v=3 };"+
542 " r=@{ l=0; r=0; v=7 };"+
546 " l=@{ l=0; r=0; v=15 };"+
547 " r=@{ l=0; r=0; v=22 };"+
552 "map={tree fun -> tree"+
553 " ? @{l=map(tree.l,fun);r=map(tree.r,fun);v=fun(tree.v)}"+
556 "@{l=*$?; r=$; v=int64}");
559 String ll_cona =
"a=0; ";
560 String ll_conb =
"b=math_rand(1) ? ((a,1),\"abc\") : a; ";
561 String ll_conc =
"c=math_rand(1) ? ((b,2),\"def\") : b; ";
562 String ll_cond =
"d=math_rand(1) ? ((c,3),\"ghi\") : c; ";
563 String ll_cone =
"e=math_rand(1) ? ((d,4),\"jkl\") : d; ";
564 String ll_cont =
"tmp=e; ";
566 String ll_map2 =
"map = {fun list -> list ? (map(fun,list.0),fun(list.1)) : 0};";
567 String ll_fun2 =
"plus = {x -> x+x};";
568 String ll_apl2 =
"map(plus,tmp);";
578 test_isa(ll_cona+ll_conb+ll_conc+ll_cond+ll_cone+ll_cont+ll_map2+ll_fun2+ll_apl2,xtmp);
585 testerr(
"x=y=",
"Missing ifex after assignment of 'y'",4);
586 testerr(
"x=z" ,
"Unknown ref 'z'",2);
587 testerr(
"x=1+y",
"Unknown ref 'y'",4);
592 testerr(
"x=1; x:=2; x",
"Cannot re-assign final val 'x'", 5);
593 testerr(
"x=1; x =2; x",
"Cannot re-assign final val 'x'", 5);
600 testerr(
"x:=0; math_rand(1) ? (x =4):3; x=2; x",
"Cannot re-assign read-only val 'x'",31);
603 test(
"noinline_x={@{a}}; noinline_x().a=2; noinline_x().a",
TypeInt.
INT8);
628 testerr (
"x=@{n =1;v:=2}; x.n = 3; x.n",
"Cannot re-assign final field '.n' in @{n=1; v:=2}",18);
630 test_ptr(
"x=@{n:=1;v:=2}; x.n := 3; x",
"@{n:=3; v:=2}");
631 testerr (
"x=@{n:=1;v:=2}; x.n = 3; x.v = 1; x.n = 4; x.n",
"Cannot re-assign final field '.n' in @{n=3; v=1}",37);
632 test (
"x=@{n:=1;v:=2}; y=@{n=3;v:=4}; tmp = math_rand(1) ? x : y; tmp.n",
TypeInt.
NINT8);
633 testerr (
"x=@{n:=1;v:=2}; y=@{n=3;v:=4}; tmp = math_rand(1) ? x : y; tmp.n = 5; tmp.n",
"Cannot re-assign read-only field '.n' in @{n==nint8; v:=nint8}",63);
634 test (
"x=@{n:=1;v:=2}; foo={q -> q.n=3}; foo(x); x.n",
TypeInt.
con(3));
636 testerr (
"x=(1,2); x.0=3; x",
"Cannot re-assign final field '.0' in (1, 2)",11);
638 testerr (
"ptr2rw = @{f:=1}; ptr2final:@{f=} = ptr2rw; ptr2final",
"*@{f:=1} is not a *@{f=; ...}",27);
640 test_obj_isa(
"ptr2 = @{f =1}; ptr2final:@{f=} = ptr2 ; ptr2final",
642 testerr (
"ptr=@{f=1}; ptr2rw:@{f:=} = ptr; ptr2rw",
"*@{f=1} is not a *@{f:=; ...}", 18);
645 testerr (
"f={ptr2final:@{x;y=} -> ptr2final.y }; f(@{x:=1;y:=2})",
"*@{x:=1; y:=2} is not a *@{x:=; y=; ...}",42);
646 testerr (
"f={ptr2final:@{x;y=} -> ptr2final.y=3; ptr2final}; f(@{x:=1;y =2})",
"Cannot re-assign final field '.y' in @{x:=1; y=2}",34);
647 test (
"f={ptr:@{x==;y:=} -> ptr.y=3; ptr}; f(@{x:=1;y:=2}).y",
TypeInt.
con(3));
648 test (
"f={ptr:@{x=;y:=} -> ptr.y=3; ptr}; f(@{x =1;y:=2}).y",
TypeInt.
con(3));
649 testerr (
"f={ptr:@{x=;y:=} -> ptr.y=3; ptr}; f(@{x:=1;y:=2}).x",
"*@{x:=1; y:=2} is not a *@{x=; y:=; ...}",37);
650 test (
"f={ptr:@{x;y} -> ptr.y }; f(@{x:=1;y:=2}:@{x;y==})",
TypeInt.
con(2));
651 test (
"f={ptr:@{x==;y==} -> ptr }; f(@{x=1;y=2}).y",
TypeInt.
con(2));
657 testerr (
"f={ptr:@{x;y=} -> ptr.y=3}; f(@{x:=1;y:=2});",
"*@{x:=1; y:=2} is not a *@{x:=; y=; ...}",30);
661 test (
"ptr0=@{p:=0;v:=1}; ptr1=@{p=ptr0;v:=2}; ptr0.p=ptr1; ptr0.p.v+ptr1.p.v+(ptr0.p==ptr1)",
TypeInt.
con(4));
673 test(
"find={list pred -> !list ? ^0; pred(list.1) ? ^list.1; find(list.0,pred)}; find(((0,3),2),{e -> e&1})",
TypeInt.
con(3));
678 test(
"for={pred->{body->!pred()?^;tmp=body(); tmp?^tmp;7}}; for {1}{0}",
TypeInt.
con(7));
687 test(
"tmp = {cnt:=0;({cnt++},{cnt})}();incA=tmp.0;getA=tmp.1;incA();incA()+getA()",
TypeInt.
con(1+2));
688 test(
"gen = {cnt:=0;({cnt++},{cnt})};" +
689 "tmp:=gen(); incA=tmp.0;getA=tmp.1;"+
690 "tmp:=gen(); incB=tmp.0;getB=tmp.1;"+
691 "incA();incB();incA(); getA()*10+getB()",
700 private final String
FORELSE=
"for={pred->{body->!pred()?^;(tmp=body())?^tmp; for pred body}};";
704 private final String
DO=
"do={pred->{body->!pred()?^;body(); do pred body}};";
719 test_obj(
"ary = [3]; ary[0]:=0; ary[1]:=1; ary[2]:=2; (ary[0],ary[1],ary[2])",
721 testary(
"0[0]",
"0 is not a *[]Scalar/obj",1);
722 testary(
"[3] [4]",
"Index must be out of bounds",5);
723 testary(
"[3] [-1]",
"Index must be out of bounds",5);
727 test_ptr(
DO+
"ary=[99]; i:=0; do {i++ < #ary} {ary[i]:=i*i};ary",
"[$]int64/obj");
738 test_ptr(
"noinline_map={lst fcn -> lst ? fcn lst.1};"+
740 "in_str=(0,\"abc\");"+
741 "out_str =noinline_map(in_int,str:{int->str});"+
742 "out_bool=noinline_map(in_str,{str -> str==\"abc\"});"+
743 "(out_str,out_bool)",
751 test(
"id={x->x};id({+})(id(1),id(math_pi))",
TypeFlt.
make(0,64,Math.PI+1));
757 test_ptr(
"fun={ g -> f={x -> g}; (f 3,f 1)}; (fun \"abc\",fun 3.14)",
758 "(*(*\"abc\", $), *(3.14, 3.14))");
766 testerr(
"x={x x};x(1)",
"Passing 1 arguments to x which takes 0 arguments",9);
768 test_struct(
"noinline_id = {x->x};(noinline_id(5)&7, #noinline_id([3]))",
771 test_ptr(
"noinline_map={lst fcn -> lst ? fcn lst.1};"+
773 "in_str=(0,\"abc\");"+
774 "out_str =noinline_map(in_int,str:{int->str});"+
775 "out_bool=noinline_map(in_str,{str -> str==\"abc\"});"+
776 "(out_str,out_bool)",
779 test_ptr(
"noinline_map={tup fcn -> (0,fcn tup.1)};"+
781 "lst_str=(0,\"abc\");"+
782 "lst_istr=noinline_map(lst_int,str);"+
783 "lst_bool=noinline_map(lst_str,{str-> str==\"abc\"});"+
784 "(lst_istr,lst_bool)",
785 "(*(0, *\"2\")?, *(0, int1))");
787 test(
"noinline_map={lst fcn -> lst ? (noinline_map(lst.0,fcn),fcn lst.1)};"+
788 "in_int=(((0,2),3),5);"+
789 "in_str= ((0,\"abc\"),\"def\");"+
790 "out_istr=noinline_map(in_int,str);"+
791 "out_bool=noinline_map(in_str,{str:str ->str==\"abc\"});"+
792 "(out_istr,out_bool)",
841 if( te.
_errs !=
null ) System.err.println(te.
_errs.toString());
842 assertNull(te.
_errs);
846 static private void test( String program,
Type expected ) {
848 assertEquals(expected,te._t);
851 static private void test_prim( String program, String prim ) {
855 if( te._errs !=
null ) System.err.println(te._errs.toString());
856 assertNull(te._errs);
857 assertEquals(expected,te._t);
865 assertEquals(expected,actual);
868 static private void test_ptr( String program, Function<Integer,Type> expected ) {
871 int alias = actual.
getbit();
872 Type t_expected = expected.apply(alias);
873 assertEquals(t_expected,actual);
876 static private void test_ptr0( String program, Function<Integer,Type> expected ) {
880 assertTrue(bits.
test(0));
882 Type t_expected = expected.apply(alias);
883 assertEquals(t_expected,tmp);
891 assertEquals(expected,actual);
898 assertEquals(expected,actual);
903 int alias = ((
TypeMemPtr)te._t)._aliases.strip_nil().getbit();
905 assertTrue(actual.
isa(expected));
908 static private void test_ptr( String program, String expected ) {
916 static private void test( String program, Function<Integer,Type> expected ) {
918 Type t_expected = expected.apply(-99);
919 assertEquals(t_expected,te._t);
925 assertTrue(actual.
isa(expected));
928 static private void testerr( String program, String err, String cursor ) {
929 System.out.println(
"fix test, cur_off="+cursor.length());
932 static void testerr( String program, String err,
int cur_off ) {
934 assertTrue(te.
_errs !=
null && te.
_errs.size()>=1);
935 String cursor =
new String(
new char[cur_off]).replace(
'\0',
' ');
949 return err.replaceAll(
"\\[[,0-9]*",
"\\[\\$");
951 static private void testary( String program, String err,
int cur_off ) {
953 assertTrue(te.
_errs !=
null && te.
_errs.size()>=1);
954 String cursor =
new String(
new char[cur_off]).replace(
'\0',
' ');
956 assertEquals(err2,te.
_errs.get(0).toString());
static final Type NO_DISP
static BitsAlias RECORD_BITS0
static final TypeInt INT8
an implementation of language AA
TypeObj ld(TypeMemPtr ptr)
static final TypeMemPtr STRUCT0
static BitsFun make0(int bit)
Type lookup_valtype(String name)
static final TypeMemPtr OOP
static final BitsFun TEST_FUNBITS
static void testerr(String program, String err, String cursor)
static final TypeFld DISP_FLD
static void test(String program, Type expected)
static void test_ptr0(String program, Function< Integer, Type > expected)
static final TypeFunPtr GENERIC_FUNPTR
an implementation of language AA
static String strip_alias_numbers(String err)
static final TypeFld NO_DISP
static TypeInt con(long con)
A memory-based collection of optionally named fields.
static TypeFld make(String fld, Type t, int order)
static boolean test(long[] bits, int i)
static void test_struct(String program, TypeStruct expected)
static final TypeInt INT64
final T set_name(String name)
static void test_ptr(String program, Function< Integer, Type > expected)
static void testerr(String program, String err, int cur_off)
static Type con(double con)
static void test_obj_isa(String program, TypeObj expected)
static Type make(int x, int z, double con)
static void test_prim(String program, String prim)
static TypeAry make(String name, boolean any, TypeInt sz, Type elem, TypeObj stor)
static final TypeInt NINT8
static final TypeObj ISUSED
static TypeStr con(String con)
static TypeFunPtr make(BitsFun fidxs, int nargs, Type disp)
static Env file_scope(Env top_scope)
static void test_isa(String program, Type expected)
static TypeFld[] tups(Type t1, Type t2)
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Tight/tiny StringBuilder wrapper.
static TypeEnv run(String program)
an implementation of language AA
static BitsAlias make0(int bit)
static void testary(String program, String err, int cur_off)
TypeStruct set_fld(int i, Type t, Access ff)
static TypeStruct make(String fld_name, Type t)
TypeMemPtr sharpen(TypeMemPtr dull)
static final TypeMemPtr ISUSED
static TypeEnv go(Env top, String src, String str)
static final TypeMemPtr STRPTR
final ArrayList< Node.ErrMsg > _errs
static final TypeMemPtr OOP0
static void test_obj(String program, TypeObj expected)
static final TypeInt TRUE
static TypeMemPtr make_nil(int alias, TypeObj obj)
static void test(String program, Function< Integer, Type > expected)
static void test_ptr(String program, String expected)
static TypeEnv open(Env top, String src, String str)
static final TypeInt BOOL
static final TypeFlt NFLT64
static void test_name(String program, Type... args)
static final TypeFlt FLT64
static TypeMemPtr make(BitsAlias aliases, TypeObj obj)