Working on a struct example for Howard
git-svn-id: http://picoc.googlecode.com/svn/trunk@218 21eae674-98b7-11dd-bd71-f92a316d2d60
This commit is contained in:
parent
74673d965a
commit
61e93e4774
|
@ -2,11 +2,53 @@
|
|||
|
||||
void PlatformLibraryInit()
|
||||
{
|
||||
#if 0
|
||||
struct ParseState Parser;
|
||||
char *Identifier;
|
||||
struct ValueType *ParsedType;
|
||||
void *Tokens;
|
||||
const char *IntrinsicName = TableStrRegister("unix library");
|
||||
const char *StructDefinition = "struct complex { int i; int j; }";
|
||||
|
||||
/* define an example structure */
|
||||
Tokens = LexAnalyse(IntrinsicName, StructDefinition, strlen(StructDefinition), NULL);
|
||||
LexInitParser(&Parser, Tokens, IntrinsicName, 1, TRUE);
|
||||
TypeParse(&Parser, &ParsedType, &Identifier);
|
||||
HeapFree(Tokens);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ShowComplex(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||
{
|
||||
#if 0
|
||||
struct Value *ComplexVal = Param[0]->Val->Pointer.Segment; /* dereferences the pointer */
|
||||
struct Value *RealOffset;
|
||||
struct Value *ComplexOffset;
|
||||
int RealPart;
|
||||
int ComplexPart;
|
||||
struct ValueType *StructComplexType;
|
||||
|
||||
/* find the type */
|
||||
StructComplexType = TypeGetMatching(Parser, NULL, TypeStruct, 0, TableStrRegister("complex"));
|
||||
|
||||
/* get the real and complex members */
|
||||
TableGet(StructComplexType->Members, TableStrRegister("i"), &RealOffset);
|
||||
RealPart = *(int *)((void *)ComplexVal->Val + RealOffset->Val->Integer);
|
||||
|
||||
TableGet(StructComplexType->Members, TableStrRegister("j"), &ComplexOffset);
|
||||
ComplexPart = *(int *)((void *)ComplexVal->Val + ComplexOffset->Val->Integer);
|
||||
|
||||
/* print the result */
|
||||
PrintInt(RealPart, PlatformPutc);
|
||||
PlatformPutc(',');
|
||||
PrintInt(ComplexPart, PlatformPutc);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* list of all library functions and their prototypes */
|
||||
struct LibraryFunction PlatformLibrary[] =
|
||||
{
|
||||
// { ShowComplex, "void ShowComplex(struct complex *)" },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue