コード例 #1
0
ファイル: KitStd.cs プロジェクト: LayeLang/Laye
        private LayeObject Callback__require(LayeState state, LayeObject ths, params LayeObject[] args)
        {
            // Vars we need:
            LayeKit thisKit = null;
            string originalRequirePath = null;

            // Try to get these:
            if (args.Length < 2)
                throw new ArgumentException("args"); // TODO throw an exception in the state.

            thisKit = args[0] as LayeKit;
            originalRequirePath = (args[1] as LayeString)?.value;

            // Check if we succeeded:
            if (thisKit == null || originalRequirePath == null)
                throw new ArgumentException("kit || requirePath"); // TODO throw an exception in the state.

            // Get the name of the kit:

            // Load up the kit, or error if no kit can be found:
            LayeKit kit;
            switch (originalRequirePath)
            {
                case "std": kit = state.std; break;
                default:
                    // Determine the actual path to require:
                    var requirePath = originalRequirePath.Replace('.', '\\') + ".laye";
                    var newRequirePath = Path.Combine(thisKit.fileLocation, requirePath);
                    if (File.Exists(newRequirePath))
                    {
                        // Compile the kit and run it:
                        try
                        {
                            Compile(newRequirePath, null, out kit);
                        }
                        catch (CompilerException e)
                        {
                            e.log.Print();
                            throw e;
                        }
                        kit.Run(state);
                    }
                    else
                    {
                        state.RaiseException("Failed to load kit '{0}'.", originalRequirePath);
                        return NULL;
                    }
                    break;
            }

            // Load that kit into this kits global state:
            thisKit.Use(state, kit, originalRequirePath);

            // This is void.
            return NULL;
        }
コード例 #2
0
ファイル: KitStd.cs プロジェクト: LayeLang/Laye
 private LayeObject Callback__println(LayeState state, LayeObject ths, params LayeObject[] args)
 {
     var builder = new StringBuilder();
     for (var i = 0; i < args.Length; i++)
     {
         if (i > 0)
             builder.Append(" ");
         var value = args[i];
         builder.Append(value.ToString(state));
     }
     stdout.WriteLine(builder.ToString());
     return NULL;
 }
コード例 #3
0
ファイル: LayeGenerator.cs プロジェクト: LayeLang/Laye
 public abstract override LayeObject InvokeAsMethod(LayeState state, LayeObject ths, params LayeObject[] args);
コード例 #4
0
ファイル: LayeGenerator.cs プロジェクト: LayeLang/Laye
 /// <summary>
 /// Returns <c>true</c> if this generator resumed, even if the function returned, false if the resume failed.
 /// If result is <c>null</c>, either resuming failed or the generator died this cycle.
 /// </summary>
 /// <param name="state"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public abstract bool Resume(LayeState state, out LayeObject result);
コード例 #5
0
ファイル: LayeGenerator.cs プロジェクト: LayeLang/Laye
 public override LayeObject InvokeAsMethod(LayeState state, LayeObject ths, params LayeObject[] args)
 {
     var frame = state.stack.NewFrame(closure, ths, args);
     return new LayeClosureGenerator(frame, closure, ths);
 }
コード例 #6
0
ファイル: LayeGenerator.cs プロジェクト: LayeLang/Laye
 public override bool Resume(LayeState state, out LayeObject result)
 {
     if (!TryResume(state))
     {
         result = null;
         return false;
     }
     frame.yielded = false;
     state.Execute(frame, closure, ths);
     if (frame.yielded)
     {
         Suspend();
         result = frame.HasValue() ? frame.Pop() : Laye.NULL;
         return true;
     }
     Kill();
     result = null;
     return true;
 }
コード例 #7
0
ファイル: LayeGenerator.cs プロジェクト: LayeLang/Laye
 public LayeClosureGenerator(StackFrame frame, LayeClosure closure, LayeObject ths)
 {
     frame.gtor = this;
     this.frame = frame;
     this.closure = closure;
     this.ths = ths;
 }
コード例 #8
0
ファイル: LayeReference.cs プロジェクト: LayeLang/Laye
 public abstract void Store(LayeState state, LayeObject value);