port from perforce
This commit is contained in:
49
intromat/Intromat/Model/Compiler/CompilerContext.cs
Normal file
49
intromat/Intromat/Model/Compiler/CompilerContext.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Intromat.Model.Compiler
|
||||
{
|
||||
public class ScopeDefinition
|
||||
{
|
||||
public ScopeDefinition(string identifier)
|
||||
{
|
||||
Identifier = identifier;
|
||||
}
|
||||
|
||||
public string Identifier { get; }
|
||||
|
||||
public List<IVariableDefinition> Variables { get; } = new();
|
||||
}
|
||||
|
||||
public class CompilerContext
|
||||
{
|
||||
public Stack<ScopeDefinition> VariablesScopesStack { get; } = new();
|
||||
|
||||
public string FindFreeVariableName()
|
||||
{
|
||||
return "v" + VariablesScopesStack.SelectMany(s => s.Variables).Count();
|
||||
}
|
||||
|
||||
public void AddVariableToCurrentScope(IVariableDefinition variable)
|
||||
{
|
||||
VariablesScopesStack.Peek().Variables.Add(variable);
|
||||
}
|
||||
|
||||
public void EnterNewScope(string scopeIdentifier)
|
||||
{
|
||||
VariablesScopesStack.Push(new ScopeDefinition(scopeIdentifier));
|
||||
}
|
||||
|
||||
public void LeaveScope()
|
||||
{
|
||||
VariablesScopesStack.Pop();
|
||||
}
|
||||
|
||||
public bool IsInScope(IVariableDefinition variable)
|
||||
{
|
||||
if (variable == null) return false;
|
||||
|
||||
return VariablesScopesStack.Any(s => s.Variables.Contains(variable));
|
||||
}
|
||||
}
|
||||
}
|
||||
15
intromat/Intromat/Model/Compiler/Error/CompilerException.cs
Normal file
15
intromat/Intromat/Model/Compiler/Error/CompilerException.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace Intromat.Model.Compiler.Error
|
||||
{
|
||||
public class CompilerException : Exception
|
||||
{
|
||||
public CompilerException(string msg) : base(msg)
|
||||
{
|
||||
}
|
||||
|
||||
public CompilerException(string msg, Exception inner) : base(msg, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Intromat.Model.Compiler.Error
|
||||
{
|
||||
public class VariableOutOfScopeException : CompilerException
|
||||
{
|
||||
public VariableOutOfScopeException(string variableName)
|
||||
: base($"The variable '{variableName}' was referenced outside its scope.")
|
||||
{
|
||||
VariableName = variableName;
|
||||
}
|
||||
|
||||
public string VariableName { get; }
|
||||
}
|
||||
}
|
||||
10
intromat/Intromat/Model/Compiler/IStatement.cs
Normal file
10
intromat/Intromat/Model/Compiler/IStatement.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Intromat.Model.Compiler
|
||||
{
|
||||
public interface IStatement
|
||||
{
|
||||
void Compile(CompilerContext context, StringBuilder sb);
|
||||
void CompileHeader(CompilerContext context, StringBuilder sb);
|
||||
}
|
||||
}
|
||||
15
intromat/Intromat/Model/Compiler/ITypedExpression.cs
Normal file
15
intromat/Intromat/Model/Compiler/ITypedExpression.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Intromat.Model.Compiler
|
||||
{
|
||||
public interface IExpression
|
||||
{
|
||||
void Compile(CompilerContext context, StringBuilder sb);
|
||||
}
|
||||
|
||||
public interface ITypedExpression<T> : IExpression
|
||||
{
|
||||
string? PreviewValue { get; }
|
||||
T Evaluate();
|
||||
}
|
||||
}
|
||||
15
intromat/Intromat/Model/Compiler/MeshValue.cs
Normal file
15
intromat/Intromat/Model/Compiler/MeshValue.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using SharpDX.Direct3D11;
|
||||
|
||||
namespace Intromat.Model.Compiler
|
||||
{
|
||||
public class MeshValue
|
||||
{
|
||||
public MeshValue()
|
||||
{
|
||||
}
|
||||
|
||||
public MeshValue(MeshValue other)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
24
intromat/Intromat/Model/Compiler/TextureValue.cs
Normal file
24
intromat/Intromat/Model/Compiler/TextureValue.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using SharpDX.Direct3D11;
|
||||
|
||||
namespace Intromat.Model.Compiler
|
||||
{
|
||||
public class TextureValue
|
||||
{
|
||||
public TextureValue()
|
||||
{
|
||||
}
|
||||
|
||||
public TextureValue(TextureValue other)
|
||||
{
|
||||
Width = other.Width;
|
||||
Height = other.Height;
|
||||
ShaderResourceView = other.ShaderResourceView;
|
||||
UnorderedAccessView = other.UnorderedAccessView;
|
||||
}
|
||||
|
||||
public int Width { get; set; }
|
||||
public int Height { get; set; }
|
||||
public ShaderResourceView? ShaderResourceView { get; set; }
|
||||
public UnorderedAccessView? UnorderedAccessView { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user