Exemple #1
0
int32_t CompileENDOF(ContextType *context,int32_t value)
 {
 UNUSED(value);
 int32_t addr;

 // Pop value set by OF
 if (CPOP(&addr))
	    {
		consoleErrorMessage(&MainContext,"ENDOF not matched by OF");
		return 0;
	    }

 // Check that there is a related OF
 if ((addr&HEAD_MASK)!=BHEAD_OF)
      {
	  consoleErrorMessage(&MainContext,"ENDOF not matched by OF");
	  return 0;
      }

 // Discard head
 addr&=BRANCH_MASK;

 // Compile leave to go to the endcase
 CompileLEAVE(context,0);

 // Set OF addr to current position
 set16uValue(addr,CodePosition);

 return 0;
 }
Exemple #2
0
int32_t CompileENDIF(ContextType *context,int32_t value)
 {
 UNUSED(value); UNUSED(context);
 int32_t data;

 // Pop value set by IF or ELSE
 if (CPOP(&data))
     {
	 consoleErrorMessage(&MainContext,"THEN not matched by IF or ELSE");
	 abortCompile();
	 return 0;
     }

 // Check that there is a related IF or ELSE
 //if (!(data&BHEAD_IF))
 if ((data&HEAD_MASK)!=BHEAD_IF)
      {
	  consoleErrorMessage(&MainContext,"THEN not matched by IF or ELSE");
	  return 0;
      }

 // Discard head
 data&=BRANCH_MASK;

 // Set IF addr to current position
 set16uValue(data,CodePosition);

 return 0;
 }
Exemple #3
0
// Process pendent leaves
static void processLeaves(void)
 {
 int32_t data,addr;
 uint16_t *pointer;

 // Pop value set by DO
 if (CPOP(&data))
     {
	 consoleErrorMessage(&MainContext,"Cannot process leaves");
	 return;
     }

 // Check that data is about leaves
 if ((data&HEAD_MASK)!=BHEAD_LEAVE)
      {
	  consoleErrorMessage(&MainContext,"Inconsistent leave processing");
	  return;
      }

 // Discard head
 data&=BRANCH_MASK;

 // Discard one because 1 was added
 data--;

 while(MainContext.rstack.Pointer>data)
     {
	 // Try to get one element from the return stack
	 if (RPOP(&addr))
	    {
		consoleErrorMessage(&MainContext,"Inconsistent leave processing");
		return;
	    }

	 // Check that data is about leaves
	 if ((addr&HEAD_MASK)!=BHEAD_LEAVE)
	       {
	 	   consoleErrorMessage(&MainContext,"Inconsistent leave processing");
	 	   return;
	       }

	 // Discard head
	 addr&=BRANCH_MASK;

	 // Set pointer
	 pointer=(uint16_t*)(UDict.Mem+addr);

	 // Set value in pointer to current code position
	 (*pointer)=CodePosition;
     }
  }
Exemple #4
0
// Compiles the words:
// LOOP @LOOP
int32_t CompileLOOP(ContextType *context,int32_t value)
 {
 UNUSED(value); UNUSED(context);
 int32_t data;

 if (value==F_LOOP)
	 if (baseCode("LOOP"))
	 	  {
	      consoleErrorMessage(&MainContext,"Error compiling LOOP");
	 	  return 0;
	 	  }

 if (value==F_NEW_LOOP)
	 if (baseCode("@LOOP"))
	 	  {
	      consoleErrorMessage(&MainContext,"Error compiling @LOOP");
	 	  return 0;
	 	  }

 // Pop value set by DO
 if (CPOP(&data))
     {
	 consoleErrorMessage(&MainContext,"LOOP or @LOOP not matched by DO");
	 return 0;
     }

 // Check that there is a related DO
 if ((data&HEAD_MASK)!=BHEAD_DO)
      {
	  consoleErrorMessage(&MainContext,"LOOP or @LOOP not matched by DO");
	  return 0;
      }

 // Discard head
 data&=BRANCH_MASK;

 // Allocate space for JMP addr with addr value
 allocate16u((uint16_t)data);

 // Process leaves
 processLeaves();

 if (baseCode("UNLOOP"))
 	{
 	consoleErrorMessage(&MainContext,"Error compiling UNLOOP");
 	return 0;
 	}

 return 0;
 }
Exemple #5
0
void _Br1 (void) {     // BR1
        CPOP(pc);
        if (AITEM(1)==AT)
        {       ADELn(2);
                GETCMD;
                // looking for ELSE
                while (ML(pc)!=cmd_Else) pc++;
                pc +=2; // so that pc points after P0
                EXECMD;
        } else {
                ADEL;
                pc++;
                GETCMD;
                CPUSH(pc);
                pc=PCADR(cmd_BR1);
                EXECMD;
        }
 }
Exemple #6
0
int32_t CompileELSE(ContextType *context,int32_t value)
 {
 UNUSED(value); UNUSED(context);
 int32_t data;

 // Pop value set by IF
 if (CPOP(&data))
     {
	 consoleErrorMessage(&MainContext,"ELSE not matched by IF");
	 return 0;
     }

 // Check that there is a related IF
 if ((data&HEAD_MASK)!=BHEAD_IF)
      {
	  consoleErrorMessage(&MainContext,"ELSE not matched by IF");
	  return 0;
      }

 // Discard head
 data&=BRANCH_MASK;

 // Try to compile the JMP execute command
 if (baseCode("JMP"))
        {
	    consoleErrorMessage(&MainContext,"Error compiling ELSE");
	    return 0;
        }

 // Push current counter with IF head
 CPUSH_HERE(BHEAD_IF);

 // Allocate space for JMP addr with a dummy value
 allocate16u(0);

 // Set IF addr to current position
 set16uValue(data,CodePosition);

 return 0;
 }
Exemple #7
0
// Implements REPEAT and AGAIN
int32_t CompileREPEAT(ContextType *context,int32_t value)
 {
 UNUSED(value); UNUSED(context);

 int32_t addr;

 // Pop value set by BEGIN
 if (CPOP(&addr))
	    {
		consoleErrorMessage(&MainContext,"REPEAT/AGAIN not matched by BEGIN");
		return 0;
	    }

 // Check that there is a related BEGIN
 if ((addr&HEAD_MASK)!=BHEAD_BEGIN)
      {
	  consoleErrorMessage(&MainContext,"REPEAT/AGAIN not matched by BEGIN");
	  return 0;
      }

 // Discard head
 addr&=BRANCH_MASK;

 // Try to compile the JMP execute command
 if (baseCode("JMP"))
        {
	    consoleErrorMessage(&MainContext,"Error compiling REPEAT/AGAIN");
	    return 0;
        }

 // Allocate space for JMP addr with addr value
 allocate16u((uint16_t)addr);

 // Process leaves
 processLeaves();

 return 0;
 }
Exemple #8
0
// finish current-level interpretation ( END DSSP-procedure )
void _K  (void)
{     CPOP(pc); }
Exemple #9
0
 void _GetR  (void) {   // @R
         int32  RVal;
         CPOP (RVal);
         APUSH(RVal);
 }
Exemple #10
0
void _Else (void) { // ELSE
        CPOP(pc);
        ADEL;
}