ReleaseHandle() public static method

public static ReleaseHandle ( ContextHandle hnd ) : void
hnd ContextHandle
return void
Beispiel #1
0
        public int BackrackImpl(PlTerm a0, int arity, IntPtr control)
        {
            FRG           fc = (FRG)(libpl.PL_foreign_control(control));
            ContextHandle handle;

            switch (fc)
            {
            case FRG.PL_FIRST_CALL:
            {
                handle = NondetContextHandle.ObtainHandle(control, Clone());
                var av = new PlTermV(a0, arity);
                handle.ManagedObject = New(handle, av);
                return(Call0(handle, av));
            }
            break;

            case FRG.PL_REDO:
            {
                handle = NondetContextHandle.FindHandle(control);
                return(Call0(handle, new PlTermV(a0, arity)));
            }
            break;

            case FRG.PL_CUTTED:
            {
                handle = NondetContextHandle.FindHandle(control);
                var  av  = new PlTermV(a0, arity);
                bool res = Close(handle, av);
                NondetContextHandle.ReleaseHandle(handle);
                return(res ? 1 : 0);
            }
            break;

            default:
            {
                throw new PlException("no frg");
                return(libpl.PL_fail);
            }
            break;
            }
        }
Beispiel #2
0
        public static int cliAddEventHandler0(PlTerm clazzOrInstance, PlTerm memberSpec, PlTerm closureTerm, PlTerm blockOn, IntPtr control)
        {
            var handle = control;
            FRG fc     = (FRG)(libpl.PL_foreign_control(control));

            switch (fc)
            {
            case FRG.PL_FIRST_CALL:
            {
                object getInstance;
                Type   c;
                if (!GetInstanceAndType(clazzOrInstance, out getInstance, out c))
                {
                    return(PlSucceedOrFail(false));
                }
                Type[] paramz = null;
                if (!CheckBound(memberSpec, closureTerm))
                {
                    return(PlSucceedOrFail(false));
                }
                EventInfo fi = findEventInfo(memberSpec, c, ref paramz, BindingFlagsALL);
                if (fi == null)
                {
                    return(Error("Cant find event {0} on {1}", memberSpec, (object)c ?? clazzOrInstance) ? 3 : 0);
                }
                ClosureDelegate newClosureDelegate = new ClosureDelegate(fi, getInstance, closureTerm);
                var             v   = NondetContextHandle.ObtainHandle(control, newClosureDelegate);
                bool            res = v.Setup(new PlTermV(closureTerm, blockOn));
                blockOn.FromObject(newClosureDelegate);
                bool more = v.HasMore();
                if (more)
                {
                    libpl.PL_retry(v.Handle);
                    return(res ? 3 : 0);
                }
                return(res ? 1 : 0);
            } break;

            case FRG.PL_REDO:
            {
                var  v    = NondetContextHandle.FindHandle(control);
                bool res  = v.Call(new PlTermV(closureTerm, blockOn));
                bool more = v.HasMore();
                if (more)
                {
                    libpl.PL_retry(v.Handle);
                    return(res ? 3 : 0);
                }
                return(res ? 1 : 0);
            } break;

            case FRG.PL_CUTTED:
            {
                var  v   = NondetContextHandle.FindHandle(control);
                bool res = v.Close(new PlTermV(closureTerm, blockOn));
                NondetContextHandle.ReleaseHandle(v);
                return(res ? 1 : 0);
            } break;

            default:
            {
                throw new PlException("no frg");
                return(libpl.PL_fail);
            }
            break;
            }
        }