00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <assert.h>
00039 #include <stdint.h>
00040 #include <stdlib.h>
00041 #include <dirent.h>
00042 #include <fstream>
00043 #include <iostream>
00044 #include <string>
00045 #include <sstream>
00046 #include <errno.h>
00047 #include <sstream>
00048
00049 #include "UocInfo.hxx"
00050 #include "AST.hxx"
00051 #include "Type.hxx"
00052 #include "TypeInfer.hxx"
00053 #include "inter-pass.hxx"
00054
00055 using namespace boost;
00056 using namespace sherpa;
00057 using namespace std;
00058
00059
00060 void
00061 markTail(shared_ptr<AST> ast, shared_ptr<AST> fn, shared_ptr<AST> bps, bool isTail)
00062 {
00063
00064
00065 switch(ast->astType) {
00066
00067 case at_Null:
00068 break;
00069
00070 case at_AnyGroup:
00071 case agt_literal:
00072 case agt_tvar:
00073 case agt_var:
00074 case agt_definition:
00075 case agt_type:
00076 case agt_expr:
00077 case agt_expr_or_define:
00078 case agt_eform:
00079 case agt_type_definition:
00080 case agt_value_definition:
00081 case agt_openclosed:
00082 case agt_uselhs:
00083 case at_letbindings:
00084 case at_letbinding:
00085 case at_loopbindings:
00086 case at_loopbinding:
00087 case agt_CompilationUnit:
00088 case at_ifident:
00089 case at_localFrame:
00090 case at_frameBindings:
00091 case agt_tc_definition:
00092 case agt_if_definition:
00093 case agt_category:
00094 case agt_ow:
00095 case agt_qtype:
00096 case agt_fielditem:
00097 case at_boxedCat:
00098 case at_unboxedCat:
00099 case at_oc_closed:
00100 case at_oc_open:
00101 case at_opaqueCat:
00102 case at_tcdecls:
00103 case at_tyfn:
00104 case at_tcapp:
00105 case at_method_decls:
00106 case at_method_decl:
00107 case at_usesel:
00108 case at_letGather:
00109 case agt_ucon:
00110 {
00111 assert(false);
00112 break;
00113 }
00114
00115 case at_unit:
00116 case at_boolLiteral:
00117 case at_charLiteral:
00118 case at_intLiteral:
00119 case at_floatLiteral:
00120 case at_stringLiteral:
00121 case at_bitfieldType:
00122 case at_deftypeclass:
00123 case at_definstance:
00124 case at_tcmethods:
00125 case at_tcmethod_binding:
00126 case at_declunion:
00127 case at_declstruct:
00128 case at_declrepr:
00129 case at_importAs:
00130 case at_provide:
00131 case at_import:
00132 case at_ifsel:
00133 case at_declares:
00134 case at_declare:
00135 case at_tvlist:
00136 case at_typeapp:
00137 case at_arrayType:
00138 case at_vectorType:
00139 case at_boxedType:
00140 case at_arrayRefType:
00141 case at_byRefType:
00142 case at_exceptionType:
00143 case at_dummyType:
00144 case at_unboxedType:
00145 case at_primaryType:
00146 case at_fieldType:
00147 case at_fnargVec:
00148 case at_mutableType:
00149 case at_methType:
00150 case at_constType:
00151 case at_defunion:
00152 case at_defstruct:
00153 case at_defrepr:
00154 case at_constructors:
00155 case at_fields:
00156 case at_constructor:
00157 case at_field:
00158 case at_methdecl:
00159 case at_fill:
00160 case at_defexception:
00161 case at_proclaim:
00162 case at_fn:
00163 case at_identPattern:
00164 case at_lambda:
00165 case at_argVec:
00166 case at_qualType:
00167 case at_constraints:
00168 case at_identList:
00169
00170
00171
00172
00173
00174 case at_reprctrs:
00175 case at_reprctr:
00176 case at_reprrepr:
00177 case at_docString:
00178 case at_sizeof:
00179 case at_bitsizeof:
00180 {
00181 break;
00182 }
00183
00184 case at_ident:
00185 {
00186 if (ast->symbolDef == fn && isTail) {
00187
00188 ast->flags |= (SELF_TAIL);
00189 }
00190
00191 break;
00192 }
00193
00194 case at_container:
00195 {
00196 markTail(ast->child(1), fn, bps, isTail);
00197 break;
00198 }
00199
00200 case at_interface:
00201 case at_module:
00202 {
00203 size_t c = (ast->astType == at_module)?0:1;
00204 for (; c < ast->children.size(); c++)
00205 markTail(ast->child(c), fn, bps, isTail);
00206
00207 break;
00208 }
00209
00210 case at_define:
00211 case at_recdef:
00212 {
00213 if (ast->child(1)->astType == at_lambda) {
00214 ast->child(0)->child(0)->defbps = ast->child(1)->child(0);
00215 markTail(ast->child(1)->child(1),
00216 ast->child(0)->child(0),
00217 ast->child(1)->child(0), true);
00218 }
00219 break;
00220 }
00221
00222 case at_suspend:
00223 {
00224 markTail(ast->child(1), fn, bps, isTail);
00225 break;
00226 }
00227
00228 case at_typeAnnotation:
00229 {
00230 markTail(ast->child(0), fn, bps, isTail);
00231 break;
00232 }
00233
00234 case at_begin:
00235 case at_labeledBlock:
00236 case at_return_from:
00237 {
00238
00239
00240 if (ast->children.size())
00241 markTail(ast->child(ast->children.size() - 1), fn, bps, isTail);
00242 break;
00243 }
00244
00245 case at_loop:
00246 {
00247 markTail(ast->child(1), fn, bps, isTail);
00248 break;
00249 }
00250
00251 case at_looptest:
00252 {
00253 markTail(ast->child(1), fn, bps, isTail);
00254 break;
00255 }
00256
00257 case at_fqCtr:
00258 case at_sel_ctr:
00259 case at_select:
00260 {
00261
00262 break;
00263 }
00264
00265 case at_if:
00266 {
00267
00268 markTail(ast->child(1), fn, bps, isTail);
00269 markTail(ast->child(2), fn, bps, isTail);
00270 break;
00271 }
00272
00273 case at_when:
00274 case at_unless:
00275 {
00276
00277 markTail(ast->child(1), fn, bps, isTail);
00278 break;
00279 }
00280
00281 case at_apply:
00282 {
00283 markTail(ast->child(0), fn, bps, isTail);
00284
00285
00286
00287 break;
00288 }
00289
00290 case at_ucon_apply:
00291 case at_struct_apply:
00292 case at_object_apply:
00293 {
00294
00295
00296
00297 break;
00298 }
00299
00300 case at_allocREF:
00301 case at_and:
00302 case at_or:
00303 case at_dup:
00304 case at_deref:
00305 case at_inner_ref:
00306 #ifdef HAVE_INDEXABLE_LENGTH_OPS
00307 case at_array_length:
00308 case at_array_ref_length:
00309 case at_vector_length:
00310 #endif
00311 case at_array_nth:
00312 case at_array_ref_nth:
00313 case at_vector_nth:
00314 case at_vector:
00315 case at_array:
00316 case at_MakeVector:
00317 case at_setbang:
00318 case at_mkClosure:
00319 case at_mkArrayRef:
00320 {
00321 break;
00322 }
00323
00324 case at_nth:
00325
00326 assert(false);
00327 break;
00328
00329 case at_cond:
00330 case at_cond_legs:
00331 case at_condelse:
00332 case at_usw_legs:
00333 case at_throw:
00334 case at_setClosure:
00335 case at_copyREF:
00336 {
00337 for (size_t c = 0; c < ast->children.size(); c++)
00338 markTail(ast->child(c), fn, bps, isTail);
00339 break;
00340 }
00341
00342 case at_uswitch:
00343 case at_try:
00344 {
00345 for (size_t c = 0; c < ast->children.size(); c++)
00346 if (c != IGNORE(ast))
00347 markTail(ast->child(c), fn, bps, isTail);
00348 break;
00349 }
00350
00351 case at_cond_leg:
00352 {
00353
00354 markTail(ast->child(1), fn, bps, isTail);
00355 break;
00356 }
00357
00358 case at_otherwise:
00359 case at_usw_leg:
00360 {
00361 markTail(ast->child(1), fn, bps, isTail);
00362 break;
00363 }
00364
00365 case at_let:
00366 case at_letrec:
00367 case at_letStar:
00368 {
00369
00370
00371
00372
00373
00374 markTail(ast->child(1), fn, bps, isTail);
00375 break;
00376 }
00377 }
00378 }
00379
00380
00381 bool
00382 UocInfo::be_tail(std::ostream& errStream,
00383 bool init, unsigned long flags)
00384 {
00385 bool errFree = true;
00386
00387 shared_ptr<UocInfo> uoc = shared_from_this();
00388
00389 markTail(uoc->uocAst, GC_NULL, GC_NULL, true);
00390 return errFree;
00391 }