gawk-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gawk-diffs] [SCM] gawk branch, feature/fix-indirect-call, created. gawk


From: Arnold Robbins
Subject: [gawk-diffs] [SCM] gawk branch, feature/fix-indirect-call, created. gawk-4.1.0-617-g5951486
Date: Fri, 20 Mar 2015 08:32:26 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".

The branch, feature/fix-indirect-call has been created
        at  59514868fde1190f719e78d4c4b91bd14a321541 (commit)

- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=59514868fde1190f719e78d4c4b91bd14a321541

commit 59514868fde1190f719e78d4c4b91bd14a321541
Author: Arnold D. Robbins <address@hidden>
Date:   Fri Mar 20 10:31:49 2015 +0200

    Start on testing/fixing indirect calls of builtins.

diff --git a/ChangeLog b/ChangeLog
index b8b3ee9..723ee3a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2015-03-20         Arnold D. Robbins     <address@hidden>
+
+       Start on fixing indirect calls of builtins.
+
+       * awk.h (call_sub_func): Add declaration.
+       * awkgram.y (lookup_builtin): Handle length, sub functions.
+       (install_builtin): Handle length function.
+       * builtin.c (call_sub_func): New function.
+       * interpret.h (r_interpret): If calling do_sub, do it through
+       call_sub_func().
+
 2015-03-18         Arnold D. Robbins     <address@hidden>
 
        * config.guess, config.sub: Updated, from libtool 2.4.6.
diff --git a/awk.h b/awk.h
index 08c6891..f2ef358 100644
--- a/awk.h
+++ b/awk.h
@@ -1360,6 +1360,7 @@ extern NODE *do_rand(int nargs);
 extern NODE *do_srand(int nargs);
 extern NODE *do_match(int nargs);
 extern NODE *do_sub(int nargs, unsigned int flags);
+extern NODE *call_sub_func(const char *name, int nargs);
 extern NODE *format_tree(const char *, size_t, NODE **, long);
 extern NODE *do_lshift(int nargs);
 extern NODE *do_rshift(int nargs);
diff --git a/awkgram.c b/awkgram.c
index 5376d01..ec9b16a 100644
--- a/awkgram.c
+++ b/awkgram.c
@@ -7969,13 +7969,26 @@ lookup_builtin(const char *name)
 {
        int mid = check_special(name);
 
-       if (mid == -1 || tokentab[mid].class != LEX_BUILTIN)
+       if (mid == -1)
                return NULL;
+
+       switch (tokentab[mid].class) {
+       case LEX_BUILTIN:
+       case LEX_LENGTH:
+               break;
+       default:
+               return NULL;
+       }
+
 #ifdef HAVE_MPFR
        if (do_mpfr)
                return tokentab[mid].ptr2;
 #endif
 
+       /* And another special case... */
+       if (tokentab[mid].value == Op_sub_builtin)
+               return (builtin_func_t) do_sub;
+
        return tokentab[mid].ptr;
 }
 
