Platform-shared global variables implemented

git-svn-id: http://picoc.googlecode.com/svn/trunk@130 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
zik.saleeba 2009-02-28 20:46:02 +00:00
parent 085bb1fc9d
commit d98c55d5e5
4 changed files with 19 additions and 1 deletions

View file

@ -7,10 +7,10 @@ void Initialise()
TableInit();
VariableInit();
LexInit();
VariableInit();
TypeInit();
LibraryInit(&GlobalTable, "c library", &CLibrary);
LibraryInit(&GlobalTable, "platform library", &PlatformLibrary);
PlatformLibraryInit();
}
/* platform-dependent code for running programs is in this file */

View file

@ -284,6 +284,7 @@ struct Value *VariableAllocValueShared(struct ParseState *Parser, struct Value *
void VariableDefine(struct ParseState *Parser, char *Ident, struct Value *InitValue);
int VariableDefined(const char *Ident);
void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LVal);
void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable);
void VariableStackFrameAdd(struct ParseState *Parser, int NumParams);
void VariableStackFramePop(struct ParseState *Parser);
@ -303,5 +304,6 @@ void PlatformPrintf(const char *Format, ...);
void PlatformVPrintf(const char *Format, va_list Args);
int PlatformSetExitPoint();
void PlatformExit();
void PlatformLibraryInit();
#endif /* PICOC_H */

View file

@ -17,6 +17,12 @@ void Random(struct Value *ReturnValue, struct Value **Param, int NumArgs)
}
#endif
static int SomeVar = 42;
void PlatformLibraryInit()
{
VariableDefinePlatformVar(NULL, "somevar", &IntType, (union AnyValue *)&SomeVar, TRUE);
}
/* list of all library functions and their prototypes */
struct LibraryFunction PlatformLibrary[] =
{

View file

@ -126,6 +126,16 @@ void VariableGet(struct ParseState *Parser, const char *Ident, struct Value **LV
}
}
/* define a global variable shared with a platform global */
void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct ValueType *Typ, union AnyValue *FromValue, int IsWritable)
{
struct Value *SomeValue = VariableAllocValueAndData(NULL, 0, IsWritable, NULL, TRUE);
SomeValue->Typ = Typ;
SomeValue->Val = FromValue;
VariableDefine(Parser, TableStrRegister(Ident), SomeValue);
}
/* free and/or pop the top value off the stack. Var must be the top value on the stack! */
void VariableStackPop(struct ParseState *Parser, struct Value *Var)
{