Skip to content

Commit

Permalink
Version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperSphereStudio committed Dec 5, 2022
1 parent 0b0303f commit 22a5d23
Show file tree
Hide file tree
Showing 103 changed files with 1,243 additions and 1,031 deletions.
4 changes: 4 additions & 0 deletions JuliadotNET.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/AssemblyExplorer/XmlDocument/@EntryValue">&lt;AssemblyExplorer&gt;&#xD;
&lt;Assembly Path="C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0\ref\net5.0\System.Runtime.dll" /&gt;&#xD;
&lt;/AssemblyExplorer&gt;</s:String></wpf:ResourceDictionary>
4 changes: 2 additions & 2 deletions JuliadotNET/JuliadotNET.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<Title>JuliadotNET</Title>
<Authors>Johnathan Bizzano</Authors>
<PackageProjectUrl>https://github.com/HyperSphereStudio/JULIAdotNET</PackageProjectUrl>
Expand All @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Lokad.ILPack" Version="0.2.0" />
<PackageReference Include="Lokad.ILPack" Version="0.1.7" />
</ItemGroup>

</Project>
32 changes: 31 additions & 1 deletion JuliadotNET/bin/Debug/net5.0/JuliadotNET.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
".NETCoreApp,Version=v5.0": {
"JuliadotNET/1.0.0": {
"dependencies": {
"Lokad.ILPack": "0.2.0"
"Lokad.ILPack": "0.2.0",
"System.Runtime": "4.3.1"
},
"runtime": {
"JuliadotNET.dll": {}
Expand All @@ -27,6 +28,8 @@
}
}
},
"Microsoft.NETCore.Platforms/1.1.1": {},
"Microsoft.NETCore.Targets/1.1.3": {},
"System.Collections.Immutable/6.0.0": {
"dependencies": {
"System.Memory": "4.5.4",
Expand All @@ -53,6 +56,12 @@
}
}
},
"System.Runtime/4.3.1": {
"dependencies": {
"Microsoft.NETCore.Platforms": "1.1.1",
"Microsoft.NETCore.Targets": "1.1.3"
}
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {
"runtime": {
"lib/netcoreapp3.1/System.Runtime.CompilerServices.Unsafe.dll": {
Expand All @@ -76,6 +85,20 @@
"path": "lokad.ilpack/0.2.0",
"hashPath": "lokad.ilpack.0.2.0.nupkg.sha512"
},
"Microsoft.NETCore.Platforms/1.1.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-TMBuzAHpTenGbGgk0SMTwyEkyijY/Eae4ZGsFNYJvAr/LDn1ku3Etp3FPxChmDp5HHF3kzJuoaa08N0xjqAJfQ==",
"path": "microsoft.netcore.platforms/1.1.1",
"hashPath": "microsoft.netcore.platforms.1.1.1.nupkg.sha512"
},
"Microsoft.NETCore.Targets/1.1.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-3Wrmi0kJDzClwAC+iBdUBpEKmEle8FQNsCs77fkiOIw/9oYA07bL1EZNX0kQ2OMN3xpwvl0vAtOCYY3ndDNlhQ==",
"path": "microsoft.netcore.targets/1.1.3",
"hashPath": "microsoft.netcore.targets.1.1.3.nupkg.sha512"
},
"System.Collections.Immutable/6.0.0": {
"type": "package",
"serviceable": true,
Expand Down Expand Up @@ -111,6 +134,13 @@
"path": "system.reflection.metadata/6.0.1",
"hashPath": "system.reflection.metadata.6.0.1.nupkg.sha512"
},
"System.Runtime/4.3.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-abhfv1dTK6NXOmu4bgHIONxHyEqFjW8HwXPmpY9gmll+ix9UNo4XDcmzJn6oLooftxNssVHdJC1pGT9jkSynQg==",
"path": "system.runtime/4.3.1",
"hashPath": "system.runtime.4.3.1.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {
"type": "package",
"serviceable": true,
Expand Down
Binary file modified JuliadotNET/bin/Debug/net5.0/JuliadotNET.dll
Binary file not shown.
Binary file modified JuliadotNET/bin/Debug/net5.0/JuliadotNET.pdb
Binary file not shown.
41 changes: 41 additions & 0 deletions JuliadotNET/bin/Debug/net6.0/JuliadotNET.deps.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v6.0",
"signature": ""
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v6.0": {
"JuliadotNET/1.0.0": {
"dependencies": {
"Lokad.ILPack": "0.1.7"
},
"runtime": {
"JuliadotNET.dll": {}
}
},
"Lokad.ILPack/0.1.7": {
"runtime": {
"lib/netcoreapp2.1/Lokad.ILPack.dll": {
"assemblyVersion": "0.1.7.0",
"fileVersion": "0.1.7.0"
}
}
}
}
},
"libraries": {
"JuliadotNET/1.0.0": {
"type": "project",
"serviceable": false,
"sha512": ""
},
"Lokad.ILPack/0.1.7": {
"type": "package",
"serviceable": true,
"sha512": "sha512-0tNM0zh0zJcjHUt/PHqgeML7OoWof0tiltGLcX2zur8Kjildye01X/RDwTt4Fxru5uIGXQvGHWqkWicvHmpcaQ==",
"path": "lokad.ilpack/0.1.7",
"hashPath": "lokad.ilpack.0.1.7.nupkg.sha512"
}
}
}
Binary file added JuliadotNET/bin/Debug/net6.0/JuliadotNET.dll
Binary file not shown.
Binary file added JuliadotNET/bin/Debug/net6.0/JuliadotNET.pdb
Binary file not shown.
103 changes: 103 additions & 0 deletions JuliadotNET/generated/csharp/Core/JPrimitive.gen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using Base;

