From d103cbe5f71372116bb096d9cd544d323884a8c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fredrik=20H=C3=BCbinette=20=28Hubbe=29?= <hubbe@hubbe.net>
Date: Fri, 30 Jan 1998 12:04:32 -0800
Subject: [PATCH] tailrecurse-fix

Rev: src/docode.c:1.29
Rev: src/interpret.c:1.64
Rev: src/peep.in:1.10
---
 src/docode.c    | 15 +++++++++++----
 src/interpret.c | 18 ++++++++++++++++--
 src/peep.in     |  1 +
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/src/docode.c b/src/docode.c
index 47fb435395..7109fc5998 100644
--- a/src/docode.c
+++ b/src/docode.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: docode.c,v 1.28 1998/01/29 02:47:43 hubbe Exp $");
+RCSID("$Id: docode.c,v 1.29 1998/01/30 20:04:31 hubbe Exp $");
 #include "las.h"
 #include "program.h"
 #include "language.h"
@@ -481,7 +481,7 @@ static int do_docode2(node *n,int flags)
   case F_NOT:
   case F_COMPL:
   case F_NEGATE:
-    fatal("Optimizer errror.\n");
+    fatal("Optimizer error.\n");
 
   case F_RANGE:
     tmp1=do_docode(CAR(n),DO_NOT_COPY);
@@ -712,8 +712,15 @@ static int do_docode2(node *n,int flags)
       {
 	yyerror("No call_function efun.");
       }else{
-	tmp1=store_constant(& foo->u.sval, 1);
-	emit(F_APPLY, tmp1);
+	if(foo->u.sval.type == T_FUNCTION &&
+	   foo->u.sval.subtype == FUNCTION_BUILTIN &&
+	   foo->u.sval.u.efun->function == f_call_function)
+	{
+	  emit2(F_CALL_FUNCTION);
+	}else{
+	  tmp1=store_constant(& foo->u.sval, 1);
+	  emit(F_APPLY, tmp1);
+	}
       }
       free_node(foo);
       return 1;
diff --git a/src/interpret.c b/src/interpret.c
index cadcec7a56..22404a8aee 100644
--- a/src/interpret.c
+++ b/src/interpret.c
@@ -4,7 +4,7 @@
 ||| See the files COPYING and DISCLAIMER for more information.
 \*/
 #include "global.h"
-RCSID("$Id: interpret.c,v 1.63 1998/01/29 06:02:28 hubbe Exp $");
+RCSID("$Id: interpret.c,v 1.64 1998/01/30 20:04:32 hubbe Exp $");
 #include "interpret.h"
 #include "object.h"
 #include "program.h"
@@ -1438,7 +1438,21 @@ static int eval_instruction(unsigned char *pc)
     break;
 
     CASE(F_CALL_FUNCTION_AND_RETURN);
-    return sp - *--mark_sp;
+    {
+      INT32 args=sp - *--mark_sp;
+      if(!args)
+	error("Too few arguments to call_function()\n");
+      switch(sp[-args].type)
+      {
+	case T_INT:
+	case T_STRING:
+	case T_FLOAT:
+	case T_MAPPING:
+	case T_MULTISET:
+	  error("Attempting to call a non-function value (%s).\n",get_name_of_type(sp[-args].type));
+      }
+      return args;
+    }
 
     default:
       fatal("Strange instruction %ld\n",(long)instr);
diff --git a/src/peep.in b/src/peep.in
index 93f78ccc7c..b594bd99ef 100644
--- a/src/peep.in
+++ b/src/peep.in
@@ -153,3 +153,4 @@ LTOSVAL ADD ASSIGN_AND_POP : ADD_TO_AND_POP
 
 APPLY RETURN : APPLY_AND_RETURN($1a)
 CALL_FUNCTION RETURN : CALL_FUNCTION_AND_RETURN
+CALL_LFUN RETURN : CALL_LFUN_AND_RETURN($1a)
-- 
GitLab