diff -r 0163df6e1ff4 pure/interpreter.cc
|
|
|
17156 | 17156 | debug(msg.str().c_str()); } |
17157 | 17157 | #endif |
17158 | 17158 | if (retv) { |
| 17159 | if (rp) debug_redn(rp, retv); |
17159 | 17160 | if (f.n+f.m != 0 || !debugging) { |
17160 | 17161 | // do cleanup |
17161 | 17162 | Function *free_fun = module->getFunction("pure_pop_args"); |
17162 | 17163 | f.builder.CreateCall3(free_fun, retv, UInt(f.n), UInt(f.m)); |
17163 | 17164 | } |
17164 | | if (rp) debug_redn(rp, retv); |
17165 | 17165 | f.builder.CreateRet(retv); |
17166 | 17166 | } else if (tail) { |
17167 | 17167 | // Tail-recursive type rule. Perform a direct tail call on the rightmost |
diff -r 0163df6e1ff4 pure/printer.cc
|
|
|
917 | 917 | static inline bool pstr(ostream& os, pure_expr *x) |
918 | 918 | { |
919 | 919 | static bool recursive = false; |
| 920 | if (!x) return false; |
920 | 921 | if (recursive || |
921 | 922 | // We don't want to force a thunk here. Unfortunately, this means that |
922 | 923 | // currently you can't define a print representation for a thunk, at |
… |
… |
|
928 | 929 | map<int32_t,GlobalVar>::iterator it; |
929 | 930 | if (f > 0 && (it = interp.globalvars.find(f)) != interp.globalvars.end() && |
930 | 931 | it->second.x && it->second.x->tag >= 0 && it->second.x->data.clos) { |
931 | | assert(x->refc > 0); |
932 | 932 | pure_aframe *ex = interp.push_aframe(interp.sstk_sz); |
933 | 933 | if (setjmp(ex->jmp)) { |
934 | 934 | // caught an exception |
… |
… |
|
943 | 943 | recursive = false; |
944 | 944 | return false; |
945 | 945 | } else { |
| 946 | bool ret = false; |
946 | 947 | recursive = true; |
| 948 | // The argument expression may well be a temporary if we're being |
| 949 | // invoked internally, so make sure that it doesn't get collected |
| 950 | // prematurely. |
| 951 | pure_ref(x); |
947 | 952 | pure_expr *y = pure_app(it->second.x, x); |
948 | 953 | interp.pop_aframe(); |
949 | 954 | recursive = false; |
950 | | assert(y); |
951 | | if (y->tag == EXPR::STR) { |
952 | | char *s = fromutf8(y->data.s); |
| 955 | if (y) { |
| 956 | if (y->tag == EXPR::STR) { |
| 957 | char *s = fromutf8(y->data.s); |
| 958 | if (s) { |
| 959 | os << s; free(s); |
| 960 | ret = true; |
| 961 | } |
| 962 | } |
953 | 963 | pure_freenew(y); |
954 | | if (s) { |
955 | | os << s; free(s); |
956 | | return true; |
957 | | } else |
958 | | return false; |
959 | | } else |
960 | | return false; |
| 964 | } |
| 965 | pure_unref(x); |
| 966 | return ret; |
961 | 967 | } |
962 | 968 | } else |
963 | 969 | return false; |