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
This commit is contained in:
parent
e44aca659f
commit
18acb6dc1a
57
clibrary.c
57
clibrary.c
|
@ -43,10 +43,6 @@ void SPutc(unsigned char Ch, union OutputStreamInfo *Stream)
|
||||||
{
|
{
|
||||||
struct StringOutputStream *Out = &Stream->Str;
|
struct StringOutputStream *Out = &Stream->Str;
|
||||||
*Out->WritePos++ = Ch;
|
*Out->WritePos++ = Ch;
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
if (Out->WritePos == Out->MaxPos)
|
|
||||||
Out->WritePos--;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* print a character to a stream without using printf/sprintf */
|
/* 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 LeftJustify = FALSE;
|
||||||
int ZeroPad = FALSE;
|
int ZeroPad = FALSE;
|
||||||
int FieldWidth = 0;
|
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;
|
char *Format = Param[0]->Val->NativePointer;
|
||||||
/* XXX - dereference this properly */
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (FPos = Format; *FPos != '\0'; FPos++)
|
for (FPos = Format; *FPos != '\0'; FPos++)
|
||||||
{
|
{
|
||||||
|
@ -258,18 +243,7 @@ void GenericPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct
|
||||||
char *Str;
|
char *Str;
|
||||||
|
|
||||||
if (NextArg->Typ->Base == TypePointer)
|
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;
|
Str = NextArg->Val->NativePointer;
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
Str = NextArg->Val->Array.Data;
|
Str = NextArg->Val->Array.Data;
|
||||||
|
|
||||||
|
@ -321,40 +295,14 @@ void LibSPrintf(struct ParseState *Parser, struct Value *ReturnValue, struct Val
|
||||||
|
|
||||||
StrStream.Putch = &SPutc;
|
StrStream.Putch = &SPutc;
|
||||||
StrStream.i.Str.Parser = Parser;
|
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);
|
GenericPrintf(Parser, ReturnValue, Param+1, NumArgs-1, &StrStream);
|
||||||
PrintCh(0, &StrStream);
|
PrintCh(0, &StrStream);
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
ReturnValue->Val->Pointer.Segment = *Param;
|
|
||||||
ReturnValue->Val->Pointer.Offset = 0;
|
|
||||||
#else
|
|
||||||
ReturnValue->Val->NativePointer = *Param;
|
ReturnValue->Val->NativePointer = *Param;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get a line of input. protected from buffer overrun */
|
/* get a line of input. protected from buffer overrun */
|
||||||
void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
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);
|
struct Value *CharArray = (struct Value *)(Param[0]->Val->NativePointer);
|
||||||
char *ReadBuffer = CharArray->Val->Array.Data;
|
char *ReadBuffer = CharArray->Val->Array.Data;
|
||||||
char *Result;
|
char *Result;
|
||||||
|
@ -365,7 +313,6 @@ void LibGets(struct ParseState *Parser, struct Value *ReturnValue, struct Value
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ReturnValue->Val->NativePointer = Param[0]->Val->NativePointer;
|
ReturnValue->Val->NativePointer = Param[0]->Val->NativePointer;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibGetc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef NATIVE_POINTERS
|
#ifndef NO_STRING_FUNCTIONS
|
||||||
void LibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
void LibMalloc(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
|
||||||
{
|
{
|
||||||
ReturnValue->Val->NativePointer = malloc(Param[0]->Val->Integer);
|
ReturnValue->Val->NativePointer = malloc(Param[0]->Val->Integer);
|
||||||
|
@ -575,7 +522,7 @@ struct LibraryFunction CLibrary[] =
|
||||||
{ LibCeil, "float ceil(float)" },
|
{ LibCeil, "float ceil(float)" },
|
||||||
{ LibFloor, "float floor(float)" },
|
{ LibFloor, "float floor(float)" },
|
||||||
#endif
|
#endif
|
||||||
#ifdef NATIVE_POINTERS
|
#ifndef NO_STRING_FUNCTIONS
|
||||||
{ LibMalloc, "void *malloc(int)" },
|
{ LibMalloc, "void *malloc(int)" },
|
||||||
{ LibCalloc, "void *calloc(int,int)" },
|
{ LibCalloc, "void *calloc(int,int)" },
|
||||||
{ LibCalloc, "void *realloc(void *,int)" },
|
{ LibCalloc, "void *realloc(void *,int)" },
|
||||||
|
|
146
expression.c
146
expression.c
|
@ -138,12 +138,7 @@ int ExpressionCoerceInteger(struct Value *Val)
|
||||||
case TypeUnsignedInt: return (int)Val->Val->UnsignedInteger;
|
case TypeUnsignedInt: return (int)Val->Val->UnsignedInteger;
|
||||||
case TypeUnsignedChar: return (int)Val->Val->UnsignedCharacter;
|
case TypeUnsignedChar: return (int)Val->Val->UnsignedCharacter;
|
||||||
case TypeUnsignedShort: return (int)Val->Val->UnsignedShortInteger;
|
case TypeUnsignedShort: return (int)Val->Val->UnsignedShortInteger;
|
||||||
case TypePointer:
|
case TypePointer: return (int)Val->Val->NativePointer;
|
||||||
#ifdef NATIVE_POINTERS
|
|
||||||
return (int)Val->Val->NativePointer;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
case TypeFP: return (int)Val->Val->FP;
|
case TypeFP: return (int)Val->Val->FP;
|
||||||
#endif
|
#endif
|
||||||
|
@ -161,12 +156,7 @@ unsigned int ExpressionCoerceUnsignedInteger(struct Value *Val)
|
||||||
case TypeUnsignedInt: return (unsigned int)Val->Val->UnsignedInteger;
|
case TypeUnsignedInt: return (unsigned int)Val->Val->UnsignedInteger;
|
||||||
case TypeUnsignedChar: return (unsigned int)Val->Val->UnsignedCharacter;
|
case TypeUnsignedChar: return (unsigned int)Val->Val->UnsignedCharacter;
|
||||||
case TypeUnsignedShort: return (unsigned int)Val->Val->UnsignedShortInteger;
|
case TypeUnsignedShort: return (unsigned int)Val->Val->UnsignedShortInteger;
|
||||||
case TypePointer:
|
case TypePointer: return (unsigned int)Val->Val->NativePointer;
|
||||||
#ifdef NATIVE_POINTERS
|
|
||||||
return (unsigned int)Val->Val->NativePointer;
|
|
||||||
#else
|
|
||||||
return 0;
|
|
||||||
#endif
|
|
||||||
#ifndef NO_FP
|
#ifndef NO_FP
|
||||||
case TypeFP: return (unsigned int)Val->Val->FP;
|
case TypeFP: return (unsigned int)Val->Val->FP;
|
||||||
#endif
|
#endif
|
||||||
|
@ -174,7 +164,6 @@ unsigned int ExpressionCoerceUnsignedInteger(struct Value *Val)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef NATIVE_POINTERS
|
|
||||||
double ExpressionCoerceFP(struct Value *Val)
|
double ExpressionCoerceFP(struct Value *Val)
|
||||||
{
|
{
|
||||||
switch (Val->Typ->Base)
|
switch (Val->Typ->Base)
|
||||||
|
@ -191,7 +180,6 @@ double ExpressionCoerceFP(struct Value *Val)
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* assign an integer value */
|
/* assign an integer value */
|
||||||
int ExpressionAssignInt(struct ParseState *Parser, struct Value *DestValue, int FromInt, int After)
|
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)
|
void ExpressionAssignToPointer(struct ParseState *Parser, struct Value *ToValue, struct Value *FromValue, const char *FuncName, int ParamNo, int AllowPointerCoercion)
|
||||||
{
|
{
|
||||||
struct ValueType *PointedToType = ToValue->Typ->FromType;
|
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)
|
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 */
|
ToValue->Val->NativePointer = FromValue->Val->NativePointer; /* plain old pointer assignment */
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (FromValue->Typ->Base == TypeArray && PointedToType == FromValue->Typ->FromType)
|
else if (FromValue->Typ->Base == TypeArray && PointedToType == FromValue->Typ->FromType)
|
||||||
{
|
{
|
||||||
/* the form is: blah *x = array of blah */
|
/* 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;
|
ToValue->Val->NativePointer = FromValue->Val->Array.Data;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (FromValue->Typ->Base == TypePointer && FromValue->Typ->FromType->Base == TypeArray && PointedToType == FromValue->Typ->FromType->FromType)
|
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 */
|
/* 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);
|
ToValue->Val->NativePointer = VariableDereferencePointer(Parser, FromValue, NULL, NULL, NULL, NULL);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (IS_NUMERIC_COERCIBLE(FromValue) && ExpressionCoerceInteger(FromValue) == 0)
|
else if (IS_NUMERIC_COERCIBLE(FromValue) && ExpressionCoerceInteger(FromValue) == 0)
|
||||||
{
|
{
|
||||||
/* null pointer assignment */
|
/* null pointer assignment */
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
ToValue->Val->Pointer.Segment = NULL;
|
|
||||||
ToValue->Val->Pointer.Offset = 0;
|
|
||||||
#else
|
|
||||||
ToValue->Val->NativePointer = NULL;
|
ToValue->Val->NativePointer = NULL;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#ifdef NATIVE_POINTERS
|
|
||||||
else if (AllowPointerCoercion && IS_NUMERIC_COERCIBLE(FromValue))
|
else if (AllowPointerCoercion && IS_NUMERIC_COERCIBLE(FromValue))
|
||||||
{
|
{
|
||||||
/* assign integer to native pointer */
|
/* assign integer to native pointer */
|
||||||
ToValue->Val->NativePointer = (void *)ExpressionCoerceUnsignedInteger(FromValue);
|
ToValue->Val->NativePointer = (void *)ExpressionCoerceUnsignedInteger(FromValue);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
else
|
else
|
||||||
AssignFail(Parser, "%t from %t", ToValue->Typ, FromValue->Typ, 0, 0, FuncName, ParamNo);
|
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)
|
if (DestValue->Typ != SourceValue->Typ)
|
||||||
AssignFail(Parser, "%t from %t", DestValue->Typ, SourceValue->Typ, 0, 0, FuncName, ParamNo);
|
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)
|
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);
|
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);
|
memcpy((void *)DestValue->Val->Array.Data, (void *)SourceValue->Val->Array.Data, DestValue->Typ->ArraySize);
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TypeStruct:
|
case TypeStruct:
|
||||||
|
@ -430,17 +382,7 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
ProgramFail(Parser, "can't get the address of this");
|
ProgramFail(Parser, "can't get the address of this");
|
||||||
|
|
||||||
Result = VariableAllocValueFromType(Parser, TypeGetMatching(Parser, TopValue->Typ, TypePointer, 0, StrEmpty), FALSE, NULL, FALSE);
|
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;
|
Result->Val->NativePointer = TopValue->Val;
|
||||||
#endif
|
|
||||||
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
ExpressionStackPushValueNode(Parser, StackTop, Result);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -507,29 +449,6 @@ void ExpressionPrefixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
/* pointer prefix arithmetic */
|
/* pointer prefix arithmetic */
|
||||||
int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE);
|
int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE);
|
||||||
struct Value *StackValue;
|
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)
|
if (TopValue->Val->NativePointer == NULL)
|
||||||
ProgramFail(Parser, "invalid use of a NULL pointer");
|
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 = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ);
|
||||||
StackValue->Val->NativePointer = TopValue->Val->NativePointer;
|
StackValue->Val->NativePointer = TopValue->Val->NativePointer;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ProgramFail(Parser, "invalid operation");
|
ProgramFail(Parser, "invalid operation");
|
||||||
|
@ -584,31 +502,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
/* pointer postfix arithmetic */
|
/* pointer postfix arithmetic */
|
||||||
int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE);
|
int Size = TypeSize(TopValue->Typ->FromType, 0, TRUE);
|
||||||
struct Value *StackValue;
|
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;
|
void *OrigPointer = TopValue->Val->NativePointer;
|
||||||
|
|
||||||
if (TopValue->Val->NativePointer == NULL)
|
if (TopValue->Val->NativePointer == NULL)
|
||||||
|
@ -626,7 +519,6 @@ void ExpressionPostfixOperator(struct ParseState *Parser, struct ExpressionStack
|
||||||
|
|
||||||
StackValue = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ);
|
StackValue = ExpressionStackPushValueByType(Parser, StackTop, TopValue->Typ);
|
||||||
StackValue->Val->NativePointer = OrigPointer;
|
StackValue->Val->NativePointer = OrigPointer;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ProgramFail(Parser, "invalid operation");
|
ProgramFail(Parser, "invalid operation");
|
||||||
|
@ -637,11 +529,7 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
{
|
{
|
||||||
int ResultInt = 0;
|
int ResultInt = 0;
|
||||||
struct Value *StackValue;
|
struct Value *StackValue;
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
struct PointerValue Pointer;
|
|
||||||
#else
|
|
||||||
void *NativePointer;
|
void *NativePointer;
|
||||||
#endif
|
|
||||||
|
|
||||||
if (Parser->Mode != RunModeRun)
|
if (Parser->Mode != RunModeRun)
|
||||||
{
|
{
|
||||||
|
@ -767,40 +655,16 @@ void ExpressionInfixOperator(struct ParseState *Parser, struct ExpressionStack *
|
||||||
if (TopInt != 0)
|
if (TopInt != 0)
|
||||||
ProgramFail(Parser, "invalid operation");
|
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)
|
if (Op == TokenEqual)
|
||||||
ExpressionPushInt(Parser, StackTop, BottomValue->Val->NativePointer == NULL);
|
ExpressionPushInt(Parser, StackTop, BottomValue->Val->NativePointer == NULL);
|
||||||
else
|
else
|
||||||
ExpressionPushInt(Parser, StackTop, BottomValue->Val->NativePointer != NULL);
|
ExpressionPushInt(Parser, StackTop, BottomValue->Val->NativePointer != NULL);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (Op == TokenPlus || Op == TokenMinus)
|
else if (Op == TokenPlus || Op == TokenMinus)
|
||||||
{
|
{
|
||||||
/* pointer arithmetic */
|
/* pointer arithmetic */
|
||||||
int Size = TypeSize(BottomValue->Typ->FromType, 0, TRUE);
|
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;
|
NativePointer = BottomValue->Val->NativePointer;
|
||||||
if (NativePointer == NULL)
|
if (NativePointer == NULL)
|
||||||
ProgramFail(Parser, "invalid use of a NULL pointer");
|
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 = ExpressionStackPushValueByType(Parser, StackTop, BottomValue->Typ);
|
||||||
StackValue->Val->NativePointer = NativePointer;
|
StackValue->Val->NativePointer = NativePointer;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else if (Op == TokenAssign && TopInt == 0)
|
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)
|
else if (BottomValue->Typ->Base == TypePointer && TopValue->Typ->Base == TypePointer && Op != TokenAssign)
|
||||||
{
|
{
|
||||||
/* pointer/pointer operations */
|
/* 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 *TopLoc = (char *)TopValue->Val->NativePointer;
|
||||||
char *BottomLoc = (char *)BottomValue->Val->NativePointer;
|
char *BottomLoc = (char *)BottomValue->Val->NativePointer;
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (Op)
|
switch (Op)
|
||||||
{
|
{
|
||||||
|
|
12
lex.c
12
lex.c
|
@ -308,21 +308,13 @@ enum LexToken LexGetStringConstant(struct LexState *Lexer, struct Value *Value)
|
||||||
/* create and store this string literal */
|
/* create and store this string literal */
|
||||||
ArrayValue = VariableAllocValueAndData(NULL, sizeof(struct ArrayValue), FALSE, NULL, TRUE);
|
ArrayValue = VariableAllocValueAndData(NULL, sizeof(struct ArrayValue), FALSE, NULL, TRUE);
|
||||||
ArrayValue->Typ = CharArrayType;
|
ArrayValue->Typ = CharArrayType;
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
ArrayValue->Val->Array.Size = EscBufPos - EscBuf + 1;
|
|
||||||
#endif
|
|
||||||
ArrayValue->Val->Array.Data = RegString;
|
ArrayValue->Val->Array.Data = RegString;
|
||||||
VariableStringLiteralDefine(RegString, ArrayValue);
|
VariableStringLiteralDefine(RegString, ArrayValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create the the pointer for this char* */
|
/* create the the pointer for this char* */
|
||||||
Value->Typ = CharPtrType;
|
Value->Typ = CharPtrType;
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
Value->Val->Pointer.Segment = ArrayValue;
|
|
||||||
Value->Val->Pointer.Offset = 0;
|
|
||||||
#else
|
|
||||||
Value->Val->NativePointer = RegString;
|
Value->Val->NativePointer = RegString;
|
||||||
#endif
|
|
||||||
if (*Lexer->Pos == '"')
|
if (*Lexer->Pos == '"')
|
||||||
LEXER_INC(Lexer);
|
LEXER_INC(Lexer);
|
||||||
|
|
||||||
|
@ -649,11 +641,7 @@ enum LexToken LexGetToken(struct ParseState *Parser, struct Value **Value, int I
|
||||||
{
|
{
|
||||||
switch (Token)
|
switch (Token)
|
||||||
{
|
{
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
case TokenStringConstant: LexValue.Typ = CharPtrType; LexValue.Val->Pointer.Offset = 0; break;
|
|
||||||
#else
|
|
||||||
case TokenStringConstant: LexValue.Typ = CharPtrType; break;
|
case TokenStringConstant: LexValue.Typ = CharPtrType; break;
|
||||||
#endif
|
|
||||||
case TokenIdentifier: LexValue.Typ = NULL; break;
|
case TokenIdentifier: LexValue.Typ = NULL; break;
|
||||||
case TokenIntegerConstant: LexValue.Typ = &IntType; break;
|
case TokenIntegerConstant: LexValue.Typ = &IntType; break;
|
||||||
case TokenCharacterConstant: LexValue.Typ = &CharType; break;
|
case TokenCharacterConstant: LexValue.Typ = &CharType; break;
|
||||||
|
|
4
parse.c
4
parse.c
|
@ -423,11 +423,7 @@ enum ParseResult ParseStatement(struct ParseState *Parser)
|
||||||
if (LexGetToken(Parser, &LexerValue, TRUE) != TokenStringConstant)
|
if (LexGetToken(Parser, &LexerValue, TRUE) != TokenStringConstant)
|
||||||
ProgramFail(Parser, "\"filename.h\" expected");
|
ProgramFail(Parser, "\"filename.h\" expected");
|
||||||
|
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
PlatformScanFile(LexerValue->Val->Pointer.Segment->Val->Array.Data);
|
|
||||||
#else
|
|
||||||
PlatformScanFile((char *)LexerValue->Val->NativePointer);
|
PlatformScanFile((char *)LexerValue->Val->NativePointer);
|
||||||
#endif
|
|
||||||
CheckTrailingSemicolon = FALSE;
|
CheckTrailingSemicolon = FALSE;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
23
picoc.h
23
picoc.h
|
@ -36,13 +36,8 @@
|
||||||
#define FP_VAL(v) 0
|
#define FP_VAL(v) 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NATIVE_POINTERS
|
|
||||||
#define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0)
|
#define IS_POINTER_COERCIBLE(v, ap) ((ap) ? ((v)->Typ->Base == TypePointer) : 0)
|
||||||
#define POINTER_COERCE(v) ((int)(v)->Val->NativePointer)
|
#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_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))
|
#define IS_NUMERIC_COERCIBLE(v) (IS_INTEGER_NUMERIC(v) || IS_FP(v))
|
||||||
|
@ -166,20 +161,9 @@ struct FuncDef
|
||||||
/* values */
|
/* values */
|
||||||
struct ArrayValue
|
struct ArrayValue
|
||||||
{
|
{
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
unsigned int Size; /* the number of elements in the array */
|
|
||||||
#endif
|
|
||||||
void *Data; /* pointer to the array data */
|
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
|
union AnyValue
|
||||||
{
|
{
|
||||||
char Character;
|
char Character;
|
||||||
|
@ -198,11 +182,7 @@ union AnyValue
|
||||||
double FP;
|
double FP;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
struct PointerValue Pointer; /* safe pointers */
|
|
||||||
#else
|
|
||||||
void *NativePointer; /* unsafe native pointers */
|
void *NativePointer; /* unsafe native pointers */
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Value
|
struct Value
|
||||||
|
@ -277,9 +257,6 @@ union OutputStreamInfo
|
||||||
{
|
{
|
||||||
struct ParseState *Parser;
|
struct ParseState *Parser;
|
||||||
char *WritePos;
|
char *WritePos;
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
char *MaxPos;
|
|
||||||
#endif
|
|
||||||
} Str;
|
} Str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
20
type.c
20
type.c
|
@ -52,11 +52,7 @@ struct ValueType *TypeGetMatching(struct ParseState *Parser, struct ValueType *P
|
||||||
|
|
||||||
switch (Base)
|
switch (Base)
|
||||||
{
|
{
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
case TypePointer: Sizeof = sizeof(struct PointerValue); break;
|
|
||||||
#else
|
|
||||||
case TypePointer: Sizeof = sizeof(void *); break;
|
case TypePointer: Sizeof = sizeof(void *); break;
|
||||||
#endif
|
|
||||||
case TypeArray: Sizeof = sizeof(struct ArrayValue) + ArraySize * ParentType->Sizeof; break;
|
case TypeArray: Sizeof = sizeof(struct ArrayValue) + ArraySize * ParentType->Sizeof; break;
|
||||||
case TypeEnum: Sizeof = sizeof(int); break;
|
case TypeEnum: Sizeof = sizeof(int); break;
|
||||||
default: Sizeof = 0; break; /* structs and unions will get bigger when we add members to them */
|
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;
|
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 */
|
/* memory used by a variable given its type and array size */
|
||||||
int TypeSize(struct ValueType *Typ, int ArraySize, int Compact)
|
int TypeSize(struct ValueType *Typ, int ArraySize, int Compact)
|
||||||
{
|
{
|
||||||
|
@ -151,13 +136,8 @@ void TypeInit()
|
||||||
TypeAddBaseType(&TypeType, Type_Type, sizeof(struct ValueType *));
|
TypeAddBaseType(&TypeType, Type_Type, sizeof(struct ValueType *));
|
||||||
#endif
|
#endif
|
||||||
CharArrayType = TypeAdd(NULL, &CharType, TypeArray, 0, StrEmpty, sizeof(char));
|
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 *));
|
CharPtrType = TypeAdd(NULL, &CharType, TypePointer, 0, StrEmpty, sizeof(void *));
|
||||||
VoidPtrType = TypeAdd(NULL, &VoidType, TypePointer, 0, StrEmpty, sizeof(void *));
|
VoidPtrType = TypeAdd(NULL, &VoidType, TypePointer, 0, StrEmpty, sizeof(void *));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* deallocate heap-allocated types */
|
/* deallocate heap-allocated types */
|
||||||
|
|
45
variable.c
45
variable.c
|
@ -106,12 +106,7 @@ struct Value *VariableAllocValueFromType(struct ParseState *Parser, struct Value
|
||||||
assert(Size > 0 || Typ == &VoidType);
|
assert(Size > 0 || Typ == &VoidType);
|
||||||
NewValue->Typ = Typ;
|
NewValue->Typ = Typ;
|
||||||
if (Typ->Base == TypeArray)
|
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));
|
NewValue->Val->Array.Data = (void *)((char *)NewValue->Val + sizeof(struct ArrayValue));
|
||||||
}
|
|
||||||
|
|
||||||
return NewValue;
|
return NewValue;
|
||||||
}
|
}
|
||||||
|
@ -197,13 +192,7 @@ void VariableDefinePlatformVar(struct ParseState *Parser, char *Ident, struct Va
|
||||||
if (Typ->Base != TypeArray)
|
if (Typ->Base != TypeArray)
|
||||||
SomeValue->Val = FromValue;
|
SomeValue->Val = FromValue;
|
||||||
else
|
else
|
||||||
{
|
|
||||||
/* define an array */
|
|
||||||
#ifndef NATIVE_POINTERS
|
|
||||||
SomeValue->Val->Array.Size = Typ->ArraySize;
|
|
||||||
#endif
|
|
||||||
SomeValue->Val->Array.Data = FromValue;
|
SomeValue->Val->Array.Data = FromValue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, TableStrRegister(Ident), SomeValue))
|
if (!TableSet((TopStackFrame == NULL) ? &GlobalTable : &TopStackFrame->LocalTable, TableStrRegister(Ident), SomeValue))
|
||||||
ProgramFail(Parser, "'%s' is already defined", Ident);
|
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 */
|
/* 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)
|
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)
|
if (DerefVal != NULL)
|
||||||
*DerefVal = NULL;
|
*DerefVal = NULL;
|
||||||
|
|
||||||
|
@ -328,5 +285,5 @@ void *VariableDereferencePointer(struct ParseState *Parser, struct Value *Pointe
|
||||||
*DerefIsLValue = TRUE;
|
*DerefIsLValue = TRUE;
|
||||||
|
|
||||||
return PointerValue->Val->NativePointer;
|
return PointerValue->Val->NativePointer;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue