Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
HyperSphereStudio committed Nov 23, 2022
1 parent cacf527 commit 0b0303f
Show file tree
Hide file tree
Showing 30 changed files with 338 additions and 28 deletions.
99 changes: 99 additions & 0 deletions JuliadotNET/bin/Debug/net5.0/JuliadotNET.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,59 @@
"targets": {
".NETCoreApp,Version=v5.0": {
"JuliadotNET/1.0.0": {
"dependencies": {
"Lokad.ILPack": "0.2.0"
},
"runtime": {
"JuliadotNET.dll": {}
}
},
"Lokad.ILPack/0.2.0": {
"dependencies": {
"System.Reflection.Emit": "4.7.0",
"System.Reflection.Emit.Lightweight": "4.7.0",
"System.Reflection.Metadata": "6.0.1"
},
"runtime": {
"lib/netstandard2.0/Lokad.ILPack.dll": {
"assemblyVersion": "0.2.0.0",
"fileVersion": "0.2.0.0"
}
}
},
"System.Collections.Immutable/6.0.0": {
"dependencies": {
"System.Memory": "4.5.4",
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
},
"runtime": {
"lib/netstandard2.0/System.Collections.Immutable.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
},
"System.Memory/4.5.4": {},
"System.Reflection.Emit/4.7.0": {},
"System.Reflection.Emit.Lightweight/4.7.0": {},
"System.Reflection.Metadata/6.0.1": {
"dependencies": {
"System.Collections.Immutable": "6.0.0"
},
"runtime": {
"lib/netstandard2.0/System.Reflection.Metadata.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.322.12309"
}
}
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {
"runtime": {
"lib/netcoreapp3.1/System.Runtime.CompilerServices.Unsafe.dll": {
"assemblyVersion": "6.0.0.0",
"fileVersion": "6.0.21.52210"
}
}
}
}
},
Expand All @@ -18,6 +68,55 @@
"type": "project",
"serviceable": false,
"sha512": ""
},
"Lokad.ILPack/0.2.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-V0IJGV9babksQEOBkp1PHgpUdkaMpSZIdywHFcfgAomzvnwAt/SX3Q0sySvraKYmn35Py0RMxthgft7162kegw==",
"path": "lokad.ilpack/0.2.0",
"hashPath": "lokad.ilpack.0.2.0.nupkg.sha512"
},
"System.Collections.Immutable/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-l4zZJ1WU2hqpQQHXz1rvC3etVZN+2DLmQMO79FhOTZHMn8tDRr+WU287sbomD0BETlmKDn0ygUgVy9k5xkkJdA==",
"path": "system.collections.immutable/6.0.0",
"hashPath": "system.collections.immutable.6.0.0.nupkg.sha512"
},
"System.Memory/4.5.4": {
"type": "package",
"serviceable": true,
"sha512": "sha512-1MbJTHS1lZ4bS4FmsJjnuGJOu88ZzTT2rLvrhW7Ygic+pC0NWA+3hgAen0HRdsocuQXCkUTdFn9yHJJhsijDXw==",
"path": "system.memory/4.5.4",
"hashPath": "system.memory.4.5.4.nupkg.sha512"
},
"System.Reflection.Emit/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-VR4kk8XLKebQ4MZuKuIni/7oh+QGFmZW3qORd1GvBq/8026OpW501SzT/oypwiQl4TvT8ErnReh/NzY9u+C6wQ==",
"path": "system.reflection.emit/4.7.0",
"hashPath": "system.reflection.emit.4.7.0.nupkg.sha512"
},
"System.Reflection.Emit.Lightweight/4.7.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-a4OLB4IITxAXJeV74MDx49Oq2+PsF6Sml54XAFv+2RyWwtDBcabzoxiiJRhdhx+gaohLh4hEGCLQyBozXoQPqA==",
"path": "system.reflection.emit.lightweight/4.7.0",
"hashPath": "system.reflection.emit.lightweight.4.7.0.nupkg.sha512"
},
"System.Reflection.Metadata/6.0.1": {
"type": "package",
"serviceable": true,
"sha512": "sha512-III/lNMSn0ZRBuM9m5Cgbiho5j81u0FAEagFX5ta2DKbljZ3T0IpD8j+BIiHQPeKqJppWS9bGEp6JnKnWKze0g==",
"path": "system.reflection.metadata/6.0.1",
"hashPath": "system.reflection.metadata.6.0.1.nupkg.sha512"
},
"System.Runtime.CompilerServices.Unsafe/6.0.0": {
"type": "package",
"serviceable": true,
"sha512": "sha512-/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg==",
"path": "system.runtime.compilerservices.unsafe/6.0.0",
"hashPath": "system.runtime.compilerservices.unsafe.6.0.0.nupkg.sha512"
}
}
}
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.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
b788ab83789ad9acf7978c9e1c96e986ea9b7be1
b4696e5d14df4e6ff0d7fc4e121aef589b44613c
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ C:\Users\JohnB\Desktop\HyperProjects\JuliadotNET\JuliadotNET\obj\Debug\net5.0\Ju
C:\Users\JohnB\Desktop\HyperProjects\JuliadotNET\JuliadotNET\obj\Debug\net5.0\refint\JuliadotNET.dll
C:\Users\JohnB\Desktop\HyperProjects\JuliadotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.pdb
C:\Users\JohnB\Desktop\HyperProjects\JuliadotNET\JuliadotNET\obj\Debug\net5.0\ref\JuliadotNET.dll
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\bin\Debug\net5.0\JuliadotNET.deps.json
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\bin\Debug\net5.0\JuliadotNET.dll
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\bin\Debug\net5.0\JuliadotNET.pdb
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.csproj.AssemblyReference.cache
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.GeneratedMSBuildEditorConfig.editorconfig
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.AssemblyInfoInputs.cache
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.AssemblyInfo.cs
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.csproj.CoreCompileInputs.cache
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.dll
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\refint\JuliadotNET.dll
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\JuliadotNET.pdb
C:\Users\JohnB\Desktop\HyperProjects\HExcel\JULIAdotNET\JuliadotNET\obj\Debug\net5.0\ref\JuliadotNET.dll
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.
14 changes: 10 additions & 4 deletions JuliadotNET/src/csharp/Core/JPrimitive.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using Base;