@@ -7988,7 +8001,8 @@ install_builtins(void)
 
        j = sizeof(tokentab) / sizeof(tokentab[0]);
        for (i = 0; i < j; i++) {
-               if (    tokentab[i].class == LEX_BUILTIN
+               if (    (tokentab[i].class == LEX_BUILTIN
+                        || tokentab[i].class == LEX_LENGTH)
                    && (tokentab[i].flags & DEBUG_USE) == 0) {
                        (void) install_symbol(tokentab[i].operator, 
Node_builtin_func);
                }
diff --git a/awkgram.y b/awkgram.y
index 2307c36..2be4d37 100644
--- a/awkgram.y
+++ b/awkgram.y
@@ -5630,13 +5630,26 @@ lookup_builtin(const char *name)
 {
        int mid = check_special(name);
 
-       if (mid == -1 || tokentab[mid].class != LEX_BUILTIN)
+       if (mid == -1)
                return NULL;
+
+       switch (tokentab[mid].class) {
+       case LEX_BUILTIN:
+       case LEX_LENGTH:
+               break;
+       default:
+               return NULL;
+       }
+
 #ifdef HAVE_MPFR
        if (do_mpfr)
                return tokentab[mid].ptr2;
 #endif
 
+       /* And another special case... */
+       if (tokentab[mid].value == Op_sub_builtin)
+               return (builtin_func_t) do_sub;
+
        return tokentab[mid].ptr;
 }
 
@@ -5649,7 +5662,8 @@ install_builtins(void)
 
        j = sizeof(tokentab) / sizeof(tokentab[0]);
        for (i = 0; i < j; i++) {
-               if (    tokentab[i].class == LEX_BUILTIN
+               if (    (tokentab[i].class == LEX_BUILTIN
+                        || tokentab[i].class == LEX_LENGTH)
                    && (tokentab[i].flags & DEBUG_USE) == 0) {
                        (void) install_symbol(tokentab[i].operator, 
Node_builtin_func);
                }
diff --git a/builtin.c b/builtin.c
index 1383572..4dd08eb 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2994,6 +2994,29 @@ done:
        return make_number((AWKNUM) matches);
 }
 
+/* call_sub_func --- call do_sub indirectly */
+
+NODE *
+call_sub_func(const char *name, int nargs)
+{
+       unsigned int flags = 0;
+       NODE *tmp;
+
+       if (name[0] == 'g') {
+               if (name[1] == 'e')
+                       flags = GENSUB;
+               else
+                       flags = GSUB;
+       }
+
+       tmp = PEEK(1);
+       if (tmp->type == Node_val) {
+               flags |= LITERAL;
+       }
+
+       return do_sub(nargs, flags);
+}
+
 
 /* make_integer - Convert an integer to a number node.  */
 
diff --git a/indirectbuitin.awk b/indirectbuitin.awk
new file mode 100644
index 0000000..26cb5cc
--- /dev/null
+++ b/indirectbuitin.awk
@@ -0,0 +1,247 @@
+function print_result(category, fname, builtin_result, indirect_result)
+{
+       if (builtin_result == indirect_result)
+               printf("%s: %s: pass\n", category, fname)
+       else
+               printf("%s: %s: fail: builtin: %s \tindirect: %s\n", category, 
fname,
+                               builtin_result, indirect_result)
+}
+
+BEGIN {
+
+       fun = "sub"
+       x = "ff11bb"
+       b1 = sub("f", "q", x)
+       i1 = @fun("f", "q", x)
+       print_result("string", fun, b1, i1)
+}
+
+
+BEGIN {
+# math functions
+
+       fun = "and"
+       b1 = and(0x11, 0x01)
+       i1 = @fun(0x11, 0x01)
+       print_result("math", fun, b1, i1)
+
+       fun = "atan2"
+       b1 = atan2(-1, 0)
+       i1 = @fun(-1, 0)
+       print_result("math", fun, b1, i1)
+
+       fun = "compl"
+       b1 = compl(0x1111)
+       i1 = @fun(0x1111)
+       print_result("math", fun, b1, i1)
+
+       fun = "cos"
+       b1 = cos(3.1415927 / 4)
+       i1 = @fun(3.1415927 / 4)
+       print_result("math", fun, b1, i1)
+
+       fun = "exp"
+       b1 = exp(2)
+       i1 = @fun(2)
+       print_result("math", fun, b1, i1)
+
+       fun = "int"
+       b1 = int(3.1415927)
+       i1 = @fun(3.1415927)
+       print_result("math", fun, b1, i1)
+
+       fun = "log"
+       b1 = log(10)
+       i1 = @fun(10)
+       print_result("math", fun, b1, i1)
+
+       fun = "lshift"
+       b1 = lshift(1, 2)
+       i1 = @fun(1, 2)
+       print_result("math", fun, b1, i1)
+
+       fun = "or"
+       b1 = or(0x10, 0x01)
+       i1 = @fun(0x10, 0x01)
+       print_result("math", fun, b1, i1)
+
+       fun = "rand"
+       srand(1)
+       b1 = rand();
+       srand(1)
+       i1 = @fun()
+       print_result("math", fun, b1, i1)
+
+       fun = "rshift"
+       b1 = rshift(0x10, 1)
+       i1 = @fun(0x10, 1)
+       print_result("math", fun, b1, i1)
+
+       fun = "sin"
+       b1 = sin(3.1415927 / 4)
+       i1 = @fun(3.1415927 / 4)
+       print_result("math", fun, b1, i1)
+
+       fun = "sqrt"
+       b1 = sqrt(2)
+       i1 = @fun(2)
+       print_result("math", fun, b1, i1)
+
+       srand()
+       fun = "srand"
+       b1 = srand()
+       i1 = @fun()
+       print_result("math", fun, b1, i1)
+
+       fun = "xor"
+       b1 = xor(0x11, 0x01)
+       i1 = @fun(0x11, 0x01)
+       print_result("math", fun, b1, i1)
+
+# string functions
+
+#      fun = "gensub"
+#      b1 = gensub("f", "q","g", "ff11bb")
+#      i1 = @fun("f", "q", "g", "ff11bb")
+#      print_result("string", fun, b1, i1)
+
+#      fun = "gsub"
+#      x = "ff11bb"
+#      b1 = gsub("f", "q", x)
+#      i1 = @fun("f", "q", x)
+#      print_result("string", fun, b1, i1)
+
+       fun = "index"
+       b1 = index("hi, how are you", "how")
+       i1 = @fun("hi, how are you", "how")
+       print_result("string", fun, b1, i1)
+
+       fun = "dcgettext"
+       b1 = dcgettext("hello, world")
+       i1 = @fun("hello, world")
+       print_result("string", fun, b1, i1)
+
+       fun = "dcngettext"
+       b1 = dcngettext("hello, world", "howdy", 2)
+       i1 = @fun("hello, world", "howdy", 2)
+       print_result("string", fun, b1, i1)
+
+       fun = "length"
+       b1 = length("hi, how are you")
+       i1 = @fun("hi, how are you")
+       print_result("string", fun, b1, i1)
+
+       fun = "sprintf"
+       b1 = sprintf("%s world", "hello")
+       i1 = @fun("%s world", "hello")
+       print_result("string", fun, b1, i1)
+
+       fun = "strtonum"
+       b1 = strtonum("0xdeadbeef")
+       i1 = @fun("0xdeadbeef")
+       print_result("string", fun, b1, i1)
+
+       fun = "sub"
+       x = "ff11bb"
+       b1 = sub("f", "q", x)
+       i1 = @fun("f", "q", x)
+       print_result("string", fun, b1, i1)
+
+       fun = "substr"
+       b1 = substr("0xdeadbeef", 7, 4)
+       i1 = @fun("0xdeadbeef", 7, 4)
+       print_result("string", fun, b1, i1)
+
+       fun = "tolower"
+       b1 = tolower("0xDeAdBeEf")
+       i1 = @fun("0xDeAdBeEf")
+       print_result("string", fun, b1, i1)
+
+       fun = "toupper"
+       b1 = toupper("0xDeAdBeEf")
+       i1 = @fun("0xDeAdBeEf")
+       print_result("string", fun, b1, i1)
+
+# time functions
+
+       fun = "mktime"
+       b1 = mktime("1990 02 11 12 00 00")
+       i1 = @fun("1990 02 11 12 00 00")
+       print_result("time", fun, b1, i1)
+
+       then = b1
+       fun = "strftime"
+       b1 = strftime(PROCINFO["strftime"], then)
+       i1 = @fun(PROCINFO["strftime"], then)
+       print_result("time", fun, b1, i1)
+
+       fun = "systime"
+       b1 = systime()
+       i1 = @fun()
+       print_result("time", fun, b1, i1)
+
+# regexp functions
+
+#      fun = "match"
+#      print_result("regexp", fun, b1, i1)
+
+#      fun = "patsplit"
+#      print_result("regexp", fun, b1, i1)
+
+#      fun = "split"
+#      print_result("regexp", fun, b1, i1)
+
+# array functions
+
+       split("z y x w v u t", data)
+       fun = "asort"
+       asort(data, newdata)
+       @fun(data, newdata2)
+       print_result("array", fun, b1, i1)
+       for (i in newdata) {
+               if (! (i in newdata2) || newdata[i] != newdata2[i]) {
+                       print fun ": failed, index", i
+                       exit
+               }
+       }
+
+       for (i in data)
+               data2[data[i]] = i
+
+       fun = "asorti"
+       asort(data2, newdata)
+       @fun(data2, newdata2)
+       print_result("array", fun, b1, i1)
+       for (i in newdata) {
+               if (! (i in newdata2) || newdata[i] != newdata2[i]) {
+                       print fun ": failed, index", i
+                       exit
+               }
+       }
+
+       arr[1] = arr[2] = 42
+       fun = "isarray"
+       b1 = isarray(arr)
+       i1 = @fun(arr)
+       print_result("array", fun, b1, i1)
+
+# i/o functions
+
+       print("hi") > "x1.out"
+       print("hi") > "x2.out"
+
+       fun = "fflush"
+       b1 = fflush("x1.out")
+       i1 = @fun("x2.out")
+       print_result("i/o", fun, b1, i1)
+
+       fun = "close"
+       b1 = close("x1.out")
+       i1 = @fun("x2.out")
+       print_result("i/o", fun, b1, i1)
+
+       fun = "system"
+       b1 = system("rm x1.out")
+       i1 = @fun("rm x2.out")
+       print_result("i/o", fun, b1, i1)
+}
diff --git a/interpret.h b/interpret.h
index b16dc12..9160d47 100644
--- a/interpret.h
+++ b/interpret.h
@@ -1066,7 +1066,11 @@ match_re:
                                assert(the_func != NULL);
 
                                /* call it */
-                               r = the_func(arg_count);
+                               if (the_func == do_sub)
+                                       r = call_sub_func(t1->stptr, arg_count);
+                               else
+                                       r = the_func(arg_count);
+
                                PUSH(r);
                                break;
                        } else if (f->type != Node_func) {

-----------------------------------------------------------------------


hooks/post-receive
-- 
gawk



reply via email to

[Prev in Thread] Current Thread [Next in Thread]