Package Rakudo.Metamodel

Examples of Rakudo.Metamodel.Representation


    /// supports forwarding to the native code.
    /// </summary>
    /// <param name="Code"></param>
    public static RakudoObject WrapNativeMethod(RakudoCodeRef.IFunc_Body code)
    {
        Representation repr = REPRRegistry.get_REPR_by_name("KnowHOWREPR");
        RakudoObject wrapper = repr.type_object_for(null,null);
        wrapper.getSTable().SpecialInvoke = code;
        return wrapper;
    }
View Full Code Here


    /// <returns></returns>
    public static RakudoObject Bootstrap()
    {
        // Create our KnowHOW type object. Note we don't have a HOW
        // just yet, so pass in null.
        Representation REPR = REPRRegistry.get_REPR_by_name("KnowHOWREPR");
        RakudoObject KnowHOW = REPR.type_object_for(null,null);

        // We'll set up a dictionary of our various methods to go into
        // KnowHOW's HOW, since we'll want to work with them a bit.
        HashMap<String, RakudoObject> KnowHOWMeths = new HashMap<String, RakudoObject>();
        KnowHOWMeths.put("new_type", CodeObjectUtility.WrapNativeMethod( new RakudoCodeRef.IFunc_Body() { // C# has a lambda
            public RakudoObject Invoke(ThreadContext tc, RakudoObject ignored, RakudoObject capture)
            {
                // We first create a new HOW instance.
                RakudoObject knowHOWTypeObj = CaptureHelper.GetPositional(capture, 0);
                RakudoObject HOW = knowHOWTypeObj.getSTable().REPR.instance_of(tc, knowHOWTypeObj.getSTable().WHAT);

                // If we have a name arg, stash that value away.
                RakudoObject typeName = CaptureHelper.GetNamed(capture, "name");
                ((KnowHOWREPR.KnowHOWInstance)HOW).Name = typeName != null ? typeName : Ops.box_str(tc, "<anon>");

                // Now create a new type object to go with it of the
                // desired REPR; we default to P6opaque (note that the
                // KnowHOW repr only knows how to store a table of
                // methods and attributes, it can't be used for an
                // instance object that actually wants to store some
                // instance data).
                RakudoObject REPRName = CaptureHelper.GetNamed(capture, "repr");
                if (REPRName != null)
                {
                    // Look up the REPR.
                    Representation REPRToUse = REPRRegistry.get_REPR_by_name(Ops.unbox_str(null, REPRName));
                    return REPRToUse.type_object_for(null, HOW);
                }
                else
                {
                    // Just go with the P6opaque REPR.
                    return REPRRegistry.get_REPR_by_name("P6opaque").type_object_for(tc, HOW);
View Full Code Here

    /// </summary>
    /// <param name="Value"></param>
    /// <returns></returns>
    public static RakudoObject box_int(ThreadContext tc, int value, RakudoObject to)
    {
        Representation REPR = to.getSTable().REPR;
        RakudoObject result = REPR.instance_of(tc, to);
        REPR.set_int(tc, result, value);
        return result;
    }
View Full Code Here

    /// </summary>
    /// <param name="Value"></param>
    /// <returns></returns>
    public static RakudoObject box_num(ThreadContext tc, double value, RakudoObject to)
    {
        Representation REPR = to.getSTable().REPR;
        RakudoObject result = REPR.instance_of(tc, to);
        REPR.set_num(tc, result, value);
        return result;
    }
View Full Code Here

    /// </summary>
    /// <param name="Value"></param>
    /// <returns></returns>
    public static RakudoObject box_str(ThreadContext tc, String value, RakudoObject to)
    {
        Representation REPR = to.getSTable().REPR;
        RakudoObject result = REPR.instance_of(tc, to);
        REPR.set_str(tc, result, value);
        return result;
    }
View Full Code Here

TOP

Related Classes of Rakudo.Metamodel.Representation

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.