* add evil support and remove evil windows code

* correctly handle alloca include
 * remove trailing spaces


SVN revision: 34072
This commit is contained in:
doursse 2008-03-21 17:18:25 +00:00 committed by doursse
parent 7fe7199a0c
commit 53c0a2d01d
6 changed files with 79 additions and 147 deletions

View File

@ -35,11 +35,14 @@ AC_CHECK_FUNCS(gettimeofday)
create_shared_lib="" create_shared_lib=""
case "$host_os" in case "$host_os" in
mingw|mingw32) mingw|mingw32*|cegcc)
create_shared_lib="-no-undefined " PKG_CHECK_MODULES([EVIL], evil)
AC_DEFINE(HAVE_EVIL, 1, [Set to 1 if evil package is installed])
dnl needed for correct definition of EAPI
AC_DEFINE(EFL_EMBRYO_BUILD, 1, [Define to mention that embryo is built])
create_shared_lib="-no-undefined"
;; ;;
esac esac
AC_SUBST(create_shared_lib) AC_SUBST(create_shared_lib)
AC_CHECK_HEADERS(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file])) AC_CHECK_HEADERS(fnmatch.h,, AC_MSG_ERROR([Cannot find fnmatch.h. Make sure your CFLAGS environment variable contains include lines for the location of this file]))

View File

@ -8,7 +8,8 @@ AM_CPPFLAGS = \
-I$(top_builddir) \ -I$(top_builddir) \
-DPACKAGE_BIN_DIR=\"$(bindir)\" \ -DPACKAGE_BIN_DIR=\"$(bindir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \ -DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" -DPACKAGE_DATA_DIR=\"$(datadir)/$(PACKAGE)\" \
@EVIL_CFLAGS@
bin_PROGRAMS = embryo_cc bin_PROGRAMS = embryo_cc
@ -29,7 +30,7 @@ embryo_cc_scvars.c \
embryo_cc_prefix.c \ embryo_cc_prefix.c \
embryo_cc_prefix.h embryo_cc_prefix.h
embryo_cc_LDADD = -lm embryo_cc_LDADD = @EVIL_LIBS@ -lm
embryo_cc_DEPENDENCIES = embryo_cc_DEPENDENCIES =
EXTRA_DIST = \ EXTRA_DIST = \

View File

@ -17,93 +17,17 @@
#include <ctype.h> #include <ctype.h>
#include <time.h> #include <time.h>
#include <dirent.h> #include <dirent.h>
#ifdef _WIN32 #include <dlfcn.h> /* dlopen,dlclose,etc */
# define WIN32_LEAN_AND_MEAN #ifdef HAVE_EVIL
# include <windows.h> # include <evil.h> /* for realpath */
# undef WIN32_LEAN_AND_MEAN
# include <stdlib.h>
# include <stdio.h>
# include <errno.h>
#else #else
# include <dlfcn.h> /* dlopen,dlclose,etc */
# include <pwd.h> # include <pwd.h>
# include <grp.h> # include <grp.h>
# include <glob.h> # include <glob.h>
#endif /* _WIN32 */ #endif /* HAVE_E_WIN32 */
#include "embryo_cc_prefix.h" #include "embryo_cc_prefix.h"
/* FIXME: that hack is a temporary one. That code will be in MinGW soon */
#ifdef _WIN32
#define RTLD_LAZY 1 /* lazy function call binding */
#define RTLD_NOW 2 /* immediate function call binding */
#define RTLD_GLOBAL 4 /* symbols in this dlopen'ed obj are visible
to other dlopen'ed objs */
static char *dlerr_ptr;
static char dlerr_data[80];
void *dlopen (const char *file, int mode)
{
HMODULE hmodule;
hmodule = LoadLibrary(file);
if (hmodule == NULL) {
int error;
error = GetLastError();
sprintf(dlerr_data, "LoadLibraryEx returned %d.", error);
dlerr_ptr = dlerr_data;
}
return hmodule;
}
int dlclose (void *handle)
{
if (FreeLibrary(handle)) {
return 0;
}
else {
int error;
error = GetLastError();
sprintf(dlerr_data, "FreeLibrary returned %d.", error);
dlerr_ptr = dlerr_data;
return -1;
}
}
void *dlsym (void *handle, const char *name)
{
FARPROC fp;
fp = GetProcAddress(handle, name);
if (fp == NULL) {
int error;
error = GetLastError();
sprintf(dlerr_data, "GetProcAddress returned %d.", error);
dlerr_ptr = dlerr_data;
}
return fp;
}
char *dlerror (void)
{
if (dlerr_ptr != NULL) {
dlerr_ptr = NULL;
return dlerr_data;
}
else {
return NULL;
}
}
#define realpath(file_name, resolved_name) _fullpath((resolved_name), (file_name), PATH_MAX)
#endif /* _WIN32 */
/* local subsystem functions */ /* local subsystem functions */
static int _e_prefix_share_hunt(void); static int _e_prefix_share_hunt(void);
static int _e_prefix_fallbacks(void); static int _e_prefix_fallbacks(void);