namespace JULIAdotNET{
public static partial class JPrimitive {
public static Any BaseM, CoreM, MainM;
public static JType ModuleT, TypeT, FunctionT, MethodT, UnionT;
public static Any sprintF, showerrorF, catch_backtraceF, stringF, getpropertyF, setpropertyNotF, namesF, makearrayF, writeSharpArrayF, maketupleF, ievalF, getindexF, setindexNotF, lengthF, iterateF, EqualityF, InequalityF, GreaterThanF, LessThanF, GreaterThanOrEqualF, LessThanOrEqualF, NotF, OnesComplementF, ExclusiveOrF, BitwiseAndF, BitwiseOrF, ModulusF, MultiplyF, AdditionF, SubtractionF, DivisionF, RightShiftF, LeftShiftF, typeofF, hashF, ismutableF, isabstracttypeF, isimmutableF, isprimitivetypeF, sizeofF, parentmoduleF, nameofF, fieldcountF, fieldnameF, fieldoffsetF, fieldtypeF;

internal static unsafe void primitive_init() {

Julia.Eval(@"module SharpModule begin
export makearray, maketuple, writeSharpArray, maketuple, ieval
function method_argnames(m::Method)
argnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), m.slot_syms)
isempty(argnames) && return argnames
return [string(sym) for sym = (argnames[1:m.nargs])[2:end]]
end
ieval(mod::Module, ex) = begin
Core.eval(mod, Meta.parse(ex))
end
makearray(T::Type, dims::Ptr{Cvoid}, len::Int32) = begin
ptr = convert(Ptr{Int32}, dims)
Array{T}(undef, [unsafe_load(ptr, i) for i = 1:len]...)
end
maketuple(vals...) = begin
tuple(vals...)
end
linedEvaluation(s::String, file::String, m::Module) = begin
Core.eval(m, Meta.parseall(s, filename = file))
end
function writeSharpArray(p, arr)
ptr = convert(Ptr{Any}, p)
for i = eachindex(arr)
unsafe_store!(ptr, arr[i], i)
end
end
end end; using .SharpModule");

var writeSharpArray = Julia.Eval("writeSharpArray");
fixed (Any* values = new Any[54]) {
var syms = Julia.Eval("[Base,Core,Main,sprint,showerror,catch_backtrace,string,getproperty,setproperty!,names,makearray,writeSharpArray,maketuple,ieval,getindex,setindex!,length,iterate,Module,Type,Function,Method,Union,==,!=,>,<,>=,<=,!,~,^,&,|,rem,*,+,-,/,>>,<<,typeof,hash,ismutable,isabstracttype,isimmutable,isprimitivetype,sizeof,parentmodule,nameof,fieldcount,fieldname,fieldoffset,fieldtype]");
writeSharpArray.Invoke(new Any(values), syms);

BaseM = values[0];
CoreM = values[1];
MainM = values[2];
ModuleT = values[18];
TypeT = values[19];
FunctionT = values[20];
MethodT = values[21];
UnionT = values[22];
sprintF = values[3];
showerrorF = values[4];
catch_backtraceF = values[5];
stringF = values[6];
getpropertyF = values[7];
setpropertyNotF = values[8];
namesF = values[9];
makearrayF = values[10];
writeSharpArrayF = values[11];
maketupleF = values[12];
ievalF = values[13];
getindexF = values[14];
setindexNotF = values[15];
lengthF = values[16];
iterateF = values[17];
EqualityF = values[23];
InequalityF = values[24];
GreaterThanF = values[25];
LessThanF = values[26];
GreaterThanOrEqualF = values[27];
LessThanOrEqualF = values[28];
NotF = values[29];
OnesComplementF = values[30];
ExclusiveOrF = values[31];
BitwiseAndF = values[32];
BitwiseOrF = values[33];
ModulusF = values[34];
MultiplyF = values[35];
AdditionF = values[36];
SubtractionF = values[37];
DivisionF = values[38];
RightShiftF = values[39];
LeftShiftF = values[40];
typeofF = values[41];
hashF = values[42];
ismutableF = values[43];
isabstracttypeF = values[44];
isimmutableF = values[45];
isprimitivetypeF = values[46];
sizeofF = values[47];
parentmoduleF = values[48];
nameofF = values[49];
fieldcountF = values[50];
fieldnameF = values[51];
fieldoffsetF = values[52];
fieldtypeF = values[53];
}
}
}
}
2 changes: 2 additions & 0 deletions JuliadotNET/generators/Generate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

