Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public RFiber LoadSourceCodeAsFiber(string source)
public MrbNativeBytesHandle CompileToBinaryFormat(ReadOnlySpan<byte> utf8Source) =>
CompileToBytecode(utf8Source);

public unsafe MrbNativeBytesHandle CompileToBytecode(string source) =>
CompileToBytecode(Encoding.UTF8.GetBytes(source));

public unsafe MrbNativeBytesHandle CompileToBytecode(ReadOnlySpan<byte> utf8Source)
{
var mrbPtr = compileStateHandle.DangerousGetPtr();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ namespace MRubyCS.Compiler
public class MrbNativeBytesHandle : SafeHandle
{
readonly MrbStateHandle stateHandle1;
readonly int length1;

internal MrbNativeBytesHandle(
MrbStateHandle stateHandle,
IntPtr ptr,
int length) : base(ptr, true)
{
stateHandle1 = stateHandle;
length1 = length;
Length = length;
}

public override bool IsInvalid => handle == IntPtr.Zero;
public int Length => length1;
public int Length { get; }

public unsafe ReadOnlySpan<byte> GetNativeData()
public unsafe ReadOnlySpan<byte> AsSpan()
{
return new ReadOnlySpan<byte>(DangerousGetHandle().ToPointer(), Length);
}
Expand Down
30 changes: 15 additions & 15 deletions src/MRubyCS/Internals/Operands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal struct Operand
[StructLayout(LayoutKind.Explicit)]
internal struct OperandZ
{
public static void Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static void Read(ref byte sequence, ref int pc)
{
pc += 1;
}
Expand All @@ -58,10 +58,10 @@ internal struct OperandB
[FieldOffset(0)]
public byte A;

public static OperandB Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandB Read(ref byte sequence, ref int pc)
{
pc += 2;
var result = Unsafe.ReadUnaligned<OperandB>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 1)));
var result = Unsafe.ReadUnaligned<OperandB>(ref Unsafe.Add(ref sequence, (pc - 1)));

return result;
}
Expand All @@ -76,10 +76,10 @@ internal struct OperandBB
[FieldOffset(1)]
public byte B;

public static OperandBB Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandBB Read(ref byte sequence, ref int pc)
{
pc += 3;
var result = Unsafe.ReadUnaligned<OperandBB>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 2)));
var result = Unsafe.ReadUnaligned<OperandBB>(ref Unsafe.Add(ref sequence, (pc - 2)));

return result;
}
Expand All @@ -95,10 +95,10 @@ internal unsafe struct OperandS
fixed byte bytesA[2];


public static OperandS Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandS Read(ref byte sequence, ref int pc)
{
pc += 3;
var result = Unsafe.ReadUnaligned<OperandS>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 2)));
var result = Unsafe.ReadUnaligned<OperandS>(ref Unsafe.Add(ref sequence, (pc - 2)));
result.A = (short)((result.bytesA[0] << 8) | result.bytesA[1]);
return result;
}
Expand All @@ -117,10 +117,10 @@ internal unsafe struct OperandBS
fixed byte bytesB[2];

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static OperandBS Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandBS Read(ref byte sequence, ref int pc)
{
pc += 4;
var result = Unsafe.ReadUnaligned<OperandBS>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 3)));
var result = Unsafe.ReadUnaligned<OperandBS>(ref Unsafe.Add(ref sequence, (pc - 3)));
result.B = (short)((result.bytesB[0] << 8) | result.bytesB[1]);
return result;
}
Expand All @@ -138,10 +138,10 @@ internal struct OperandBBB
[FieldOffset(2)]
public byte C;

public static OperandBBB Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandBBB Read(ref byte sequence, ref int pc)
{
pc += 4;
var result = Unsafe.ReadUnaligned<OperandBBB>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 3)));
var result = Unsafe.ReadUnaligned<OperandBBB>(ref Unsafe.Add(ref sequence, (pc - 3)));
return result;
}
}
Expand All @@ -165,10 +165,10 @@ internal unsafe struct OperandBSS
fixed byte bytesC[2];

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static OperandBSS Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandBSS Read(ref byte sequence, ref int pc)
{
pc += 6;
var result = Unsafe.ReadUnaligned<OperandBSS>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 5)));
var result = Unsafe.ReadUnaligned<OperandBSS>(ref Unsafe.Add(ref sequence, (pc - 5)));

result.B = (short)((result.bytesB[0] << 8) | result.bytesB[1]);
result.C = (short)((result.bytesC[0] << 8) | result.bytesC[1]);
Expand All @@ -183,10 +183,10 @@ internal unsafe struct OperandW
public int A => (Bytes[0] << 16) | (Bytes[1] << 8) | Bytes[2];

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static OperandW Read(in ReadOnlySpan<byte> sequence, ref int pc)
public static OperandW Read(ref byte sequence, ref int pc)
{
pc += 4;
var result = Unsafe.ReadUnaligned<OperandW>(ref Unsafe.Add(ref MemoryMarshal.GetReference(sequence), (pc - 3)));
var result = Unsafe.ReadUnaligned<OperandW>(ref Unsafe.Add(ref sequence, (pc - 3)));
return result;
}
}
2 changes: 2 additions & 0 deletions src/MRubyCS/Irep.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Runtime.CompilerServices;

namespace MRubyCS;

public enum CatchHandlerType : byte
Expand Down
Loading
Loading