View File

@ -20,7 +20,7 @@
* 2. Altered source versions must be plainly marked as such, and * 2. Altered source versions must be plainly marked as such, and
* must not be misrepresented as being the original software. * must not be misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
* Version: $Id$ * Version: $Id$
*/ */
@ -36,12 +36,9 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifdef _WIN32 #ifdef HAVE_EVIL
# include <fcntl.h> # include <evil.h>
# include <io.h> #endif /* HAVE_EVIL */
# include <share.h>
# include <sys/stat.h>
#endif /* _WIN32 */
#include "embryo_cc_osdefs.h" #include "embryo_cc_osdefs.h"
#include "embryo_cc_sc.h" #include "embryo_cc_sc.h"
@ -143,7 +140,7 @@ main(int argc, char *argv[], char *env[])
snprintf(argv0, _MAX_PATH, "%s/%s", pwd, argv[0]); snprintf(argv0, _MAX_PATH, "%s/%s", pwd, argv[0]);
} /* if */ } /* if */
argv[0] = argv0; /* set location to new first parameter */ argv[0] = argv0; /* set location to new first parameter */
e_prefix_determine(argv0); e_prefix_determine(argv0);
return sc_compile(argc, argv); return sc_compile(argc, argv);
@ -318,30 +315,15 @@ sc_compile(int argc, char *argv[])
/* open the output file */ /* open the output file */
#ifndef _WIN32 #ifndef HAVE_EVIL
tmpdir = getenv("TMPDIR"); tmpdir = getenv("TMPDIR");
if (!tmpdir) tmpdir = "/tmp"; if (!tmpdir) tmpdir = "/tmp";
#else
tmpdir = evil_tmpdir_get();
#endif /* ! HAVE_EVIL */
snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir); snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
fd_out = mkstemp(outfname); fd_out = mkstemp(outfname);
#else
tmpdir = getenv("TMP");
if (!tmpdir) tmpdir = getenv("TEMP");
if (!tmpdir) tmpdir = getenv("USERPROFILE");
if (!tmpdir) tmpdir = getenv("WINDIR");
if (!tmpdir) error(101, "embryo_cc.asm-tmp-XXXXXX (unable to get a valid temp path)");
snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
# ifdef __MINGW32__
if (!mktemp(outfname))
error(101, outfname);
fd_out = _sopen(outfname, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
# else
if (_mktemp_s(outfname, _MAX_PATH))
error(101, outfname);
_sopen_s(&fd_out, outfname, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, _S_IREAD | _S_IWRITE);
# endif /* __MINGW32__ */
#endif /* _WIN32 */
if (fd_out < 0) if (fd_out < 0)
error(101, outfname); error(101, outfname);
@ -706,10 +688,10 @@ setconfig(char *root)
if ((ptr = strrchr(path, DIRSEP_CHAR)) != NULL if ((ptr = strrchr(path, DIRSEP_CHAR)) != NULL
|| (ptr = strchr(path, ':')) != NULL) || (ptr = strchr(path, ':')) != NULL)
{ {
/* If there was no terminating "\" or ":", /* If there was no terminating "\" or ":",
* the filename probably does not * the filename probably does not
* contain the path; so we just don't add it * contain the path; so we just don't add it
* to the list in that case * to the list in that case
*/ */
*(ptr + 1) = '\0'; *(ptr + 1) = '\0';
if (strlen(path) < (sizeof(path) - 1 - 7)) if (strlen(path) < (sizeof(path) - 1 - 7))
@ -2139,7 +2121,7 @@ funcstub(int native)
/* "declargs()" found the ")" */ /* "declargs()" found the ")" */
if (!operatoradjust(opertok, sym, symbolname, tag)) if (!operatoradjust(opertok, sym, symbolname, tag))
sym->usage &= ~uDEFINE; sym->usage &= ~uDEFINE;
/* for a native operator, also need to specify an "exported" /* for a native operator, also need to specify an "exported"
* function name; for a native function, this is optional * function name; for a native function, this is optional
*/ */
if (native) if (native)
@ -2406,7 +2388,7 @@ argcompare(arginfo * a1, arginfo * a2)
result = a1->numdim == a2->numdim; result = a1->numdim == a2->numdim;
for (level = 0; result && level < a1->numdim; level++) for (level = 0; result && level < a1->numdim; level++)
result = a1->dim[level] == a2->dim[level]; result = a1->dim[level] == a2->dim[level];
/* ??? should also check contents of the default array /* ??? should also check contents of the default array
* (these troubles go away in a 2-pass compiler that forbids * (these troubles go away in a 2-pass compiler that forbids
* double declarations, but Small currently does not forbid them) * double declarations, but Small currently does not forbid them)
*/ */
@ -2433,8 +2415,8 @@ argcompare(arginfo * a1, arginfo * a2)
/* declargs() /* declargs()
* *
* This routine adds an entry in the local symbol table for each * This routine adds an entry in the local symbol table for each
* argument found in the argument list. * argument found in the argument list.
* It returns the number of arguments. * It returns the number of arguments.
*/ */
static int static int
@ -2537,7 +2519,7 @@ declargs(symbol * sym)
if (sym->dim.arglist == 0) if (sym->dim.arglist == 0)
error(103); /* insufficient memory */ error(103); /* insufficient memory */
sym->dim.arglist[argcnt] = arg; sym->dim.arglist[argcnt] = arg;
sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list
* terminated */ * terminated */
} }
else else
@ -2573,7 +2555,7 @@ declargs(symbol * sym)
(argcnt + 2) * sizeof(arginfo)); (argcnt + 2) * sizeof(arginfo));
if (sym->dim.arglist == 0) if (sym->dim.arglist == 0)
error(103); /* insufficient memory */ error(103); /* insufficient memory */
sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list sym->dim.arglist[argcnt + 1].ident = 0; /* keep the list
* terminated */ * terminated */
sym->dim.arglist[argcnt].ident = iVARARGS; sym->dim.arglist[argcnt].ident = iVARARGS;
sym->dim.arglist[argcnt].hasdefault = FALSE; sym->dim.arglist[argcnt].hasdefault = FALSE;
@ -2614,7 +2596,7 @@ declargs(symbol * sym)
int altidx; int altidx;
/* Find the argument with the name mentioned after the "sizeof". /* Find the argument with the name mentioned after the "sizeof".
* Note that we cannot use findloc here because we need the * Note that we cannot use findloc here because we need the
* arginfo struct, not the symbol. * arginfo struct, not the symbol.
*/ */
ptr = arglist[idx].defvalue.size.symname; ptr = arglist[idx].defvalue.size.symname;
@ -2704,7 +2686,7 @@ doarg(char *name, int ident, int offset, int tags[], int numtags,
lexpush(); /* initials() needs the "=" token again */ lexpush(); /* initials() needs the "=" token again */
assert(numtags > 0); assert(numtags > 0);
/* for the moment, when a default value is given for the array, /* for the moment, when a default value is given for the array,
* all dimension sizes, except the last, must be non-zero * all dimension sizes, except the last, must be non-zero
* (function initials() requires to know the major dimensions) * (function initials() requires to know the major dimensions)
*/ */
for (level = 0; level < arg->numdim - 1; level++) for (level = 0; level < arg->numdim - 1; level++)
@ -2813,7 +2795,7 @@ doarg(char *name, int ident, int offset, int tags[], int numtags,
if (ident == iREFERENCE) if (ident == iREFERENCE)
argsym->usage |= uREAD; /* because references are passed back */ argsym->usage |= uREAD; /* because references are passed back */
if (fpublic) if (fpublic)
argsym->usage |= uREAD; /* arguments of public functions argsym->usage |= uREAD; /* arguments of public functions
* are always "used" */ * are always "used" */
if (fconst) if (fconst)
argsym->usage |= uCONST; argsym->usage |= uCONST;
@ -3182,8 +3164,8 @@ add_constant(char *name, cell val, int vclass, int tag)
/* statement - The Statement Parser /* statement - The Statement Parser
* *
* This routine is called whenever the parser needs to know what * This routine is called whenever the parser needs to know what
* statement it encounters (i.e. whenever program syntax requires a * statement it encounters (i.e. whenever program syntax requires a
* statement). * statement).
*/ */
static void static void
@ -3206,11 +3188,11 @@ statement(int *lastindent, int allow_decl)
/* lex() has set stmtindent */ /* lex() has set stmtindent */
if (lastindent != NULL && tok != tLABEL) if (lastindent != NULL && tok != tLABEL)
{ {
#if 0 #if 0
if (*lastindent >= 0 && *lastindent != stmtindent && if (*lastindent >= 0 && *lastindent != stmtindent &&
!indent_nowarn && sc_tabsize > 0) !indent_nowarn && sc_tabsize > 0)
error(217); /* loose indentation */ error(217); /* loose indentation */
#endif #endif
*lastindent = stmtindent; *lastindent = stmtindent;
indent_nowarn = TRUE; /* if warning was blocked, re-enable it */ indent_nowarn = TRUE; /* if warning was blocked, re-enable it */
} /* if */ } /* if */
@ -3534,10 +3516,10 @@ doif(void)
{ {
/* to avoid the "dangling else" error, we want a warning if the "else" /* to avoid the "dangling else" error, we want a warning if the "else"
* has a lower indent than the matching "if" */ * has a lower indent than the matching "if" */
#if 0 #if 0
if (stmtindent < ifindent && sc_tabsize > 0) if (stmtindent < ifindent && sc_tabsize > 0)
error(217); /* loose indentation */ error(217); /* loose indentation */
#endif #endif
flab2 = getlabel(); flab2 = getlabel();
if ((lastst != tRETURN) && (lastst != tGOTO)) if ((lastst != tRETURN) && (lastst != tGOTO))
jumplabel(flab2); jumplabel(flab2);
@ -3632,7 +3614,7 @@ dofor(void)
setlabel(wq[wqLOOP]); /* "continue" goes to this label: expr3 */ setlabel(wq[wqLOOP]); /* "continue" goes to this label: expr3 */
setline(fline, fcurrent); setline(fline, fcurrent);
/* Expressions 2 and 3 are reversed in the generated code: /* Expressions 2 and 3 are reversed in the generated code:
* expression 3 precedes expression 2. * expression 3 precedes expression 2.
* When parsing, the code is buffered and marks for * When parsing, the code is buffered and marks for
* the start of each expression are insterted in the buffer. * the start of each expression are insterted in the buffer.
*/ */
@ -3646,7 +3628,7 @@ dofor(void)
setlabel(skiplab); /*jump to this point after 1st expression */ setlabel(skiplab); /*jump to this point after 1st expression */
if (matchtoken(';') == 0) if (matchtoken(';') == 0)
{ {
test(wq[wqEXIT], FALSE, FALSE); /* expression 2 test(wq[wqEXIT], FALSE, FALSE); /* expression 2
*(jump to wq[wqEXIT] if false) */ *(jump to wq[wqEXIT] if false) */
needtoken(';'); needtoken(';');
} /* if */ } /* if */
@ -3753,7 +3735,7 @@ doswitch(void)
/* nothing */ ; /* nothing */ ;
if (cse != NULL && cse->value == val) if (cse != NULL && cse->value == val)
error(40, val); /* duplicate "case" label */ error(40, val); /* duplicate "case" label */
/* Since the label is stored as a string in the /* Since the label is stored as a string in the
* "constvalue", the size of an identifier must * "constvalue", the size of an identifier must
* be at least 8, as there are 8 * be at least 8, as there are 8
* hexadecimal digits in a 32-bit number. * hexadecimal digits in a 32-bit number.

View File

@ -2,14 +2,19 @@
#define _EMBRYO_H #define _EMBRYO_H
#ifdef EAPI #ifdef EAPI
#undef EAPI # undef EAPI
#endif #endif
#ifdef _MSC_VER
# ifdef BUILDING_DLL #ifdef _WIN32
# define EAPI __declspec(dllexport) # ifdef EFL_EMBRYO_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif /* ! DLL_EXPORT */
# else # else
# define EAPI __declspec(dllimport) # define EAPI __declspec(dllimport)
# endif # endif /* ! EFL_EMBRYO_BUILD */
#else #else
# ifdef __GNUC__ # ifdef __GNUC__
# if __GNUC__ >= 4 # if __GNUC__ >= 4
@ -20,7 +25,7 @@
# else # else
# define EAPI # define EAPI
# endif # endif
#endif #endif /* ! _WIN32 */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -43,7 +48,7 @@ extern "C" {
EMBRYO_ERROR_NATIVE, /** Native function failed */ EMBRYO_ERROR_NATIVE, /** Native function failed */
EMBRYO_ERROR_DIVIDE, /** Divide by zero */ EMBRYO_ERROR_DIVIDE, /** Divide by zero */
EMBRYO_ERROR_SLEEP, /** Go into sleepmode - code can be restarted */ EMBRYO_ERROR_SLEEP, /** Go into sleepmode - code can be restarted */
EMBRYO_ERROR_MEMORY = 16, /** Out of memory */ EMBRYO_ERROR_MEMORY = 16, /** Out of memory */
EMBRYO_ERROR_FORMAT, /** Invalid file format */ EMBRYO_ERROR_FORMAT, /** Invalid file format */
EMBRYO_ERROR_VERSION, /** File is for a newer version of the Embryo_Program */ EMBRYO_ERROR_VERSION, /** File is for a newer version of the Embryo_Program */
@ -62,7 +67,7 @@ extern "C" {
#define EMBRYO_FUNCTION_MAIN -1 /* Start at program entry point */ #define EMBRYO_FUNCTION_MAIN -1 /* Start at program entry point */
#define EMBRYO_FUNCTION_CONT -2 /* Continue from last address */ #define EMBRYO_FUNCTION_CONT -2 /* Continue from last address */
/** An invalid cell reference */ /** An invalid cell reference */
#define EMBRYO_CELL_NONE 0x7fffffff #define EMBRYO_CELL_NONE 0x7fffffff
/* program run return values */ /* program run return values */
#define EMBRYO_PROGRAM_OK 1 #define EMBRYO_PROGRAM_OK 1
#define EMBRYO_PROGRAM_SLEEP 2 #define EMBRYO_PROGRAM_SLEEP 2
@ -85,10 +90,10 @@ extern "C" {
#define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c #define EMBRYO_FLOAT_TO_CELL(f) ((Embryo_Float_Cell) f).c
/** Embryo_Cell to float */ /** Embryo_Cell to float */
#define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f #define EMBRYO_CELL_TO_FLOAT(c) ((Embryo_Float_Cell) c).f
EAPI int embryo_init(void); EAPI int embryo_init(void);
EAPI int embryo_shutdown(void); EAPI int embryo_shutdown(void);
EAPI Embryo_Program *embryo_program_new(void *data, int size); EAPI Embryo_Program *embryo_program_new(void *data, int size);
EAPI Embryo_Program *embryo_program_const_new(void *data, int size); EAPI Embryo_Program *embryo_program_const_new(void *data, int size);
EAPI Embryo_Program *embryo_program_load(char *file); EAPI Embryo_Program *embryo_program_load(char *file);
@ -122,9 +127,9 @@ extern "C" {
EAPI int embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell); EAPI int embryo_parameter_cell_push(Embryo_Program *ep, Embryo_Cell cell);
EAPI int embryo_parameter_string_push(Embryo_Program *ep, const char *str); EAPI int embryo_parameter_string_push(Embryo_Program *ep, const char *str);
EAPI int embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num); EAPI int embryo_parameter_cell_array_push(Embryo_Program *ep, Embryo_Cell *cells, int num);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif #endif

View File

@ -8,12 +8,29 @@
#include <limits.h> #include <limits.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#if HAVE_ALLOCA_H
#include <alloca.h> #ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_ALLOCA_H
# include <alloca.h>
#elif defined __GNUC__
# define alloca __builtin_alloca
#elif defined _AIX
# define alloca __alloca
#elif defined _MSC_VER
# include <malloc.h>
# define alloca _alloca
#else
# include <stddef.h>
# ifdef __cplusplus
extern "C"
# endif
void *alloca (size_t);
#endif #endif
#include "Embryo.h" #include "Embryo.h"
#include "config.h"
#ifdef __GNUC__ #ifdef __GNUC__
# if __GNUC__ >= 4 # if __GNUC__ >= 4