static exprType getenvFunc(void)
{
  exprType stringType;

  TRACE(lstFile, "[getenvFunc]");

  /* FORM:  <string_var> = getenv(<string>) */

  checkLParen();

  /* Get the string expression representing the environment variable
   * name.
   */

  stringType = expression(exprString, NULL);

  /* Two possible kinds of strings could be returned.
   * Anything else other then 'exprString' would be an error (but
   * should happen).
   */

  if ((stringType != exprString) && (stringType != exprStkString))
    {
      error(eINVARG);
    }

  pas_BuiltInFunctionCall(lbGETENV);
  checkRParen();
  return exprCString;
}
static void valProc(void)         /* VAL procedure */
{
  int size;

  TRACE(lstFile, "[valProc]");

  /* Declaration:
   *   procedure val(const S : string; var V; var Code : word);
   *
   * Description:
   * val() converts the value represented in the string S to a numerical
   * value, and stores this value in the variable V, which can be of type
   * Longint, Real and Byte. If the conversion isn��t succesfull, then the
   * parameter Code contains the index of the character in S which
   * prevented the conversion. The string S is allowed to contain spaces
   * in the beginning.
   *
   * The string S can contain a number in decimal, hexadecimal, binary or
   * octal format, as described in the language reference.
   *
   * Errors:
   * If the conversion doesn��t succeed, the value of Code indicates the
   * position where the conversion went wrong.
   */

  /* Skip over the 'val' identifer */

  getToken();

  /* Setup the actual-parameter-list */

  size = actualParameterList(valSymbol);

  /* Generate the built-in procedure call.  NOTE the procedure call
   * logic will release the parameters from the stack saving us from
   * having to generate the INDS here.
   */

  pas_BuiltInFunctionCall(lbVAL);

} /* end writelnProc */
Пример #3
0
static void pas_StringAssignment(STYPE *varPtr, STYPE *typePtr)
{
  exprType stringKind;

   TRACE(lstFile,"[pas_StringAssignment]");

   /* FORM:  <variable OR function identifer> := <expression> */

   /* Verify that the assignment token follows the indentifier */

   if (token != tASSIGN) error (eASSIGN);
   else getToken();

   /* Get the expression after assignment token. We'll take any kind
    * of string expression.  This is a hack to handle calls to system
    * functions that return exprCString pointers that must be converted
    * to exprString records upon assignment.
    */

   stringKind = expression(exprAnyString, typePtr);

   /* Place the address of the destination string structure instance on the
    * stack.
    */

   pas_GenerateStackReference(opLAS, varPtr);

   /* Check if this is an assignment to a global allocated string, or
    * to a stack reference to an allocated string.
    */

   if (varPtr->sKind == sRSTRING)
     {
       /* It is an assignment to a string reference --
        * Generate a runtime library call to copy the destination
        * string string into the pascal string instance.  The particular
        * runtime call will account for any necesary string type conversion.
        */

       if ((stringKind == exprString) || (stringKind == exprStkString))
         {
           /* It is a pascal string type. Current stack representation is:
            *
            *   TOS(0)=address of dest string reference
            *   TOS(1)=length of source string
            *   TOS(2)=pointer to source string
            */

           pas_BuiltInFunctionCall(lbSTR2RSTR);
         }
       else if (stringKind == exprCString)
         {
           /* It is a 32-bit C string point.  Current stack representation is:
            *
            *   TOS(0)=address of dest string reference
            *   TOS(1)=MS 16-bits of 32-bit C source string pointer
            *   TOS(2)=LS 16-bits of 32-bit C source string pointer
            */

           pas_BuiltInFunctionCall(lbCSTR2RSTR);
         }
     }
   else
     {
       /* It is an assignment to a allocated Pascal string --
        * Generate a runtime library call to copy the destination
        * string string into the pascal string instance.  The particular
        * runtime call will account for any necesary string type conversion.
        */

       if ((stringKind == exprString) || (stringKind == exprStkString))
         {
           /* It is a pascal string type. Current stack representation is:
            *
            *   TOS(0)=address of dest string hdr
            *   TOS(1)=length of source string
            *   TOS(2)=pointer to source string
            */

           pas_BuiltInFunctionCall(lbSTR2STR);
         }
       else if (stringKind == exprCString)
         {
           /* It is a 32-bit C string point.  Current stack representation is:
            *
            *   TOS(0)=address of dest string hdr
            *   TOS(1)=MS 16-bits of 32-bit C source string pointer
            *   TOS(2)=LS 16-bits of 32-bit C source string pointer
            */

           pas_BuiltInFunctionCall(lbCSTR2STR);
         }
     }

   /* else ... type mismatch error already reported by expression() */
}