Ejemplo n.º 1
0
        /// <summary>
        /// Log output to the transcript file.
        /// Do this only if the transcript is on, and the port is the current output port.
        /// </summary>
        /// <param name="str">The output to log.</param>
        /// <param name="port">The port that it was written to.</param>
        internal void LogOutput(string str, OutputPort port)
        {
            if (this.transcriptWriter == null || port != this.interp.CurrentOutputPort)
            {
                return;
            }

            this.transcriptWriter.Write(str);
        }
 /// <summary>
 /// Initializes a new instance of the EvaluateCallWithOutputFile class.
 /// </summary>
 /// <param name="args">A pair, containing a filename and a proc to evaluate.</param>
 /// <param name="env">The evaluation environment</param>
 /// <param name="caller">The caller.  Return to this when done.</param>
 /// <param name="port">The output port.</param>
 private EvaluateCallWithOutputFile(SchemeObject args, Environment env, Evaluator caller, OutputPort port)
     : base(InitialStep, args, env, caller)
 {
     this.port = port;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Determine the port object to use with the OutputPort primitives.
 /// The port is optional: if supplied, it is the port to use.
 /// Otherwise, the current output port is used instead.
 /// </summary>
 /// <param name="port">The port to use, if supplied.  If is is not empty list, then it is an output port.</param>
 /// <param name="curr">The current output port.</param>
 /// <returns>The port to use.</returns>
 private static OutputPort Port(SchemeObject port, OutputPort curr)
 {
     return port is EmptyList ? curr : (OutputPort)port;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Read from the input port and evaluate whatever is there.
        /// Done for the side effect, not the result.
        /// Since the result is never tested, asynchronous suspensions do not prevent the rest
        /// of the file from being loaded.
        /// </summary>
        /// <param name="inp">The input port.</param>
        /// <param name="outp">If not null, input and results are written here.</param>
        /// <returns>Undefined instance.</returns>
        internal SchemeObject Load(InputPort inp, OutputPort outp)
        {
            while (true)
            {
                SchemeObject input;
                if ((input = inp.Read()) is Eof)
                {
                    inp.Close();
                    return Undefined.Instance;
                }

                if (outp != null)
                {
                    outp.WriteLine("> " + input);
                }

                var res = this.Eval(input);
                if (outp != null)
                {
                    outp.WriteLine(res.ToString());
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Load a file.  
 /// Open the file and read it.
 /// Evaluate whatever it contains.
 /// This may be one or more expressions.
 /// If any of them are asynchronous, then the evaluation is NOT blocked, but continues on.
 /// </summary>
 /// <param name="fileName">The filename.</param>
 /// <param name="outp">If not null, input and results are written here.</param>
 public void LoadFile(SchemeObject fileName, OutputPort outp)
 {
     string name = string.Empty;
     try
     {
         name = fileName.ToString();
         using (var fs = new FileStream(name, FileMode.Open, FileAccess.Read))
         {
             this.Load(InputPort.New(new StreamReader(fs), this), outp);
         }
     }
     catch (IOException)
     {
         ErrorHandlers.IoError("Can't load " + name);
     }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Dump the counters on the console.
 /// </summary>
 /// <param name="port">The port to dump to.</param>
 /// <returns>The result is unspecified.</returns>
 private SchemeObject DumpCounters(OutputPort port)
 {
     Contract.Requires(port != null);
     var sb = new StringBuilder();
     this.Dump(sb);
     port.WriteLine(sb.ToString());
     return Undefined.Instance;
 }