Skip to content

[Discussion] Using ldftn and calli to call X# methods from managed code #73

Open

Description

@jp2masa

I think it would be interesting to call X# methods from IL (C#) using ldftn/calli. The assembler plug would be replaced with managed code, which means better portability.

Example

public static void SendNumber(int number)
{
	ldarg.0
    ldftn
	calli
}

[XSharpMethod("DebugStub_SendSimpleNumber")]
private static void DoSendNumber(int number);

We just need to handle the attribute in ldftn, where we just emit push label.

Possible issues

  • In the debug stub assembler plugs, we currently ifdef the calls, because the debug stub may be disabled (i.e. it's not emitted), so we need to handle that somehow.
  • Calling conventions.

Activity

  1. fanoI commented on Feb 19, 2019

    @fanoI
    Contributor

    I think this would be a good idea to make things simpler.
    You could - for example - write the opcoded Execute part in "real" X# too using this method?

    A clarification I need only to write this:

    [XSharpMethod("DebugStub_SendSimpleNumber")]
    private static void DoSendNumber(int number);

    the stub method in C# will be generated automatically by IL2CPU?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions