shithub: lu9-lua

Download patch

ref: 2f66462116426ef5bb22d29ec9b467f2e5e3bdf8
parent: 836fb511e9ada628af2b536e050ec4f7603a9eeb
author: kvik <kvik@a-b.xyz>
date: Thu Apr 8 18:07:49 EDT 2021

shim: incorporate shim code into liblua

Having shim code in a separate repository seemed like a good
idea since it could have been reused by different projects.
However, this didn't really occur since I realized that it's
best to provide only the shim code that's needed on a per-port
basis -- for which a simple copy-paste approach works fine.

This change simplifies the project structure and makes it easier
for others to use liblua -- all they need is liblua.

However, it is still neccessary to tell the compiler where
the shim headers are.  It's not great, but better than dumping
all this stuff into lua's own directory.

diff: cannot open b/shim//null: file does not exist: 'b/shim//null'
--- a/mkfile
+++ b/mkfile
@@ -1,9 +1,12 @@
 </$objtype/mkfile
 
-CFLAGS=-FTV -p -I../shim -DLUA_USE_PLAN9 -DLUA_UCID
+CFLAGS=-FTV -p -Ishim -DLUA_USE_PLAN9 -DLUA_UCID
 
 LIB=liblua.a.$O
 
+SHIMOBJS=\
+	shim.$O\
+
 COREOBJS=\
 	lapi.$O\
 	lcode.$O\
@@ -25,7 +28,6 @@
 	lundump.$O\
 	lvm.$O\
 	lzio.$O\
-	ltests.$O\
 	lauxlib.$O
 
 LIBOBJS=\
@@ -42,7 +44,7 @@
 	lcorolib.$O\
 	linit.$O
 
-ALLOBJS=$COREOBJS $LIBOBJS
+ALLOBJS=$SHIMOBJS $COREOBJS $LIBOBJS
 
 all:V: $LIB
 
--- /dev/null
+++ b/shim.c
@@ -1,0 +1,21 @@
+#include <u.h>
+#include <libc.h>
+
+#include "shim.h"
+
+/*
+ * This pointer MUST be initialized by
+ * a call to privalloc(2) prior to any
+ * use of the errno.
+ *   if(priv_errno == nil) priv_errno = privalloc();
+ */
+errno_t *priv_errno;
+
+char*
+strerror(int)
+{
+	static char err[ERRMAX];
+	
+	rerrstr(err, sizeof err);
+	return err;
+}
--- /dev/null
+++ b/shim/assert.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/errno.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/float.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/limits.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/locale.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/math.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/regex.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/setjmp.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/shim.h
@@ -1,0 +1,118 @@
+#ifndef _SHIM_H_
+#define _SHIM_H_
+
+/** PLAN 9 **/
+#ifndef nil
+#include <u.h>
+#include <libc.h>
+#include <tos.h>
+#endif
+
+/** assert.h **/
+
+/** ctype.h **/
+
+/** errno.h **/
+typedef int errno_t;
+extern errno_t *priv_errno;
+#define errno (*priv_errno)
+
+/** float.h **/
+#define FLT_ROUNDS	1
+#define FLT_RADIX	2
+
+#define FLT_DIG		6
+#define FLT_EPSILON	1.19209290e-07
+#define FLT_MANT_DIG	24
+#define FLT_MAX		3.40282347e+38
+#define FLT_MAX_10_EXP	38
+#define FLT_MAX_EXP	128
+#define FLT_MIN		1.17549435e-38
+#define FLT_MIN_10_EXP	-37
+#define FLT_MIN_EXP	-125
+
+#define DBL_DIG		15
+#define DBL_EPSILON	2.2204460492503131e-16
+#define DBL_MANT_DIG	53
+#define DBL_MAX		1.797693134862315708145e+308
+#define DBL_MAX_10_EXP	308
+#define DBL_MAX_EXP	1024
+#define DBL_MIN		2.225073858507201383090233e-308
+#define DBL_MIN_10_EXP	-307
+#define DBL_MIN_EXP	-1021
+#define LDBL_MANT_DIG	DBL_MANT_DIG
+#define LDBL_EPSILON	DBL_EPSILON
+#define LDBL_DIG	DBL_DIG
+#define LDBL_MIN_EXP	DBL_MIN_EXP
+#define LDBL_MIN	DBL_MIN
+#define LDBL_MIN_10_EXP	DBL_MIN_10_EXP
+#define LDBL_MAX_EXP	DBL_MAX_EXP
+#define LDBL_MAX	DBL_MAX
+#define LDBL_MAX_10_EXP	DBL_MAX_10_EXP
+
+/** limits.h **/
+#define CHAR_BIT	8
+#define MB_LEN_MAX	4
+
+#define UCHAR_MAX	0xff
+#define USHRT_MAX	0xffff
+#define UINT_MAX	0xffffffffU
+#define ULONG_MAX	0xffffffffUL
+#define ULLONG_MAX	0xffffffffffffffffULL
+
+#define CHAR_MAX	SCHAR_MAX
+#define SCHAR_MAX	0x7f
+#define SHRT_MAX	0x7fff
+#define INT_MAX		0x7fffffff
+#define LONG_MAX	0x7fffffffL
+#define LLONG_MAX	0x7fffffffffffffffLL
+
+#define CHAR_MIN	SCHAR_MIN
+#define SCHAR_MIN	(-SCHAR_MAX-1)
+#define SHRT_MIN	(-SHRT_MAX-1)
+#define INT_MIN		(-INT_MAX-1)
+#define LONG_MIN	(-LONG_MAX-1)
+#define LLONG_MIN	(-LLONG_MAX-1)
+
+/** locale.h **/
+
+/** math.h **/
+#define HUGE_VAL Inf(1)
+
+/** regex.h **/
+
+/** setjmp.h **/
+
+/** signal.h **/
+typedef int sig_atomic_t;
+
+/** stdarg.h **/
+
+/** stdbool.h **/
+
+/** stddef.h **/
+#define NULL ((void*)0)
+
+typedef long long ptrdiff_t;
+typedef unsigned long long size_t;
+
+/** stdio.h **/
+#include "/sys/include/stdio.h"
+
+/** stdlib.h **/
+
+/** string.h **/
+char *strerror(int);
+
+#define strcoll strcmp
+
+/** time.h **/
+#define CLOCKS_PER_SEC 1000
+
+typedef long clock_t;
+typedef long time_t;
+
+clock_t clock(void);
+#define clock() (clock_t)(-1);
+
+#endif /* _SHIM_H_ */
--- /dev/null
+++ b/shim/signal.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/stdarg.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/stdbool.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/stddef.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/stdio.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/stdlib.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/string.h
@@ -1,0 +1,1 @@
+#include <shim.h>
--- /dev/null
+++ b/shim/time.h
@@ -1,0 +1,1 @@
+#include <shim.h>