Skip to content

Commit

Permalink
Merge pull request #231 from vein-lang/feature/partial-unsafe-logic
Browse files Browse the repository at this point in the history
BoehmGC & Upgrade multiple logic part to native unsafe (no classes, struct only)
  • Loading branch information
0xF6 authored May 18, 2024
2 parents 9d7588a + 57972c0 commit b2e3ac4
Show file tree
Hide file tree
Showing 105 changed files with 6,755 additions and 3,798 deletions.
13 changes: 5 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
target: linux-x64
install_deps: true
- os: windows-latest
target: win10-x64
target: win-x64
install_deps: false
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -39,7 +39,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100
dotnet-version: 8.0.100
- name: install pre-req
if: ${{ matrix.install_deps }}
run: sudo apt-get install clang zlib1g-dev libkrb5-dev libssl-dev
Expand All @@ -56,9 +56,6 @@ jobs:
- name: Build (Installer)
run: dotnet publish -r ${{ matrix.target }} -c Release --self-contained --output ./../out
working-directory: ./installer/
- name: Build (DCH)
run: dotnet publish -r ${{ matrix.target }} -c Release --self-contained --output ./../../out
working-directory: ./runtime/ishtar.dch/
- name: Upload artifacts
uses: actions/[email protected]
with:
Expand All @@ -83,7 +80,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100
dotnet-version: 8.0.100
- name: Install GitVersion
run: dotnet tool install --global --version 5.6.7 GitVersion.Tool
- name: Restore dependencies
Expand Down Expand Up @@ -113,7 +110,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100
dotnet-version: 8.0.100
- name: Restore dependencies
run: dotnet restore
- name: AOT build
Expand Down Expand Up @@ -151,7 +148,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.100-rc.1.21458.32
dotnet-version: 8.0.100
- name: Install DotCover
run: dotnet tool install --global JetBrains.dotCover.GlobalTool --version 2021.2.0-eap03
- name: Restore dependencies
Expand Down
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ insmvm.sln
/ALL_BUILD.vcxproj.filters

wave.std/bin/

bin/

!bin/gc.dll
Release/
*.*~

.idea/
Expand Down Expand Up @@ -75,4 +74,6 @@ installer/gen/blobs/
dotCover.Output.xml

# wtf
!logic.cs
!logic.cs


11 changes: 0 additions & 11 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,4 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>


<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Linux'))">
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<DefineConstants>$(DefineConstants);OSX</DefineConstants>
</PropertyGroup>
</Project>
Binary file added bin/gc.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion compiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
if (!skipIntro)
{
MarkupLine($"[grey]Vein Lang Compiler[/] [red]{AssemblySemFileVer}-{BranchName}+{ShortSha}[/]");
MarkupLine($"[grey]Copyright (C)[/] [cyan3]2023[/] [bold]Yuuki Wesp[/].\n\n");
MarkupLine($"[grey]Copyright (C)[/] [cyan3]2024[/] [bold]Yuuki Wesp[/].\n\n");
}


Expand Down
7 changes: 7 additions & 0 deletions runtime/common/exceptions/MethodAlreadyDefined.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public class FieldAlreadyDefined : Exception
public FieldAlreadyDefined(string msg) : base(msg)
{

}
}
public class ClassAlreadyDefined : Exception
{
public ClassAlreadyDefined(string msg) : base(msg)
{

}
}
}
8 changes: 6 additions & 2 deletions runtime/common/reflection/ClassFlags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace vein.runtime
[Flags]
public enum ClassFlags : short
{
None = 0 << 0,
None = 0,
Public = 1 << 1,
Static = 1 << 2,
Internal = 1 << 3,
Expand All @@ -14,6 +14,10 @@ public enum ClassFlags : short
Abstract = 1 << 6,
Special = 1 << 7,
Interface = 1 << 8,
Aspect = 1 << 9
Aspect = 1 << 9,
Undefined = 1 << 10,
Unresolved = 1 << 11,
Predefined = 1 << 12,
NotCompleted= 1 << 13
}
}
2 changes: 2 additions & 0 deletions runtime/common/reflection/TypeName.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public string NameWithNS
}
}

public string FullName => _fullName;

public QualityTypeName(string fullName) => this._fullName = fullName;

