Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src lua libm API from Phil Rulon
details: https://anonhg.NetBSD.org/src/rev/9b1db38b9b81
branches: trunk
changeset: 372398:9b1db38b9b81
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 21 22:01:32 2022 +0000
description:
lua libm API from Phil Rulon
diffstat:
distrib/sets/lists/base/shl.mi | 3 +-
distrib/sets/lists/debug/mi | 6 +-
distrib/sets/lists/man/mi | 5 +-
distrib/sets/lists/tests/mi | 9 +-
etc/mtree/NetBSD.dist.tests | 6 +-
lib/lua/Makefile | 4 +-
lib/lua/libm/Makefile | 7 +
lib/lua/libm/libm.c | 313 ++++++++++++++++++++++++++++++++++++++++
share/man/man3lua/Makefile | 5 +-
share/man/man3lua/libm.3lua | 151 +++++++++++++++++++
tests/lib/Makefile | 4 +-
tests/lib/lua/Makefile | 9 +
tests/lib/lua/Makefile.inc | 1 +
tests/lib/lua/libm/Makefile | 20 ++
tests/lib/lua/libm/h_lualibm.c | 89 +++++++++++
tests/lib/lua/libm/lualibm.lua | 92 +++++++++++
tests/lib/lua/libm/t_lualibm.sh | 46 +++++
17 files changed, 759 insertions(+), 11 deletions(-)
diffs (truncated from 930 to 300 lines):
diff -r bf7ceb486890 -r 9b1db38b9b81 distrib/sets/lists/base/shl.mi
--- a/distrib/sets/lists/base/shl.mi Mon Nov 21 21:29:32 2022 +0000
+++ b/distrib/sets/lists/base/shl.mi Mon Nov 21 22:01:32 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: shl.mi,v 1.941 2022/10/05 22:40:12 christos Exp $
+# $NetBSD: shl.mi,v 1.942 2022/11/21 22:01:32 christos Exp $
#
# Note: Don't delete entries from here - mark them as "obsolete" instead,
# unless otherwise stated below.
@@ -966,6 +966,7 @@
./usr/lib/lua/5.1/syslog.so base-obsolete obsolete
./usr/lib/lua/5.3/bozohttpd.so base-sys-shlib compatfile
./usr/lib/lua/5.3/gpio.so base-sys-shlib compatfile
+./usr/lib/lua/5.3/libm.so base-sys-shlib compatfile
./usr/lib/lua/5.3/netpgp.so base-sys-shlib compatfile
./usr/lib/lua/5.3/sqlite.so base-sys-shlib compatfile
./usr/lib/lua/5.3/syslog.so base-sys-shlib compatfile
diff -r bf7ceb486890 -r 9b1db38b9b81 distrib/sets/lists/debug/mi
--- a/distrib/sets/lists/debug/mi Mon Nov 21 21:29:32 2022 +0000
+++ b/distrib/sets/lists/debug/mi Mon Nov 21 22:01:32 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.391 2022/11/17 08:45:35 ozaki-r Exp $
+# $NetBSD: mi,v 1.392 2022/11/21 22:01:32 christos Exp $
./etc/mtree/set.debug comp-sys-root
./usr/lib comp-sys-usr compatdir
./usr/lib/i18n/libBIG5_g.a comp-c-debuglib debuglib,compatfile
@@ -2400,6 +2400,10 @@
./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_dlvsym.debug tests-libexec-debug debug,atf,pic,compattestfile
./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_rtld_r_debug.debug tests-libexec-debug debug,atf,pic,compattestfile
./usr/libdata/debug/usr/tests/libexec/ld.elf_so/t_ifunc.debug tests-libexec-debug debug,atf,pic,compattestfile
+./usr/libdata/debug/usr/tests/lib tests-libexec-debug debug,atf,pic,compattestfile
+./usr/libdata/debug/usr/tests/lib/lua tests-libexec-debug debug,atf,pic,compattestfile
+./usr/libdata/debug/usr/tests/lib/lua/libm tests-libexec-debug debug,atf,pic,compattestfile
+./usr/libdata/debug/usr/tests/lib/lua/libm/h_lualibm.debug tests-libexec-debug debug,atf,pic,compattestfile
./usr/libdata/debug/usr/tests/net/bpf/t_bpf.debug tests-net-debug debug,atf,rump
./usr/libdata/debug/usr/tests/net/bpf/t_div-by-zero.debug tests-net-debug debug,atf,rump
./usr/libdata/debug/usr/tests/net/bpf/t_mbuf.debug tests-net-debug debug,atf,rump
diff -r bf7ceb486890 -r 9b1db38b9b81 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Mon Nov 21 21:29:32 2022 +0000
+++ b/distrib/sets/lists/man/mi Mon Nov 21 22:01:32 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1756 2022/11/21 21:24:01 brad Exp $
+# $NetBSD: mi,v 1.1757 2022/11/21 22:01:32 christos Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -695,6 +695,7 @@
./usr/share/man/cat3lua/gpio.unset.0 man-sys-catman .cat
./usr/share/man/cat3lua/gpio.write.0 man-sys-catman .cat
./usr/share/man/cat3lua/intro.0 man-sys-catman .cat
+./usr/share/man/cat3lua/libm.0 man-sys-catman .cat
./usr/share/man/cat3lua/netpgp.0 man-sys-catman .cat
./usr/share/man/cat3lua/sqlite.0 man-sys-catman .cat
./usr/share/man/cat3lua/syslog.0 man-sys-catman .cat
@@ -4013,6 +4014,7 @@
./usr/share/man/html3lua/gpio.unset.html man-sys-htmlman html
./usr/share/man/html3lua/gpio.write.html man-sys-htmlman html
./usr/share/man/html3lua/intro.html man-sys-htmlman html
+./usr/share/man/html3lua/libm.html man-sys-htmlman html
./usr/share/man/html3lua/netpgp.html man-sys-htmlman html
./usr/share/man/html3lua/sqlite.html man-sys-htmlman html
./usr/share/man/html3lua/syslog.html man-sys-htmlman html
@@ -7007,6 +7009,7 @@
./usr/share/man/man3lua/gpio.unset.3lua man-sys-man .man
./usr/share/man/man3lua/gpio.write.3lua man-sys-man .man
./usr/share/man/man3lua/intro.3lua man-sys-man .man
+./usr/share/man/man3lua/libm.3lua man-sys-man .man
./usr/share/man/man3lua/netpgp.3lua man-sys-man .man
./usr/share/man/man3lua/sqlite.3lua man-sys-man .man
./usr/share/man/man3lua/syslog.3lua man-sys-man .man
diff -r bf7ceb486890 -r 9b1db38b9b81 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Mon Nov 21 21:29:32 2022 +0000
+++ b/distrib/sets/lists/tests/mi Mon Nov 21 22:01:32 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1233 2022/11/17 09:58:42 ozaki-r Exp $
+# $NetBSD: mi,v 1.1234 2022/11/21 22:01:33 christos Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -4035,6 +4035,13 @@
./usr/tests/lib/libutil/t_pidfile tests-lib-tests compattestfile,atf
./usr/tests/lib/libutil/t_snprintb tests-lib-tests compattestfile,atf
./usr/tests/lib/libutil/t_sockaddr_snprintf tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua/Atffile tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua/libm tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua/libm/Atffile tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua/libm/h_lualibm tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua/libm/lualibm.lua tests-lib-tests compattestfile,atf
+./usr/tests/lib/lua/libm/t_lualibm tests-lib-tests compattestfile,atf
./usr/tests/lib/semaphore tests-lib-tests compattestfile,atf
./usr/tests/lib/semaphore/Atffile tests-lib-tests compattestfile,atf
./usr/tests/lib/semaphore/Kyuafile tests-lib-tests compattestfile,atf,kyua
diff -r bf7ceb486890 -r 9b1db38b9b81 etc/mtree/NetBSD.dist.tests
--- a/etc/mtree/NetBSD.dist.tests Mon Nov 21 21:29:32 2022 +0000
+++ b/etc/mtree/NetBSD.dist.tests Mon Nov 21 22:01:32 2022 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: NetBSD.dist.tests,v 1.196 2022/11/17 08:45:35 ozaki-r Exp $
+# $NetBSD: NetBSD.dist.tests,v 1.197 2022/11/21 22:01:33 christos Exp $
./usr/libdata/debug/usr/tests
./usr/libdata/debug/usr/tests/atf
@@ -132,6 +132,8 @@
./usr/libdata/debug/usr/tests/lib/libtre
./usr/libdata/debug/usr/tests/lib/libusbhid
./usr/libdata/debug/usr/tests/lib/libutil
+./usr/libdata/debug/usr/tests/lib/lua
+./usr/libdata/debug/usr/tests/lib/lua/libm
./usr/libdata/debug/usr/tests/lib/semaphore
./usr/libdata/debug/usr/tests/lib/semaphore/pthread
./usr/libdata/debug/usr/tests/libexec
@@ -343,6 +345,8 @@
./usr/tests/lib/libtre/data
./usr/tests/lib/libusbhid
./usr/tests/lib/libutil
+./usr/tests/lib/lua
+./usr/tests/lib/lua/libm
./usr/tests/lib/semaphore
./usr/tests/lib/semaphore/pthread
./usr/tests/libexec
diff -r bf7ceb486890 -r 9b1db38b9b81 lib/lua/Makefile
--- a/lib/lua/Makefile Mon Nov 21 21:29:32 2022 +0000
+++ b/lib/lua/Makefile Mon Nov 21 22:01:32 2022 +0000
@@ -1,10 +1,10 @@
-# $NetBSD: Makefile,v 1.7 2018/05/03 22:51:18 sevan Exp $
+# $NetBSD: Makefile,v 1.8 2022/11/21 22:01:33 christos Exp $
.include <bsd.own.mk>
.if ${MKPIC} != "no"
# No support for shared libraries and pic code.
-SUBDIR+= bozohttpd gpio sqlite syslog
+SUBDIR+= bozohttpd gpio libm sqlite syslog
.endif
.include <bsd.subdir.mk>
diff -r bf7ceb486890 -r 9b1db38b9b81 lib/lua/libm/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/lua/libm/Makefile Mon Nov 21 22:01:32 2022 +0000
@@ -0,0 +1,7 @@
+# $NetBSD: Makefile,v 1.1 2022/11/21 22:01:33 christos Exp $
+
+LUA_MODULES = libm
+LUA_SRCS.libm = libm.c
+LUA_DPLIBS += m /usr/lib
+
+.include <bsd.lua.mk>
diff -r bf7ceb486890 -r 9b1db38b9b81 lib/lua/libm/libm.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/lua/libm/libm.c Mon Nov 21 22:01:32 2022 +0000
@@ -0,0 +1,313 @@
+/* $NetBSD: libm.c,v 1.1 2022/11/21 22:01:33 christos Exp $ */
+
+/*-
+ * Copyright (c) 2022 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Phillip Rulon
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: libm.c,v 1.1 2022/11/21 22:01:33 christos Exp $");
+
+#include <lua.h>
+#include <lauxlib.h>
+#include <math.h>
+
+const char badarg[] = "argument to libm function not a number";
+
+/*-
+ * The majority of libm functions fall into a few forms:
+ *
+ * int func(double);
+ * double func(double);
+ * double func(double, double);
+ * and,
+ * double func(int, double);
+ *
+ * Accordingly, this lends itself to systematic declaration of the lua
+ * interface functions. These macros set this up.
+ */
+#define BFUNC_DBL(fname) \
+static int \
+libm_##fname(lua_State *L) \
+{ \
+ if (!lua_isnumber(L, 1)) \
+ return luaL_error(L, badarg); \
+ \
+ double x = lua_tonumber(L, 1); \
+ lua_pushboolean(L, fname(x)); \
+ return 1; \
+}
+
+#define DFUNC_DBL(fname) \
+static int \
+libm_##fname(lua_State *L) \
+{ \
+ if (!lua_isnumber(L, 1)) \
+ return luaL_error(L, badarg); \
+ \
+ double x = lua_tonumber(L, 1); \
+ lua_pushnumber(L, fname(x)); \
+ return 1; \
+}
+
+#define DFUNC_INT_DBL(fname) \
+static int \
+libm_##fname(lua_State *L) \
+{ \
+ if (!lua_isinteger(L, 1) || \
+ !lua_isnumber(L, 2)) \
+ return luaL_error(L, badarg); \
+ \
+ int i = (int)lua_tointeger(L, 1); \
+ double x = lua_tonumber(L, 2); \
+ lua_pushnumber(L, fname(i, x)); \
+ return 1; \
+}
+
+#define DFUNC_DBL_DBL(fname) \
+static int \
+libm_##fname(lua_State *L) \
+{ \
+ if (!lua_isnumber(L, 1) || \
+ !lua_isnumber(L, 2)) \
+ return luaL_error(L, badarg); \
+ double x[] = { \
+ lua_tonumber(L, 1), \
+ lua_tonumber(L,2) \
+ }; \
+ lua_pushnumber(L, fname(x[0], x[1])); \
+ return 1; \
+}
+
+int luaopen_libm(lua_State *);
+
+DFUNC_DBL(acos)
+DFUNC_DBL(acosh)
+DFUNC_DBL(asin)
+DFUNC_DBL(asinh)
+DFUNC_DBL(atan)
+DFUNC_DBL(atanh)
+DFUNC_DBL_DBL(atan2)
+DFUNC_DBL(cbrt)
+DFUNC_DBL(ceil)
+DFUNC_DBL_DBL(copysign)
+DFUNC_DBL(cos)
+DFUNC_DBL(cosh)
+DFUNC_DBL(erf)
+DFUNC_DBL(erfc)
+DFUNC_DBL(exp)
+DFUNC_DBL(exp2)
+DFUNC_DBL(expm1)
+DFUNC_DBL(fabs)
+DFUNC_DBL_DBL(fdim)
+BFUNC_DBL(finite)
+DFUNC_DBL(floor)
+DFUNC_DBL_DBL(fmax)
+DFUNC_DBL_DBL(fmin)
+DFUNC_DBL_DBL(fmod)
+DFUNC_DBL(gamma)
+DFUNC_DBL_DBL(hypot)
+BFUNC_DBL(isfinite)
+BFUNC_DBL(isnan)
+BFUNC_DBL(isinf)
+DFUNC_DBL(j0)
+DFUNC_DBL(j1)
+DFUNC_INT_DBL(jn)
+DFUNC_DBL(lgamma)
+DFUNC_DBL(log)
+DFUNC_DBL(log10)
+DFUNC_DBL(log1p)
+DFUNC_DBL_DBL(nextafter)
+DFUNC_DBL_DBL(pow)
+DFUNC_DBL_DBL(remainder)
+DFUNC_DBL(rint)
+DFUNC_DBL(round)
+DFUNC_DBL(sin)
+DFUNC_DBL(sinh)
Home |
Main Index |
Thread Index |
Old Index