Skip to content

Commit bf8d26a

Browse files
committed
Prepare pre-release
1 parent 71cc523 commit bf8d26a

File tree

13 files changed

+52
-19
lines changed

13 files changed

+52
-19
lines changed

KSP2Runtime-Test/PluginBootTests.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using KontrolSystem.TO2;
1+
using KontrolSystem.KSP.Runtime.Testing;
2+
using KontrolSystem.TO2;
23
using Xunit;
34
using Xunit.Abstractions;
45
using Xunit.Sdk;

KSP2Runtime/Core/Mainframe.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,29 @@ public void Reboot(bool showInConsole) {
130130
var task = Task.Factory.StartNew(() => {
131131
var stopwatch = new Stopwatch();
132132
try {
133+
config.Logger.Info("Start compile");
133134
stopwatch.Start();
134135

135136
var nextRegistry = KontrolSystemKSPRegistry.CreateKSP();
136137

137138
if (Directory.Exists(config.StdLibPath)) {
138-
config.Logger.Debug($"Add Directory: {config.StdLibPath}");
139-
nextRegistry.AddDirectory(config.StdLibPath);
139+
config.Logger.Info($"Add Directory: {config.StdLibPath}");
140+
nextRegistry.AddDirectory(config.StdLibPath, config.Logger);
140141
} else {
141142
config.Logger.Warning($"StdLibPath does not exists: {config.LocalLibPath}");
142143
}
143144

144145
if (Directory.Exists(config.LocalLibPath)) {
145-
config.Logger.Debug($"Add Directory: {config.LocalLibPath}");
146-
nextRegistry.AddDirectory(config.LocalLibPath);
146+
config.Logger.Info($"Add Directory: {config.LocalLibPath}");
147+
nextRegistry.AddDirectory(config.LocalLibPath, config.Logger);
147148
} else {
148149
config.Logger.Warning($"LocalLibPath does not exists: {config.LocalLibPath}");
149150
}
150151

151152
stopwatch.Stop();
152153

154+
config.Logger.Info($"Done compile {stopwatch.Elapsed}");
155+
153156
return new State(nextRegistry, stopwatch.Elapsed, []);
154157
} catch (CompilationErrorException e) {
155158
config.Logger.Debug(e.ToString());

KSP2Runtime/KontrolSystemKSPRegistry.cs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using KontrolSystem.KSP.Runtime.Testing;
1515
using KontrolSystem.TO2;
1616
using KontrolSystem.TO2.Binding;
17+
using KontrolSystem.TO2.Runtime;
1718

1819
namespace KontrolSystem.KSP.Runtime;
1920

SpaceWarpMod/KontrolSystemMod.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313

1414
namespace KontrolSystem.SpaceWarpMod;
1515

16-
[BepInPlugin("com.github.untoldwind.KontrolSystem2", "KontrolSystem2", "0.5.8.5")]
16+
[BepInPlugin("com.github.untoldwind.KontrolSystem2", "KontrolSystem2", "0.5.9.0")]
1717
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
1818
[BepInDependency(KSPAddonsModule.FlightPlanAdapter.ModGuid, BepInDependency.DependencyFlags.SoftDependency)]
1919
public class KontrolSystemMod : BaseSpaceWarpPlugin {
2020
public const string ModGuid = "com.github.untoldwind.KontrolSystem2";
2121
public const string ModName = "KontrolSystem2";
22-
public const string ModVersion = "0.5.8.5";
22+
public const string ModVersion = "0.5.9.0";
2323

2424
private ModuleManagerWindow? moduleManagerWindow;
2525
private UIWindows? uiWindows;

SpaceWarpMod/swinfo.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Kontrol System",
55
"description": "Autopilot scripting framework",
66
"source": "https://github.com/untoldwind/KontrolSystem2",
7-
"version": "0.5.8.5",
7+
"version": "0.5.9.0",
88
"dependencies": [],
99
"ksp2_version": {
1010
"min": "0",

TO2-Test/to2Nursery/nvector.to2

+9-5
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ pub struct NVector(values: float[]) {
44
}
55

66
impl NVector {
7+
sync fn add_scalar(self, scalar: float) -> NVector = NVector(self.values.map(fn(v) -> v + scalar))
8+
9+
sync fn mul_scalar(self, scalar: float) -> NVector = NVector(self.values.map(fn(v) -> v * scalar))
10+
711
sync fn to_string(self) -> string = $"NVector({self.dim}, {self.values.to_string()})"
812
}
913

1014
impl operators for NVector {
11-
sync fn unary_minus(right: NVector) -> NVector = NVector(right.values.map(fn(r) -> -r))
15+
sync fn neg(right: NVector) -> NVector = NVector(right.values.map(fn(r) -> -r))
1216

13-
sync fn add(left: float, right: NVector) -> NVector = NVector(right.values.map(fn(r) -> left + r))
17+
sync fn add(left: float, right: NVector) -> NVector = right.add_scalar(left)
1418

15-
sync fn add(left: NVector, right: float) -> NVector = NVector(left.values.map(fn(l) -> l + right))
19+
sync fn add(left: NVector, right: float) -> NVector = left.add_scalar(right)
1620

1721
sync fn add(left: NVector, right: NVector) -> NVector = NVector((0..min_dim(left.dim, right.dim)).map(fn(i) -> left.values[i] + right.values[i]))
1822

19-
sync fn mul(left: float, right: NVector) -> NVector = NVector(right.values.map(fn(r) -> left * r))
23+
sync fn mul(left: float, right: NVector) -> NVector = right.mul_scalar(left)
2024

21-
sync fn mul(left: NVector, right: float) -> NVector = NVector(left.values.map(fn(l) -> l * right))
25+
sync fn mul(left: NVector, right: float) -> NVector = left.mul_scalar(right)
2226

2327
sync fn div(left: NVector, right: float) -> NVector = NVector(left.values.map(fn(l) -> l / right))
2428
}

TO2/AST/ImplOperatorsDeclaration.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class ImplOperatorsDeclaration(
1212
Position start = new(),
1313
Position end = new()) : Node(start, end), IModuleItem {
1414
private static readonly Dictionary<string, Operator> unaryOperatorMap = new() {
15-
{ "unary_minus", Operator.Neg }
15+
{ "neg", Operator.Neg }
1616
};
1717

1818
private static readonly Dictionary<string, Operator> binaryOperatorMap = new() {
@@ -21,6 +21,7 @@ public class ImplOperatorsDeclaration(
2121
{ "mul", Operator.Mul },
2222
{ "div", Operator.Div },
2323
{ "mod", Operator.Mod },
24+
{ "pow", Operator.Pow },
2425
};
2526

2627
private List<DeclaredOperatorEmitter> operatorFunctions = [];

TO2/KontrolRegistry.cs

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
56
using KontrolSystem.Parsing;
@@ -54,10 +55,12 @@ public Context AddFile(string baseDir, string file) {
5455
return context;
5556
}
5657

57-
public Context AddDirectory(string baseDir) {
58+
public Context AddDirectory(string baseDir, ITO2Logger? logger = null) {
5859
var context = new Context(this);
5960
var declaredModules = new List<DeclaredKontrolModule>();
60-
61+
var stopwatch = new Stopwatch();
62+
63+
stopwatch.Start();
6164
foreach (var fileName in Directory.GetFiles(baseDir, "*.to2", SearchOption.AllDirectories)) {
6265
if (!fileName.EndsWith(".to2")) continue;
6366

@@ -68,36 +71,53 @@ public Context AddDirectory(string baseDir) {
6871
declaredModules.Add(module);
6972
context.registry.RegisterModule(module);
7073
}
74+
logger?.Info($"Phase1: {stopwatch.Elapsed}");
7175

7276
foreach (var declared in declaredModules)
7377
// ... so that types can be imported by other modules
7478
ModuleGenerator.ImportTypes(declared);
7579

80+
logger?.Info($"Phase2: {stopwatch.Elapsed}");
81+
7682
foreach (var declared in declaredModules) ModuleGenerator.DeclareConstants(declared);
7783

84+
logger?.Info($"Phase3: {stopwatch.Elapsed}");
85+
7886
foreach (var declared in declaredModules) ModuleGenerator.ImportConstants(declared);
7987

88+
logger?.Info($"Phase4: {stopwatch.Elapsed}");
89+
8090
foreach (var declared in declaredModules)
8191
// ... so that function can be declared (potentially using imported types as arguments or return)
8292
ModuleGenerator.DeclareFunctions(declared);
8393

94+
logger?.Info($"Phase5: {stopwatch.Elapsed}");
95+
8496
foreach (var declared in declaredModules)
8597
// ... so that other modules may import these functions
8698
ModuleGenerator.ImportFunctions(declared);
8799

100+
logger?.Info($"Phase6: {stopwatch.Elapsed}");
101+
88102
foreach (var declared in declaredModules) ModuleGenerator.CompileStructs(declared);
89103

104+
logger?.Info($"Phase6: {stopwatch.Elapsed}");
105+
90106
foreach (var declared in declaredModules)
91107
// ... so that we should now be able to infer all types
92108
ModuleGenerator.VerifyFunctions(declared);
93109

110+
logger?.Info($"Phase7: {stopwatch.Elapsed}");
111+
94112
foreach (var declared in declaredModules) {
95113
// ... and eventually emit the code and bake the modules
96114
var compiled = ModuleGenerator.CompileModule(declared);
97115

98116
context.registry.RegisterModule(compiled);
99117
}
100118

119+
logger?.Info($"Finalized: {stopwatch.Elapsed}");
120+
101121
return context;
102122
}
103123

Tools/GenDocs/Main.cs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using KontrolSystem.TO2.AST;
88
using KontrolSystem.KSP.Runtime;
99
using KontrolSystem.TO2.Generator;
10+
using KontrolSystem.TO2.Runtime;
1011

1112
namespace KontrolSystem.GenDocs;
1213

Tools/GenRefs/Main.cs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using KontrolSystem.TO2;
77
using KontrolSystem.TO2.AST;
88
using KontrolSystem.TO2.Generator;
9+
using KontrolSystem.TO2.Runtime;
910
using Newtonsoft.Json;
1011
using Newtonsoft.Json.Converters;
1112

Tools/vscode/to2-syntax/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "to2-syntax",
33
"displayName": "to2-syntax",
44
"description": "",
5-
"version": "0.0.51",
5+
"version": "0.0.52",
66
"license": "MIT",
77
"engines": {
88
"vscode": "^1.76.0"

Tools/vscode/to2-syntax/server/src/to2/ast/impl-operator-declaration.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class ImplOperatorsDeclaration implements ModuleItem {
109109
}
110110

111111
const unaryOperatorMap: Record<string, Operator> = {
112-
unary_minus: "-",
112+
neg: "-",
113113
};
114114

115115
const binaryOperatorMap: Record<string, Operator> = {
@@ -118,6 +118,7 @@ const binaryOperatorMap: Record<string, Operator> = {
118118
mul: "*",
119119
div: "/",
120120
mod: "%",
121+
pow: "**",
121122
};
122123

123124
class ImplOperatorsModuleContext implements ModuleContext {

prepare_release.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ zip -r KontrolSystem2-${version}.zip BepInEx
1010

1111
gh release upload v${version} KontrolSystem2-${version}.zip
1212
gh release upload v${version} ../Tools/vscode/to2-syntax/to2-syntax-0.0.1.vsix
13-
gh release upload v${version} ../Tools/vscode/to2-syntax/to2-syntax-0.0.51.vsix
13+
gh release upload v${version} ../Tools/vscode/to2-syntax/to2-syntax-0.0.52.vsix
1414
gh release upload v${version} ../Tools/vscode/to2-syntax/server/out/lsp-server.js

0 commit comments

Comments
 (0)