Skip to content

Commit

Permalink
First pass of Lua53 changes to make runable Lua53
Browse files Browse the repository at this point in the history
  • Loading branch information
TerryE committed Sep 13, 2019
1 parent 9300249 commit 1f75eaa
Show file tree
Hide file tree
Showing 68 changed files with 2,813 additions and 1,452 deletions.
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ else
CCFLAGS += -O2
endif


# Handling of V=1/VERBOSE=1 flag
#
# if V=1, $(summary) does nothing
Expand Down Expand Up @@ -274,7 +273,7 @@ endif # TARGET
#

ifndef TARGET
all: toolchain sdk_pruned pre_build buildinfo .subdirs
all: toolchain sdk_pruned pre_build .subdirs
else
all: .subdirs $(OBJS) $(OLIBS) $(OIMAGES) $(OBINS) $(SPECIAL_MKTARGETS)
endif
Expand Down Expand Up @@ -412,11 +411,6 @@ pre_build:
@-rm -f $(APP_DIR)/modules/server-ca.crt.h
endif

.PHONY: buildinfo

buildinfo:
tools/update_buildinfo.sh

ifdef TARGET
$(OBJODIR)/%.o: %.c
@mkdir -p $(dir $@);
Expand Down
17 changes: 12 additions & 5 deletions app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ TARGET = eagle
#FLAVOR = release
FLAVOR = debug

# Handle Lua Directory selector
ifeq ("$(LUA)","53")
LUA_DIR := lua53
else
LUA_DIR := lua
endif

ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
Expand All @@ -34,15 +41,15 @@ SUBDIRS= \
mbedtls \
platform \
libc \
lua \
$(LUA_DIR) \
lwip \
smart \
modules \
spiffs \
net \
net \
fatfs \
esp-gdbstub \
pm \
pm \
uzlib \
$(OPT_SEL_MKTARGETS)

Expand All @@ -65,7 +72,7 @@ COMPONENTS_eagle.app.v6 = \
driver/libdriver.a \
platform/libplatform.a \
libc/liblibc.a \
lua/liblua.a \
$(LUA_DIR)/liblua.a \
lwip/liblwip.a \
smart/smart.a \
spiffs/spiffs.a \
Expand Down Expand Up @@ -150,7 +157,7 @@ DDEFINES += \
#
# Required for each makefile to inherit from the parent
#
INCLUDES := -I $(PDIR)libc -I $(PDIR)lua -I $(PDIR)platform \
INCLUDES := -I $(PDIR)libc -I $(PDIR)$(LUA_DIR) -I $(PDIR)platform \
$(INCLUDES) -I $(PDIR) -I $(PDIR)include
PDIR := ../$(PDIR)

