mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-06-18 15:50:11 -06:00
An initial import of the teyjus source code in the C runtime for GF. The two runtime are still not connected but the source code compiles.
This commit is contained in:
170
src/runtime/c/teyjus/system/error.h
Normal file
170
src/runtime/c/teyjus/system/error.h
Normal file
@@ -0,0 +1,170 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Copyright 2008
|
||||
// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Teyjus. //
|
||||
// //
|
||||
// Teyjus is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Teyjus is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/****************************************************************************
|
||||
* *
|
||||
* File error.h -- error-handling functions *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef ERROR_H
|
||||
#define ERROR_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <setjmp.h>
|
||||
#include "tjsignal.h"
|
||||
#include "../simulator/mctypes.h" //to be modified
|
||||
|
||||
/****************************************************************************
|
||||
* Exception stack declarations. *
|
||||
****************************************************************************/
|
||||
|
||||
typedef enum EM_ExnType{
|
||||
EM_NO_ERR = 0, // no errors
|
||||
EM_NO_EXN, // used for warnings ??
|
||||
EM_ABORT, // exit the executable immediately
|
||||
EM_EXIT, // traverse the exception stack and exit
|
||||
EM_TOP_LEVEL, // return to the toplevel
|
||||
EM_QUERY, // abort solving the query
|
||||
EM_QUERY_RESULT, // query is solved; print answer
|
||||
EM_FAIL, // fail to simulator level
|
||||
} EM_ExnType;
|
||||
|
||||
//function call environment stack
|
||||
extern SIGNAL_jmp_buf *EM_ExnHandlerStack;
|
||||
extern int EM_ExnHandlerStackTop;
|
||||
extern int EM_ExnHandlerStackSize;
|
||||
|
||||
//exception type
|
||||
extern EM_ExnType EM_CurrentExnType;
|
||||
|
||||
/****************************************************************************
|
||||
* Exception-handling macros *
|
||||
****************************************************************************/
|
||||
|
||||
//try
|
||||
#define EM_TRY \
|
||||
if (EM_ExnHandlerStackTop >= EM_ExnHandlerStackSize) \
|
||||
{ \
|
||||
EM_ExnHandlerStackSize = \
|
||||
(EM_ExnHandlerStackSize + 1) * 2; \
|
||||
EM_ExnHandlerStack = \
|
||||
(SIGNAL_jmp_buf *)EM_realloc((void *)EM_ExnHandlerStack, \
|
||||
EM_ExnHandlerStackSize * sizeof(SIGNAL_jmp_buf)); \
|
||||
} \
|
||||
if (SIGNAL_setjmp(EM_ExnHandlerStack[EM_ExnHandlerStackTop++]) == 0) \
|
||||
{
|
||||
|
||||
//catch
|
||||
#define EM_CATCH \
|
||||
EM_ExnHandlerStackTop--; \
|
||||
} \
|
||||
else
|
||||
|
||||
//throw
|
||||
/* Jump to the nearest (in a dynamic sense) EM_Try block, setting
|
||||
EM_CurrentExnType to TYPE. Given a constant, the conditional in
|
||||
this macro will be optimized away.
|
||||
|
||||
TODO: added cast to EM_CurrentExnType. */
|
||||
#define EM_THROW(type) EM_THROWVAL((type), 1)
|
||||
|
||||
#define EM_THROWVAL(type, val) \
|
||||
do { \
|
||||
if ((type) == EM_ABORT) \
|
||||
exit(1); \
|
||||
else \
|
||||
{ \
|
||||
EM_CurrentExnType = (EM_ExnType)(type); \
|
||||
SIGNAL_longjmp(EM_ExnHandlerStack[--EM_ExnHandlerStackTop], val); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
//rethrow
|
||||
/* pass the current exception to the next handler. Use only within an
|
||||
EM_Catch block. */
|
||||
#define EM_RETHROW() \
|
||||
SIGNAL_longjmp(EM_ExnHandlerStack[--EM_ExnHandlerStackTop], 1)
|
||||
|
||||
/* Here's an example use of the above macros:
|
||||
|
||||
...
|
||||
EM_TRY
|
||||
{
|
||||
foo();
|
||||
if (foobar)
|
||||
EM_THROW(EM_FOOBAR);
|
||||
}
|
||||
EM_CATCH
|
||||
{
|
||||
un_foo(); /* clean up *
|
||||
if (EM_CurrentExnType == EM_FOOBAR)
|
||||
printf("foobar!"); /* stop the error here *
|
||||
else
|
||||
EM_RETHROW(); /* let a later handler handle it *
|
||||
}
|
||||
*/
|
||||
|
||||
/****************************************************************************
|
||||
* Routines which will generate errors automatically. *
|
||||
****************************************************************************/
|
||||
void *EM_malloc(unsigned int);
|
||||
void *EM_realloc(void *, unsigned int);
|
||||
char *EM_strdup(char *);
|
||||
|
||||
/****************************************************************************
|
||||
* Beginning error indices for different modules (by module abbreviation) *
|
||||
****************************************************************************/
|
||||
/* general errors */
|
||||
#define EM_NO_ERROR 0
|
||||
#define EM_FIRST_ERR_INDEX 1
|
||||
#define LINKER_FIRST_ERR_INDEX 50
|
||||
#define LOADER_FIRST_ERR_INDEX 100
|
||||
#define STREAM_FIRST_ERR_INDEX 150
|
||||
#define SIM_FIRST_ERR_INDEX 200
|
||||
#define BI_FIRST_ERR_INDEX 300
|
||||
#define RT_FIRST_ERR_INDEX 400
|
||||
#define FRONT_FIRST_ERR_INDEX 500
|
||||
|
||||
/****************************************************************************
|
||||
* General-use error messages *
|
||||
****************************************************************************/
|
||||
enum
|
||||
{
|
||||
EM_OUT_OF_MEMORY = EM_FIRST_ERR_INDEX,
|
||||
EM_OUT_OF_HEAP,
|
||||
EM_NEWLINE,
|
||||
EM_ERROR_COLON,
|
||||
EM_WARNING_COLON
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* The routine that gets called in the event of an error *
|
||||
****************************************************************************/
|
||||
void EM_error(int inIndex, ...);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Have there been any errors since last EM_Reset()? *
|
||||
****************************************************************************/
|
||||
extern Boolean EM_anyErrors;
|
||||
void EM_reset();
|
||||
|
||||
#endif //ERROR_H
|
||||
222
src/runtime/c/teyjus/system/memory.h
Normal file
222
src/runtime/c/teyjus/system/memory.h
Normal file
@@ -0,0 +1,222 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Copyright 2008
|
||||
// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Teyjus. //
|
||||
// //
|
||||
// Teyjus is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Teyjus is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/****************************************************************************/
|
||||
/* */
|
||||
/* Files memory.h{c}. These files define the system memory structures and */
|
||||
/* their access functions, including the system memory, run-time symbol */
|
||||
/* tables, implication and import tables and the system module table. */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
#ifndef MEMORY_H
|
||||
#define MEMORY_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include "../simulator/mctypes.h" //to be changed
|
||||
#include "../simulator/dataformats.h" //to be changed
|
||||
//#include "../config.h"
|
||||
|
||||
/******************************************************************************/
|
||||
/* FIND CODE FUNCTION */
|
||||
/******************************************************************************/
|
||||
//arguments: constInd, search table size, search table addr
|
||||
typedef CSpacePtr (*MEM_FindCodeFnPtr)(int, int, MemPtr);
|
||||
|
||||
/******************************************************************************/
|
||||
/* SYSTEM MEMORY MANAGEMENT */
|
||||
/******************************************************************************/
|
||||
extern WordPtr MEM_memBeg; //starting addr of the system memory
|
||||
extern WordPtr MEM_memEnd; //end addr of the system memory
|
||||
extern WordPtr MEM_memTop; //the first usable word in the system memory
|
||||
extern WordPtr MEM_memBot; //the last usable word in the system memory
|
||||
|
||||
/* Asking for the system memory of a given size (in word), */
|
||||
/* and initialize relevant global variables. */
|
||||
void MEM_memInit(unsigned int size);
|
||||
/* Asking the simulator (system) memory for space of a given size (in word) */
|
||||
WordPtr MEM_memExtend(unsigned int size);
|
||||
|
||||
/******************************************************************************/
|
||||
/* MODULE SPACE COMPONENTS */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* I. Run time symbol tables: kind table; type skeleton table; constant table*/
|
||||
/* II. Implication table */
|
||||
/* III.Import table */
|
||||
/******************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* KIND SYMBOL TABLE */
|
||||
/*****************************************************************************/
|
||||
/* kind symbol table entry */
|
||||
typedef struct
|
||||
{
|
||||
DF_StrDataPtr name;
|
||||
TwoBytes arity; //agree with DF_StrTypeArity (simulator/dataformats.c)
|
||||
} MEM_KstEnt;
|
||||
|
||||
typedef MEM_KstEnt *MEM_KstPtr;
|
||||
|
||||
/* max possible index of kind table */
|
||||
/* (agree with DF_KstTabInd in simulator/dataformats.c) */
|
||||
#define MEM_KST_MAX_IND USHRT_MAX
|
||||
|
||||
/* size of each entry of this table (in word) */
|
||||
//Note this arithematic should in reality go into "config.h"
|
||||
#define MEM_KST_ENTRY_SIZE (int)ceil((double)sizeof(MEM_KstEnt)/WORD_SIZE)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* TYPE SKELETON TABLE */
|
||||
/*****************************************************************************/
|
||||
/* type skeleton table entry */
|
||||
typedef DF_TypePtr MEM_TstEnt;
|
||||
|
||||
typedef MEM_TstEnt *MEM_TstPtr;
|
||||
|
||||
/* max possible index of type skeleton table */
|
||||
#define MEM_TST_MAX_IND USHRT_MAX
|
||||
|
||||
/* size of each entry of this table (in word) */
|
||||
//Note this arithematic should in reality go into "config.h"
|
||||
#define MEM_TST_ENTRY_SIZE (int)ceil((double)sizeof(MEM_TstEnt)/WORD_SIZE)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* CONSTANT SYMBOL TABLE */
|
||||
/*****************************************************************************/
|
||||
/* constant symbol table entry */
|
||||
typedef struct
|
||||
{
|
||||
DF_StrDataPtr name;
|
||||
TwoBytes typeEnvSize;
|
||||
TwoBytes tskTabIndex; //index to the type skeleton table
|
||||
TwoBytes neededness; //neededness info
|
||||
TwoBytes univCount;
|
||||
int precedence;
|
||||
int fixity;
|
||||
} MEM_CstEnt;
|
||||
|
||||
typedef MEM_CstEnt *MEM_CstPtr;
|
||||
|
||||
/* max possible index of constant symbol table */
|
||||
/* (agree with DF_CstTabInd in simulator/dataformats.c) */
|
||||
#define MEM_CST_MAX_IND USHRT_MAX
|
||||
//add one entry at the current top
|
||||
/* size of each entry of this table (in word) */
|
||||
//Note this arithematic should in reality go into "config.h"
|
||||
#define MEM_CST_ENTRY_SIZE (int)(sizeof(MEM_CstEnt)/WORD_SIZE)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ACCESSING THE IMPLICATION GOAL TABLE */
|
||||
/*****************************************************************************/
|
||||
#define MEM_IMPL_FIX_SIZE 3
|
||||
/* functions for filling in the fields of an impl table */
|
||||
/* Q: the data stored in each field in byte code: are they word or in their */
|
||||
/* specific types? */
|
||||
void MEM_implPutLTS(WordPtr tab, int lts); //# pred (def extended)
|
||||
void MEM_implPutFC(WordPtr tab, MEM_FindCodeFnPtr fcPtr);//ptr to find code func
|
||||
void MEM_implPutPSTS(WordPtr tab, int tabSize); //# entries link tab
|
||||
void MEM_implPutLT(WordPtr tab, int ind, int cst); //link tab; ind from 0
|
||||
|
||||
/* functions for retrieving the addresses of associated tables */
|
||||
MemPtr MEM_implLT(MemPtr tab); //start add of seq. of pred (link tab)
|
||||
MemPtr MEM_implPST(MemPtr tab, int lts); //start add of pred search tab
|
||||
|
||||
/* functions for retrieving the fields of a impl table */
|
||||
int MEM_implLTS(MemPtr tab); //pred field (def extended)
|
||||
MEM_FindCodeFnPtr MEM_implFC(MemPtr tab); //ptr to find code func
|
||||
int MEM_implPSTS(MemPtr tab); //num entries in link tab
|
||||
int MEM_implIthLT(MemPtr ltab, int index); /* value in ith entry of link tab
|
||||
ltab is the addr of link tab;
|
||||
index should start from 0 */
|
||||
|
||||
/*****************************************************************************
|
||||
* ACCESSING THE IMPORTED MODULE TABLE *
|
||||
*****************************************************************************/
|
||||
#define MEM_IMP_FIX_SIZE 5
|
||||
/* functions for filling in the fields of an import table */
|
||||
/* Q: the data stored in each field in byte code: are they word or in their */
|
||||
/* specific types? */
|
||||
void MEM_impPutNCSEG(WordPtr tab, int nseg); //# code segments
|
||||
void MEM_impPutNLC(WordPtr tab, int nlc); //# local constants
|
||||
void MEM_impPutLTS(WordPtr tab, int lts); //# pred (def extended)
|
||||
void MEM_impPutFC(WordPtr tab, MEM_FindCodeFnPtr fcp); //ptr to find code func
|
||||
void MEM_impPutPSTS(WordPtr tab, int tabSize); //# entries in link tab
|
||||
void MEM_impPutLT(WordPtr tab, int ind, int cst); //link tab; ind from 0
|
||||
void MEM_impPutLCT(WordPtr lcTab, int ind, int cst); /*loc c tab(may null)
|
||||
lcTab addr of local
|
||||
ctab; ind from 0 */
|
||||
|
||||
/* functions for retrieving the addresses of associated tables */
|
||||
MemPtr MEM_impLT(MemPtr tab); //start addr of seq. of pred (link tab)
|
||||
MemPtr MEM_impLCT(MemPtr tab, int lts); //start addr of local const table
|
||||
MemPtr MEM_impPST(MemPtr tab, int lts, int nlc); //start addr of pred search tab
|
||||
|
||||
/* functions for retrieving the fields of a impl table */
|
||||
int MEM_impNCSEG(MemPtr tab); //# code segments
|
||||
int MEM_impNLC(MemPtr tab); //# local constants
|
||||
int MEM_impLTS(MemPtr tab); //# of preds (def extended)
|
||||
MEM_FindCodeFnPtr MEM_impFC(MemPtr tab); //ptr to find code func
|
||||
int MEM_impPSTS(MemPtr tab); //# entries in link tab
|
||||
int MEM_impIthLT(MemPtr lt, int ind); /* ith entry in the link table: lt addr
|
||||
of link tab; ind start from 0 */
|
||||
int MEM_impIthLCT(MemPtr lct, int ind); /* ith entry in the local const table:
|
||||
lct local c tab; ind start from 0 */
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* ACCESSING THE BOUND VARIABLE INDEXING TABLE (BRACHING TABLE) */
|
||||
/*****************************************************************************/
|
||||
int MEM_branchTabIndexVal(MemPtr tab, int index); //the nth index value
|
||||
CSpacePtr MEM_branchTabCodePtr(MemPtr tab, int index); //transfer addr
|
||||
|
||||
/*****************************************************************************/
|
||||
/* SYSTEM MODULE TABLE */
|
||||
/*****************************************************************************/
|
||||
typedef struct
|
||||
{
|
||||
char *modname; //(top-level) module name
|
||||
CSpacePtr addtable; //addr to the add code table of the top module
|
||||
MEM_KstPtr kstBase; //starting addr of kind table
|
||||
MEM_TstPtr tstBase; //starting addr of type skel table
|
||||
MEM_CstPtr cstBase; //starting addr of constant table
|
||||
WordPtr modSpaceBeg; //starting addr of module space
|
||||
WordPtr modSpaceEnd; //ending addr of module space
|
||||
WordPtr codeSpaceBeg; //starting addr of module space
|
||||
WordPtr codeSpaceEnd; //ending addr of module space
|
||||
} MEM_GmtEnt;
|
||||
|
||||
#define MEM_MAX_MODULES 255 //max number of modules (temp)
|
||||
|
||||
typedef MEM_GmtEnt MEM_Gmt[MEM_MAX_MODULES];
|
||||
|
||||
extern MEM_Gmt MEM_modTable; //global module table
|
||||
|
||||
MEM_GmtEnt *MEM_findInModTable(char* name);
|
||||
MEM_GmtEnt *MEM_findFreeModTableEntry();
|
||||
void MEM_removeModTableEntry(char* name);
|
||||
|
||||
|
||||
extern MEM_GmtEnt MEM_topModule; //top module
|
||||
void MEM_topModuleInit();
|
||||
|
||||
extern MEM_GmtEnt *MEM_currentModule; //current module being used
|
||||
|
||||
|
||||
#endif //MEMORY_H
|
||||
76
src/runtime/c/teyjus/system/message.h
Normal file
76
src/runtime/c/teyjus/system/message.h
Normal file
@@ -0,0 +1,76 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Copyright 2008
|
||||
// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Teyjus. //
|
||||
// //
|
||||
// Teyjus is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Teyjus is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/****************************************************************************
|
||||
* *
|
||||
* File message.h -- code to present messages to the user in Teyjus. *
|
||||
* supports dynamically adding "%x"-style formatting switches, as well as *
|
||||
* complete support for simply making separate builds. *
|
||||
* *
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include "../simulator/mctypes.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Type of a function to handle a particular formatting switch. *
|
||||
****************************************************************************/
|
||||
/* these functions should increment ioArgument as necessary. */
|
||||
typedef void (*MSG_SwitchFunction)(char *inSwitch, WordPtr inStream,
|
||||
va_list *ioArgument);
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Type of a block of messages, with associated constants. *
|
||||
****************************************************************************/
|
||||
typedef struct MSG_Msg
|
||||
{
|
||||
int mIndex; /* Index of this error message */
|
||||
int mPreChain; /* Index of message to print before this one */
|
||||
char *mMessage; /* The message itself */
|
||||
int mPostChain; /* Index of message to print after this one */
|
||||
|
||||
int mExnType; /* if MSG_NO_EXN, MSG_Error() will return */
|
||||
unsigned int mExitStatus; /* value to return with abort() */
|
||||
} MSG_Msg;
|
||||
|
||||
typedef struct MSG_MessageBlock
|
||||
{
|
||||
int mCount; /* No. of messages in this block */
|
||||
int mMinIndex, mMaxIndex; /* mMinIndex <= every index <= mMaxIndex */
|
||||
struct MSG_MessageBlock *mNext; /* Next block of messages in linked list */
|
||||
MSG_Msg *mMessages; /* Array of messages */
|
||||
} MSG_MessageBlock;
|
||||
|
||||
/****************************************************************************
|
||||
* Initialization functions *
|
||||
****************************************************************************/
|
||||
void MSG_addSwitch(char inSwitch, MSG_SwitchFunction inFunction);
|
||||
void MSG_addMessages(int inCount, MSG_Msg *inMessages);
|
||||
|
||||
/****************************************************************************
|
||||
* The routine that gets called to print a message, returning the exception *
|
||||
* type for the error message (mExnType) *
|
||||
****************************************************************************/
|
||||
int MSG_vMessage(int inIndex, va_list *ap);
|
||||
|
||||
#endif /* MESSAGE_H */
|
||||
91
src/runtime/c/teyjus/system/operators.h
Normal file
91
src/runtime/c/teyjus/system/operators.h
Normal file
@@ -0,0 +1,91 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Copyright 2008
|
||||
// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Teyjus. //
|
||||
// //
|
||||
// Teyjus is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Teyjus is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef OPERATORS_H
|
||||
#define OPERATORS_H
|
||||
|
||||
//#include <limits.h>
|
||||
|
||||
/* Fixity types */
|
||||
typedef enum
|
||||
{
|
||||
OP_INFIX = 0,
|
||||
OP_INFIXL = 1,
|
||||
OP_INFIXR = 2,
|
||||
OP_NONE = 3,
|
||||
OP_PREFIX = 4,
|
||||
OP_PREFIXR = 5,
|
||||
OP_POSTFIX = 6,
|
||||
OP_POSTFIXL = 7
|
||||
} OP_FixityType;
|
||||
|
||||
|
||||
typedef enum {
|
||||
OP_WHOLE_TERM,
|
||||
OP_LEFT_TERM,
|
||||
OP_RIGHT_TERM
|
||||
} OP_TermContext;
|
||||
|
||||
#define OP_MAXPREC 255
|
||||
#define OP_MINPREC 0
|
||||
|
||||
#define OP_LAM_FIXITY OP_PREFIXR
|
||||
#define OP_LAM_PREC -1
|
||||
|
||||
#define OP_APP_FIXITY OP_INFIXL
|
||||
#define OP_APP_PREC 257
|
||||
|
||||
//usful ?
|
||||
/*
|
||||
#define OP_CCOMMA_FIXITY OP_infixr
|
||||
#define OP_CCOMMA_PREC -2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define OP_LT_FIXITY OP_infix
|
||||
#define OP_LT_PREC 130
|
||||
|
||||
#define OP_LE_FIXITY OP_infix
|
||||
#define OP_LE_PREC 130
|
||||
|
||||
#define OP_GT_FIXITY OP_infix
|
||||
#define OP_GT_PREC 130
|
||||
|
||||
#define OP_GE_FIXITY OP_infix
|
||||
#define OP_GE_PREC 130
|
||||
|
||||
#define OP_UM_FIXITY OP_prefix
|
||||
#define OP_UM_PREC 256 //?
|
||||
|
||||
#define OP_PLUS_FIXITY OP_infixl
|
||||
#define OP_PLUS_PREC 150
|
||||
|
||||
#define OP_MINUS_FIXITY OP_infixl
|
||||
#define OP_MINUS_PREC 150
|
||||
|
||||
#define OP_TIMES_FIXITY OP_infixl
|
||||
#define OP_TIMES_PREC 160
|
||||
|
||||
#define OP_COMMA_FIXITY OP_infixl
|
||||
#define OP_COMMA_PREC 110
|
||||
*/
|
||||
|
||||
#endif // OPERATORS_H
|
||||
90
src/runtime/c/teyjus/system/stream.h
Normal file
90
src/runtime/c/teyjus/system/stream.h
Normal file
@@ -0,0 +1,90 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Copyright 2008
|
||||
// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Teyjus. //
|
||||
// //
|
||||
// Teyjus is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Teyjus is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/****************************************************************************
|
||||
* *
|
||||
* system/stream.h{c} implements stream support for the C part of the LP *
|
||||
* system. *
|
||||
****************************************************************************/
|
||||
#ifndef STREAM_H
|
||||
#define STREAM_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include "../simulator/mctypes.h" //to be modified
|
||||
|
||||
/*****************************************************************************
|
||||
* CONSTANTS *
|
||||
*****************************************************************************/
|
||||
|
||||
#define STREAM_ILLEGAL 0
|
||||
|
||||
#define STREAM_READ "r"
|
||||
#define STREAM_WRITE "w"
|
||||
#define STREAM_APPEND "a"
|
||||
|
||||
/*****************************************************************************
|
||||
* EXPORTED VARIABLES *
|
||||
*****************************************************************************/
|
||||
/* STREAMs corresponding to the three standard streams */
|
||||
extern WordPtr STREAM_stdin, STREAM_stdout, STREAM_stderr;
|
||||
|
||||
/****************************************************************************
|
||||
* BASIC FUNCTIONS *
|
||||
****************************************************************************/
|
||||
|
||||
/* STREAM_open returns STREAM_ILLEGAL if the stream can't be opened;
|
||||
if inDoCountLines is false, the line numbering calls below will not
|
||||
work. */
|
||||
WordPtr STREAM_open(char *inFilename, char *inMode, int inDoUsePaths);
|
||||
/* open strings as streams. Note that the STREAM system does not
|
||||
distinguish to_string and from_string streams after they are
|
||||
opened. Results are undefined for a write to a from_string or read
|
||||
from a to_string. */
|
||||
WordPtr STREAM_fromString(char *inString, int inDoCopyString);
|
||||
WordPtr STREAM_toString();
|
||||
|
||||
/* will not close the standard streams */
|
||||
void STREAM_close(WordPtr inStream);
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* RAW I/O SUPPORT ROUTINES *
|
||||
* each routine returns -1 to indicate an error *
|
||||
***************************************************************************/
|
||||
int STREAM_readCharacters(WordPtr inStream, int inMaxCount, char* outString,
|
||||
int inDoStopOnNewline);
|
||||
/* STREAM_printf and STREAM_sans_printf return the number of characters
|
||||
written, -1 in case of error. STREAM_printf takes a format
|
||||
STREAM_sans_printf interprets the input as a string to be printed */
|
||||
int STREAM_printf(WordPtr inStream, char *format, ...);
|
||||
int STREAM_sans_printf(WordPtr inStream, char *str);
|
||||
/* STREAM_printf returns the number of characters written, -1 in case of error*/
|
||||
int STREAM_lookahead(WordPtr inStream, char *outChar);
|
||||
Boolean STREAM_eof(WordPtr inStream);
|
||||
int STREAM_flush(WordPtr inStream);
|
||||
|
||||
/***************************************************************************
|
||||
* ACCESSORS *
|
||||
***************************************************************************/
|
||||
char* STREAM_getString(WordPtr inStream);
|
||||
FILE* STREAM_getFile(WordPtr inStream);
|
||||
char* STREAM_getName(WordPtr inStream);
|
||||
|
||||
#endif //STREAM_H
|
||||
41
src/runtime/c/teyjus/system/tjsignal.h
Normal file
41
src/runtime/c/teyjus/system/tjsignal.h
Normal file
@@ -0,0 +1,41 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//Copyright 2008
|
||||
// Andrew Gacek, Steven Holte, Gopalan Nadathur, Xiaochu Qi, Zach Snow
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// This file is part of Teyjus. //
|
||||
// //
|
||||
// Teyjus is free software: you can redistribute it and/or modify //
|
||||
// it under the terms of the GNU General Public License as published by //
|
||||
// the Free Software Foundation, either version 3 of the License, or //
|
||||
// (at your option) any later version. //
|
||||
// //
|
||||
// Teyjus is distributed in the hope that it will be useful, //
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
||||
// GNU General Public License for more details. //
|
||||
// //
|
||||
// You should have received a copy of the GNU General Public License //
|
||||
// along with Teyjus. If not, see <http://www.gnu.org/licenses/>. //
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/****************************************************************************
|
||||
* *
|
||||
* File signal.h -- code to implement signals and signal handlers for *
|
||||
* Teyjus. (TEMP) *
|
||||
* *
|
||||
****************************************************************************/
|
||||
#ifndef SIGNAL_H
|
||||
#define SIGNAL_H
|
||||
|
||||
#include <setjmp.h>
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Different sigsetjmp/siglongjmp depending on support.. *
|
||||
****************************************************************************/
|
||||
|
||||
#define SIGNAL_jmp_buf jmp_buf
|
||||
#define SIGNAL_setjmp(env) setjmp(env)
|
||||
#define SIGNAL_longjmp(env, val) longjmp(env, val)
|
||||
|
||||
|
||||
#endif /* SIGNAL_H */
|
||||
Reference in New Issue
Block a user