Commit 31b4810d authored by Laszlo Domoszlai's avatar Laszlo Domoszlai
Browse files

stub for general tail call optimization

parent 659d419d
TARGET = main
LIBS =
CC = clang++
CFLAGS = -O3 -x c++ -Wno-write-strings # -g -pg -fstack-usage
CFLAGS = -g -x c++ -Wno-write-strings # -g -pg -fstack-usage
.PHONY: default all clean
......@@ -17,7 +17,7 @@ HEADERS = $(wildcard *.h)
.PRECIOUS: $(TARGET) $(OBJECTS)
$(TARGET): $(OBJECTS)
$(CC) $(OBJECTS) -static -static-libgcc -static-libstdc++ -Wl,--stack,16777216 -Wall $(LIBS) -o $@ # -pg -g
$(CC) $(OBJECTS) -static -static-libgcc -static-libstdc++ -Wl,--stack,16777216 -Wall -g $(LIBS) -o $@ # -pg -g
clean:
-rm -f *.o
......
......@@ -145,6 +145,13 @@ void set_create_thunk_fun(Code* code)
}
}
// eval: frame_ptr, frame_ptr
// start: stack_top_a, stack_top_a
// otherwise: frame_ptr, stack_top_a
// frame_ptr: first arguments
// root_frame_ptr: place of the result
void exec(Code* expr, int frame_ptr, int root_frame_ptr)
{
if(heap_curr > gc_trigger) gc();
......@@ -655,6 +662,7 @@ void eval_fun()
}
exec(((FunEntry*) thunk->desc)->body, frame_ptr, frame_ptr);
//stack_a[frame_ptr] = stack_a[stack_top_a];
}
void eval_prim()
......
......@@ -29,7 +29,7 @@ int main ( int argc, char *argv[] )
init_desc();
init_prim();
char* input = "..\\tests\\Adjoxo.bsapl";
char* input = "..\\tests\\queens2.bsapl";
if ( argc == 2 )
{
......
......@@ -632,6 +632,8 @@ Code* parseTerm(char **ptr) {
return (Code*) parseApp(ptr, false, false);
case 'T': // Tail recursive application
return (Code*) parseApp(ptr, false, true);
case 't': // Tail call application
return (Code*) parseApp(ptr, false, true);
case 'D': // Dynamic application
return (Code*) parseApp(ptr, true, false);
case 'S': // Select
......
......@@ -105,7 +105,8 @@ isLocalVar ctx var = member (unpackVar var) ctx.vars
appType ctx var | isLocalVar ctx var
= "D"
appType {inspine, currentFun} var = if (inspine && unpackVar var == currentFun) "T" "A" // T: tail recursive
appType {inspine = True, currentFun} var = if (unpackVar var == currentFun) "T" "A" // T: tail recursive / TODO: "t: tail call "
appType _ _ = "A" // A: normal call
sLetDef ctx (SaplLetDef var binding) a = a <++ sVarFlag ctx (Local 0 (typeInfo var)) <++ sTerm ctx binding
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment