mirror of
https://github.com/sfall-team/sslc.git
synced 2026-07-27 16:52:49 -07:00
commit source from sfall 4.2 modderspack
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
# sslc
|
||||
Script compiler/parser for FO2/sfall scripts.
|
||||
|
||||
Script compiler/parser for Fallout 2/sfall script.
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define _CRT_RAND_S
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "lex.h"
|
||||
#include "parse.h"
|
||||
#include <io.h>
|
||||
|
||||
int noinputwait = 0;
|
||||
int warnings = 1;
|
||||
int backwardcompat = 0;
|
||||
int optimize = 0;
|
||||
int debug = 0;
|
||||
int preprocess_fullpath = 0;
|
||||
int dumpTree = 0;
|
||||
int shortCircuit = 0;
|
||||
FILE *parseroutput;
|
||||
|
||||
#define FINDDATA _finddata_t
|
||||
#define FINDFIRST(x, y) _findfirst(x, y)
|
||||
#define FINDNEXT(x, y) _findnext(x, y)
|
||||
#define FINDCLOSE(x, y) _findclose(x)
|
||||
#define FINDHANDLE long
|
||||
// #define BAD_HANDLE -1
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define FIND_SUCCESS(x) ((x) != -1)
|
||||
#else
|
||||
#define FIND_SUCCESS(x) ((x) == 0)
|
||||
#endif
|
||||
|
||||
static void PrintLogo() {
|
||||
parseOutput("Startreck scripting language compiler (Fallout 2 sfall edition 4.2)\n\n"
|
||||
"Preprocessing handled by mcpp 2.7.2\n"
|
||||
"Copyright (c) 1998, 2002-2008 Kiyoshi Matsui <kmatsui@t3.rim.or.jp>\n"
|
||||
"All rights reserved.\n\n");
|
||||
}
|
||||
|
||||
extern int warn_level; //the mcpp warning level
|
||||
extern int mcpp_lib_main(FILE *fin, FILE *fout, const char* in_file, const char* dir);
|
||||
//extern void set_a_dir(const char * dirname);
|
||||
|
||||
#ifndef BUILDING_DLL
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
InputStream foo;
|
||||
char name[260], *c, *file;
|
||||
struct FINDDATA buf;
|
||||
FINDHANDLE handle;
|
||||
int nologo=0;
|
||||
int preprocess=0;
|
||||
int onlypreprocess=0;
|
||||
|
||||
if (argc < 2) {
|
||||
PrintLogo();
|
||||
parseOutput("Usage: compile {switches} filename [-o outputname] [filename [..]]\n");
|
||||
parseOutput(" -q don't wait for input on error\n");
|
||||
parseOutput(" -n no warnings\n");
|
||||
parseOutput(" -b use backward compatibility mode\n");
|
||||
parseOutput(" -l no logo\n");
|
||||
parseOutput(" -p preprocess\n");
|
||||
parseOutput(" -P preprocess only. (Don't generate .int)\n");
|
||||
parseOutput(" -F write full file paths in #line directives\n");
|
||||
parseOutput(" -O<level> optimize (0 - none, 1 - only remove unreferenced globals, 2 - full, 3 - full+experimental, don't use!)\n");
|
||||
parseOutput(" -d show debug info\n");
|
||||
parseOutput(" -s enable short-circuit evaluation for boolean operators (AND, OR)\n");
|
||||
parseOutput(" -D dump abstract syntax tree after optimizations\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
while((argv[1] != NULL) && (argv[1][0] == '-')) {
|
||||
switch(argv[1][1]) {
|
||||
case 'w':
|
||||
case '-':
|
||||
break;
|
||||
case 'n':
|
||||
warnings=0;
|
||||
warn_level=0;
|
||||
break;
|
||||
case 'q':
|
||||
noinputwait=1;
|
||||
break;
|
||||
case 'd':
|
||||
debug=1;
|
||||
break;
|
||||
case 'b':
|
||||
backwardcompat = 1;
|
||||
break;
|
||||
case 'l':
|
||||
nologo=1;
|
||||
break;
|
||||
case 'O':
|
||||
if (strlen(argv[1]) == 2) optimize = 2;
|
||||
else optimize = atoi(&argv[1][2]);
|
||||
break;
|
||||
case 'P':
|
||||
onlypreprocess = 1;
|
||||
case 'p':
|
||||
preprocess = 1;
|
||||
break;
|
||||
case 'F':
|
||||
preprocess_fullpath = 1;
|
||||
break;
|
||||
case 'D':
|
||||
dumpTree = 1;
|
||||
break;
|
||||
case 's':
|
||||
shortCircuit = 1;
|
||||
break;
|
||||
default:
|
||||
parseOutput("Unknown option %c\n", argv[1][1]);
|
||||
}
|
||||
|
||||
argv++;
|
||||
argc--;
|
||||
}
|
||||
|
||||
/*if(backwardcompat&&(optimize||preprocess)) {
|
||||
parseOutput("Invalid option combination; cannot run preprocess or optimization passes in backward compatibility mode\n");
|
||||
return -1;
|
||||
}*/
|
||||
|
||||
if(!nologo) PrintLogo();
|
||||
|
||||
compilerErrorTotal = 0;
|
||||
|
||||
while(argv[1]) {
|
||||
file = argv[1];
|
||||
argv++;
|
||||
argc--;
|
||||
|
||||
if (FIND_SUCCESS(handle = FINDFIRST(file, &buf))) {
|
||||
do {
|
||||
foo.name = AddFileName(buf.name);
|
||||
|
||||
if ((foo.file = fopen(buf.name, "r")) == 0) {
|
||||
parseOutput("Couldn't find file %s\n", buf.name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
parseOutput("Compiling %s\n", buf.name);
|
||||
|
||||
if(argc>=2&&!strcmp(argv[1], "-o")) {
|
||||
argv+=2;
|
||||
argc-=2;
|
||||
strcpy_s(name, 260, argv[0]);
|
||||
} else {
|
||||
strcpy_s(name, 260, buf.name);
|
||||
c = strrchr(name, '.');
|
||||
|
||||
if (c) {
|
||||
*c = 0;
|
||||
}
|
||||
|
||||
if(onlypreprocess) {
|
||||
strcat_s(name, 260, ".preprocessed.ssl");
|
||||
|
||||
if (strcmp(name, buf.name) == 0) {
|
||||
c = strrchr(name, '.');
|
||||
*c = 0;
|
||||
*--c = 0;
|
||||
strcat_s(name, 260, "1.preprocessed.ssl");
|
||||
}
|
||||
} else {
|
||||
strcat_s(name, 260, ".int");
|
||||
|
||||
if (strcmp(name, buf.name) == 0) {
|
||||
c = strrchr(name, '.');
|
||||
*c = 0;
|
||||
*--c = 0;
|
||||
strcat_s(name, 260, "1.int");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(preprocess) {
|
||||
FILE *newfile;
|
||||
unsigned int letters;
|
||||
char tmpbuf[260];
|
||||
rand_s(&letters);
|
||||
if(onlypreprocess) {
|
||||
strcpy_s(tmpbuf, 260, name);
|
||||
newfile=fopen(tmpbuf, "w+");
|
||||
} else {
|
||||
sprintf(tmpbuf, "%d_%8x.tmp", GetCurrentProcessId(), letters);
|
||||
//#if _DEBUG
|
||||
// newfile=fopen(tmpbuf, "w+");
|
||||
//#else
|
||||
newfile=fopen(tmpbuf, "w+DT");
|
||||
//#endif
|
||||
}
|
||||
if(mcpp_lib_main(foo.file, newfile, buf.name, buf.name)) {
|
||||
parseOutput("*** An error occured during preprocessing of %s ***\n", buf.name);
|
||||
return 1;
|
||||
}
|
||||
fclose(foo.file);
|
||||
rewind(newfile);
|
||||
foo.file=newfile;
|
||||
}
|
||||
if(!onlypreprocess) {
|
||||
parse(&foo, name);
|
||||
freeCurrentProgram();
|
||||
}
|
||||
fclose(foo.file);
|
||||
FreeFileNames();
|
||||
} while (!FINDNEXT(handle, &buf));
|
||||
|
||||
FINDCLOSE(handle, &buf);
|
||||
|
||||
if (compilerErrorTotal) {
|
||||
parseOutput("\n*** THERE WERE ERRORS (%u of them) ***\n", compilerErrorTotal);
|
||||
if (!noinputwait)
|
||||
getchar();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
parseOutput("Warning: %s not found\n", file);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef BUILDING_DLL
|
||||
|
||||
static int inited=0;
|
||||
|
||||
int _stdcall parse_main(const char *filePath, const char* origPath, const char* dir, int backMode) {
|
||||
InputStream foo;
|
||||
char tmpbuf[260];
|
||||
//char cwd[1024];
|
||||
FILE *newfile;
|
||||
unsigned int letters;
|
||||
|
||||
if(inited) {
|
||||
freeCurrentProgram();
|
||||
FreeFileNames();
|
||||
inited=0;
|
||||
}
|
||||
|
||||
if (backMode) {
|
||||
backwardcompat = 1;
|
||||
lexClear();
|
||||
}
|
||||
|
||||
foo.name=AddFileName(origPath);
|
||||
foo.file = fopen(filePath, "r");
|
||||
|
||||
rand_s(&letters);
|
||||
sprintf(tmpbuf, "%d_%8x.tmp", GetCurrentProcessId(), letters);
|
||||
newfile=fopen(tmpbuf, "w+DT");
|
||||
//newfile=fopen(tmpbuf, "w+");
|
||||
parseroutput = fopen("errors.txt", "w");
|
||||
//GetCurrentDirectoryA(1024, cwd);
|
||||
//chdir(dir);
|
||||
compilerErrorTotal = 0;
|
||||
compilerSyntaxError = 0;
|
||||
preprocess_fullpath = 1;
|
||||
if (mcpp_lib_main(foo.file, newfile, origPath, dir)) {
|
||||
fclose(foo.file);
|
||||
fclose(newfile);
|
||||
if (parseroutput)
|
||||
fclose(parseroutput);
|
||||
return 2;
|
||||
}
|
||||
//chdir(cwd);
|
||||
|
||||
fclose(foo.file);
|
||||
//fflush(newfile);
|
||||
rewind(newfile);
|
||||
foo.file=newfile;
|
||||
parse(&foo, NULL);
|
||||
fclose(foo.file);
|
||||
|
||||
inited=1;
|
||||
if (parseroutput)
|
||||
fclose(parseroutput);
|
||||
|
||||
return (compilerErrorTotal) ? 1 : (compilerSyntaxError) ? -1 : 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
LIBRARY parser
|
||||
EXPORTS
|
||||
parse_main
|
||||
numProcs
|
||||
getProc
|
||||
getProcNamespaceSize
|
||||
getProcNamespace
|
||||
numVars
|
||||
getVar
|
||||
getProcVar
|
||||
namespaceSize
|
||||
getNamespace
|
||||
stringspaceSize
|
||||
getStringspace
|
||||
getProcRefs
|
||||
getVarRefs
|
||||
getProcVarRefs
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef _GENCODE_H_
|
||||
#define _GENCODE_H_
|
||||
|
||||
extern void generateCode(Program *, const char *);
|
||||
|
||||
extern int writeNumExpression(NodeList *n, int i, int num, FILE *f);
|
||||
extern int writeExpression(NodeList *n, int i, FILE *f);
|
||||
extern int writeExpressionProc(NodeList *n, int i, FILE *f);
|
||||
extern int writeNumExpressionProc(NodeList *n, int i, int num, FILE *f);
|
||||
extern void writeOp(unsigned short op, FILE *f);
|
||||
extern void writeInt(unsigned long a, FILE *f);
|
||||
extern void writeFloat(float a, FILE *f);
|
||||
extern void writeString(unsigned long a, FILE *f);
|
||||
extern int writeBlock(NodeList *n, int i, FILE *f);
|
||||
|
||||
#endif
|
||||
+558
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,56 @@
|
||||
#ifndef _LEX_H_
|
||||
#define _LEX_H_
|
||||
|
||||
#include "tokens.h"
|
||||
|
||||
typedef struct {
|
||||
int token; /* token we just parsed */
|
||||
int type; /* will be either T_INT, T_FLOAT, T_STRING, or T_SYMBOL */
|
||||
union {
|
||||
char *stringData;
|
||||
int intData;
|
||||
float floatData;
|
||||
};
|
||||
} LexData;
|
||||
|
||||
extern LexData lexData;
|
||||
extern char *tokens[];
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int lastChar;
|
||||
int lineno;
|
||||
int column;
|
||||
int lastLineLen;
|
||||
// int lastColumn; // column of last token
|
||||
union {
|
||||
FILE *file;
|
||||
struct {
|
||||
char *string;
|
||||
int len;
|
||||
char *curpos;
|
||||
int readEOF;
|
||||
} s;
|
||||
};
|
||||
} InputStream;
|
||||
|
||||
extern const char* AddFileName(const char *c);
|
||||
extern void FreeFileNames();
|
||||
extern void ungetToken(void);
|
||||
extern void setNextToken(LexData *data);
|
||||
extern int lex(void);
|
||||
extern void initLex(void), lexClose(void), lexClear(void);
|
||||
extern void startLex(InputStream *);
|
||||
extern void continueLex(InputStream *);
|
||||
extern int lexGetLineno(InputStream *);
|
||||
extern int lexGetColumn(InputStream *);
|
||||
extern const char *lexGetFilename(InputStream *);
|
||||
extern void lexAddToken(int token, char *name);
|
||||
extern void lexAddConstant(int c, char *name, int type, unsigned long val);
|
||||
char* lexGetToken(int token);
|
||||
#define INPUT_FILE 1
|
||||
#define INPUT_STRING 2
|
||||
|
||||
#endif
|
||||
+1437
File diff suppressed because it is too large
Load Diff
+1340
File diff suppressed because it is too large
Load Diff
+2436
File diff suppressed because it is too large
Load Diff
+752
File diff suppressed because it is too large
Load Diff
+1961
File diff suppressed because it is too large
Load Diff
+1714
File diff suppressed because it is too large
Load Diff
+213
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* noconfig.H
|
||||
* Configurations for MCPP not using config.h.
|
||||
*
|
||||
* WARNING: These are default settings. To configure for your system, you
|
||||
* must edit this file here and there.
|
||||
*/
|
||||
|
||||
#define TRUE 1
|
||||
#define FALSE 0
|
||||
|
||||
/* Default MBCHAR (multi-byte character) encoding. */
|
||||
#define UTF8 0x1000 /* UTF-8 encoding */
|
||||
|
||||
/*
|
||||
* MBCHAR means multi-byte character encoding.
|
||||
* MBCHAR means the default encoding, and you can change the encoding by
|
||||
* #pragma MCPP setlocale, -e <encoding> option or environment variable
|
||||
* LC_ALL, LC_CTYPE, LANG.
|
||||
* MBCHAR == 0 means not to recognize any multi-byte character encoding.
|
||||
*/
|
||||
|
||||
/*
|
||||
* In order to predefine target-system-dependent macros,
|
||||
* several macros are defined here:
|
||||
* *_OLD define the macro beginning with an alphabetic letter,
|
||||
* *_STD, *_STD?, *_EXT, *_EXT2 define the macro beginning with an '_'.
|
||||
* *_STD1 define the macro beginning with '__' and ending with an alphanumeric
|
||||
* letter.
|
||||
* *_STD2 define the macro beginning with '__' and ending with '__'.
|
||||
* These may not be defined, if they are not needed.
|
||||
* They should not be #defined to no token or to "".
|
||||
*
|
||||
* SYSTEM_OLD, SYSTEM_STD1, SYSTEM_STD2, SYSTEM_EXT, SYSTEM_EXT2
|
||||
* define the target operating system (by name).
|
||||
* SYSTEM_SP_OLD, SYSTEM_SP_STD define the target-OS specific macro name
|
||||
* COMPILER_OLD, COMPILER_STD1, COMPILER_STD2, COMPILER_EXT, COMPILER_EXT2
|
||||
* , COMPILER_SP_OLD, COMPILER_SP_STD
|
||||
* define the target compiler (by name).
|
||||
* COMPILER_CPLUS defines the target C++ compiler.
|
||||
* COMPILER_SP1, COMPILER_SP2, COMPILER_SP3
|
||||
* define the compiler-specific macros.
|
||||
*
|
||||
* <macro>_VAL specify the value of the <macro>.
|
||||
* If not specified, these values default to "1".
|
||||
* To define the value of no-token, specify as "" rather than no-token.
|
||||
* SYSTEM_OLD, SYSTEM_STD?, COMPILER_OLD have the value of "1".
|
||||
*/
|
||||
|
||||
/*
|
||||
* target-compiler-dependent definitions:
|
||||
*
|
||||
* LINE_PREFIX defines the output line prefix, if not "#line 123".
|
||||
* This should be defined as "# " to represent "# 123" format
|
||||
* ("#line " represents "#line 123" format).
|
||||
*
|
||||
* C_INCLUDE_DIR1, C_INCLUDE_DIR2 may be defined if you have a compiler-
|
||||
* specific include directory which is to be searched *before*
|
||||
* the operating-system specific directories (e.g. /usr/include).
|
||||
* CPLUS_INCLUDE_DIR1, CPLUS_INCLUDE_DIR2, CPLUS_INCLUDE_DIR3
|
||||
* , CPLUS_INCLUDE_DIR4 are for C++ include directory which exist
|
||||
* other than C include directory.
|
||||
* ENV_C_INCLUDE_DIR may be defined to the name of environment-variable for
|
||||
* C include directory.
|
||||
* ENV_CPLUS_INCLUDE_DIR is name of environment-variable for C++ include
|
||||
* directory which exists other than ENV_C_INCLUDE_DIR.
|
||||
* ENV_SEP is the separator (other than space) of include-paths in an
|
||||
* environment-variable. e.g. the ':' in
|
||||
* "/usr/abc/include:/usr/xyz/include"
|
||||
*
|
||||
* EMFILE should be defined to the macro to represent errno of 'too many
|
||||
* open files' if the macro is different from EMFILE.
|
||||
*
|
||||
* ONE_PASS should be set TRUE, if COMPILER is "one pass compiler".
|
||||
*
|
||||
* FNAME_FOLD means that target-system folds upper and lower cases of
|
||||
* directory and file-name.
|
||||
*
|
||||
* SEARCH_INIT specifies the default value of 'search_rule' (in system.c).
|
||||
* 'search_rule' holds searching rule of #include "header.h" to
|
||||
* search first before searching user specified or system-
|
||||
* specific include directories.
|
||||
* CURRENT means to search the directory relative to "current
|
||||
* directory" which is current at cpp invocation.
|
||||
* SOURCE means to search the directory relative to that of the
|
||||
* source file (i.e. "includer").
|
||||
* (CURRENT & SOURCE) means to search current directory first
|
||||
* source directory next.
|
||||
* 'search_rule' is initialized to SEARCH_INIT.
|
||||
*/
|
||||
#define CURRENT 1
|
||||
#define SOURCE 2
|
||||
|
||||
#define SYSTEM_SP_STD "__FLAT__"
|
||||
#define SYSTEM_SP_STD_VAL "1"
|
||||
#define SJIS_IS_ESCAPE_FREE TRUE /* or FALSE following your compiler */
|
||||
#define LINE_PREFIX "#line "
|
||||
#define STD_LINE_PREFIX TRUE /* Output #line by C source format */
|
||||
#define HAVE_DIGRAPHS TRUE /* Output digraphs as it is */
|
||||
#define SEARCH_INIT SOURCE /* Include directory relative to source */
|
||||
#define SJIS_IS_ESCAPE_FREE TRUE /* Do not treat SJIS specially */
|
||||
#define BIGFIVE_IS_ESCAPE_FREE TRUE /* Do not treat specially */
|
||||
#define ISO2022_JP_IS_ESCAPE_FREE TRUE /* Do not treat specially */
|
||||
#define TARGET_HAVE_LONG_LONG TRUE /* dummy */
|
||||
#define STDC_VERSION 199409L /* Initial value of __STDC_VERSION__ */
|
||||
#define ENV_C_INCLUDE_DIR "INCLUDE"
|
||||
#define ENV_CPLUS_INCLUDE_DIR "CPLUS_INCLUDE"
|
||||
#define ENV_SEP ';'
|
||||
#define ONE_PASS FALSE
|
||||
#define FNAME_FOLD TRUE
|
||||
|
||||
/*
|
||||
* CHARBIT, UCHARMAX are respectively CHAR_BIT, UCHAR_MAX of target compiler.
|
||||
* CHARBIT should be defined to the number of bits per character.
|
||||
* It is needed only for processing of multi-byte character constants.
|
||||
* UCHARMAX should be defined to the maximum value of type unsigned char
|
||||
* or maximum value of unsigned int which is converted from type (signed)
|
||||
* char.
|
||||
*
|
||||
* LONGMAX should be defined to the LONG_MAX in <limits.h>.
|
||||
* ULONGMAX should be defined to the ULONG_MAX in <limits.h> or LONG_MAX
|
||||
* for the compiler which does not have unsigned long.
|
||||
*/
|
||||
|
||||
#ifndef CHARBIT
|
||||
#define CHARBIT 8
|
||||
#endif
|
||||
#ifndef UCHARMAX
|
||||
#define UCHARMAX 0xFF
|
||||
#endif
|
||||
#ifndef LONGMAX
|
||||
#define LONGMAX 0x7FFFFFFFL
|
||||
#endif
|
||||
#ifndef ULONGMAX
|
||||
#define ULONGMAX 0xFFFFFFFFUL
|
||||
#endif
|
||||
|
||||
/*
|
||||
* SJIS_IS_ESCAPE_FREE means the compiler does not escape '0x5c' ('\\') in
|
||||
* shift-JIS encoded multi-byte character. SJIS_IS_ESCAPE_FREE == FALSE
|
||||
* enables cpp to insert * '\\' before '\\' of the 2nd byte of SJIS code in
|
||||
* literal. This insertion is for the compiler-proper which can't recognize
|
||||
* SJIS literal.
|
||||
* BIGFIVE_IS_ESCAPE_FREE means similar case on BIGFIVE encoding.
|
||||
* ISO2022_JP_IS_ESCAPE_FREE means similar case on ISO2022_JP encoding.
|
||||
*/
|
||||
/*
|
||||
* P A R T 2 Configurations for host-compiler.
|
||||
*
|
||||
* WARNING: In case of HOST_COMPILER differs from COMPILER, you must
|
||||
* edit here and there of this part.
|
||||
*/
|
||||
|
||||
#define HOST_HAVE_LONG_LONG TRUE
|
||||
#define HAVE_INTMAX_T FALSE
|
||||
|
||||
/*
|
||||
* This definitions should be set TRUE, if *both* of the target
|
||||
* and the host compilers have long long type.
|
||||
*/
|
||||
#if TARGET_HAVE_LONG_LONG && HOST_HAVE_LONG_LONG
|
||||
#define HAVE_LONG_LONG TRUE
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Define the format specifier of intmax_t or long long for
|
||||
* fprintf( fp_debug,).
|
||||
* Both of target COMPILER and HOST_COMPILER should have long long.
|
||||
*/
|
||||
#if HAVE_LONG_LONG
|
||||
#ifndef LL_FORM
|
||||
#define LL_FORM "ll" /* C99: for long long, "j" for intmax_t */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HOST_HAVE_STPCPY
|
||||
#define HOST_HAVE_STPCPY FALSE
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Declaration of standard library functions and macros.
|
||||
*/
|
||||
|
||||
/* stdin, stdout, stderr, FILE, NULL, fgets(), fputs() and other functions. */
|
||||
#include "stdio.h"
|
||||
|
||||
/* PATHMAX is the maximum length of path-list on the host system. */
|
||||
/* _POSIX_* only to get PATH_MAX */
|
||||
#define _POSIX_ 1
|
||||
#define _POSIX_SOURCE 1
|
||||
#ifndef _POSIX_C_SOURCE
|
||||
#define _POSIX_C_SOURCE 1
|
||||
#define _POSIX_C_SOURCE_defined 1
|
||||
#endif
|
||||
#include "limits.h"
|
||||
#undef _POSIX_
|
||||
#undef _POSIX_SOURCE
|
||||
#ifdef _POSIX_C_SOURCE_defined
|
||||
#undef _POSIX_C_SOURCE
|
||||
#undef _POSIX_C_SOURCE_defined
|
||||
#endif
|
||||
#define PATHMAX PATH_MAX /* Posix macro */
|
||||
|
||||
/* islower(), isupper(), toupper(), isdigit(), isxdigit(), iscntrl() */
|
||||
#include "ctype.h"
|
||||
|
||||
/* errno */
|
||||
#include "errno.h"
|
||||
|
||||
#include "string.h"
|
||||
#include "stdlib.h"
|
||||
#include "time.h"
|
||||
#include "setjmp.h"
|
||||
@@ -0,0 +1,117 @@
|
||||
#ifndef _OPCODES_H_
|
||||
#define _OPCODES_H_
|
||||
|
||||
//
|
||||
// Definitions of all the core-level opcodes for the interpreter.
|
||||
// These should not be modified or changed in any way.
|
||||
//
|
||||
|
||||
// number of longwords for each procedure table entry
|
||||
#define PROCTABLE_SIZE 6
|
||||
#define OPCODE_SIZE 2
|
||||
|
||||
#define O_OPERATOR 0x8000
|
||||
#define O_INT 0x4000 // types of constants
|
||||
#define O_FLOAT 0x2000
|
||||
#define O_STRING 0x1000 // strings
|
||||
//#define O_DYNSTRING 0x0800 // dynamic strings
|
||||
//#define O_TYPEMASK 0xfc00
|
||||
//#define OP(x) (O_OPERATOR|(x))
|
||||
#define O_INTOP (O_CONST|O_INT)
|
||||
#define O_STRINGOP (O_CONST|O_STRING)
|
||||
#define O_FLOATOP (O_CONST|O_FLOAT)
|
||||
//#define O_DYNSTRINGOP (O_STRINGOP|O_DYNSTRING)
|
||||
|
||||
// Remember that if any opcodes are added 'in the middle' of this list,
|
||||
// all scripts must be recompiled.
|
||||
|
||||
enum {
|
||||
O_NOOP = O_OPERATOR,
|
||||
O_CONST,
|
||||
O_CRITICAL_START,
|
||||
O_CRITICAL_DONE,
|
||||
O_JMP,
|
||||
O_CALL,
|
||||
O_CALL_AT, // timed function calls
|
||||
O_CALL_CONDITION,
|
||||
O_CALLSTART,
|
||||
O_EXEC,
|
||||
O_SPAWN,
|
||||
O_FORK,
|
||||
O_A_TO_D,
|
||||
O_D_TO_A,
|
||||
O_EXIT, // exit prog and purge it from process queue
|
||||
O_DETACH, // detach spawned process from its parent.
|
||||
O_EXIT_PROG, // exit program but leave it in process queue
|
||||
O_STOP_PROG,
|
||||
O_FETCH_GLOBAL,
|
||||
O_STORE_GLOBAL,
|
||||
O_FETCH_EXTERNAL,
|
||||
O_STORE_EXTERNAL,
|
||||
O_EXPORT_VAR,
|
||||
O_EXPORT_PROC,
|
||||
O_SWAP,
|
||||
O_SWAPA,
|
||||
O_POP,
|
||||
O_DUP,
|
||||
O_POP_RETURN,
|
||||
O_POP_EXIT,
|
||||
O_POP_ADDRESS,
|
||||
O_POP_FLAGS,
|
||||
O_POP_FLAGS_RETURN,
|
||||
O_POP_FLAGS_EXIT,
|
||||
O_POP_FLAGS_RETURN_EXTERN,
|
||||
O_POP_FLAGS_EXIT_EXTERN,
|
||||
O_POP_FLAGS_RETURN_VAL_EXTERN,
|
||||
|
||||
// return from a procedure called from C, leaving the return value
|
||||
// on the stack.
|
||||
O_POP_FLAGS_RETURN_VAL_EXIT,
|
||||
O_POP_FLAGS_RETURN_VAL_EXIT_EXTERN,
|
||||
|
||||
O_CHECK_ARG_COUNT, // call to do a run-time check of arguments to functions
|
||||
O_LOOKUP_STRING_PROC, // call to lookup a procedure index given a string
|
||||
O_POP_BASE,
|
||||
O_POP_TO_BASE,
|
||||
O_PUSH_BASE,
|
||||
O_SET_GLOBAL,
|
||||
O_FETCH_PROC_ADDRESS,
|
||||
O_DUMP,
|
||||
O_IF,
|
||||
O_WHILE,
|
||||
O_STORE,
|
||||
O_FETCH,
|
||||
O_EQUAL,
|
||||
O_NOT_EQUAL,
|
||||
O_LESS_EQUAL,
|
||||
O_GREATER_EQUAL,
|
||||
O_LESS,
|
||||
O_GREATER,
|
||||
O_ADD,
|
||||
O_SUB,
|
||||
O_MUL,
|
||||
O_DIV,
|
||||
O_MOD,
|
||||
O_AND,
|
||||
O_OR,
|
||||
O_BWAND,
|
||||
O_BWOR,
|
||||
O_BWXOR,
|
||||
O_BWNOT,
|
||||
O_FLOOR,
|
||||
O_NOT,
|
||||
O_NEGATE,
|
||||
O_WAIT,
|
||||
O_CANCEL,
|
||||
O_CANCELALL,
|
||||
|
||||
O_STARTCRITICAL,
|
||||
O_ENDCRITICAL,
|
||||
|
||||
O_END_CORE // don't use this anywhere, or you'll die
|
||||
};
|
||||
|
||||
// if these ever get above 255, the size of opTable in inttable.i needs to
|
||||
// be increased. if it gets bigger than 0x7ff, bad things will happen.
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,107 @@
|
||||
#ifndef _OPLIB_H_
|
||||
#define _OPLIB_H_
|
||||
|
||||
#include "opcodes.h"
|
||||
|
||||
//
|
||||
// Definitions of the default library set of opcodes for the interpreter.
|
||||
// These should not be changed.
|
||||
|
||||
enum {
|
||||
O_SAYQUIT = O_END_CORE,
|
||||
O_SAYEND,
|
||||
O_SAYSTART,
|
||||
O_SAYSTARTPOS,
|
||||
O_SAYREPLYTITLE,
|
||||
O_SAYGOTOREPLY,
|
||||
O_SAYREPLY,
|
||||
O_SAYOPTION,
|
||||
O_SAYMESSAGE,
|
||||
O_SAYREPLYWINDOW, // sayreplywindow(sx, sy, w, h, "fill3x3 pattern");
|
||||
O_SAYOPTIONWINDOW, // sayoptionwindow ''
|
||||
O_SAYBORDER, // sayoptionborder(x, y)
|
||||
O_SAYSCROLLUP,
|
||||
O_SAYSCROLLDOWN,
|
||||
O_SAYSETSPACING,
|
||||
O_SAYOPTIONCOLOR,
|
||||
O_SAYREPLYCOLOR,
|
||||
O_SAYRESTART,
|
||||
O_SAYGETLASTPOS,
|
||||
O_SAYREPLYFLAGS,
|
||||
O_SAYOPTIONFLAGS,
|
||||
O_SAYMESSAGETIMEOUT, // removes sayMsg in x time, unless x = 0
|
||||
|
||||
O_CREATEWIN,
|
||||
O_DELETEWIN,
|
||||
O_SELECTWIN,
|
||||
O_RESIZEWIN,
|
||||
O_SCALEWIN,
|
||||
O_SHOWWIN,
|
||||
O_FILLWIN,
|
||||
O_FILLRECT,
|
||||
O_FILLWIN3X3,
|
||||
O_DISPLAY,
|
||||
O_DISPLAYGFX,
|
||||
O_DISPLAYRAW,
|
||||
O_LOADPALETTETABLE,
|
||||
O_FADEIN,
|
||||
O_FADEOUT,
|
||||
O_GOTOXY,
|
||||
O_PRINT,
|
||||
O_FORMAT,
|
||||
O_PRINTRECT,
|
||||
O_SETFONT,
|
||||
O_SETTEXTFLAGS,
|
||||
O_SETTEXTCOLOR,
|
||||
O_SETHIGHLIGHTCOLOR,
|
||||
O_STOPMOVIE,
|
||||
O_PLAYMOVIE,
|
||||
O_MOVIEFLAGS,
|
||||
O_PLAYMOVIERECT,
|
||||
O_PLAYMOVIEALPHA,
|
||||
O_PLAYMOVIEALPHARECT,
|
||||
O_ADDREGION,
|
||||
O_ADDREGIONFLAG,
|
||||
O_ADDREGIONPROC,
|
||||
O_ADDREGIONRIGHTPROC,
|
||||
O_DELETEREGION,
|
||||
O_ACTIVATEREGION,
|
||||
O_CHECKREGION, // returns if a region exists or not
|
||||
|
||||
O_ADDBUTTON,
|
||||
O_ADDBUTTONTEXT,
|
||||
O_ADDBUTTONFLAG,
|
||||
O_ADDBUTTONGFX,
|
||||
O_ADDBUTTONPROC,
|
||||
O_ADDBUTTONRIGHTPROC,
|
||||
O_DELETEBUTTON,
|
||||
|
||||
O_HIDEMOUSE,
|
||||
O_SHOWMOUSE,
|
||||
O_MOUSESHAPE,
|
||||
O_REFRESHMOUSE,
|
||||
O_SETGLOBALMOUSEFUNC,
|
||||
|
||||
O_ADDNAMEDEVENT,
|
||||
O_ADDNAMEDHANDLER,
|
||||
O_CLEARNAMED,
|
||||
O_SIGNALNAMED,
|
||||
|
||||
O_ADDKEY,
|
||||
O_DELETEKEY,
|
||||
|
||||
O_SOUNDPLAY,
|
||||
O_SOUNDPAUSE,
|
||||
O_SOUNDRESUME,
|
||||
O_SOUNDSTOP,
|
||||
O_SOUNDREWIND,
|
||||
O_SOUNDDELETE,
|
||||
O_SETONEOPTPAUSE,
|
||||
|
||||
O_SELECTFILELIST,
|
||||
|
||||
O_TOKENIZE,
|
||||
O_END_LIB // don't use this anywhere or your head will explode
|
||||
};
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user