From 7748144a8fcb8f8bd2e4f0a04c7d3436a2884f96 Mon Sep 17 00:00:00 2001 From: Dmitry Boulytchev Date: Fri, 10 Apr 2020 03:15:18 +0300 Subject: [PATCH] Fixed bug in tail-call optimization --- src/X86.ml | 4 ++-- src/version.ml | 2 +- stdlib/regression/orig/test27.log | 1 + stdlib/regression/test27.lama | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 stdlib/regression/orig/test27.log create mode 100644 stdlib/regression/test27.lama diff --git a/src/X86.ml b/src/X86.ml index 4a20d1676..14684a165 100644 --- a/src/X86.ml +++ b/src/X86.ml @@ -179,7 +179,7 @@ let compile cmd env imports code = ) in let call env f n tail = - let tail = tail && env#nargs = n && f.[0] <> '.' in + let tail = tail && env#nargs = n && f.[0] <> '.' in let f = match f.[0] with '.' -> "B" ^ String.sub f 1 (String.length f - 1) | _ -> f in @@ -194,7 +194,7 @@ let compile cmd env imports code = in let env, pushs = push_args env [] n in let y, env = env#allocate in - env, pushs @ [Mov (ebp, esp); Pop (ebp); Jmp f] + env, pushs @ [Mov (ebp, esp); Pop (ebp)] @ (if env#has_closure then [Pop ebx] else []) @ [Jmp f] ) else ( let pushr, popr = diff --git a/src/version.ml b/src/version.ml index 62f566655..155880415 100644 --- a/src/version.ml +++ b/src/version.ml @@ -1 +1 @@ -let version = "Version 1.00, eeab48ed3, Sun Mar 22 21:58:11 2020 +0300" +let version = "Version 1.00, b7ec1c2e6, Mon Mar 23 00:51:00 2020 +0300" diff --git a/stdlib/regression/orig/test27.log b/stdlib/regression/orig/test27.log new file mode 100644 index 000000000..dcd7a5d6d --- /dev/null +++ b/stdlib/regression/orig/test27.log @@ -0,0 +1 @@ +Yes diff --git a/stdlib/regression/test27.lama b/stdlib/regression/test27.lama new file mode 100644 index 000000000..2d91d8228 --- /dev/null +++ b/stdlib/regression/test27.lama @@ -0,0 +1,15 @@ +import Ostap; + +fun pure(v) { + empty @ lift(v) +} + +local parse = + token(".") |> fun(e1) { + token(".") |> fun(e2) { + pure(Dot(e1, e2)) }}; + +case parseString(parse |> bypass(eof), "..") of + Succ(_) -> printf("Yes\n") + | Fail(_, _, _) -> printf("No\n") +esac \ No newline at end of file