00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 #include <stdlib.h>
00153 #include <stdio.h>
00154 #include <string.h>
00155 #include <ctype.h>
00156 #include <math.h>
00157 #include <limits.h>
00158
00159 #include "basext.h"
00160 #include "sym.h"
00161 #include "errcodes.h"
00162 #include "report.h"
00163 #include "lexer.h"
00164 #include "expression.h"
00165 #include "builder.h"
00166 #include "memory.h"
00167 #include "syntax.h"
00168 #include "execute.h"
00169 #include "myalloc.h"
00170 #include "modumana.h"
00171
00172 #define REPORT(x) if( pEo->report )pEo->report(pEo->reportptr,"",0,x,REPORT_ERROR,NULL,NULL,&(pEo->fErrorFlags))
00173
00174 #if BCC32
00175 #define pow10 _mypow10
00176 #endif
00177
00178 static double pow10(double a)
00179 {
00180 int j,i;
00181 double pro,k;
00182
00183 for( (i= a<0.0) && (a = -a) , j=(int)a , pro=1.0 , k=10; j ;
00184 j%2 && (pro *=k) , j /= 2 , k *= k )
00185 continue;
00186 i && (pro=1.0/pro);
00187 return pro;
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 long execute_GetCommandByName(pExecuteObject pEo,
00235 char *pszCommandName,
00236 long lCodeHint
00237 ){
00238
00239
00240 long DownCounter,UpCounter;
00241
00242 if( lCodeHint < START_CMD )lCodeHint = START_CMD;
00243 if( lCodeHint >= END_EXEC )lCodeHint = END_EXEC-1;
00244
00245 DownCounter = UpCounter = lCodeHint;
00246 while( DownCounter || UpCounter ){
00247 if( DownCounter && !strcmp(pszCommandName,pEo->CSymbolList[DownCounter-START_CMD]) )return DownCounter;
00248 if( UpCounter && !strcmp(pszCommandName,pEo->CSymbolList[UpCounter-START_CMD]) )return UpCounter;
00249 UpCounter ++;
00250 if( UpCounter == END_EXEC )UpCounter = 0;
00251 DownCounter --;
00252 if( DownCounter < START_CMD )DownCounter = 0;
00253 }
00254 return 0;
00255 }
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 int execute_CopyCommandTable(pExecuteObject pEo
00280 ){
00281
00282
00283 CommandFunctionType *p;
00284
00285
00286 if( pEo->fThreadedCommandTable )return COMMAND_ERROR_SUCCESS;
00287
00288 p = ALLOC( sizeof( CommandFunctionType ) * (END_EXEC-START_CMD) );
00289 if( p == NULL )return COMMAND_ERROR_MEMORY_LOW;
00290 memcpy(p, pEo->pCommandFunction, sizeof( CommandFunctionType ) * (END_EXEC-START_CMD) );
00291 pEo->pCommandFunction = p;
00292 pEo->fThreadedCommandTable = 1;
00293 return COMMAND_ERROR_SUCCESS;
00294 }
00295
00296
00297
00298
00299
00300 int execute_InitStructure(pExecuteObject pEo,
00301 pBuildObject pBo
00302 ){
00303
00304
00305 long maxmem;
00306 int iError;
00307
00308 build_MagicCode(&(pEo->Ver));
00309 pEo->fpStdinFunction = NULL;
00310 pEo->fpStdouFunction = NULL;
00311 pEo->fpEnvirFunction = NULL;
00312 pEo->CmdLineArgument = NULL;
00313
00314 if( cft_GetEx(pEo->pConfig,"maxstep",NULL,NULL,
00315 &(pEo->GlobalStepLimit),NULL,NULL) )
00316 pEo->GlobalStepLimit = 0;
00317
00318 if( cft_GetEx(pEo->pConfig,"maxlocalstep",NULL,NULL,
00319 &(pEo->LocalStepLimit),NULL,NULL) )
00320 pEo->LocalStepLimit = 0;
00321
00322 if( cft_GetEx(pEo->pConfig,"maxlevel",NULL,NULL,
00323 &(pEo->FunctionLevelLimit),NULL,NULL) )
00324 pEo->FunctionLevelLimit = 0;
00325
00326 pEo->CommandArray = pBo->CommandArray ;
00327 pEo->StartNode = pBo->StartNode;
00328 pEo->CommandArraySize = pBo->NodeCounter;
00329 pEo->StringTable = pBo->StringTable;
00330 pEo->cbStringTable = pBo->cbStringTable;
00331 pEo->cGlobalVariables = pBo->cGlobalVariables;
00332 pEo->lGlobalStepCounter = 0L;
00333 pEo->LastError = 0;
00334
00335
00336
00337
00338 pEo->pCommandFunction = CommandFunction;
00339 pEo->CSymbolList = COMMANDSYMBOLS;
00340 pEo->fThreadedCommandTable = 0;
00341 pEo->pFunctionResult = NULL;
00342 pEo->pGlobalMortalList = NULL;
00343 pEo->pST = NULL;
00344 pEo->pSTI = NULL;
00345 pEo->pEPo = NULL;
00346 pEo->modules = NULL;
00347
00348 pEo->pMemorySegment = alloc_InitSegment(pEo->memory_allocating_function,pEo->memory_releasing_function);
00349
00350 if( pEo->pMemorySegment == NULL )return COMMAND_ERROR_MEMORY_LOW;
00351
00352
00353 pEo->pMo = alloc_Alloc(sizeof(MemoryObject),pEo->pMemorySegment);
00354 if( pEo->pMo == NULL )return EXE_ERROR_MEMORY_LOW;
00355
00356 if( cft_GetEx(pEo->pConfig,"maxderef",NULL,NULL,
00357 &(pEo->pMo->maxderef),NULL,NULL) )
00358 pEo->pMo->maxderef = 1000;
00359 pEo->pMo->memory_allocating_function = pEo->memory_allocating_function;
00360 pEo->pMo->memory_releasing_function = pEo->memory_releasing_function;
00361 pEo->cbStringTable = 0L;
00362 pEo->OptionsTable = NULL;
00363 if( iError = memory_InitStructure(pEo->pMo) )return iError;
00364
00365 if( cft_GetEx(pEo->pConfig,"maxmem",NULL,NULL,
00366 &maxmem,NULL,NULL) == CFT_ERROR_SUCCESS )
00367 alloc_SegmentLimit(pEo->pMo->pMemorySegment,maxmem);
00368
00369
00370 memory_RegisterTypes(pEo->pMo);
00371 if( hook_Init(pEo, &(pEo->pHookers)) )return 1;
00372 if( modu_Preload(pEo) )return 1;
00373
00374 pEo->GlobalVariables = NULL;
00375 pEo->InstructionParameter = NULL;
00376
00377 return EXE_ERROR_SUCCESS;
00378 }
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388 int execute_ReInitStructure(pExecuteObject pEo,
00389 pBuildObject pBo
00390 ){
00391
00392
00393
00394 pEo->lGlobalStepCounter = 0L;
00395 pEo->pFunctionResult = NULL;
00396
00397 pEo->pST = NULL;
00398 pEo->pSTI = NULL;
00399 pEo->pEPo = NULL;
00400 pEo->modules = NULL;
00401 if( modu_Preload(pEo) )return 1;
00402
00403 return 0;
00404 }
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415 void execute_Execute_r(pExecuteObject pEo,
00416 int *piErrorCode
00417 ){
00418
00419
00420 CommandFunctionType ThisCommandFunction;
00421 unsigned long CommandOpCode;
00422 unsigned long pc,npc;
00423
00424 pEo->fStop = 0;
00425 pEo->lStepCounter = 0L;
00426 pEo->fErrorGoto = ONERROR_NOTHING;
00427 while( pEo->ProgramCounter ){
00428 pEo->fNextPC = 0;
00429 if( pEo->ProgramCounter > pEo->CommandArraySize ){
00430 *piErrorCode = EXE_ERROR_INVALID_PC;
00431 return;
00432 }
00433
00434 if( pEo->CommandArray[pEo->ProgramCounter-1].OpCode != eNTYPE_LST ){
00435 *piErrorCode = EXE_ERROR_INVALID_NODE;
00436 return;
00437 }
00438
00439 pc = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.actualm;
00440 if( pc > pEo->CommandArraySize ){
00441 *piErrorCode = EXE_ERROR_INVALID_PC1;
00442 return;
00443 }
00444 if( pc ){
00445 CommandOpCode = pEo->CommandArray[pc-1].OpCode;
00446 if( CommandOpCode < START_CMD || CommandOpCode > END_CMD ){
00447 *piErrorCode = EXE_ERROR_INVALID_OPCODE;
00448 return;
00449 }
00450 }
00451 npc = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.rest ;
00452
00453 if( pc ){
00454 ThisCommandFunction = pEo->pCommandFunction[CommandOpCode - START_CMD];
00455 if( ThisCommandFunction == NULL ){
00456 *piErrorCode = EXE_ERROR_NOT_IMPLEMENTED;
00457 return;
00458 }
00459 }
00460 pEo->ErrorCode = EXE_ERROR_SUCCESS;
00461 if( pEo->pHookers->HOOK_ExecBefore && (*piErrorCode = pEo->pHookers->HOOK_ExecBefore(pEo)) )return;
00462 if( pc )
00463 ThisCommandFunction(pEo);
00464 if( pEo->pHookers->HOOK_ExecAfter && (*piErrorCode = pEo->pHookers->HOOK_ExecAfter(pEo)) )return;
00465 pEo->fWeAreCallingFuction = 0;
00466 pEo->lStepCounter++;
00467 if( pEo->LocalStepLimit && pEo->lStepCounter > (unsigned)pEo->LocalStepLimit ){
00468 *piErrorCode = EXE_ERROR_TOO_LONG_RUN;
00469 return;
00470 }
00471 pEo->lGlobalStepCounter++;
00472 if( pEo->GlobalStepLimit && pEo->lGlobalStepCounter > (unsigned)pEo->GlobalStepLimit ){
00473 *piErrorCode = EXE_ERROR_TOO_LONG_RUN;
00474 return;
00475 }
00476
00477
00478 if( pEo->ErrorCode ){
00479 pEo->LastError = pEo->ErrorCode;
00480 if( pEo->fErrorGoto == ONERROR_RESUMENEXT ){
00481 pEo->fErrorGoto = ONERROR_NOTHING;
00482 pEo->ErrorResume = 0;
00483 pEo->LastError = 0;
00484 pEo->ErrorGoto = 0;
00485 }else
00486 if( pEo->fErrorGoto == ONERROR_RESUME ){
00487 if( ! pEo->ErrorGoto ){
00488 *piErrorCode = pEo->ErrorCode;
00489 return;
00490 }
00491 pEo->ErrorResume = 0;
00492 pEo->LastError = 0;
00493 pEo->fErrorGoto = ONERROR_NOTHING;
00494 pEo->ErrorGoto = 0;
00495 pEo->fNextPC = 1;
00496 pEo->NextProgramCounter = pEo->ErrorGoto;
00497 }else
00498 if( pEo->fErrorGoto == ONERROR_GOTO ){
00499 if( ! pEo->ErrorGoto ){
00500 *piErrorCode = pEo->ErrorCode;
00501 return;
00502 }
00503 pEo->ErrorResume = pEo->ProgramCounter;
00504 pEo->fNextPC = 1;
00505 pEo->NextProgramCounter = pEo->ErrorGoto;
00506 pEo->ErrorGoto = 0;
00507 }else{
00508
00509 *piErrorCode = pEo->ErrorCode;
00510 return;
00511 }
00512 }
00513
00514 if( pEo->fStop ){
00515 if( pEo->fStop == fStopRETURN )pEo->fStop = 0;
00516 *piErrorCode = EXE_ERROR_SUCCESS;
00517 return;
00518 }
00519 if( pEo->fNextPC )
00520 pEo->ProgramCounter = pEo->NextProgramCounter;
00521 else
00522 pEo->ProgramCounter = npc;
00523 }
00524 *piErrorCode = EXE_ERROR_SUCCESS;
00525 return;
00526 }
00527
00528
00529
00530
00531
00532 void execute_InitExecute(pExecuteObject pEo,
00533 int *piErrorCode
00534 ){
00535
00536
00537 #ifdef NULL_IS_NOT_ZERO
00538 unsigned long i;
00539 #endif
00540 *piErrorCode = 0;
00541 pEo->ProgramCounter = pEo->StartNode;
00542
00543 pEo->LocalVariables = NULL;
00544 pEo->pszModuleError = NULL;
00545 pEo->cLocalVariables = 0;
00546 pEo->ErrorGoto = 0;
00547
00548 if( pEo->GlobalVariables == NULL ){
00549 pEo->GlobalVariables = memory_NewArray(pEo->pMo,1,pEo->cGlobalVariables);
00550 if( pEo->GlobalVariables == NULL ){
00551 *piErrorCode = EXE_ERROR_MEMORY_LOW;
00552 return;
00553 }
00554 }
00555 pEo->fWeAreCallingFuction = 0;
00556 pEo->lFunctionLevel = 0;
00557 if( pEo->InstructionParameter == NULL ){
00558 pEo->InstructionParameter = alloc_Alloc(pEo->CommandArraySize*sizeof(void *),pEo->pMemorySegment);
00559 if( pEo->InstructionParameter == NULL ){
00560 *piErrorCode = EXE_ERROR_MEMORY_LOW;
00561 return;
00562 }
00563 memset(pEo->InstructionParameter,0,pEo->CommandArraySize*sizeof(void *));
00564 }
00565 memset(pEo->CommandParameter,0,NUM_CMD*sizeof(void *));
00566 memset(pEo->Finaliser,0,NUM_CMD*sizeof(void *));
00567 }
00568
00569
00570
00571
00572
00573 void execute_FinishExecute(pExecuteObject pEo,
00574 int *piErrorCode
00575 ){
00576
00577
00578 unsigned long i;
00579
00580 for( i=0 ; i < NUM_CMD ; i++ ){
00581 if( pEo->Finaliser[i] )pEo->Finaliser[i](pEo);
00582 }
00583 modu_UnloadAllModules(pEo);
00584 }
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600 void execute_Execute(pExecuteObject pEo,
00601 int *piErrorCode
00602 ){
00603
00604
00605 execute_InitExecute(pEo,piErrorCode);
00606 if( *piErrorCode )return;
00607
00608 execute_Execute_r(pEo,piErrorCode);
00609
00610 if( *piErrorCode ){
00611 REPORT(*piErrorCode);
00612 }
00613
00614 execute_FinishExecute(pEo,piErrorCode);
00615 }
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640 void execute_ExecuteFunction(pExecuteObject pEo,
00641 unsigned long StartNode,
00642 long cArgs,
00643 pFixSizeMemoryObject *pArgs,
00644 pFixSizeMemoryObject *pResult,
00645 int *piErrorCode
00646 ){
00647
00648
00649 unsigned long nItem,pc;
00650 long i;
00651 long CommandOpCode;
00652
00653 pEo->ProgramCounter = StartNode;
00654 pEo->pFunctionResult = NULL;
00655 pEo->lStepCounter = 0;
00656 pEo->fWeAreCallingFuction = 1;
00657 pEo->ErrorGoto = 0;
00658 pEo->ErrorResume = 0;
00659 pEo->fErrorGoto = ONERROR_NOTHING;
00660 pEo->LocalVariables = NULL;
00661 if( pResult )*pResult = NULL;
00662
00663 if( pEo->CommandArray[pEo->ProgramCounter-1].OpCode != eNTYPE_LST ){
00664 *piErrorCode = EXE_ERROR_INVALID_NODE;
00665 return;
00666 }
00667
00668 pc = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.actualm;
00669 if( pc > pEo->CommandArraySize ){
00670 *piErrorCode = EXE_ERROR_INVALID_PC1;
00671 return;
00672 }
00673 if( pc ){
00674 CommandOpCode = pEo->CommandArray[pc-1].OpCode;
00675 if( CommandOpCode < START_CMD || CommandOpCode > END_CMD ){
00676 *piErrorCode = EXE_ERROR_INVALID_OPCODE;
00677 return;
00678 }
00679 }
00680 if( CommandOpCode != CMD_FUNCTION &&
00681 CommandOpCode != CMD_FUNCTIONARG &&
00682 CommandOpCode != CMD_SUB &&
00683 CommandOpCode != CMD_SUBARG
00684 ){
00685 *piErrorCode = COMMAND_ERROR_INVALID_CODE;
00686 return;
00687 }
00688 nItem = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.actualm ;
00689 pEo->cLocalVariables = pEo->CommandArray[nItem-1].Parameter.CommandArgument.Argument.lLongValue;
00690
00691 if( pEo->cLocalVariables ){
00692 pEo->LocalVariables = memory_NewArray(pEo->pMo,1,pEo->cLocalVariables);
00693 if( pEo->LocalVariables == NULL ){
00694 pEo->fStop = fStopSTOP;
00695 return;
00696 }
00697 }
00698
00699
00700 if( cArgs > pEo->cLocalVariables )cArgs = pEo->cLocalVariables;
00701 for( i=0 ; i < cArgs ; i++ ){
00702 pEo->LocalVariables->Value.aValue[i] = memory_NewRef(pEo->pMo);
00703 memory_SetRef(pEo->pMo,pEo->LocalVariables->Value.aValue+i,pArgs+i);
00704 }
00705
00706
00707 pEo->ProgramCounter = pEo->CommandArray[pEo->ProgramCounter-1].Parameter.NodeList.rest ;
00708
00709 execute_Execute_r(pEo,piErrorCode);
00710
00711
00712 if( pEo->LocalVariables )
00713 memory_ReleaseVariable(pEo->pMo,pEo->LocalVariables);
00714
00715
00716 if( pResult )
00717 *pResult = pEo->pFunctionResult;
00718 else
00719 memory_ReleaseVariable(pEo->pMo,pEo->pFunctionResult);
00720 return;
00721 }
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746 pFixSizeMemoryObject execute_Evaluate(pExecuteObject pEo,
00747 unsigned long lExpressionRootNode,
00748 pMortalList pMyMortal,
00749 int *piErrorCode,
00750 int iArrayAccepted
00751 ){
00752
00753
00754 pFixSizeMemoryObject pVar;
00755 char *s;
00756 unsigned long slen,refcount;
00757 unsigned long SaveProgramCounter,SaveStepCounter;
00758 unsigned long SavefErrorGoto,SaveErrorGoto,SaveErrorResume;
00759 pFixSizeMemoryObject SaveLocalVariablesPointer;
00760 pFixSizeMemoryObject SaveFunctionResultPointer;
00761 pFixSizeMemoryObject ThisFunctionResultPointer;
00762 long OpCode;
00763 CommandFunctionType ThisCommandFunction;
00764 pMortalList pSaveMortalList;
00765
00766 if( ! lExpressionRootNode ){
00767 *piErrorCode = EXE_ERROR_INTERNAL;
00768 return NULL;
00769 }
00770 if( pMyMortal == NULL ){
00771 *piErrorCode = EXE_ERROR_INTERNAL;
00772 return NULL;
00773 }
00774 *piErrorCode = EXE_ERROR_SUCCESS;
00775 #define ASSERT_NON_NULL(x) if( (x) == NULL ){ *piErrorCode = EXE_ERROR_MEMORY_LOW; return NULL; }
00776 switch( OpCode = pEo->CommandArray[lExpressionRootNode-1].OpCode ){
00777 case eNTYPE_ARR:
00778 pVar = execute_EvaluateArray(pEo,lExpressionRootNode,pMyMortal,piErrorCode);
00779 while( pVar && ( ((!iArrayAccepted) && pVar->vType == VTYPE_ARRAY) || pVar->vType == VTYPE_REF) ){
00780
00781 while( pVar && (!iArrayAccepted) && pVar->vType == VTYPE_ARRAY )
00782 pVar = pVar->Value.aValue[0];
00783 while( pVar && pVar->vType == VTYPE_REF )
00784 pVar = *(pVar->Value.aValue);
00785 }
00786 return memory_SelfOrRealUndef(pVar);
00787 case eNTYPE_SAR:
00788 pVar = execute_EvaluateSarray(pEo,lExpressionRootNode,pMyMortal,piErrorCode);
00789 while( pVar && ( ((!iArrayAccepted) && pVar->vType == VTYPE_ARRAY) || pVar->vType == VTYPE_REF) ){
00790
00791 while( pVar && (!iArrayAccepted) && pVar->vType == VTYPE_ARRAY )
00792 pVar = pVar->Value.aValue[0];
00793 while( pVar && pVar->vType == VTYPE_REF )
00794 pVar = *(pVar->Value.aValue);
00795 }
00796 return memory_SelfOrRealUndef(pVar);
00797 case eNTYPE_FUN:
00798 if( pEo->FunctionLevelLimit && pEo->lFunctionLevel > pEo->FunctionLevelLimit ){
00799 *piErrorCode = EXE_ERROR_TOO_DEEP_CALL;
00800 return NULL;
00801 }
00802 SaveLocalVariablesPointer = pEo->LocalVariables;
00803 SaveProgramCounter = pEo->ProgramCounter;
00804 pEo->ProgramCounter = pEo->CommandArray[lExpressionRootNode-1].Parameter.UserFunction.NodeId;
00805 if( pEo->ProgramCounter == 0 ){
00806 *piErrorCode = EXE_ERROR_USERFUN_UNDEFINED;
00807 return NULL;
00808 }
00809 pEo->FunctionArgumentsNode = pEo->CommandArray[lExpressionRootNode-1].Parameter.UserFunction.Argument;
00810 SaveFunctionResultPointer = pEo->pFunctionResult;
00811 pEo->pFunctionResult = NULL;
00812 SaveStepCounter = pEo->lStepCounter;
00813 pEo->lStepCounter = 0;
00814 pEo->fWeAreCallingFuction = 1;
00815 SaveErrorGoto = pEo->ErrorGoto;
00816 pEo->ErrorGoto = 0;
00817 SaveErrorResume = pEo->ErrorResume;
00818 pEo->ErrorResume = 0;
00819 SavefErrorGoto = pEo->fErrorGoto;
00820 pEo->fErrorGoto = ONERROR_NOTHING;
00821 if( pEo->pHookers->HOOK_ExecCall && (*piErrorCode = pEo->pHookers->HOOK_ExecCall(pEo)) )return NULL;
00822
00823
00824 execute_Execute_r(pEo,piErrorCode);
00825 if( pEo->pHookers->HOOK_ExecReturn ){
00826
00827
00828
00829 if( *piErrorCode )
00830 pEo->pHookers->HOOK_ExecReturn(pEo);
00831 else
00832 *piErrorCode = pEo->pHookers->HOOK_ExecReturn(pEo);
00833 }
00834 pEo->lStepCounter = SaveStepCounter;
00835 if( pEo->LocalVariables )
00836 memory_ReleaseVariable(pEo->pMo,pEo->LocalVariables);
00837 pEo->ProgramCounter = SaveProgramCounter;
00838 pEo->LocalVariables = SaveLocalVariablesPointer;
00839 ThisFunctionResultPointer = pEo->pFunctionResult;
00840 pEo->pFunctionResult = SaveFunctionResultPointer;
00841 while( ThisFunctionResultPointer &&
00842 (!iArrayAccepted) &&
00843 ThisFunctionResultPointer->vType == VTYPE_ARRAY ){
00844 ThisFunctionResultPointer = ThisFunctionResultPointer->Value.aValue[0];
00845 }
00846
00847
00848
00849 if( ThisFunctionResultPointer &&
00850 ThisFunctionResultPointer->vType != VTYPE_ARRAY &&
00851 ! IsMortal(ThisFunctionResultPointer) )
00852 memory_Mortalize(ThisFunctionResultPointer,pMyMortal);
00853
00854 pEo->ErrorGoto = SaveErrorGoto;
00855 pEo->fErrorGoto = SavefErrorGoto;
00856 pEo->ErrorResume = SaveErrorResume;
00857 if( *piErrorCode )return NULL;
00858 return memory_SelfOrRealUndef(ThisFunctionResultPointer);
00859 case eNTYPE_LVR:
00860 if( pEo->LocalVariables == NULL ){
00861 *piErrorCode = EXE_ERROR_NO_LOCAL;
00862 return NULL;
00863 }
00864 pVar = pEo->LocalVariables->Value.aValue[pEo->CommandArray[lExpressionRootNode-1].Parameter.Variable.Serial-1];
00865 while( pVar && ( ((!iArrayAccepted) && pVar->vType == VTYPE_ARRAY) || pVar->vType == VTYPE_REF) ){
00866
00867 while( pVar && (!iArrayAccepted) && pVar->vType == VTYPE_ARRAY )
00868 pVar = pVar->Value.aValue[0];
00869 refcount = 0;
00870 while( pVar && pVar->vType == VTYPE_REF ){
00871 pVar = *(pVar->Value.aValue);
00872 if( refcount++ > pEo->pMo->maxderef ){
00873 *piErrorCode = COMMAND_ERROR_CIRCULAR;
00874 return NULL;
00875 }
00876 }
00877 }
00878 return memory_SelfOrRealUndef(pVar);
00879 case eNTYPE_GVR:
00880 pVar = pEo->GlobalVariables->Value.aValue[pEo->CommandArray[lExpressionRootNode-1].Parameter.Variable.Serial-1];
00881 while( pVar && ( ((!iArrayAccepted) && pVar->vType == VTYPE_ARRAY) || pVar->vType == VTYPE_REF) ){
00882
00883 while( pVar && (!iArrayAccepted) && pVar->vType == VTYPE_ARRAY )
00884 pVar = pVar->Value.aValue[0];
00885 refcount = 0;
00886 while( pVar && pVar->vType == VTYPE_REF ){
00887 pVar = *(pVar->Value.aValue);
00888 if( refcount++ > pEo->pMo->maxderef ){
00889 *piErrorCode = COMMAND_ERROR_CIRCULAR;
00890 return NULL;
00891 }
00892 }
00893 }
00894 return memory_SelfOrRealUndef(pVar);
00895 case eNTYPE_DBL:
00896 if( pEo->InstructionParameter[lExpressionRootNode-1] == NULL ){
00897 pVar = pEo->InstructionParameter[lExpressionRootNode-1] = memory_NewDouble(pEo->pMo);
00898 ASSERT_NON_NULL(pVar);
00899 pVar->Value.dValue = pEo->CommandArray[lExpressionRootNode-1].Parameter.Constant.dValue;
00900 }else
00901 pVar = pEo->InstructionParameter[lExpressionRootNode-1];
00902 return memory_SelfOrRealUndef(pVar);
00903
00904 case eNTYPE_LNG:
00905 if( pEo->InstructionParameter[lExpressionRootNode-1] == NULL ){
00906 pVar = pEo->InstructionParameter[lExpressionRootNode-1] = memory_NewLong(pEo->pMo);
00907 ASSERT_NON_NULL(pVar);
00908 pVar->Value.lValue = pEo->CommandArray[lExpressionRootNode-1].Parameter.Constant.lValue;
00909 }else
00910 pVar = pEo->InstructionParameter[lExpressionRootNode-1];
00911 return memory_SelfOrRealUndef(pVar);
00912
00913 case eNTYPE_STR:
00914 s = pEo->StringTable+pEo->CommandArray[lExpressionRootNode-1].Parameter.Constant.sValue;
00915 memcpy(&slen, s-sizeof(long), sizeof(long));
00916 pVar = memory_NewMortalCString(pEo->pMo,slen,pMyMortal);
00917 ASSERT_NON_NULL(pVar);
00918 pVar->Value.pValue = s;
00919 return memory_SelfOrRealUndef(pVar);
00920
00921 case eNTYPE_LST:
00922 *piErrorCode = EXE_ERROR_INVALID_EXPRESSION_NODE;
00923 return NULL;
00924 case eNTYPE_CRG:
00925 *piErrorCode = EXE_ERROR_INVALID_EXPRESSION_NODE1;
00926 return NULL;
00927 default:
00928 ThisCommandFunction = pEo->pCommandFunction[OpCode - START_CMD];
00929 if( ThisCommandFunction == NULL ){
00930 *piErrorCode = EXE_ERROR_NOT_IMPLEMENTED;
00931 return NULL;
00932 }
00933 pEo->OperatorNode = lExpressionRootNode;
00934 pEo->pOpResult = NULL;
00935 pSaveMortalList = pEo->pGlobalMortalList;
00936 pEo->pGlobalMortalList = pMyMortal;
00937 ThisCommandFunction(pEo);
00938 pEo->pGlobalMortalList = pSaveMortalList;
00939 *piErrorCode = pEo->ErrorCode;
00940 return memory_SelfOrRealUndef(pEo->pOpResult);
00941 }
00942 *piErrorCode = EXE_ERROR_INTERNAL;
00943 return NULL;
00944 }
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956 pFixSizeMemoryObject *execute_LeftValue(pExecuteObject pEo,
00957 unsigned long lExpressionRootNode,
00958 pMortalList pMyMortal,
00959 int *piErrorCode,
00960 int iArrayAccepted
00961 ){
00962
00963
00964 pFixSizeMemoryObject *ppVar;
00965 long OpCode;
00966
00967 *piErrorCode = EXE_ERROR_SUCCESS;
00968
00969 switch( OpCode = pEo->CommandArray[lExpressionRootNode-1].OpCode ){
00970
00971 case eNTYPE_ARR:
00972 return execute_LeftValueArray(pEo,lExpressionRootNode,pMyMortal,piErrorCode);
00973
00974 case eNTYPE_SAR:
00975 return execute_LeftValueSarray(pEo,lExpressionRootNode,pMyMortal,piErrorCode);
00976
00977 case eNTYPE_LVR:
00978 if( pEo->LocalVariables == NULL ){
00979 *piErrorCode = EXE_ERROR_NO_LOCAL;
00980 return NULL;
00981 }
00982 ppVar = &(pEo->LocalVariables->Value.aValue[pEo->CommandArray[lExpressionRootNode-1].Parameter.Variable.Serial-1]);
00983
00984 while( (!iArrayAccepted) && *ppVar && (*ppVar)->vType == VTYPE_ARRAY )
00985 ppVar = &((*ppVar)->Value.aValue[0]);
00986 return ppVar;
00987
00988 case eNTYPE_GVR:
00989 ppVar = &(pEo->GlobalVariables->Value.aValue[pEo->CommandArray[lExpressionRootNode-1].Parameter.Variable.Serial-1]);
00990
00991 while( (!iArrayAccepted) && *ppVar && (*ppVar)->vType == VTYPE_ARRAY )
00992 ppVar = &((*ppVar)->Value.aValue[0]);
00993 return ppVar;
00994
00995 case eNTYPE_FUN:
00996 *piErrorCode = EXE_ERROR_INVALID_LVALNODE0;
00997 return NULL;
00998
00999 case eNTYPE_DBL:
01000 *piErrorCode = EXE_ERROR_INVALID_LVALNODE1;
01001 return NULL;
01002
01003 case eNTYPE_LNG:
01004 *piErrorCode = EXE_ERROR_INVALID_LVALNODE2;
01005 return NULL;
01006
01007 case eNTYPE_STR:
01008 *piErrorCode = EXE_ERROR_INVALID_LVALNODE3;
01009 return NULL;
01010
01011 case eNTYPE_LST:
01012 *piErrorCode = EXE_ERROR_INVALID_LVALNODE4;
01013 return NULL;
01014
01015 case eNTYPE_CRG:
01016 *piErrorCode = EXE_ERROR_INVALID_LVALNODE5;
01017 return NULL;
01018 default:
01019 *piErrorCode = EXE_ERROR_INVALID_LVALNODE6;
01020 return NULL;
01021 }
01022 *piErrorCode = EXE_ERROR_INTERNAL;
01023 return NULL;
01024 }
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039 pFixSizeMemoryObject execute_EvaluateArray(pExecuteObject pEo,
01040 unsigned long lExpressionRootNode,
01041 pMortalList pMyMortal,
01042 int *piErrorCode
01043 ){
01044
01045
01046
01047 return *execute_LeftValueArray(pEo,lExpressionRootNode,pMyMortal,piErrorCode);
01048 }
01049
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060
01061
01062
01063
01064
01065
01066
01067
01068
01069
01070
01071
01072
01073
01074
01075 pFixSizeMemoryObject execute_EvaluateSarray(pExecuteObject pEo,
01076 unsigned long lExpressionRootNode,
01077 pMortalList pMyMortal,
01078 int *piErrorCode
01079 ){
01080
01081
01082
01083 return *execute_LeftValueSarray(pEo,lExpressionRootNode,pMyMortal,piErrorCode);
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093 pFixSizeMemoryObject *execute_LeftValueArray(pExecuteObject pEo,
01094 unsigned long lExpressionRootNode,
01095 pMortalList pMyMortal,
01096 int *piErrorCode
01097 ){
01098
01099
01100
01101 long OpCode;
01102 long lIndex,lMinIndex,lMaxIndex;
01103 unsigned long nVariable, nIndex;
01104 unsigned long nHead;
01105 pFixSizeMemoryObject *ppVar,pVar;
01106 unsigned long __refcount_;
01107
01108 nHead = pEo->CommandArray[lExpressionRootNode-1].Parameter.Arguments.Argument;
01109 nVariable = pEo->CommandArray[nHead-1].Parameter.NodeList.actualm;
01110 OpCode = pEo->CommandArray[nVariable-1].OpCode;
01111
01112 nHead = pEo->CommandArray[nHead-1].Parameter.NodeList.rest;
01113
01114 switch( OpCode ){
01115 case eNTYPE_LVR:
01116 if( pEo->LocalVariables == NULL ){
01117 *piErrorCode = EXE_ERROR_NO_LOCAL;
01118 return NULL;
01119 }
01120 ppVar = &(pEo->LocalVariables->Value.aValue[pEo->CommandArray[nVariable-1].Parameter.Variable.Serial-1]);
01121 break;
01122 case eNTYPE_GVR:
01123 ppVar = &(pEo->GlobalVariables->Value.aValue[pEo->CommandArray[nVariable-1].Parameter.Variable.Serial-1]);
01124 break;
01125 case eNTYPE_ARR:
01126 ppVar = execute_LeftValueArray(pEo,nVariable,pMyMortal,piErrorCode);
01127 break;
01128 case eNTYPE_SAR:
01129 ppVar = execute_LeftValueSarray(pEo,nVariable,pMyMortal,piErrorCode);
01130 break;
01131 default:
01132
01133 *piErrorCode =EXE_ERROR_INTERNAL;
01134 return NULL;
01135 }
01136
01137
01138 __refcount_ = pEo->pMo->maxderef;
01139 while( *ppVar && (*ppVar)->vType == VTYPE_REF && __refcount_-- )
01140 ppVar = (*ppVar)->Value.aValue;
01141 if( *ppVar && (*ppVar)->vType == VTYPE_REF ){
01142 *piErrorCode = COMMAND_ERROR_CIRCULAR;
01143 return NULL;
01144 }
01145 while( nHead ){
01146 nIndex = pEo->CommandArray[nHead-1].Parameter.NodeList.actualm;
01147 nHead = pEo->CommandArray[nHead-1].Parameter.NodeList.rest;
01148 pVar = execute_Evaluate(pEo,
01149 nIndex,
01150 pMyMortal,
01151 piErrorCode,0);
01152 if( *piErrorCode )return NULL;
01153
01154 if( pVar )
01155 lIndex = GETLONGVALUE(pVar);
01156 else
01157 lIndex = 0;
01158
01159
01160
01161 if( !*ppVar || (*ppVar)->vType != VTYPE_ARRAY ){
01162 if( *ppVar ){
01163 if( 0 < lIndex )lMinIndex = 0; else lMinIndex = lIndex;
01164 if( 0 > lIndex )lMaxIndex = 0; else lMaxIndex = lIndex;
01165 }else lMinIndex = lMaxIndex = lIndex;
01166 pVar = memory_NewArray(pEo->pMo,
01167 lMinIndex,
01168 lMaxIndex);
01169 if( pVar == NULL ){
01170 *piErrorCode = EXE_ERROR_MEMORY_LOW;
01171 return NULL;
01172 }
01173 if( *ppVar ){
01174 pVar->Value.aValue[-lMinIndex] = *ppVar;
01175 }
01176 *ppVar = pVar;
01177 }
01178 memory_CheckArrayIndex(pEo->pMo,(*ppVar),lIndex);
01179 ppVar = (*ppVar)->Value.aValue+lIndex-(*ppVar)->ArrayLowLimit;
01180
01181 }
01182 return ppVar;
01183 }
01184
01185
01186
01187 static int STRCMP(VARIABLE Op1, VARIABLE Op2, int iCase){
01188 unsigned long n;
01189 char *a,*b;
01190 char ca,cb;
01191
01192 if( memory_IsUndef(Op1) && memory_IsUndef(Op2) )return 0;
01193 if( memory_IsUndef(Op1) )return 1;
01194 if( memory_IsUndef(Op2) )return -1;
01195 iCase &= 1;
01196 n = STRLEN(Op1);
01197 if( n > STRLEN(Op2) ) n= STRLEN(Op2);
01198 a = STRINGVALUE(Op1);
01199 b = STRINGVALUE(Op2);
01200 while( n-- ){
01201 ca = *a;
01202 cb = *b;
01203 if( iCase ){
01204 if( isupper(ca) )ca = tolower(ca);
01205 if( isupper(cb) )cb = tolower(cb);
01206 }
01207 if( ca != cb )return ( (ca)-(cb) );
01208 a++;
01209 b++;
01210 }
01211 if( STRLEN(Op1) == STRLEN(Op2) )return 0;
01212 if( STRLEN(Op1) > STRLEN(Op2) )return 1;
01213 return -1;
01214 }
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225 pFixSizeMemoryObject *execute_LeftValueSarray(pExecuteObject pEo,
01226 unsigned long lExpressionRootNode,
01227 pMortalList pMyMortal,
01228 int *piErrorCode
01229 ){
01230
01231
01232
01233 long OpCode;
01234 long lIndex;
01235 int KeyIsFound;
01236 unsigned long nVariable, nIndex;
01237 unsigned long nHead;
01238 pFixSizeMemoryObject *ppVar,pVar,vIndex,vCurrentKey;
01239 unsigned long __refcount_;
01240 int iCase = options_Get(pEo,"compare")&1;
01241
01242 nHead = pEo->CommandArray[lExpressionRootNode-1].Parameter.Arguments.Argument;
01243 nVariable = pEo->CommandArray[nHead-1].Parameter.NodeList.actualm;
01244 OpCode = pEo->CommandArray[nVariable-1].OpCode;
01245
01246 nHead = pEo->CommandArray[nHead-1].Parameter.NodeList.rest;
01247
01248 switch( OpCode ){
01249 case eNTYPE_LVR:
01250 if( pEo->LocalVariables == NULL ){
01251 *piErrorCode = EXE_ERROR_NO_LOCAL;
01252 return NULL;
01253 }
01254 ppVar = &(pEo->LocalVariables->Value.aValue[pEo->CommandArray[nVariable-1].Parameter.Variable.Serial-1]);
01255 break;
01256 case eNTYPE_GVR:
01257 ppVar = &(pEo->GlobalVariables->Value.aValue[pEo->CommandArray[nVariable-1].Parameter.Variable.Serial-1]);
01258 break;
01259 case eNTYPE_ARR:
01260 ppVar = execute_LeftValueArray(pEo,nVariable,pMyMortal,piErrorCode);
01261 break;
01262 case eNTYPE_SAR:
01263 ppVar = execute_LeftValueSarray(pEo,nVariable,pMyMortal,piErrorCode);
01264 break;
01265 default:
01266
01267 *piErrorCode =EXE_ERROR_INTERNAL;
01268 return NULL;
01269 }
01270
01271
01272 __refcount_ = pEo->pMo->maxderef;
01273 while( *ppVar && (*ppVar)->vType == VTYPE_REF &&__refcount_-- )
01274 ppVar = (*ppVar)->Value.aValue;
01275
01276 if( *ppVar && (*ppVar)->vType == VTYPE_REF ){
01277 *piErrorCode = COMMAND_ERROR_CIRCULAR;
01278 return NULL;
01279 }
01280
01281 while( nHead ){
01282 nIndex = pEo->CommandArray[nHead-1].Parameter.NodeList.actualm;
01283 nHead = pEo->CommandArray[nHead-1].Parameter.NodeList.rest;
01284 vIndex = execute_Evaluate(pEo,
01285 nIndex,
01286 pMyMortal,
01287 piErrorCode,0);
01288 if( *piErrorCode )return NULL;
01289
01290
01291 if( !*ppVar || (*ppVar)->vType != VTYPE_ARRAY ){
01292 if( *ppVar ){
01293 pVar = memory_NewArray(pEo->pMo,
01294 0,
01295 3);
01296 if( pVar == NULL ){
01297 *piErrorCode = EXE_ERROR_MEMORY_LOW;
01298 return NULL;
01299 }
01300
01301 pVar->Value.aValue[0] = *ppVar;
01302 pVar->Value.aValue[1] = NULL;
01303 pVar->Value.aValue[2] = memory_DupVar(pEo->pMo,vIndex,pMyMortal,piErrorCode);
01304 memory_Immortalize(pVar->Value.aValue[2],pMyMortal);
01305 if( *piErrorCode )return NULL;
01306 pVar->Value.aValue[3] = NULL;
01307 lIndex = 3;
01308 }else{
01309 pVar = memory_NewArray(pEo->pMo,
01310 0,
01311 1);
01312 if( pVar == NULL ){
01313 *piErrorCode = EXE_ERROR_MEMORY_LOW;
01314 return NULL;
01315 }
01316 pVar->Value.aValue[0] = memory_DupVar(pEo->pMo,vIndex,pMyMortal,piErrorCode);
01317 memory_Immortalize(pVar->Value.aValue[0],pMyMortal);
01318 if( *piErrorCode )return NULL;
01319 pVar->Value.aValue[1] = NULL;
01320 lIndex = 1;
01321 }
01322 *ppVar = pVar;
01323 }else{
01324 KeyIsFound = 0;
01325 for( lIndex = (*ppVar)->ArrayLowLimit ; lIndex < (*ppVar)->ArrayHighLimit ; lIndex += 2 ){
01326 vCurrentKey = (*ppVar)->Value.aValue[lIndex-(*ppVar)->ArrayLowLimit];
01327
01328 while( vCurrentKey && vCurrentKey->vType == VTYPE_REF )vCurrentKey = *vCurrentKey->Value.aValue;
01329 if( memory_IsUndef(vCurrentKey) && memory_IsUndef(vIndex) ){
01330 lIndex++;
01331 KeyIsFound = 1;
01332 goto KEY_IS_FOUND;
01333 }
01334 if( memory_IsUndef(vCurrentKey) )continue;
01335 if( memory_IsUndef(vIndex) )continue;
01336 if( vCurrentKey->vType != vIndex->vType )continue;
01337 switch( vIndex->vType ){
01338 case VTYPE_LONG:
01339 if( vIndex->Value.lValue == vCurrentKey->Value.lValue ){
01340 lIndex++;
01341 KeyIsFound = 1;
01342 goto KEY_IS_FOUND;
01343 }
01344 break;
01345 case VTYPE_DOUBLE:
01346 if( vIndex->Value.dValue == vCurrentKey->Value.dValue ){
01347 lIndex++;
01348 KeyIsFound = 1;
01349 goto KEY_IS_FOUND;
01350 }
01351 break;
01352 case VTYPE_STRING:
01353 if( !STRCMP(vIndex,vCurrentKey,iCase) ){
01354 lIndex++;
01355 KeyIsFound = 1;
01356 goto KEY_IS_FOUND;
01357 }
01358 break;
01359 case VTYPE_ARRAY:
01360
01361 break;
01362 default:
01363 *piErrorCode = EXE_ERROR_INTERNAL;
01364 return NULL;
01365 }
01366 }
01367 KEY_IS_FOUND:
01368 if( ! KeyIsFound ){
01369
01370 memory_CheckArrayIndex(pEo->pMo,*ppVar,(*ppVar)->ArrayHighLimit+2);
01371
01372 (*ppVar)->Value.aValue[(*ppVar)->ArrayHighLimit-(*ppVar)->ArrayLowLimit] = NULL;
01373 (*ppVar)->Value.aValue[(*ppVar)->ArrayHighLimit-(*ppVar)->ArrayLowLimit-1] = memory_DupVar(pEo->pMo,vIndex,pMyMortal,piErrorCode);
01374 memory_Immortalize((*ppVar)->Value.aValue[(*ppVar)->ArrayHighLimit-(*ppVar)->ArrayLowLimit-1],pMyMortal);
01375 lIndex = (*ppVar)->ArrayHighLimit;
01376 }
01377 }
01378 memory_CheckArrayIndex(pEo->pMo,(*ppVar),lIndex);
01379 ppVar = (*ppVar)->Value.aValue+lIndex-(*ppVar)->ArrayLowLimit;
01380 }
01381 return ppVar;
01382 }
01383
01384
01385
01386
01387
01388
01389
01390
01391
01392
01393
01394 pFixSizeMemoryObject execute_Convert2String(pExecuteObject pEo,
01395 pFixSizeMemoryObject pVar,
01396 pMortalList pMyMortal
01397 ){
01398
01399
01400 char buffer[256];
01401
01402 while( pVar && pVar->vType == VTYPE_ARRAY )
01403 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01404
01405
01406 if( memory_IsUndef(pVar) ){
01407 pVar = memory_NewMortalString(pEo->pMo,0,pMyMortal);
01408 if( pVar == NULL )return NULL;
01409 return pVar;
01410 }
01411
01412 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01413
01414 switch( pVar->vType ){
01415 default: return NULL;
01416 case VTYPE_LONG:
01417 sprintf(buffer,"%ld",pVar->Value.lValue);
01418 break;
01419 case VTYPE_STRING:
01420 return pVar;
01421 case VTYPE_DOUBLE:
01422 sprintf(buffer,"%lf",pVar->Value.dValue);
01423 break;
01424 }
01425 pVar = memory_NewMortalString(pEo->pMo,strlen(buffer),pMyMortal);
01426 if( pVar == NULL )return NULL;
01427 memcpy(pVar->Value.pValue,buffer,strlen(buffer));
01428 return pVar;
01429 }
01430
01431
01432
01433
01434
01435
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450 pFixSizeMemoryObject execute_Convert2Long(pExecuteObject pEo,
01451 pFixSizeMemoryObject pVar,
01452 pMortalList pMyMortal
01453 ){
01454
01455
01456 char *s;
01457 int lintpart;
01458 double intpart,fracpart,exppart,man;
01459 int i,esig,isig;
01460 unsigned long sLen;
01461
01462 while( pVar && pVar->vType == VTYPE_ARRAY )
01463 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01464
01465 if( memory_IsUndef(pVar) ){
01466 pVar = memory_NewMortalLong(pEo->pMo,pMyMortal);
01467 if( pVar == NULL )return NULL;
01468 pVar->Value.lValue = 0;
01469 return pVar;
01470 }
01471
01472 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01473
01474 switch( pVar->vType ){
01475 default: return NULL;
01476 case VTYPE_LONG: return pVar;
01477 case VTYPE_STRING:
01478 s = (char *)pVar->Value.pValue;
01479 sLen = pVar->Size;
01480 while( isspace( *s ) && sLen ){
01481 s++;
01482 sLen--;
01483 }
01484 isig = 1; esig =1;
01485 if( *s == '-' )isig = -1;
01486 if( sLen )
01487 if( *s == '-' || *s == '+' ){ s++; sLen--; }
01488 for( lintpart = 0 ; sLen && isdigit(*s) ; s++,sLen-- ){
01489 lintpart *= 10;
01490 lintpart += *s -'0';
01491 }
01492 if( (!sLen) || (*s != '.' && *s != 'e' && *s != 'E') ){
01493 pVar = memory_NewMortalLong(pEo->pMo,pMyMortal);
01494 if( pVar == NULL )return NULL;
01495 pVar->Value.lValue = isig*lintpart;
01496 return pVar;
01497 }
01498 intpart = lintpart;
01499 fracpart = 0.0;
01500 if( sLen && *s == '.' ){
01501 s++;
01502 sLen --;
01503 i = 0;
01504 fracpart = 0.0;
01505 man = 1.0;
01506 for( ; isdigit(*s) && sLen ; s++, sLen-- )
01507 fracpart += (man *= 0.1) * (*s-'0');
01508 }
01509 if( sLen && (*s == 'E' || *s == 'e') ){
01510 i = 0;
01511 s++;
01512 sLen --;
01513 if( *s == '-' )esig=-1; else esig = 1;
01514 if( sLen )
01515 if( *s == '+' || *s == '-'){ s++; sLen--; }
01516 for( exppart=0.0 , i = 0 ; sLen && isdigit(*s) ; s++, sLen-- )
01517 exppart = 10*exppart + *s-'0';
01518 }else exppart = 0.0;
01519 pVar = memory_NewMortalLong(pEo->pMo,pMyMortal);
01520 if( pVar == NULL )return NULL;
01521 pVar->Value.lValue = (long)(isig*(intpart + fracpart)*pow10(esig*exppart));
01522 return pVar;
01523 case VTYPE_DOUBLE:
01524 pVar->vType = VTYPE_LONG;
01525 pVar->Value.lValue = (long)pVar->Value.dValue;
01526 return pVar;
01527 }
01528 }
01529
01530
01531
01532
01533
01534
01535
01536
01537
01538
01539
01540
01541
01542
01543 pFixSizeMemoryObject execute_Convert2LongS(pExecuteObject pEo,
01544 pFixSizeMemoryObject pVar,
01545 pMortalList pMyMortal
01546 ){
01547
01548
01549 pFixSizeMemoryObject pVarr;
01550
01551 while( pVar && pVar->vType == VTYPE_ARRAY )
01552 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01553
01554 if( memory_IsUndef(pVar) ){
01555 pVar = memory_NewMortalLong(pEo->pMo,pMyMortal);
01556 if( pVar == NULL )return NULL;
01557 pVar->Value.lValue = 0;
01558 return pVar;
01559 }
01560
01561 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01562
01563 switch( pVar->vType ){
01564 default: return NULL;
01565 case VTYPE_LONG: return pVar;
01566 case VTYPE_STRING:
01567
01568
01569 return execute_Convert2Long(pEo,pVar,pMyMortal);
01570
01571 case VTYPE_DOUBLE:
01572 pVarr = memory_NewMortalLong(pEo->pMo,pMyMortal);
01573 if( pVarr == NULL )return NULL;
01574 pVarr->vType = VTYPE_LONG;
01575 pVarr->Value.lValue = (long)pVar->Value.dValue;
01576 return pVarr;
01577 }
01578 }
01579
01580
01581
01582
01583
01584
01585
01586
01587
01588
01589
01590
01591
01592
01593
01594
01595 pFixSizeMemoryObject execute_Convert2Double(pExecuteObject pEo,
01596 pFixSizeMemoryObject pVar,
01597 pMortalList pMyMortal
01598 ){
01599
01600
01601 char *s;
01602 double intpart,fracpart,exppart,man;
01603 int i,esig,isig;
01604 unsigned long sLen;
01605
01606 while( pVar && pVar->vType == VTYPE_ARRAY )
01607 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01608
01609 if( memory_IsUndef(pVar) ){
01610 pVar = memory_NewMortalDouble(pEo->pMo,pMyMortal);
01611 if( pVar == NULL )return NULL;
01612 pVar->Value.dValue = 0.0;
01613 return pVar;
01614 }
01615
01616 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01617
01618 switch( pVar->vType ){
01619 default: return NULL;
01620 case VTYPE_LONG:
01621 pVar->vType = VTYPE_DOUBLE;
01622 pVar->Value.dValue = (double)pVar->Value.lValue;
01623 return pVar;
01624 case VTYPE_DOUBLE:
01625 return pVar;
01626 case VTYPE_STRING:
01627 s = (char *)pVar->Value.pValue;
01628 sLen = pVar->Size;
01629 while( isspace( *s ) && sLen ){
01630 s++;
01631 sLen--;
01632 }
01633 isig = 1; esig =1;
01634 if( *s == '-' )isig = -1;
01635 if( sLen )
01636 if( *s == '-' || *s == '+' ){ s++; sLen--; }
01637 for( intpart = 0 ; sLen && isdigit(*s) ; s++,sLen-- ){
01638 intpart *= 10;
01639 intpart += *s -'0';
01640 }
01641 fracpart = 0.0;
01642 if( sLen && *s == '.' ){
01643 s++;
01644 sLen --;
01645 i = 0;
01646 fracpart = 0.0;
01647 man = 1.0;
01648 for( ; isdigit(*s) && sLen ; s++, sLen-- )
01649 fracpart += (man *= 0.1) * (*s-'0');
01650 }
01651 if( sLen && (*s == 'E' || *s == 'e') ){
01652 i = 0;
01653 s++;
01654 sLen --;
01655 if( *s == '-' )esig=-1; else esig = 1;
01656 if( sLen )
01657 if( *s == '+' || *s == '-'){ s++; sLen--; }
01658 for( exppart=0.0 , i = 0 ; sLen && isdigit(*s) ; s++, sLen-- )
01659 exppart = 10*exppart + *s-'0';
01660 }else exppart = 0.0;
01661 pVar = memory_NewMortalDouble(pEo->pMo,pMyMortal);
01662 if( pVar == NULL )return NULL;
01663 pVar->Value.dValue = isig*(intpart + fracpart)*pow10(esig*exppart);
01664 return pVar;
01665 }
01666 }
01667
01668
01669
01670
01671
01672
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682 pFixSizeMemoryObject execute_Convert2DoubleS(pExecuteObject pEo,
01683 pFixSizeMemoryObject pVar,
01684 pMortalList pMyMortal
01685 ){
01686
01687
01688 pFixSizeMemoryObject pVarr;
01689
01690 while( pVar && pVar->vType == VTYPE_ARRAY )
01691 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01692
01693 if( memory_IsUndef(pVar) ){
01694 pVar = memory_NewMortalDouble(pEo->pMo,pMyMortal);
01695 if( pVar == NULL )return NULL;
01696 pVar->Value.dValue = 0.0;
01697 return pVar;
01698 }
01699
01700 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01701
01702 switch( pVar->vType ){
01703 default: return NULL;
01704 case VTYPE_LONG:
01705 pVarr = memory_NewMortalDouble(pEo->pMo,pMyMortal);
01706 if( pVarr == NULL )return NULL;
01707 pVarr->vType = VTYPE_DOUBLE;
01708 pVarr->Value.dValue = (double)pVar->Value.lValue;
01709 return pVarr;
01710 case VTYPE_DOUBLE:
01711 return pVar;
01712 case VTYPE_STRING:
01713
01714 return execute_Convert2Double(pEo,pVar,pMyMortal);
01715 }
01716 }
01717
01718
01719
01720
01721
01722
01723
01724
01725
01726
01727
01728
01729
01730
01731
01732
01733
01734
01735 pFixSizeMemoryObject execute_Convert2Numeric(pExecuteObject pEo,
01736 pFixSizeMemoryObject pVar,
01737 pMortalList pMyMortal
01738 ){
01739
01740
01741
01742 while( pVar && pVar->vType == VTYPE_ARRAY )
01743 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01744
01745 if( memory_IsUndef(pVar) ){
01746 pVar = memory_NewMortalLong(pEo->pMo,pMyMortal);
01747 if( pVar == NULL )return NULL;
01748 pVar->Value.lValue = 0;
01749 return pVar;
01750 }
01751
01752 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01753
01754 switch( pVar->vType ){
01755 default: return NULL;
01756 case VTYPE_LONG:
01757 return pVar;
01758 case VTYPE_DOUBLE:
01759 return pVar;
01760 case VTYPE_STRING:
01761 if( ISSTRINGINTEGER(pVar) )
01762 return execute_Convert2Long(pEo,pVar,pMyMortal);
01763 else
01764 return execute_Convert2Double(pEo,pVar,pMyMortal);
01765 }
01766 }
01767
01768
01769
01770
01771
01772
01773
01774
01775
01776
01777
01778
01779
01780
01781 pFixSizeMemoryObject execute_Dereference(pExecuteObject pEo,
01782 pFixSizeMemoryObject p,
01783 int *piErrorCode
01784 ){
01785
01786
01787
01788 unsigned long refcount;
01789
01790 if( *piErrorCode )return p;
01791 refcount = pEo->pMo->maxderef;
01792 while( p && TYPE(p) == VTYPE_REF ){
01793 p = *(p->Value.aValue);
01794 if( ! refcount-- ){
01795 *piErrorCode = COMMAND_ERROR_CIRCULAR;
01796 return NULL;
01797 }
01798 }
01799 return p;
01800 }
01801
01802
01803
01804
01805
01806
01807
01808
01809
01810 int execute_DereferenceS(unsigned long refcount,
01811 pFixSizeMemoryObject *p
01812 ){
01813
01814
01815
01816
01817
01818
01819
01820
01821
01822
01823
01824 while( p && *p && TYPE(*p) == VTYPE_REF ){
01825 *p = *((*p)->Value.aValue);
01826 if( ! refcount-- )return COMMAND_ERROR_CIRCULAR;
01827 }
01828
01829 if( p && *p && TYPE(*p) == VTYPE_UNDEF )*p = NULL;
01830 return EXE_ERROR_SUCCESS;
01831 }
01832
01833
01834
01835
01836
01837
01838
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848
01849
01850 double execute_GetDoubleValue(pExecuteObject pEo,
01851 pFixSizeMemoryObject pVar
01852 ){
01853
01854
01855 char *s;
01856 double intpart,fracpart,exppart,man;
01857 int i,esig,isig;
01858 unsigned long sLen;
01859
01860 while( pVar && pVar->vType == VTYPE_ARRAY )
01861 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01862
01863 if( memory_IsUndef(pVar) )return 0.0;
01864
01865 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01866
01867 switch( pVar->vType ){
01868 default: return 0.0;
01869 case VTYPE_LONG:
01870 return (double)pVar->Value.lValue;
01871 case VTYPE_DOUBLE:
01872 return pVar->Value.dValue;
01873 case VTYPE_STRING:
01874 s = (char *)pVar->Value.pValue;
01875 sLen = pVar->Size;
01876 while( isspace( *s ) && sLen ){
01877 s++;
01878 sLen--;
01879 }
01880 isig = 1; esig =1;
01881 if( *s == '-' )isig = -1;
01882 if( sLen )
01883 if( *s == '-' || *s == '+' ){ s++; sLen--; }
01884 for( intpart = 0 ; sLen && isdigit(*s) ; s++,sLen-- ){
01885 intpart *= 10;
01886 intpart += *s -'0';
01887 }
01888 fracpart = 0.0;
01889 if( sLen && *s == '.' ){
01890 s++;
01891 sLen --;
01892 i = 0;
01893 fracpart = 0.0;
01894 man = 1.0;
01895 for( ; isdigit(*s) && sLen ; s++, sLen-- )
01896 fracpart += (man *= 0.1) * (*s-'0');
01897 }
01898 if( sLen && (*s == 'E' || *s == 'e') ){
01899 i = 0;
01900 s++;
01901 sLen --;
01902 if( *s == '-' )esig=-1; else esig = 1;
01903 if( sLen )
01904 if( *s == '+' || *s == '-'){ s++; sLen--; }
01905 for( exppart=0.0 , i = 0 ; sLen && isdigit(*s) ; s++, sLen-- )
01906 exppart = 10*exppart + *s-'0';
01907 }else exppart = 0.0;
01908 return isig*(intpart + fracpart)*pow10(esig*exppart);
01909 }
01910 }
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926
01927
01928
01929 long execute_GetLongValue(pExecuteObject pEo,
01930 pFixSizeMemoryObject pVar
01931 ){
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942
01943
01944 char *s;
01945 long lintpart;
01946 double intpart,fracpart,exppart,man;
01947 int i,esig,isig;
01948 unsigned long sLen;
01949
01950 while( pVar && pVar->vType == VTYPE_ARRAY )
01951 pVar = pVar->Value.aValue[pVar->ArrayLowLimit];
01952
01953 if( memory_IsUndef(pVar) )return 0;
01954
01955 execute_DereferenceS(pEo->pMo->maxderef,&pVar);
01956
01957 switch( pVar->vType ){
01958 default: return 0;
01959 case VTYPE_LONG: return pVar->Value.lValue;
01960 case VTYPE_STRING:
01961 s = (char *)pVar->Value.pValue;
01962 sLen = pVar->Size;
01963 while( isspace( *s ) && sLen ){
01964 s++;
01965 sLen--;
01966 }
01967 isig = 1;
01968 if( *s == '-' )isig = -1;
01969 if( sLen )
01970 if( *s == '-' || *s == '+' ){ s++; sLen--; }
01971 for( lintpart = 0 ; sLen && isdigit(*s) ; s++,sLen-- ){
01972 lintpart *= 10;
01973 lintpart += *s -'0';
01974 }
01975
01976 if( (!sLen) || (*s != '.' && *s != 'e' && *s != 'E') )return isig*lintpart;
01977 intpart = lintpart;
01978 fracpart = 0.0;
01979 if( sLen && *s == '.' ){
01980 s++;
01981 sLen --;
01982 i = 0;
01983 fracpart = 0.0;
01984 man = 1.0;
01985 for( ; isdigit(*s) && sLen ; s++, sLen-- )
01986 fracpart += (man *= 0.1) * (*s-'0');
01987 }
01988 if( sLen && (*s == 'E' || *s == 'e') ){
01989 i = 0;
01990 s++;
01991 sLen --;
01992 if( *s == '-' )esig=-1; else esig = 1;
01993 if( sLen )
01994 if( *s == '+' || *s == '-'){ s++; sLen--; }
01995 for( exppart=0.0 , i = 0 ; sLen && isdigit(*s) ; s++, sLen-- )
01996 exppart = 10*exppart + *s-'0';
01997 }else exppart = 0.0;
01998 return (long)(isig*(intpart + fracpart)*pow10(esig*exppart));
01999 case VTYPE_DOUBLE:
02000 return (long)pVar->Value.dValue;
02001 }
02002 }
02003
02004
02005
02006
02007
02008
02009
02010
02011
02012
02013
02014 int execute_IsStringInteger(pFixSizeMemoryObject pVar
02015 ){
02016
02017
02018 char *s;
02019 double mantissa,fracpart,frac;
02020 long sLen;
02021 long fraclen,fracreallen;
02022 long exponent;
02023 int sig,esig;
02024
02025 if( memory_IsUndef(pVar) || pVar->vType != VTYPE_STRING )return 0;
02026 s = (char *)pVar->Value.pValue;
02027 sLen = pVar->Size;
02028 while( isspace(*s) && sLen ){
02029 s++;
02030 sLen--;
02031 }
02032 sig = 1;
02033 if( sLen )
02034 if( *s == '+' || *s == '-' ){
02035 sig = *s == '+';
02036 s++;
02037 sLen--;
02038 }
02039
02040 mantissa = 0.0;
02041 fracreallen = 0;
02042 while( sLen && isdigit(*s) ){
02043 mantissa *= 10;
02044 mantissa += (double)*s - '0';
02045
02046 if( '0' == *s )fracreallen --;
02047 s++;
02048 sLen--;
02049 }
02050
02051
02052 if( sLen == 0 )
02053 return sig ? mantissa <= LONG_MAX : mantissa <= -(LONG_MIN);
02054
02055
02056 if( *s != '.' && *s != 'e' && *s != 'E' )return 1;
02057
02058 fraclen = 0;
02059 fracpart = 0.0;
02060 frac = 0.1;
02061 if( *s == '.' ){
02062 s++;
02063 sLen --;
02064 while( sLen && isdigit(*s) ){
02065 fracpart += frac * ( *s - '0' );
02066 frac /= 10.0;
02067 fraclen ++;
02068 if( *s != '0' )fracreallen = fraclen;
02069 s++;
02070 sLen--;
02071 }
02072 }
02073 esig = 1;
02074 exponent = 0;
02075 if( sLen && ( *s == 'e' || *s == 'E' ) ){
02076 sLen--;
02077 s++;
02078 if( sLen && ( *s == '+' || *s == '-' ) ){
02079 if( *s == '-' )esig = -1;
02080 sLen--;
02081 s++;
02082 }
02083 while( sLen && isdigit(*s) ){
02084 exponent *= 10;
02085 exponent += *s -'0';
02086 s++;
02087 sLen--;
02088 }
02089 }
02090
02091
02092 if( fracreallen > esig * exponent )return 0;
02093
02094
02095 mantissa += fracpart;
02096 mantissa *= pow10(esig *exponent);
02097 return sig ? mantissa <= LONG_MAX : mantissa <= -(LONG_MIN);
02098 }
02099
02100
02101
02102
02103
02104
02105
02106
02107 int execute_IsInteger(pFixSizeMemoryObject pVar
02108 ){
02109
02110
02111 long lTest;
02112
02113
02114
02115 if( memory_IsUndef(pVar) )return 0;
02116
02117 switch( TYPE(pVar) ){
02118 case VTYPE_LONG: return 1;
02119
02120 case VTYPE_DOUBLE:
02121 lTest = (long)DOUBLEVALUE(pVar);
02122 return DOUBLEVALUE(pVar) == (double)lTest;
02123
02124 case VTYPE_STRING: return ISSTRINGINTEGER(pVar);
02125 default: return 0;
02126 }
02127
02128 }