00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020 #include <stdio.h>
00021
00022 #include "../command.h"
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
00079 COMMAND(WHILE)
00080 #if NOTIMP_WHILE
00081 NOTIMPLEMENTED;
00082 #else
00083
00084 NODE nItem;
00085 NODE nGoForward;
00086 VARIABLE ItemResult;
00087
00088 nItem = PARAMETERNODE;
00089 ItemResult = EVALUATEEXPRESSION(nItem);
00090 ASSERTOKE;
00091 NEXTPARAMETER;
00092
00093 nGoForward = CDR(PARAMETERNODE);
00094 if( memory_IsUndef(ItemResult) ){
00095 SETPROGRAMCOUNTER(nGoForward);
00096 RETURN;
00097 }
00098
00099 switch( TYPE(ItemResult) ){
00100 case VTYPE_LONG:
00101 if( ! LONGVALUE(ItemResult) ){
00102 SETPROGRAMCOUNTER(nGoForward);
00103 RETURN;
00104 }
00105 break;
00106 case VTYPE_DOUBLE:
00107 if( ! DOUBLEVALUE(ItemResult) ){
00108 SETPROGRAMCOUNTER(nGoForward);
00109 RETURN;
00110 }
00111 break;
00112 case VTYPE_STRING:
00113 if( * STRINGVALUE(ItemResult) == (char)0 ){
00114 SETPROGRAMCOUNTER(nGoForward);
00115 RETURN;
00116 }
00117 break;
00118 case VTYPE_ARRAY:
00119 break;
00120 }
00121
00122 #endif
00123 END
00124
00155 COMMAND(DOUNTIL)
00156 #if NOTIMP_DOUNTIL
00157 NOTIMPLEMENTED;
00158 #else
00159
00160
00161 NODE nItem;
00162 NODE nGoForward;
00163 VARIABLE ItemResult;
00164
00165 nItem = PARAMETERNODE;
00166 ItemResult = EVALUATEEXPRESSION(nItem);
00167 ASSERTOKE;
00168 NEXTPARAMETER;
00169
00170
00171 nGoForward = CDR(PARAMETERNODE);
00172 if( memory_IsUndef(ItemResult) ){
00173 RETURN;
00174 }
00175
00176 switch( TYPE(ItemResult) ){
00177 case VTYPE_LONG:
00178 if( LONGVALUE(ItemResult) ){
00179 SETPROGRAMCOUNTER(nGoForward);
00180 RETURN;
00181 }
00182 break;
00183 case VTYPE_DOUBLE:
00184 if( DOUBLEVALUE(ItemResult) ){
00185 SETPROGRAMCOUNTER(nGoForward);
00186 RETURN;
00187 }
00188 break;
00189 case VTYPE_STRING:
00190 if( * STRINGVALUE(ItemResult) != (char)0 ){
00191 SETPROGRAMCOUNTER(nGoForward);
00192 RETURN;
00193 }
00194 break;
00195 case VTYPE_ARRAY:
00196 break;
00197 }
00198
00199 #endif
00200 END
00201
00202 COMMAND(WEND)
00203 #if NOTIMP_WEND
00204 NOTIMPLEMENTED;
00205 #else
00206
00207
00208 SETPROGRAMCOUNTER(PARAMETERNODE);
00209
00210 #endif
00211 END
00212
00231 COMMAND(DOWHILE)
00232 #if NOTIMP_DOWHILE
00233 NOTIMPLEMENTED;
00234 #else
00235 IDENTICAL_COMMAND(WHILE)
00236 #endif
00237 END
00238
00239 COMMAND(LOOP)
00240 #if NOTIMP_LOOP
00241 NOTIMPLEMENTED;
00242 #else
00243 IDENTICAL_COMMAND(WEND)
00244 #endif
00245 END
00246
00266 COMMAND(REPEAT)
00267 #if NOTIMP_REPEAT
00268 NOTIMPLEMENTED;
00269 #else
00270
00271
00272
00273 #endif
00274 END
00275
00308 COMMAND(DO)
00309 #if NOTIMP_DO
00310 NOTIMPLEMENTED;
00311 #else
00312
00313
00314 #endif
00315 END
00316
00317 COMMAND(LOOPWHILE)
00318 #if NOTIMP_LOOPWHILE
00319 NOTIMPLEMENTED;
00320 #else
00321 IDENTICAL_COMMAND(DOUNTIL)
00322 #endif
00323 END
00324
00325 COMMAND(UNTIL)
00326 #if NOTIMP_UNTIL
00327 NOTIMPLEMENTED;
00328 #else
00329 IDENTICAL_COMMAND(WHILE)
00330 #endif
00331 END
00332
00333 COMMAND(LOOPUNTIL)
00334 #if NOTIMP_LOOPUNTIL
00335 NOTIMPLEMENTED;
00336 #else
00337 IDENTICAL_COMMAND(WHILE)
00338 #endif
00339 END
00340
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 COMMAND(FOR)
00556 #if NOTIMP_FOR
00557 NOTIMPLEMENTED;
00558 #else
00559
00560 VARIABLE vStartExpression,
00561 vEndExpression,
00562 vStepExpression;
00563 LEFTVALUE LetThisVariable;
00564 NODE nToStatement;
00565 NODE nStepStatement;
00566 NODE nLoopStart,nLoopEnd;
00567 int iGoingUp;
00568 long refcount;
00569 int bEnterTheLoop;
00570
00571
00572 nToStatement = CDR(pEo->ProgramCounter);
00573
00574 if( nToStatement == 0 ){
00575
00576 SETPROGRAMCOUNTER(0);
00577 RETURN;
00578 }
00579
00580 nStepStatement = CDR(nToStatement);
00581 nToStatement = CAR(nToStatement);
00582
00583 if( nStepStatement ){
00584 if( pEo->CommandArray[CAR(nStepStatement)-1].OpCode == CMD_FORSTEP ){
00585 nLoopStart = CDR(nStepStatement);
00586 nStepStatement = CAR(nStepStatement);
00587 }else{
00588 nLoopStart = nStepStatement;
00589 nStepStatement = 0;
00590 }
00591 }else{
00592 nLoopStart = 0;
00593 }
00594
00595 if( OPCODE(nToStatement) != CMD_FORTO ){
00596 pEo->fStop = fStopSTOP;
00597 RETURN;
00598 }
00599
00600 nLoopEnd = pEo->CommandArray[nToStatement-1].Parameter.CommandArgument.next;
00601 nLoopEnd = pEo->CommandArray[nLoopEnd -1].Parameter.CommandArgument.next;
00602 nLoopEnd = pEo->CommandArray[nLoopEnd-1].Parameter.CommandArgument.Argument.pNode;
00603 if( nLoopEnd )nLoopEnd = CDR(nLoopEnd);
00604
00605 LetThisVariable = EVALUATELEFTVALUE(PARAMETERNODE);
00606 ASSERTOKE;
00607 DEREFERENCE(LetThisVariable)
00608
00609 NEXTPARAMETER;
00610 vStartExpression = EVALUATEEXPRESSION(PARAMETERNODE);
00611 ASSERTOKE;
00612
00613 if( memory_IsUndef(vStartExpression) ){
00614 SETPROGRAMCOUNTER(nLoopEnd);
00615 RETURN;
00616 }
00617 vStartExpression = CONVERT2NUMERIC(vStartExpression);
00618
00619 vEndExpression = EVALUATEEXPRESSION(pEo->CommandArray[nToStatement-1].Parameter.CommandArgument.Argument.pNode);
00620 ASSERTOKE;
00621 vEndExpression = CONVERT2NUMERIC(vEndExpression);
00622
00623 if( nStepStatement && OPCODE(nStepStatement) == CMD_FORSTEP ){
00624 vStepExpression = EVALUATEEXPRESSION(pEo->CommandArray[nStepStatement-1].Parameter.CommandArgument.Argument.pNode);
00625 ASSERTOKE;
00626 vStepExpression = CONVERT2NUMERIC(vStepExpression);
00627 switch( TYPE(vStepExpression) ){
00628 case VTYPE_LONG:
00629 iGoingUp = 0 < LONGVALUE(vStepExpression);
00630 break;
00631 case VTYPE_DOUBLE:
00632 iGoingUp = 0 < DOUBLEVALUE(vStepExpression);
00633 break;
00634 default: fprintf(stderr,"Internal error 667"); exit(667);
00635 }
00636 }else{
00637 iGoingUp = 1;
00638 }
00639
00640
00641
00642
00643 bEnterTheLoop = 0;
00644 if( TYPE(vStartExpression) == VTYPE_LONG && TYPE(vEndExpression) == VTYPE_LONG )
00645 bEnterTheLoop = iGoingUp ? LONGVALUE(vStartExpression) <= LONGVALUE(vEndExpression)
00646 : LONGVALUE(vStartExpression) >= LONGVALUE(vEndExpression);
00647
00648 if( TYPE(vStartExpression) == VTYPE_LONG && TYPE(vEndExpression) == VTYPE_DOUBLE )
00649 bEnterTheLoop = iGoingUp ? ((double)LONGVALUE(vStartExpression)) <= DOUBLEVALUE(vEndExpression)
00650 : ((double)LONGVALUE(vStartExpression)) >= DOUBLEVALUE(vEndExpression);
00651
00652 if( TYPE(vStartExpression) == VTYPE_DOUBLE && TYPE(vEndExpression) == VTYPE_DOUBLE )
00653 bEnterTheLoop = iGoingUp ? DOUBLEVALUE(vStartExpression) <= DOUBLEVALUE(vEndExpression)
00654 : DOUBLEVALUE(vStartExpression) >= DOUBLEVALUE(vEndExpression);
00655
00656 if( TYPE(vStartExpression) == VTYPE_DOUBLE && TYPE(vEndExpression) == VTYPE_LONG )
00657 bEnterTheLoop = iGoingUp ? DOUBLEVALUE(vStartExpression) <= (double)LONGVALUE(vEndExpression)
00658 : DOUBLEVALUE(vStartExpression) >= (double)LONGVALUE(vEndExpression);
00659
00660 if( bEnterTheLoop ){
00661
00662 memory_ReplaceVariable(pEo->pMo,LetThisVariable,vStartExpression,_pThisCommandMortals,1);
00663
00664 SETPROGRAMCOUNTER(nLoopStart);
00665 RETURN;
00666 }
00667
00668 SETPROGRAMCOUNTER(nLoopEnd);
00669
00670 #endif
00671 END
00672
00673 COMMAND(FORTO)
00674 #if NOTIMP_FORTO
00675 NOTIMPLEMENTED;
00676 #else
00677
00678 LEFTVALUE LetThisVariable;
00679 VARIABLE vEndExpression;
00680 VARIABLE vStepExpression;
00681 VARIABLE vNewLoopValue;
00682 NODE nStepStatement;
00683 NODE nForStatement;
00684 NODE nLoopStart,nLoopEnd;
00685 int iGoingUp;
00686 int bContinueLoop;
00687 long refcount;
00688 int iError;
00689
00690 vEndExpression = EVALUATEEXPRESSION(PARAMETERNODE);
00691 ASSERTOKE;
00692 vEndExpression = CONVERT2NUMERIC(vEndExpression);
00693
00694 NEXTPARAMETER;
00695 nForStatement = CAR(PARAMETERNODE);
00696 NEXTPARAMETER;
00697 nLoopEnd = CDR(PARAMETERNODE);
00698
00699 LetThisVariable = EVALUATELEFTVALUE( pEo->CommandArray[nForStatement-1].Parameter.CommandArgument.Argument.pNode );
00700 ASSERTOKE;
00701 DEREFERENCE(LetThisVariable)
00702 if( memory_IsUndef( *LetThisVariable) ||
00703 ( TYPE(*LetThisVariable) != VTYPE_LONG && TYPE(*LetThisVariable) != VTYPE_DOUBLE ) ){
00704
00705 vNewLoopValue = CONVERT2NUMERIC(*LetThisVariable);
00706 if( vNewLoopValue == NULL )ERROR(COMMAND_ERROR_MEMORY_LOW);
00707 iError = memory_ReplaceVariable(pEo->pMo,LetThisVariable,vNewLoopValue,_pThisCommandMortals,0);
00708 if( iError )ERROR(iError);
00709 }
00710 nStepStatement = CDR(pEo->ProgramCounter);
00711
00712 if( nStepStatement ){
00713 if( pEo->CommandArray[CAR(nStepStatement)-1].OpCode == CMD_FORSTEP ){
00714 nLoopStart = CDR(nStepStatement);
00715 nStepStatement = CAR(nStepStatement);
00716 }else{
00717 nLoopStart = nStepStatement;
00718 nStepStatement = 0;
00719 }
00720 }else{
00721 nLoopStart = 0;
00722 }
00723
00724 if( nStepStatement && OPCODE(nStepStatement) == CMD_FORSTEP ){
00725 vStepExpression = EVALUATEEXPRESSION(pEo->CommandArray[nStepStatement-1].Parameter.CommandArgument.Argument.pNode);
00726 ASSERTOKE;
00727 vStepExpression = CONVERT2NUMERIC(vStepExpression);
00728 switch( TYPE(vStepExpression) ){
00729 case VTYPE_LONG:
00730 iGoingUp = 0 < LONGVALUE(vStepExpression);
00731 switch( TYPE( (*LetThisVariable) ) ){
00732 case VTYPE_LONG:
00733 LONGVALUE( (*LetThisVariable) )+= LONGVALUE(vStepExpression);
00734 break;
00735 case VTYPE_DOUBLE:
00736 DOUBLEVALUE( (*LetThisVariable) )+= (double)LONGVALUE(vStepExpression);
00737 break;
00738 }
00739 break;
00740 case VTYPE_DOUBLE:
00741 iGoingUp = 0 < DOUBLEVALUE(vStepExpression);
00742 switch( TYPE( (*LetThisVariable) ) ){
00743 case VTYPE_LONG:
00744
00745
00746 (*LetThisVariable)->vType = VTYPE_DOUBLE;
00747 (*LetThisVariable)->Value.dValue = (double)(*LetThisVariable)->Value.lValue;
00748
00749 case VTYPE_DOUBLE:
00750 DOUBLEVALUE( (*LetThisVariable) )+= DOUBLEVALUE(vStepExpression);
00751 break;
00752 }
00753 break;
00754 }
00755 }else{
00756 iGoingUp = 1;
00757 switch( TYPE( (*LetThisVariable) ) ){
00758 case VTYPE_LONG:
00759 LONGVALUE( (*LetThisVariable) )+= 1;
00760 break;
00761 case VTYPE_DOUBLE:
00762 DOUBLEVALUE( (*LetThisVariable) )+= 1.0;
00763 break;
00764 }
00765 }
00766
00767 if( iGoingUp ){
00768 bContinueLoop = (TYPE(*LetThisVariable) == VTYPE_LONG ? LONGVALUE(*LetThisVariable) : DOUBLEVALUE(*LetThisVariable) )
00769 <=
00770 (TYPE(vEndExpression) == VTYPE_LONG ? LONGVALUE(vEndExpression) : DOUBLEVALUE(vEndExpression) );
00771 }else{
00772 bContinueLoop = (TYPE(*LetThisVariable) == VTYPE_LONG ? LONGVALUE(*LetThisVariable) : DOUBLEVALUE(*LetThisVariable) )
00773 >=
00774 (TYPE(vEndExpression) == VTYPE_LONG ? LONGVALUE(vEndExpression) : DOUBLEVALUE(vEndExpression) );
00775 }
00776 if( bContinueLoop ){
00777
00778 SETPROGRAMCOUNTER(nLoopStart);
00779 }else{
00780
00781 SETPROGRAMCOUNTER(nLoopEnd);
00782 }
00783
00784 #endif
00785 END
00786
00787 COMMAND(FORSTEP)
00788 #if NOTIMP_FORSTEP
00789 NOTIMPLEMENTED;
00790 #else
00791
00792
00793
00794
00795 #endif
00796 END
00797
00798 COMMAND(NEXT)
00799 #if NOTIMP_NEXT
00800 NOTIMPLEMENTED;
00801 #else
00802 IDENTICAL_COMMAND(WEND)
00803 #endif
00804 END
00805
00806 COMMAND(NEXTI)
00807 #if NOTIMP_NEXTI
00808 NOTIMPLEMENTED;
00809 #else
00810 NEXTPARAMETER;
00811 SETPROGRAMCOUNTER(PARAMETERNODE);
00812 #endif
00813 END