Skip to content

Commit

Permalink
Small tweaks, bugfixes and missing features.
Browse files Browse the repository at this point in the history
  • Loading branch information
vddCore committed May 24, 2024
1 parent f05e207 commit 9b2d7d0
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 21 deletions.
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# Obsidian metadata
.obsidian/

# User-specific files
*.rsuser
Expand Down Expand Up @@ -33,8 +31,6 @@ bld/

# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/

# Visual Studio 2017 auto generated files
Generated\ Files/
Expand Down
2 changes: 1 addition & 1 deletion Core/EVIL.Lexical/EVIL.Lexical.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>

<Version>4.0.0</Version>
<Version>4.1.0</Version>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
69 changes: 65 additions & 4 deletions Core/EVIL.Lexical/Lexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,71 @@ private Token GetDecimalNumber()
{
var number = string.Empty;

while (char.IsDigit(State.Character) || State.Character == '.')
if (char.IsDigit(State.Character) || State.Character == '.')
{
number += State.Character;
Advance();
var foundDecimalSeparator = false;
var foundExponent = false;
var foundExponentSign = false;

while (char.IsDigit(State.Character) || State.Character == '.'
|| State.Character == 'e'
|| State.Character == 'E'
|| State.Character == '-'
|| State.Character == '+')
{
if (State.Character == '.')
{
if (foundDecimalSeparator)
{
throw new LexerException(
$"Character `{State.Character}' was unexpected at this time.",
State.Line,
State.Column
);
}

foundDecimalSeparator = true;
}

if (State.Character == 'e' || State.Character == 'E')
{
if (foundExponent)
{
throw new LexerException(
$"Character `{State.Character}' was unexpected at this time.",
State.Line,
State.Column
);
}

foundExponent = true;
}

if (State.Character == '+' || State.Character == '-')
{
if (!foundExponent || foundExponentSign)
{
throw new LexerException(
$"Character `{State.Character}' was unexpected at this time.",
State.Line,
State.Column
);
}

foundExponent = true;
}

number += State.Character;
Advance();
}
}
else
{
throw new LexerException(
$"Character `{State.Character}' was unexpected at this time.",
State.Line,
State.Column
);
}

try
Expand All @@ -373,7 +434,7 @@ private Token GetDecimalNumber()
}
catch (FormatException)
{
throw new LexerException("Invalid number format.", State.Line, State.Column);
throw new LexerException($"Malformed numeric constant `{number}'.", State.Line, State.Column);
}
}

Expand Down
2 changes: 1 addition & 1 deletion VirtualMachine/EVIL.Ceres/EVIL.Ceres.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>

<Version>7.4.1</Version>
<Version>7.5.0</Version>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public static Chunk Deserialize(Stream stream, out byte version, out long timest
chunk.MarkSelfAware();
}

if (flags.HasFlag(ChunkFlags.MayThrow))
{
chunk.MarkThrowing();
}

chunk.IsSpecialName = flags.HasFlag(ChunkFlags.IsSpecialName);

if (flags.HasFlag(ChunkFlags.HasParameters))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public sealed partial class Chunk : IDisposable, IEquatable<Chunk>
public int SubChunkCount => SubChunks.Count;
public bool IsSelfAware { get; private set; }
public bool IsSpecialName { get; private set; }
public bool MayThrow { get; private set; }

public IReadOnlyList<int> Labels => _labels;
public IReadOnlyList<ChunkAttribute> Attributes => _attributes;
Expand Down Expand Up @@ -112,6 +113,9 @@ public ChunkFlags Flags

if (ProtectedBlocks.Count > 0)
ret |= ChunkFlags.HasProtectedBlocks;

if (MayThrow)
ret |= ChunkFlags.MayThrow;

return ret;
}
Expand Down Expand Up @@ -183,6 +187,9 @@ public BinaryReader SpawnCodeReader()
);
}

public void MarkThrowing()
=> MayThrow = true;

public void MarkSelfAware()
=> IsSelfAware = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum ChunkFlags
IsSubChunk = 1 << 8,
IsSelfAware = 1 << 9,
IsSpecialName = 1 << 10,
HasProtectedBlocks = 1 << 11
HasProtectedBlocks = 1 << 11,
MayThrow = 1 << 12
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public static void Disassemble(Chunk chunk, TextWriter output, DisassemblyOption
}

output.WriteLine("{");

if (chunk.MayThrow)
{
output.WriteLine($"{indent} .MAY_THROW");
output.WriteLine();
}

output.WriteLine($"{indent} .LOCALS {chunk.LocalCount}");
output.WriteLine($"{indent} .CLOSRS {chunk.ClosureCount}");
Expand Down
24 changes: 20 additions & 4 deletions VirtualMachine/EVIL.Ceres/ExecutionEngine/Diagnostics/Error.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
using EVIL.Ceres.ExecutionEngine.Collections;
using EVIL.Ceres.ExecutionEngine.TypeSystem;
using EVIL.CommonTypes.TypeSystem;

namespace EVIL.Ceres.ExecutionEngine.Diagnostics
{
public class Error
public sealed class Error
{
private Table UserData { get; } = new();

public int Length => UserData.Length;


public string? Message
{
get
{
if (UserData["msg"].Type == DynamicValueType.String)
{
return UserData["msg"].String!;
}

return null;
}

set => UserData["msg"] = value ?? DynamicValue.Nil;
}

public DynamicValue this[DynamicValue key]
{
get => UserData[key];
Expand All @@ -26,13 +42,13 @@ public Error(Table userData)

public Error(string message)
{
UserData["msg"] = message;
Message = message;
}

public Error(Table userData, string message)
{
UserData = userData;
UserData["msg"] = message;
Message = message;
}

public bool Contains(DynamicValue key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ public partial class Compiler
{
public override void Visit(ThrowStatement throwStatement)
{
Chunk.MarkThrowing();

Visit(throwStatement.ThrownExpression);
Chunk.CodeGenerator.Emit(OpCode.THROW);
}
Expand Down
4 changes: 2 additions & 2 deletions VirtualMachine/EVIL.Ceres/TranslationEngine/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public Chunk Compile(string source, string fileName = "")
le.Message,
CurrentFileName,
EvilMessageCode.LexerError,
line: Line,
column: Column,
line: le.Line,
column: le.Column,
innerException: le
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[test]
fn fn_indexed_simple() {
fn fn_indexed_simple {
val t = { };

loc fn t.function(a, b) -> a + b;
Expand All @@ -9,11 +9,22 @@ fn fn_indexed_simple() {
}

#[test]
fn fn_indexed_nested() {
fn fn_indexed_nested {
val t = { q: { } };

loc fn t.q.function(a, b) -> a - b;

assert.is_of_type(t.q.function, Function);
assert.equal(t.q.function(5, 3), 2);
}

#[test]
fn fn_indexed_byref {
val f = fn(table) { loc fn table.func(a, b) -> a * b; };

val t = { };
f(t);

assert.is_of_type(t.func, Function);
assert.equal(t.func(10, 2), 20);
}

0 comments on commit 9b2d7d0

Please sign in to comment.