namespace JULIAdotNET
{
public static class JPrimitive
{
public static Any Base, Core, Main, Meta;
public static Any BaseM, CoreM, MainM, MetaM;
public static Any SprintF, ShowErrorF, StringF, GetPropertyF, SetPropertyF,
CatchBackTraceF, MakeArrayF, GetIndexF, SetIndexF, NamesF, LengthF, IterateF;
CatchBackTraceF, MakeArrayF, GetIndexF, SetIndexF, NamesF, LengthF, IterateF,

EqualsF, NEqualsF, GreaterThenF, LessThenF, GreaterThenOrEqualF, LessThenOrEqualF,

NotF, TildeF, CaretF, AmpersandF, PipeF, PercentF, MultF, AddF, SubF, DivF, RightShiftF, LeftShiftF,

GetTypeF;

public static Any ModuleT, TypeT, FunctionT, MethodT;
private static readonly Dictionary<Type, Any> Sharp2Julia = new();
private static readonly Dictionary<Any, Type> Julia2Sharp = new();

Expand All @@ -18,6 +25,5 @@ internal static void RegisterPrimitive(Type t, Any type) {
Julia2Sharp.Add(type, t);
}


}
}
9 changes: 5 additions & 4 deletions JuliadotNET/src/csharp/Core/Julia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.InteropServices;
using System.Text;
using Base;
using System.Runtime.CompilerServices;

//Written by Johnathan Bizzano
namespace JULIAdotNET
Expand Down Expand Up @@ -55,7 +56,7 @@ internal static void Init(JuliaOptions options, bool sharpInit) {
}
}

