Beispiel #1
0
void LispLocalSymbols(LispEnvironment& aEnvironment, LispInt aStackTop)
{
    LispInt nrArguments = InternalListLength(ARGUMENT(0));

    LispInt nrSymbols = nrArguments-2;

    std::vector<const LispString*> names(nrSymbols);
    std::vector<const LispString*> localnames(nrSymbols);

    LispInt uniquenumber = aEnvironment.GetUniqueId();
    LispInt i;
    for (i=0;i<nrSymbols;i++)
    {
        const LispString* atomname = Argument(ARGUMENT(0), i+1)->String();
        CheckArg(atomname, i + 1, aEnvironment, aStackTop);
        names[i] = atomname;

        std::string newname = "$";
        newname.append(*atomname);
        newname.append(std::to_string(uniquenumber));
        localnames[i] = aEnvironment.HashTable().LookUp(newname);
    }

    LocalSymbolBehaviour behaviour(aEnvironment, std::move(names), std::move(localnames));
    LispPtr result;
    InternalSubstitute(result, Argument(ARGUMENT(0), nrArguments-1), behaviour);

    InternalEval(aEnvironment, RESULT, result);
}
Beispiel #2
0
void LispDebugFile(LispEnvironment& aEnvironment, LispInt aStackTop)
{
#ifndef YACAS_DEBUG
    throw LispErrGeneric("Cannot call DebugFile in non-debug version of Yacas");
#else
  const LispChar * file = ARGUMENT(1)->iFileName;
  if (!file) file = "";
  LispString * str = aEnvironment.HashTable().LookUpStringify(file);
  RESULT = LispAtom::New(aEnvironment, *str);
#endif
}
Beispiel #3
0
static void DoLoadDefFile(
    LispEnvironment& aEnvironment,
    LispInput* aInput,
    LispDefFile* def)
{
  LispLocalInput localInput(aEnvironment, aInput);

  const LispString* eof = aEnvironment.iEndOfFile->String();
  const LispString* end = aEnvironment.iListClose->String();

  bool endoffile = false;

  LispTokenizer tok;

  while (!endoffile)
  {
    // Read expression
    const LispString* token =
        tok.NextToken(*aEnvironment.CurrentInput(), aEnvironment.HashTable());

    // Check for end of file
    if (token == eof || token == end)
    {
      endoffile = true;
    }
    // Else evaluate
    else
    {
        LispMultiUserFunction* multiUser = aEnvironment.MultiUserFunction(token);

        if (multiUser->iFileToOpen != nullptr) {
            aEnvironment.CurrentOutput() << '[' << *token << "]\n";
            if (multiUser->iFileToOpen)
               throw LispErrDefFileAlreadyChosen();
        }

        multiUser->iFileToOpen = def;

        def->symbols.insert(token);

        aEnvironment.Protect(token);
    }
  }
}
Beispiel #4
0
void DoInternalLoad(LispEnvironment& aEnvironment,LispInput* aInput)
{
    LispLocalInput localInput(aEnvironment, aInput);

    // TODO make "EndOfFile" a global thing
    // read-parse-eval to the end of file
    const LispString* eof = aEnvironment.HashTable().LookUp("EndOfFile");
    bool endoffile = false;

    LispTokenizer tok;
    InfixParser parser(tok,
                       *aEnvironment.CurrentInput(),
                       aEnvironment,
                       aEnvironment.PreFix(),
                       aEnvironment.InFix(),
                       aEnvironment.PostFix(),
                       aEnvironment.Bodied());

    while (!endoffile)
    {
        LispPtr readIn;
        // Read expression
        parser.Parse(readIn);

        if (!readIn)
            throw LispErrReadingFile();

        // Check for end of file
        if (readIn->String() == eof)
        {
            endoffile = true;
            }
        // Else evaluate
        else
        {
            LispPtr result;
            aEnvironment.iEvaluator->Eval(aEnvironment, result, readIn);
        }
    }
}