More work on Records and Cardinal

This commit is contained in:
mysticbbs 2012-03-19 00:41:10 -04:00
parent 2a88c22671
commit f6d87b72a9
2 changed files with 47 additions and 43 deletions

View File

@ -70,7 +70,7 @@ Type
Procedure SetNumber (VN: Word; R: Real; Var A: TArrayInfo); Procedure SetNumber (VN: Word; R: Real; Var A: TArrayInfo);
Procedure SetVariable (VarNum: Word); Procedure SetVariable (VarNum: Word);
Function DefineVariable : LongInt; Function DefineVariable (DataStart: Pointer; RecSize: Word) : LongInt;
Procedure DefineProcedure; Procedure DefineProcedure;
Procedure DefineRecord; Procedure DefineRecord;
@ -919,7 +919,7 @@ Begin
End; End;
End; End;
Function TInterpEngine.DefineVariable : LongInt; Function TInterpEngine.DefineVariable (DataStart: Pointer; RecSize: Word) : LongInt;
Var Var
VarType : TIdentTypes; VarType : TIdentTypes;
NumVars : Word; NumVars : Word;
@ -975,20 +975,34 @@ Begin
vType := VarType; vType := VarType;
NumParams := 0; NumParams := 0;
ProcPos := 0; ProcPos := 0;
If VarType = iString Then
VarSize := StrSize
Else
VarSize := GetVarSize(VarType);
Kill := True;
ArrPos := ArrayPos; ArrPos := ArrayPos;
ArrDim := ArrayData; ArrDim := ArrayData;
Case VarType of
iString : Begin
VarSize := StrSize;
DataSize := GetDataSize(CurVarNum); DataSize := GetDataSize(CurVarNum);
End;
iRecord : Begin
VarSize := RecSize;
DataSize := RecSize;
End;
Else
VarSize := GetVarSize(VarType);
DataSize := GetDataSize(CurVarNum);
End;
Result := DataSize; Result := DataSize;
If DataStart = NIL Then Begin
GetMem (Data, DataSize); GetMem (Data, DataSize);
FillChar (Data^, DataSize, 0); FillChar (Data^, DataSize, 0);
Kill := True;
End Else Begin
Data := DataStart;
Kill := False;
End;
End; End;
End; End;
@ -1206,8 +1220,8 @@ Begin
'l' : LongInt(Pointer(Data)^) := Param[Count].L; 'l' : LongInt(Pointer(Data)^) := Param[Count].L;
'r' : Real(Pointer(Data)^) := Param[Count].R; 'r' : Real(Pointer(Data)^) := Param[Count].R;
'o' : Boolean(Pointer(Data)^) := Param[Count].O; 'o' : Boolean(Pointer(Data)^) := Param[Count].O;
'x' : ; 'x' : // still need to redo all of this nonsense;
end; End;
Kill := True; Kill := True;
End; End;
@ -1972,9 +1986,6 @@ Begin
Ok := EvaluateBoolean; Ok := EvaluateBoolean;
//tbbscore(owner).systemlog('if statement');
//if ok then tbbscore(owner).systemlog('is true') else tbbscore(owner).systemlog('is false');
If Ok Then If Ok Then
Result := ExecuteBlock(CurVarNum, CurRecNum) Result := ExecuteBlock(CurVarNum, CurRecNum)
Else Else
@ -2012,22 +2023,15 @@ Begin
NextChar; // opVarDeclare NextChar; // opVarDeclare
DefineVariable; // Base var DefineVariable (NIL, RecSize); // Base record identifier
// get mem the dataptr for recsize RecSize := 1;
// THIS IS WHERE YOU LEFT OFF LAST TIME PICK IT UP HERE
// TURN DEBUGGING ON SO WE CATCH MEMORY LEAKS NOW
For Count := 1 to RecData[CurRecNum]^.NumFields Do Begin For Count := 1 to RecData[CurRecNum]^.NumFields Do Begin
NextChar; NextChar; // opVarDeclare
Inc (RecSize, DefineVariable); // create myrecvar.element ID Inc (RecSize, DefineVariable(@TStack(VarData[RecData[CurRecNum]^.RecStart - 1]^.Data^)[RecSize], 0));
// DefineVariable should have a RecAllocate that is NIL UNLESS
// it is a Record element. In that case a Pointer to DATAPTR[OFFSET]
// is passed and no getmem is done
End; End;
// session.io.outfull('Record vars: ' + strI2S(RecData[CurRecNum]^.NumFields) + ' size: ' + strI2S(RecSize));
End; End;
Function TInterpEngine.ExecuteBlock (StartVar, StartRec: Word) : Byte; Function TInterpEngine.ExecuteBlock (StartVar, StartRec: Word) : Byte;
@ -2059,7 +2063,7 @@ Begin
Self.ExecuteBlock(CurVarNum, CurRecNum); Self.ExecuteBlock(CurVarNum, CurRecNum);
End; End;
{1} opBlockClose : Break; {1} opBlockClose : Break;
{2} opVarDeclare : DefineVariable; {2} opVarDeclare : DefineVariable (NIL, 0);
{12} opSetVar : Begin {12} opSetVar : Begin
NextWord; NextWord;
SetVariable(FindVariable(W)); SetVariable(FindVariable(W));
@ -2069,6 +2073,7 @@ Begin
{21} opFor : StatementForLoop; {21} opFor : StatementForLoop;
{34} opIf : Begin {34} opIf : Begin
Result := StatementIfThenElse; Result := StatementIfThenElse;
If Result > 0 Then Begin If Result > 0 Then Begin
MoveToPos(BlockStart + BlockSize); MoveToPos(BlockStart + BlockSize);
Break; Break;
@ -2083,6 +2088,7 @@ Begin
{49} opHalt : Done := True; {49} opHalt : Done := True;
{50} opCase : Begin {50} opCase : Begin
Result := StatementCase; Result := StatementCase;
If Result > 0 Then Begin If Result > 0 Then Begin
MoveToPos(BlockStart + BlockSize); MoveToPos(BlockStart + BlockSize);
Break; Break;
@ -2119,6 +2125,13 @@ Begin
End; End;
Until (ErrNum <> 0) or Done or DataFile^.EOF; Until (ErrNum <> 0) or Done or DataFile^.EOF;
{$IFDEF LOGGING}
Session.SystemLog('[' + strI2S(Depth) + '] ExecBlock KILL REC: ' + strI2S(CurRecNum) + ' to ' + strI2S(StartRec + 1));
{$ENDIF}
For Count := CurRecNum DownTo StartRec + 1 Do
Dispose(RecData[Count]);
{$IFDEF LOGGING} {$IFDEF LOGGING}
Session.SystemLog('[' + strI2S(Depth) + '] ExecBlock KILL VAR: ' + strI2S(CurVarNum) + ' to ' + strI2S(StartVar + 1)); Session.SystemLog('[' + strI2S(Depth) + '] ExecBlock KILL VAR: ' + strI2S(CurVarNum) + ' to ' + strI2S(StartVar + 1));
{$ENDIF} {$ENDIF}
@ -2143,15 +2156,6 @@ Begin
Dispose (VarData[Count]); Dispose (VarData[Count]);
End; End;
{$IFDEF LOGGING}
Session.SystemLog('[' + strI2S(Depth) + '] ExecBlock KILL REC: ' + strI2S(CurRecNum) + ' to ' + strI2S(StartRec + 1));
{$ENDIF}
For Count := CurRecNum DownTo StartRec + 1 Do
Dispose(RecData[Count]);
// dispose record data block? or just calc it whenever there is an
// assignment or filewrite, etc?
CurVarNum := StartVar; CurVarNum := StartVar;
CurRecNum := StartRec; CurRecNum := StartRec;

View File

@ -225,7 +225,7 @@ Const
{$ENDIF} {$ENDIF}
vNums : Set of TIdentTypes = [iByte, iShort, iWord, iInteger, iLongInt, iReal]; vNums : Set of TIdentTypes = [iByte, iShort, iWord, iInteger, iLongInt, iCardinal, iReal];
vStrings : Set of TIdentTypes = [iChar, iString]; vStrings : Set of TIdentTypes = [iChar, iString];
Type Type