clean up code a bit and revert back to .net8 in a desperate attempt to fix the profiler
This commit is contained in:
parent
dc94c16b03
commit
9e4fbd5906
|
|
@ -1,5 +1,4 @@
|
|||
|
||||
using Qrakhen.Qamp.Core;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using Qrakhen.Qamp.Core.Tokenization;
|
||||
using System.Text;
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,18 @@ using Qrakhen.Qamp.Core.Execution;
|
|||
using Qrakhen.Qamp.Core.Logging;
|
||||
using System.Text;
|
||||
|
||||
char[] Ignored = [ '\0', '\b' ];
|
||||
// do args here too, keep console, etc. output with exit, all the spicy things
|
||||
// if no file is given for example in args just keep cli live until quit
|
||||
|
||||
List<char> Ignored = [ '\0', '\b' ];
|
||||
LoggerService.Default = LogLevel.Error;
|
||||
Stack<byte[]> History = [];
|
||||
List<byte[]> History = [];
|
||||
int historyCursor = -1;
|
||||
ConsoleKeyInfo input;
|
||||
bool useSyntaxHighlighting = false;
|
||||
(int x, int y) cursor = (0, 0);
|
||||
ConsoleCode code = ConsoleCode.Error;
|
||||
Runner runner = new Runner(new Options());
|
||||
ConsoleWriter cli = new ConsoleWriter(Encoding.Default);
|
||||
Runner runner = new(new Options());
|
||||
do {
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
MemoryStream stream = new MemoryStream();
|
||||
|
|
@ -53,6 +56,18 @@ do {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (input.Key == ConsoleKey.UpArrow) {
|
||||
historyCursor = Math.Min(History.Count - 1, historyCursor + 1);
|
||||
byte[] bytes = History[historyCursor];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (input.Key == ConsoleKey.DownArrow) {
|
||||
historyCursor = Math.Max(0, historyCursor - 1);
|
||||
byte[] bytes = History[historyCursor];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (input.Key == ConsoleKey.Backspace && stream.Position > 0) {
|
||||
Console.CursorLeft -= 1;
|
||||
Console.Write(' ');
|
||||
|
|
@ -72,8 +87,10 @@ do {
|
|||
}
|
||||
} while (input.Key != ConsoleKey.Enter || input.Modifiers == ConsoleModifiers.Shift);
|
||||
try {
|
||||
History.Insert(0, stream.GetBuffer());
|
||||
Console.WriteLine();
|
||||
runner.Run(stream);
|
||||
stream.Dispose();
|
||||
}
|
||||
catch (QampException e) {
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\Build\</BaseOutputPath>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Abstractions;
|
||||
|
||||
public interface IDebug<out T>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Abstractions;
|
||||
|
||||
public interface ISerialize<TSelf>
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using System.Numerics;
|
||||
|
||||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IAdd<out TKey, in TValue>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface ICaptureBuffer<TData, THandle>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IConsumable<in T>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IGet<in TKey, out TValue>
|
||||
{
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IGetSet<in TKey, TValue> : IGet<TKey, TValue>, ISet<TKey, TValue>;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IPeekable<out T>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IReadable<out T>
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
using Qrakhen.Qamp.Core.Tokenization;
|
||||
|
||||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IReader<out T>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface ISeekable<TKey, out TValue>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface ISet<in TKey, in TValue>
|
||||
{
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IStack<out TKey, TValue> : IPush<TKey, TValue>, IPop<TValue>;
|
||||
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface ISteppable<out T>
|
||||
{
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
public interface IToArray<out T>
|
||||
{
|
||||
T[] ToArray();
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using System.Collections;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using System.Collections;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Dynamic Pointer able to point to any object implementing the <see cref="IGetSet{long, TValue}"/> interface.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using System.Collections;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Push-only Stack that is based on <see cref="Expander{T}"/>.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Collections;
|
||||
|
||||
/// <summary>
|
||||
/// Stack-like implementation with a few added features like seeking and setting values.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Abstractions;
|
||||
using Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Execution;
|
||||
using Qrakhen.Qamp.Core.Values;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ using Qrakhen.Qamp.Core.Compilation.Builders;
|
|||
using Qrakhen.Qamp.Core.Values.Objects;
|
||||
using Qrakhen.Qamp.Core.Tokenization;
|
||||
using Qrakhen.Qamp.Core.Logging;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Compilation;
|
||||
|
||||
|
|
|
|||
|
|
@ -107,17 +107,11 @@ public static class ExpressionParser
|
|||
else
|
||||
break;
|
||||
}
|
||||
digester.Consume(TokenType.ArrayClose, "Expected ']' after array definition");
|
||||
digester.Consume(TokenType.ArrayClose, "Expected ']' after array declaration");
|
||||
digester.EmitDynamic(OpCode.Array, length); // digester.MakeConstant(new Value((long)length)));
|
||||
}
|
||||
|
||||
static void ArrayAdd(Digester digester, bool canAssign)
|
||||
{
|
||||
digester.ParseExpression();
|
||||
digester.Emit(OpCode.ArrayAdd);
|
||||
}
|
||||
|
||||
static void Index(Digester digester, bool canAssign)
|
||||
static void ArrayAccessor(Digester digester, bool canAssign)
|
||||
{
|
||||
digester.ParseExpression();
|
||||
digester.Consume(TokenType.ArrayClose, "expected ] after array accessor");
|
||||
|
|
@ -252,7 +246,7 @@ public static class ExpressionParser
|
|||
_rules[TokenType.GroupClose] = new Rule(null, null, Weight.None);
|
||||
_rules[TokenType.ContextOpen] = new Rule(null, null, Weight.None);
|
||||
_rules[TokenType.ContextClose] = new Rule(null, null, Weight.None);
|
||||
_rules[TokenType.ArrayOpen] = new Rule(Array, Index, Weight.Call);
|
||||
_rules[TokenType.ArrayOpen] = new Rule(Array, ArrayAccessor, Weight.Call);
|
||||
_rules[TokenType.ArrayClose] = new Rule(null, null, Weight.None);
|
||||
_rules[TokenType.ArrayAdd] = new Rule(null, null, Weight.None);
|
||||
_rules[TokenType.ArrayRemove] = new Rule(null, null, Weight.None);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Qrakhen.Qamp.Core.Tokenization;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using Qrakhen.Qamp.Core.Tokenization;
|
||||
using Qrakhen.Qamp.Core.Values;
|
||||
|
||||
namespace Qrakhen.Qamp.Core;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Qrakhen.Qamp.Core.Execution;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Execution;
|
||||
|
||||
public class Instructions<T>(IEnumerable<T> instructions) :
|
||||
ISteppable<T>,
|
||||
|
|
|
|||
|
|
@ -192,6 +192,26 @@ public class Runner : IDisposable
|
|||
break;
|
||||
}
|
||||
|
||||
case Op.Array: {
|
||||
// essentially collect all pushed values and create an array, no?
|
||||
break;
|
||||
}
|
||||
|
||||
case Op.ArrayGet: {
|
||||
// attempt to retrieve nth element of array on stack
|
||||
break;
|
||||
}
|
||||
|
||||
case Op.ArraySet: {
|
||||
// set nth item on array
|
||||
break;
|
||||
}
|
||||
|
||||
case Op.ArrayAdd: {
|
||||
// add to array
|
||||
break;
|
||||
}
|
||||
|
||||
case Op.Jump: {
|
||||
long delta = call.Instruction.NextLong();
|
||||
call.Instruction.Cursor += delta;
|
||||
|
|
@ -260,7 +280,7 @@ public class Runner : IDisposable
|
|||
break;
|
||||
}
|
||||
|
||||
case Op.Return: // todo: not done
|
||||
case Op.Return:
|
||||
Value result = Pop();
|
||||
CloseOuters(call.StackPtr.Branch());
|
||||
Calls.Pop();
|
||||
|
|
@ -288,7 +308,7 @@ public class Runner : IDisposable
|
|||
if (!inheritingClass.Members.Has(member.Key))
|
||||
inheritingClass.Members.Add(member.Key, member.Value);
|
||||
}
|
||||
Pop(); //
|
||||
Pop();
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -321,14 +341,14 @@ public class Runner : IDisposable
|
|||
|
||||
case Op.PrintStack: {
|
||||
for (int i = 0; i < Cursor; i++) {
|
||||
Console.WriteLine($"{Stack[i].ToString(true)}");
|
||||
IO.Console.Write($"{Stack[i].ToString(true)}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case Op.PrintGlobals: {
|
||||
foreach (var value in Globals) {
|
||||
Console.WriteLine($"{value.Key}: {value.Value.ToString(true)}");
|
||||
IO.Console.Write($"{value.Key}: {value.Value.ToString(true)}");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Abstractions;
|
||||
using Qrakhen.Qamp.Core.Collections;
|
||||
using Qrakhen.Qamp.Core.Values;
|
||||
using Qrakhen.Qamp.Core.Values.Objects;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ public static class Extensions
|
|||
{
|
||||
if (string.IsNullOrEmpty(str))
|
||||
return 0;
|
||||
|
||||
byte[] bytes = Encoding.ASCII.GetBytes(str);
|
||||
unchecked {
|
||||
uint hash = 216613661u;
|
||||
|
|
@ -73,10 +74,8 @@ public static class Extensions
|
|||
public static int GetPrimitiveLength(this long value)
|
||||
{
|
||||
int length = 8;
|
||||
for (int i = 1; i < 8; i++)
|
||||
{
|
||||
if (value <= (1L << (i * 8)))
|
||||
{
|
||||
for (int i = 1; i < 8; i++) {
|
||||
if (value <= (1L << (i * 8))) {
|
||||
length = i;
|
||||
break;
|
||||
}
|
||||
|
|
@ -84,7 +83,6 @@ public static class Extensions
|
|||
return length;
|
||||
}
|
||||
|
||||
|
||||
public static byte[] GetBytes(this short value) => BitConverter.GetBytes(value);
|
||||
public static byte[] GetBytes(this ushort value) => BitConverter.GetBytes(value);
|
||||
public static byte[] GetBytes(this int value) => BitConverter.GetBytes(value);
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
namespace Qrakhen.Qamp.Core;
|
||||
|
||||
public interface IToArray<out T>
|
||||
{
|
||||
T[] ToArray();
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
using Qrakhen.Qamp.Core.Logging;
|
||||
using Qrakhen.Qamp.Core.Collections.Abstractions;
|
||||
using Qrakhen.Qamp.Core.Logging;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using static Qrakhen.Qamp.Core.Tokenization.TokenType;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
namespace Qrakhen.Qamp.Core.Tokenization;
|
||||
using Qrakhen.Qamp.Core.Abstractions;
|
||||
|
||||
namespace Qrakhen.Qamp.Core.Tokenization;
|
||||
|
||||
public class Tokens : IDebug<string>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,5 +4,20 @@ public class Array(IEnumerable<Value> data) : Obj(ValueType.Array)
|
|||
{
|
||||
public List<Value> Data = [..data];
|
||||
|
||||
public override string ToString() => $"Array [{Data.Count}]";
|
||||
public void Set(int index, Value value)
|
||||
{
|
||||
Data[index] = value;
|
||||
}
|
||||
|
||||
public Value Get(int index)
|
||||
{
|
||||
return Data[index];
|
||||
}
|
||||
|
||||
public void Add(Value value)
|
||||
{
|
||||
Data.Add(value);
|
||||
}
|
||||
|
||||
public override string ToString() => $"[{string.Join(", ", Data)}]";
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
namespace Qrakhen.Qamp.Core.Values.Objects;
|
||||
|
||||
public class Dictionary(IEnumerable<KeyValuePair<string, Value>> data) : Obj(ValueType.Object)
|
||||
{
|
||||
public Dictionary<string, Value> Data = new(data);
|
||||
|
||||
public void Set(string key, Value value)
|
||||
{
|
||||
Data[key] = value;
|
||||
}
|
||||
|
||||
public Value Get(string key)
|
||||
{
|
||||
if (Data.TryGetValue(key, out Value value))
|
||||
return value;
|
||||
return Value.Void;
|
||||
}
|
||||
|
||||
public override string ToString() => $"[{string.Join(", ", Data)}]";
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime.InteropServices;
|
||||
using Qrakhen.Qamp.Core.Abstractions;
|
||||
using Qrakhen.Qamp.Core.Values.Objects;
|
||||
using String = Qrakhen.Qamp.Core.Values.Objects.String;
|
||||
using T = Qrakhen.Qamp.Core.Values.ValueType;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\Build\</BaseOutputPath>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
|
||||
|
|
|
|||
14
README.md
14
README.md
|
|
@ -38,12 +38,13 @@ All of the following examples are written in the classic dialect `--dialect=sqr`
|
|||
### Syntax
|
||||
|
||||
Most basic Usage:
|
||||
```
|
||||
# This is a comment.
|
||||
*~ q <~ 12;
|
||||
*~ f <~ (n) <: n < 2 ? n : f(n-1) + f(n-2);
|
||||
*~ a <~ [1, 2, 3];
|
||||
*~ x <~ a:0 + a:2; # = 4
|
||||
```cs
|
||||
# this is a comment.
|
||||
*~ q <~ 12; # q == 12
|
||||
*~ f <~ (n) <: n < 2 ? n : f(n-1) + f(n-2); # fibonacci
|
||||
f(12); # 233
|
||||
*~ a <~ [1, 2, 3]; # a = [1, 2, 3]
|
||||
*~ x <~ a:0 + a:2; # x == 4
|
||||
```
|
||||
|
||||
### Assignments
|
||||
|
|
@ -51,6 +52,7 @@ Most basic Usage:
|
|||
**Q&** has two distinct ways to assign a value to a variable:
|
||||
- By reference `<&`, or
|
||||
- By value `<=`.
|
||||
|
||||
Using the auto-assignment operator `<~`, **Q&** will choose the correct assignment based on what
|
||||
type the right-hand expression consists of.
|
||||
Primitive types will be assigned by value, any object values will be assigned by reference.
|
||||
|
|
|
|||
Loading…
Reference in New Issue