public static bool Isa(Any v, Any t) => JuliaCalls.jl_isa(v, t) != 0;
[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static bool Isa(Any v, Any t) => JuliaCalls.jl_isa(v, t) != 0;

public static void SetGlobal(Any m, string sym, Any val) => SetGlobal(m, JuliaCalls.jl_symbol(sym), val);
public static void SetGlobal(Any m, Any sym, Any val){
Expand All @@ -72,7 +73,8 @@ public static Any GetGlobal(Any m, Any sym)

public static Any GetGlobal(Any m, string sym) => GetGlobal(m, JuliaCalls.jl_symbol(sym));

public static void CheckExceptions() {

[MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static void CheckExceptions() {
if (JuliaCalls.jl_exception_occurred() != IntPtr.Zero)
throw new JuliaException(JuliaCalls.jl_exception_occurred());
}
Expand Down Expand Up @@ -107,11 +109,10 @@ public static void POP_GC(){
public static Any BoxPtr(IntPtr ptr) => new(JuliaCalls.jl_box_voidpointer(ptr));
public static unsafe Any AllocStruct(Any type, Span<Any> vals) => JuliaCalls.jl_new_structv(type, vals.ToPointer(), (uint) vals.Length);

internal static string MString(IntPtr p) {
private static string MString(IntPtr p) {
CheckExceptions();
return Marshal.PtrToStringAnsi(p);
}

}


Expand Down
44 changes: 38 additions & 6 deletions JuliadotNET/src/csharp/Core/JuliaBoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ function getprimitivetypes(p::Ptr{Cvoid})
_makearray,
getindex, setindex!, length, iterate]
getindex, setindex!, length, iterate,
Module, Type, Function, Method,
==, !=, >, <, >=, <=, !, ~, ^, &, |, %, *, +, -, /, >>, <<,
typeof]
for i in eachindex(array)
unsafe_store!(ptr, array[i], i)
Expand All @@ -124,13 +130,13 @@ function getprimitivetypes(p::Ptr{Cvoid})
end
");

fixed (Any* values = stackalloc Any[16]) {
fixed (Any* values = stackalloc Any[39]) {
Julia.GetGlobal(sharp, "getprimitivetypes").Invoke(new Any(values));

JPrimitive.Base = values[0];
JPrimitive.Core = values[1];
JPrimitive.Main = values[2];
JPrimitive.Meta = values[3];
JPrimitive.BaseM = values[0];
JPrimitive.CoreM = values[1];
JPrimitive.MainM = values[2];
JPrimitive.MetaM = values[3];

JPrimitive.SprintF = values[4];
JPrimitive.ShowErrorF = values[5];
Expand All @@ -145,6 +151,32 @@ function getprimitivetypes(p::Ptr{Cvoid})
JPrimitive.SetIndexF = values[13];
JPrimitive.LengthF = values[14];
JPrimitive.IterateF = values[15];

JPrimitive.ModuleT = values[16];
JPrimitive.TypeT = values[17];
JPrimitive.FunctionT = values[18];
JPrimitive.MethodT = values[19];

JPrimitive.EqualsF = values[20];
JPrimitive.NEqualsF = values[21];
JPrimitive.GreaterThenF = values[22];
JPrimitive.LessThenF = values[23];
JPrimitive.GreaterThenOrEqualF = values[24];
JPrimitive.LessThenOrEqualF = values[25];
JPrimitive.NotF = values[26];
JPrimitive.TildeF = values[27];
JPrimitive.CaretF = values[28];
JPrimitive.AmpersandF = values[29];
JPrimitive.PipeF = values[30];
JPrimitive.PercentF = values[31];
JPrimitive.MultF = values[32];
JPrimitive.AddF = values[33];
JPrimitive.SubF = values[34];
JPrimitive.DivF = values[35];
JPrimitive.RightShiftF = values[36];
JPrimitive.LeftShiftF = values[37];

JPrimitive.GetTypeF = values[38];
}
}
}
Expand Down
25 changes: 17 additions & 8 deletions JuliadotNET/src/csharp/Statics/JuliaParser.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
using System;
using JULIAdotNET;
using JULIAdotNET;
using Base;
using runtime.ILCompiler;
using System.Reflection;
using System.Reflection.Emit;

namespace JuliadotNET.csharp.Statics
{
namespace JuliadotNET.csharp.Statics {
public class JuliaParser {

public static void GenerateStaticLibrary(Any module, string libPath) {
var modName = module.ToString();
var asm = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName(modName), AssemblyBuilderAccess.Run);
GenerateModule(asm.DefineDynamicModule(modName), module);
new Lokad.ILPack.AssemblyGenerator().GenerateAssembly(asm, libPath);
}


private static void GenerateModule(ModuleBuilder mb, Any module) {
var modTy = new ILTypeBuilder(mb.DefineType(module.ToString(), TypeAttributes.Class));

var names = JPrimitive.NamesF.Invoke(module);
foreach(var name in names) {
Console.WriteLine(name);
foreach(var name in JPrimitive.NamesF.Invoke(module)) {

}

modTy.Create();
}

}
}
32 changes: 30 additions & 2 deletions JuliadotNET/src/csharp/Stdlib/Any.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public bool MoveNext() {
return Index != IntPtr.Zero;
}

public void Reset() => _state = JPrimitive.IterateF.Invoke(_ptr);
public void Reset() => _state = IntPtr.Zero;
public Any Current => _state[1];
object IEnumerator.Current => Current;
public void Dispose(){}
Expand Down Expand Up @@ -255,9 +255,37 @@ public Any this[Any idx] {
set => JPrimitive.SetIndexF.UnsafeInvoke(stackalloc Any[]{ptr, value, i1, i2, i3, i4});
}
#endregion

#region UsefulFunctions
public int Length => (int) JPrimitive.LengthF.UnsafeInvoke(this);
public bool Is(Any ty) => Julia.Isa(this, ty);
#endregion
#region Comparison

public static bool operator ==(Any v, IntPtr p) => v.ptr == p;
public static bool operator !=(Any v, IntPtr p) => v.ptr != p;
public static bool operator ==(IntPtr p, Any v) => v.ptr == p;
public static bool operator !=(IntPtr p, Any v) => v.ptr != p;
public static bool operator ==(Any v, Any v2) => (bool) JPrimitive.EqualsF.Invoke(v, v2);
public static bool operator !=(Any v, Any v2) => (bool) JPrimitive.NEqualsF.Invoke(v, v2);
public static bool operator >(Any v, Any v2) => (bool) JPrimitive.GreaterThenF.Invoke(v, v2);
public static bool operator <(Any v, Any v2) => (bool) JPrimitive.LessThenF.Invoke(v, v2);
public static bool operator >=(Any v, Any v2) => (bool) JPrimitive.GreaterThenOrEqualF.Invoke(v, v2);
public static bool operator <=(Any v, Any v2) => (bool) JPrimitive.LessThenOrEqualF.Invoke(v, v2);
public static Any operator !(Any v) => (bool)JPrimitive.NotF.Invoke(v);
#endregion
#region Math
public static Any operator ~(Any v) => JPrimitive.TildeF.Invoke(v);
public static Any operator ^(Any v, Any v2) => JPrimitive.CaretF.Invoke(v, v2);
public static Any operator &(Any v, Any v2) => JPrimitive.AmpersandF.Invoke(v, v2);
public static Any operator |(Any v, Any v2) => JPrimitive.PipeF.Invoke(v, v2);
public static Any operator %(Any v, Any v2) => JPrimitive.PercentF.Invoke(v, v2);
public static Any operator *(Any v, Any v2) => JPrimitive.MultF.Invoke(v, v2);
public static Any operator +(Any v, Any v2) => JPrimitive.AddF.Invoke(v, v2);
public static Any operator -(Any v, Any v2) => JPrimitive.SubF.Invoke(v, v2);
public static Any operator /(Any v, Any v2) => JPrimitive.DivF.Invoke(v, v2);
public static Any operator >>(Any v, int n) => JPrimitive.RightShiftF.Invoke(v, n);
public static Any operator <<(Any v, int n) => JPrimitive.LeftShiftF.Invoke(v, n);

#endregion

public override string ToString() => ptr == IntPtr.Zero ? "null" : JPrimitive.StringF.Invoke1(this).UnboxString();
Expand Down
3 changes: 2 additions & 1 deletion Sandbox/Program.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
using System;
using JULIAdotNET;
using Base;

namespace Sandbox
{
class Program {
static void Main(string[] args) {
try {
Julia.Init();

Console.WriteLine(new Any(24) * 4 + 8);
Julia.Exit();
}catch (Exception e) {
e.Print();
Expand Down
Binary file modified Sandbox/bin/Debug/net5.0/JuliadotNET.dll
Binary file not shown.
Binary file modified Sandbox/bin/Debug/net5.0/JuliadotNET.pdb
Binary file not shown.
Binary file added Sandbox/bin/Debug/net5.0/Lokad.ILPack.dll
Binary file not shown.
Loading

0 comments on commit 0b0303f

Please sign in to comment.