make editor editing and running
This commit is contained in:
parent
f002cd8de4
commit
30a11c7b0b
|
|
@ -33,14 +33,14 @@ public static class Benchmark
|
||||||
|
|
||||||
if (!_clocks.TryGetValue(key, out Stopwatch? sw)) {
|
if (!_clocks.TryGetValue(key, out Stopwatch? sw)) {
|
||||||
sw = _clocks[key] = new Stopwatch();
|
sw = _clocks[key] = new Stopwatch();
|
||||||
Console.WriteLine($" ::: Registered new benchmark clock '{key}'");
|
IO.Console.Write($" ::: Registered new benchmark clock '{key}'\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(message))
|
if (!string.IsNullOrEmpty(message))
|
||||||
Console.WriteLine($" ::: {key}:{line} > {message}");
|
IO.Console.Write($" ::: {key}:{line} > {message}\n");
|
||||||
|
|
||||||
if (sw.IsRunning)
|
if (sw.IsRunning)
|
||||||
Console.WriteLine($" ::: {key}:{line} > already running with an elapsed time of {sw.Elapsed}. clock was reset.");
|
IO.Console.Write($" ::: {key}:{line} > already running with an elapsed time of {sw.Elapsed}. clock was reset.\n");
|
||||||
|
|
||||||
sw.Reset();
|
sw.Reset();
|
||||||
sw.Start();
|
sw.Start();
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,19 @@
|
||||||
|
|
||||||
public static class Console
|
public static class Console
|
||||||
{
|
{
|
||||||
|
// TEMP
|
||||||
|
public static Action<string>? StdOut;
|
||||||
|
// TEMP
|
||||||
|
|
||||||
public static void Write(object? any)
|
public static void Write(object? any)
|
||||||
{
|
{
|
||||||
string[] split = $"{any ?? "null"}".Split('\n');
|
string[] split = $"{any ?? "null"}".Split('\n');
|
||||||
for (int i = 0; i < split.Length; i++) {
|
for (int i = 0; i < split.Length; i++) {
|
||||||
System.Console.Write((i == 0 ? " :> " : " ") + $"{split[i]}\n");
|
string line = (i == 0 ? " :> " : " ") + $"{split[i]}\n";
|
||||||
|
if (StdOut == null)
|
||||||
|
System.Console.Write(line);
|
||||||
|
else
|
||||||
|
StdOut(line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -48,6 +48,7 @@ public class Runner : IDisposable
|
||||||
Options = options;
|
Options = options;
|
||||||
Calls = new StackLike<Call>(options.MaxCalls);
|
Calls = new StackLike<Call>(options.MaxCalls);
|
||||||
Stack = new StackLike<Value>(options.InitialStackSize);
|
Stack = new StackLike<Value>(options.InitialStackSize);
|
||||||
|
IO.Console.StdOut = options.StdOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutionResult Run(Stream stream)
|
public ExecutionResult Run(Stream stream)
|
||||||
|
|
@ -664,13 +665,17 @@ public enum ExecutionResult
|
||||||
}
|
}
|
||||||
|
|
||||||
public readonly struct Options(
|
public readonly struct Options(
|
||||||
int maxCalls = 0x100,
|
Action<string>? stdOut = null,
|
||||||
int stackSize = 0x200,
|
Action<string>? stdIn = null,
|
||||||
int initialStackSize = 0x80)
|
int maxCalls = 0x100,
|
||||||
|
int stackSize = 0x200,
|
||||||
|
int initialStackSize = 0x80)
|
||||||
{
|
{
|
||||||
|
public readonly Action<string>? StdOut = stdOut;
|
||||||
|
public readonly Action<string>? StdIn = stdIn;
|
||||||
public readonly int MaxCalls = maxCalls;
|
public readonly int MaxCalls = maxCalls;
|
||||||
public readonly int StackSize = stackSize;
|
public readonly int StackSize = stackSize;
|
||||||
public readonly int InitialStackSize = initialStackSize;
|
public readonly int InitialStackSize = initialStackSize;
|
||||||
|
|
||||||
public Options() : this(0x100, 0x200, 0x80) { }
|
public Options() : this(null, null, 0x100, 0x200, 0x80) { }
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ public class Logger : ILogger, ILogFormatter
|
||||||
foreach (var value in values) {
|
foreach (var value in values) {
|
||||||
var lines = Format(value);
|
var lines = Format(value);
|
||||||
for (int i = 0; i < lines.Length; i++)
|
for (int i = 0; i < lines.Length; i++)
|
||||||
Console.WriteLine($"{(i == 0 ? header.First : header.Extra)}{lines[i]}");
|
IO.Console.Write($"{(i == 0 ? header.First : header.Extra)}{lines[i]}\n");
|
||||||
}
|
}
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Qrakhen.Qamp.Memory;
|
using Qrakhen.Qamp.Editor.Primitives;
|
||||||
|
using Qrakhen.Qamp.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
@ -38,11 +39,11 @@ public partial class LineRenderer : UserControl
|
||||||
);
|
);
|
||||||
|
|
||||||
var x = Random.Shared.Next(0, LineBuffer.Tail);
|
var x = Random.Shared.Next(0, LineBuffer.Tail);
|
||||||
var s = new BufferSpan(x, Random.Shared.Next(x, LineBuffer.Tail));
|
var s = new BufferRegion(new BufferPosition(0, x), new BufferPosition(0, Random.Shared.Next(x, LineBuffer.Tail)));
|
||||||
Selection = s;
|
Selection = s;
|
||||||
|
|
||||||
var highlighter = TextHelper.GetText(
|
var highlighter = TextHelper.GetText(
|
||||||
new string(' ', Selection.Start) + new string('█', Selection.End - Selection.Start),
|
new string(' ', Selection.From.Column) + new string('█', Selection.To.Column - Selection.From.Column),
|
||||||
FontSize,
|
FontSize,
|
||||||
Highlighter,
|
Highlighter,
|
||||||
VisualTreeHelper.GetDpi(this).PixelsPerDip
|
VisualTreeHelper.GetDpi(this).PixelsPerDip
|
||||||
|
|
@ -90,12 +91,12 @@ public partial class LineRenderer : UserControl
|
||||||
public static readonly DependencyProperty SelectionProperty =
|
public static readonly DependencyProperty SelectionProperty =
|
||||||
DependencyProperty.Register(
|
DependencyProperty.Register(
|
||||||
nameof(Selection),
|
nameof(Selection),
|
||||||
typeof(BufferSpan),
|
typeof(BufferRegion),
|
||||||
typeof(LineRenderer),
|
typeof(LineRenderer),
|
||||||
new FrameworkPropertyMetadata(BufferSpan.None, OnSelectionChanged));
|
new FrameworkPropertyMetadata(BufferRegion.Void, OnSelectionChanged));
|
||||||
|
|
||||||
public BufferSpan Selection {
|
public BufferRegion Selection {
|
||||||
get => (BufferSpan)GetValue(SelectionProperty);
|
get => (BufferRegion)GetValue(SelectionProperty);
|
||||||
set => SetValue(SelectionProperty, value);
|
set => SetValue(SelectionProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,8 @@
|
||||||
<TextBlock Background="#202122"
|
<TextBlock Background="#202122"
|
||||||
Foreground="#32ef64"
|
Foreground="#32ef64"
|
||||||
Padding="4"
|
Padding="4"
|
||||||
FontFamily="Consolas">$ ...</TextBlock>
|
Text="{Binding RunnerOutput}"
|
||||||
|
FontFamily="Consolas"></TextBlock>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,11 @@
|
||||||
using Qrakhen.Qamp.Editor.Commands;
|
using Microsoft.Win32;
|
||||||
|
using Qrakhen.Qamp.Editor.Commands;
|
||||||
using Qrakhen.Qamp.Editor.Primitives;
|
using Qrakhen.Qamp.Editor.Primitives;
|
||||||
using Qrakhen.Qamp.Memory;
|
using Qrakhen.Qamp.Memory;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
using System.Windows.Documents;
|
using System.Windows.Documents;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
|
|
@ -17,6 +19,12 @@ public class SelectableLineBuffer(LineBuffer buffer)
|
||||||
|
|
||||||
public class EditorFrameViewModel : ObservableObject
|
public class EditorFrameViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
|
private Encoding _encoding;
|
||||||
|
public Encoding Encoding {
|
||||||
|
get => _encoding;
|
||||||
|
set => SetProperty(ref _encoding, value);
|
||||||
|
}
|
||||||
|
|
||||||
private FileInfo _fileInfo;
|
private FileInfo _fileInfo;
|
||||||
public FileInfo FileInfo {
|
public FileInfo FileInfo {
|
||||||
get => _fileInfo;
|
get => _fileInfo;
|
||||||
|
|
@ -56,6 +64,8 @@ public class EditorFrameViewModel : ObservableObject
|
||||||
|
|
||||||
public EditorFrameViewModel()
|
public EditorFrameViewModel()
|
||||||
{
|
{
|
||||||
|
Encoding = Encoding.ASCII;
|
||||||
|
|
||||||
MoveCaretCommand = new RelayCommand(ExecuteMoveCaret);
|
MoveCaretCommand = new RelayCommand(ExecuteMoveCaret);
|
||||||
MoveBlockCommand = new RelayCommand(ExecuteMoveBlock);
|
MoveBlockCommand = new RelayCommand(ExecuteMoveBlock);
|
||||||
InsertCommand = new RelayCommand(ExecuteInsert);
|
InsertCommand = new RelayCommand(ExecuteInsert);
|
||||||
|
|
@ -202,4 +212,25 @@ public class EditorFrameViewModel : ObservableObject
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
public string Serialize(string? lineTerminator = null)
|
||||||
|
{
|
||||||
|
lineTerminator ??= Environment.NewLine;
|
||||||
|
string result = "";
|
||||||
|
foreach (var line in Lines) {
|
||||||
|
result += $"{line.Buffer.ToString()}{lineTerminator}";
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deserialize(string source, Encoding? encoding = null, string? lineTerminator = null)
|
||||||
|
{
|
||||||
|
encoding ??= Encoding.ASCII;
|
||||||
|
lineTerminator ??= Environment.NewLine;
|
||||||
|
Lines.Clear();
|
||||||
|
string[] lines = source.Split(lineTerminator);
|
||||||
|
foreach (var line in lines) {
|
||||||
|
Lines.Add(new SelectableLineBuffer(new LineBuffer(line, encoding)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,24 @@
|
||||||
using Qrakhen.Qamp.Editor.Commands;
|
using Qrakhen.Qamp.Core.Execution;
|
||||||
|
using Qrakhen.Qamp.Editor.Commands;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
|
|
||||||
namespace Qrakhen.Qamp.Editor.ViewModel;
|
namespace Qrakhen.Qamp.Editor.ViewModel;
|
||||||
|
|
||||||
public class MainViewModel
|
public class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
public EditorFrameViewModel EditorFrame { get; set; }
|
public EditorFrameViewModel EditorFrame { get; set; }
|
||||||
|
|
||||||
|
private string _runnerOutput = "";
|
||||||
|
public string RunnerOutput
|
||||||
|
{
|
||||||
|
get => _runnerOutput;
|
||||||
|
set => SetProperty(ref _runnerOutput, value);
|
||||||
|
}
|
||||||
|
|
||||||
public ICommand RunCommand { get; set; }
|
public ICommand RunCommand { get; set; }
|
||||||
public ICommand SaveCommand { get; set; }
|
public ICommand SaveCommand { get; set; }
|
||||||
public ICommand LoadCommand { get; set; }
|
public ICommand LoadCommand { get; set; }
|
||||||
|
|
@ -25,7 +34,16 @@ public class MainViewModel
|
||||||
|
|
||||||
private void ExecuteRun()
|
private void ExecuteRun()
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
|
string code = EditorFrame.Serialize();
|
||||||
|
Runner runner = new Runner(new Options((m) => { RunnerOutput += m; }));
|
||||||
|
MemoryStream stream = new MemoryStream();
|
||||||
|
stream.Write(EditorFrame.Encoding.GetBytes(code));
|
||||||
|
runner.Run(stream);
|
||||||
|
OnPropertyChanged(nameof(RunnerOutput));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
RunnerOutput += $"\nERR: {ex.Message}\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CanRun()
|
private bool CanRun()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue