Пример #1
0
 /// <summary>
 /// Returns a pattern with the specified name from the engine's cache. If the pattern doesn't exist, it is loaded from
 /// file.
 /// </summary>
 /// <param name="name">The name or path of the pattern to retrieve.</param>
 /// <returns></returns>
 internal RantProgram GetProgramInternal(string name)
 {
     if (_patternCache.TryGetValue(name, out RantProgram pattern))
     {
         return(pattern);
     }
     return(_patternCache[name] = RantProgram.CompileFile(name));
 }
Пример #2
0
 /// <summary>
 /// Used by package loader
 /// </summary>
 /// <param name="program">Program to load</param>
 /// <returns></returns>
 internal bool CacheProgramInternal(RantProgram program)
 {
     if (Util.IsNullOrWhiteSpace(program.Name) || _patternCache.ContainsKey(program.Name))
     {
         return(false);
     }
     _patternCache[program.Name] = program;
     return(true);
 }
Пример #3
0
 public IEnumerable <RantOutput> DoSerial(string input, RNG rng, int charLimit = 0, double timeout = -1,
                                          RantProgramArgs args = null) =>
 new Sandbox(this, RantProgram.CompileString(input), rng, charLimit, GetPreservedCarrierState(), args).RunSerial(timeout);
Пример #4
0
 /// <summary>
 /// Executes the specified pattern and returns a series of outputs.
 /// </summary>
 /// <param name="input">The patten to execute.</param>
 /// <param name="seed">The seed to generate output with.</param>
 /// <param name="charLimit">
 /// The maximum number of characters that can be printed. An exception will be thrown if the limit
 /// is exceeded. Set to zero or below for unlimited characters.
 /// </param>
 /// <param name="timeout">The maximum number of seconds that the pattern will execute for.</param>
 /// <param name="args">The arguments to pass to the pattern.</param>
 /// <returns></returns>
 public IEnumerable <RantOutput> DoSerial(RantProgram input, long seed, int charLimit = 0, double timeout = -1,
                                          RantProgramArgs args = null) =>
 new Sandbox(this, input, new RNG(seed), charLimit, GetPreservedCarrierState(), args).RunSerial(timeout);
Пример #5
0
 /// <summary>
 /// Executes the specified pattern using a custom random number generator and returns the resulting output.
 /// </summary>
 /// <param name="input">The pattern to execute.</param>
 /// <param name="rng">The random number generator to use when generating output.</param>
 /// <param name="charLimit">
 /// The maximum number of characters that can be printed. An exception will be thrown if the limit
 /// is exceeded. Set to zero or below for unlimited characters.
 /// </param>
 /// <param name="timeout">The maximum number of seconds that the pattern will execute for.</param>
 /// <param name="args">The arguments to pass to the pattern.</param>
 /// <returns></returns>
 public RantOutput Do(RantProgram input, RNG rng, int charLimit = 0, double timeout = -1, RantProgramArgs args = null)
 =>
 RunVM(new Sandbox(this, input, rng, charLimit, GetPreservedCarrierState(), args), timeout);
Пример #6
0
 /// <summary>
 /// Loads the file located at the specified path and executes it using a custom seed, returning the resulting output.
 /// </summary>
 /// <param name="path">The path to the file to execute.</param>
 /// <param name="rng">The random number generator to use when generating output.</param>
 /// <param name="charLimit">
 /// The maximum number of characters that can be printed. An exception will be thrown if the limit
 /// is exceeded. Set to zero or below for unlimited characters.
 /// </param>
 /// <param name="timeout">The maximum number of seconds that the pattern will execute for.</param>
 /// <param name="args">The arguments to pass to the pattern.</param>
 /// <returns></returns>
 public RantOutput DoFile(string path, RNG rng, int charLimit = 0, double timeout = -1, RantProgramArgs args = null) =>
 RunVM(new Sandbox(this, RantProgram.CompileFile(path), rng, charLimit, GetPreservedCarrierState(), args), timeout);
Пример #7
0
 public RantOutput Do(string input, long seed, int charLimit = 0, double timeout = -1, RantProgramArgs args = null) =>
 RunVM(new Sandbox(this, RantProgram.CompileString(input), new RNG(seed), charLimit, GetPreservedCarrierState(), args),
       timeout);