From 18acb6dc1a7dab7c85e4f982027c5cc65166bc28 Mon Sep 17 00:00:00 2001 From: "zik.saleeba" Date: Sun, 1 Nov 2009 21:02:31 +0000 Subject: [PATCH] Removed old pointer system. Now it's "native pointers" all the way. git-svn-id: http://picoc.googlecode.com/svn/trunk@368 21eae674-98b7-11dd-bd71-f92a316d2d60 --- clibrary.c | 57 +------------------- expression.c | 146 +-------------------------------------------------- lex.c | 12 ----- parse.c | 4 -- picoc.h | 23 -------- type.c | 20 ------- variable.c | 45 +--------------- 7 files changed, 5 insertions(+), 302 deletions(-) diff --git a/clibrary.c b/clibrary.c index 6122ce8..4cb1972 100644 --- a/clibrary.c +++ b/clibrary.c @@ -43,10 +43,6 @@ void SPutc(unsigned char Ch, union OutputStreamInfo *Stream) { struct StringOutputStream *Out = &Stream->Str; *Out->WritePos++ = Ch; -#ifndef NATIVE_POINTERS - if (Out->WritePos == Out->MaxPos) - Out->WritePos--; -#endif } /* print a character to a stream without using printf/sprintf */ @@ -188,18 +184,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct int LeftJustify = FALSE; int ZeroPad = FALSE; int FieldWidth = 0; -#ifndef NATIVE_POINTERS - char *Format; - struct Value *CharArray = Param[0]->Val->Pointer.Segment; - - if (Param[0]->Val->Pointer.Offset < 0 || Param[0]->Val->Pointer.Offset >= CharArray->Val->Array.Size) - Format = StrEmpty; - else - Format = (char *)CharArray->Val->Array.Data + Param[0]->Val->Pointer.Offset; -#else char *Format = Param[0]->Val->NativePointer; - /* XXX - dereference this properly */ -#endif for (FPos = Format; *FPos != '\0'; FPos++) { @@ -258,18 +243,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct char *Str; if (NextArg->Typ->Base == TypePointer) - { -#ifndef NATIVE_POINTERS - struct Value *CharArray = NextArg->Val->Pointer.Segment; - - if (NextArg->Val->Pointer.Offset < 0 || NextArg->Val->Pointer.Offset >= CharArray->Val->Array.Size) - Str = StrEmpty; - else - Str = (char *)CharArray->Val->Array.Data + NextArg->Val->Pointer.Offset; -#else Str = NextArg->Val->NativePointer; -#endif - } else Str = NextArg->Val->Array.Data; @@ -321,40 +295,14 @@ void LibSPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Val StrStream.Putch = &SPutc; StrStream.i.Str.Parser = Parser; -#ifndef NATIVE_POINTERS - StrStream.i.Str.MaxPos = StrStream.i.Str.WritePos - DerefOffset + DerefVal->Val->Array.Size; -#endif GenericPrintf(Parser, ReturnValue, Param+1, NumArgs-1, &StrStream); PrintCh(0, &StrStream); -#ifndef NATIVE_POINTERS - ReturnValue->Val->Pointer.Segment = *Param; - ReturnValue->Val->Pointer.Offset = 0; -#else ReturnValue->Val->NativePointer = *Param; -#endif } /* get a line of input. protected from buffer overrun */ void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { -#ifndef NATIVE_POINTERS - struct Value *CharArray = Param[0]->Val->Pointer.Segment; - char *ReadBuffer = (char *)CharArray->Val->Array.Data + Param[0]->Val->Pointer.Offset; - int MaxLength = CharArray->Val->Array.Size - Param[0]->Val->Pointer.Offset; - char *Result; - - ReturnValue->Val->Pointer.Segment = NULL; - ReturnValue->Val->Pointer.Offset = 0; - - if (Param[0]->Val->Pointer.Offset < 0 || MaxLength < 0) - return; /* no room for data */ - - Result = PlatformGetLine(ReadBuffer, MaxLength); - if (Result == NULL) - return; - - ReturnValue->Val->Pointer = Param[0]->Val->Pointer; -#else struct Value *CharArray = (struct Value *)(Param[0]->Val->NativePointer); char *ReadBuffer = CharArray->Val->Array.Data; char *Result; @@ -365,7 +313,6 @@ void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value return; ReturnValue->Val->NativePointer = Param[0]->Val->NativePointer; -#endif } void LibGetc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) @@ -470,7 +417,7 @@ void LibFloor(struct ParseState *Parser, struct Value *ReturnValue, struct Value } #endif -#ifdef NATIVE_POINTERS +#ifndef NO_STRING_FUNCTIONS void LibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs) { ReturnValue->Val->NativePointer = malloc(Param[0]->Val->Integer); @@ -575,7 +522,7 @@ struct LibraryFunction CLibrary[] = { LibCeil, "float ceil(float)" }, { LibFloor, "float floor(float)" }, #endif -#ifdef NATIVE_POINTERS +#ifndef NO_STRING_FUNCTIONS { LibMalloc, "void *malloc(int)" }, { LibCalloc, "void *calloc(int,int)" }, { LibCalloc, "void *realloc(void *,int)" }, diff --git a/expression.c b/expression.c index b600f65..637eaea 100644 --- a/expression.c +++ b/expression.c @@ -138,12 +138,7 @@ int ExpressionCoerceInteger(struct Value *Val) case TypeUnsignedInt: return (int)Val->Val->UnsignedInteger; case TypeUnsignedChar: return (int)Val->Val->UnsignedCharacter; case TypeUnsignedShort: return (int)Val->Val->UnsignedShortInteger; - case TypePointer: -#ifdef NATIVE_POINTERS - return (int)Val->Val->NativePointer; -#else - return 0; -#endif + case TypePointer: return (int)Val->Val->NativePointer; #ifndef NO_FP case TypeFP: return (int)Val->Val->FP; #endif @@ -161,12 +156,7 @@ unsigned int ExpressionCoerceUnsignedInteger(struct Value *Val) case TypeUnsignedInt: return (unsigned int)Val->Val->UnsignedInteger; case TypeUnsignedChar: return (unsigned int)Val->Val->UnsignedCharacter; case TypeUnsignedShort: return (unsigned int)Val->Val->UnsignedShortInteger; - case TypePointer: -#ifdef NATIVE_POINTERS - return (unsigned int)Val->Val->NativePointer; -#else - return 0; -#endif + case TypePointer: return (unsigned int)Val->Val->NativePointer; #ifndef NO_FP case TypeFP: return (unsigned int)Val->Val->FP; #endif @@ -174,7 +164,6 @@ unsigned int ExpressionCoerceUnsignedInteger(struct Value *Val) } } -#ifdef NATIVE_POINTERS double ExpressionCoerceFP(struct Value *Val) { switch (Val->Typ->Base) @@ -191,7 +180,6 @@ double ExpressionCoerceFP(struct Value *Val) default: return 0; } } -#endif /* assign an integer value */ int ExpressionAssignInt(struct ParseState *Parser, struct Value *DestValue, int FromInt, int After) @@ -292,59 +280,30 @@ void ExpressionPushFP(struct ParseState *Parser, struct ExpressionStack **StackT void ExpressionAssignToPointer(struct ParseState *Parser, struct Value *ToValue, struct Value *FromValue, const char *FuncName, int ParamNo, int AllowPointerCoercion) { struct ValueType *PointedToType = ToValue->Typ->FromType; -#ifndef NATIVE_POINTERS - struct Value *DerefVal = NULL; - int DerefOffset; -#endif if (FromValue->Typ == ToValue->Typ || FromValue->Typ == VoidPtrType || ToValue->Typ == VoidPtrType) - { -#ifndef NATIVE_POINTERS - ToValue->Val->Pointer = FromValue->Val->Pointer; /* plain old pointer assignment */ -#else ToValue->Val->NativePointer = FromValue->Val->NativePointer; /* plain old pointer assignment */ -#endif - } else if (FromValue->Typ->Base == TypeArray && PointedToType == FromValue->Typ->FromType) { /* the form is: blah *x = array of blah */ -#ifndef NATIVE_POINTERS - ToValue->Val->Pointer.Segment = FromValue; - ToValue->Val->Pointer.Offset = 0; - DerefVal = FromValue; -#else ToValue->Val->NativePointer = FromValue->Val->Array.Data; -#endif } else if (FromValue->Typ->Base == TypePointer && FromValue->Typ->FromType->Base == TypeArray && PointedToType == FromValue->Typ->FromType->FromType) { /* the form is: blah *x = pointer to array of blah */ -#ifndef NATIVE_POINTERS - VariableDereferencePointer(Parser, FromValue, &DerefVal, &DerefOffset, NULL, NULL); - ToValue->Val->Pointer.Segment = DerefVal; - ToValue->Val->Pointer.Offset = DerefOffset; -#else ToValue->Val->NativePointer = VariableDereferencePointer(Parser, FromValue, NULL, NULL, NULL, NULL); -#endif } else if (IS_NUMERIC_COERCIBLE(FromValue) && ExpressionCoerceInteger(FromValue) == 0) { /* null pointer assignment */ -#ifndef NATIVE_POINTERS - ToValue->Val->Pointer.Segment = NULL; - ToValue->Val->Pointer.Offset = 0; -#else ToValue->Val->NativePointer = NULL; -#endif } -#ifdef NATIVE_POINTERS else if (AllowPointerCoercion && IS_NUMERIC_COERCIBLE(FromValue)) { /* assign integer to native pointer */ ToValue->Val->NativePointer = (void *)ExpressionCoerceUnsignedInteger(FromValue); } -#endif else AssignFail(Parser, "%t from %t", ToValue->Typ, FromValue->Typ, 0, 0, FuncName, ParamNo); } @@ -383,17 +342,10 @@ void ExpressionAssign(struct ParseState *Parser, struct Value *DestValue, struct if (DestValue->Typ != SourceValue->Typ) AssignFail(Parser, "%t from %t", DestValue->Typ, SourceValue->Typ, 0, 0, FuncName, ParamNo); -#ifndef NATIVE_POINTERS - if (DestValue->Val->Array.Size != SourceValue->Val->Array.Size) - AssignFail(Parser, "from an array of size %d to one of size %d", NULL, NULL, SourceValue->Val->Array.Size, DestValue->Val->Array.Size, FuncName, ParamNo); - - memcpy((void *)DestValue->Val->Array.Data, (void *)SourceValue->Val->Array.Data, DestValue->Val->Array.Size); -#else if (DestValue->Typ->ArraySize != SourceValue->Typ->ArraySize) AssignFail(Parser, "from an array of size %d to one of size %d", NULL, NULL, DestValue->Typ->ArraySize, SourceValue->Typ->ArraySize, FuncName, ParamNo); memcpy((void *)DestValue->Val->Array.Data, (void *)SourceValue->Val->Array.Data, DestValue->Typ->ArraySize); -#endif break; case TypeStruct: @@ -430,17 +382,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack ProgramFail(Parser, "can't get the address of this"); Result = VariableAllocValueFromType(Parser, TypeGetMatching(Parser, TopValue->Typ, TypePointer, 0, StrEmpty), FALSE, NULL, FALSE); -#ifndef NATIVE_POINTERS - { - struct Value *TempLValue = TopValue->LValueFrom; - assert(TempLValue != NULL); - Result->Val->Pointer.Segment = TempLValue; - if (Result->LValueFrom != NULL) - Result->Val->Pointer.Offset = (char *)Result->Val - (char *)Result->LValueFrom; - } -#else Result->Val->NativePointer = TopValue->Val; -#endif ExpressionStackPushValueNode(Parser, StackTop, Result); break; @@ -507,29 +449,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack /* pointer prefix arithmetic */ int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE); struct Value *StackValue; -#ifndef NATIVE_POINTERS - int OrigOffset = TopValue->Val->Pointer.Offset; - - if (TopValue->Val->Pointer.Segment == NULL) - ProgramFail(Parser, "invalid use of a NULL pointer"); - - if (!TopValue->IsLValue) - ProgramFail(Parser, "can't assign to this"); - - switch (Op) - { - case TokenIncrement: TopValue->Val->Pointer.Offset += Size; break; - case TokenDecrement: TopValue->Val->Pointer.Offset -= Size; break; - default: ProgramFail(Parser, "invalid operation"); break; - } - - /* check pointer bounds */ - if (TopValue->Val->Pointer.Offset < 0 || TopValue->Val->Pointer.Offset > TypeLastAccessibleOffset(TopValue->Val->Pointer.Segment)) - TopValue->Val->Pointer.Offset = OrigOffset; - - StackValue = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ); - StackValue->Val->Pointer = TopValue->Val->Pointer; -#else if (TopValue->Val->NativePointer == NULL) ProgramFail(Parser, "invalid use of a NULL pointer"); @@ -545,7 +464,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack StackValue = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ); StackValue->Val->NativePointer = TopValue->Val->NativePointer; -#endif } else ProgramFail(Parser, "invalid operation"); @@ -584,31 +502,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack /* pointer postfix arithmetic */ int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE); struct Value *StackValue; -#ifndef NATIVE_POINTERS - struct PointerValue OrigPointer = TopValue->Val->Pointer; - - if (TopValue->Val->Pointer.Segment == NULL) - ProgramFail(Parser, "invalid use of a NULL pointer"); - - if (!TopValue->IsLValue) - ProgramFail(Parser, "can't assign to this"); - - switch (Op) - { - case TokenIncrement: TopValue->Val->Pointer.Offset += Size; break; - case TokenDecrement: TopValue->Val->Pointer.Offset -= Size; break; - default: ProgramFail(Parser, "invalid operation"); break; - } - - /* check pointer bounds */ - if (TopValue->Val->Pointer.Offset < 0) - TopValue->Val->Pointer.Offset = 0; - else if (TopValue->Val->Pointer.Offset > TypeLastAccessibleOffset(TopValue->Val->Pointer.Segment)) - TopValue->Val->Pointer.Offset = TypeLastAccessibleOffset(TopValue->Val->Pointer.Segment); - - StackValue = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ); - StackValue->Val->Pointer = OrigPointer; -#else void *OrigPointer = TopValue->Val->NativePointer; if (TopValue->Val->NativePointer == NULL) @@ -626,7 +519,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack StackValue = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ); StackValue->Val->NativePointer = OrigPointer; -#endif } else ProgramFail(Parser, "invalid operation"); @@ -637,11 +529,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * { int ResultInt = 0; struct Value *StackValue; -#ifndef NATIVE_POINTERS - struct PointerValue Pointer; -#else void *NativePointer; -#endif if (Parser->Mode != RunModeRun) { @@ -767,40 +655,16 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * if (TopInt != 0) ProgramFail(Parser, "invalid operation"); -#ifndef NATIVE_POINTERS - if (Op == TokenEqual) - ExpressionPushInt(Parser, StackTop, BottomValue->Val->Pointer.Segment == NULL); - else - ExpressionPushInt(Parser, StackTop, BottomValue->Val->Pointer.Segment != NULL); -#else if (Op == TokenEqual) ExpressionPushInt(Parser, StackTop, BottomValue->Val->NativePointer == NULL); else ExpressionPushInt(Parser, StackTop, BottomValue->Val->NativePointer != NULL); -#endif } else if (Op == TokenPlus || Op == TokenMinus) { /* pointer arithmetic */ int Size = TypeSize(BottomValue->Typ->FromType, 0, TRUE); -#ifndef NATIVE_POINTERS - Pointer = BottomValue->Val->Pointer; - if (Pointer.Segment == NULL) - ProgramFail(Parser, "invalid use of a NULL pointer"); - - if (Op == TokenPlus) - Pointer.Offset += TopInt * Size; - else - Pointer.Offset -= TopInt * Size; - - /* check pointer bounds */ - if (Pointer.Offset < 0 || Pointer.Offset > TypeLastAccessibleOffset(Pointer.Segment)) - Pointer.Offset = BottomValue->Val->Pointer.Offset; - - StackValue = ExpressionStackPushValueByType(Parser, StackTop, BottomValue->Typ); - StackValue->Val->Pointer = Pointer; -#else NativePointer = BottomValue->Val->NativePointer; if (NativePointer == NULL) ProgramFail(Parser, "invalid use of a NULL pointer"); @@ -812,7 +676,6 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * StackValue = ExpressionStackPushValueByType(Parser, StackTop, BottomValue->Typ); StackValue->Val->NativePointer = NativePointer; -#endif } else if (Op == TokenAssign && TopInt == 0) { @@ -827,13 +690,8 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack * else if (BottomValue->Typ->Base == TypePointer && TopValue->Typ->Base == TypePointer && Op != TokenAssign) { /* pointer/pointer operations */ -#ifndef NATIVE_POINTERS - char *TopLoc = (char *)TopValue->Val->Pointer.Segment->Val + TopValue->Val->Pointer.Offset; - char *BottomLoc = (char *)BottomValue->Val->Pointer.Segment->Val + BottomValue->Val->Pointer.Offset; -#else char *TopLoc = (char *)TopValue->Val->NativePointer; char *BottomLoc = (char *)BottomValue->Val->NativePointer; -#endif switch (Op) { diff --git a/lex.c b/lex.c index df22099..44f7a33 100644 --- a/lex.c +++ b/lex.c @@ -308,21 +308,13 @@ enum LexToken LexGetStringConstant(struct LexState *Lexer, struct Value *Value) /* create and store this string literal */ ArrayValue = VariableAllocValueAndData(NULL, sizeof(struct ArrayValue), FALSE, NULL, TRUE); ArrayValue->Typ = CharArrayType; -#ifndef NATIVE_POINTERS - ArrayValue->Val->Array.Size = EscBufPos - EscBuf + 1; -#endif ArrayValue->Val->Array.Data = RegString; VariableStringLiteralDefine(RegString, ArrayValue); } /* create the the pointer for this char* */ Value->Typ = CharPtrType; -#ifndef NATIVE_POINTERS - Value->Val->Pointer.Segment = ArrayValue; - Value->Val->Pointer.Offset = 0; -#else Value->Val->NativePointer = RegString; -#endif if (*Lexer->Pos == '"') LEXER_INC(Lexer); @@ -649,11 +641,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I { switch (Token) { -#ifndef NATIVE_POINTERS - case TokenStringConstant: LexValue.Typ = CharPtrType; LexValue.Val->Pointer.Offset = 0; break; -#else case TokenStringConstant: LexValue.Typ = CharPtrType; break; -#endif case TokenIdentifier: LexValue.Typ = NULL; break; case TokenIntegerConstant: LexValue.Typ = &IntType; break; case TokenCharacterConstant: LexValue.Typ = &CharType; break; diff --git a/parse.c b/parse.c index 97a0c3b..416ce12 100644 --- a/parse.c +++ b/parse.c @@ -423,11 +423,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser) if (LexGetToken(Parser, &LexerValue, TRUE) != TokenStringConstant) ProgramFail(Parser, "\"filename.h\" expected"); -#ifndef NATIVE_POINTERS - PlatformScanFile(LexerValue->Val->Pointer.Segment->Val->Array.Data); -#else PlatformScanFile((char *)LexerValue->Val->NativePointer); -#endif CheckTrailingSemicolon = FALSE; break; #endif diff --git a/picoc.h b/picoc.h index e99c074..54e4744 100644 --- a/picoc.h +++ b/picoc.h @@ -36,13 +36,8 @@ #define FP_VAL(v) 0 #endif -#ifdef NATIVE_POINTERS #define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0) #define POINTER_COERCE(v) ((int)(v)->Val->NativePointer) -#else -#define IS_POINTER_COERCIBLE(v, ap) 0 -#define POINTER_COERCE(v) 0 -#endif #define IS_INTEGER_NUMERIC(v) ((v)->Typ->Base == TypeInt || (v)->Typ->Base == TypeChar || (v)->Typ->Base == TypeShort) #define IS_NUMERIC_COERCIBLE(v) (IS_INTEGER_NUMERIC(v) || IS_FP(v)) @@ -166,20 +161,9 @@ struct FuncDef /* values */ struct ArrayValue { -#ifndef NATIVE_POINTERS - unsigned int Size; /* the number of elements in the array */ -#endif void *Data; /* pointer to the array data */ }; -#ifndef NATIVE_POINTERS -struct PointerValue -{ - struct Value *Segment; /* array or basic value which this points to, NULL for machine memory access */ - unsigned int Offset; /* index into an array */ -}; -#endif - union AnyValue { char Character; @@ -198,11 +182,7 @@ union AnyValue double FP; #endif -#ifndef NATIVE_POINTERS - struct PointerValue Pointer; /* safe pointers */ -#else void *NativePointer; /* unsafe native pointers */ -#endif }; struct Value @@ -277,9 +257,6 @@ union OutputStreamInfo { struct ParseState *Parser; char *WritePos; -#ifndef NATIVE_POINTERS - char *MaxPos; -#endif } Str; }; diff --git a/type.c b/type.c index e18ed06..e180b8a 100644 --- a/type.c +++ b/type.c @@ -52,11 +52,7 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P switch (Base) { -#ifndef NATIVE_POINTERS - case TypePointer: Sizeof = sizeof(struct PointerValue); break; -#else case TypePointer: Sizeof = sizeof(void *); break; -#endif case TypeArray: Sizeof = sizeof(struct ArrayValue) + ArraySize * ParentType->Sizeof; break; case TypeEnum: Sizeof = sizeof(int); break; default: Sizeof = 0; break; /* structs and unions will get bigger when we add members to them */ @@ -85,17 +81,6 @@ int TypeSizeValue(struct Value *Val) return sizeof(struct ArrayValue) + Val->Typ->FromType->Sizeof * Val->Typ->ArraySize; } -#ifndef NATIVE_POINTERS -/* the last accessible offset of a value */ -int TypeLastAccessibleOffset(struct Value *Val) -{ - if (Val->Typ->Base != TypeArray) - return 0; - else - return Val->Typ->FromType->Sizeof * (Val->Val->Array.Size-1); -} -#endif - /* memory used by a variable given its type and array size */ int TypeSize(struct ValueType *Typ, int ArraySize, int Compact) { @@ -151,13 +136,8 @@ void TypeInit() TypeAddBaseType(&TypeType, Type_Type, sizeof(struct ValueType *)); #endif CharArrayType = TypeAdd(NULL, &CharType, TypeArray, 0, StrEmpty, sizeof(char)); -#ifndef NATIVE_POINTERS - CharPtrType = TypeAdd(NULL, &CharType, TypePointer, 0, StrEmpty, sizeof(struct PointerValue)); - VoidPtrType = TypeAdd(NULL, &VoidType, TypePointer, 0, StrEmpty, sizeof(struct PointerValue)); -#else CharPtrType = TypeAdd(NULL, &CharType, TypePointer, 0, StrEmpty, sizeof(void *)); VoidPtrType = TypeAdd(NULL, &VoidType, TypePointer, 0, StrEmpty, sizeof(void *)); -#endif } /* deallocate heap-allocated types */ diff --git a/variable.c b/variable.c index fceb834..d0ee26b 100644 --- a/variable.c +++ b/variable.c @@ -106,12 +106,7 @@ struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct Value assert(Size > 0 || Typ == &VoidType); NewValue->Typ = Typ; if (Typ->Base == TypeArray) - { -#ifndef NATIVE_POINTERS - NewValue->Val->Array.Size = Typ->ArraySize; -#endif NewValue->Val->Array.Data = (void *)((char *)NewValue->Val + sizeof(struct ArrayValue)); - } return NewValue; } @@ -197,13 +192,7 @@ void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct Va if (Typ->Base != TypeArray) SomeValue->Val = FromValue; else - { - /* define an array */ -#ifndef NATIVE_POINTERS - SomeValue->Val->Array.Size = Typ->ArraySize; -#endif SomeValue->Val->Array.Data = FromValue; - } if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, TableStrRegister(Ident), SomeValue)) ProgramFail(Parser, "'%s' is already defined", Ident); @@ -283,38 +272,6 @@ void VariableStringLiteralDefine(char *Ident, struct Value *Val) /* check a pointer for validity and dereference it for use */ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *PointerValue, struct Value **DerefVal, int *DerefOffset, struct ValueType **DerefType, int *DerefIsLValue) { -#ifndef NATIVE_POINTERS - struct Value *PointedToValue = PointerValue->Val->Pointer.Segment; - - /* this is a pointer to picoc memory */ - if (PointerValue->Typ->Base != TypePointer) - ProgramFail(Parser, "pointer expected"); - - if (PointedToValue == NULL) - ProgramFail(Parser, "can't dereference NULL pointer"); - - if (PointerValue->Val->Pointer.Offset < 0 || PointerValue->Val->Pointer.Offset > TypeLastAccessibleOffset(PointedToValue)) - ProgramFail(Parser, "attempt to access invalid pointer"); - - /* pass back the optional dereferenced pointer, offset and type */ - if (DerefVal != NULL) - *DerefVal = PointedToValue; - - if (DerefOffset != NULL) - *DerefOffset = PointerValue->Val->Pointer.Offset; - - if (DerefType != NULL) - *DerefType = PointerValue->Typ->FromType; - - if (DerefIsLValue != NULL) - *DerefIsLValue = PointedToValue->IsLValue; - - /* return a pointer to the data */ - if (PointedToValue->Typ->Base == TypeArray) - return (void *)((char *)PointedToValue->Val->Array.Data + PointerValue->Val->Pointer.Offset); - else - return (void *)((char *)PointedToValue->Val + PointerValue->Val->Pointer.Offset); -#else if (DerefVal != NULL) *DerefVal = NULL; @@ -328,5 +285,5 @@ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *Pointe *DerefIsLValue = TRUE; return PointerValue->Val->NativePointer; -#endif } +