From 3c4e7dd20c9d5cc2bfe9499f52fc06099855882f Mon Sep 17 00:00:00 2001 From: krangelov Date: Tue, 5 Oct 2021 15:37:42 +0200 Subject: [PATCH] partial evaluation for (+) --- src/compiler/GF/Compile/Compute/Concrete.hs | 5 +++++ testsuite/compiler/compute/predef.gfs | 2 ++ testsuite/compiler/compute/predef.gfs.gold | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/compiler/GF/Compile/Compute/Concrete.hs b/src/compiler/GF/Compile/Compute/Concrete.hs index c824cf797..bd8da7e3d 100644 --- a/src/compiler/GF/Compile/Compute/Concrete.hs +++ b/src/compiler/GF/Compile/Compute/Concrete.hs @@ -126,6 +126,11 @@ eval env (C t1 t2) [] = do v1 <- eval env t1 [] (VC vs1,v2 ) -> return (VC (vs1++[v2])) (v1, VC vs2) -> return (VC ([v1]++vs2)) (v1, v2 ) -> return (VC [v1,v2]) +eval env t@(Glue t1 t2) [] = do v1 <- eval env t1 [] + v2 <- eval env t2 [] + case liftM2 (++) (value2string v1) (value2string v2) of + Just s -> return (string2value s) + Nothing -> evalError ("Cannot reduce term" <+> pp t) eval env (FV ts) vs = msum [eval env t vs | t <- ts] eval env (Error msg) vs = fail msg eval env t vs = evalError ("Cannot reduce term" <+> pp t) diff --git a/testsuite/compiler/compute/predef.gfs b/testsuite/compiler/compute/predef.gfs index cd1b9c6c6..14fc0a920 100644 --- a/testsuite/compiler/compute/predef.gfs +++ b/testsuite/compiler/compute/predef.gfs @@ -31,3 +31,5 @@ cc "x"++SOFT_BIND++"y" cc "x"++SOFT_SPACE++"y" cc "x"++CAPIT++"y" cc "x"++ALL_CAPIT++"y" +cc "a"+"b" +cc eqInt (length ("a"+"b")) 2 diff --git a/testsuite/compiler/compute/predef.gfs.gold b/testsuite/compiler/compute/predef.gfs.gold index 31e8cdd18..0db3b26d5 100644 --- a/testsuite/compiler/compute/predef.gfs.gold +++ b/testsuite/compiler/compute/predef.gfs.gold @@ -32,3 +32,5 @@ CallStack (from HasCallStack): "x" ++ Predef.SOFT_SPACE ++ "y" "x" ++ Predef.CAPIT ++ "y" "x" ++ Predef.ALL_CAPIT ++ "y" +"ab" +Predef.PTrue