1: # 5 "./lpsrc/flx_stub.ipk" 2: open Flx_types 3: ;; 4: let pe x = print_endline x 5: ;; 6: pe "STUB TEST PROGRAM" 7: ;; 8: 9: open Flx_ctypes 10: open Flx_cexpr 11: open Flx_ctype 12: open List 13: 14: let raw_options = Flx_getopt.parse_options Sys.argv;; 15: let compiler_options = Flx_flxopt.get_felix_options raw_options;; 16: let syms = Flx_flxopt.make_syms compiler_options;; 17: 18: let input_file_name = Sys.argv.(1) 19: ;; 20: 21: let () = 22: let pre_tokens = Flx_pretok.pre_tokens_of_filename 23: input_file_name 24: (Filename.dirname input_file_name) 25: [] 26: Flx_macro.expand_expression 27: in 28: Flx_tok.print_pre_tokens pre_tokens; 29: let tokens = Flx_lex1.translate pre_tokens in 30: 31: (* strip EOF *) 32: let lexbuf = (Lexing.from_string "dummy" ) in 33: let toker = (new Flx_tok.tokeniser tokens) in 34: while toker#token_peek lexbuf != Flx_parse .ENDMARKER do 35: let x,tok = 36: try 37: Flx_parse.exprx 38: (toker#token_src) 39: lexbuf 40: with _ -> begin 41: toker#report_syntax_error; 42: raise (Flx_exceptions.ParseError "Parsing Expr") 43: end 44: in 45: print_endline (Flx_print.string_of_expr x) 46: ; 47: toker#put_back tok 48: ; 49: let _ = 50: try 51: Flx_parse.semi 52: (toker#token_src) 53: lexbuf 54: with _ -> begin 55: toker#report_syntax_error; 56: raise (Flx_exceptions.ParseError "Parsing String") 57: end 58: in () 59: done; 60: print_endline "Parsed it" 61: ;; 62: 63: (* 64: let e1 = 65: `Ce_infix ("*", 66: `Ce_infix ("+",`Ce_atom "x",`Ce_atom "y"), 67: `Ce_infix ("*",`Ce_atom "x",`Ce_atom "y") 68: ) 69: ;; 70: let e2 = 71: `Ce_infix ("-", 72: `Ce_infix ("+",`Ce_atom "x",`Ce_atom "y"), 73: `Ce_infix ("-",`Ce_atom "x",`Ce_atom "y") 74: ) 75: ;; 76: let e3 = 77: `Ce_infix ("-", 78: `Ce_infix ("*",`Ce_atom "x",`Ce_atom "y"), 79: `Ce_infix ("/",`Ce_atom "x",`Ce_atom "y") 80: ) 81: ;; 82: 83: let e4 = 84: `Ce_infix ("-", 85: `Ce_infix ("-",`Ce_atom "x",`Ce_atom "y"), 86: `Ce_atom "z" 87: ) 88: ;; 89: let e5 = 90: `Ce_infix ("-", 91: `Ce_atom "x", 92: `Ce_infix ("-",`Ce_atom "y",`Ce_atom "z") 93: ) 94: ;; 95: pe (string_of_cexpr e1) ;; 96: pe (string_of_cexpr e2) ;; 97: pe (string_of_cexpr e3) ;; 98: pe (string_of_cexpr e4) ;; 99: pe (string_of_cexpr e5) ;; 100: 101: let pt t = pe (" " ^ (string_of_ctype t)) 102: let pd n t = pe (" " ^ (string_of_cdecl_type n t)) 103: let pv n t = pe (" "^ (string_of_cdecl_type n (`Cdt_value t))) 104: 105: let int_t = `Ct_base "int" 106: let long_t = `Ct_base "long" 107: let pi_t = `Ct_ptr int_t 108: let ai_t = `Ct_varray int_t 109: let pai_t = `Ct_ptr ai_t 110: let api_t = `Ct_varray pi_t 111: let a6a4i_t = `Ct_array (6,`Ct_array(4,int_t)) 112: ;; 113: 114: pv "pi" pi_t;; 115: pv "ai" ai_t;; 116: pv "pai" pai_t;; 117: pv "api" api_t;; 118: pv "a6a4i" a6a4i_t;; 119: 120: 121: pt int_t;; 122: pt long_t;; 123: pt pi_t;; 124: 125: pe "//int * const * volatile *";; 126: pt (`Ct_vptr (`Ct_cptr pi_t));; 127: 128: pd "cri" (`Cdt_cref int_t);; 129: pv "a" (`Ct_array (9,int_t));; 130: 131: let f = `Ct_fun(int_t,[long_t]);; 132: pe "//int f(long)";; 133: pv "f" f;; 134: 135: pe "//int (*pf)(long)";; 136: pv "pf" (`Ct_ptr f);; 137: 138: pe "//int *g(long)";; 139: let g = `Ct_fun(`Ct_ptr int_t,[long_t]);; 140: pv "g" g;; 141: 142: pe "//f is a function of int returning a pointer to a function of long returning int";; 143: pe "//int (*ff(int))(long)";; 144: let ff = `Ct_fun(`Ct_ptr f,[int_t]);; 145: pv "ff" ff;; 146: 147: 148: (* reduce type check *) 149: 150: let u = `BTYP_tuple [];; 151: let u2= `BTYP_tuple [u;u];; 152: let u4 = `BTYP_tuple [u2;u2];; 153: 154: print_endline ("u4="^Flx_print.string_of_btypecode syms.Flx_mtypes2.dfns u4);; 155: let u4 = Flx_maps.reduce_type u4 in 156: print_endline ("u4="^Flx_print.string_of_btypecode syms.Flx_mtypes2.dfns u4);; 157: 158: 159: *) 160: