initialize
This commit is contained in:
parent
26b21d04be
commit
9c05060820
|
@ -333,7 +333,7 @@ void PlatformLibraryInit()
|
||||||
```
|
```
|
||||||
|
|
||||||
This code takes the structure definition in StructDefinition and runs the lexical
|
This code takes the structure definition in StructDefinition and runs the lexical
|
||||||
analyser over it. This returns some lexical tokens. Then we initialise the parser
|
analyser over it. This returns some lexical tokens. Then we initialize the parser
|
||||||
and have it parse the type of the structure definition from the tokens we made.
|
and have it parse the type of the structure definition from the tokens we made.
|
||||||
That's enough to define the structure in the system. Finally we free the tokens.
|
That's enough to define the structure in the system. Finally we free the tokens.
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct StdVararg
|
||||||
int NumArgs;
|
int NumArgs;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* initialises the I/O system so error reporting works */
|
/* initializes the I/O system so error reporting works */
|
||||||
void BasicIOInit(Picoc *pc)
|
void BasicIOInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
pc->CStdOut = stdout;
|
pc->CStdOut = stdout;
|
||||||
|
|
2
debug.c
2
debug.c
|
@ -4,7 +4,7 @@
|
||||||
#define BREAKPOINT_HASH(p) (((unsigned long)(p)->FileName) ^ (((p)->Line << 16) | ((p)->CharacterPos << 16)))
|
#define BREAKPOINT_HASH(p) (((unsigned long)(p)->FileName) ^ (((p)->Line << 16) | ((p)->CharacterPos << 16)))
|
||||||
|
|
||||||
#ifdef DEBUGGER
|
#ifdef DEBUGGER
|
||||||
/* initialise the debugger by clearing the breakpoint table */
|
/* initialize the debugger by clearing the breakpoint table */
|
||||||
void DebugInit(Picoc *pc)
|
void DebugInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
TableInitTable(&pc->BreakpointTable, &pc->BreakpointHashTable[0],
|
TableInitTable(&pc->BreakpointTable, &pc->BreakpointHashTable[0],
|
||||||
|
|
2
heap.c
2
heap.c
|
@ -18,7 +18,7 @@ void ShowBigList(Picoc *pc)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* initialise the stack and heap storage */
|
/* initialize the stack and heap storage */
|
||||||
void HeapInit(Picoc *pc, int StackOrHeapSize)
|
void HeapInit(Picoc *pc, int StackOrHeapSize)
|
||||||
{
|
{
|
||||||
int Count;
|
int Count;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "interpreter.h"
|
#include "interpreter.h"
|
||||||
|
|
||||||
|
|
||||||
/* initialise the built-in include libraries */
|
/* initialize the built-in include libraries */
|
||||||
void IncludeInit(Picoc *pc)
|
void IncludeInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
IncludeRegister(pc, "ctype.h", NULL, &StdCtypeFunctions[0], NULL);
|
IncludeRegister(pc, "ctype.h", NULL, &StdCtypeFunctions[0], NULL);
|
||||||
|
|
|
@ -633,7 +633,7 @@ extern void LibPrintf(struct ParseState *Parser, struct Value *ReturnValue,
|
||||||
/* the following are defined in picoc.h:
|
/* the following are defined in picoc.h:
|
||||||
* void PicocCallMain(int argc, char **argv);
|
* void PicocCallMain(int argc, char **argv);
|
||||||
* int PicocPlatformSetExitPoint();
|
* int PicocPlatformSetExitPoint();
|
||||||
* void PicocInitialise(int StackSize);
|
* void PicocInitialize(int StackSize);
|
||||||
* void PicocCleanup();
|
* void PicocCleanup();
|
||||||
* void PicocPlatformScanFile(const char *FileName);
|
* void PicocPlatformScanFile(const char *FileName);
|
||||||
* extern int PicocExitValue; */
|
* extern int PicocExitValue; */
|
||||||
|
|
2
lex.c
2
lex.c
|
@ -97,7 +97,7 @@ static struct ReservedWord ReservedWords[] = {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* initialise the lexer */
|
/* initialize the lexer */
|
||||||
void LexInit(Picoc *pc)
|
void LexInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
int Count;
|
int Count;
|
||||||
|
|
22
parse.c
22
parse.c
|
@ -5,7 +5,7 @@
|
||||||
static enum ParseResult ParseStatementMaybeRun(struct ParseState *Parser,
|
static enum ParseResult ParseStatementMaybeRun(struct ParseState *Parser,
|
||||||
int Condition, int CheckTrailingSemicolon);
|
int Condition, int CheckTrailingSemicolon);
|
||||||
static int ParseCountParams(struct ParseState *Parser);
|
static int ParseCountParams(struct ParseState *Parser);
|
||||||
static int ParseArrayInitialiser(struct ParseState *Parser,
|
static int ParseArrayInitializer(struct ParseState *Parser,
|
||||||
struct Value *NewVariable, int DoAssignment);
|
struct Value *NewVariable, int DoAssignment);
|
||||||
static void ParseDeclarationAssignment(struct ParseState *Parser,
|
static void ParseDeclarationAssignment(struct ParseState *Parser,
|
||||||
struct Value *NewVariable, int DoAssignment);
|
struct Value *NewVariable, int DoAssignment);
|
||||||
|
@ -186,8 +186,8 @@ struct Value *ParseFunctionDefinition(struct ParseState *Parser,
|
||||||
return FuncValue;
|
return FuncValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse an array initialiser and assign to a variable */
|
/* parse an array initializer and assign to a variable */
|
||||||
int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
int ParseArrayInitializer(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
int DoAssignment)
|
int DoAssignment)
|
||||||
{
|
{
|
||||||
int ArrayIndex = 0;
|
int ArrayIndex = 0;
|
||||||
|
@ -200,7 +200,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
int NumElements;
|
int NumElements;
|
||||||
|
|
||||||
ParserCopy(&CountParser, Parser);
|
ParserCopy(&CountParser, Parser);
|
||||||
NumElements = ParseArrayInitialiser(&CountParser, NewVariable, false);
|
NumElements = ParseArrayInitializer(&CountParser, NewVariable, false);
|
||||||
|
|
||||||
if (NewVariable->Typ->Base != TypeArray)
|
if (NewVariable->Typ->Base != TypeArray)
|
||||||
AssignFail(Parser, "%t from array initializer", NewVariable->Typ,
|
AssignFail(Parser, "%t from array initializer", NewVariable->Typ,
|
||||||
|
@ -218,11 +218,11 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse the array initialiser */
|
/* parse the array initializer */
|
||||||
Token = LexGetToken(Parser, NULL, false);
|
Token = LexGetToken(Parser, NULL, false);
|
||||||
while (Token != TokenRightBrace) {
|
while (Token != TokenRightBrace) {
|
||||||
if (LexGetToken(Parser, NULL, false) == TokenLeftBrace) {
|
if (LexGetToken(Parser, NULL, false) == TokenLeftBrace) {
|
||||||
/* this is a sub-array initialiser */
|
/* this is a sub-array initializer */
|
||||||
int SubArraySize = 0;
|
int SubArraySize = 0;
|
||||||
struct Value *SubArray = NewVariable;
|
struct Value *SubArray = NewVariable;
|
||||||
if (Parser->Mode == RunModeRun && DoAssignment) {
|
if (Parser->Mode == RunModeRun && DoAssignment) {
|
||||||
|
@ -245,7 +245,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
ProgramFail(Parser, "too many array elements");
|
ProgramFail(Parser, "too many array elements");
|
||||||
}
|
}
|
||||||
LexGetToken(Parser, NULL, true);
|
LexGetToken(Parser, NULL, true);
|
||||||
ParseArrayInitialiser(Parser, SubArray, DoAssignment);
|
ParseArrayInitializer(Parser, SubArray, DoAssignment);
|
||||||
} else {
|
} else {
|
||||||
struct Value *ArrayElement = NULL;
|
struct Value *ArrayElement = NULL;
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ int ParseArrayInitialiser(struct ParseState *Parser, struct Value *NewVariable,
|
||||||
true, NewVariable);
|
true, NewVariable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this is a normal expression initialiser */
|
/* this is a normal expression initializer */
|
||||||
if (!ExpressionParse(Parser, &CValue))
|
if (!ExpressionParse(Parser, &CValue))
|
||||||
ProgramFail(Parser, "expression expected");
|
ProgramFail(Parser, "expression expected");
|
||||||
|
|
||||||
|
@ -318,11 +318,11 @@ void ParseDeclarationAssignment(struct ParseState *Parser,
|
||||||
struct Value *CValue;
|
struct Value *CValue;
|
||||||
|
|
||||||
if (LexGetToken(Parser, NULL, false) == TokenLeftBrace) {
|
if (LexGetToken(Parser, NULL, false) == TokenLeftBrace) {
|
||||||
/* this is an array initialiser */
|
/* this is an array initializer */
|
||||||
LexGetToken(Parser, NULL, true);
|
LexGetToken(Parser, NULL, true);
|
||||||
ParseArrayInitialiser(Parser, NewVariable, DoAssignment);
|
ParseArrayInitializer(Parser, NewVariable, DoAssignment);
|
||||||
} else {
|
} else {
|
||||||
/* this is a normal expression initialiser */
|
/* this is a normal expression initializer */
|
||||||
if (!ExpressionParse(Parser, &CValue))
|
if (!ExpressionParse(Parser, &CValue))
|
||||||
ProgramFail(Parser, "expression expected");
|
ProgramFail(Parser, "expression expected");
|
||||||
|
|
||||||
|
|
2
picoc.c
2
picoc.c
|
@ -41,7 +41,7 @@ int main(int argc, char **argv)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PicocInitialise(&pc, StackSize);
|
PicocInitialize(&pc, StackSize);
|
||||||
|
|
||||||
if (strcmp(argv[ParamCount], "-s") == 0) {
|
if (strcmp(argv[ParamCount], "-s") == 0) {
|
||||||
DontRunMain = true;
|
DontRunMain = true;
|
||||||
|
|
2
picoc.h
2
picoc.h
|
@ -26,7 +26,7 @@ extern void PicocParseInteractive(Picoc *pc);
|
||||||
|
|
||||||
/* platform.c */
|
/* platform.c */
|
||||||
extern void PicocCallMain(Picoc *pc, int argc, char **argv);
|
extern void PicocCallMain(Picoc *pc, int argc, char **argv);
|
||||||
extern void PicocInitialise(Picoc *pc, int StackSize);
|
extern void PicocInitialize(Picoc *pc, int StackSize);
|
||||||
extern void PicocCleanup(Picoc *pc);
|
extern void PicocCleanup(Picoc *pc);
|
||||||
extern void PicocPlatformScanFile(Picoc *pc, const char *FileName);
|
extern void PicocPlatformScanFile(Picoc *pc, const char *FileName);
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@ static int gEnableDebugger = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* initialise everything */
|
/* initialize everything */
|
||||||
void PicocInitialise(Picoc *pc, int StackSize)
|
void PicocInitialize(Picoc *pc, int StackSize)
|
||||||
{
|
{
|
||||||
memset(pc, '\0', sizeof(*pc));
|
memset(pc, '\0', sizeof(*pc));
|
||||||
PlatformInit(pc);
|
PlatformInit(pc);
|
||||||
|
@ -255,7 +255,7 @@ void PlatformVPrintf(IOFILE *Stream, const char *Format, va_list Args)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make a new temporary name. takes a static buffer of char [7] as a parameter.
|
/* make a new temporary name. takes a static buffer of char [7] as a parameter.
|
||||||
* should be initialised to "XX0000"
|
* should be initialized to "XX0000"
|
||||||
* where XX can be any characters */
|
* where XX can be any characters */
|
||||||
char *PlatformMakeTempName(Picoc *pc, char *TempNameBuffer)
|
char *PlatformMakeTempName(Picoc *pc, char *TempNameBuffer)
|
||||||
{
|
{
|
||||||
|
|
4
table.c
4
table.c
|
@ -10,7 +10,7 @@ static struct TableEntry *TableSearch(struct Table *Tbl, const char *Key,
|
||||||
static struct TableEntry *TableSearchIdentifier(struct Table *Tbl,
|
static struct TableEntry *TableSearchIdentifier(struct Table *Tbl,
|
||||||
const char *Key, int Len, int *AddAt);
|
const char *Key, int Len, int *AddAt);
|
||||||
|
|
||||||
/* initialise the shared string system */
|
/* initialize the shared string system */
|
||||||
void TableInit(Picoc *pc)
|
void TableInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
TableInitTable(&pc->StringTable, &pc->StringHashTable[0],
|
TableInitTable(&pc->StringTable, &pc->StringHashTable[0],
|
||||||
|
@ -35,7 +35,7 @@ unsigned int TableHash(const char *Key, int Len)
|
||||||
return Hash;
|
return Hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialise a table */
|
/* initialize a table */
|
||||||
void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size,
|
void TableInitTable(struct Table *Tbl, struct TableEntry **HashTable, int Size,
|
||||||
int OnHeap)
|
int OnHeap)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,7 +33,7 @@ TESTS= 00_assignment.test \
|
||||||
33_ternary_op.test \
|
33_ternary_op.test \
|
||||||
34_array_assignment.test \
|
34_array_assignment.test \
|
||||||
35_sizeof.test \
|
35_sizeof.test \
|
||||||
36_array_initialisers.test \
|
36_array_initializers.test \
|
||||||
37_sprintf.test \
|
37_sprintf.test \
|
||||||
38_multiple_array_index.test \
|
38_multiple_array_index.test \
|
||||||
39_typedef.test \
|
39_typedef.test \
|
||||||
|
@ -49,7 +49,7 @@ TESTS= 00_assignment.test \
|
||||||
51_static.test \
|
51_static.test \
|
||||||
52_unnamed_enum.test \
|
52_unnamed_enum.test \
|
||||||
54_goto.test \
|
54_goto.test \
|
||||||
55_array_initialiser.test \
|
55_array_initializer.test \
|
||||||
56_cross_structure.test \
|
56_cross_structure.test \
|
||||||
57_macro_bug.test \
|
57_macro_bug.test \
|
||||||
58_return_outside.test \
|
58_return_outside.test \
|
||||||
|
|
2
type.c
2
type.c
|
@ -136,7 +136,7 @@ void TypeAddBaseType(Picoc *pc, struct ValueType *TypeNode, enum BaseType Base,
|
||||||
pc->UberType.DerivedTypeList = TypeNode;
|
pc->UberType.DerivedTypeList = TypeNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialise the type system */
|
/* initialize the type system */
|
||||||
void TypeInit(Picoc *pc)
|
void TypeInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
struct IntAlign {char x; int y;} ia;
|
struct IntAlign {char x; int y;} ia;
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#define MAX_TMP_COPY_BUF (256)
|
#define MAX_TMP_COPY_BUF (256)
|
||||||
|
|
||||||
|
|
||||||
/* initialise the variable system */
|
/* initialize the variable system */
|
||||||
void VariableInit(Picoc *pc)
|
void VariableInit(Picoc *pc)
|
||||||
{
|
{
|
||||||
TableInitTable(&(pc->GlobalTable), &(pc->GlobalHashTable)[0],
|
TableInitTable(&(pc->GlobalTable), &(pc->GlobalHashTable)[0],
|
||||||
|
|
Loading…
Reference in a new issue