Skip to content

Commit

Permalink
Version 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperSphereStudio committed Dec 24, 2022
1 parent 22a5d23 commit 0be9a42
Show file tree
Hide file tree
Showing 153 changed files with 7,545 additions and 135 deletions.
6 changes: 6 additions & 0 deletions JuliadotNET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JuliadotNET", "JuliadotNET\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Sandbox\Sandbox.csproj", "{D2E7F1D3-BAC1-453D-A88C-06250415B832}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JuliadotNETTest", "JuliadotNETTest\JuliadotNETTest.csproj", "{9B099638-725B-441B-91EC-85BFE93A2ECD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +20,9 @@ Global
{D2E7F1D3-BAC1-453D-A88C-06250415B832}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D2E7F1D3-BAC1-453D-A88C-06250415B832}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D2E7F1D3-BAC1-453D-A88C-06250415B832}.Release|Any CPU.Build.0 = Release|Any CPU
{9B099638-725B-441B-91EC-85BFE93A2ECD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9B099638-725B-441B-91EC-85BFE93A2ECD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B099638-725B-441B-91EC-85BFE93A2ECD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B099638-725B-441B-91EC-85BFE93A2ECD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
5 changes: 4 additions & 1 deletion JuliadotNET.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<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>
&lt;/AssemblyExplorer&gt;</s:String>
<s:String x:Key="/Default/Environment/UnitTesting/UnitTestSessionStore/Sessions/=d7e47783_002D591f_002D4951_002D853a_002Dd4d47f18c9de/@EntryIndexedValue">&lt;SessionState ContinuousTestingMode="0" IsActive="True" Name="All tests from &amp;lt;JuliadotNETTest&amp;gt;" xmlns="urn:schemas-jetbrains-com:jetbrains-ut-session"&gt;&#xD;
&lt;Project Location="C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNETTest" Presentation="&amp;lt;JuliadotNETTest&amp;gt;" /&gt;&#xD;
&lt;/SessionState&gt;</s:String></wpf:ResourceDictionary>
Binary file modified JuliadotNET/bin/Debug/net6.0/JuliadotNET.dll
Binary file not shown.
Binary file modified JuliadotNET/bin/Debug/net6.0/JuliadotNET.pdb
Binary file not shown.
123 changes: 79 additions & 44 deletions JuliadotNET/generated/csharp/Core/JPrimitive.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@

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;
public static JModule BaseM, CoreM, MainM;
public static JType ModuleT, TypeT, FunctionT, MethodT, UnionT, IntegerT, AbstractFloatT, StringT, PtrT;
public static JType BoolT, CharT, Float64T, Float32T, Float16T, Int64T, Int32T, Int16T, Int8T, UInt64T, UInt32T, UInt16T, UInt8T, ArrayT;
public static Any sprintF, showerrorF, catch_backtraceF, stringF, getpropertyF, setpropertyNotF, namesF, makentupleF, 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
export makearray, maketuple, writeSharpArray, maketuple, ieval, union_types, makentuple
function method_argnames(m::Method)
argnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), m.slot_syms)
isempty(argnames) && return argnames
Expand All @@ -20,13 +21,15 @@ function method_argnames(m::Method)
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
(makentuple(::Type{T}, n, p::Ptr{Cvoid}) where T) = begin
p2 = convert(Ptr{T}, p)
return ntuple((i->begin
unsafe_load(p2, i)
end), n)
end
linedEvaluation(s::String, file::String, m::Module) = begin
Core.eval(m, Meta.parseall(s, filename = file))
end
Expand All @@ -37,12 +40,11 @@ function writeSharpArray(p, arr)
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]");
fixed (Any* values = new Any[72]) {
var syms = Julia.Eval("[Base,Core,Main,sprint,showerror,catch_backtrace,string,getproperty,setproperty!,names,makentuple,writeSharpArray,maketuple,ieval,getindex,setindex!,length,iterate,Module,Type,Function,Method,Union,Integer,AbstractFloat,String,Ptr,==,!=,>,<,>=,<=,!,~,^,&,|,rem,*,+,-,/,>>,<<,typeof,hash,ismutable,isabstracttype,isimmutable,isprimitivetype,sizeof,parentmodule,nameof,fieldcount,fieldname,fieldoffset,fieldtype,Bool,Char,Float64,Float32,Float16,Int64,Int32,Int16,Int8,UInt64,UInt32,UInt16,UInt8,Array]");
writeSharpArray.Invoke(new Any(values), syms);

BaseM = values[0];
CoreM = values[1];
MainM = values[2];
Expand All @@ -51,52 +53,85 @@ function writeSharpArray(p, arr)
FunctionT = values[20];
MethodT = values[21];
UnionT = values[22];
IntegerT = values[23];
AbstractFloatT = values[24];
StringT = values[25];
PtrT = values[26];
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];
makentupleF = 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];
EqualityF = values[27];
InequalityF = values[28];
GreaterThanF = values[29];
LessThanF = values[30];
GreaterThanOrEqualF = values[31];
LessThanOrEqualF = values[32];
NotF = values[33];
OnesComplementF = values[34];
ExclusiveOrF = values[35];
BitwiseAndF = values[36];
BitwiseOrF = values[37];
ModulusF = values[38];
MultiplyF = values[39];
AdditionF = values[40];
SubtractionF = values[41];
DivisionF = values[42];
RightShiftF = values[43];
LeftShiftF = values[44];
typeofF = values[45];
hashF = values[46];
ismutableF = values[47];
isabstracttypeF = values[48];
isimmutableF = values[49];
isprimitivetypeF = values[50];
sizeofF = values[51];
parentmoduleF = values[52];
nameofF = values[53];
fieldcountF = values[54];
fieldnameF = values[55];
fieldoffsetF = values[56];
fieldtypeF = values[57];
BoolT = values[58];
CharT = values[59];
Float64T = values[60];
Float32T = values[61];
Float16T = values[62];
Int64T = values[63];
Int32T = values[64];
Int16T = values[65];
Int8T = values[66];
UInt64T = values[67];
UInt32T = values[68];
UInt16T = values[69];
UInt8T = values[70];
ArrayT = values[71];

