From 61e93e47746530d0b6dd7931bcf49252e2560bd0 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Tue, 7 Apr 2009 06:36:06 +0000 Subject: [PATCH] Working on a struct example for Howard git-svn-id: http://picoc.googlecode.com/svn/trunk@218 21eae674-98b7-11dd-bd71-f92a316d2d60 --- library_unix.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/library_unix.c b/library_unix.c index 403fef6..d28531b 100644 --- a/library_unix.c +++ b/library_unix.c @@ -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 } };