1.2.2. test/regress/rt-1.01.02

     1: #line 142 "./lpsrc/flx_regress.pak"
     2: //Check closures
     3: #line 142 "./lpsrc/flx_regress.pak"
     4: //Check recursion
Start felix section to test/regress/rt-1.01.02-0.flx[1 /1 ]
     5: #line 144 "./lpsrc/flx_regress.pak"
     6: //Check closures
     7: //Check recursion
     8: header r"""
     9: #include <stdio.h>
    10: typedef char *charp;
    11: """;
    12: 
    13: typedef bool = 2;
    14: type int = "int";
    15: type string = "charp";
    16: 
    17: proc print: string = 'printf("%s",$1);';
    18: proc print: int = 'printf("%d",$1);';
    19: 
    20: fun sub: int * int -> int = "$1 - $2";
    21: fun mul: int * int -> int = "$1 * $2";
    22: fun gt: int * int -> bool = "$1 > $2";
    23: fun eq: int * int -> bool = "$1 == $2";
    24: 
    25: // test some recursion
    26: fun fact(a:int): int =
    27: {
    28:   fun f (a:int, p:int) : int = {
    29:     return
    30:       if a>1 then f(a-1, p*a) else p endif;
    31:   }
    32:   return f(a,1);
    33: }
    34: 
    35: // test function variable
    36: val factc : int -> int = fact of (int);
    37: assert (fact 6 == 6 * 5 * 4 * 3 * 2);
    38: assert (factc 6 == 6 * 5 * 4 * 3 * 2);
    39: 
    40: // test procedure variable
    41: proc printer (a:int) { print a; }
    42: val printv = printer of (int);
    43: printer 10;
    44: print "\n";
    45: printv 10;
    46: 
    47: // test structure constructor function
    48: struct X = {
    49:   x : int;
    50:   y : int;
    51: }
    52: 
    53: proc printX (x:X) {
    54:   print "x=";
    55:   print x.x;
    56:   print ", y=";
    57:   print x.y;
    58:   print "\n";
    59: }
    60: 
    61: val x = X(1,2);
    62: printX x;
    63: 
    64: // test special procedure overloading
    65: proc t1()
    66: {
    67:   proc print: int = 'printf("int=%d",$1);';
    68:   print "Not hidden: ";
    69:   print 1;
    70:   print " print:int hides outer\n";
    71: }
    72: t1();
    73: 
    74: module A
    75: {
    76:   proc print:int='printf("module A print int=%d",$1);';
    77:   print 1;
    78:   print "\n";
    79: }
End felix section to test/regress/rt-1.01.02-0.flx[1]
Start data section to test/regress/rt-1.01.02-0.expect[1 /1 ]
     1: 10
     2: 10x=1, y=2
     3: Not hidden: int=1 print:int hides outer
     4: module A print int=1
End data section to test/regress/rt-1.01.02-0.expect[1]