RegisterPrimitive(typeof(bool), BoolT);
RegisterPrimitive(typeof(char), CharT);
RegisterPrimitive(typeof(double), Float64T);
RegisterPrimitive(typeof(float), Float32T);
RegisterPrimitive(typeof(Half), Float16T);
RegisterPrimitive(typeof(long), Int64T);
RegisterPrimitive(typeof(int), Int32T);
RegisterPrimitive(typeof(short), Int16T);
RegisterPrimitive(typeof(sbyte), Int8T);
RegisterPrimitive(typeof(ulong), UInt64T);
RegisterPrimitive(typeof(uint), UInt32T);
RegisterPrimitive(typeof(ushort), UInt16T);
RegisterPrimitive(typeof(byte), UInt8T);
RegisterPrimitive(typeof(Array), ArrayT);
}
}
}
Expand Down
50 changes: 40 additions & 10 deletions JuliadotNET/generators/csharp/Core/JPrimitive.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Used for Parser Validation
SharpModule = quote
export makearray, maketuple, writeSharpArray, maketuple, ieval
export makearray, maketuple, writeSharpArray, maketuple, ieval, union_types, makentuple

function method_argnames(m::Method)
argnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), m.slot_syms)
Expand All @@ -9,9 +9,10 @@ SharpModule = quote
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...)
makentuple(::Type{T}, n, p::Ptr{Cvoid}) where T = (p2 = convert(Ptr{T}, p); return ntuple(i -> unsafe_load(p2, i), n))
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)
Expand All @@ -25,13 +26,32 @@ eval(SharpModule)
symbols = [Base, Core, Main,
sprint, showerror, catch_backtrace, string,
getproperty, setproperty!, names,
makearray, writeSharpArray, maketuple, ieval,
makentuple, writeSharpArray, maketuple, ieval,
getindex, setindex!, length, iterate,
Module, Type, Function, Method, Union,
Module, Type, Function, Method, Union, Integer, AbstractFloat, String, Ptr,
==, !=, >, <, >=, <=, !, ~, ^, &, |, %, *, +, -, /, >>, <<,
typeof, hash,
ismutable, isabstracttype, isimmutable, isprimitivetype, sizeof, parentmodule, nameof,
fieldcount, fieldname, fieldoffset, fieldtype]

primitiveTypeConversions = [
Bool => "bool",
Char => "char",

Float64 => "double",
Float32 => "float",
Float16 => "Half",

Int64 => "long",
Int32 => "int",
Int16 => "short",
Int8 => "sbyte",
UInt64 => "ulong",
UInt32 => "uint",
UInt16 => "ushort",
UInt8 => "byte",
Array => "Array"
]

function generate_primitives(project_root, src_root, gen_root)

Expand Down Expand Up @@ -84,29 +104,39 @@ function generate_primitives(project_root, src_root, gen_root)
count += 1
end

count += 1
for v in primitiveTypeConversions
push!(symbols, v[1])
end

write_lines(kernel, array) = join(["$(kernel(m));" for m in array], "\n\t\t\t\t")

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 JModule $(join(["$(m[1])M" for m in modules], ", "));
public static JType $(join(["$(t[1])T" for t in types], ", "));
public static JType $(join(["$(t)T" for t in symbols[count:end]], ", "));
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]) {
fixed (Any* values = new Any[$(length(symbols))]) {
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"))
$(write_lines(m -> "$(m[1])M = values[$(m[2])]", modules))
$(write_lines(t -> "$(t[1])T = values[$(t[2])]", types))
$(write_lines(f -> "$(fix_name(f[1]))F = values[$(f[2])]", functions))
$(write_lines(i -> "$(symbols[i])T = values[$(i-1)]", count:length(symbols)))
$(write_lines(t -> "RegisterPrimitive(typeof($(t[2])), $(t[1])T)", primitiveTypeConversions))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8f184346a170cc6d6cce6b5e01e2d59d9359b3de
66b35ae081f7fc8cd1c57fe8437a9690c4b8d0be
Binary file modified JuliadotNET/obj/Debug/net6.0/JuliadotNET.dll
Binary file not shown.
Binary file modified JuliadotNET/obj/Debug/net6.0/JuliadotNET.pdb
Binary file not shown.
Binary file modified JuliadotNET/obj/Debug/net6.0/ref/JuliadotNET.dll
Binary file not shown.
Binary file modified JuliadotNET/obj/Debug/net6.0/refint/JuliadotNET.dll
Binary file not shown.
Loading

0 comments on commit 0be9a42

Please sign in to comment.