public QualityTypeName(string asmName, string name, string ns) : this($"{asmName}%{ns}/{name}")
Expand Down
12 changes: 6 additions & 6 deletions runtime/common/reflection/VeinMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,12 @@ namespace vein.runtime
public class VeinMethod : VeinMethodBase, IAspectable
{
public VeinClass ReturnType { get; set; }
public VeinClass Owner { get; protected set; }
public VeinClass Owner { get; protected internal set; }
public readonly Dictionary<int, VeinArgumentRef> Locals = new();
public List<Aspect> Aspects { get; } = new();

protected VeinMethod() : base(null, 0) { }

internal VeinMethod(string name, MethodFlags flags, VeinCore types, params VeinArgumentRef[] args)
: base(name, flags, args) =>
this.ReturnType = VeinTypeCode.TYPE_VOID.AsClass()(types);


internal VeinMethod(string name, MethodFlags flags, VeinClass returnType, VeinClass owner,
params VeinArgumentRef[] args)
: base(name, flags, args)
Expand Down Expand Up @@ -49,6 +45,10 @@ private string RegenerateName(string n) =>

public static string GetFullName(string name, IEnumerable<VeinArgumentRef> args)
=> $"{name}({args.Where(x => !x.Name.Equals(VeinArgumentRef.THIS_ARGUMENT)).Select(x => x.Type?.Name).Join(",")})";

public static string GetFullName(string name, IEnumerable<(string argName, string typeName)> args)
=> $"{name}({args.Where(x => !x.argName.Equals(VeinArgumentRef.THIS_ARGUMENT)).Select(x => x.typeName).Join(",")})";

public static string GetFullName(string name, IEnumerable<VeinClass> args)
=> $"{name}({args.Select(x => x.Name).Join(",")})";

Expand Down
2 changes: 1 addition & 1 deletion runtime/common/reflection/VeinModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class VeinModule
{
public VeinCore Types { get; }
public string Name { get; protected set; }
public Version Version { get; protected set; } = new(1, 0, 0, 0);
public Version Version { get; internal set; } = new(1, 0, 0, 0);
protected internal List<VeinModule> Deps { get; set; } = new();

internal VeinModule(string name, VeinCore types) => (Name, Types) = (name.AssertNotNull(), types);
Expand Down
64 changes: 10 additions & 54 deletions runtime/ishtar.base/emit/ILReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,18 @@ namespace ishtar.emit
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using global::ishtar;
using ishtar;
using vein.extensions;
using vein.runtime;

internal static unsafe class ILReader
public interface INamed
{
public static List<ProtectedZone> DeconstructExceptions(byte[] arr, int offset, VeinModule module)
{
if (arr.Length == 0)
return new();

using var mem = new MemoryStream(arr);
using var bin = new BinaryReader(mem);

mem.Seek(offset, SeekOrigin.Begin);

if (arr.Length == offset)
return new();

var magic = bin.ReadInt16();

if (magic != -0xFF1)
return new();

var size = bin.ReadInt32();

if (size == 0)
return new();
var result = new List<ProtectedZone>();

foreach (var i in ..size)
{
var startAddr = bin.ReadInt32();
var tryEndLabel = bin.ReadInt32();
var endAddr = bin.ReadInt32();
var filterAddr = bin.ReadIntArray();
var catchAddr = bin.ReadIntArray();
var catchClass = bin.ReadTypesArray(module);
var types = bin.ReadSpecialByteArray<ExceptionMarkKind>();
var item = new ProtectedZone(
(uint)startAddr,
(uint)endAddr,
tryEndLabel,
filterAddr,
catchAddr,
catchClass,
types);

result.Add(item);
}
string Name { get; }
}


return result;
}
internal static unsafe class ILReader
{
public static List<int> DeconstructLabels(byte[] arr, int* offset)
{
if (arr.Length == 0)
Expand Down Expand Up @@ -86,12 +42,12 @@ public static List<int> DeconstructLabels(byte[] arr, int* offset)
}
return result;
}
public static (List<uint> opcodes, Dictionary<int, (int pos, OpCodeValue opcode)> map) Deconstruct(byte[] arr, VeinMethod method)
public static (List<uint> opcodes, Dictionary<int, (int pos, OpCodeValue opcode)> map) Deconstruct(byte[] arr, INamed method)
{
var i = 0;
return Deconstruct(arr, &i, method);
}
public static (List<uint> opcodes, Dictionary<int, (int pos, OpCodeValue opcode)> map) Deconstruct(byte[] arr, int* offset, VeinMethod method)
public static (List<uint> opcodes, Dictionary<int, (int pos, OpCodeValue opcode)> map) Deconstruct(byte[] arr, int* offset, INamed method)
{
using var mem = new MemoryStream(arr);
using var bin = new BinaryReader(mem);
Expand Down Expand Up @@ -123,7 +79,7 @@ string PreviousValue(int index)
$"OpCode '{opcode}' is not found in metadata.\n" +
$"re-run 'gen.csx' for fix this error.\n" +
$"Previous values: '{PreviousValue(1)}, {PreviousValue(2)}, {PreviousValue(3)}'.\n" +
$"Method: '{method.Name}' in '{method.Owner.Name}'.");
$"Method: '{method.Name}'.");
var value = OpCodes.all[opcode];

d.Add((int)mem.Position - sizeof(ushort), (list.Count, opcode));
Expand Down
28 changes: 27 additions & 1 deletion runtime/ishtar.base/emit/ModuleReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,19 @@ public static QualityTypeName[] ReadTypesArray(this BinaryReader bin, VeinModule
return result.ToArray();
}

public static List<nint> ReadTypesArray(this BinaryReader bin, TypeNameGetter getter)
{
Debug.Assert(bin.ReadInt32() == 0x19, "[magic number] bin.ReadInt32() == 0x19");
var sign = bin.ReadIshtarString();
var size = bin.ReadInt32();
var result = new List<nint>();
foreach (int i in ..size)
result.Add(bin.ReadTypeName(getter));
Debug.Assert(bin.ReadInt32() == 0x61, "[magic number] bin.ReadInt32() == 0x61");
return result;
}


public static T[] ReadSpecialByteArray<T>(this BinaryReader bin) where T : Enum
{
Debug.Assert(bin.ReadInt32() == 0x19, "[magic number] bin.ReadInt32() == 0x19");
Expand All @@ -93,6 +106,19 @@ public static T[] ReadSpecialByteArray<T>(this BinaryReader bin) where T : Enum
return result.ToArray();
}

public static byte[] ReadSpecialDirectByteArray(this BinaryReader bin)
{
Debug.Assert(bin.ReadInt32() == 0x19, "[magic number] bin.ReadInt32() == 0x19");
var sign = bin.ReadIshtarString();
var size = bin.ReadInt32();
var result = new List<byte>();
foreach (int _ in ..size)
result.Add(bin.ReadByte());
Debug.Assert(bin.ReadInt32() == 0x61, "[magic number] bin.ReadInt32() == 0x61");
return result.ToArray();
}


public static void WriteArray<T>(this BinaryWriter bin, T[] arr, Action<T, BinaryWriter> selector, [CallerArgumentExpression("arr")] string name = "")
{
using (new MagicNumberArmor(bin))
Expand Down Expand Up @@ -351,7 +377,7 @@ private static List<VeinArgumentRef> ReadArguments(BinaryReader binary, ModuleRe
}
return args;
}
public ModuleReader(VeinCore types) : base(null, types)
public ModuleReader(VeinCore types) : base(".unnamed", types)
{
}
}
Expand Down
12 changes: 0 additions & 12 deletions runtime/ishtar.base/emit/ProtectedZone.cs

This file was deleted.

9 changes: 9 additions & 0 deletions runtime/ishtar.base/emit/extensions/QualityTypeEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace ishtar.emit.extensions
using System.IO;
using vein.runtime;


public delegate nint TypeNameGetter(int typeIndex);
public static class QualityTypeEx
{
public static QualityTypeName ReadTypeName(this BinaryReader bin, VeinModule module)
Expand All @@ -15,6 +17,13 @@ public static QualityTypeName ReadTypeName(this BinaryReader bin, VeinModule mod
throw new Exception($"TypeName by index '{typeIndex}' not found in '{module.Name}' module.");
}

public static nint ReadTypeName(this BinaryReader bin, TypeNameGetter getter)
{
var typeIndex = bin.ReadInt32();

return getter(typeIndex);
}

public static void WriteTypeName(this BinaryWriter bin, QualityTypeName type, VeinModuleBuilder module)
{
var key = module.InternTypeName(type);
Expand Down
Loading

0 comments on commit b2e3ac4

Please sign in to comment.