julia generators/Generator.jl
5 changes: 5 additions & 0 deletions JuliadotNET/generators/Generator.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include("csharp/Core/JPrimitive.jl")

project_root = pwd()

generate_primitives(project_root, "$project_root/src/csharp/Core", "$project_root/generated/csharp/Core")
116 changes: 116 additions & 0 deletions JuliadotNET/generators/csharp/Core/JPrimitive.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#Used for Parser Validation
SharpModule = quote
export makearray, maketuple, writeSharpArray, maketuple, ieval

function method_argnames(m::Method)
argnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), m.slot_syms)
isempty(argnames) && return argnames
return [string(sym) for sym in argnames[1:m.nargs][2:end]]
end

ieval(mod::Module, ex) = Core.eval(mod, Meta.parse(ex))
makearray(T::Type, dims::Ptr{Cvoid}, len::Int32) = (ptr = convert(Ptr{Int32}, dims); Array{T}(undef, [unsafe_load(ptr, i) for i in 1:len]...))
maketuple(vals...) = tuple(vals...)
linedEvaluation(s::String, file::String, m::Module) = Core.eval(m, Meta.parseall(s, filename=file))
function writeSharpArray(p, arr)
ptr = convert(Ptr{Any}, p)
for i in eachindex(arr)
unsafe_store!(ptr, arr[i], i)
end
end
end

eval(SharpModule)

