@skillstech/thunderlang 1.6.1 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -0
- package/README.md +10 -3
- package/dist/core.cjs +264 -47
- package/dist/index.cjs +9118 -1077
- package/dist/learn.cjs +1419 -90
- package/package.json +1 -1
- package/src/ai.mjs +2 -1
- package/src/atlas.mjs +2 -1
- package/src/behaviour.mjs +246 -0
- package/src/cli-main.mjs +3015 -0
- package/src/cli.mjs +9 -2799
- package/src/conflict.mjs +0 -0
- package/src/core/ThunderDotnet.cs +195 -0
- package/src/core/check.mjs +316 -10
- package/src/core/cli.mjs +67 -10
- package/src/core/csharp-run.mjs +29 -8
- package/src/core/diagnostics.mjs +12 -1
- package/src/core/engine-core.mjs +161 -20
- package/src/core/engine-values.mjs +1 -0
- package/src/core/engine.mjs +131 -7
- package/src/core/go-run.mjs +3 -2
- package/src/core/index.mjs +6 -2
- package/src/core/java-run.mjs +3 -3
- package/src/core/kind.mjs +45 -0
- package/src/core/lexer.mjs +16 -2
- package/src/core/parser.mjs +254 -22
- package/src/core/project-root.mjs +18 -0
- package/src/core/project.mjs +18 -18
- package/src/core/react-run.mjs +3 -3
- package/src/core/runtime-go/thunder_runtime.go +269 -1
- package/src/core/runtime-npm.mjs +79 -0
- package/src/core/runtime-python.mjs +365 -3
- package/src/core/runtime-react.mjs +2 -1
- package/src/core/runtime-typescript.mjs +155 -6
- package/src/core/rust-run.mjs +3 -2
- package/src/core/serving.mjs +12 -0
- package/src/core/store-format.mjs +110 -0
- package/src/core/target-csharp.mjs +5 -1
- package/src/core/target-go.mjs +11 -4
- package/src/core/target-python.mjs +39 -6
- package/src/core/target-rust.mjs +1 -1
- package/src/core/target-typescript.mjs +95 -7
- package/src/core/typescript-run.mjs +14 -7
- package/src/core-changes-fs.mjs +28 -0
- package/src/core-changes.d.mts +67 -0
- package/src/core-changes.mjs +603 -0
- package/src/core-rules.mjs +146 -0
- package/src/core-services.d.mts +4 -0
- package/src/core-services.mjs +49 -0
- package/src/decision.mjs +2 -1
- package/src/distributed.mjs +2 -1
- package/src/emit.mjs +2 -2
- package/src/evidence.mjs +28 -0
- package/src/examples.d.mts +21 -0
- package/src/examples.mjs +175 -0
- package/src/focus.mjs +2 -1
- package/src/index.d.ts +4 -0
- package/src/index.mjs +4 -0
- package/src/intent-atlas.mjs +4 -3
- package/src/mcp.mjs +52 -6
- package/src/passport-fs.mjs +2 -1
- package/src/passport.mjs +2 -1
- package/src/privacy.mjs +2 -1
- package/src/program.d.mts +4 -0
- package/src/program.mjs +4 -0
- package/src/read-repo-fs.mjs +2 -1
- package/src/read-repo.mjs +3 -2
- package/src/report.mjs +3 -2
- package/src/review.mjs +71 -4
- package/src/select.mjs +2 -1
- package/src/semantic-diff.mjs +7 -6
- package/src/system.mjs +3 -2
- package/src/text-order.mjs +6 -0
- package/src/thunderize.mjs +2 -1
- package/src/trace-cli.mjs +8 -3
- package/src/trace-data.mjs +3 -2
- package/src/trace-fs.mjs +29 -3
- package/src/trace.mjs +27 -10
- package/src/write-across-cli.mjs +22 -4
- package/src/write-across.mjs +2 -1
- package/syntaxes/thunder.tmLanguage.json +196 -0
package/src/conflict.mjs
CHANGED
|
Binary file
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// ThunderDotnet.cs: written by the Thunder compiler next to compiled C# when a program uses .NET libraries
|
|
2
|
+
// (Use "<Type>" from .NET as <name>, or from NuGet). The boundary between Thunder values and .NET values.
|
|
3
|
+
//
|
|
4
|
+
// Thunder -> .NET, to fit the method's parameter: a whole number becomes int, long, double, or decimal (whichever the
|
|
5
|
+
// parameter is, when it fits); a decimal number becomes decimal or double; money becomes its amount; text stays a
|
|
6
|
+
// string; yes/no a bool; nothing null; a list an array or a List of the parameter's element type; a date a DateTime
|
|
7
|
+
// at midnight. A value that came from .NET goes back unchanged.
|
|
8
|
+
// .NET -> Thunder: int, long, short, byte (and unsigned) become whole numbers; decimal becomes the exact decimal;
|
|
9
|
+
// double and float become the decimal they print as ("R"), so 0.1 stays 0.1; string, bool, and null as they are;
|
|
10
|
+
// arrays and lists become lists; anything else stays a library value that can be handed back to .NET.
|
|
11
|
+
// The method is chosen by name and by which overload every value fits, in the order .NET lists them, preferring one
|
|
12
|
+
// whose parameters need no widening. No fit: TC508 in words.
|
|
13
|
+
#nullable disable
|
|
14
|
+
namespace Thunder
|
|
15
|
+
{
|
|
16
|
+
using System;
|
|
17
|
+
using System.Collections;
|
|
18
|
+
using System.Collections.Generic;
|
|
19
|
+
using System.Globalization;
|
|
20
|
+
using System.Linq;
|
|
21
|
+
using System.Numerics;
|
|
22
|
+
using System.Reflection;
|
|
23
|
+
|
|
24
|
+
public sealed class DotnetLibrary
|
|
25
|
+
{
|
|
26
|
+
public readonly Type type; public readonly string name;
|
|
27
|
+
public DotnetLibrary(Type type, string name) { this.type = type; this.name = name; }
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static class Dotnet
|
|
31
|
+
{
|
|
32
|
+
// Libraries may format by culture (words, dates). A program that uses .NET libraries runs with real culture
|
|
33
|
+
// data, pinned to en-US, so it says the same thing on every machine.
|
|
34
|
+
static Dotnet()
|
|
35
|
+
{
|
|
36
|
+
var c = CultureInfo.GetCultureInfo("en-US");
|
|
37
|
+
CultureInfo.DefaultThreadCurrentCulture = c; CultureInfo.DefaultThreadCurrentUICulture = c;
|
|
38
|
+
CultureInfo.CurrentCulture = c; CultureInfo.CurrentUICulture = c;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The type named `typeName`: in .NET itself, or in a package's assembly next to the program (NuGet). */
|
|
42
|
+
public static DotnetLibrary library(string typeName)
|
|
43
|
+
{
|
|
44
|
+
var t = Type.GetType(typeName, false);
|
|
45
|
+
if (t == null) foreach (var a in AppDomain.CurrentDomain.GetAssemblies()) { t = a.GetType(typeName, false); if (t != null) break; }
|
|
46
|
+
if (t == null)
|
|
47
|
+
foreach (var dll in System.IO.Directory.GetFiles(AppContext.BaseDirectory, "*.dll"))
|
|
48
|
+
{
|
|
49
|
+
try { t = Assembly.LoadFrom(dll).GetType(typeName, false); } catch { }
|
|
50
|
+
if (t != null) break;
|
|
51
|
+
}
|
|
52
|
+
if (t == null) throw new ThunderErr("TC508", "There is no .NET type called \"" + typeName + "\". Write it with its namespace, as in \"System.IO.Path\"; a type from a package needs its NuGet line.", "LibraryError");
|
|
53
|
+
return new DotnetLibrary(t, typeName);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
sealed class NoFit { public static readonly NoFit It = new NoFit(); }
|
|
57
|
+
|
|
58
|
+
static object to(object v, Type p, ref int cost)
|
|
59
|
+
{
|
|
60
|
+
var u = Nullable.GetUnderlyingType(p) ?? p;
|
|
61
|
+
if (v == null || v is NotGiven) return (!p.IsValueType || Nullable.GetUnderlyingType(p) != null) ? null : NoFit.It;
|
|
62
|
+
if (v is Money m) v = m.amount;
|
|
63
|
+
if (u == typeof(object)) { cost += 3; return toPlain(v); }
|
|
64
|
+
if (u.IsInstanceOfType(v) && !(v is Dec) && !(v is BigInteger)) return v;
|
|
65
|
+
if (v is bool b) return u == typeof(bool) ? b : NoFit.It;
|
|
66
|
+
if (v is string s) { if (u == typeof(string)) return s; if (u == typeof(char) && s.Length == 1) { cost += 1; return s[0]; } return NoFit.It; }
|
|
67
|
+
if (v is BigInteger n)
|
|
68
|
+
{
|
|
69
|
+
try
|
|
70
|
+
{
|
|
71
|
+
if (u == typeof(int) && n >= int.MinValue && n <= int.MaxValue) return (int)n;
|
|
72
|
+
if (u == typeof(long) && n >= long.MinValue && n <= long.MaxValue) { cost += 1; return (long)n; }
|
|
73
|
+
if (u == typeof(short) && n >= short.MinValue && n <= short.MaxValue) { cost += 2; return (short)n; }
|
|
74
|
+
if (u == typeof(byte) && n >= byte.MinValue && n <= byte.MaxValue) { cost += 2; return (byte)n; }
|
|
75
|
+
if (u == typeof(decimal)) { cost += 2; return (decimal)n; }
|
|
76
|
+
if (u == typeof(double)) { cost += 3; return (double)n; }
|
|
77
|
+
if (u == typeof(float)) { cost += 4; return (float)n; }
|
|
78
|
+
if (u == typeof(BigInteger)) return n;
|
|
79
|
+
}
|
|
80
|
+
catch (OverflowException) { }
|
|
81
|
+
return NoFit.It;
|
|
82
|
+
}
|
|
83
|
+
if (v is Dec d)
|
|
84
|
+
{
|
|
85
|
+
var text = d.ToString();
|
|
86
|
+
if (u == typeof(decimal) && decimal.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var dm)) return dm;
|
|
87
|
+
if (u == typeof(double)) { cost += 1; return double.Parse(text, CultureInfo.InvariantCulture); }
|
|
88
|
+
if (u == typeof(float)) { cost += 2; return float.Parse(text, CultureInfo.InvariantCulture); }
|
|
89
|
+
return NoFit.It;
|
|
90
|
+
}
|
|
91
|
+
if (v is PyDate dt) return u == typeof(DateTime) ? new DateTime(dt.y, dt.m, dt.d) : u == typeof(DateOnly) ? new DateOnly(dt.y, dt.m, dt.d) : (object)NoFit.It;
|
|
92
|
+
if (v is List<object> list)
|
|
93
|
+
{
|
|
94
|
+
Type el = u.IsArray ? u.GetElementType() : u.IsGenericType && u.GetGenericArguments().Length == 1 && (typeof(IEnumerable).IsAssignableFrom(u)) ? u.GetGenericArguments()[0] : null;
|
|
95
|
+
if (el == null) return NoFit.It;
|
|
96
|
+
var items = new List<object>();
|
|
97
|
+
foreach (var x in list) { var c = to(x, el, ref cost); if (c is NoFit) return NoFit.It; items.Add(c); }
|
|
98
|
+
if (u.IsArray) { var arr = Array.CreateInstance(el, items.Count); for (int i = 0; i < items.Count; i++) arr.SetValue(items[i], i); return arr; }
|
|
99
|
+
var lt = typeof(List<>).MakeGenericType(el);
|
|
100
|
+
if (!u.IsAssignableFrom(lt)) return NoFit.It;
|
|
101
|
+
var l = (IList)Activator.CreateInstance(lt);
|
|
102
|
+
foreach (var x in items) l.Add(x);
|
|
103
|
+
return l;
|
|
104
|
+
}
|
|
105
|
+
return NoFit.It;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A Thunder value as the plainest .NET value, for an object parameter. */
|
|
109
|
+
static object toPlain(object v)
|
|
110
|
+
{
|
|
111
|
+
if (v is BigInteger n) return n >= long.MinValue && n <= long.MaxValue ? (object)(long)n : n;
|
|
112
|
+
if (v is Dec d) return decimal.TryParse(d.ToString(), NumberStyles.Float, CultureInfo.InvariantCulture, out var dm) ? dm : (object)double.Parse(d.ToString(), CultureInfo.InvariantCulture);
|
|
113
|
+
if (v is Money m) return toPlain(m.amount);
|
|
114
|
+
if (v is PyDate dt) return new DateTime(dt.y, dt.m, dt.d);
|
|
115
|
+
if (v is List<object> l) return l.Select(toPlain).ToList();
|
|
116
|
+
return v;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** A .NET value as a Thunder value. */
|
|
120
|
+
public static object from(object v)
|
|
121
|
+
{
|
|
122
|
+
switch (v)
|
|
123
|
+
{
|
|
124
|
+
case null: return null;
|
|
125
|
+
case string s: return s;
|
|
126
|
+
case bool b: return b;
|
|
127
|
+
case char c: return c.ToString();
|
|
128
|
+
case int i: return new BigInteger(i);
|
|
129
|
+
case long l: return new BigInteger(l);
|
|
130
|
+
case short sh: return new BigInteger(sh);
|
|
131
|
+
case byte by: return new BigInteger(by);
|
|
132
|
+
case uint ui: return new BigInteger(ui);
|
|
133
|
+
case ulong ul: return new BigInteger(ul);
|
|
134
|
+
case BigInteger n: return n;
|
|
135
|
+
case decimal dm: return Dec.Parse(dm.ToString(CultureInfo.InvariantCulture));
|
|
136
|
+
case double db: if (double.IsNaN(db) || double.IsInfinity(db)) throw new ThunderErr("TC509", "The library gave back " + db.ToString(CultureInfo.InvariantCulture) + ", which is not a number Thunder can use.", "ValueError"); return Dec.Parse(db.ToString("R", CultureInfo.InvariantCulture));
|
|
137
|
+
case float f: return Dec.Parse(((double)f).ToString("R", CultureInfo.InvariantCulture));
|
|
138
|
+
case DateTime dt: return dt.TimeOfDay == TimeSpan.Zero ? new PyDate(dt.Year, dt.Month, dt.Day) : (object)dt;
|
|
139
|
+
case DateOnly d: return new PyDate(d.Year, d.Month, d.Day);
|
|
140
|
+
case IEnumerable e when !(v is IDictionary): { var list = new List<object>(); foreach (var x in e) list.Add(from(x)); return list; }
|
|
141
|
+
default: return v;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** <library>.<method>(<args>): the static method of that name whose parameters every value fits. */
|
|
146
|
+
public static object call(object lib, string method, object[] args)
|
|
147
|
+
{
|
|
148
|
+
var L = lib as DotnetLibrary;
|
|
149
|
+
if (L == null) throw new ThunderErr("TC508", "\"" + method + "\" with a dot reaches into a library brought in with Use.", "LibraryError");
|
|
150
|
+
var methods = L.type.GetMethods(BindingFlags.Public | BindingFlags.Static).Where((m) => m.Name == method).ToArray();
|
|
151
|
+
if (methods.Length == 0) throw new ThunderErr("TC508", "The .NET type \"" + L.name + "\" has no method named \"" + method + "\".", "LibraryError");
|
|
152
|
+
MethodInfo best = null; object[] bestArgs = null; int bestCost = int.MaxValue;
|
|
153
|
+
foreach (var m in methods)
|
|
154
|
+
{
|
|
155
|
+
if (m.ContainsGenericParameters) continue;
|
|
156
|
+
var ps = m.GetParameters();
|
|
157
|
+
if (ps.Length < args.Length) continue;
|
|
158
|
+
if (ps.Skip(args.Length).Any((p) => !p.HasDefaultValue)) continue;
|
|
159
|
+
var conv = new object[ps.Length]; int cost = 0; bool ok = true;
|
|
160
|
+
for (int i = 0; i < ps.Length && ok; i++)
|
|
161
|
+
{
|
|
162
|
+
if (i >= args.Length) { conv[i] = ps[i].DefaultValue; cost += 1; continue; }
|
|
163
|
+
var c = to(args[i], ps[i].ParameterType, ref cost);
|
|
164
|
+
if (c is NoFit) ok = false; else conv[i] = c;
|
|
165
|
+
}
|
|
166
|
+
if (ok && cost < bestCost) { best = m; bestArgs = conv; bestCost = cost; }
|
|
167
|
+
}
|
|
168
|
+
if (best == null)
|
|
169
|
+
{
|
|
170
|
+
var kinds = string.Join(", ", args.Select((a) => T.typeName(a)));
|
|
171
|
+
throw new ThunderErr("TC508", "No \"" + L.name + "." + method + "\" takes " + (args.Length == 0 ? "no values" : "these values (" + kinds + ")") + ". It takes: " + string.Join("; ", methods.Select((m) => "(" + string.Join(", ", m.GetParameters().Select((p) => p.ParameterType.Name + " " + p.Name)) + ")")) + ".", "LibraryError");
|
|
172
|
+
}
|
|
173
|
+
try { return from(best.Invoke(null, bestArgs)); }
|
|
174
|
+
catch (TargetInvocationException e) when (e.InnerException != null)
|
|
175
|
+
{
|
|
176
|
+
if (e.InnerException is TErr te) throw te;
|
|
177
|
+
// The innermost cause says why (a type that failed to start up wraps the real reason).
|
|
178
|
+
var cause = e.InnerException;
|
|
179
|
+
while ((cause is TypeInitializationException || cause is TargetInvocationException) && cause.InnerException != null) cause = cause.InnerException;
|
|
180
|
+
throw new ThunderErr("TC508", ".NET code used by this line failed: " + cause.GetType().Name + ": " + cause.Message, "LibraryError");
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** <library>.<name> without a call: a static property or field. */
|
|
185
|
+
public static object get(object lib, string name)
|
|
186
|
+
{
|
|
187
|
+
var L = lib as DotnetLibrary;
|
|
188
|
+
var p = L?.type.GetProperty(name, BindingFlags.Public | BindingFlags.Static);
|
|
189
|
+
if (p != null) return from(p.GetValue(null));
|
|
190
|
+
var f = L?.type.GetField(name, BindingFlags.Public | BindingFlags.Static);
|
|
191
|
+
if (f != null) return from(f.GetValue(null));
|
|
192
|
+
throw new ThunderErr("TC508", "The .NET type \"" + L?.name + "\" has nothing named \"" + name + "\".", "LibraryError");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|