Expand Down
2 changes: 1 addition & 1 deletion app/lua/lvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
if (ttistable(t)) { /* `t' is a table? */
Table *h = hvalue(t);
const TValue *res = luaH_get(h, key); /* do a primitive get */
if (!ttisnil(res) || /* result is no nil? */
if (!ttisnil(res) || /* result is no nil? */
(tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
setobj2s(L, val, res);
return;
Expand Down
40 changes: 40 additions & 0 deletions app/lua53/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
SUBDIRS = host
GEN_LIBS = liblua.a
endif

STD_CFLAGS=-std=gnu11 -Wimplicit -Wall

#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
#
#DEFINES += -DDEVELOPMENT_TOOLS -DDEVELOPMENT_USE_GDB -DDEVELOPMENT_BREAK_ON_STARTUP_PIN=1
#EXTRA_CCFLAGS += -ggdb -O0

#############################################################
# Recursion Magic - Don't touch this!!
#

INCLUDES := $(INCLUDES) -I $(PDIR)include
INCLUDES += -I ./
INCLUDES += -I ../spiffs
INCLUDES += -I ../libc
INCLUDES += -I ../modules
INCLUDES += -I ../platform
INCLUDES += -I ../uzlib
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
111 changes: 111 additions & 0 deletions app/lua53/host/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#
# This Makefile is called from the core Makefile hierarchy which is a hierarchical
# make which uses parent callbacks to implement inheritance. However if luac_cross
# build stands outside this, it uses the host toolchain to implement a separate
# host build of the luac.cross image.
#
.NOTPARALLEL:

CCFLAGS:= -I. -I.. -I../../include -I../../uzlib
LDFLAGS:= -L$(SDK_DIR)/lib -L$(SDK_DIR)/ld -lm -ldl -Wl,-Map=mapfile

CCFLAGS += -Wall

TARGET = host

VERBOSE ?=
V ?= $(VERBOSE)
ifeq ("$(V)","1")
export summary := @true
else
export summary := @echo
# disable echoing of commands, directory names
# MAKEFLAGS += --silent -w
endif # $(V)==1

DEBUG ?=
ifeq ("$(DEBUG)","1")
FLAVOR = debug
CCFLAGS += -O0 -ggdb
TARGET_LDFLAGS += -O0 -ggdb
DEFINES += -DLUA_DEBUG_BUILD -DDEVELOPMENT_TOOLS -DDEVELOPMENT_USE_GDB
else
FLAVOR = release
CCFLAGS += -O2
TARGET_LDFLAGS += -O2
endif # DEBUG

LUACSRC := luac.c lflashimg.c liolib.c loslib.c
LUASRC := lapi.c lauxlib.c lbaselib.c lcode.c lcorolib.c lctype.c \
ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c \
linit.c llex.c lmathlib.c lmem.c loadlib.c lnodemcu.c \
lobject.c lopcodes.c lparser.c lstate.c lstring.c lstrlib.c \
ltable.c ltablib.c ltm.c lundump.c lutf8lib.c lvm.c \
lzio.c
UZSRC := uzlib_deflate.c crc32.c

TEST ?=
ifeq ("$(TEST)","1")
DEFINES += -DLUA_ENABLE_TEST
LUASRC += ltests.c
endif # $(TEST)==1

#
# This relies on the files being unique on the vpath
#
SRC := $(LUACSRC) $(LUASRC) $(UZSRC)
vpath %.c .:..:../../libc:../../uzlib

ODIR := .output/$(TARGET)/$(FLAVOR)/obj

OBJS := $(SRC:%.c=$(ODIR)/%.o)
DEPS := $(SRC:%.c=$(ODIR)/%.d)

CFLAGS = $(CCFLAGS) $(DEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)
DFLAGS = $(CCFLAGS) $(DDEFINES) $(EXTRA_CCFLAGS) $(STD_CFLAGS) $(INCLUDES)

CC := $(WRAPCC) gcc

ECHO := echo

BUILD_TYPE := $(shell $(CC) $(EXTRA_CCFLAGS) -E -dM - <../../include/user_config.h | grep LUA_NUMBER_INTEGRAL | wc -l)
ifeq ($(BUILD_TYPE),0)
IMAGE := ../../../luac.cross
else
IMAGE := ../../../luac.cross.int
endif

.PHONY: test clean all

all: $(DEPS) $(IMAGE)

$(IMAGE) : $(OBJS)
$(summary) HOSTLD $@
$(CC) $(OBJS) -o $@ $(LDFLAGS)

test :
@echo CC: $(CC)
@echo SRC: $(SRC)
@echo OBJS: $(OBJS)
@echo DEPS: $(DEPS)
@echo IMAGE: $(IMAGE)

clean :
$(RM) -r $(ODIR)

ifneq ($(MAKECMDGOALS),clean)
-include $(DEPS)
endif

$(ODIR)/%.o: %.c
@mkdir -p $(ODIR);
$(summary) HOSTCC $(CURDIR)/$<
$(CC) $(if $(findstring $<,$(DSRCS)),$(DFLAGS),$(CFLAGS)) $(COPTS_$(*F)) -o $@ -c $<

$(ODIR)/%.d: %.c
@mkdir -p $(ODIR);
$(summary) DEPEND: HOSTCC $(CURDIR)/$<
@set -e; rm -f $@; \
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
sed 's,\($*\.o\)[ :]*,$(ODIR)/\1 $@ : ,g' < $@.$$$$ > $@; \
rm -f $@.$$$$
Empty file added app/lua53/host/lflashimg.c
Empty file.
37 changes: 11 additions & 26 deletions app/lua53/host/ltests.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ typedef union Header {
struct {
size_t size;
int type;
union Header *prev;
union Header *next;
} d;
} Header;

static Header headBlock;
static Header headBlock = {.d.next = &headBlock, .d.prev = &headBlock};

#if !defined(EXTERNMEMCHECK)

Expand All @@ -112,6 +116,8 @@ static void freeblock (Memcontrol *mc, Header *block) {
if (block) {
size_t size = block->d.size;
int i;
block->d.next->d.prev = block->d.prev;
block->d.prev->d.next = block->d.next;
for (i = 0; i < MARKSIZE; i++) /* check marks after block */
lua_assert(*(cast(char *, block + 1) + size + i) == MARK);
mc->objcount[block->d.type]--;
Expand Down Expand Up @@ -165,6 +171,10 @@ void *debug_realloc (void *ud, void *b, size_t oldsize, size_t size) {
*(cast(char *, newblock + 1) + size + i) = MARK;
newblock->d.size = size;
newblock->d.type = type;
newblock->d.next = headBlock.d.next;
newblock->d.prev = &headBlock;
newblock->d.next->d.prev = newblock;
headBlock.d.next = newblock;
mc->total += size;
if (mc->total > mc->maxmem)
mc->maxmem = mc->total;
Expand Down Expand Up @@ -247,7 +257,6 @@ static void checktable (global_State *g, Table *h) {
static void checkproto (global_State *g, Proto *f) {
int i;
GCObject *fgc = obj2gco(f);
checkobjref(g, fgc, f->cache);
checkobjref(g, fgc, f->source);
for (i=0; i<f->sizek; i++) {
if (ttisstring(f->k + i))
Expand Down Expand Up @@ -465,7 +474,7 @@ static char *buildop (Proto *p, int pc, char *buff) {
Instruction i = p->code[pc];
OpCode o = GET_OPCODE(i);
const char *name = luaP_opnames[o];
int line = getfuncline(p, pc);
int line = luaG_getfuncline(NULL, p, pc);
sprintf(buff, "(%4d) %4d - ", line, pc);
switch (getOpMode(o)) {
case iABC:
Expand Down Expand Up @@ -850,30 +859,6 @@ static lua_State *getstate (lua_State *L) {


static int loadlib (lua_State *L) {
static const luaL_Reg libs[] = {
{"_G", luaopen_base},
{"coroutine", luaopen_coroutine},
{"debug", luaopen_debug},
{"io", luaopen_io},
{"os", luaopen_os},
{"math", luaopen_math},
{"string", luaopen_string},
{"table", luaopen_table},
{NULL, NULL}
};
lua_State *L1 = getstate(L);
int i;
luaL_requiref(L1, "package", luaopen_package, 0);
lua_assert(lua_type(L1, -1) == LUA_TTABLE);
/* 'requiref' should not reload module already loaded... */
luaL_requiref(L1, "package", NULL, 1); /* seg. fault if it reloads */
/* ...but should return the same module */
lua_assert(lua_compare(L1, -1, -2, LUA_OPEQ));
luaL_getsubtable(L1, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
for (i = 0; libs[i].name; i++) {
lua_pushcfunction(L1, libs[i].func);
lua_setfield(L1, -2, libs[i].name);
}
return 0;
}

Expand Down
7 changes: 4 additions & 3 deletions app/lua53/host/ltests.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
/* turn on assertions */
#undef NDEBUG
#include <assert.h>
#ifndef lua_assert
#define lua_assert(c) assert(c)

#endif

/* to avoid warnings, and to make sure value is really unused */
#define UNUSED(x) (x=0, (void)(x))
Expand Down Expand Up @@ -95,7 +96,7 @@ LUA_API int luaB_opentests (lua_State *L);
LUA_API void *debug_realloc (void *ud, void *block,
size_t osize, size_t nsize);

#if defined(lua_c)
#if defined(luac_c)
#define luaL_newstate() lua_newstate(debug_realloc, &l_memcontrol)
#define luaL_openlibs(L) \
{ (luaL_openlibs)(L); \
Expand All @@ -122,7 +123,7 @@ LUA_API void *debug_realloc (void *ud, void *block,
#define LUAI_USER_ALIGNMENT_T union { char b[sizeof(void*) * 8]; }


#define STRCACHE_N 23
#define STRCACHE_N 16
#define STRCACHE_M 5

#endif
Expand Down
Loading

0 comments on commit 1f75eaa

Please sign in to comment.