Merge branch 'calli-4'
This commit is contained in:
commit
27c3866b90
@ -42,6 +42,7 @@ binary = SM.Program(builder, 'spcomp')
|
||||
compiler = binary.compiler
|
||||
compiler.includes += [
|
||||
os.path.join(builder.sourcePath, 'public'),
|
||||
os.path.join(builder.sourcePath, 'public', 'amtl'),
|
||||
os.path.join(builder.sourcePath, 'public', 'sourcepawn'),
|
||||
os.path.join(builder.sourcePath, 'sourcepawn', 'compiler'),
|
||||
os.path.join(builder.buildPath, 'includes'),
|
||||
@ -50,7 +51,8 @@ compiler.includes += [
|
||||
compiler.sourcedeps += packed_includes
|
||||
|
||||
if compiler.cc.behavior == 'gcc':
|
||||
compiler.cflags += ['-std=c99', '-Wno-format']
|
||||
compiler.cflags += ['-Wno-format']
|
||||
compiler.c_only_flags += ['-std=c99']
|
||||
if builder.target_platform == 'linux':
|
||||
compiler.postlink += ['-lgcc', '-lm']
|
||||
elif compiler.cc.behavior == 'msvc':
|
||||
@ -76,25 +78,25 @@ elif builder.target_platform == 'mac':
|
||||
]
|
||||
|
||||
binary.sources += [
|
||||
'libpawnc.c',
|
||||
'lstring.c',
|
||||
'memfile.c',
|
||||
'pawncc.c',
|
||||
'sc1.c',
|
||||
'sc2.c',
|
||||
'sc3.c',
|
||||
'sc4.c',
|
||||
'sc5.c',
|
||||
'sc6.c',
|
||||
'sc7.c',
|
||||
'scexpand.c',
|
||||
'sci18n.c',
|
||||
'sclist.c',
|
||||
'scmemfil.c',
|
||||
'scstate.c',
|
||||
'sctracker.c',
|
||||
'scvars.c',
|
||||
'sp_file.c',
|
||||
'libpawnc.cpp',
|
||||
'lstring.cpp',
|
||||
'memfile.cpp',
|
||||
'pawncc.cpp',
|
||||
'sc1.cpp',
|
||||
'sc2.cpp',
|
||||
'sc3.cpp',
|
||||
'sc4.cpp',
|
||||
'sc5.cpp',
|
||||
'sc6.cpp',
|
||||
'sc7.cpp',
|
||||
'scexpand.cpp',
|
||||
'sci18n.cpp',
|
||||
'sclist.cpp',
|
||||
'scmemfil.cpp',
|
||||
'scstate.cpp',
|
||||
'sctracker.cpp',
|
||||
'scvars.cpp',
|
||||
'sp_file.cpp',
|
||||
'zlib/adler32.c',
|
||||
'zlib/compress.c',
|
||||
'zlib/crc32.c',
|
||||
@ -107,7 +109,7 @@ binary.sources += [
|
||||
'zlib/trees.c',
|
||||
'zlib/uncompr.c',
|
||||
'zlib/zutil.c',
|
||||
'sp_symhash.c'
|
||||
'sp_symhash.cpp'
|
||||
]
|
||||
if builder.target_platform != 'windows':
|
||||
binary.sources.append('binreloc.c')
|
||||
|
@ -1,173 +1,173 @@
|
||||
/* Abstract Machine for the Pawn compiler, debugger support
|
||||
*
|
||||
* This file contains extra definitions that are convenient for debugger
|
||||
* support.
|
||||
*
|
||||
* Copyright (c) ITB CompuPhase, 2005
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#ifndef AMXDBG_H_INCLUDED
|
||||
#define AMXDBG_H_INCLUDED
|
||||
|
||||
#ifndef AMX_H_INCLUDED
|
||||
#include "amx.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Some compilers do not support the #pragma align, which should be fine. Some
|
||||
* compilers give a warning on unknown #pragmas, which is not so fine...
|
||||
*/
|
||||
#if defined SN_TARGET_PS2 || defined __GNUC__
|
||||
#define AMX_NO_ALIGN
|
||||
#endif
|
||||
|
||||
#if defined __GNUC__
|
||||
#define PACKED __attribute__((packed))
|
||||
#else
|
||||
#define PACKED
|
||||
#endif
|
||||
|
||||
#if !defined AMX_NO_ALIGN
|
||||
#if defined LINUX || defined __FreeBSD__
|
||||
#pragma pack(1) /* structures must be packed (byte-aligned) */
|
||||
#elif defined MACOS && defined __MWERKS__
|
||||
#pragma options align=mac68k
|
||||
#else
|
||||
#pragma pack(push)
|
||||
#pragma pack(1) /* structures must be packed (byte-aligned) */
|
||||
#if defined __TURBOC__
|
||||
#pragma option -a- /* "pack" pragma for older Borland compilers */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct tagAMX_DBG_HDR {
|
||||
int32_t size PACKED; /* size of the debug information chunk */
|
||||
uint16_t magic PACKED; /* signature, must be 0xf1ef */
|
||||
char file_version; /* file format version */
|
||||
char amx_version; /* required version of the AMX */
|
||||
int16_t flags PACKED; /* currently unused */
|
||||
int16_t files PACKED; /* number of entries in the "file" table */
|
||||
int32_t lines PACKED; /* number of entries in the "line" table */
|
||||
int32_t symbols PACKED; /* number of entries in the "symbol" table */
|
||||
int16_t tags PACKED; /* number of entries in the "tag" table */
|
||||
int16_t automatons PACKED; /* number of entries in the "automaton" table */
|
||||
int16_t states PACKED; /* number of entries in the "state" table */
|
||||
} PACKED AMX_DBG_HDR;
|
||||
#define AMX_DBG_MAGIC 0xf1ef
|
||||
|
||||
typedef struct tagAMX_DBG_FILE {
|
||||
ucell address PACKED; /* address in the code segment where generated code (for this file) starts */
|
||||
const char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_FILE;
|
||||
|
||||
typedef struct tagAMX_DBG_LINE {
|
||||
ucell address PACKED; /* address in the code segment where generated code (for this line) starts */
|
||||
int32_t line PACKED; /* line number */
|
||||
} PACKED AMX_DBG_LINE;
|
||||
|
||||
typedef struct tagAMX_DBG_SYMBOL {
|
||||
ucell address PACKED; /* address in the data segment or relative to the frame */
|
||||
int16_t tag PACKED; /* tag for the symbol */
|
||||
ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */
|
||||
ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */
|
||||
char ident; /* kind of symbol (function/variable) */
|
||||
char vclass; /* class of symbol (global/local) */
|
||||
int16_t dim PACKED; /* number of dimensions */
|
||||
const char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_SYMBOL;
|
||||
|
||||
typedef struct tagAMX_DBG_SYMDIM {
|
||||
int16_t tag PACKED; /* tag for the array dimension */
|
||||
ucell size PACKED; /* size of the array dimension */
|
||||
} PACKED AMX_DBG_SYMDIM;
|
||||
|
||||
typedef struct tagAMX_DBG_TAG {
|
||||
int16_t tag PACKED; /* tag id */
|
||||
const char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_TAG;
|
||||
|
||||
typedef struct tagAMX_DBG_MACHINE {
|
||||
int16_t automaton PACKED; /* automaton id */
|
||||
ucell address PACKED; /* address of state variable */
|
||||
const char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_MACHINE;
|
||||
|
||||
typedef struct tagAMX_DBG_STATE {
|
||||
int16_t state PACKED; /* state id */
|
||||
int16_t automaton PACKED; /* automaton id */
|
||||
const char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_STATE;
|
||||
|
||||
typedef struct tagAMX_DBG {
|
||||
AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */
|
||||
AMX_DBG_FILE _FAR **filetbl PACKED;
|
||||
AMX_DBG_LINE _FAR *linetbl PACKED;
|
||||
AMX_DBG_SYMBOL _FAR **symboltbl PACKED;
|
||||
AMX_DBG_TAG _FAR **tagtbl PACKED;
|
||||
AMX_DBG_MACHINE _FAR **automatontbl PACKED;
|
||||
AMX_DBG_STATE _FAR **statetbl PACKED;
|
||||
} PACKED AMX_DBG;
|
||||
|
||||
#if !defined iVARIABLE
|
||||
#define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */
|
||||
#define iREFERENCE 2 /* iVARIABLE, but must be dereferenced */
|
||||
#define iARRAY 3
|
||||
#define iREFARRAY 4 /* an array passed by reference (i.e. a pointer) */
|
||||
#define iFUNCTN 9
|
||||
#endif
|
||||
|
||||
|
||||
int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg);
|
||||
int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, void *dbg_addr);
|
||||
|
||||
int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename);
|
||||
int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname);
|
||||
int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line);
|
||||
|
||||
int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address);
|
||||
int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address);
|
||||
int AMXAPI dbg_GetAutomatonName(AMX_DBG *amxdbg, int automaton, const char **name);
|
||||
int AMXAPI dbg_GetStateName(AMX_DBG *amxdbg, int state, const char **name);
|
||||
int AMXAPI dbg_GetTagName(AMX_DBG *amxdbg, int tag, const char **name);
|
||||
int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr, const AMX_DBG_SYMBOL **sym);
|
||||
int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX_DBG_SYMDIM **symdim);
|
||||
|
||||
|
||||
#if !defined AMX_NO_ALIGN
|
||||
#if defined LINUX || defined __FreeBSD__
|
||||
#pragma pack() /* reset default packing */
|
||||
#elif defined MACOS && defined __MWERKS__
|
||||
#pragma options align=reset
|
||||
#else
|
||||
#pragma pack(pop) /* reset previous packing */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AMXDBG_H_INCLUDED */
|
||||
|
||||
/* Abstract Machine for the Pawn compiler, debugger support
|
||||
*
|
||||
* This file contains extra definitions that are convenient for debugger
|
||||
* support.
|
||||
*
|
||||
* Copyright (c) ITB CompuPhase, 2005
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
#ifndef AMXDBG_H_INCLUDED
|
||||
#define AMXDBG_H_INCLUDED
|
||||
|
||||
#ifndef AMX_H_INCLUDED
|
||||
#include "amx.h"
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Some compilers do not support the #pragma align, which should be fine. Some
|
||||
* compilers give a warning on unknown #pragmas, which is not so fine...
|
||||
*/
|
||||
#if defined SN_TARGET_PS2 || defined __GNUC__
|
||||
#define AMX_NO_ALIGN
|
||||
#endif
|
||||
|
||||
#if defined __GNUC__
|
||||
#define PACKED __attribute__((packed))
|
||||
#else
|
||||
#define PACKED
|
||||
#endif
|
||||
|
||||
#if !defined AMX_NO_ALIGN
|
||||
#if defined LINUX || defined __FreeBSD__
|
||||
#pragma pack(1) /* structures must be packed (byte-aligned) */
|
||||
#elif defined MACOS && defined __MWERKS__
|
||||
#pragma options align=mac68k
|
||||
#else
|
||||
#pragma pack(push)
|
||||
#pragma pack(1) /* structures must be packed (byte-aligned) */
|
||||
#if defined __TURBOC__
|
||||
#pragma option -a- /* "pack" pragma for older Borland compilers */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct tagAMX_DBG_HDR {
|
||||
int32_t size PACKED; /* size of the debug information chunk */
|
||||
uint16_t magic PACKED; /* signature, must be 0xf1ef */
|
||||
char file_version; /* file format version */
|
||||
char amx_version; /* required version of the AMX */
|
||||
int16_t flags PACKED; /* currently unused */
|
||||
int16_t files PACKED; /* number of entries in the "file" table */
|
||||
int32_t lines PACKED; /* number of entries in the "line" table */
|
||||
int32_t symbols PACKED; /* number of entries in the "symbol" table */
|
||||
int16_t tags PACKED; /* number of entries in the "tag" table */
|
||||
int16_t automatons PACKED; /* number of entries in the "automaton" table */
|
||||
int16_t states PACKED; /* number of entries in the "state" table */
|
||||
} PACKED AMX_DBG_HDR;
|
||||
#define AMX_DBG_MAGIC 0xf1ef
|
||||
|
||||
typedef struct tagAMX_DBG_FILE {
|
||||
ucell address PACKED; /* address in the code segment where generated code (for this file) starts */
|
||||
char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_FILE;
|
||||
|
||||
typedef struct tagAMX_DBG_LINE {
|
||||
ucell address PACKED; /* address in the code segment where generated code (for this line) starts */
|
||||
int32_t line PACKED; /* line number */
|
||||
} PACKED AMX_DBG_LINE;
|
||||
|
||||
typedef struct tagAMX_DBG_SYMBOL {
|
||||
ucell address PACKED; /* address in the data segment or relative to the frame */
|
||||
int16_t tag PACKED; /* tag for the symbol */
|
||||
ucell codestart PACKED; /* address in the code segment from which this symbol is valid (in scope) */
|
||||
ucell codeend PACKED; /* address in the code segment until which this symbol is valid (in scope) */
|
||||
char ident; /* kind of symbol (function/variable) */
|
||||
char vclass; /* class of symbol (global/local) */
|
||||
int16_t dim PACKED; /* number of dimensions */
|
||||
char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_SYMBOL;
|
||||
|
||||
typedef struct tagAMX_DBG_SYMDIM {
|
||||
int16_t tag PACKED; /* tag for the array dimension */
|
||||
ucell size PACKED; /* size of the array dimension */
|
||||
} PACKED AMX_DBG_SYMDIM;
|
||||
|
||||
typedef struct tagAMX_DBG_TAG {
|
||||
int16_t tag PACKED; /* tag id */
|
||||
char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_TAG;
|
||||
|
||||
typedef struct tagAMX_DBG_MACHINE {
|
||||
int16_t automaton PACKED; /* automaton id */
|
||||
ucell address PACKED; /* address of state variable */
|
||||
char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_MACHINE;
|
||||
|
||||
typedef struct tagAMX_DBG_STATE {
|
||||
int16_t state PACKED; /* state id */
|
||||
int16_t automaton PACKED; /* automaton id */
|
||||
char name[1]; /* ASCII string, zero-terminated */
|
||||
} PACKED AMX_DBG_STATE;
|
||||
|
||||
typedef struct tagAMX_DBG {
|
||||
AMX_DBG_HDR _FAR *hdr PACKED; /* points to the AMX_DBG header */
|
||||
AMX_DBG_FILE _FAR **filetbl PACKED;
|
||||
AMX_DBG_LINE _FAR *linetbl PACKED;
|
||||
AMX_DBG_SYMBOL _FAR **symboltbl PACKED;
|
||||
AMX_DBG_TAG _FAR **tagtbl PACKED;
|
||||
AMX_DBG_MACHINE _FAR **automatontbl PACKED;
|
||||
AMX_DBG_STATE _FAR **statetbl PACKED;
|
||||
} PACKED AMX_DBG;
|
||||
|
||||
#if !defined iVARIABLE
|
||||
#define iVARIABLE 1 /* cell that has an address and that can be fetched directly (lvalue) */
|
||||
#define iREFERENCE 2 /* iVARIABLE, but must be dereferenced */
|
||||
#define iARRAY 3
|
||||
#define iREFARRAY 4 /* an array passed by reference (i.e. a pointer) */
|
||||
#define iFUNCTN 9
|
||||
#endif
|
||||
|
||||
|
||||
int AMXAPI dbg_FreeInfo(AMX_DBG *amxdbg);
|
||||
int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, void *dbg_addr);
|
||||
|
||||
int AMXAPI dbg_LookupFile(AMX_DBG *amxdbg, ucell address, const char **filename);
|
||||
int AMXAPI dbg_LookupFunction(AMX_DBG *amxdbg, ucell address, const char **funcname);
|
||||
int AMXAPI dbg_LookupLine(AMX_DBG *amxdbg, ucell address, long *line);
|
||||
|
||||
int AMXAPI dbg_GetFunctionAddress(AMX_DBG *amxdbg, const char *funcname, const char *filename, ucell *address);
|
||||
int AMXAPI dbg_GetLineAddress(AMX_DBG *amxdbg, long line, const char *filename, ucell *address);
|
||||
int AMXAPI dbg_GetAutomatonName(AMX_DBG *amxdbg, int automaton, const char **name);
|
||||
int AMXAPI dbg_GetStateName(AMX_DBG *amxdbg, int state, const char **name);
|
||||
int AMXAPI dbg_GetTagName(AMX_DBG *amxdbg, int tag, const char **name);
|
||||
int AMXAPI dbg_GetVariable(AMX_DBG *amxdbg, const char *symname, ucell scopeaddr, const AMX_DBG_SYMBOL **sym);
|
||||
int AMXAPI dbg_GetArrayDim(AMX_DBG *amxdbg, const AMX_DBG_SYMBOL *sym, const AMX_DBG_SYMDIM **symdim);
|
||||
|
||||
|
||||
#if !defined AMX_NO_ALIGN
|
||||
#if defined LINUX || defined __FreeBSD__
|
||||
#pragma pack() /* reset default packing */
|
||||
#elif defined MACOS && defined __MWERKS__
|
||||
#pragma options align=reset
|
||||
#else
|
||||
#pragma pack(pop) /* reset previous packing */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* AMXDBG_H_INCLUDED */
|
||||
|
||||
|
@ -1,409 +0,0 @@
|
||||
// vim: set sts=8 ts=4 sw=4 tw=99 noet:
|
||||
/* LIBPAWNC.C
|
||||
*
|
||||
* A "glue file" for building the Pawn compiler as a DLL or shared library.
|
||||
*
|
||||
* Copyright (c) ITB CompuPhase, 2000-2006
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sc.h"
|
||||
#include "memfile.h"
|
||||
|
||||
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined DARWIN
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
/* pc_printf()
|
||||
* Called for general purpose "console" output. This function prints general
|
||||
* purpose messages; errors go through pc_error(). The function is modelled
|
||||
* after printf().
|
||||
*/
|
||||
int pc_printf(const char *message,...)
|
||||
{
|
||||
int ret;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr,message);
|
||||
ret=vprintf(message,argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* pc_error()
|
||||
* Called for producing error output.
|
||||
* number the error number (as documented in the manual)
|
||||
* message a string describing the error with embedded %d and %s tokens
|
||||
* filename the name of the file currently being parsed
|
||||
* firstline the line number at which the expression started on which
|
||||
* the error was found, or -1 if there is no "starting line"
|
||||
* lastline the line number at which the error was detected
|
||||
* argptr a pointer to the first of a series of arguments (for macro
|
||||
* "va_arg")
|
||||
* Return:
|
||||
* If the function returns 0, the parser attempts to continue compilation.
|
||||
* On a non-zero return value, the parser aborts.
|
||||
*/
|
||||
int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr)
|
||||
{
|
||||
static char *prefix[3]={ "error", "fatal error", "warning" };
|
||||
|
||||
if (number!=0) {
|
||||
char *pre;
|
||||
int idx;
|
||||
|
||||
if (number < 160)
|
||||
idx = 0;
|
||||
else if (number < 200)
|
||||
idx = 1;
|
||||
else
|
||||
idx = 2;
|
||||
|
||||
pre=prefix[idx];
|
||||
if (firstline>=0)
|
||||
fprintf(stdout,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number);
|
||||
else
|
||||
fprintf(stdout,"%s(%d) : %s %03d: ",filename,lastline,pre,number);
|
||||
} /* if */
|
||||
vfprintf(stdout,message,argptr);
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct src_file_s {
|
||||
FILE *fp; // Set if writing.
|
||||
char *buffer; // IO buffer.
|
||||
char *pos; // IO position.
|
||||
char *end; // End of buffer.
|
||||
size_t maxlength; // Maximum length of the writable buffer.
|
||||
} src_file_t;
|
||||
|
||||
/* pc_opensrc()
|
||||
* Opens a source file (or include file) for reading. The "file" does not have
|
||||
* to be a physical file, one might compile from memory.
|
||||
* filename the name of the "file" to read from
|
||||
* Return:
|
||||
* The function must return a pointer, which is used as a "magic cookie" to
|
||||
* all I/O functions. When failing to open the file for reading, the
|
||||
* function must return NULL.
|
||||
* Note:
|
||||
* Several "source files" may be open at the same time. Specifically, one
|
||||
* file can be open for reading and another for writing.
|
||||
*/
|
||||
void *pc_opensrc(char *filename)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
long length;
|
||||
src_file_t *src = NULL;
|
||||
|
||||
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined DARWIN
|
||||
struct stat fileInfo;
|
||||
if (stat(filename, &fileInfo) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (S_ISDIR(fileInfo.st_mode)) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(filename, "rb")) == NULL)
|
||||
return NULL;
|
||||
if (fseek(fp, 0, SEEK_END) == -1)
|
||||
goto err;
|
||||
if ((length = ftell(fp)) == -1)
|
||||
goto err;
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
goto err;
|
||||
|
||||
if ((src = (src_file_t *)calloc(1, sizeof(src_file_t))) == NULL)
|
||||
goto err;
|
||||
if ((src->buffer = (char *)calloc(length, sizeof(char))) == NULL)
|
||||
goto err;
|
||||
if (fread(src->buffer, length, 1, fp) != 1)
|
||||
goto err;
|
||||
|
||||
src->pos = src->buffer;
|
||||
src->end = src->buffer + length;
|
||||
fclose(fp);
|
||||
return src;
|
||||
|
||||
err:
|
||||
pc_closesrc(src);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* pc_createsrc()
|
||||
* Creates/overwrites a source file for writing. The "file" does not have
|
||||
* to be a physical file, one might compile from memory.
|
||||
* filename the name of the "file" to create
|
||||
* Return:
|
||||
* The function must return a pointer which is used as a "magic cookie" to
|
||||
* all I/O functions. When failing to open the file for reading, the
|
||||
* function must return NULL.
|
||||
* Note:
|
||||
* Several "source files" may be open at the same time. Specifically, one
|
||||
* file can be open for reading and another for writing.
|
||||
*/
|
||||
void *pc_createsrc(char *filename)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)calloc(1, sizeof(src_file_t));
|
||||
if (!src)
|
||||
return NULL;
|
||||
if ((src->fp = fopen(filename, "wt")) == NULL) {
|
||||
pc_closesrc(src);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
src->maxlength = 1024;
|
||||
if ((src->buffer = (char *)calloc(1, src->maxlength)) == NULL) {
|
||||
pc_closesrc(src);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
src->pos = src->buffer;
|
||||
src->end = src->buffer + src->maxlength;
|
||||
return src;
|
||||
}
|
||||
|
||||
/* pc_closesrc()
|
||||
* Closes a source file (or include file). The "handle" parameter has the
|
||||
* value that pc_opensrc() returned in an earlier call.
|
||||
*/
|
||||
void pc_closesrc(void *handle)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
if (!src)
|
||||
return;
|
||||
if (src->fp) {
|
||||
fwrite(src->buffer, src->pos - src->buffer, 1, src->fp);
|
||||
fclose(src->fp);
|
||||
}
|
||||
free(src->buffer);
|
||||
free(src);
|
||||
}
|
||||
|
||||
/* pc_readsrc()
|
||||
* Reads a single line from the source file (or up to a maximum number of
|
||||
* characters if the line in the input file is too long).
|
||||
*/
|
||||
char *pc_readsrc(void *handle,unsigned char *target,int maxchars)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
char *outptr = (char *)target;
|
||||
char *outend = outptr + maxchars;
|
||||
|
||||
assert(!src->fp);
|
||||
|
||||
if (src->pos == src->end)
|
||||
return NULL;
|
||||
|
||||
while (outptr < outend && src->pos < src->end) {
|
||||
char c = *src->pos++;
|
||||
*outptr++ = c;
|
||||
|
||||
if (c == '\n')
|
||||
break;
|
||||
if (c == '\r') {
|
||||
// Handle CRLF.
|
||||
if (src->pos < src->end && *src->pos == '\n') {
|
||||
src->pos++;
|
||||
if (outptr < outend)
|
||||
*outptr++ = '\n';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Caller passes in a buffer of size >= maxchars+1.
|
||||
*outptr = '\0';
|
||||
return (char *)target;
|
||||
}
|
||||
|
||||
/* pc_writesrc()
|
||||
* Writes to to the source file. There is no automatic line ending; to end a
|
||||
* line, write a "\n".
|
||||
*/
|
||||
int pc_writesrc(void *handle,unsigned char *source)
|
||||
{
|
||||
char *str = (char *)source;
|
||||
size_t len = strlen(str);
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
|
||||
assert(src->fp && src->maxlength);
|
||||
|
||||
if (src->pos + len > src->end) {
|
||||
char *newbuf;
|
||||
size_t newmax = src->maxlength;
|
||||
size_t newlen = (src->pos - src->buffer) + len;
|
||||
while (newmax < newlen) {
|
||||
// Grow by 1.5X
|
||||
newmax += newmax + newmax / 2;
|
||||
if (newmax < src->maxlength)
|
||||
abort();
|
||||
}
|
||||
|
||||
newbuf = (char *)realloc(src->buffer, newmax);
|
||||
if (!newbuf)
|
||||
abort();
|
||||
src->pos = newbuf + (src->pos - src->buffer);
|
||||
src->end = newbuf + newmax;
|
||||
src->buffer = newbuf;
|
||||
src->maxlength = newmax;
|
||||
}
|
||||
|
||||
strcpy(src->pos, str);
|
||||
src->pos += len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *pc_getpossrc(void *handle,void *position)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
|
||||
assert(!src->fp);
|
||||
return (void *)(ptrdiff_t)(src->pos - src->buffer);
|
||||
}
|
||||
|
||||
/* pc_resetsrc()
|
||||
* "position" may only hold a pointer that was previously obtained from
|
||||
* pc_getpossrc()
|
||||
*/
|
||||
void pc_resetsrc(void *handle,void *position)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
ptrdiff_t pos = (ptrdiff_t)position;
|
||||
|
||||
assert(!src->fp);
|
||||
assert(pos >= 0 && src->buffer + pos <= src->end);
|
||||
src->pos = src->buffer + pos;
|
||||
}
|
||||
|
||||
int pc_eofsrc(void *handle)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
|
||||
assert(!src->fp);
|
||||
return src->pos == src->end;
|
||||
}
|
||||
|
||||
/* should return a pointer, which is used as a "magic cookie" to all I/O
|
||||
* functions; return NULL for failure
|
||||
*/
|
||||
void *pc_openasm(char *filename)
|
||||
{
|
||||
#if defined __MSDOS__ || defined SC_LIGHT
|
||||
return fopen(filename,"w+t");
|
||||
#else
|
||||
return mfcreate(filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
void pc_closeasm(void *handle, int deletefile)
|
||||
{
|
||||
#if defined __MSDOS__ || defined SC_LIGHT
|
||||
if (handle!=NULL)
|
||||
fclose((FILE*)handle);
|
||||
if (deletefile)
|
||||
remove(outfname);
|
||||
#else
|
||||
if (handle!=NULL) {
|
||||
if (!deletefile)
|
||||
mfdump((MEMFILE*)handle);
|
||||
mfclose((MEMFILE*)handle);
|
||||
} /* if */
|
||||
#endif
|
||||
}
|
||||
|
||||
void pc_resetasm(void *handle)
|
||||
{
|
||||
assert(handle!=NULL);
|
||||
#if defined __MSDOS__ || defined SC_LIGHT
|
||||
fflush((FILE*)handle);
|
||||
fseek((FILE*)handle,0,SEEK_SET);
|
||||
#else
|
||||
mfseek((MEMFILE*)handle,0,SEEK_SET);
|
||||
#endif
|
||||
}
|
||||
|
||||
int pc_writeasm(void *handle,char *string)
|
||||
{
|
||||
#if defined __MSDOS__ || defined SC_LIGHT
|
||||
return fputs(string,(FILE*)handle) >= 0;
|
||||
#else
|
||||
return mfputs((MEMFILE*)handle,string);
|
||||
#endif
|
||||
}
|
||||
|
||||
char *pc_readasm(void *handle, char *string, int maxchars)
|
||||
{
|
||||
#if defined __MSDOS__ || defined SC_LIGHT
|
||||
return fgets(string,maxchars,(FILE*)handle);
|
||||
#else
|
||||
return mfgets((MEMFILE*)handle,string,maxchars);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern memfile_t *bin_file;
|
||||
|
||||
/* Should return a pointer, which is used as a "magic cookie" to all I/O
|
||||
* functions; return NULL for failure.
|
||||
*/
|
||||
void *pc_openbin(char *filename)
|
||||
{
|
||||
return memfile_creat(filename, 1);
|
||||
}
|
||||
|
||||
void pc_closebin(void *handle,int deletefile)
|
||||
{
|
||||
if (deletefile)
|
||||
{
|
||||
memfile_destroy((memfile_t *)handle);
|
||||
bin_file = NULL;
|
||||
} else {
|
||||
bin_file = (memfile_t *)handle;
|
||||
}
|
||||
}
|
||||
|
||||
/* pc_resetbin()
|
||||
* Can seek to any location in the file.
|
||||
* The offset is always from the start of the file.
|
||||
*/
|
||||
void pc_resetbin(void *handle,long offset)
|
||||
{
|
||||
memfile_seek((memfile_t *)handle, offset);
|
||||
}
|
||||
|
||||
int pc_writebin(void *handle,void *buffer,int size)
|
||||
{
|
||||
return memfile_write((memfile_t *)handle, buffer, size);
|
||||
}
|
||||
|
||||
long pc_lengthbin(void *handle)
|
||||
{
|
||||
return memfile_tell((memfile_t *)handle);
|
||||
}
|
382
sourcepawn/compiler/libpawnc.cpp
Normal file
382
sourcepawn/compiler/libpawnc.cpp
Normal file
@ -0,0 +1,382 @@
|
||||
// vim: set sts=8 ts=4 sw=4 tw=99 noet:
|
||||
/* LIBPAWNC.C
|
||||
*
|
||||
* A "glue file" for building the Pawn compiler as a DLL or shared library.
|
||||
*
|
||||
* Copyright (c) ITB CompuPhase, 2000-2006
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "sc.h"
|
||||
#include "memfile.h"
|
||||
|
||||
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined DARWIN
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
/* pc_printf()
|
||||
* Called for general purpose "console" output. This function prints general
|
||||
* purpose messages; errors go through pc_error(). The function is modelled
|
||||
* after printf().
|
||||
*/
|
||||
int pc_printf(const char *message,...)
|
||||
{
|
||||
int ret;
|
||||
va_list argptr;
|
||||
|
||||
va_start(argptr,message);
|
||||
ret=vprintf(message,argptr);
|
||||
va_end(argptr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* pc_error()
|
||||
* Called for producing error output.
|
||||
* number the error number (as documented in the manual)
|
||||
* message a string describing the error with embedded %d and %s tokens
|
||||
* filename the name of the file currently being parsed
|
||||
* firstline the line number at which the expression started on which
|
||||
* the error was found, or -1 if there is no "starting line"
|
||||
* lastline the line number at which the error was detected
|
||||
* argptr a pointer to the first of a series of arguments (for macro
|
||||
* "va_arg")
|
||||
* Return:
|
||||
* If the function returns 0, the parser attempts to continue compilation.
|
||||
* On a non-zero return value, the parser aborts.
|
||||
*/
|
||||
int pc_error(int number,const char *message,const char *filename,int firstline,int lastline,va_list argptr)
|
||||
{
|
||||
static const char *prefix[3]={ "error", "fatal error", "warning" };
|
||||
|
||||
if (number!=0) {
|
||||
int idx;
|
||||
|
||||
if (number < 160)
|
||||
idx = 0;
|
||||
else if (number < 200)
|
||||
idx = 1;
|
||||
else
|
||||
idx = 2;
|
||||
|
||||
const char *pre=prefix[idx];
|
||||
if (firstline>=0)
|
||||
fprintf(stdout,"%s(%d -- %d) : %s %03d: ",filename,firstline,lastline,pre,number);
|
||||
else
|
||||
fprintf(stdout,"%s(%d) : %s %03d: ",filename,lastline,pre,number);
|
||||
} /* if */
|
||||
vfprintf(stdout,message,argptr);
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct src_file_s {
|
||||
FILE *fp; // Set if writing.
|
||||
char *buffer; // IO buffer.
|
||||
char *pos; // IO position.
|
||||
char *end; // End of buffer.
|
||||
size_t maxlength; // Maximum length of the writable buffer.
|
||||
} src_file_t;
|
||||
|
||||
/* pc_opensrc()
|
||||
* Opens a source file (or include file) for reading. The "file" does not have
|
||||
* to be a physical file, one might compile from memory.
|
||||
* filename the name of the "file" to read from
|
||||
* Return:
|
||||
* The function must return a pointer, which is used as a "magic cookie" to
|
||||
* all I/O functions. When failing to open the file for reading, the
|
||||
* function must return NULL.
|
||||
* Note:
|
||||
* Several "source files" may be open at the same time. Specifically, one
|
||||
* file can be open for reading and another for writing.
|
||||
*/
|
||||
void *pc_opensrc(char *filename)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
long length;
|
||||
src_file_t *src = NULL;
|
||||
|
||||
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined DARWIN
|
||||
struct stat fileInfo;
|
||||
if (stat(filename, &fileInfo) != 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (S_ISDIR(fileInfo.st_mode)) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((fp = fopen(filename, "rb")) == NULL)
|
||||
return NULL;
|
||||
if (fseek(fp, 0, SEEK_END) == -1)
|
||||
goto err;
|
||||
if ((length = ftell(fp)) == -1)
|
||||
goto err;
|
||||
if (fseek(fp, 0, SEEK_SET) == -1)
|
||||
goto err;
|
||||
|
||||
if ((src = (src_file_t *)calloc(1, sizeof(src_file_t))) == NULL)
|
||||
goto err;
|
||||
if ((src->buffer = (char *)calloc(length, sizeof(char))) == NULL)
|
||||
goto err;
|
||||
if (fread(src->buffer, length, 1, fp) != 1)
|
||||
goto err;
|
||||
|
||||
src->pos = src->buffer;
|
||||
src->end = src->buffer + length;
|
||||
fclose(fp);
|
||||
return src;
|
||||
|
||||
err:
|
||||
pc_closesrc(src);
|
||||
fclose(fp);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* pc_createsrc()
|
||||
* Creates/overwrites a source file for writing. The "file" does not have
|
||||
* to be a physical file, one might compile from memory.
|
||||
* filename the name of the "file" to create
|
||||
* Return:
|
||||
* The function must return a pointer which is used as a "magic cookie" to
|
||||
* all I/O functions. When failing to open the file for reading, the
|
||||
* function must return NULL.
|
||||
* Note:
|
||||
* Several "source files" may be open at the same time. Specifically, one
|
||||
* file can be open for reading and another for writing.
|
||||
*/
|
||||
void *pc_createsrc(char *filename)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)calloc(1, sizeof(src_file_t));
|
||||
if (!src)
|
||||
return NULL;
|
||||
if ((src->fp = fopen(filename, "wt")) == NULL) {
|
||||
pc_closesrc(src);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
src->maxlength = 1024;
|
||||
if ((src->buffer = (char *)calloc(1, src->maxlength)) == NULL) {
|
||||
pc_closesrc(src);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
src->pos = src->buffer;
|
||||
src->end = src->buffer + src->maxlength;
|
||||
return src;
|
||||
}
|
||||
|
||||
/* pc_closesrc()
|
||||
* Closes a source file (or include file). The "handle" parameter has the
|
||||
* value that pc_opensrc() returned in an earlier call.
|
||||
*/
|
||||
void pc_closesrc(void *handle)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
if (!src)
|
||||
return;
|
||||
if (src->fp) {
|
||||
fwrite(src->buffer, src->pos - src->buffer, 1, src->fp);
|
||||
fclose(src->fp);
|
||||
}
|
||||
free(src->buffer);
|
||||
free(src);
|
||||
}
|
||||
|
||||
/* pc_readsrc()
|
||||
* Reads a single line from the source file (or up to a maximum number of
|
||||
* characters if the line in the input file is too long).
|
||||
*/
|
||||
char *pc_readsrc(void *handle,unsigned char *target,int maxchars)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
char *outptr = (char *)target;
|
||||
char *outend = outptr + maxchars;
|
||||
|
||||
assert(!src->fp);
|
||||
|
||||
if (src->pos == src->end)
|
||||
return NULL;
|
||||
|
||||
while (outptr < outend && src->pos < src->end) {
|
||||
char c = *src->pos++;
|
||||
*outptr++ = c;
|
||||
|
||||
if (c == '\n')
|
||||
break;
|
||||
if (c == '\r') {
|
||||
// Handle CRLF.
|
||||
if (src->pos < src->end && *src->pos == '\n') {
|
||||
src->pos++;
|
||||
if (outptr < outend)
|
||||
*outptr++ = '\n';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Caller passes in a buffer of size >= maxchars+1.
|
||||
*outptr = '\0';
|
||||
return (char *)target;
|
||||
}
|
||||
|
||||
/* pc_writesrc()
|
||||
* Writes to to the source file. There is no automatic line ending; to end a
|
||||
* line, write a "\n".
|
||||
*/
|
||||
int pc_writesrc(void *handle,unsigned char *source)
|
||||
{
|
||||
char *str = (char *)source;
|
||||
size_t len = strlen(str);
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
|
||||
assert(src->fp && src->maxlength);
|
||||
|
||||
if (src->pos + len > src->end) {
|
||||
char *newbuf;
|
||||
size_t newmax = src->maxlength;
|
||||
size_t newlen = (src->pos - src->buffer) + len;
|
||||
while (newmax < newlen) {
|
||||
// Grow by 1.5X
|
||||
newmax += newmax + newmax / 2;
|
||||
if (newmax < src->maxlength)
|
||||
abort();
|
||||
}
|
||||
|
||||
newbuf = (char *)realloc(src->buffer, newmax);
|
||||
if (!newbuf)
|
||||
abort();
|
||||
src->pos = newbuf + (src->pos - src->buffer);
|
||||
src->end = newbuf + newmax;
|
||||
src->buffer = newbuf;
|
||||
src->maxlength = newmax;
|
||||
}
|
||||
|
||||
strcpy(src->pos, str);
|
||||
src->pos += len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *pc_getpossrc(void *handle,void *position)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
|
||||
assert(!src->fp);
|
||||
return (void *)(ptrdiff_t)(src->pos - src->buffer);
|
||||
}
|
||||
|
||||
/* pc_resetsrc()
|
||||
* "position" may only hold a pointer that was previously obtained from
|
||||
* pc_getpossrc()
|
||||
*/
|
||||
void pc_resetsrc(void *handle,void *position)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
ptrdiff_t pos = (ptrdiff_t)position;
|
||||
|
||||
assert(!src->fp);
|
||||
assert(pos >= 0 && src->buffer + pos <= src->end);
|
||||
src->pos = src->buffer + pos;
|
||||
}
|
||||
|
||||
int pc_eofsrc(void *handle)
|
||||
{
|
||||
src_file_t *src = (src_file_t *)handle;
|
||||
|
||||
assert(!src->fp);
|
||||
return src->pos == src->end;
|
||||
}
|
||||
|
||||
/* should return a pointer, which is used as a "magic cookie" to all I/O
|
||||
* functions; return NULL for failure
|
||||
*/
|
||||
void *pc_openasm(char *filename)
|
||||
{
|
||||
return mfcreate(filename);
|
||||
}
|
||||
|
||||
void pc_closeasm(void *handle, int deletefile)
|
||||
{
|
||||
if (handle!=NULL) {
|
||||
if (!deletefile)
|
||||
mfdump((MEMFILE*)handle);
|
||||
mfclose((MEMFILE*)handle);
|
||||
} /* if */
|
||||
}
|
||||
|
||||
void pc_resetasm(void *handle)
|
||||
{
|
||||
mfseek((MEMFILE*)handle,0,SEEK_SET);
|
||||
}
|
||||
|
||||
int pc_writeasm(void *handle,const char *string)
|
||||
{
|
||||
return mfputs((MEMFILE*)handle,string);
|
||||
}
|
||||
|
||||
char *pc_readasm(void *handle, char *string, int maxchars)
|
||||
{
|
||||
return mfgets((MEMFILE*)handle,string,maxchars);
|
||||
}
|
||||
|
||||
extern memfile_t *bin_file;
|
||||
|
||||
/* Should return a pointer, which is used as a "magic cookie" to all I/O
|
||||
* functions; return NULL for failure.
|
||||
*/
|
||||
void *pc_openbin(char *filename)
|
||||
{
|
||||
return memfile_creat(filename, 1);
|
||||
}
|
||||
|
||||
void pc_closebin(void *handle,int deletefile)
|
||||
{
|
||||
if (deletefile) {
|
||||
memfile_destroy((memfile_t *)handle);
|
||||
bin_file = NULL;
|
||||
} else {
|
||||
bin_file = (memfile_t *)handle;
|
||||
}
|
||||
}
|
||||
|
||||
/* pc_resetbin()
|
||||
* Can seek to any location in the file.
|
||||
* The offset is always from the start of the file.
|
||||
*/
|
||||
void pc_resetbin(void *handle,long offset)
|
||||
{
|
||||
memfile_seek((memfile_t *)handle, offset);
|
||||
}
|
||||
|
||||
int pc_writebin(void *handle,void *buffer,int size)
|
||||
{
|
||||
return memfile_write((memfile_t *)handle, buffer, size);
|
||||
}
|
||||
|
||||
long pc_lengthbin(void *handle)
|
||||
{
|
||||
return memfile_tell((memfile_t *)handle);
|
||||
}
|
@ -37,7 +37,7 @@
|
||||
* will be copied. Always NUL terminates (unless siz == 0).
|
||||
* Returns strlen(src); if retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
extern "C" size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
@ -93,7 +93,7 @@ strlcpy(char *dst, const char *src, size_t siz)
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
extern "C" size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
@ -9,10 +9,18 @@
|
||||
|
||||
#if !defined HAVE_SAFESTR
|
||||
|
||||
size_t
|
||||
#if defined(__cplusplus)
|
||||
# define EXPORT extern "C"
|
||||
#else
|
||||
# define EXPORT
|
||||
#endif
|
||||
|
||||
EXPORT size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz);
|
||||
|
||||
size_t
|
||||
EXPORT size_t
|
||||
strlcat(char *dst, const char *src, size_t siz);
|
||||
|
||||
#undef EXPORT
|
||||
|
||||
#endif
|
||||
|
@ -52,4 +52,15 @@ long memfile_tell(memfile_t *mf);
|
||||
*/
|
||||
void memfile_reset(memfile_t *mf);
|
||||
|
||||
typedef memfile_t MEMFILE;
|
||||
MEMFILE *mfcreate(const char *filename);
|
||||
void mfclose(MEMFILE *mf);
|
||||
int mfdump(MEMFILE *mf);
|
||||
long mflength(const MEMFILE *mf);
|
||||
long mfseek(MEMFILE *mf,long offset,int whence);
|
||||
unsigned int mfwrite(MEMFILE *mf,const unsigned char *buffer,unsigned int size);
|
||||
unsigned int mfread(MEMFILE *mf,unsigned char *buffer,unsigned int size);
|
||||
char *mfgets(MEMFILE *mf,char *string,unsigned int size);
|
||||
int mfputs(MEMFILE *mf,const char *string);
|
||||
|
||||
#endif //_INCLUDE_MEMFILE_H
|
||||
|
@ -528,7 +528,6 @@ void sp_fdbg_ntv_start(int num_natives)
|
||||
}
|
||||
|
||||
#include "sc.h"
|
||||
|
||||
void sp_fdbg_ntv_hook(int index, symbol *sym)
|
||||
{
|
||||
int i, j;
|
||||
@ -553,3 +552,30 @@ void sp_fdbg_ntv_hook(int index, symbol *sym)
|
||||
|
||||
native->ret_tag = sym->tag;
|
||||
}
|
||||
|
||||
|
||||
#if defined __linux__ || defined __APPLE__
|
||||
extern "C" void __cxa_pure_virtual(void)
|
||||
{
|
||||
}
|
||||
|
||||
void *operator new(size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void *operator new[](size_t size)
|
||||
{
|
||||
return malloc(size);
|
||||
}
|
||||
|
||||
void operator delete(void *ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
|
||||
void operator delete[](void * ptr)
|
||||
{
|
||||
free(ptr);
|
||||
}
|
||||
#endif
|
@ -537,18 +537,13 @@ typedef enum s_optmark {
|
||||
#define CELL_MAX (((ucell)1 << (sizeof(cell)*8-1)) - 1)
|
||||
|
||||
|
||||
/* interface functions */
|
||||
#if defined __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Functions you call from the "driver" program
|
||||
*/
|
||||
int pc_compile(int argc, char **argv);
|
||||
int pc_addconstant(char *name,cell value,int tag);
|
||||
int pc_addtag(char *name);
|
||||
int pc_addtag_flags(char *name, int flags);
|
||||
int pc_addconstant(const char *name,cell value,int tag);
|
||||
int pc_addtag(const char *name);
|
||||
int pc_addtag_flags(const char *name, int flags);
|
||||
int pc_findtag(const char *name);
|
||||
constvalue *pc_tagptr(const char *name);
|
||||
int pc_enablewarning(int number,int enable);
|
||||
@ -564,7 +559,7 @@ const char *type_to_name(int tag);
|
||||
int pc_printf(const char *message,...);
|
||||
|
||||
/* error report function */
|
||||
int pc_error(int number,char *message,char *filename,int firstline,int lastline,va_list argptr);
|
||||
int pc_error(int number,const char *message,const char *filename,int firstline,int lastline,va_list argptr);
|
||||
|
||||
/* input from source file */
|
||||
void *pc_opensrc(char *filename); /* reading only */
|
||||
@ -580,7 +575,7 @@ int pc_eofsrc(void *handle);
|
||||
void *pc_openasm(char *filename); /* read/write */
|
||||
void pc_closeasm(void *handle,int deletefile);
|
||||
void pc_resetasm(void *handle);
|
||||
int pc_writeasm(void *handle,char *str);
|
||||
int pc_writeasm(void *handle,const char *str);
|
||||
char *pc_readasm(void *handle,char *target,int maxchars);
|
||||
|
||||
/* output to binary (.AMX) file */
|
||||
@ -590,162 +585,144 @@ void pc_resetbin(void *handle,long offset);
|
||||
int pc_writebin(void *handle,void *buffer,int size);
|
||||
long pc_lengthbin(void *handle); /* return the length of the file */
|
||||
|
||||
#if defined __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* by default, functions and variables used in throughout the compiler
|
||||
* files are "external"
|
||||
*/
|
||||
#if !defined SC_FUNC
|
||||
#define SC_FUNC
|
||||
#endif
|
||||
#if !defined SC_VDECL
|
||||
#define SC_VDECL extern
|
||||
#endif
|
||||
#if !defined SC_VDEFINE
|
||||
#define SC_VDEFINE
|
||||
#endif
|
||||
|
||||
void sp_fdbg_ntv_start(int num_natives);
|
||||
void sp_fdbg_ntv_hook(int index, symbol *sym);
|
||||
|
||||
/* function prototypes in SC1.C */
|
||||
SC_FUNC void set_extension(char *filename,char *extension,int force);
|
||||
SC_FUNC symbol *fetchfunc(char *name);
|
||||
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag);
|
||||
SC_FUNC char *funcdisplayname(char *dest,char *funcname);
|
||||
SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr);
|
||||
SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
|
||||
SC_FUNC constvalue *find_constval(constvalue *table,char *name,int index);
|
||||
SC_FUNC void delete_consttable(constvalue *table);
|
||||
SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag);
|
||||
SC_FUNC void exporttag(int tag);
|
||||
SC_FUNC void sc_attachdocumentation(symbol *sym);
|
||||
SC_FUNC constvalue *find_tag_byval(int tag);
|
||||
SC_FUNC int get_actual_compound(symbol *sym);
|
||||
void set_extension(char *filename,const char *extension,int force);
|
||||
symbol *fetchfunc(char *name);
|
||||
char *operator_symname(char *symname,const char *opername,int tag1,int tag2,int numtags,int resulttag);
|
||||
char *funcdisplayname(char *dest,char *funcname);
|
||||
int exprconst(cell *val,int *tag,symbol **symptr);
|
||||
constvalue *append_constval(constvalue *table,const char *name,cell val,int index);
|
||||
constvalue *find_constval(constvalue *table,char *name,int index);
|
||||
void delete_consttable(constvalue *table);
|
||||
symbol *add_constant(const char *name,cell val,int vclass,int tag);
|
||||
void exporttag(int tag);
|
||||
void sc_attachdocumentation(symbol *sym);
|
||||
constvalue *find_tag_byval(int tag);
|
||||
int get_actual_compound(symbol *sym);
|
||||
|
||||
/* function prototypes in SC2.C */
|
||||
#define PUSHSTK_P(v) { stkitem s_; s_.pv=(v); pushstk(s_); }
|
||||
#define PUSHSTK_I(v) { stkitem s_; s_.i=(v); pushstk(s_); }
|
||||
#define POPSTK_P() (popstk().pv)
|
||||
#define POPSTK_I() (popstk().i)
|
||||
SC_FUNC void pushstk(stkitem val);
|
||||
SC_FUNC stkitem popstk(void);
|
||||
SC_FUNC void clearstk(void);
|
||||
SC_FUNC int plungequalifiedfile(char *name); /* explicit path included */
|
||||
SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths); /* search through "include" paths */
|
||||
SC_FUNC void preprocess(void);
|
||||
SC_FUNC void lexinit(void);
|
||||
SC_FUNC int lex(cell *lexvalue,char **lexsym);
|
||||
SC_FUNC int lextok(token_t *tok);
|
||||
SC_FUNC int lexpeek(int id);
|
||||
SC_FUNC void lexpush(void);
|
||||
SC_FUNC void lexclr(int clreol);
|
||||
SC_FUNC int matchtoken(int token);
|
||||
SC_FUNC int tokeninfo(cell *val,char **str);
|
||||
SC_FUNC int needtoken(int token);
|
||||
SC_FUNC int matchtoken2(int id, token_t *tok);
|
||||
SC_FUNC int expecttoken(int id, token_t *tok);
|
||||
SC_FUNC int matchsymbol(token_ident_t *ident);
|
||||
SC_FUNC int needsymbol(token_ident_t *ident);
|
||||
SC_FUNC int peek_same_line();
|
||||
SC_FUNC int require_newline(int allow_semi);
|
||||
SC_FUNC void litadd(cell value);
|
||||
SC_FUNC void litinsert(cell value,int pos);
|
||||
SC_FUNC int alphanum(char c);
|
||||
SC_FUNC int ishex(char c);
|
||||
SC_FUNC void delete_symbol(symbol *root,symbol *sym);
|
||||
SC_FUNC void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
|
||||
SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom);
|
||||
SC_FUNC void markusage(symbol *sym,int usage);
|
||||
SC_FUNC symbol *findglb(const char *name,int filter);
|
||||
SC_FUNC symbol *findloc(const char *name);
|
||||
SC_FUNC symbol *findconst(const char *name,int *matchtag);
|
||||
SC_FUNC symbol *finddepend(const symbol *parent);
|
||||
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag, int usage);
|
||||
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
void pushstk(stkitem val);
|
||||
stkitem popstk(void);
|
||||
void clearstk(void);
|
||||
int plungequalifiedfile(char *name); /* explicit path included */
|
||||
int plungefile(char *name,int try_currentpath,int try_includepaths); /* search through "include" paths */
|
||||
void preprocess(void);
|
||||
void lexinit(void);
|
||||
int lex(cell *lexvalue,char **lexsym);
|
||||
int lextok(token_t *tok);
|
||||
int lexpeek(int id);
|
||||
void lexpush(void);
|
||||
void lexclr(int clreol);
|
||||
int matchtoken(int token);
|
||||
int tokeninfo(cell *val,char **str);
|
||||
int needtoken(int token);
|
||||
int matchtoken2(int id, token_t *tok);
|
||||
int expecttoken(int id, token_t *tok);
|
||||
int matchsymbol(token_ident_t *ident);
|
||||
int needsymbol(token_ident_t *ident);
|
||||
int peek_same_line();
|
||||
int require_newline(int allow_semi);
|
||||
void litadd(cell value);
|
||||
void litinsert(cell value,int pos);
|
||||
int alphanum(char c);
|
||||
int ishex(char c);
|
||||
void delete_symbol(symbol *root,symbol *sym);
|
||||
void delete_symbols(symbol *root,int level,int del_labels,int delete_functions);
|
||||
int refer_symbol(symbol *entry,symbol *bywhom);
|
||||
void markusage(symbol *sym,int usage);
|
||||
symbol *findglb(const char *name,int filter);
|
||||
symbol *findloc(const char *name);
|
||||
symbol *findconst(const char *name,int *matchtag);
|
||||
symbol *finddepend(const symbol *parent);
|
||||
symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag, int usage);
|
||||
symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
int dim[],int numdim,int idxtag[]);
|
||||
SC_FUNC symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
int dim[],int numdim,int idxtag[],int slength);
|
||||
SC_FUNC symbol *addvariable3(declinfo_t *decl,cell addr,int vclass,int slength);
|
||||
SC_FUNC int getlabel(void);
|
||||
SC_FUNC char *itoh(ucell val);
|
||||
symbol *addvariable3(declinfo_t *decl,cell addr,int vclass,int slength);
|
||||
int getlabel(void);
|
||||
char *itoh(ucell val);
|
||||
|
||||
#define MATCHTAG_COERCE 0x1 // allow coercion
|
||||
#define MATCHTAG_SILENT 0x2 // silence the error(213) warning
|
||||
#define MATCHTAG_COMMUTATIVE 0x4 // order does not matter
|
||||
|
||||
/* function prototypes in SC3.C */
|
||||
SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
|
||||
int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
|
||||
value *lval,int *resulttag);
|
||||
SC_FUNC int matchtag(int formaltag,int actualtag,int allowcoerce);
|
||||
SC_FUNC int checktag(int tags[],int numtags,int exprtag);
|
||||
SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult,value *_lval);
|
||||
SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state);
|
||||
SC_FUNC cell array_totalsize(symbol *sym);
|
||||
SC_FUNC int matchtag_string(int ident, int tag);
|
||||
SC_FUNC int checktag_string(value *sym1, value *sym2);
|
||||
SC_FUNC int checktags_string(int tags[], int numtags, value *sym1);
|
||||
SC_FUNC int lvalexpr(svalue *sval);
|
||||
int matchtag(int formaltag,int actualtag,int allowcoerce);
|
||||
int checktag(int tags[],int numtags,int exprtag);
|
||||
int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult,value *_lval);
|
||||
int sc_getstateid(constvalue **automaton,constvalue **state);
|
||||
cell array_totalsize(symbol *sym);
|
||||
int matchtag_string(int ident, int tag);
|
||||
int checktag_string(value *sym1, value *sym2);
|
||||
int checktags_string(int tags[], int numtags, value *sym1);
|
||||
int lvalexpr(svalue *sval);
|
||||
|
||||
/* function prototypes in SC4.C */
|
||||
SC_FUNC void writeleader(symbol *root);
|
||||
SC_FUNC void writetrailer(void);
|
||||
SC_FUNC void begcseg(void);
|
||||
SC_FUNC void begdseg(void);
|
||||
SC_FUNC void setline(int chkbounds);
|
||||
SC_FUNC void setfiledirect(char *name);
|
||||
SC_FUNC void setlinedirect(int line);
|
||||
SC_FUNC void setlabel(int index);
|
||||
SC_FUNC void markexpr(optmark type,const char *name,cell offset);
|
||||
SC_FUNC void startfunc(char *fname);
|
||||
SC_FUNC void endfunc(void);
|
||||
SC_FUNC void alignframe(int numbytes);
|
||||
SC_FUNC void rvalue(value *lval);
|
||||
SC_FUNC void address(symbol *ptr,regid reg);
|
||||
SC_FUNC void store(value *lval);
|
||||
SC_FUNC void loadreg(cell address,regid reg);
|
||||
SC_FUNC void storereg(cell address,regid reg);
|
||||
SC_FUNC void memcopy(cell size);
|
||||
SC_FUNC void copyarray(symbol *sym,cell size);
|
||||
SC_FUNC void fillarray(symbol *sym,cell size,cell value);
|
||||
SC_FUNC void ldconst(cell val,regid reg);
|
||||
SC_FUNC void moveto1(void);
|
||||
SC_FUNC void move_alt(void);
|
||||
SC_FUNC void pushreg(regid reg);
|
||||
SC_FUNC void pushval(cell val);
|
||||
SC_FUNC void popreg(regid reg);
|
||||
SC_FUNC void genarray(int dims, int _autozero);
|
||||
SC_FUNC void swap1(void);
|
||||
SC_FUNC void ffswitch(int label);
|
||||
SC_FUNC void ffcase(cell value,char *labelname,int newtable);
|
||||
SC_FUNC void ffcall(symbol *sym,const char *label,int numargs);
|
||||
SC_FUNC void ffret(int remparams);
|
||||
SC_FUNC void ffabort(int reason);
|
||||
SC_FUNC void ffbounds(cell size);
|
||||
SC_FUNC void jumplabel(int number);
|
||||
SC_FUNC void defstorage(void);
|
||||
SC_FUNC void modstk(int delta);
|
||||
SC_FUNC void setstk(cell value);
|
||||
SC_FUNC void modheap(int delta);
|
||||
SC_FUNC void modheap_i();
|
||||
SC_FUNC void setheap_pri(void);
|
||||
SC_FUNC void setheap(cell value);
|
||||
SC_FUNC void cell2addr(void);
|
||||
SC_FUNC void cell2addr_alt(void);
|
||||
SC_FUNC void addr2cell(void);
|
||||
SC_FUNC void char2addr(void);
|
||||
SC_FUNC void charalign(void);
|
||||
SC_FUNC void addconst(cell value);
|
||||
SC_FUNC void setheap_save(cell value);
|
||||
SC_FUNC void stradjust(regid reg);
|
||||
SC_FUNC void invoke_getter(struct methodmap_method_s *method);
|
||||
SC_FUNC void invoke_setter(struct methodmap_method_s *method, int save);
|
||||
SC_FUNC void inc_pri();
|
||||
SC_FUNC void dec_pri();
|
||||
SC_FUNC void load_hidden_arg();
|
||||
void writeleader(symbol *root);
|
||||
void writetrailer(void);
|
||||
void begcseg(void);
|
||||
void begdseg(void);
|
||||
void setline(int chkbounds);
|
||||
void setfiledirect(char *name);
|
||||
void setlinedirect(int line);
|
||||
void setlabel(int index);
|
||||
void markexpr(optmark type,const char *name,cell offset);
|
||||
void startfunc(char *fname);
|
||||
void endfunc(void);
|
||||
void alignframe(int numbytes);
|
||||
void rvalue(value *lval);
|
||||
void address(symbol *ptr,regid reg);
|
||||
void store(value *lval);
|
||||
void loadreg(cell address,regid reg);
|
||||
void storereg(cell address,regid reg);
|
||||
void memcopy(cell size);
|
||||
void copyarray(symbol *sym,cell size);
|
||||
void fillarray(symbol *sym,cell size,cell value);
|
||||
void ldconst(cell val,regid reg);
|
||||
void moveto1(void);
|
||||
void move_alt(void);
|
||||
void pushreg(regid reg);
|
||||
void pushval(cell val);
|
||||
void popreg(regid reg);
|
||||
void genarray(int dims, int _autozero);
|
||||
void swap1(void);
|
||||
void ffswitch(int label);
|
||||
void ffcase(cell value,char *labelname,int newtable);
|
||||
void ffcall(symbol *sym,const char *label,int numargs);
|
||||
void ffret(int remparams);
|
||||
void ffabort(int reason);
|
||||
void ffbounds(cell size);
|
||||
void jumplabel(int number);
|
||||
void defstorage(void);
|
||||
void modstk(int delta);
|
||||
void setstk(cell value);
|
||||
void modheap(int delta);
|
||||
void modheap_i();
|
||||
void setheap_pri(void);
|
||||
void setheap(cell value);
|
||||
void cell2addr(void);
|
||||
void cell2addr_alt(void);
|
||||
void addr2cell(void);
|
||||
void char2addr(void);
|
||||
void charalign(void);
|
||||
void addconst(cell value);
|
||||
void setheap_save(cell value);
|
||||
void stradjust(regid reg);
|
||||
void invoke_getter(struct methodmap_method_s *method);
|
||||
void invoke_setter(struct methodmap_method_s *method, int save);
|
||||
void inc_pri();
|
||||
void dec_pri();
|
||||
void load_hidden_arg();
|
||||
|
||||
/* Code generation functions for arithmetic operators.
|
||||
*
|
||||
@ -755,212 +732,197 @@ SC_FUNC void load_hidden_arg();
|
||||
* | +--------- "u"nsigned operator, "s"igned operator or "b"oth
|
||||
* +------------- "o"perator
|
||||
*/
|
||||
SC_FUNC void os_mult(void); /* multiplication (signed) */
|
||||
SC_FUNC void os_div(void); /* division (signed) */
|
||||
SC_FUNC void os_mod(void); /* modulus (signed) */
|
||||
SC_FUNC void ob_add(void); /* addition */
|
||||
SC_FUNC void ob_sub(void); /* subtraction */
|
||||
SC_FUNC void ob_sal(void); /* shift left (arithmetic) */
|
||||
SC_FUNC void os_sar(void); /* shift right (arithmetic, signed) */
|
||||
SC_FUNC void ou_sar(void); /* shift right (logical, unsigned) */
|
||||
SC_FUNC void ob_or(void); /* bitwise or */
|
||||
SC_FUNC void ob_xor(void); /* bitwise xor */
|
||||
SC_FUNC void ob_and(void); /* bitwise and */
|
||||
SC_FUNC void ob_eq(void); /* equality */
|
||||
SC_FUNC void ob_ne(void); /* inequality */
|
||||
SC_FUNC void relop_prefix(void);
|
||||
SC_FUNC void relop_suffix(void);
|
||||
SC_FUNC void os_le(void); /* less or equal (signed) */
|
||||
SC_FUNC void os_ge(void); /* greater or equal (signed) */
|
||||
SC_FUNC void os_lt(void); /* less (signed) */
|
||||
SC_FUNC void os_gt(void); /* greater (signed) */
|
||||
void os_mult(void); /* multiplication (signed) */
|
||||
void os_div(void); /* division (signed) */
|
||||
void os_mod(void); /* modulus (signed) */
|
||||
void ob_add(void); /* addition */
|
||||
void ob_sub(void); /* subtraction */
|
||||
void ob_sal(void); /* shift left (arithmetic) */
|
||||
void os_sar(void); /* shift right (arithmetic, signed) */
|
||||
void ou_sar(void); /* shift right (logical, unsigned) */
|
||||
void ob_or(void); /* bitwise or */
|
||||
void ob_xor(void); /* bitwise xor */
|
||||
void ob_and(void); /* bitwise and */
|
||||
void ob_eq(void); /* equality */
|
||||
void ob_ne(void); /* inequality */
|
||||
void relop_prefix(void);
|
||||
void relop_suffix(void);
|
||||
void os_le(void); /* less or equal (signed) */
|
||||
void os_ge(void); /* greater or equal (signed) */
|
||||
void os_lt(void); /* less (signed) */
|
||||
void os_gt(void); /* greater (signed) */
|
||||
|
||||
SC_FUNC void lneg(void);
|
||||
SC_FUNC void neg(void);
|
||||
SC_FUNC void invert(void);
|
||||
SC_FUNC void nooperation(void);
|
||||
SC_FUNC void inc(value *lval);
|
||||
SC_FUNC void dec(value *lval);
|
||||
SC_FUNC void jmp_ne0(int number);
|
||||
SC_FUNC void jmp_eq0(int number);
|
||||
SC_FUNC void outval(cell val,int newline);
|
||||
void lneg(void);
|
||||
void neg(void);
|
||||
void invert(void);
|
||||
void nooperation(void);
|
||||
void inc(value *lval);
|
||||
void dec(value *lval);
|
||||
void jmp_ne0(int number);
|
||||
void jmp_eq0(int number);
|
||||
void outval(cell val,int newline);
|
||||
|
||||
/* function prototypes in SC5.C */
|
||||
SC_FUNC int error(int number,...);
|
||||
SC_FUNC void errorset(int code,int line);
|
||||
int error(int number,...);
|
||||
void errorset(int code,int line);
|
||||
|
||||
/* function prototypes in SC6.C */
|
||||
SC_FUNC int assemble(FILE *fout,FILE *fin);
|
||||
int assemble(void *fout,void *fin);
|
||||
|
||||
/* function prototypes in SC7.C */
|
||||
SC_FUNC void stgbuffer_cleanup(void);
|
||||
SC_FUNC void stgmark(char mark);
|
||||
SC_FUNC void stgwrite(const char *st);
|
||||
SC_FUNC void stgout(int index);
|
||||
SC_FUNC void stgdel(int index,cell code_index);
|
||||
SC_FUNC int stgget(int *index,cell *code_index);
|
||||
SC_FUNC void stgset(int onoff);
|
||||
SC_FUNC int phopt_init(void);
|
||||
SC_FUNC int phopt_cleanup(void);
|
||||
void stgbuffer_cleanup(void);
|
||||
void stgmark(char mark);
|
||||
void stgwrite(const char *st);
|
||||
void stgout(int index);
|
||||
void stgdel(int index,cell code_index);
|
||||
int stgget(int *index,cell *code_index);
|
||||
void stgset(int onoff);
|
||||
int phopt_init(void);
|
||||
int phopt_cleanup(void);
|
||||
|
||||
/* function prototypes in SCLIST.C */
|
||||
SC_FUNC char* duplicatestring(const char* sourcestring);
|
||||
SC_FUNC stringpair *insert_alias(char *name,char *alias);
|
||||
SC_FUNC stringpair *find_alias(char *name);
|
||||
SC_FUNC int lookup_alias(char *target,char *name);
|
||||
SC_FUNC void delete_aliastable(void);
|
||||
SC_FUNC stringlist *insert_path(char *path);
|
||||
SC_FUNC char *get_path(int index);
|
||||
SC_FUNC void delete_pathtable(void);
|
||||
SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen);
|
||||
SC_FUNC int get_subst(int index,char **pattern,char **substitution);
|
||||
SC_FUNC stringpair *find_subst(char *name,int length);
|
||||
SC_FUNC int delete_subst(char *name,int length);
|
||||
SC_FUNC void delete_substtable(void);
|
||||
SC_FUNC stringlist *insert_sourcefile(char *string);
|
||||
SC_FUNC char *get_sourcefile(int index);
|
||||
SC_FUNC void delete_sourcefiletable(void);
|
||||
SC_FUNC stringlist *insert_docstring(char *string);
|
||||
SC_FUNC char *get_docstring(int index);
|
||||
SC_FUNC void delete_docstring(int index);
|
||||
SC_FUNC void delete_docstringtable(void);
|
||||
SC_FUNC stringlist *insert_autolist(char *string);
|
||||
SC_FUNC char *get_autolist(int index);
|
||||
SC_FUNC void delete_autolisttable(void);
|
||||
SC_FUNC stringlist *insert_dbgfile(const char *filename);
|
||||
SC_FUNC stringlist *insert_dbgline(int linenr);
|
||||
SC_FUNC stringlist *insert_dbgsymbol(symbol *sym);
|
||||
SC_FUNC char *get_dbgstring(int index);
|
||||
SC_FUNC void delete_dbgstringtable(void);
|
||||
SC_FUNC stringlist *get_dbgstrings();
|
||||
|
||||
/* function prototypes in SCMEMFILE.C */
|
||||
#if !defined tMEMFILE
|
||||
typedef unsigned char MEMFILE;
|
||||
#define tMEMFILE 1
|
||||
#endif
|
||||
MEMFILE *mfcreate(const char *filename);
|
||||
void mfclose(MEMFILE *mf);
|
||||
int mfdump(MEMFILE *mf);
|
||||
long mflength(const MEMFILE *mf);
|
||||
long mfseek(MEMFILE *mf,long offset,int whence);
|
||||
unsigned int mfwrite(MEMFILE *mf,const unsigned char *buffer,unsigned int size);
|
||||
unsigned int mfread(MEMFILE *mf,unsigned char *buffer,unsigned int size);
|
||||
char *mfgets(MEMFILE *mf,char *string,unsigned int size);
|
||||
int mfputs(MEMFILE *mf,const char *string);
|
||||
char* duplicatestring(const char* sourcestring);
|
||||
stringpair *insert_alias(char *name,char *alias);
|
||||
stringpair *find_alias(char *name);
|
||||
int lookup_alias(char *target,char *name);
|
||||
void delete_aliastable(void);
|
||||
stringlist *insert_path(char *path);
|
||||
char *get_path(int index);
|
||||
void delete_pathtable(void);
|
||||
stringpair *insert_subst(const char *pattern,const char *substitution,int prefixlen);
|
||||
int get_subst(int index,char **pattern,char **substitution);
|
||||
stringpair *find_subst(char *name,int length);
|
||||
int delete_subst(char *name,int length);
|
||||
void delete_substtable(void);
|
||||
stringlist *insert_sourcefile(char *string);
|
||||
char *get_sourcefile(int index);
|
||||
void delete_sourcefiletable(void);
|
||||
stringlist *insert_docstring(char *string);
|
||||
char *get_docstring(int index);
|
||||
void delete_docstring(int index);
|
||||
void delete_docstringtable(void);
|
||||
stringlist *insert_autolist(const char *string);
|
||||
char *get_autolist(int index);
|
||||
void delete_autolisttable(void);
|
||||
stringlist *insert_dbgfile(const char *filename);
|
||||
stringlist *insert_dbgline(int linenr);
|
||||
stringlist *insert_dbgsymbol(symbol *sym);
|
||||
char *get_dbgstring(int index);
|
||||
void delete_dbgstringtable(void);
|
||||
stringlist *get_dbgstrings();
|
||||
|
||||
/* function prototypes in SCI18N.C */
|
||||
#define MAXCODEPAGE 12
|
||||
SC_FUNC int cp_path(const char *root,const char *directory);
|
||||
SC_FUNC int cp_set(const char *name);
|
||||
SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endptr);
|
||||
SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **endptr);
|
||||
SC_FUNC int scan_utf8(FILE *fp,const char *filename);
|
||||
int cp_path(const char *root,const char *directory);
|
||||
int cp_set(const char *name);
|
||||
cell cp_translate(const unsigned char *string,const unsigned char **endptr);
|
||||
cell get_utf8_char(const unsigned char *string,const unsigned char **endptr);
|
||||
int scan_utf8(void *fp,const char *filename);
|
||||
|
||||
/* function prototypes in SCSTATE.C */
|
||||
SC_FUNC constvalue *automaton_add(const char *name);
|
||||
SC_FUNC constvalue *automaton_find(const char *name);
|
||||
SC_FUNC constvalue *automaton_findid(int id);
|
||||
SC_FUNC constvalue *state_add(const char *name,int fsa_id);
|
||||
SC_FUNC constvalue *state_find(const char *name,int fsa_id);
|
||||
SC_FUNC constvalue *state_findid(int id);
|
||||
SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid);
|
||||
SC_FUNC int state_addlist(int *list,int count,int fsa_id);
|
||||
SC_FUNC void state_deletetable(void);
|
||||
SC_FUNC int state_getfsa(int listid);
|
||||
SC_FUNC int state_count(int listid);
|
||||
SC_FUNC int state_inlist(int listid,int state);
|
||||
SC_FUNC int state_listitem(int listid,int index);
|
||||
SC_FUNC void state_conflict(symbol *root);
|
||||
SC_FUNC int state_conflict_id(int listid1,int listid2);
|
||||
constvalue *automaton_add(const char *name);
|
||||
constvalue *automaton_find(const char *name);
|
||||
constvalue *automaton_findid(int id);
|
||||
constvalue *state_add(const char *name,int fsa_id);
|
||||
constvalue *state_find(const char *name,int fsa_id);
|
||||
constvalue *state_findid(int id);
|
||||
void state_buildlist(int **list,int *listsize,int *count,int stateid);
|
||||
int state_addlist(int *list,int count,int fsa_id);
|
||||
void state_deletetable(void);
|
||||
int state_getfsa(int listid);
|
||||
int state_count(int listid);
|
||||
int state_inlist(int listid,int state);
|
||||
int state_listitem(int listid,int index);
|
||||
void state_conflict(symbol *root);
|
||||
int state_conflict_id(int listid1,int listid2);
|
||||
|
||||
/* external variables (defined in scvars.c) */
|
||||
#if !defined SC_SKIP_VDECL
|
||||
typedef struct HashTable HashTable;
|
||||
SC_VDECL struct HashTable *sp_Globals;
|
||||
SC_VDECL symbol loctab; /* local symbol table */
|
||||
SC_VDECL symbol glbtab; /* global symbol table */
|
||||
SC_VDECL cell *litq; /* the literal queue */
|
||||
SC_VDECL unsigned char pline[]; /* the line read from the input file */
|
||||
SC_VDECL const unsigned char *lptr;/* points to the current position in "pline" */
|
||||
SC_VDECL constvalue tagname_tab;/* tagname table */
|
||||
SC_VDECL constvalue libname_tab;/* library table (#pragma library "..." syntax) */
|
||||
SC_VDECL constvalue *curlibrary;/* current library */
|
||||
SC_VDECL int pc_addlibtable; /* is the library table added to the AMX file? */
|
||||
SC_VDECL symbol *curfunc; /* pointer to current function */
|
||||
SC_VDECL char *inpfname; /* name of the file currently read from */
|
||||
SC_VDECL char outfname[]; /* intermediate (assembler) file name */
|
||||
SC_VDECL char binfname[]; /* binary file name */
|
||||
SC_VDECL char errfname[]; /* error file name */
|
||||
SC_VDECL char sc_ctrlchar; /* the control character (or escape character) */
|
||||
SC_VDECL char sc_ctrlchar_org;/* the default control character */
|
||||
SC_VDECL int litidx; /* index to literal table */
|
||||
SC_VDECL int litmax; /* current size of the literal table */
|
||||
SC_VDECL int stgidx; /* index to the staging buffer */
|
||||
SC_VDECL int sc_labnum; /* number of (internal) labels */
|
||||
SC_VDECL int staging; /* true if staging output */
|
||||
SC_VDECL cell declared; /* number of local cells declared */
|
||||
SC_VDECL cell glb_declared; /* number of global cells declared */
|
||||
SC_VDECL cell code_idx; /* number of bytes with generated code */
|
||||
SC_VDECL int ntv_funcid; /* incremental number of native function */
|
||||
SC_VDECL int errnum; /* number of errors */
|
||||
SC_VDECL int warnnum; /* number of warnings */
|
||||
SC_VDECL int sc_debug; /* debug/optimization options (bit field) */
|
||||
SC_VDECL int sc_packstr; /* strings are packed by default? */
|
||||
SC_VDECL int sc_asmfile; /* create .ASM file? */
|
||||
SC_VDECL int sc_listing; /* create .LST file? */
|
||||
SC_VDECL int sc_compress; /* compress bytecode? */
|
||||
SC_VDECL int sc_needsemicolon;/* semicolon required to terminate expressions? */
|
||||
SC_VDECL int sc_dataalign; /* data alignment value */
|
||||
SC_VDECL int sc_alignnext; /* must frame of the next function be aligned? */
|
||||
SC_VDECL int pc_docexpr; /* must expression be attached to documentation comment? */
|
||||
SC_VDECL int sc_showincludes; /* show include files? */
|
||||
SC_VDECL int curseg; /* 1 if currently parsing CODE, 2 if parsing DATA */
|
||||
SC_VDECL cell pc_stksize; /* stack size */
|
||||
SC_VDECL cell pc_amxlimit; /* abstract machine size limit (code + data, or only code) */
|
||||
SC_VDECL cell pc_amxram; /* abstract machine data size limit */
|
||||
SC_VDECL int freading; /* is there an input file ready for reading? */
|
||||
SC_VDECL int fline; /* the line number in the current file */
|
||||
SC_VDECL short fnumber; /* number of files in the file table (debugging) */
|
||||
SC_VDECL short fcurrent; /* current file being processed (debugging) */
|
||||
SC_VDECL short sc_intest; /* true if inside a test */
|
||||
SC_VDECL int sideeffect; /* true if an expression causes a side-effect */
|
||||
SC_VDECL int stmtindent; /* current indent of the statement */
|
||||
SC_VDECL int indent_nowarn; /* skip warning "217 loose indentation" */
|
||||
SC_VDECL int sc_tabsize; /* number of spaces that a TAB represents */
|
||||
SC_VDECL short sc_allowtags; /* allow/detect tagnames in lex() */
|
||||
SC_VDECL int sc_status; /* read/write status */
|
||||
SC_VDECL int sc_err_status; /* TRUE if errors should be generated even if sc_status = SKIP */
|
||||
SC_VDECL int sc_rationaltag; /* tag for rational numbers */
|
||||
SC_VDECL int rational_digits; /* number of fractional digits */
|
||||
SC_VDECL int sc_allowproccall;/* allow/detect tagnames in lex() */
|
||||
SC_VDECL short sc_is_utf8; /* is this source file in UTF-8 encoding */
|
||||
SC_VDECL char *pc_deprecate; /* if non-NULL, mark next declaration as deprecated */
|
||||
SC_VDECL int sc_curstates; /* ID of the current state list */
|
||||
SC_VDECL int pc_optimize; /* (peephole) optimization level */
|
||||
SC_VDECL int pc_memflags; /* special flags for the stack/heap usage */
|
||||
SC_VDECL int pc_functag; /* global function tag */
|
||||
SC_VDECL int pc_tag_string; /* global String tag */
|
||||
SC_VDECL int pc_tag_void; /* global void tag */
|
||||
SC_VDECL int pc_tag_object; /* root object tag */
|
||||
SC_VDECL int pc_tag_bool; /* global bool tag */
|
||||
SC_VDECL int pc_tag_null_t; /* the null type */
|
||||
SC_VDECL int pc_tag_nullfunc_t; /* the null function type */
|
||||
SC_VDECL int pc_anytag; /* global any tag */
|
||||
SC_VDECL int glbstringread; /* last global string read */
|
||||
SC_VDECL int sc_require_newdecls; /* only newdecls are allowed */
|
||||
extern struct HashTable *sp_Globals;
|
||||
extern symbol loctab; /* local symbol table */
|
||||
extern symbol glbtab; /* global symbol table */
|
||||
extern cell *litq; /* the literal queue */
|
||||
extern unsigned char pline[]; /* the line read from the input file */
|
||||
extern const unsigned char *lptr;/* points to the current position in "pline" */
|
||||
extern constvalue tagname_tab;/* tagname table */
|
||||
extern constvalue libname_tab;/* library table (#pragma library "..." syntax) */
|
||||
extern constvalue *curlibrary;/* current library */
|
||||
extern int pc_addlibtable; /* is the library table added to the AMX file? */
|
||||
extern symbol *curfunc; /* pointer to current function */
|
||||
extern char *inpfname; /* name of the file currently read from */
|
||||
extern char outfname[]; /* intermediate (assembler) file name */
|
||||
extern char binfname[]; /* binary file name */
|
||||
extern char errfname[]; /* error file name */
|
||||
extern char sc_ctrlchar; /* the control character (or escape character) */
|
||||
extern char sc_ctrlchar_org;/* the default control character */
|
||||
extern int litidx; /* index to literal table */
|
||||
extern int litmax; /* current size of the literal table */
|
||||
extern int stgidx; /* index to the staging buffer */
|
||||
extern int sc_labnum; /* number of (internal) labels */
|
||||
extern int staging; /* true if staging output */
|
||||
extern cell declared; /* number of local cells declared */
|
||||
extern cell glb_declared; /* number of global cells declared */
|
||||
extern cell code_idx; /* number of bytes with generated code */
|
||||
extern int ntv_funcid; /* incremental number of native function */
|
||||
extern int errnum; /* number of errors */
|
||||
extern int warnnum; /* number of warnings */
|
||||
extern int sc_debug; /* debug/optimization options (bit field) */
|
||||
extern int sc_packstr; /* strings are packed by default? */
|
||||
extern int sc_asmfile; /* create .ASM file? */
|
||||
extern int sc_listing; /* create .LST file? */
|
||||
extern int sc_compress; /* compress bytecode? */
|
||||
extern int sc_needsemicolon;/* semicolon required to terminate expressions? */
|
||||
extern int sc_dataalign; /* data alignment value */
|
||||
extern int sc_alignnext; /* must frame of the next function be aligned? */
|
||||
extern int pc_docexpr; /* must expression be attached to documentation comment? */
|
||||
extern int sc_showincludes; /* show include files? */
|
||||
extern int curseg; /* 1 if currently parsing CODE, 2 if parsing DATA */
|
||||
extern cell pc_stksize; /* stack size */
|
||||
extern cell pc_amxlimit; /* abstract machine size limit (code + data, or only code) */
|
||||
extern cell pc_amxram; /* abstract machine data size limit */
|
||||
extern int freading; /* is there an input file ready for reading? */
|
||||
extern int fline; /* the line number in the current file */
|
||||
extern short fnumber; /* number of files in the file table (debugging) */
|
||||
extern short fcurrent; /* current file being processed (debugging) */
|
||||
extern short sc_intest; /* true if inside a test */
|
||||
extern int sideeffect; /* true if an expression causes a side-effect */
|
||||
extern int stmtindent; /* current indent of the statement */
|
||||
extern int indent_nowarn; /* skip warning "217 loose indentation" */
|
||||
extern int sc_tabsize; /* number of spaces that a TAB represents */
|
||||
extern short sc_allowtags; /* allow/detect tagnames in lex() */
|
||||
extern int sc_status; /* read/write status */
|
||||
extern int sc_err_status; /* TRUE if errors should be generated even if sc_status = SKIP */
|
||||
extern int sc_rationaltag; /* tag for rational numbers */
|
||||
extern int rational_digits; /* number of fractional digits */
|
||||
extern int sc_allowproccall;/* allow/detect tagnames in lex() */
|
||||
extern short sc_is_utf8; /* is this source file in UTF-8 encoding */
|
||||
extern char *pc_deprecate; /* if non-NULL, mark next declaration as deprecated */
|
||||
extern int sc_curstates; /* ID of the current state list */
|
||||
extern int pc_optimize; /* (peephole) optimization level */
|
||||
extern int pc_memflags; /* special flags for the stack/heap usage */
|
||||
extern int pc_functag; /* global function tag */
|
||||
extern int pc_tag_string; /* global String tag */
|
||||
extern int pc_tag_void; /* global void tag */
|
||||
extern int pc_tag_object; /* root object tag */
|
||||
extern int pc_tag_bool; /* global bool tag */
|
||||
extern int pc_tag_null_t; /* the null type */
|
||||
extern int pc_tag_nullfunc_t; /* the null function type */
|
||||
extern int pc_anytag; /* global any tag */
|
||||
extern int glbstringread; /* last global string read */
|
||||
extern int sc_require_newdecls; /* only newdecls are allowed */
|
||||
|
||||
SC_VDECL constvalue sc_automaton_tab; /* automaton table */
|
||||
SC_VDECL constvalue sc_state_tab; /* state table */
|
||||
extern constvalue sc_automaton_tab; /* automaton table */
|
||||
extern constvalue sc_state_tab; /* state table */
|
||||
|
||||
SC_VDECL FILE *inpf; /* file read from (source or include) */
|
||||
SC_VDECL FILE *inpf_org; /* main source file */
|
||||
SC_VDECL FILE *outf; /* file written to */
|
||||
extern void *inpf; /* file read from (source or include) */
|
||||
extern void *inpf_org; /* main source file */
|
||||
extern void *outf; /* file written to */
|
||||
|
||||
SC_VDECL jmp_buf errbuf; /* target of longjmp() on a fatal error */
|
||||
extern jmp_buf errbuf; /* target of longjmp() on a fatal error */
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
SC_VDECL int sc_makereport; /* generate a cross-reference report */
|
||||
extern int sc_makereport; /* generate a cross-reference report */
|
||||
#endif
|
||||
|
||||
#if defined WIN32
|
||||
|
@ -193,9 +193,6 @@ char g_tmpfile[_MAX_PATH] = {0};
|
||||
|
||||
/* "main" of the compiler
|
||||
*/
|
||||
#if defined __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int pc_compile(int argc, char *argv[])
|
||||
{
|
||||
int entry,i,jmpcode;
|
||||
@ -582,10 +579,7 @@ cleanup:
|
||||
return retcode;
|
||||
}
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int pc_addconstant(char *name,cell value,int tag)
|
||||
int pc_addconstant(const char *name,cell value,int tag)
|
||||
{
|
||||
errorset(sFORCESET,0); /* make sure error engine is silenced */
|
||||
sc_status=statIDLE;
|
||||
@ -678,20 +672,19 @@ int pc_findtag(const char *name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if defined __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
int pc_addtag(char *name)
|
||||
int pc_addtag(const char *name)
|
||||
{
|
||||
int val;
|
||||
int flags = 0;
|
||||
|
||||
if (name==NULL) {
|
||||
/* no tagname was given, check for one */
|
||||
if (lex(&val,&name)!=tLABEL) {
|
||||
char *nameptr;
|
||||
if (lex(&val,&nameptr)!=tLABEL) {
|
||||
lexpush();
|
||||
return 0; /* untagged */
|
||||
} /* if */
|
||||
name = nameptr;
|
||||
} /* if */
|
||||
|
||||
if (isupper(*name))
|
||||
@ -700,7 +693,7 @@ int pc_addtag(char *name)
|
||||
return pc_addtag_flags(name, flags);
|
||||
}
|
||||
|
||||
int pc_addtag_flags(char *name, int flags)
|
||||
int pc_addtag_flags(const char *name, int flags)
|
||||
{
|
||||
constvalue *ptr;
|
||||
int last,tag;
|
||||
@ -831,7 +824,7 @@ static char *get_extension(char *filename)
|
||||
* Set the default extension, or force an extension. To erase the
|
||||
* extension of a filename, set "extension" to an empty string.
|
||||
*/
|
||||
SC_FUNC void set_extension(char *filename,char *extension,int force)
|
||||
void set_extension(char *filename,const char *extension,int force)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
@ -1362,35 +1355,14 @@ static void setconstants(void)
|
||||
add_constant("false",0,sGLOBAL,1);
|
||||
add_constant("EOS",0,sGLOBAL,0); /* End Of String, or '\0' */
|
||||
add_constant("INVALID_FUNCTION", -1, sGLOBAL, pc_tag_nullfunc_t);
|
||||
#if PAWN_CELL_SIZE==16
|
||||
add_constant("cellbits",16,sGLOBAL,0);
|
||||
#if defined _I16_MAX
|
||||
add_constant("cellmax",_I16_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I16_MIN,sGLOBAL,0);
|
||||
#else
|
||||
add_constant("cellmax",SHRT_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",SHRT_MIN,sGLOBAL,0);
|
||||
#endif
|
||||
#elif PAWN_CELL_SIZE==32
|
||||
add_constant("cellbits",32,sGLOBAL,0);
|
||||
#if defined _I32_MAX
|
||||
add_constant("cellmax",_I32_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I32_MIN,sGLOBAL,0);
|
||||
#else
|
||||
add_constant("cellmax",LONG_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",LONG_MIN,sGLOBAL,0);
|
||||
#endif
|
||||
#elif PAWN_CELL_SIZE==64
|
||||
#if !defined _I64_MIN
|
||||
#define _I64_MIN (-9223372036854775807ULL - 1)
|
||||
#define _I64_MAX 9223372036854775807ULL
|
||||
#endif
|
||||
add_constant("cellbits",64,sGLOBAL,0);
|
||||
add_constant("cellmax",_I64_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I64_MIN,sGLOBAL,0);
|
||||
#else
|
||||
#error Unsupported cell size
|
||||
#endif
|
||||
add_constant("cellbits",32,sGLOBAL,0);
|
||||
#if defined _I32_MAX
|
||||
add_constant("cellmax",_I32_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",_I32_MIN,sGLOBAL,0);
|
||||
#else
|
||||
add_constant("cellmax",LONG_MAX,sGLOBAL,0);
|
||||
add_constant("cellmin",LONG_MIN,sGLOBAL,0);
|
||||
#endif
|
||||
add_constant("charbits",sCHARBITS,sGLOBAL,0);
|
||||
add_constant("charmin",0,sGLOBAL,0);
|
||||
add_constant("charmax",~(-1 << sCHARBITS) - 1,sGLOBAL,0);
|
||||
@ -2794,7 +2766,7 @@ static cell init(int ident,int *tag,int *errorfound)
|
||||
litidx=1; /* reset literal queue */
|
||||
} /* if */
|
||||
*tag=pc_tag_string;
|
||||
} else if (constexpr(&i,tag,NULL)){
|
||||
} else if (exprconst(&i,tag,NULL)){
|
||||
litadd(i); /* store expression result in literal table */
|
||||
} else {
|
||||
if (errorfound!=NULL)
|
||||
@ -2819,7 +2791,7 @@ static cell needsub(int *tag,constvalue **enumroot)
|
||||
if (matchtoken(']')) /* we have already seen "[" */
|
||||
return 0; /* zero size (like "char msg[]") */
|
||||
|
||||
constexpr(&val,tag,&sym); /* get value (must be constant expression) */
|
||||
exprconst(&val,tag,&sym); /* get value (must be constant expression) */
|
||||
if (val<0) {
|
||||
error(9); /* negative array size is invalid; assumed zero */
|
||||
val=0;
|
||||
@ -2891,7 +2863,7 @@ static void decl_const(int vclass)
|
||||
|
||||
symbolline=fline; /* save line where symbol was found */
|
||||
needtoken('=');
|
||||
constexpr(&val,&exprtag,NULL); /* get value */
|
||||
exprconst(&val,&exprtag,NULL); /* get value */
|
||||
|
||||
/* add_constant() checks for duplicate definitions */
|
||||
/* temporarily reset the line number to where the symbol was defined */
|
||||
@ -4059,19 +4031,36 @@ static void domethodmap(LayoutSpec spec)
|
||||
require_newline(TRUE);
|
||||
}
|
||||
|
||||
class AutoStage
|
||||
{
|
||||
public:
|
||||
AutoStage() : lcl_staging_(FALSE)
|
||||
{
|
||||
if (!staging) {
|
||||
stgset(TRUE);
|
||||
lcl_staging_ = TRUE;
|
||||
lcl_stgidx_ = stgidx;
|
||||
assert(stgidx == 0);
|
||||
}
|
||||
}
|
||||
~AutoStage() {
|
||||
if (lcl_staging_) {
|
||||
stgout(lcl_stgidx_);
|
||||
stgset(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
int lcl_staging_;
|
||||
int lcl_stgidx_;
|
||||
};
|
||||
|
||||
// delete ::= "delete" expr
|
||||
static void dodelete()
|
||||
{
|
||||
AutoStage staging_on;
|
||||
|
||||
svalue sval;
|
||||
|
||||
int lcl_staging = FALSE;
|
||||
if (!staging) {
|
||||
stgset(TRUE);
|
||||
lcl_staging = TRUE;
|
||||
assert(stgidx == 0);
|
||||
}
|
||||
int lcl_stgidx = stgidx;
|
||||
|
||||
int ident = lvalexpr(&sval);
|
||||
needtoken(tTERM);
|
||||
|
||||
@ -4079,7 +4068,7 @@ static void dodelete()
|
||||
case iFUNCTN:
|
||||
case iREFFUNC:
|
||||
error(115, "functions");
|
||||
goto cleanup;
|
||||
return;
|
||||
|
||||
case iARRAY:
|
||||
case iREFARRAY:
|
||||
@ -4089,7 +4078,7 @@ static void dodelete()
|
||||
symbol *sym = sval.val.sym;
|
||||
if (!sym || sym->dim.array.level > 0) {
|
||||
error(115, "arrays");
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -4097,13 +4086,13 @@ static void dodelete()
|
||||
|
||||
if (sval.val.tag == 0) {
|
||||
error(115, "primitive types or enums");
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
methodmap_t *map = methodmap_find_by_tag(sval.val.tag);
|
||||
if (!map) {
|
||||
error(115, pc_tagname(sval.val.tag));
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
@ -4119,7 +4108,7 @@ static void dodelete()
|
||||
|
||||
if (!map || !map->dtor) {
|
||||
error(115, layout_spec_name(map->spec), map->name);
|
||||
goto cleanup;
|
||||
return;
|
||||
}
|
||||
|
||||
// Only zap non-const lvalues.
|
||||
@ -4180,12 +4169,6 @@ static void dodelete()
|
||||
}
|
||||
|
||||
markexpr(sEXPR, NULL, 0);
|
||||
|
||||
cleanup:
|
||||
if (lcl_staging) {
|
||||
stgout(lcl_stgidx);
|
||||
stgset(FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -4526,11 +4509,11 @@ static void decl_enum(int vclass)
|
||||
multiplier=1;
|
||||
if (matchtoken('(')) {
|
||||
if (matchtoken(taADD)) {
|
||||
constexpr(&increment,NULL,NULL);
|
||||
exprconst(&increment,NULL,NULL);
|
||||
} else if (matchtoken(taMULT)) {
|
||||
constexpr(&multiplier,NULL,NULL);
|
||||
exprconst(&multiplier,NULL,NULL);
|
||||
} else if (matchtoken(taSHL)) {
|
||||
constexpr(&val,NULL,NULL);
|
||||
exprconst(&val,NULL,NULL);
|
||||
while (val-->0)
|
||||
multiplier*=2;
|
||||
} /* if */
|
||||
@ -4571,12 +4554,12 @@ static void decl_enum(int vclass)
|
||||
size=increment; /* default increment of 'val' */
|
||||
fieldtag=0; /* default field tag */
|
||||
if (matchtoken('[')) {
|
||||
constexpr(&size,&fieldtag,NULL); /* get size */
|
||||
exprconst(&size,&fieldtag,NULL); /* get size */
|
||||
needtoken(']');
|
||||
} /* if */
|
||||
/* :TODO: do we need a size modifier here for pc_tag_string? */
|
||||
if (matchtoken('='))
|
||||
constexpr(&value,NULL,NULL); /* get value */
|
||||
exprconst(&value,NULL,NULL); /* get value */
|
||||
/* add_constant() checks whether a variable (global or local) or
|
||||
* a constant with the same name already exists
|
||||
*/
|
||||
@ -4737,7 +4720,7 @@ static int compare_tag(int tag1, int tag2)
|
||||
* Finds a function in the global symbol table or creates a new entry.
|
||||
* It does some basic processing and error checking.
|
||||
*/
|
||||
SC_FUNC symbol *fetchfunc(char *name)
|
||||
symbol *fetchfunc(char *name)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -4966,7 +4949,7 @@ static char *tag2str(char *dest,int tag)
|
||||
return isdigit(dest[1]) ? &dest[1] : dest;
|
||||
}
|
||||
|
||||
SC_FUNC char *operator_symname(char *symname,char *opername,int tag1,int tag2,int numtags,int resulttag)
|
||||
char *operator_symname(char *symname,const char *opername,int tag1,int tag2,int numtags,int resulttag)
|
||||
{
|
||||
char tagstr1[10], tagstr2[10];
|
||||
int opertok;
|
||||
@ -5016,7 +4999,7 @@ constvalue *find_tag_byval(int tag)
|
||||
return tagsym;
|
||||
}
|
||||
|
||||
SC_FUNC char *funcdisplayname(char *dest,char *funcname)
|
||||
char *funcdisplayname(char *dest,char *funcname)
|
||||
{
|
||||
int tags[2];
|
||||
char opname[10];
|
||||
@ -5128,7 +5111,7 @@ static symbol *funcstub(int tokid, declinfo_t *decl, const int *thistag)
|
||||
tokeninfo(&val,&str);
|
||||
insert_alias(sym->name,str);
|
||||
} else {
|
||||
constexpr(&val,NULL,NULL);
|
||||
exprconst(&val,NULL,NULL);
|
||||
sym->addr=val;
|
||||
/* At the moment, I have assumed that this syntax is only valid if
|
||||
* val < 0. To properly mix "normal" native functions and indexed
|
||||
@ -5282,7 +5265,7 @@ static int newfunc(declinfo_t *decl, const int *thistag, int fpublic, int fstati
|
||||
} /* if */
|
||||
|
||||
if ((sym->flags & flgDEPRECATED) != 0 && (sym->usage & uSTOCK) == 0) {
|
||||
char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
|
||||
const char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
|
||||
error(234, decl->name, ptr); /* deprecated (probably a public function) */
|
||||
} /* if */
|
||||
begcseg();
|
||||
@ -5473,7 +5456,7 @@ static int declargs(symbol *sym, int chkshadow, const int *thistag)
|
||||
memset(argptr, 0, sizeof(*argptr));
|
||||
strcpy(argptr->name, "this");
|
||||
argptr->ident = iVARIABLE;
|
||||
argptr->tags = malloc(sizeof(int));
|
||||
argptr->tags = (int *)malloc(sizeof(int));
|
||||
argptr->tags[0] = *thistag;
|
||||
argptr->numtags = 1;
|
||||
} else {
|
||||
@ -5731,7 +5714,7 @@ static void doarg(declinfo_t *decl, int offset, int fpublic, int chkshadow, argi
|
||||
while (paranthese--)
|
||||
needtoken(')');
|
||||
} else {
|
||||
constexpr(&arg->defvalue.val,&arg->defvalue_tag,NULL);
|
||||
exprconst(&arg->defvalue.val,&arg->defvalue_tag,NULL);
|
||||
assert(type->numtags > 0);
|
||||
matchtag(type->tags[0], arg->defvalue_tag, TRUE);
|
||||
} /* if */
|
||||
@ -5776,11 +5759,12 @@ static int count_referrers(symbol *entry)
|
||||
}
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
static int find_xmltag(char *source,char *xmltag,char *xmlparam,char *xmlvalue,
|
||||
static int find_xmltag(char *source, const char *xmltag, const char *xmlparam, const char *xmlvalue,
|
||||
char **outer_start,int *outer_length,
|
||||
char **inner_start,int *inner_length)
|
||||
const char **inner_start,int *inner_length)
|
||||
{
|
||||
char *ptr,*inner_end;
|
||||
char *ptr;
|
||||
const char *inner_end;
|
||||
int xmltag_len,xmlparam_len,xmlvalue_len;
|
||||
int match;
|
||||
|
||||
@ -6123,7 +6107,8 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
|
||||
assert(sym->dim.arglist!=NULL);
|
||||
for (arg=0; sym->dim.arglist[arg].ident!=0; arg++) {
|
||||
int dim,paraminfo;
|
||||
char *outer_start,*inner_start;
|
||||
char *outer_start;
|
||||
const char *inner_start;
|
||||
int outer_length,inner_length;
|
||||
if (sym->dim.arglist[arg].ident==iVARARGS)
|
||||
fprintf(log,"\t\t\t<param name=\"...\">\n");
|
||||
@ -6176,10 +6161,9 @@ static void make_report(symbol *root,FILE *log,char *sourcefile)
|
||||
&& find_xmltag(sym->documentation, "param", "name", sym->dim.arglist[arg].name,
|
||||
&outer_start, &outer_length, &inner_start, &inner_length))
|
||||
{
|
||||
char *tail;
|
||||
fprintf(log,"\t\t\t\t%.*s\n",inner_length,inner_start);
|
||||
/* delete from documentation string */
|
||||
tail=outer_start+outer_length;
|
||||
char *tail=outer_start+outer_length;
|
||||
memmove(outer_start,tail,strlen(tail)+1);
|
||||
} /* if */
|
||||
fprintf(log,"\t\t\t</param>\n");
|
||||
@ -6503,7 +6487,7 @@ static constvalue *insert_constval(constvalue *prev,constvalue *next,const char
|
||||
return cur;
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,int index)
|
||||
constvalue *append_constval(constvalue *table,const char *name,cell val,int index)
|
||||
{
|
||||
constvalue *cur,*prev;
|
||||
|
||||
@ -6513,7 +6497,7 @@ SC_FUNC constvalue *append_constval(constvalue *table,const char *name,cell val,
|
||||
return insert_constval(prev,NULL,name,val,index);
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *find_constval(constvalue *table,char *name,int index)
|
||||
constvalue *find_constval(constvalue *table,char *name,int index)
|
||||
{
|
||||
constvalue *ptr = table->next;
|
||||
|
||||
@ -6556,7 +6540,7 @@ static int delete_constval(constvalue *table,char *name)
|
||||
}
|
||||
#endif
|
||||
|
||||
SC_FUNC void delete_consttable(constvalue *table)
|
||||
void delete_consttable(constvalue *table)
|
||||
{
|
||||
constvalue *cur=table->next, *next;
|
||||
|
||||
@ -6572,7 +6556,7 @@ SC_FUNC void delete_consttable(constvalue *table)
|
||||
*
|
||||
* Adds a symbol to the symbol table. Returns NULL on failure.
|
||||
*/
|
||||
SC_FUNC symbol *add_constant(char *name,cell val,int vclass,int tag)
|
||||
symbol *add_constant(const char *name,cell val,int vclass,int tag)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -6904,9 +6888,9 @@ static int doexpr2(int comma,int chkeffect,int allowarray,int mark_endexpr,
|
||||
return ident;
|
||||
}
|
||||
|
||||
/* constexpr
|
||||
/* exprconst
|
||||
*/
|
||||
SC_FUNC int constexpr(cell *val,int *tag,symbol **symptr)
|
||||
int exprconst(cell *val,int *tag,symbol **symptr)
|
||||
{
|
||||
int ident,index;
|
||||
cell cidx;
|
||||
@ -6981,7 +6965,7 @@ static int test(int label,int parens,int invert)
|
||||
if (endtok!=0)
|
||||
needtoken(endtok);
|
||||
if (ident==iARRAY || ident==iREFARRAY) {
|
||||
char *ptr=(sym->name!=NULL) ? sym->name : "-unknown-";
|
||||
const char *ptr=(sym->name!=NULL) ? sym->name : "-unknown-";
|
||||
error(33,ptr); /* array must be indexed */
|
||||
} /* if */
|
||||
if (ident==iCONSTEXPR) { /* constant expression */
|
||||
@ -7297,7 +7281,7 @@ static void doswitch(void)
|
||||
* parse all expressions until that special token.
|
||||
*/
|
||||
|
||||
constexpr(&val,NULL,NULL);
|
||||
exprconst(&val,NULL,NULL);
|
||||
/* Search the insertion point (the table is kept in sorted order, so
|
||||
* that advanced abstract machines can sift the case table with a
|
||||
* binary search). Check for duplicate case values at the same time.
|
||||
@ -7643,7 +7627,7 @@ static void docont(void)
|
||||
jumplabel(ptr[wqLOOP]);
|
||||
}
|
||||
|
||||
SC_FUNC void exporttag(int tag)
|
||||
void exporttag(int tag)
|
||||
{
|
||||
/* find the tag by value in the table, then set the top bit to mark it
|
||||
* "public"
|
@ -47,7 +47,7 @@ static cell litchar(const unsigned char **lptr,int flags);
|
||||
static symbol *find_symbol(const symbol *root,const char *name,int fnumber,int automaton,int *cmptag);
|
||||
|
||||
static void substallpatterns(unsigned char *line,int buffersize);
|
||||
static int match(char *st,int end);
|
||||
static int match(const char *st,int end);
|
||||
static int alpha(char c);
|
||||
|
||||
#define SKIPMODE 1 /* bit field in "#if" stack */
|
||||
@ -86,7 +86,7 @@ static double pow10(double d)
|
||||
static stkitem *stack=NULL;
|
||||
static int stkidx=0,stktop=0;
|
||||
|
||||
SC_FUNC void pushstk(stkitem val)
|
||||
void pushstk(stkitem val)
|
||||
{
|
||||
assert(stkidx<=stktop);
|
||||
if (stkidx==stktop) {
|
||||
@ -109,7 +109,7 @@ SC_FUNC void pushstk(stkitem val)
|
||||
stkidx+=1;
|
||||
}
|
||||
|
||||
SC_FUNC stkitem popstk(void)
|
||||
stkitem popstk(void)
|
||||
{
|
||||
if (stkidx==0) {
|
||||
stkitem s;
|
||||
@ -121,7 +121,7 @@ SC_FUNC stkitem popstk(void)
|
||||
return stack[stkidx];
|
||||
}
|
||||
|
||||
SC_FUNC void clearstk(void)
|
||||
void clearstk(void)
|
||||
{
|
||||
assert(stack!=NULL || stktop==0);
|
||||
if (stack!=NULL) {
|
||||
@ -132,9 +132,10 @@ SC_FUNC void clearstk(void)
|
||||
assert(stktop==0);
|
||||
}
|
||||
|
||||
SC_FUNC int plungequalifiedfile(char *name)
|
||||
int plungequalifiedfile(char *name)
|
||||
{
|
||||
static char *extensions[] = { ".inc", ".p", ".pawn" };
|
||||
static const char *extensions[] = { ".inc", ".p", ".pawn" };
|
||||
|
||||
void *fp;
|
||||
char *ext;
|
||||
int ext_idx;
|
||||
@ -184,7 +185,7 @@ static char *extensions[] = { ".inc", ".p", ".pawn" };
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC int plungefile(char *name,int try_currentpath,int try_includepaths)
|
||||
int plungefile(char *name,int try_currentpath,int try_includepaths)
|
||||
{
|
||||
int result=FALSE;
|
||||
|
||||
@ -796,7 +797,7 @@ static int preproc_expr(cell *val,int *tag)
|
||||
term=strchr((char*)pline,'\0');
|
||||
assert(term!=NULL);
|
||||
chrcat((char*)pline,PREPROC_TERM); /* the "DEL" code (see SC.H) */
|
||||
result=constexpr(val,tag,NULL); /* get value (or 0 on error) */
|
||||
result=exprconst(val,tag,NULL); /* get value (or 0 on error) */
|
||||
*term='\0'; /* erase the token (if still present) */
|
||||
lexclr(FALSE); /* clear any "pushed" tokens */
|
||||
return result;
|
||||
@ -1251,7 +1252,7 @@ static int command(void)
|
||||
break;
|
||||
default: {
|
||||
char s2[20];
|
||||
extern char *sc_tokens[];/* forward declaration */
|
||||
extern const char *sc_tokens[];/* forward declaration */
|
||||
if (tok<256)
|
||||
sprintf(s2,"%c",(char)tok);
|
||||
else
|
||||
@ -1482,7 +1483,7 @@ static char *strdel(char *str,size_t len)
|
||||
return str;
|
||||
}
|
||||
|
||||
static char *strins(char *dest,char *src,size_t srclen)
|
||||
static char *strins(char *dest,const char *src,size_t srclen)
|
||||
{
|
||||
size_t destlen=strlen(dest);
|
||||
assert(srclen<=strlen(src));
|
||||
@ -1792,7 +1793,7 @@ static int scanellipsis(const unsigned char *lptr)
|
||||
* pline (altered)
|
||||
* freading (referred to only)
|
||||
*/
|
||||
SC_FUNC void preprocess(void)
|
||||
void preprocess(void)
|
||||
{
|
||||
int iscommand;
|
||||
|
||||
@ -1931,7 +1932,7 @@ static full_token_t *next_token()
|
||||
return &sTokenBuffer->tokens[cursor];
|
||||
}
|
||||
|
||||
SC_FUNC void lexinit(void)
|
||||
void lexinit(void)
|
||||
{
|
||||
stkidx=0; /* index for pushstk() and popstk() */
|
||||
iflevel=0; /* preprocessor: nesting of "#if" is currently 0 */
|
||||
@ -1943,7 +1944,7 @@ SC_FUNC void lexinit(void)
|
||||
sTokenBuffer = &sNormalBuffer;
|
||||
}
|
||||
|
||||
char *sc_tokens[] = {
|
||||
const char *sc_tokens[] = {
|
||||
"*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=",
|
||||
"||", "&&", "==", "!=", "<=", ">=", "<<", ">>>", ">>", "++", "--",
|
||||
"...", "..", "::",
|
||||
@ -2000,10 +2001,9 @@ static void lexpop()
|
||||
sTokenBuffer->cursor = 0;
|
||||
}
|
||||
|
||||
SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
||||
int lex(cell *lexvalue,char **lexsym)
|
||||
{
|
||||
int i,toolong,newline;
|
||||
char **tokptr;
|
||||
const unsigned char *starttoken;
|
||||
|
||||
if (sTokenBuffer->depth > 0) {
|
||||
@ -2054,7 +2054,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
||||
tok->start.col = (int)(lptr - pline);
|
||||
|
||||
i=tFIRST;
|
||||
tokptr=sc_tokens;
|
||||
const char **tokptr=sc_tokens;
|
||||
while (i<=tMIDDLE) { /* match multi-character operators */
|
||||
if (*lptr==**tokptr && match(*tokptr,FALSE)) {
|
||||
tok->id = i;
|
||||
@ -2259,7 +2259,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
|
||||
* to read and return the information from these variables, rather than
|
||||
* to read in a new token from the input file.
|
||||
*/
|
||||
SC_FUNC void lexpush(void)
|
||||
void lexpush(void)
|
||||
{
|
||||
assert(sTokenBuffer->depth < MAX_TOKEN_DEPTH);
|
||||
sTokenBuffer->depth++;
|
||||
@ -2276,7 +2276,7 @@ SC_FUNC void lexpush(void)
|
||||
* symbol (a not continue with some old one). This is required upon return
|
||||
* from Assembler mode, and in a few cases after detecting an syntax error.
|
||||
*/
|
||||
SC_FUNC void lexclr(int clreol)
|
||||
void lexclr(int clreol)
|
||||
{
|
||||
sTokenBuffer->depth = 0;
|
||||
if (clreol) {
|
||||
@ -2286,7 +2286,7 @@ SC_FUNC void lexclr(int clreol)
|
||||
}
|
||||
|
||||
// Return true if the symbol is ahead, false otherwise.
|
||||
SC_FUNC int lexpeek(int id)
|
||||
int lexpeek(int id)
|
||||
{
|
||||
if (matchtoken(id)) {
|
||||
lexpush();
|
||||
@ -2305,7 +2305,7 @@ SC_FUNC int lexpeek(int id)
|
||||
* (i.e. not present in the source code) should not be pushed back, which is
|
||||
* why it is sometimes important to distinguish the two.
|
||||
*/
|
||||
SC_FUNC int matchtoken(int token)
|
||||
int matchtoken(int token)
|
||||
{
|
||||
cell val;
|
||||
char *str;
|
||||
@ -2338,7 +2338,7 @@ SC_FUNC int matchtoken(int token)
|
||||
*
|
||||
* The token itself is the return value. Normally, this one is already known.
|
||||
*/
|
||||
SC_FUNC int tokeninfo(cell *val,char **str)
|
||||
int tokeninfo(cell *val,char **str)
|
||||
{
|
||||
*val = current_token()->value;
|
||||
*str = current_token()->str;
|
||||
@ -2352,7 +2352,7 @@ SC_FUNC int tokeninfo(cell *val,char **str)
|
||||
* this function returns 1 for "token found" and 2 for "statement termination
|
||||
* token" found; see function matchtoken() for details.
|
||||
*/
|
||||
SC_FUNC int needtoken(int token)
|
||||
int needtoken(int token)
|
||||
{
|
||||
char s1[20],s2[20];
|
||||
int t;
|
||||
@ -2379,7 +2379,7 @@ SC_FUNC int needtoken(int token)
|
||||
|
||||
// If the next token is on the current line, return that token. Otherwise,
|
||||
// return tNEWLINE.
|
||||
SC_FUNC int peek_same_line()
|
||||
int peek_same_line()
|
||||
{
|
||||
// We should not call this without having parsed at least one token.
|
||||
assert(sTokenBuffer->num_tokens > 0);
|
||||
@ -2407,7 +2407,7 @@ SC_FUNC int peek_same_line()
|
||||
return tEOL;
|
||||
}
|
||||
|
||||
SC_FUNC int require_newline(int allow_semi)
|
||||
int require_newline(int allow_semi)
|
||||
{
|
||||
if (allow_semi) {
|
||||
// Semicolon must be on the same line.
|
||||
@ -2440,7 +2440,7 @@ SC_FUNC int require_newline(int allow_semi)
|
||||
*
|
||||
* Global references: lptr (altered)
|
||||
*/
|
||||
static int match(char *st,int end)
|
||||
static int match(const char *st,int end)
|
||||
{
|
||||
int k;
|
||||
const unsigned char *ptr;
|
||||
@ -2482,7 +2482,7 @@ static void chk_grow_litq(void)
|
||||
* Global references: litidx (altered)
|
||||
* litq (altered)
|
||||
*/
|
||||
SC_FUNC void litadd(cell value)
|
||||
void litadd(cell value)
|
||||
{
|
||||
chk_grow_litq();
|
||||
assert(litidx<litmax);
|
||||
@ -2497,7 +2497,7 @@ SC_FUNC void litadd(cell value)
|
||||
* Global references: litidx (altered)
|
||||
* litq (altered)
|
||||
*/
|
||||
SC_FUNC void litinsert(cell value,int pos)
|
||||
void litinsert(cell value,int pos)
|
||||
{
|
||||
chk_grow_litq();
|
||||
assert(litidx<litmax);
|
||||
@ -2632,7 +2632,7 @@ static int alpha(char c)
|
||||
*
|
||||
* Test if character "c" is alphanumeric ("a".."z", "0".."9", "_" or "@")
|
||||
*/
|
||||
SC_FUNC int alphanum(char c)
|
||||
int alphanum(char c)
|
||||
{
|
||||
return (alpha(c) || isdigit(c));
|
||||
}
|
||||
@ -2641,7 +2641,7 @@ SC_FUNC int alphanum(char c)
|
||||
*
|
||||
* Test if character "c" is a hexadecimal digit ("0".."9" or "a".."f").
|
||||
*/
|
||||
SC_FUNC int ishex(char c)
|
||||
int ishex(char c)
|
||||
{
|
||||
return (c>='0' && c<='9') || (c>='a' && c<='f') || (c>='A' && c<='F');
|
||||
}
|
||||
@ -2717,7 +2717,7 @@ static void free_symbol(symbol *sym)
|
||||
free(sym);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_symbol(symbol *root,symbol *sym)
|
||||
void delete_symbol(symbol *root,symbol *sym)
|
||||
{
|
||||
symbol *origRoot=root;
|
||||
/* find the symbol and its predecessor
|
||||
@ -2738,7 +2738,7 @@ SC_FUNC void delete_symbol(symbol *root,symbol *sym)
|
||||
free_symbol(sym);
|
||||
}
|
||||
|
||||
SC_FUNC int get_actual_compound(symbol *sym)
|
||||
int get_actual_compound(symbol *sym)
|
||||
{
|
||||
if (sym->ident == iARRAY || sym->ident == iREFARRAY) {
|
||||
while (sym->parent)
|
||||
@ -2748,7 +2748,7 @@ SC_FUNC int get_actual_compound(symbol *sym)
|
||||
return sym->compound;
|
||||
}
|
||||
|
||||
SC_FUNC void delete_symbols(symbol *root,int level,int delete_labels,int delete_functions)
|
||||
void delete_symbols(symbol *root,int level,int delete_labels,int delete_functions)
|
||||
{
|
||||
symbol *origRoot=root;
|
||||
symbol *sym,*parent_sym;
|
||||
@ -2908,7 +2908,7 @@ static symbol *find_symbol_child(const symbol *root,const symbol *sym)
|
||||
* bywhom will be the function that uses a variable or that calls
|
||||
* the function.
|
||||
*/
|
||||
SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom)
|
||||
int refer_symbol(symbol *entry,symbol *bywhom)
|
||||
{
|
||||
int count;
|
||||
|
||||
@ -2950,7 +2950,7 @@ SC_FUNC int refer_symbol(symbol *entry,symbol *bywhom)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC void markusage(symbol *sym,int usage)
|
||||
void markusage(symbol *sym,int usage)
|
||||
{
|
||||
assert(sym!=NULL);
|
||||
sym->usage |= (char)usage;
|
||||
@ -2974,7 +2974,7 @@ SC_FUNC void markusage(symbol *sym,int usage)
|
||||
*
|
||||
* Returns a pointer to the global symbol (if found) or NULL (if not found)
|
||||
*/
|
||||
SC_FUNC symbol *findglb(const char *name,int filter)
|
||||
symbol *findglb(const char *name,int filter)
|
||||
{
|
||||
/* find a symbol with a matching automaton first */
|
||||
symbol *sym=NULL;
|
||||
@ -3010,12 +3010,12 @@ SC_FUNC symbol *findglb(const char *name,int filter)
|
||||
* Returns a pointer to the local symbol (if found) or NULL (if not found).
|
||||
* See add_symbol() how the deepest nesting level is searched first.
|
||||
*/
|
||||
SC_FUNC symbol *findloc(const char *name)
|
||||
symbol *findloc(const char *name)
|
||||
{
|
||||
return find_symbol(&loctab,name,-1,-1,NULL);
|
||||
}
|
||||
|
||||
SC_FUNC symbol *findconst(const char *name,int *cmptag)
|
||||
symbol *findconst(const char *name,int *cmptag)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -3033,7 +3033,7 @@ SC_FUNC symbol *findconst(const char *name,int *cmptag)
|
||||
return sym;
|
||||
}
|
||||
|
||||
SC_FUNC symbol *finddepend(const symbol *parent)
|
||||
symbol *finddepend(const symbol *parent)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -3048,7 +3048,7 @@ SC_FUNC symbol *finddepend(const symbol *parent)
|
||||
* Adds a symbol to the symbol table (either global or local variables,
|
||||
* or global and local constants).
|
||||
*/
|
||||
SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,int usage)
|
||||
symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,int usage)
|
||||
{
|
||||
symbol entry, **refer;
|
||||
|
||||
@ -3083,13 +3083,13 @@ SC_FUNC symbol *addsym(const char *name,cell addr,int ident,int vclass,int tag,i
|
||||
return add_symbol(&loctab,&entry,FALSE);
|
||||
}
|
||||
|
||||
SC_FUNC symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
symbol *addvariable(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
int dim[],int numdim,int idxtag[])
|
||||
{
|
||||
return addvariable2(name,addr,ident,vclass,tag,dim,numdim,idxtag,0);
|
||||
}
|
||||
|
||||
SC_FUNC symbol *addvariable3(declinfo_t *decl,cell addr,int vclass,int slength)
|
||||
symbol *addvariable3(declinfo_t *decl,cell addr,int vclass,int slength)
|
||||
{
|
||||
typeinfo_t *type = &decl->type;
|
||||
return addvariable2(
|
||||
@ -3105,7 +3105,7 @@ SC_FUNC symbol *addvariable3(declinfo_t *decl,cell addr,int vclass,int slength)
|
||||
);
|
||||
}
|
||||
|
||||
SC_FUNC symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int tag,
|
||||
int dim[],int numdim,int idxtag[],int slength)
|
||||
{
|
||||
symbol *sym;
|
||||
@ -3154,7 +3154,7 @@ SC_FUNC symbol *addvariable2(const char *name,cell addr,int ident,int vclass,int
|
||||
* Returns te next internal label number. The global variable sc_labnum is
|
||||
* initialized to zero.
|
||||
*/
|
||||
SC_FUNC int getlabel(void)
|
||||
int getlabel(void)
|
||||
{
|
||||
return sc_labnum++;
|
||||
}
|
||||
@ -3164,7 +3164,7 @@ SC_FUNC int getlabel(void)
|
||||
* Converts a number to a hexadecimal string and returns a pointer to that
|
||||
* string. This function is NOT re-entrant.
|
||||
*/
|
||||
SC_FUNC char *itoh(ucell val)
|
||||
char *itoh(ucell val)
|
||||
{
|
||||
static char itohstr[30];
|
||||
char *ptr;
|
||||
@ -3199,13 +3199,13 @@ static char itohstr[30];
|
||||
return itohstr;
|
||||
}
|
||||
|
||||
SC_FUNC int lextok(token_t *tok)
|
||||
int lextok(token_t *tok)
|
||||
{
|
||||
tok->id = lex(&tok->val, &tok->str);
|
||||
return tok->id;
|
||||
}
|
||||
|
||||
SC_FUNC int expecttoken(int id, token_t *tok)
|
||||
int expecttoken(int id, token_t *tok)
|
||||
{
|
||||
int rval = needtoken(id);
|
||||
if (rval) {
|
||||
@ -3217,7 +3217,7 @@ SC_FUNC int expecttoken(int id, token_t *tok)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC int matchtoken2(int id, token_t *tok)
|
||||
int matchtoken2(int id, token_t *tok)
|
||||
{
|
||||
if (matchtoken(id)) {
|
||||
tok->id = tokeninfo(&tok->val, &tok->str);
|
||||
@ -3226,7 +3226,7 @@ SC_FUNC int matchtoken2(int id, token_t *tok)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC int matchsymbol(token_ident_t *ident)
|
||||
int matchsymbol(token_ident_t *ident)
|
||||
{
|
||||
if (lextok(&ident->tok) != tSYMBOL) {
|
||||
lexpush();
|
||||
@ -3237,7 +3237,7 @@ SC_FUNC int matchsymbol(token_ident_t *ident)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC int needsymbol(token_ident_t *ident)
|
||||
int needsymbol(token_ident_t *ident)
|
||||
{
|
||||
if (!expecttoken(tSYMBOL, &ident->tok))
|
||||
return FALSE;
|
@ -35,7 +35,7 @@ static int skim(int *opstr,void (*testfunc)(int),int dropval,int endval,
|
||||
int (*hier)(value*),value *lval);
|
||||
static void dropout(int lvalue,void (*testfunc)(int val),int exit1,value *lval);
|
||||
static int plnge(int *opstr,int opoff,int (*hier)(value *lval),value *lval,
|
||||
char *forcetag,int chkbitwise);
|
||||
const char *forcetag,int chkbitwise);
|
||||
static int plnge1(int (*hier)(value *lval),value *lval);
|
||||
static void plnge2(void (*oper)(void),
|
||||
int (*hier)(value *lval),
|
||||
@ -113,16 +113,20 @@ static int nextop(int *opidx,int *list)
|
||||
return FALSE; /* entire list scanned, nothing found */
|
||||
}
|
||||
|
||||
SC_FUNC int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
|
||||
int check_userop(void (*oper)(void),int tag1,int tag2,int numparam,
|
||||
value *lval,int *resulttag)
|
||||
{
|
||||
static char *binoperstr[] = { "*", "/", "%", "+", "-", "", "", "",
|
||||
"", "", "", "<=", ">=", "<", ">", "==", "!=" };
|
||||
static int binoper_savepri[] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
|
||||
FALSE, FALSE, FALSE, FALSE, FALSE,
|
||||
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE };
|
||||
static char *unoperstr[] = { "!", "-", "++", "--" };
|
||||
static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
|
||||
static const char *binoperstr[] = {
|
||||
"*", "/", "%", "+", "-", "", "", "",
|
||||
"", "", "", "<=", ">=", "<", ">", "==", "!="
|
||||
};
|
||||
static int binoper_savepri[] = { FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
|
||||
FALSE, FALSE, FALSE, FALSE, FALSE,
|
||||
TRUE, TRUE, TRUE, TRUE, FALSE, FALSE
|
||||
};
|
||||
static const char *unoperstr[] = { "!", "-", "++", "--" };
|
||||
static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
|
||||
|
||||
char opername[4] = "", symbolname[sNAMEMAX+1];
|
||||
int i,swapparams,savepri,savealt;
|
||||
int paramspassed;
|
||||
@ -286,7 +290,7 @@ static void (*unopers[])(void) = { lneg, neg, user_inc, user_dec };
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC int checktags_string(int tags[], int numtags, value *sym1)
|
||||
int checktags_string(int tags[], int numtags, value *sym1)
|
||||
{
|
||||
int i;
|
||||
if (sym1->ident == iARRAY || sym1->ident == iREFARRAY)
|
||||
@ -301,7 +305,7 @@ SC_FUNC int checktags_string(int tags[], int numtags, value *sym1)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC int checktag_string(value *sym1, value *sym2)
|
||||
int checktag_string(value *sym1, value *sym2)
|
||||
{
|
||||
if (sym1->ident == iARRAY || sym2->ident == iARRAY ||
|
||||
sym1->ident == iREFARRAY || sym2->ident == iREFARRAY)
|
||||
@ -317,7 +321,7 @@ SC_FUNC int checktag_string(value *sym1, value *sym2)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC const char *type_to_name(int tag)
|
||||
const char *type_to_name(int tag)
|
||||
{
|
||||
if (tag == 0)
|
||||
return "int";
|
||||
@ -335,7 +339,7 @@ SC_FUNC const char *type_to_name(int tag)
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
SC_FUNC int matchtag_string(int ident, int tag)
|
||||
int matchtag_string(int ident, int tag)
|
||||
{
|
||||
if (ident == iARRAY || ident == iREFARRAY)
|
||||
return FALSE;
|
||||
@ -515,7 +519,7 @@ static int matchfunctags(int formaltag, int actualtag)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC int matchtag(int formaltag, int actualtag, int flags)
|
||||
int matchtag(int formaltag, int actualtag, int flags)
|
||||
{
|
||||
if (formaltag == actualtag)
|
||||
return TRUE;
|
||||
@ -719,7 +723,7 @@ static void checkfunction(value *lval)
|
||||
* Plunge to a lower level
|
||||
*/
|
||||
static int plnge(int *opstr,int opoff,int (*hier)(value *lval),value *lval,
|
||||
char *forcetag,int chkbitwise)
|
||||
const char *forcetag,int chkbitwise)
|
||||
{
|
||||
int lvalue,opidx;
|
||||
int count;
|
||||
@ -862,10 +866,10 @@ static void plnge2(void (*oper)(void),
|
||||
checkfunction(lval1);
|
||||
checkfunction(lval2);
|
||||
if (lval1->ident==iARRAY || lval1->ident==iREFARRAY) {
|
||||
char *ptr=(lval1->sym!=NULL) ? lval1->sym->name : "-unknown-";
|
||||
const char *ptr=(lval1->sym!=NULL) ? lval1->sym->name : "-unknown-";
|
||||
error(33,ptr); /* array must be indexed */
|
||||
} else if (lval2->ident==iARRAY || lval2->ident==iREFARRAY) {
|
||||
char *ptr=(lval2->sym!=NULL) ? lval2->sym->name : "-unknown-";
|
||||
const char *ptr=(lval2->sym!=NULL) ? lval2->sym->name : "-unknown-";
|
||||
error(33,ptr); /* array must be indexed */
|
||||
} /* if */
|
||||
/* ??? ^^^ should do same kind of error checking with functions */
|
||||
@ -954,7 +958,7 @@ static cell calc(cell left,void (*oper)(),cell right,char *boolresult)
|
||||
return 0;
|
||||
}
|
||||
|
||||
SC_FUNC int lvalexpr(svalue *sval)
|
||||
int lvalexpr(svalue *sval)
|
||||
{
|
||||
memset(sval, 0, sizeof(*sval));
|
||||
|
||||
@ -967,7 +971,7 @@ SC_FUNC int lvalexpr(svalue *sval)
|
||||
return sval->val.ident;
|
||||
}
|
||||
|
||||
SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult,value *_lval)
|
||||
int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult,value *_lval)
|
||||
{
|
||||
value lval={0};
|
||||
pushheaplist();
|
||||
@ -990,7 +994,7 @@ SC_FUNC int expression(cell *val,int *tag,symbol **symptr,int chkfuncresult,valu
|
||||
return lval.ident;
|
||||
}
|
||||
|
||||
SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state)
|
||||
int sc_getstateid(constvalue **automaton,constvalue **state)
|
||||
{
|
||||
char name[sNAMEMAX+1];
|
||||
cell val;
|
||||
@ -1033,7 +1037,7 @@ SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state)
|
||||
assert(*automaton!=NULL);
|
||||
*state=state_find(name,fsa);
|
||||
if (*state==NULL) {
|
||||
char *fsaname=(*automaton)->name;
|
||||
const char *fsaname=(*automaton)->name;
|
||||
if (*fsaname=='\0')
|
||||
fsaname="<main>";
|
||||
error(87,name,fsaname); /* unknown state for automaton */
|
||||
@ -1043,7 +1047,7 @@ SC_FUNC int sc_getstateid(constvalue **automaton,constvalue **state)
|
||||
return 1;
|
||||
}
|
||||
|
||||
SC_FUNC cell array_totalsize(symbol *sym)
|
||||
cell array_totalsize(symbol *sym)
|
||||
{
|
||||
cell length;
|
||||
|
||||
@ -2526,7 +2530,7 @@ static int nesting=0;
|
||||
sc_allowproccall=FALSE; /* parameters may not use procedure call syntax */
|
||||
|
||||
if ((sym->flags & flgDEPRECATED)!=0) {
|
||||
char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
|
||||
const char *ptr= (sym->documentation!=NULL) ? sym->documentation : "";
|
||||
error(234,sym->name,ptr); /* deprecated (probably a native function) */
|
||||
} /* if */
|
||||
|
||||
@ -2557,10 +2561,9 @@ static int nesting=0;
|
||||
do {
|
||||
if (!pending_this && matchtoken('.')) {
|
||||
namedparams=TRUE;
|
||||
if (needtoken(tSYMBOL))
|
||||
tokeninfo(&lexval,&lexstr);
|
||||
else
|
||||
lexstr="";
|
||||
if (!needtoken(tSYMBOL))
|
||||
break;
|
||||
tokeninfo(&lexval,&lexstr);
|
||||
argpos=findnamedarg(arg,lexstr);
|
||||
if (argpos<0) {
|
||||
error(17,lexstr); /* undefined symbol */
|
@ -34,14 +34,14 @@
|
||||
|
||||
static int fcurseg; /* the file number (fcurrent) for the active segment */
|
||||
|
||||
SC_FUNC void load_i();
|
||||
void load_i();
|
||||
|
||||
/* When a subroutine returns to address 0, the AMX must halt. In earlier
|
||||
* releases, the RET and RETN opcodes checked for the special case 0 address.
|
||||
* Today, the compiler simply generates a HALT instruction at address 0. So
|
||||
* a subroutine can savely return to 0, and then encounter a HALT.
|
||||
*/
|
||||
SC_FUNC void writeleader(symbol *root)
|
||||
void writeleader(symbol *root)
|
||||
{
|
||||
int lbl_nostate,lbl_table;
|
||||
int statecount;
|
||||
@ -175,7 +175,7 @@ SC_FUNC void writeleader(symbol *root)
|
||||
* code_idx (altered)
|
||||
* glb_declared (altered)
|
||||
*/
|
||||
SC_FUNC void writetrailer(void)
|
||||
void writetrailer(void)
|
||||
{
|
||||
assert(sc_dataalign % opcodes(1) == 0); /* alignment must be a multiple of
|
||||
* the opcode size */
|
||||
@ -215,7 +215,7 @@ SC_FUNC void writetrailer(void)
|
||||
* Global references: curseg
|
||||
* fcurrent
|
||||
*/
|
||||
SC_FUNC void begcseg(void)
|
||||
void begcseg(void)
|
||||
{
|
||||
if (sc_status!=statSKIP && (curseg!=sIN_CSEG || fcurrent!=fcurseg)) {
|
||||
stgwrite("\n");
|
||||
@ -233,7 +233,7 @@ SC_FUNC void begcseg(void)
|
||||
*
|
||||
* Global references: curseg
|
||||
*/
|
||||
SC_FUNC void begdseg(void)
|
||||
void begdseg(void)
|
||||
{
|
||||
if (sc_status!=statSKIP && (curseg!=sIN_DSEG || fcurrent!=fcurseg)) {
|
||||
stgwrite("\n");
|
||||
@ -246,7 +246,7 @@ SC_FUNC void begdseg(void)
|
||||
} /* if */
|
||||
}
|
||||
|
||||
SC_FUNC void setline(int chkbounds)
|
||||
void setline(int chkbounds)
|
||||
{
|
||||
if (sc_asmfile) {
|
||||
stgwrite("\t; line ");
|
||||
@ -263,7 +263,7 @@ SC_FUNC void setline(int chkbounds)
|
||||
} /* if */
|
||||
}
|
||||
|
||||
SC_FUNC void setfiledirect(char *name)
|
||||
void setfiledirect(char *name)
|
||||
{
|
||||
if (sc_status==statFIRST && sc_listing) {
|
||||
assert(name!=NULL);
|
||||
@ -273,7 +273,7 @@ SC_FUNC void setfiledirect(char *name)
|
||||
} /* if */
|
||||
}
|
||||
|
||||
SC_FUNC void setlinedirect(int line)
|
||||
void setlinedirect(int line)
|
||||
{
|
||||
if (sc_status==statFIRST && sc_listing) {
|
||||
char string[40];
|
||||
@ -286,7 +286,7 @@ SC_FUNC void setlinedirect(int line)
|
||||
*
|
||||
* Post a code label (specified as a number), on a new line.
|
||||
*/
|
||||
SC_FUNC void setlabel(int number)
|
||||
void setlabel(int number)
|
||||
{
|
||||
assert(number>=0);
|
||||
stgwrite("l.");
|
||||
@ -307,7 +307,7 @@ SC_FUNC void setlabel(int number)
|
||||
* statement. This allows several simple optimizations by the peephole
|
||||
* optimizer.
|
||||
*/
|
||||
SC_FUNC void markexpr(optmark type,const char *name,cell offset)
|
||||
void markexpr(optmark type,const char *name,cell offset)
|
||||
{
|
||||
switch (type) {
|
||||
case sEXPR:
|
||||
@ -332,7 +332,7 @@ SC_FUNC void markexpr(optmark type,const char *name,cell offset)
|
||||
*
|
||||
* Global references: funcstatus (referred to only)
|
||||
*/
|
||||
SC_FUNC void startfunc(char *fname)
|
||||
void startfunc(char *fname)
|
||||
{
|
||||
stgwrite("\tproc");
|
||||
if (sc_asmfile) {
|
||||
@ -349,7 +349,7 @@ SC_FUNC void startfunc(char *fname)
|
||||
*
|
||||
* Declare a CODE ending point (function end)
|
||||
*/
|
||||
SC_FUNC void endfunc(void)
|
||||
void endfunc(void)
|
||||
{
|
||||
stgwrite("\n"); /* skip a line */
|
||||
}
|
||||
@ -361,7 +361,7 @@ SC_FUNC void endfunc(void)
|
||||
* be a power of 2, and this alignment must be done right after the frame
|
||||
* is set up (before the first variable is declared)
|
||||
*/
|
||||
SC_FUNC void alignframe(int numbytes)
|
||||
void alignframe(int numbytes)
|
||||
{
|
||||
#if !defined NDEBUG
|
||||
/* "numbytes" should be a power of 2 for this code to work */
|
||||
@ -385,7 +385,7 @@ SC_FUNC void alignframe(int numbytes)
|
||||
*
|
||||
* Generate code to get the value of a symbol into "primary".
|
||||
*/
|
||||
SC_FUNC void rvalue(value *lval)
|
||||
void rvalue(value *lval)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -429,7 +429,7 @@ SC_FUNC void rvalue(value *lval)
|
||||
/* Get the address of a symbol into the primary or alternate register (used
|
||||
* for arrays, and for passing arguments by reference).
|
||||
*/
|
||||
SC_FUNC void address(symbol *sym,regid reg)
|
||||
void address(symbol *sym,regid reg)
|
||||
{
|
||||
assert(sym!=NULL);
|
||||
assert(reg==sPRI || reg==sALT);
|
||||
@ -495,20 +495,20 @@ static void load_argcount(regid reg)
|
||||
}
|
||||
|
||||
// PRI = ALT + (PRI * cellsize)
|
||||
SC_FUNC void idxaddr()
|
||||
void idxaddr()
|
||||
{
|
||||
stgwrite("\tidxaddr\n");
|
||||
code_idx += opcodes(1);
|
||||
}
|
||||
|
||||
SC_FUNC void load_i()
|
||||
void load_i()
|
||||
{
|
||||
stgwrite("\tload.i\n");
|
||||
code_idx+=opcodes(1);
|
||||
}
|
||||
|
||||
// Load the hidden array argument into ALT.
|
||||
SC_FUNC void load_hidden_arg()
|
||||
void load_hidden_arg()
|
||||
{
|
||||
pushreg(sPRI);
|
||||
|
||||
@ -533,7 +533,7 @@ SC_FUNC void load_hidden_arg()
|
||||
* Saves the contents of "primary" into a memory cell, either directly
|
||||
* or indirectly (at the address given in the alternate register).
|
||||
*/
|
||||
SC_FUNC void store(value *lval)
|
||||
void store(value *lval)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -570,7 +570,7 @@ SC_FUNC void store(value *lval)
|
||||
}
|
||||
|
||||
/* Get a cell from a fixed address in memory */
|
||||
SC_FUNC void loadreg(cell address,regid reg)
|
||||
void loadreg(cell address,regid reg)
|
||||
{
|
||||
assert(reg==sPRI || reg==sALT);
|
||||
if (reg==sPRI)
|
||||
@ -582,7 +582,7 @@ SC_FUNC void loadreg(cell address,regid reg)
|
||||
}
|
||||
|
||||
/* Store a cell into a fixed address in memory */
|
||||
SC_FUNC void storereg(cell address,regid reg)
|
||||
void storereg(cell address,regid reg)
|
||||
{
|
||||
assert(reg==sPRI || reg==sALT);
|
||||
if (reg==sPRI)
|
||||
@ -596,7 +596,7 @@ SC_FUNC void storereg(cell address,regid reg)
|
||||
/* source must in PRI, destination address in ALT. The "size"
|
||||
* parameter is in bytes, not cells.
|
||||
*/
|
||||
SC_FUNC void memcopy(cell size)
|
||||
void memcopy(cell size)
|
||||
{
|
||||
stgwrite("\tmovs ");
|
||||
outval(size,TRUE);
|
||||
@ -607,7 +607,7 @@ SC_FUNC void memcopy(cell size)
|
||||
/* Address of the source must already have been loaded in PRI
|
||||
* "size" is the size in bytes (not cells).
|
||||
*/
|
||||
SC_FUNC void copyarray(symbol *sym,cell size)
|
||||
void copyarray(symbol *sym,cell size)
|
||||
{
|
||||
assert(sym!=NULL);
|
||||
/* the symbol can be a local array, a global array, or an array
|
||||
@ -631,7 +631,7 @@ SC_FUNC void copyarray(symbol *sym,cell size)
|
||||
memcopy(size);
|
||||
}
|
||||
|
||||
SC_FUNC void fillarray(symbol *sym,cell size,cell value)
|
||||
void fillarray(symbol *sym,cell size,cell value)
|
||||
{
|
||||
ldconst(value,sPRI); /* load value in PRI */
|
||||
|
||||
@ -660,7 +660,7 @@ SC_FUNC void fillarray(symbol *sym,cell size,cell value)
|
||||
code_idx+=opcodes(2)+opargs(2);
|
||||
}
|
||||
|
||||
SC_FUNC void stradjust(regid reg)
|
||||
void stradjust(regid reg)
|
||||
{
|
||||
assert(reg==sPRI);
|
||||
stgwrite("\tstradjust.pri\n");
|
||||
@ -670,7 +670,7 @@ SC_FUNC void stradjust(regid reg)
|
||||
/* Instruction to get an immediate value into the primary or the alternate
|
||||
* register
|
||||
*/
|
||||
SC_FUNC void ldconst(cell val,regid reg)
|
||||
void ldconst(cell val,regid reg)
|
||||
{
|
||||
assert(reg==sPRI || reg==sALT);
|
||||
switch (reg) {
|
||||
@ -698,13 +698,13 @@ SC_FUNC void ldconst(cell val,regid reg)
|
||||
}
|
||||
|
||||
/* Copy value in alternate register to the primary register */
|
||||
SC_FUNC void moveto1(void)
|
||||
void moveto1(void)
|
||||
{
|
||||
stgwrite("\tmove.pri\n");
|
||||
code_idx+=opcodes(1)+opargs(0);
|
||||
}
|
||||
|
||||
SC_FUNC void move_alt(void)
|
||||
void move_alt(void)
|
||||
{
|
||||
stgwrite("\tmove.alt\n");
|
||||
code_idx+=opcodes(1)+opargs(0);
|
||||
@ -712,7 +712,7 @@ SC_FUNC void move_alt(void)
|
||||
|
||||
/* Push primary or the alternate register onto the stack
|
||||
*/
|
||||
SC_FUNC void pushreg(regid reg)
|
||||
void pushreg(regid reg)
|
||||
{
|
||||
assert(reg==sPRI || reg==sALT);
|
||||
switch (reg) {
|
||||
@ -729,7 +729,7 @@ SC_FUNC void pushreg(regid reg)
|
||||
/*
|
||||
* Push a constant value onto the stack
|
||||
*/
|
||||
SC_FUNC void pushval(cell val)
|
||||
void pushval(cell val)
|
||||
{
|
||||
stgwrite("\tpush.c ");
|
||||
outval(val, TRUE);
|
||||
@ -738,7 +738,7 @@ SC_FUNC void pushval(cell val)
|
||||
|
||||
/* Pop stack into the primary or the alternate register
|
||||
*/
|
||||
SC_FUNC void popreg(regid reg)
|
||||
void popreg(regid reg)
|
||||
{
|
||||
assert(reg==sPRI || reg==sALT);
|
||||
switch (reg) {
|
||||
@ -755,7 +755,7 @@ SC_FUNC void popreg(regid reg)
|
||||
/*
|
||||
* Generate an array
|
||||
*/
|
||||
SC_FUNC void genarray(int dims, int _autozero)
|
||||
void genarray(int dims, int _autozero)
|
||||
{
|
||||
if (_autozero) {
|
||||
stgwrite("\tgenarray.z ");
|
||||
@ -769,7 +769,7 @@ SC_FUNC void genarray(int dims, int _autozero)
|
||||
/*
|
||||
* swap the top-of-stack with the value in primary register
|
||||
*/
|
||||
SC_FUNC void swap1(void)
|
||||
void swap1(void)
|
||||
{
|
||||
stgwrite("\tswap.pri\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -784,14 +784,14 @@ SC_FUNC void swap1(void)
|
||||
* The case table is sorted on the comparison value. This allows more advanced
|
||||
* abstract machines to sift the case table with a binary search.
|
||||
*/
|
||||
SC_FUNC void ffswitch(int label)
|
||||
void ffswitch(int label)
|
||||
{
|
||||
stgwrite("\tswitch ");
|
||||
outval(label,TRUE); /* the label is the address of the case table */
|
||||
code_idx+=opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
SC_FUNC void ffcase(cell value,char *labelname,int newtable)
|
||||
void ffcase(cell value,char *labelname,int newtable)
|
||||
{
|
||||
if (newtable) {
|
||||
stgwrite("\tcasetbl\n");
|
||||
@ -808,7 +808,7 @@ SC_FUNC void ffcase(cell value,char *labelname,int newtable)
|
||||
/*
|
||||
* Call specified function
|
||||
*/
|
||||
SC_FUNC void ffcall(symbol *sym,const char *label,int numargs)
|
||||
void ffcall(symbol *sym,const char *label,int numargs)
|
||||
{
|
||||
char symname[2*sNAMEMAX+16];
|
||||
char aliasname[sNAMEMAX+1];
|
||||
@ -868,7 +868,7 @@ SC_FUNC void ffcall(symbol *sym,const char *label,int numargs)
|
||||
*
|
||||
* Global references: funcstatus (referred to only)
|
||||
*/
|
||||
SC_FUNC void ffret(int remparams)
|
||||
void ffret(int remparams)
|
||||
{
|
||||
if (remparams)
|
||||
stgwrite("\tretn\n");
|
||||
@ -877,14 +877,14 @@ SC_FUNC void ffret(int remparams)
|
||||
code_idx+=opcodes(1);
|
||||
}
|
||||
|
||||
SC_FUNC void ffabort(int reason)
|
||||
void ffabort(int reason)
|
||||
{
|
||||
stgwrite("\thalt ");
|
||||
outval(reason,TRUE);
|
||||
code_idx+=opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
SC_FUNC void ffbounds(cell size)
|
||||
void ffbounds(cell size)
|
||||
{
|
||||
if ((sc_debug & sCHKBOUNDS)!=0) {
|
||||
stgwrite("\tbounds ");
|
||||
@ -896,7 +896,7 @@ SC_FUNC void ffbounds(cell size)
|
||||
/*
|
||||
* Jump to local label number (the number is converted to a name)
|
||||
*/
|
||||
SC_FUNC void jumplabel(int number)
|
||||
void jumplabel(int number)
|
||||
{
|
||||
stgwrite("\tjump ");
|
||||
outval(number,TRUE);
|
||||
@ -906,7 +906,7 @@ SC_FUNC void jumplabel(int number)
|
||||
/*
|
||||
* Define storage (global and static variables)
|
||||
*/
|
||||
SC_FUNC void defstorage(void)
|
||||
void defstorage(void)
|
||||
{
|
||||
stgwrite("dump ");
|
||||
}
|
||||
@ -915,7 +915,7 @@ SC_FUNC void defstorage(void)
|
||||
* Inclrement/decrement stack pointer. Note that this routine does
|
||||
* nothing if the delta is zero.
|
||||
*/
|
||||
SC_FUNC void modstk(int delta)
|
||||
void modstk(int delta)
|
||||
{
|
||||
if (delta) {
|
||||
stgwrite("\tstack ");
|
||||
@ -925,7 +925,7 @@ SC_FUNC void modstk(int delta)
|
||||
}
|
||||
|
||||
/* set the stack to a hard offset from the frame */
|
||||
SC_FUNC void setstk(cell value)
|
||||
void setstk(cell value)
|
||||
{
|
||||
stgwrite("\tstackadjust ");
|
||||
assert(value<=0); /* STK should always become <= FRM */
|
||||
@ -933,7 +933,7 @@ SC_FUNC void setstk(cell value)
|
||||
code_idx+=opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
SC_FUNC void modheap(int delta)
|
||||
void modheap(int delta)
|
||||
{
|
||||
if (delta) {
|
||||
stgwrite("\theap ");
|
||||
@ -942,13 +942,13 @@ SC_FUNC void modheap(int delta)
|
||||
} /* if */
|
||||
}
|
||||
|
||||
SC_FUNC void modheap_i()
|
||||
void modheap_i()
|
||||
{
|
||||
stgwrite("\ttracker.pop.setheap\n");
|
||||
code_idx+=opcodes(1);
|
||||
}
|
||||
|
||||
SC_FUNC void setheap_save(cell value)
|
||||
void setheap_save(cell value)
|
||||
{
|
||||
assert(value);
|
||||
stgwrite("\ttracker.push.c ");
|
||||
@ -956,7 +956,7 @@ SC_FUNC void setheap_save(cell value)
|
||||
code_idx+=opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
SC_FUNC void setheap_pri(void)
|
||||
void setheap_pri(void)
|
||||
{
|
||||
stgwrite("\theap "); /* ALT = HEA++ */
|
||||
outval(sizeof(cell), TRUE);
|
||||
@ -965,7 +965,7 @@ SC_FUNC void setheap_pri(void)
|
||||
code_idx+=opcodes(3)+opargs(1);
|
||||
}
|
||||
|
||||
SC_FUNC void setheap(cell value)
|
||||
void setheap(cell value)
|
||||
{
|
||||
stgwrite("\tconst.pri "); /* load default value in PRI */
|
||||
outval(value, TRUE);
|
||||
@ -977,7 +977,7 @@ SC_FUNC void setheap(cell value)
|
||||
* Convert a cell number to a "byte" address; i.e. double or quadruple
|
||||
* the primary register.
|
||||
*/
|
||||
SC_FUNC void cell2addr(void)
|
||||
void cell2addr(void)
|
||||
{
|
||||
#if PAWN_CELL_SIZE==16
|
||||
stgwrite("\tshl.c.pri 1\n");
|
||||
@ -994,7 +994,7 @@ SC_FUNC void cell2addr(void)
|
||||
/*
|
||||
* Double or quadruple the alternate register.
|
||||
*/
|
||||
SC_FUNC void cell2addr_alt(void)
|
||||
void cell2addr_alt(void)
|
||||
{
|
||||
#if PAWN_CELL_SIZE==16
|
||||
stgwrite("\tshl.c.alt 1\n");
|
||||
@ -1013,7 +1013,7 @@ SC_FUNC void cell2addr_alt(void)
|
||||
* Or convert a number of packed characters to the number of cells (with
|
||||
* truncation).
|
||||
*/
|
||||
SC_FUNC void addr2cell(void)
|
||||
void addr2cell(void)
|
||||
{
|
||||
#if PAWN_CELL_SIZE==16
|
||||
stgwrite("\tshr.c.pri 1\n");
|
||||
@ -1030,7 +1030,7 @@ SC_FUNC void addr2cell(void)
|
||||
/* Convert from character index to byte address. This routine does
|
||||
* nothing if a character has the size of a byte.
|
||||
*/
|
||||
SC_FUNC void char2addr(void)
|
||||
void char2addr(void)
|
||||
{
|
||||
#if sCHARBITS==16
|
||||
stgwrite("\tshl.c.pri 1\n");
|
||||
@ -1048,7 +1048,7 @@ SC_FUNC void char2addr(void)
|
||||
*
|
||||
* NOTE: For Source Pawn, this is fliped. It will do nothing on Little-Endian.
|
||||
*/
|
||||
SC_FUNC void charalign(void)
|
||||
void charalign(void)
|
||||
{
|
||||
#if 0 /* TEMPORARILY DISABLED BECAUSE WE DON'T USE BIG ENDIAN */
|
||||
stgwrite("\talign.pri ");
|
||||
@ -1060,7 +1060,7 @@ SC_FUNC void charalign(void)
|
||||
/*
|
||||
* Add a constant to the primary register.
|
||||
*/
|
||||
SC_FUNC void addconst(cell value)
|
||||
void addconst(cell value)
|
||||
{
|
||||
if (value!=0) {
|
||||
stgwrite("\tadd.c ");
|
||||
@ -1072,7 +1072,7 @@ SC_FUNC void addconst(cell value)
|
||||
/*
|
||||
* signed multiply of primary and secundairy registers (result in primary)
|
||||
*/
|
||||
SC_FUNC void os_mult(void)
|
||||
void os_mult(void)
|
||||
{
|
||||
stgwrite("\tsmul\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1082,7 +1082,7 @@ SC_FUNC void os_mult(void)
|
||||
* signed divide of alternate register by primary register (quotient in
|
||||
* primary; remainder in alternate)
|
||||
*/
|
||||
SC_FUNC void os_div(void)
|
||||
void os_div(void)
|
||||
{
|
||||
stgwrite("\tsdiv.alt\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1091,7 +1091,7 @@ SC_FUNC void os_div(void)
|
||||
/*
|
||||
* modulus of (alternate % primary), result in primary (signed)
|
||||
*/
|
||||
SC_FUNC void os_mod(void)
|
||||
void os_mod(void)
|
||||
{
|
||||
stgwrite("\tsdiv.alt\n");
|
||||
stgwrite("\tmove.pri\n"); /* move ALT to PRI */
|
||||
@ -1101,7 +1101,7 @@ SC_FUNC void os_mod(void)
|
||||
/*
|
||||
* Add primary and alternate registers (result in primary).
|
||||
*/
|
||||
SC_FUNC void ob_add(void)
|
||||
void ob_add(void)
|
||||
{
|
||||
stgwrite("\tadd\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1110,7 +1110,7 @@ SC_FUNC void ob_add(void)
|
||||
/*
|
||||
* subtract primary register from alternate register (result in primary)
|
||||
*/
|
||||
SC_FUNC void ob_sub(void)
|
||||
void ob_sub(void)
|
||||
{
|
||||
stgwrite("\tsub.alt\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1122,7 +1122,7 @@ SC_FUNC void ob_sub(void)
|
||||
* There is no need for a "logical shift left" routine, since
|
||||
* logical shift left is identical to arithmic shift left.
|
||||
*/
|
||||
SC_FUNC void ob_sal(void)
|
||||
void ob_sal(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tshl\n");
|
||||
@ -1133,7 +1133,7 @@ SC_FUNC void ob_sal(void)
|
||||
* arithmic shift right alternate register the number of bits
|
||||
* given in the primary register (result in primary).
|
||||
*/
|
||||
SC_FUNC void os_sar(void)
|
||||
void os_sar(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tsshr\n");
|
||||
@ -1144,7 +1144,7 @@ SC_FUNC void os_sar(void)
|
||||
* logical (unsigned) shift right of the alternate register by the
|
||||
* number of bits given in the primary register (result in primary).
|
||||
*/
|
||||
SC_FUNC void ou_sar(void)
|
||||
void ou_sar(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tshr\n");
|
||||
@ -1154,7 +1154,7 @@ SC_FUNC void ou_sar(void)
|
||||
/*
|
||||
* inclusive "or" of primary and alternate registers (result in primary)
|
||||
*/
|
||||
SC_FUNC void ob_or(void)
|
||||
void ob_or(void)
|
||||
{
|
||||
stgwrite("\tor\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1163,7 +1163,7 @@ SC_FUNC void ob_or(void)
|
||||
/*
|
||||
* "exclusive or" of primary and alternate registers (result in primary)
|
||||
*/
|
||||
SC_FUNC void ob_xor(void)
|
||||
void ob_xor(void)
|
||||
{
|
||||
stgwrite("\txor\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1172,7 +1172,7 @@ SC_FUNC void ob_xor(void)
|
||||
/*
|
||||
* "and" of primary and secundairy registers (result in primary)
|
||||
*/
|
||||
SC_FUNC void ob_and(void)
|
||||
void ob_and(void)
|
||||
{
|
||||
stgwrite("\tand\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1181,7 +1181,7 @@ SC_FUNC void ob_and(void)
|
||||
/*
|
||||
* test ALT==PRI; result in primary register (1 or 0).
|
||||
*/
|
||||
SC_FUNC void ob_eq(void)
|
||||
void ob_eq(void)
|
||||
{
|
||||
stgwrite("\teq\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1190,7 +1190,7 @@ SC_FUNC void ob_eq(void)
|
||||
/*
|
||||
* test ALT!=PRI
|
||||
*/
|
||||
SC_FUNC void ob_ne(void)
|
||||
void ob_ne(void)
|
||||
{
|
||||
stgwrite("\tneq\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1216,14 +1216,14 @@ SC_FUNC void ob_ne(void)
|
||||
* stack and moves the value of ALT into PRI. If there is a next comparison,
|
||||
* PRI can now serve as the "left" operand of the relational operator.
|
||||
*/
|
||||
SC_FUNC void relop_prefix(void)
|
||||
void relop_prefix(void)
|
||||
{
|
||||
stgwrite("\tpush.pri\n");
|
||||
stgwrite("\tmove.pri\n");
|
||||
code_idx+=opcodes(2);
|
||||
}
|
||||
|
||||
SC_FUNC void relop_suffix(void)
|
||||
void relop_suffix(void)
|
||||
{
|
||||
stgwrite("\tswap.alt\n");
|
||||
stgwrite("\tand\n");
|
||||
@ -1234,7 +1234,7 @@ SC_FUNC void relop_suffix(void)
|
||||
/*
|
||||
* test ALT<PRI (signed)
|
||||
*/
|
||||
SC_FUNC void os_lt(void)
|
||||
void os_lt(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tsless\n");
|
||||
@ -1244,7 +1244,7 @@ SC_FUNC void os_lt(void)
|
||||
/*
|
||||
* test ALT<=PRI (signed)
|
||||
*/
|
||||
SC_FUNC void os_le(void)
|
||||
void os_le(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tsleq\n");
|
||||
@ -1254,7 +1254,7 @@ SC_FUNC void os_le(void)
|
||||
/*
|
||||
* test ALT>PRI (signed)
|
||||
*/
|
||||
SC_FUNC void os_gt(void)
|
||||
void os_gt(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tsgrtr\n");
|
||||
@ -1264,7 +1264,7 @@ SC_FUNC void os_gt(void)
|
||||
/*
|
||||
* test ALT>=PRI (signed)
|
||||
*/
|
||||
SC_FUNC void os_ge(void)
|
||||
void os_ge(void)
|
||||
{
|
||||
stgwrite("\txchg\n");
|
||||
stgwrite("\tsgeq\n");
|
||||
@ -1274,7 +1274,7 @@ SC_FUNC void os_ge(void)
|
||||
/*
|
||||
* logical negation of primary register
|
||||
*/
|
||||
SC_FUNC void lneg(void)
|
||||
void lneg(void)
|
||||
{
|
||||
stgwrite("\tnot\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1283,7 +1283,7 @@ SC_FUNC void lneg(void)
|
||||
/*
|
||||
* two's complement primary register
|
||||
*/
|
||||
SC_FUNC void neg(void)
|
||||
void neg(void)
|
||||
{
|
||||
stgwrite("\tneg\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1292,7 +1292,7 @@ SC_FUNC void neg(void)
|
||||
/*
|
||||
* one's complement of primary register
|
||||
*/
|
||||
SC_FUNC void invert(void)
|
||||
void invert(void)
|
||||
{
|
||||
stgwrite("\tinvert\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1301,19 +1301,19 @@ SC_FUNC void invert(void)
|
||||
/*
|
||||
* nop
|
||||
*/
|
||||
SC_FUNC void nooperation(void)
|
||||
void nooperation(void)
|
||||
{
|
||||
stgwrite("\tnop\n");
|
||||
code_idx+=opcodes(1);
|
||||
}
|
||||
|
||||
SC_FUNC void inc_pri()
|
||||
void inc_pri()
|
||||
{
|
||||
stgwrite("\tinc.pri\n");
|
||||
code_idx+=opcodes(1);
|
||||
}
|
||||
|
||||
SC_FUNC void dec_pri()
|
||||
void dec_pri()
|
||||
{
|
||||
stgwrite("\tdec.pri\n");
|
||||
code_idx+=opcodes(1);
|
||||
@ -1321,7 +1321,7 @@ SC_FUNC void dec_pri()
|
||||
|
||||
/* increment symbol
|
||||
*/
|
||||
SC_FUNC void inc(value *lval)
|
||||
void inc(value *lval)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -1379,7 +1379,7 @@ SC_FUNC void inc(value *lval)
|
||||
*
|
||||
* in case of an integer pointer, the symbol must be incremented by 2.
|
||||
*/
|
||||
SC_FUNC void dec(value *lval)
|
||||
void dec(value *lval)
|
||||
{
|
||||
symbol *sym;
|
||||
|
||||
@ -1436,7 +1436,7 @@ SC_FUNC void dec(value *lval)
|
||||
/*
|
||||
* Jumps to "label" if PRI != 0
|
||||
*/
|
||||
SC_FUNC void jmp_ne0(int number)
|
||||
void jmp_ne0(int number)
|
||||
{
|
||||
stgwrite("\tjnz ");
|
||||
outval(number,TRUE);
|
||||
@ -1446,7 +1446,7 @@ SC_FUNC void jmp_ne0(int number)
|
||||
/*
|
||||
* Jumps to "label" if PRI == 0
|
||||
*/
|
||||
SC_FUNC void jmp_eq0(int number)
|
||||
void jmp_eq0(int number)
|
||||
{
|
||||
stgwrite("\tjzer ");
|
||||
outval(number,TRUE);
|
||||
@ -1454,14 +1454,14 @@ SC_FUNC void jmp_eq0(int number)
|
||||
}
|
||||
|
||||
/* write a value in hexadecimal; optionally adds a newline */
|
||||
SC_FUNC void outval(cell val,int newline)
|
||||
void outval(cell val,int newline)
|
||||
{
|
||||
stgwrite(itoh(val));
|
||||
if (newline)
|
||||
stgwrite("\n");
|
||||
}
|
||||
|
||||
SC_FUNC void invoke_getter(methodmap_method_t *method)
|
||||
void invoke_getter(methodmap_method_t *method)
|
||||
{
|
||||
if (!method->getter) {
|
||||
error(149, method->name);
|
||||
@ -1479,7 +1479,7 @@ SC_FUNC void invoke_getter(methodmap_method_t *method)
|
||||
markusage(method->getter, uREAD);
|
||||
}
|
||||
|
||||
SC_FUNC void invoke_setter(methodmap_method_t *method, int save)
|
||||
void invoke_setter(methodmap_method_t *method, int save)
|
||||
{
|
||||
if (!method->setter) {
|
||||
error(152, method->name);
|
@ -21,7 +21,7 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
|
||||
int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
|
||||
|
||||
#ifndef SCPACK
|
||||
# define SCPACK
|
||||
@ -42,7 +42,7 @@ unsigned char errstr_table
[][2] = {
|
||||
};
|
||||
/*-*SCPACK end of pair table, do not change or remove this line */
|
||||
|
||||
static char *errmsg[] = {
|
||||
static const char *errmsg[] = {
|
||||
#ifdef SCPACK
|
||||
/*001*/ "expected token: \"%s\", but found \"%s\"\n",
|
||||
/*002*/ "only a single statement (or expression) can follow each \"case\"\n",
|
||||
@ -362,7 +362,7 @@ static char *errmsg[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
static char *fatalmsg[] = {
|
||||
static const char *fatalmsg[] = {
|
||||
#ifdef SCPACK
|
||||
/*160*/ "cannot read from file: \"%s\"\n",
|
||||
/*161*/ "cannot write to file: \"%s\"\n",
|
||||
@ -398,7 +398,7 @@ static char *fatalmsg[] = {
|
||||
#endif
|
||||
};
|
||||
|
||||
static char *warnmsg[] = {
|
||||
static const char *warnmsg[] = {
|
||||
#ifdef SCPACK
|
||||
/*200*/ "symbol \"%s\" is truncated to %d characters\n",
|
||||
/*201*/ "redefinition of constant/macro (symbol \"%s\")\n",
|
||||
|
@ -67,12 +67,12 @@ static int sErrLine; /* forced line number for the error message */
|
||||
* fcurrent (reffered to only)
|
||||
* errflag (altered)
|
||||
*/
|
||||
SC_FUNC int error(int number,...)
|
||||
int error(int number,...)
|
||||
{
|
||||
static char *prefix[3]={ "error", "fatal error", "warning" };
|
||||
static const char *prefix[3]={ "error", "fatal error", "warning" };
|
||||
static int lastline,errorcount;
|
||||
static short lastfile;
|
||||
char *msg,*pre;
|
||||
const char *msg,*pre;
|
||||
va_list argptr;
|
||||
|
||||
// sErrLine is used to temporarily change the line number of reported errors.
|
||||
@ -172,7 +172,7 @@ static short lastfile;
|
||||
return 0;
|
||||
}
|
||||
|
||||
SC_FUNC void errorset(int code,int line)
|
||||
void errorset(int code,int line)
|
||||
{
|
||||
switch (code) {
|
||||
case sRESET:
|
@ -37,14 +37,14 @@
|
||||
#endif
|
||||
|
||||
|
||||
static void append_dbginfo(FILE *fout);
|
||||
static void append_dbginfo(void *fout);
|
||||
|
||||
|
||||
typedef cell (*OPCODE_PROC)(FILE *fbin,char *params,cell opcode);
|
||||
typedef cell (*OPCODE_PROC)(void *fbin,char *params,cell opcode);
|
||||
|
||||
typedef struct {
|
||||
cell opcode;
|
||||
char *name;
|
||||
const char *name;
|
||||
int segment; /* sIN_CSEG=parse in cseg, sIN_DSEG=parse in dseg */
|
||||
OPCODE_PROC func;
|
||||
} OPCODEC;
|
||||
@ -192,7 +192,7 @@ static char *stripcomment(char *str)
|
||||
return str;
|
||||
}
|
||||
|
||||
static void write_encoded(FILE *fbin,ucell *c,int num)
|
||||
static void write_encoded(void *fbin,ucell *c,int num)
|
||||
{
|
||||
#if PAWN_CELL_SIZE == 16
|
||||
#define ENC_MAX 3 /* a 16-bit cell is encoded in max. 3 bytes */
|
||||
@ -246,7 +246,7 @@ static void write_encoded(FILE *fbin,ucell *c,int num)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell noop(FILE *fbin,char *params,cell opcode)
|
||||
static cell noop(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -254,7 +254,7 @@ static cell noop(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell set_currentfile(FILE *fbin,char *params,cell opcode)
|
||||
static cell set_currentfile(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
fcurrent=(short)getparam(params,NULL);
|
||||
return 0;
|
||||
@ -263,14 +263,14 @@ static cell set_currentfile(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell parm0(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm0(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
if (fbin!=NULL)
|
||||
write_encoded(fbin,(ucell*)&opcode,1);
|
||||
return opcodes(1);
|
||||
}
|
||||
|
||||
static cell parm1(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm1(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p=getparam(params,NULL);
|
||||
if (fbin!=NULL) {
|
||||
@ -280,7 +280,7 @@ static cell parm1(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
static cell parm2(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm2(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,NULL);
|
||||
@ -292,7 +292,7 @@ static cell parm2(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(2);
|
||||
}
|
||||
|
||||
static cell parm3(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm3(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -306,7 +306,7 @@ static cell parm3(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(3);
|
||||
}
|
||||
|
||||
static cell parm4(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm4(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -322,7 +322,7 @@ static cell parm4(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(4);
|
||||
}
|
||||
|
||||
static cell parm5(FILE *fbin,char *params,cell opcode)
|
||||
static cell parm5(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p1=getparam(params,¶ms);
|
||||
ucell p2=getparam(params,¶ms);
|
||||
@ -343,7 +343,7 @@ static cell parm5(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell do_dump(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_dump(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
ucell p;
|
||||
int num = 0;
|
||||
@ -359,7 +359,7 @@ static cell do_dump(FILE *fbin,char *params,cell opcode)
|
||||
return num*sizeof(cell);
|
||||
}
|
||||
|
||||
static cell do_call(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_call(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
char name[sNAMEMAX+1];
|
||||
int i;
|
||||
@ -399,7 +399,7 @@ static cell do_call(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
static cell do_jump(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_jump(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
int i;
|
||||
ucell p;
|
||||
@ -416,7 +416,7 @@ static cell do_jump(FILE *fbin,char *params,cell opcode)
|
||||
return opcodes(1)+opargs(1);
|
||||
}
|
||||
|
||||
static cell do_switch(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_switch(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
int i;
|
||||
ucell p;
|
||||
@ -436,7 +436,7 @@ static cell do_switch(FILE *fbin,char *params,cell opcode)
|
||||
#if defined __BORLANDC__ || defined __WATCOMC__
|
||||
#pragma argsused
|
||||
#endif
|
||||
static cell do_case(FILE *fbin,char *params,cell opcode)
|
||||
static cell do_case(void *fbin,char *params,cell opcode)
|
||||
{
|
||||
int i;
|
||||
ucell p,v;
|
||||
@ -659,7 +659,7 @@ static int findopcode(char *instr,int maxlen)
|
||||
return 0; /* not found, return special index */
|
||||
}
|
||||
|
||||
SC_FUNC int assemble(FILE *fout,FILE *fin)
|
||||
int assemble(void *fout, void *fin)
|
||||
{
|
||||
AMX_HEADER hdr;
|
||||
AMX_FUNCSTUBNT func;
|
||||
@ -1058,7 +1058,7 @@ SC_FUNC int assemble(FILE *fout,FILE *fin)
|
||||
return size;
|
||||
}
|
||||
|
||||
static void append_dbginfo(FILE *fout)
|
||||
static void append_dbginfo(void *fout)
|
||||
{
|
||||
AMX_DBG_HDR dbghdr;
|
||||
AMX_DBG_LINE dbgline;
|
@ -22,7 +22,7 @@
|
||||
* Version: $Id$
|
||||
*/
|
||||
|
||||
SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
|
||||
int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2]);
|
||||
|
||||
#define SCPACK_TERMINATOR , /* end each section with a comma */
|
||||
|
||||
@ -41,12 +41,17 @@ unsigned char sequences_table[][2] = {
|
||||
/*-*SCPACK end of pair table, do not change or remove this line */
|
||||
|
||||
#define seqsize(o,p) (opcodes(o)+opargs(p))
|
||||
typedef struct {
|
||||
const char *find;
|
||||
const char *replace;
|
||||
int savesize; /* number of bytes saved (in bytecode) */
|
||||
} SETUP_SEQUENCE;
|
||||
typedef struct {
|
||||
char *find;
|
||||
char *replace;
|
||||
int savesize; /* number of bytes saved (in bytecode) */
|
||||
} SEQUENCE;
|
||||
static SEQUENCE sequences_cmp[] = {
|
||||
static SETUP_SEQUENCE sequences_cmp[] = {
|
||||
/* A very common sequence in four varieties
|
||||
* load.s.pri n1 load.s.pri n2
|
||||
* push.pri load.s.alt n1
|
||||
|
@ -108,7 +108,7 @@ static void grow_stgbuffer(char **buffer, int *curmax, int requiredsize)
|
||||
**buffer='\0';
|
||||
}
|
||||
|
||||
SC_FUNC void stgbuffer_cleanup(void)
|
||||
void stgbuffer_cleanup(void)
|
||||
{
|
||||
if (stgbuf!=NULL) {
|
||||
free(stgbuf);
|
||||
@ -141,7 +141,7 @@ SC_FUNC void stgbuffer_cleanup(void)
|
||||
* stgbuf (altered)
|
||||
* staging (referred to only)
|
||||
*/
|
||||
SC_FUNC void stgmark(char mark)
|
||||
void stgmark(char mark)
|
||||
{
|
||||
if (staging) {
|
||||
CHECK_STGBUFFER(stgidx);
|
||||
@ -188,7 +188,7 @@ static int filewrite(char *str)
|
||||
* stgbuf (altered)
|
||||
* staging (referred to only)
|
||||
*/
|
||||
SC_FUNC void stgwrite(const char *st)
|
||||
void stgwrite(const char *st)
|
||||
{
|
||||
int len;
|
||||
|
||||
@ -224,7 +224,7 @@ SC_FUNC void stgwrite(const char *st)
|
||||
* stgbuf (referred to only)
|
||||
* staging (referred to only)
|
||||
*/
|
||||
SC_FUNC void stgout(int index)
|
||||
void stgout(int index)
|
||||
{
|
||||
int reordered=0;
|
||||
int idx;
|
||||
@ -348,7 +348,7 @@ static int stgstring(char *start,char *end)
|
||||
* Global references: stgidx (altered)
|
||||
* staging (reffered to only)
|
||||
*/
|
||||
SC_FUNC void stgdel(int index,cell code_index)
|
||||
void stgdel(int index,cell code_index)
|
||||
{
|
||||
if (staging) {
|
||||
stgidx=index;
|
||||
@ -356,7 +356,7 @@ SC_FUNC void stgdel(int index,cell code_index)
|
||||
} /* if */
|
||||
}
|
||||
|
||||
SC_FUNC int stgget(int *index,cell *code_index)
|
||||
int stgget(int *index,cell *code_index)
|
||||
{
|
||||
if (staging) {
|
||||
*index=stgidx;
|
||||
@ -375,7 +375,7 @@ SC_FUNC int stgget(int *index,cell *code_index)
|
||||
* stgidx (altered)
|
||||
* stgbuf (contents altered)
|
||||
*/
|
||||
SC_FUNC void stgset(int onoff)
|
||||
void stgset(int onoff)
|
||||
{
|
||||
staging=onoff;
|
||||
if (staging){
|
||||
@ -398,7 +398,7 @@ SC_FUNC void stgset(int onoff)
|
||||
*/
|
||||
static SEQUENCE *sequences;
|
||||
|
||||
SC_FUNC int phopt_init(void)
|
||||
int phopt_init(void)
|
||||
{
|
||||
int number, i, len;
|
||||
char str[160];
|
||||
@ -440,7 +440,7 @@ SC_FUNC int phopt_init(void)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC int phopt_cleanup(void)
|
||||
int phopt_cleanup(void)
|
||||
{
|
||||
int i;
|
||||
if (sequences!=NULL) {
|
@ -16,7 +16,7 @@
|
||||
|
||||
#define STACKSIZE 16
|
||||
|
||||
SC_FUNC int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2])
|
||||
int strexpand(char *dest, unsigned char *source, int maxlen, unsigned char pairtable[128][2])
|
||||
{
|
||||
unsigned char stack[STACKSIZE];
|
||||
short c, top = 0;
|
@ -113,7 +113,7 @@ static int cp_readline(FILE *fp,char *string,size_t size)
|
||||
* codepages are most conveniently stored in a subdirectory of this home
|
||||
* directory.
|
||||
*/
|
||||
SC_FUNC int cp_path(const char *root, const char *directory)
|
||||
int cp_path(const char *root, const char *directory)
|
||||
{
|
||||
size_t len1,len2;
|
||||
int add_slash1,add_slash2;
|
||||
@ -154,7 +154,7 @@ SC_FUNC int cp_path(const char *root, const char *directory)
|
||||
* <cprootpath>/cp<name>
|
||||
* <cprootpath>/cp<name>.txt
|
||||
*/
|
||||
SC_FUNC int cp_set(const char *name)
|
||||
int cp_set(const char *name)
|
||||
{
|
||||
char filename[_MAX_PATH];
|
||||
FILE *fp=NULL;
|
||||
@ -277,7 +277,7 @@ SC_FUNC int cp_set(const char *name)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endptr)
|
||||
cell cp_translate(const unsigned char *string,const unsigned char **endptr)
|
||||
{
|
||||
wchar_t result;
|
||||
|
||||
@ -312,7 +312,7 @@ SC_FUNC cell cp_translate(const unsigned char *string,const unsigned char **endp
|
||||
#endif /* NO_CODEPAGE */
|
||||
|
||||
#if !defined NO_UTF8
|
||||
SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **endptr)
|
||||
cell get_utf8_char(const unsigned char *string,const unsigned char **endptr)
|
||||
{
|
||||
int follow=0;
|
||||
long lowmark=0;
|
||||
@ -391,7 +391,7 @@ SC_FUNC cell get_utf8_char(const unsigned char *string,const unsigned char **end
|
||||
}
|
||||
#endif
|
||||
|
||||
SC_FUNC int scan_utf8(FILE *fp,const char *filename)
|
||||
int scan_utf8(void *fp,const char *filename)
|
||||
{
|
||||
#if defined NO_UTF8
|
||||
return 0;
|
@ -41,7 +41,7 @@
|
||||
* to other memory allocators becomes easier.
|
||||
* By Søren Hannibal.
|
||||
*/
|
||||
SC_FUNC char* duplicatestring(const char* sourcestring)
|
||||
char* duplicatestring(const char* sourcestring)
|
||||
{
|
||||
char* result=(char*)malloc(strlen(sourcestring)+1);
|
||||
strcpy(result,sourcestring);
|
||||
@ -49,7 +49,7 @@ SC_FUNC char* duplicatestring(const char* sourcestring)
|
||||
}
|
||||
|
||||
|
||||
static stringpair *insert_stringpair(stringpair *root,char *first,char *second,int matchlength)
|
||||
static stringpair *insert_stringpair(stringpair *root,const char *first,const char *second,int matchlength)
|
||||
{
|
||||
stringpair *cur,*pred;
|
||||
|
||||
@ -137,7 +137,7 @@ static int delete_stringpair(stringpair *root,stringpair *item)
|
||||
}
|
||||
|
||||
/* ----- string list functions ----------------------------------- */
|
||||
static stringlist *insert_string(stringlist *root,char *string)
|
||||
static stringlist *insert_string(stringlist *root,const char *string)
|
||||
{
|
||||
stringlist *cur;
|
||||
|
||||
@ -190,7 +190,7 @@ static int delete_string(stringlist *root,int index)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC void delete_stringtable(stringlist *root)
|
||||
void delete_stringtable(stringlist *root)
|
||||
{
|
||||
stringlist *cur,*next;
|
||||
|
||||
@ -210,7 +210,7 @@ SC_FUNC void delete_stringtable(stringlist *root)
|
||||
/* ----- alias table --------------------------------------------- */
|
||||
static stringpair alias_tab = {NULL, NULL, NULL}; /* alias table */
|
||||
|
||||
SC_FUNC stringpair *insert_alias(char *name,char *alias)
|
||||
stringpair *insert_alias(char *name,char *alias)
|
||||
{
|
||||
stringpair *cur;
|
||||
|
||||
@ -223,7 +223,7 @@ SC_FUNC stringpair *insert_alias(char *name,char *alias)
|
||||
return cur;
|
||||
}
|
||||
|
||||
SC_FUNC int lookup_alias(char *target,char *name)
|
||||
int lookup_alias(char *target,char *name)
|
||||
{
|
||||
stringpair *cur=find_stringpair(alias_tab.next,name,strlen(name));
|
||||
if (cur!=NULL) {
|
||||
@ -233,7 +233,7 @@ SC_FUNC int lookup_alias(char *target,char *name)
|
||||
return cur!=NULL;
|
||||
}
|
||||
|
||||
SC_FUNC void delete_aliastable(void)
|
||||
void delete_aliastable(void)
|
||||
{
|
||||
delete_stringpairtable(&alias_tab);
|
||||
}
|
||||
@ -241,17 +241,17 @@ SC_FUNC void delete_aliastable(void)
|
||||
/* ----- include paths list -------------------------------------- */
|
||||
static stringlist includepaths; /* directory list for include files */
|
||||
|
||||
SC_FUNC stringlist *insert_path(char *path)
|
||||
stringlist *insert_path(char *path)
|
||||
{
|
||||
return insert_string(&includepaths,path);
|
||||
}
|
||||
|
||||
SC_FUNC char *get_path(int index)
|
||||
char *get_path(int index)
|
||||
{
|
||||
return get_string(&includepaths,index);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_pathtable(void)
|
||||
void delete_pathtable(void)
|
||||
{
|
||||
delete_stringtable(&includepaths);
|
||||
assert(includepaths.next==NULL);
|
||||
@ -275,7 +275,7 @@ static void adjustindex(char c)
|
||||
substindex[(int)c-PUBLIC_CHAR]=cur;
|
||||
}
|
||||
|
||||
SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen)
|
||||
stringpair *insert_subst(const char *pattern,const char *substitution,int prefixlen)
|
||||
{
|
||||
stringpair *cur;
|
||||
|
||||
@ -306,7 +306,7 @@ SC_FUNC stringpair *insert_subst(char *pattern,char *substitution,int prefixlen)
|
||||
return cur;
|
||||
}
|
||||
|
||||
SC_FUNC stringpair *find_subst(char *name,int length)
|
||||
stringpair *find_subst(char *name,int length)
|
||||
{
|
||||
stringpair *item;
|
||||
assert(name!=NULL);
|
||||
@ -319,12 +319,13 @@ SC_FUNC stringpair *find_subst(char *name,int length)
|
||||
if (item && (item->flags & flgDEPRECATED) != 0)
|
||||
{
|
||||
static char macro[128];
|
||||
char *rem, *msg = (item->documentation != NULL) ? item->documentation : "";
|
||||
const char *msg = (item->documentation != NULL) ? item->documentation : "";
|
||||
strlcpy(macro, item->first, sizeof(macro));
|
||||
|
||||
/* If macro contains an opening parentheses and a percent sign, then assume that
|
||||
* it takes arguments and remove them from the warning message.
|
||||
*/
|
||||
char *rem;
|
||||
if ((rem = strchr(macro, '(')) != NULL && strchr(macro, '%') > rem)
|
||||
{
|
||||
*rem = '\0';
|
||||
@ -335,7 +336,7 @@ SC_FUNC stringpair *find_subst(char *name,int length)
|
||||
return item;
|
||||
}
|
||||
|
||||
SC_FUNC int delete_subst(char *name,int length)
|
||||
int delete_subst(char *name,int length)
|
||||
{
|
||||
stringpair *item;
|
||||
assert(name!=NULL);
|
||||
@ -356,7 +357,7 @@ SC_FUNC int delete_subst(char *name,int length)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
SC_FUNC void delete_substtable(void)
|
||||
void delete_substtable(void)
|
||||
{
|
||||
int i;
|
||||
delete_stringpairtable(&substpair);
|
||||
@ -370,17 +371,17 @@ SC_FUNC void delete_substtable(void)
|
||||
/* ----- input file list ----------------------------------------- */
|
||||
static stringlist sourcefiles;
|
||||
|
||||
SC_FUNC stringlist *insert_sourcefile(char *string)
|
||||
stringlist *insert_sourcefile(char *string)
|
||||
{
|
||||
return insert_string(&sourcefiles,string);
|
||||
}
|
||||
|
||||
SC_FUNC char *get_sourcefile(int index)
|
||||
char *get_sourcefile(int index)
|
||||
{
|
||||
return get_string(&sourcefiles,index);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_sourcefiletable(void)
|
||||
void delete_sourcefiletable(void)
|
||||
{
|
||||
delete_stringtable(&sourcefiles);
|
||||
assert(sourcefiles.next==NULL);
|
||||
@ -391,22 +392,22 @@ SC_FUNC void delete_sourcefiletable(void)
|
||||
#if !defined SC_LIGHT
|
||||
static stringlist docstrings;
|
||||
|
||||
SC_FUNC stringlist *insert_docstring(char *string)
|
||||
stringlist *insert_docstring(char *string)
|
||||
{
|
||||
return insert_string(&docstrings,string);
|
||||
}
|
||||
|
||||
SC_FUNC char *get_docstring(int index)
|
||||
char *get_docstring(int index)
|
||||
{
|
||||
return get_string(&docstrings,index);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_docstring(int index)
|
||||
void delete_docstring(int index)
|
||||
{
|
||||
delete_string(&docstrings,index);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_docstringtable(void)
|
||||
void delete_docstringtable(void)
|
||||
{
|
||||
delete_stringtable(&docstrings);
|
||||
assert(docstrings.next==NULL);
|
||||
@ -417,17 +418,17 @@ SC_FUNC void delete_docstringtable(void)
|
||||
/* ----- autolisting --------------------------------------------- */
|
||||
static stringlist autolist;
|
||||
|
||||
SC_FUNC stringlist *insert_autolist(char *string)
|
||||
stringlist *insert_autolist(const char *string)
|
||||
{
|
||||
return insert_string(&autolist,string);
|
||||
}
|
||||
|
||||
SC_FUNC char *get_autolist(int index)
|
||||
char *get_autolist(int index)
|
||||
{
|
||||
return get_string(&autolist,index);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_autolisttable(void)
|
||||
void delete_autolisttable(void)
|
||||
{
|
||||
delete_stringtable(&autolist);
|
||||
assert(autolist.next==NULL);
|
||||
@ -463,7 +464,7 @@ SC_FUNC void delete_autolisttable(void)
|
||||
|
||||
static stringlist dbgstrings;
|
||||
|
||||
SC_FUNC stringlist *insert_dbgfile(const char *filename)
|
||||
stringlist *insert_dbgfile(const char *filename)
|
||||
{
|
||||
|
||||
if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) {
|
||||
@ -476,7 +477,7 @@ SC_FUNC stringlist *insert_dbgfile(const char *filename)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SC_FUNC stringlist *insert_dbgline(int linenr)
|
||||
stringlist *insert_dbgline(int linenr)
|
||||
{
|
||||
if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) {
|
||||
char string[40];
|
||||
@ -488,7 +489,7 @@ SC_FUNC stringlist *insert_dbgline(int linenr)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SC_FUNC stringlist *insert_dbgsymbol(symbol *sym)
|
||||
stringlist *insert_dbgsymbol(symbol *sym)
|
||||
{
|
||||
if (sc_status==statWRITE && (sc_debug & sSYMBOLIC)!=0) {
|
||||
char string[2*sNAMEMAX+128];
|
||||
@ -521,17 +522,17 @@ SC_FUNC stringlist *insert_dbgsymbol(symbol *sym)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SC_FUNC stringlist *get_dbgstrings()
|
||||
stringlist *get_dbgstrings()
|
||||
{
|
||||
return &dbgstrings;
|
||||
}
|
||||
|
||||
SC_FUNC char *get_dbgstring(int index)
|
||||
char *get_dbgstring(int index)
|
||||
{
|
||||
return get_string(&dbgstrings,index);
|
||||
}
|
||||
|
||||
SC_FUNC void delete_dbgstringtable(void)
|
||||
void delete_dbgstringtable(void)
|
||||
{
|
||||
delete_stringtable(&dbgstrings);
|
||||
assert(dbgstrings.next==NULL);
|
@ -34,8 +34,6 @@
|
||||
#if defined FORTIFY
|
||||
#include <alloc/fortify.h>
|
||||
#endif
|
||||
typedef memfile_t MEMFILE;
|
||||
#define tMEMFILE 1
|
||||
|
||||
#include "sc.h"
|
||||
|
@ -87,7 +87,7 @@ static constvalue *find_automaton(const char *name,int *last)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *automaton_add(const char *name)
|
||||
constvalue *automaton_add(const char *name)
|
||||
{
|
||||
constvalue *ptr;
|
||||
int last;
|
||||
@ -101,13 +101,13 @@ SC_FUNC constvalue *automaton_add(const char *name)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *automaton_find(const char *name)
|
||||
constvalue *automaton_find(const char *name)
|
||||
{
|
||||
int last;
|
||||
return find_automaton(name,&last);
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *automaton_findid(int id)
|
||||
constvalue *automaton_findid(int id)
|
||||
{
|
||||
constvalue *ptr;
|
||||
for (ptr=sc_automaton_tab.next; ptr!=NULL && ptr->index!=id; ptr=ptr->next)
|
||||
@ -135,7 +135,7 @@ static constvalue *find_state(const char *name,int fsa,int *last)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *state_add(const char *name,int fsa)
|
||||
constvalue *state_add(const char *name,int fsa)
|
||||
{
|
||||
constvalue *ptr;
|
||||
int last;
|
||||
@ -149,13 +149,13 @@ SC_FUNC constvalue *state_add(const char *name,int fsa)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *state_find(const char *name,int fsa_id)
|
||||
constvalue *state_find(const char *name,int fsa_id)
|
||||
{
|
||||
int last; /* dummy */
|
||||
return find_state(name,fsa_id,&last);
|
||||
}
|
||||
|
||||
SC_FUNC constvalue *state_findid(int id)
|
||||
constvalue *state_findid(int id)
|
||||
{
|
||||
constvalue *ptr;
|
||||
for (ptr=sc_state_tab.next; ptr!=NULL && ptr->value!=id; ptr=ptr->next)
|
||||
@ -163,7 +163,7 @@ SC_FUNC constvalue *state_findid(int id)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SC_FUNC void state_buildlist(int **list,int *listsize,int *count,int stateid)
|
||||
void state_buildlist(int **list,int *listsize,int *count,int stateid)
|
||||
{
|
||||
int idx;
|
||||
|
||||
@ -227,7 +227,7 @@ static statelist *state_getlist_ptr(int listid)
|
||||
return ptr;
|
||||
}
|
||||
|
||||
SC_FUNC int state_addlist(int *list,int count,int fsa)
|
||||
int state_addlist(int *list,int count,int fsa)
|
||||
{
|
||||
statelist *ptr;
|
||||
int last;
|
||||
@ -253,7 +253,7 @@ SC_FUNC int state_addlist(int *list,int count,int fsa)
|
||||
return ptr->listid;
|
||||
}
|
||||
|
||||
SC_FUNC void state_deletetable(void)
|
||||
void state_deletetable(void)
|
||||
{
|
||||
statelist *ptr;
|
||||
|
||||
@ -268,7 +268,7 @@ SC_FUNC void state_deletetable(void)
|
||||
} /* while */
|
||||
}
|
||||
|
||||
SC_FUNC int state_getfsa(int listid)
|
||||
int state_getfsa(int listid)
|
||||
{
|
||||
statelist *ptr;
|
||||
|
||||
@ -280,7 +280,7 @@ SC_FUNC int state_getfsa(int listid)
|
||||
return (ptr!=NULL) ? ptr->fsa : -1; /* fsa 0 exists */
|
||||
}
|
||||
|
||||
SC_FUNC int state_count(int listid)
|
||||
int state_count(int listid)
|
||||
{
|
||||
statelist *ptr=state_getlist_ptr(listid);
|
||||
if (ptr==NULL)
|
||||
@ -288,7 +288,7 @@ SC_FUNC int state_count(int listid)
|
||||
return ptr->numstates;
|
||||
}
|
||||
|
||||
SC_FUNC int state_inlist(int listid,int state)
|
||||
int state_inlist(int listid,int state)
|
||||
{
|
||||
statelist *ptr;
|
||||
int i;
|
||||
@ -302,7 +302,7 @@ SC_FUNC int state_inlist(int listid,int state)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SC_FUNC int state_listitem(int listid,int index)
|
||||
int state_listitem(int listid,int index)
|
||||
{
|
||||
statelist *ptr;
|
||||
|
||||
@ -329,7 +329,7 @@ static int checkconflict(statelist *psrc,statelist *ptgt)
|
||||
* of a symbol exists in any other statelist id's of the same function; it also
|
||||
* verifies that all definitions of the symbol are in the same automaton.
|
||||
*/
|
||||
SC_FUNC void state_conflict(symbol *root)
|
||||
void state_conflict(symbol *root)
|
||||
{
|
||||
statelist *psrc,*ptgt;
|
||||
constvalue *srcptr,*tgtptr;
|
||||
@ -363,7 +363,7 @@ SC_FUNC void state_conflict(symbol *root)
|
||||
/* check whether the two state lists (whose ids are passed in) share any
|
||||
* states
|
||||
*/
|
||||
SC_FUNC int state_conflict_id(int listid1,int listid2)
|
||||
int state_conflict_id(int listid1,int listid2)
|
||||
{
|
||||
statelist *psrc,*ptgt;
|
||||
|
@ -1,119 +0,0 @@
|
||||
/* Pawn compiler
|
||||
*
|
||||
* Global (cross-module) variables.
|
||||
*
|
||||
* Copyright (c) ITB CompuPhase, 1997-2006
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for _MAX_PATH */
|
||||
#include "sc.h"
|
||||
#include "sp_symhash.h"
|
||||
|
||||
/* global variables
|
||||
*
|
||||
* All global variables that are shared amongst the compiler files are
|
||||
* declared here.
|
||||
*/
|
||||
SC_VDEFINE symbol loctab; /* local symbol table */
|
||||
SC_VDEFINE symbol glbtab; /* global symbol table */
|
||||
SC_VDEFINE cell *litq; /* the literal queue */
|
||||
SC_VDEFINE unsigned char pline[sLINEMAX+1]; /* the line read from the input file */
|
||||
SC_VDEFINE const unsigned char *lptr; /* points to the current position in "pline" */
|
||||
SC_VDEFINE constvalue tagname_tab = { NULL, "", 0, 0}; /* tagname table */
|
||||
SC_VDEFINE constvalue libname_tab = { NULL, "", 0, 0}; /* library table (#pragma library "..." syntax) */
|
||||
SC_VDEFINE constvalue *curlibrary = NULL; /* current library */
|
||||
SC_VDEFINE int pc_addlibtable = TRUE; /* is the library table added to the AMX file? */
|
||||
SC_VDEFINE symbol *curfunc; /* pointer to current function */
|
||||
SC_VDEFINE char *inpfname; /* pointer to name of the file currently read from */
|
||||
SC_VDEFINE char outfname[_MAX_PATH]; /* intermediate (assembler) file name */
|
||||
SC_VDEFINE char binfname[_MAX_PATH]; /* binary file name */
|
||||
SC_VDEFINE char errfname[_MAX_PATH]; /* error file name */
|
||||
SC_VDEFINE char sc_ctrlchar = CTRL_CHAR; /* the control character (or escape character)*/
|
||||
SC_VDEFINE char sc_ctrlchar_org = CTRL_CHAR;/* the default control character */
|
||||
SC_VDEFINE int litidx = 0; /* index to literal table */
|
||||
SC_VDEFINE int litmax = sDEF_LITMAX; /* current size of the literal table */
|
||||
SC_VDEFINE int stgidx = 0; /* index to the staging buffer */
|
||||
SC_VDEFINE int sc_labnum = 0; /* number of (internal) labels */
|
||||
SC_VDEFINE int staging = 0; /* true if staging output */
|
||||
SC_VDEFINE cell declared = 0; /* number of local cells declared */
|
||||
SC_VDEFINE cell glb_declared=0; /* number of global cells declared */
|
||||
SC_VDEFINE cell code_idx = 0; /* number of bytes with generated code */
|
||||
SC_VDEFINE int ntv_funcid= 0; /* incremental number of native function */
|
||||
SC_VDEFINE int errnum = 0; /* number of errors */
|
||||
SC_VDEFINE int warnnum = 0; /* number of warnings */
|
||||
SC_VDEFINE int sc_debug = sCHKBOUNDS; /* by default: bounds checking+assertions */
|
||||
SC_VDEFINE int sc_packstr= FALSE; /* strings are packed by default? */
|
||||
SC_VDEFINE int sc_asmfile= FALSE; /* create .ASM file? */
|
||||
SC_VDEFINE int sc_listing= FALSE; /* create .LST file? */
|
||||
SC_VDEFINE int sc_compress=TRUE; /* compress bytecode? */
|
||||
SC_VDEFINE int sc_needsemicolon=TRUE;/* semicolon required to terminate expressions? */
|
||||
SC_VDEFINE int sc_dataalign=sizeof(cell);/* data alignment value */
|
||||
SC_VDEFINE int sc_alignnext=FALSE; /* must frame of the next function be aligned? */
|
||||
SC_VDEFINE int pc_docexpr=FALSE; /* must expression be attached to documentation comment? */
|
||||
SC_VDEFINE int curseg = 0; /* 1 if currently parsing CODE, 2 if parsing DATA */
|
||||
SC_VDEFINE cell pc_stksize=sDEF_AMXSTACK;/* default stack size */
|
||||
SC_VDEFINE cell pc_amxlimit=0; /* default abstract machine size limit = none */
|
||||
SC_VDEFINE cell pc_amxram=0; /* default abstract machine data size limit = none */
|
||||
SC_VDEFINE int freading = FALSE; /* Is there an input file ready for reading? */
|
||||
SC_VDEFINE int fline = 0; /* the line number in the current file */
|
||||
SC_VDEFINE short fnumber = 0; /* the file number in the file table (debugging) */
|
||||
SC_VDEFINE short fcurrent= 0; /* current file being processed (debugging) */
|
||||
SC_VDEFINE short sc_intest=FALSE; /* true if inside a test */
|
||||
SC_VDEFINE int sideeffect= 0; /* true if an expression causes a side-effect */
|
||||
SC_VDEFINE int stmtindent= 0; /* current indent of the statement */
|
||||
SC_VDEFINE int indent_nowarn=FALSE;/* skip warning "217 loose indentation" */
|
||||
SC_VDEFINE int sc_tabsize=8; /* number of spaces that a TAB represents */
|
||||
SC_VDEFINE short sc_allowtags=TRUE; /* allow/detect tagnames in lex() */
|
||||
SC_VDEFINE int sc_status; /* read/write status */
|
||||
SC_VDEFINE int sc_err_status;
|
||||
SC_VDEFINE int sc_rationaltag=0; /* tag for rational numbers */
|
||||
SC_VDEFINE int rational_digits=0; /* number of fractional digits */
|
||||
SC_VDEFINE int sc_allowproccall=0; /* allow/detect tagnames in lex() */
|
||||
SC_VDEFINE short sc_is_utf8=FALSE; /* is this source file in UTF-8 encoding */
|
||||
SC_VDEFINE char *pc_deprecate=NULL;/* if non-null, mark next declaration as deprecated */
|
||||
SC_VDEFINE int sc_curstates=0; /* ID of the current state list */
|
||||
SC_VDEFINE int pc_optimize=sOPTIMIZE_NOMACRO; /* (peephole) optimization level */
|
||||
SC_VDEFINE int pc_memflags=0; /* special flags for the stack/heap usage */
|
||||
SC_VDEFINE int sc_showincludes=0; /* show include files */
|
||||
SC_VDEFINE int sc_require_newdecls=0; /* Require new-style declarations */
|
||||
|
||||
SC_VDEFINE constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */
|
||||
SC_VDEFINE constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */
|
||||
|
||||
SC_VDEFINE FILE *inpf = NULL; /* file read from (source or include) */
|
||||
SC_VDEFINE FILE *inpf_org= NULL; /* main source file */
|
||||
SC_VDEFINE FILE *outf = NULL; /* (intermediate) text file written to */
|
||||
|
||||
SC_VDEFINE jmp_buf errbuf;
|
||||
|
||||
SC_VDEFINE HashTable *sp_Globals = NULL;
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
SC_VDEFINE int sc_makereport=FALSE; /* generate a cross-reference report */
|
||||
#endif
|
||||
|
||||
#if defined __WATCOMC__ && !defined NDEBUG
|
||||
/* Watcom's CVPACK dislikes .OBJ files without functions */
|
||||
static int dummyfunc(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
119
sourcepawn/compiler/scvars.cpp
Normal file
119
sourcepawn/compiler/scvars.cpp
Normal file
@ -0,0 +1,119 @@
|
||||
/* Pawn compiler
|
||||
*
|
||||
* Global (cross-module) variables.
|
||||
*
|
||||
* Copyright (c) ITB CompuPhase, 1997-2006
|
||||
*
|
||||
* This software is provided "as-is", without any express or implied warranty.
|
||||
* In no event will the authors be held liable for any damages arising from
|
||||
* the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software in
|
||||
* a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
* Version: $Id$
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h> /* for _MAX_PATH */
|
||||
#include "sc.h"
|
||||
#include "sp_symhash.h"
|
||||
|
||||
/* global variables
|
||||
*
|
||||
* All global variables that are shared amongst the compiler files are
|
||||
* declared here.
|
||||
*/
|
||||
symbol loctab; /* local symbol table */
|
||||
symbol glbtab; /* global symbol table */
|
||||
cell *litq; /* the literal queue */
|
||||
unsigned char pline[sLINEMAX+1]; /* the line read from the input file */
|
||||
const unsigned char *lptr; /* points to the current position in "pline" */
|
||||
constvalue tagname_tab = { NULL, "", 0, 0}; /* tagname table */
|
||||
constvalue libname_tab = { NULL, "", 0, 0}; /* library table (#pragma library "..." syntax) */
|
||||
constvalue *curlibrary = NULL; /* current library */
|
||||
int pc_addlibtable = TRUE; /* is the library table added to the AMX file? */
|
||||
symbol *curfunc; /* pointer to current function */
|
||||
char *inpfname; /* pointer to name of the file currently read from */
|
||||
char outfname[_MAX_PATH]; /* intermediate (assembler) file name */
|
||||
char binfname[_MAX_PATH]; /* binary file name */
|
||||
char errfname[_MAX_PATH]; /* error file name */
|
||||
char sc_ctrlchar = CTRL_CHAR; /* the control character (or escape character)*/
|
||||
char sc_ctrlchar_org = CTRL_CHAR;/* the default control character */
|
||||
int litidx = 0; /* index to literal table */
|
||||
int litmax = sDEF_LITMAX; /* current size of the literal table */
|
||||
int stgidx = 0; /* index to the staging buffer */
|
||||
int sc_labnum = 0; /* number of (internal) labels */
|
||||
int staging = 0; /* true if staging output */
|
||||
cell declared = 0; /* number of local cells declared */
|
||||
cell glb_declared=0; /* number of global cells declared */
|
||||
cell code_idx = 0; /* number of bytes with generated code */
|
||||
int ntv_funcid= 0; /* incremental number of native function */
|
||||
int errnum = 0; /* number of errors */
|
||||
int warnnum = 0; /* number of warnings */
|
||||
int sc_debug = sCHKBOUNDS; /* by default: bounds checking+assertions */
|
||||
int sc_packstr= FALSE; /* strings are packed by default? */
|
||||
int sc_asmfile= FALSE; /* create .ASM file? */
|
||||
int sc_listing= FALSE; /* create .LST file? */
|
||||
int sc_compress=TRUE; /* compress bytecode? */
|
||||
int sc_needsemicolon=TRUE;/* semicolon required to terminate expressions? */
|
||||
int sc_dataalign=sizeof(cell);/* data alignment value */
|
||||
int sc_alignnext=FALSE; /* must frame of the next function be aligned? */
|
||||
int pc_docexpr=FALSE; /* must expression be attached to documentation comment? */
|
||||
int curseg = 0; /* 1 if currently parsing CODE, 2 if parsing DATA */
|
||||
cell pc_stksize=sDEF_AMXSTACK;/* default stack size */
|
||||
cell pc_amxlimit=0; /* default abstract machine size limit = none */
|
||||
cell pc_amxram=0; /* default abstract machine data size limit = none */
|
||||
int freading = FALSE; /* Is there an input file ready for reading? */
|
||||
int fline = 0; /* the line number in the current file */
|
||||
short fnumber = 0; /* the file number in the file table (debugging) */
|
||||
short fcurrent= 0; /* current file being processed (debugging) */
|
||||
short sc_intest=FALSE; /* true if inside a test */
|
||||
int sideeffect= 0; /* true if an expression causes a side-effect */
|
||||
int stmtindent= 0; /* current indent of the statement */
|
||||
int indent_nowarn=FALSE;/* skip warning "217 loose indentation" */
|
||||
int sc_tabsize=8; /* number of spaces that a TAB represents */
|
||||
short sc_allowtags=TRUE; /* allow/detect tagnames in lex() */
|
||||
int sc_status; /* read/write status */
|
||||
int sc_err_status;
|
||||
int sc_rationaltag=0; /* tag for rational numbers */
|
||||
int rational_digits=0; /* number of fractional digits */
|
||||
int sc_allowproccall=0; /* allow/detect tagnames in lex() */
|
||||
short sc_is_utf8=FALSE; /* is this source file in UTF-8 encoding */
|
||||
char *pc_deprecate=NULL;/* if non-null, mark next declaration as deprecated */
|
||||
int sc_curstates=0; /* ID of the current state list */
|
||||
int pc_optimize=sOPTIMIZE_NOMACRO; /* (peephole) optimization level */
|
||||
int pc_memflags=0; /* special flags for the stack/heap usage */
|
||||
int sc_showincludes=0; /* show include files */
|
||||
int sc_require_newdecls=0; /* Require new-style declarations */
|
||||
|
||||
constvalue sc_automaton_tab = { NULL, "", 0, 0}; /* automaton table */
|
||||
constvalue sc_state_tab = { NULL, "", 0, 0}; /* state table */
|
||||
|
||||
void *inpf = NULL; /* file read from (source or include) */
|
||||
void *inpf_org= NULL; /* main source file */
|
||||
void *outf = NULL; /* (intermediate) text file written to */
|
||||
|
||||
jmp_buf errbuf;
|
||||
|
||||
HashTable *sp_Globals = NULL;
|
||||
|
||||
#if !defined SC_LIGHT
|
||||
int sc_makereport=FALSE; /* generate a cross-reference report */
|
||||
#endif
|
||||
|
||||
#if defined __WATCOMC__ && !defined NDEBUG
|
||||
/* Watcom's CVPACK dislikes .OBJ files without functions */
|
||||
static int dummyfunc(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
@ -211,40 +211,3 @@ int mf_setpos(void *handle, size_t pos)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#if UNUSED_FOR_NOW
|
||||
/**
|
||||
* Default file operations...
|
||||
* Based on C standard library calls.
|
||||
*/
|
||||
|
||||
void *fp_open(const char *name)
|
||||
{
|
||||
return fopen(name, "wb");
|
||||
}
|
||||
|
||||
void fp_close(void *handle)
|
||||
{
|
||||
fclose((FILE *)handle);
|
||||
}
|
||||
|
||||
size_t fp_write(const void *buf, size_t size, size_t count, void *handle)
|
||||
{
|
||||
return fwrite(buf, size, count, (FILE *)handle);
|
||||
}
|
||||
|
||||
size_t fp_read(void *buf, size_t size, size_t count, void *handle)
|
||||
{
|
||||
return fread(buf, size, count, (FILE *)handle);
|
||||
}
|
||||
|
||||
size_t fp_getpos(void *handle)
|
||||
{
|
||||
return (size_t)ftell((FILE *)handle);
|
||||
}
|
||||
|
||||
int fp_setpos(void *handle, size_t pos)
|
||||
{
|
||||
return fseek((FILE *)handle, (long)pos, SEEK_SET);
|
||||
}
|
||||
#endif
|
@ -1,230 +0,0 @@
|
||||
/* vim: set ts=4 sw=4 tw=99 et: */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "sp_file_headers.h"
|
||||
#include "sc.h"
|
||||
#include "sp_symhash.h"
|
||||
|
||||
SC_FUNC uint32_t
|
||||
NameHash(const char *str)
|
||||
{
|
||||
size_t len = strlen(str);
|
||||
const uint8_t *data = (uint8_t *)str;
|
||||
#undef get16bits
|
||||
#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \
|
||||
|| defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__)
|
||||
#define get16bits(d) (*((const uint16_t *) (d)))
|
||||
#endif
|
||||
#if !defined (get16bits)
|
||||
#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\
|
||||
+(uint32_t)(((const uint8_t *)(d))[0]) )
|
||||
#endif
|
||||
uint32_t hash = len, tmp;
|
||||
int rem;
|
||||
|
||||
if (len <= 0 || data == NULL) return 0;
|
||||
|
||||
rem = len & 3;
|
||||
len >>= 2;
|
||||
|
||||
/* Main loop */
|
||||
for (;len > 0; len--) {
|
||||
hash += get16bits (data);
|
||||
tmp = (get16bits (data+2) << 11) ^ hash;
|
||||
hash = (hash << 16) ^ tmp;
|
||||
data += 2*sizeof (uint16_t);
|
||||
hash += hash >> 11;
|
||||
}
|
||||
|
||||
/* Handle end cases */
|
||||
switch (rem) {
|
||||
case 3: hash += get16bits (data);
|
||||
hash ^= hash << 16;
|
||||
hash ^= data[sizeof (uint16_t)] << 18;
|
||||
hash += hash >> 11;
|
||||
break;
|
||||
case 2: hash += get16bits (data);
|
||||
hash ^= hash << 11;
|
||||
hash += hash >> 17;
|
||||
break;
|
||||
case 1: hash += *data;
|
||||
hash ^= hash << 10;
|
||||
hash += hash >> 1;
|
||||
}
|
||||
|
||||
/* Force "avalanching" of final 127 bits */
|
||||
hash ^= hash << 3;
|
||||
hash += hash >> 5;
|
||||
hash ^= hash << 4;
|
||||
hash += hash >> 17;
|
||||
hash ^= hash << 25;
|
||||
hash += hash >> 6;
|
||||
|
||||
return hash;
|
||||
|
||||
#undef get16bits
|
||||
}
|
||||
|
||||
SC_FUNC HashTable *NewHashTable()
|
||||
{
|
||||
HashTable *ht = (HashTable*)malloc(sizeof(HashTable));
|
||||
if (!ht)
|
||||
return ht;
|
||||
ht->buckets = (HashEntry **)calloc(32, sizeof(HashEntry *));
|
||||
if (!ht->buckets) {
|
||||
free(ht);
|
||||
return NULL;
|
||||
}
|
||||
ht->nbuckets = 32;
|
||||
ht->nused = 0;
|
||||
ht->bucketmask = 32 - 1;
|
||||
return ht;
|
||||
}
|
||||
|
||||
SC_FUNC void
|
||||
DestroyHashTable(HashTable *ht)
|
||||
{
|
||||
uint32_t i;
|
||||
if (!ht)
|
||||
return;
|
||||
for (i = 0; i < ht->nbuckets; i++) {
|
||||
HashEntry *he = ht->buckets[i];
|
||||
while (he != NULL) {
|
||||
HashEntry *next = he->next;
|
||||
free(he);
|
||||
he = next;
|
||||
}
|
||||
}
|
||||
free(ht->buckets);
|
||||
free(ht);
|
||||
}
|
||||
|
||||
SC_FUNC symbol *
|
||||
FindTaggedInHashTable(HashTable *ht, const char *name, int fnumber,
|
||||
int *cmptag)
|
||||
{
|
||||
int count=0;
|
||||
symbol *firstmatch=NULL;
|
||||
uint32_t hash = NameHash(name);
|
||||
uint32_t bucket = hash & ht->bucketmask;
|
||||
HashEntry *he = ht->buckets[bucket];
|
||||
|
||||
assert(cmptag!=NULL);
|
||||
|
||||
while (he != NULL) {
|
||||
symbol *sym = he->sym;
|
||||
if ((sym->parent==NULL || sym->ident==iCONSTEXPR) &&
|
||||
(sym->fnumber<0 || sym->fnumber==fnumber) &&
|
||||
(strcmp(sym->name, name) == 0))
|
||||
{
|
||||
/* return closest match or first match; count number of matches */
|
||||
if (firstmatch==NULL)
|
||||
firstmatch=sym;
|
||||
if (*cmptag==0)
|
||||
count++;
|
||||
if (*cmptag==sym->tag) {
|
||||
*cmptag=1; /* good match found, set number of matches to 1 */
|
||||
return sym;
|
||||
}
|
||||
}
|
||||
he = he->next;
|
||||
}
|
||||
|
||||
if (firstmatch!=NULL)
|
||||
*cmptag=count;
|
||||
return firstmatch;
|
||||
}
|
||||
|
||||
SC_FUNC symbol *
|
||||
FindInHashTable(HashTable *ht, const char *name, int fnumber)
|
||||
{
|
||||
uint32_t hash = NameHash(name);
|
||||
uint32_t bucket = hash & ht->bucketmask;
|
||||
HashEntry *he = ht->buckets[bucket];
|
||||
|
||||
while (he != NULL) {
|
||||
symbol *sym = he->sym;
|
||||
if ((sym->parent==NULL || sym->ident==iCONSTEXPR) &&
|
||||
(sym->fnumber<0 || sym->fnumber==fnumber) &&
|
||||
(strcmp(sym->name, name) == 0))
|
||||
{
|
||||
return sym;
|
||||
}
|
||||
he = he->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
ResizeHashTable(HashTable *ht)
|
||||
{
|
||||
uint32_t i;
|
||||
uint32_t xnbuckets = ht->nbuckets * 2;
|
||||
uint32_t xbucketmask = xnbuckets - 1;
|
||||
HashEntry **xbuckets = (HashEntry **)calloc(xnbuckets, sizeof(HashEntry*));
|
||||
if (!xbuckets)
|
||||
return;
|
||||
|
||||
for (i = 0; i < ht->nbuckets; i++) {
|
||||
HashEntry *he = ht->buckets[i];
|
||||
while (he != NULL) {
|
||||
HashEntry *next = he->next;
|
||||
uint32_t bucket = he->sym->hash & xbucketmask;
|
||||
he->next = xbuckets[bucket];
|
||||
xbuckets[bucket] = he;
|
||||
he = next;
|
||||
}
|
||||
}
|
||||
free(ht->buckets);
|
||||
ht->buckets = xbuckets;
|
||||
ht->nbuckets = xnbuckets;
|
||||
ht->bucketmask = xbucketmask;
|
||||
}
|
||||
|
||||
SC_FUNC void
|
||||
AddToHashTable(HashTable *ht, symbol *sym)
|
||||
{
|
||||
uint32_t bucket = sym->hash & ht->bucketmask;
|
||||
HashEntry **hep, *he;
|
||||
|
||||
hep = &ht->buckets[bucket];
|
||||
while (*hep) {
|
||||
assert((*hep)->sym != sym);
|
||||
hep = &(*hep)->next;
|
||||
}
|
||||
|
||||
he = (HashEntry *)malloc(sizeof(HashEntry));
|
||||
if (!he)
|
||||
error(163);
|
||||
he->sym = sym;
|
||||
he->next = NULL;
|
||||
*hep = he;
|
||||
ht->nused++;
|
||||
|
||||
if (ht->nused > ht->nbuckets && ht->nbuckets <= INT_MAX / 2)
|
||||
ResizeHashTable(ht);
|
||||
}
|
||||
|
||||
SC_FUNC void
|
||||
RemoveFromHashTable(HashTable *ht, symbol *sym)
|
||||
{
|
||||
uint32_t bucket = sym->hash & ht->bucketmask;
|
||||
HashEntry **hep = &ht->buckets[bucket];
|
||||
HashEntry *he = *hep;
|
||||
|
||||
while (he != NULL) {
|
||||
if (he->sym == sym) {
|
||||
*hep = he->next;
|
||||
free(he);
|
||||
ht->nused--;
|
||||
return;
|
||||
}
|
||||
hep = &he->next;
|
||||
he = *hep;
|
||||
}
|
||||
|
||||
assert(0);
|
||||
}
|
||||
|
130
sourcepawn/compiler/sp_symhash.cpp
Normal file
130
sourcepawn/compiler/sp_symhash.cpp
Normal file
@ -0,0 +1,130 @@
|
||||
// vim: set ts=8 sts=2 sw=2 tw=99 et:
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include "sp_file_headers.h"
|
||||
#include "sc.h"
|
||||
#include "sp_symhash.h"
|
||||
#include <am-hashtable.h>
|
||||
|
||||
struct NameAndScope
|
||||
{
|
||||
const char *name;
|
||||
int fnumber;
|
||||
int *cmptag;
|
||||
mutable symbol *matched;
|
||||
mutable int count;
|
||||
|
||||
NameAndScope(const char *name, int fnumber, int *cmptag)
|
||||
: name(name),
|
||||
fnumber(fnumber),
|
||||
cmptag(cmptag),
|
||||
matched(nullptr),
|
||||
count(0)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
struct SymbolHashPolicy
|
||||
{
|
||||
typedef symbol *Payload;
|
||||
|
||||
// Everything with the same name has the same hash, because the compiler
|
||||
// wants to know two names that have the same tag for some reason. Even
|
||||
// so, we can't be that accurate, since we might match the right symbol
|
||||
// very early.
|
||||
static uint32_t hash(const NameAndScope &key) {
|
||||
return ke::HashCharSequence(key.name, strlen(key.name));
|
||||
}
|
||||
static uint32_t hash(const symbol *s) {
|
||||
return ke::HashCharSequence(s->name, strlen(s->name));
|
||||
}
|
||||
|
||||
static bool matches(const NameAndScope &key, symbol *sym) {
|
||||
if (sym->parent && sym->ident != iCONSTEXPR)
|
||||
return false;
|
||||
if (sym->fnumber >= 0 && sym->fnumber != key.fnumber)
|
||||
return false;
|
||||
if (strcmp(key.name, sym->name) != 0)
|
||||
return false;
|
||||
if (key.cmptag) {
|
||||
key.count++;
|
||||
key.matched = sym;
|
||||
if (*key.cmptag != sym->tag)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool matches(const symbol *key, symbol *sym) {
|
||||
return key == sym;
|
||||
}
|
||||
};
|
||||
|
||||
struct HashTable : public ke::HashTable<SymbolHashPolicy>
|
||||
{
|
||||
};
|
||||
|
||||
uint32_t
|
||||
NameHash(const char *str)
|
||||
{
|
||||
return ke::HashCharSequence(str, strlen(str));
|
||||
}
|
||||
|
||||
HashTable *NewHashTable()
|
||||
{
|
||||
HashTable *ht = new HashTable();
|
||||
if (!ht->init()) {
|
||||
delete ht;
|
||||
return nullptr;
|
||||
}
|
||||
return ht;
|
||||
}
|
||||
|
||||
void
|
||||
DestroyHashTable(HashTable *ht)
|
||||
{
|
||||
delete ht;
|
||||
}
|
||||
|
||||
symbol *
|
||||
FindTaggedInHashTable(HashTable *ht, const char *name, int fnumber, int *cmptag)
|
||||
{
|
||||
NameAndScope nas(name, fnumber, cmptag);
|
||||
HashTable::Result r = ht->find(nas);
|
||||
if (!r.found()) {
|
||||
if (nas.matched) {
|
||||
*cmptag = nas.count;
|
||||
return nas.matched;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
*cmptag = 1;
|
||||
return *r;
|
||||
}
|
||||
|
||||
symbol *
|
||||
FindInHashTable(HashTable *ht, const char *name, int fnumber)
|
||||
{
|
||||
NameAndScope nas(name, fnumber, nullptr);
|
||||
HashTable::Result r = ht->find(nas);
|
||||
if (!r.found())
|
||||
return nullptr;
|
||||
return *r;
|
||||
}
|
||||
|
||||
void
|
||||
AddToHashTable(HashTable *ht, symbol *sym)
|
||||
{
|
||||
HashTable::Insert i = ht->findForAdd(sym);
|
||||
assert(!i.found());
|
||||
ht->add(i, sym);
|
||||
}
|
||||
|
||||
void
|
||||
RemoveFromHashTable(HashTable *ht, symbol *sym)
|
||||
{
|
||||
HashTable::Result r = ht->find(sym);
|
||||
assert(r.found());
|
||||
ht->remove(r);
|
||||
}
|
@ -1,28 +1,18 @@
|
||||
/* vim: set ts=4 sw=4 tw=99 et: */
|
||||
#ifndef _INCLUDE_SPCOMP_SYMHASH_H_
|
||||
#define _INCLUDE_SPCOMP_SYMHASH_H_
|
||||
|
||||
SC_FUNC uint32_t NameHash(const char *str);
|
||||
|
||||
typedef struct HashEntry {
|
||||
symbol *sym;
|
||||
struct HashEntry *next;
|
||||
} HashEntry;
|
||||
|
||||
struct HashTable {
|
||||
uint32_t nbuckets;
|
||||
uint32_t nused;
|
||||
uint32_t bucketmask;
|
||||
HashEntry **buckets;
|
||||
};
|
||||
|
||||
SC_FUNC HashTable *NewHashTable();
|
||||
SC_FUNC void DestroyHashTable(HashTable *ht);
|
||||
SC_FUNC void AddToHashTable(HashTable *ht, symbol *sym);
|
||||
SC_FUNC void RemoveFromHashTable(HashTable *ht, symbol *sym);
|
||||
SC_FUNC symbol *FindInHashTable(HashTable *ht, const char *name, int fnumber);
|
||||
SC_FUNC symbol *FindTaggedInHashTable(HashTable *ht, const char *name, int fnumber,
|
||||
int *cmptag);
|
||||
|
||||
#endif /* _INCLUDE_SPCOMP_SYMHASH_H_ */
|
||||
|
||||
/* vim: set ts=4 sw=4 tw=99 et: */
|
||||
#ifndef _INCLUDE_SPCOMP_SYMHASH_H_
|
||||
#define _INCLUDE_SPCOMP_SYMHASH_H_
|
||||
|
||||
uint32_t NameHash(const char *str);
|
||||
|
||||
struct HashTable;
|
||||
|
||||
HashTable *NewHashTable();
|
||||
void DestroyHashTable(HashTable *ht);
|
||||
void AddToHashTable(HashTable *ht, symbol *sym);
|
||||
void RemoveFromHashTable(HashTable *ht, symbol *sym);
|
||||
symbol *FindInHashTable(HashTable *ht, const char *name, int fnumber);
|
||||
symbol *FindTaggedInHashTable(HashTable *ht, const char *name, int fnumber,
|
||||
int *cmptag);
|
||||
|
||||
#endif /* _INCLUDE_SPCOMP_SYMHASH_H_ */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user