-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
164 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
namespace NeuroSpeech.Positron.Core; | ||
|
||
public class AssemblyInfo: IJSProxy | ||
{ | ||
public AssemblyInfo(string name, | ||
AssemblyInfo? parent = null, | ||
Type? type = null | ||
) { | ||
this.Parent = parent; | ||
this.Name = name; | ||
this.Fullname = parent == null | ||
? this.Name | ||
: $"{parent.Fullname}.{this.Name}"; | ||
this.Type = type; | ||
|
||
//if (this.Parent != null) | ||
//{ | ||
// var c = this.Parent.Children ??= new Dictionary<string, AssemblyInfo>(); | ||
// // c[this.Name] = this; | ||
//} | ||
} | ||
|
||
public AssemblyInfo? Parent { get; } | ||
public string Name { get; } | ||
public string Fullname { get; } | ||
public Type? Type { get; } | ||
|
||
public Dictionary<string, AssemblyInfo>? Children { get; private set; } | ||
|
||
public Type Resolve(string name) | ||
{ | ||
if (Children == null) | ||
{ | ||
throw new InvalidOperationException($"Type {name} not found in {this.Fullname}"); | ||
} | ||
if(Children.TryGetValue(name, out var value)) | ||
{ | ||
if (value.Type != null) | ||
{ | ||
return value.Type; | ||
} | ||
} | ||
throw new InvalidOperationException($"Type {name} not found in {this.Fullname}"); | ||
} | ||
|
||
internal AssemblyInfo GetOrCreate(string token) | ||
{ | ||
this.Children ??= new(); | ||
return this.Children.GetOrCreate(token, (x) => new AssemblyInfo(x, this)); | ||
} | ||
|
||
internal void AddType(Type type) | ||
{ | ||
this.Children ??= new(); | ||
this.Children.Add(type.Name, new AssemblyInfo(type.Name, this, type)); | ||
} | ||
|
||
IJSValue IJSProxy.Get(IJSContext context, IJSValue @this, IList<IJSValue> args) | ||
{ | ||
|
||
var name = args[1].ToString()!; | ||
|
||
if (this.Children?.TryGetValue(name, out var av) ?? false) | ||
{ | ||
return context.Marshal(av); | ||
} | ||
|
||
|
||
throw new ArgumentException($"{name} not found in ${this.Fullname}"); | ||
} | ||
|
||
IJSValue IJSProxy.Set(IJSContext context, IJSValue @this, IList<IJSValue> args) | ||
{ | ||
return context.Undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace NeuroSpeech.Positron; | ||
|
||
public interface IJSProxy | ||
{ | ||
|
||
IJSValue Get(IJSContext context, IJSValue @this, IList<IJSValue> args); | ||
|
||
IJSValue Set(IJSContext context, IJSValue @this, IList<IJSValue> args); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace NeuroSpeech.Positron; | ||
|
||
public static class JSProxyExtensions | ||
{ | ||
|
||
public static IJSValue CreateProxy(this IJSContext context, IJSProxy proxy) | ||
{ | ||
var wrapped = context.Wrap(proxy); | ||
var trap = context.CreateObject(); | ||
trap["get"] = context.CreateBoundFunction(3, proxy.Get , "get"); | ||
trap["set"] = context.CreateBoundFunction(3, proxy.Set, "set"); | ||
return context["Proxy"].CreateNewInstance(wrapped, trap); | ||
} | ||
|
||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule yantra
updated
4 files