symbols = [Base, Core, Main,
sprint, showerror, catch_backtrace, string,
getproperty, setproperty!, names,
makearray, writeSharpArray, maketuple, ieval,
getindex, setindex!, length, iterate,
Module, Type, Function, Method, Union,
==, !=, >, <, >=, <=, !, ~, ^, &, |, %, *, +, -, /, >>, <<,
typeof, hash,
ismutable, isabstracttype, isimmutable, isprimitivetype, sizeof, parentmodule, nameof,
fieldcount, fieldname, fieldoffset, fieldtype]

function generate_primitives(project_root, src_root, gen_root)

function write_expression(x)
buffer = IOBuffer()
Base.show_unquoted(buffer, Base.remove_linenums!(x))
return String(take!(buffer))
end

function fix_name(f)
f = replace(string(f),
"+" => "Addition",
"-" => "Subtraction",
"*" => "Multiply",
"/" => "Division",
"%" => "Modulus",
"rem" => "Modulus",
"^" => "ExclusiveOr",
"&" => "BitwiseAnd",
"|" => "BitwiseOr",
"<<" => "LeftShift",
">>" => "RightShift",
"==" => "Equality",
">=" => "GreaterThanOrEqual",
"<=" => "LessThanOrEqual",
">" => "GreaterThan",
"<" => "LessThan",
"!=" => "Inequality",
"--" => "Decrement",
"++" => "Increment",
"~" => "OnesComplement",
"!" => "Not")
f = replace(f, "!" => "")
return f
end

count = 0
modules = []
functions = []
types = []

for s in symbols
if s isa Module
push!(modules, (s, count))
elseif s isa Function
push!(functions, (s, count))
elseif s isa Type
push!(types, (s, count))
end
count += 1
end

open("$gen_root/JPrimitive.gen.cs", "w") do io
write(io, """using System;
using System.Collections.Generic;
using Base;
namespace JULIAdotNET{
public static partial class JPrimitive {
public static Any $(join(["$(m[1])M" for m in modules], ", "));
public static JType $(join(["$(t[1])T" for t in types], ", "));
public static Any $(join(["$(fix_name(f[1]))F" for f in functions], ", "));
internal static unsafe void primitive_init() {
Julia.Eval(@"module SharpModule $(write_expression(SharpModule)) end; using .SharpModule");
var writeSharpArray = Julia.Eval(\"writeSharpArray\");
fixed (Any* values = new Any[$count]) {
var syms = Julia.Eval(\"[$(join(symbols, ","))]\");
writeSharpArray.Invoke(new Any(values), syms);
$(join(["$(m[1])M = values[$(m[2])];" for m in modules], "\n\t\t\t\t"))
$(join(["$(t[1])T = values[$(t[2])];" for t in types], "\n\t\t\t\t"))
$(join(["$(fix_name(f[1]))F = values[$(f[2])];" for f in functions], "\n\t\t\t\t"))
}
}
}
}""")

end
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b4696e5d14df4e6ff0d7fc4e121aef589b44613c
2cfa2cfe14f642b688e1d6081380e6c3d799f222
Binary file modified JuliadotNET/obj/Debug/net5.0/JuliadotNET.dll
Binary file not shown.
Binary file modified JuliadotNET/obj/Debug/net5.0/JuliadotNET.pdb
Binary file not shown.
Binary file modified JuliadotNET/obj/Debug/net5.0/ref/JuliadotNET.dll
Binary file not shown.
Binary file modified JuliadotNET/obj/Debug/net5.0/refint/JuliadotNET.dll
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
23 changes: 23 additions & 0 deletions JuliadotNET/obj/Debug/net6.0/JuliadotNET.AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

[assembly: System.Reflection.AssemblyCompanyAttribute("Johnathan Bizzano")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyProductAttribute("JuliadotNET")]
[assembly: System.Reflection.AssemblyTitleAttribute("JuliadotNET")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/HyperSphereStudio/JULIAdotNET")]

// Generated by the MSBuild WriteCodeFragment class.

Loading

0 comments on commit 22a5d23

Please sign in to comment.