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
18 changes: 18 additions & 0 deletions Julia.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Sandbox\Sandbox.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{9B099638-725B-441B-91EC-85BFE93A2ECD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox48", "Sandbox48\Sandbox48.csproj", "{DF199950-742F-4DA3-9170-AF5B097CDE70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Julia.NETstandard", "Julia.NETstandard\Julia.NETstandard.csproj", "{614FED42-E1B9-4006-8D15-E96A974620FE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestStandard", "TestStandard\TestStandard.csproj", "{564E4007-4138-4E80-830C-B8106099B649}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -24,5 +30,17 @@ Global
{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
{DF199950-742F-4DA3-9170-AF5B097CDE70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF199950-742F-4DA3-9170-AF5B097CDE70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF199950-742F-4DA3-9170-AF5B097CDE70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF199950-742F-4DA3-9170-AF5B097CDE70}.Release|Any CPU.Build.0 = Release|Any CPU
{614FED42-E1B9-4006-8D15-E96A974620FE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{614FED42-E1B9-4006-8D15-E96A974620FE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{614FED42-E1B9-4006-8D15-E96A974620FE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{614FED42-E1B9-4006-8D15-E96A974620FE}.Release|Any CPU.Build.0 = Release|Any CPU
{564E4007-4138-4E80-830C-B8106099B649}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{564E4007-4138-4E80-830C-B8106099B649}.Debug|Any CPU.Build.0 = Debug|Any CPU
{564E4007-4138-4E80-830C-B8106099B649}.Release|Any CPU.ActiveCfg = Release|Any CPU
{564E4007-4138-4E80-830C-B8106099B649}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
29 changes: 29 additions & 0 deletions Julia.NETstandard/Julia.NETstandard.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>JuliadotNET</Title>
<Authors>Johnathan Bizzano</Authors>
<PackageProjectUrl>https://github.com/HyperSphereStudio/JULIAdotNET</PackageProjectUrl>
<PackageLicenseUrl>https://github.com/HyperSphereStudio/JULIAdotNET/blob/main/LICENSE</PackageLicenseUrl>
<RepositoryUrl>https://github.com/HyperSphereStudio/JULIAdotNET</RepositoryUrl>
<RootNamespace>JuliaNET</RootNamespace>
<LangVersion>10</LangVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lokad.ILPack" Version="0.1.7" />
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

</Project>
139 changes: 139 additions & 0 deletions Julia.NETstandard/generated/Core/JPrimitive.gen.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
using System;
using JuliaNET.Stdlib;

namespace JuliaNET.Core
{
public static partial class JPrimitive
{
public static JModule BaseM, CoreM, MainM;
public static JType ModuleT, TypeT, FunctionT, MethodT, UnionT, IntegerT, AbstractFloatT, StringT, PtrT, PermutedDimsArrayT;
public static JType BoolT, CharT, Float64T, Float32T, 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, union_types, makentuple
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
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
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[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,PermutedDimsArray,Bool,Char,Float64,Float32,Int64,Int32,Int16,Int8,UInt64,UInt32,UInt16,UInt8,Array]");
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];
IntegerT = values[23];
AbstractFloatT = values[24];
StringT = values[25];
PtrT = values[26];
PermutedDimsArrayT = values[58];
sprintF = values[3];
showerrorF = values[4];
catch_backtraceF = values[5];
stringF = values[6];
getpropertyF = values[7];
setpropertyNotF = values[8];
namesF = values[9];
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[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[59];
CharT = values[60];
Float64T = values[61];
Float32T = 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(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);
}
}
}
}
147 changes: 147 additions & 0 deletions Julia.NETstandard/generators/Core/JPrimitive.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
#Used for Parser Validation
SharpModule = quote
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
return [string(sym) for sym in argnames[1:m.nargs][2:end]]
end

ieval(mod::Module, ex) = Core.eval(mod, Meta.parse(ex))
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)
unsafe_store!(ptr, arr[i], i)
end
end
end

eval(SharpModule)

symbols = [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,
==, !=, >, <, >=, <=, !, ~, ^, &, |, %, *, +, -, /, >>, <<,
typeof, hash,
ismutable, isabstracttype, isimmutable, isprimitivetype, sizeof, parentmodule, nameof,
fieldcount, fieldname, fieldoffset, fieldtype, PermutedDimsArray]

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)

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

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

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

open("$gen_root/JPrimitive.gen.cs", "w") do io
write(io, """using System;
using JuliaNET.Stdlib;

namespace JuliaNET.Core
{
public static partial class JPrimitive
{
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[$(length(symbols))])
{
var syms = Julia.Eval(\"[$(join(symbols, ","))]\");
writeSharpArray.Invoke(new Any(values), syms);
$(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))
}
}
}
}""")
end
end
2 changes: 2 additions & 0 deletions Julia.NETstandard/generators/Generate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

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

project_root = pwd() * "/.."

generate_primitives(project_root, "$project_root/src/Core", "$project_root/generated/Core")
Loading