mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-02-14 19:29:36 +01:00
* Move RobustXaml to a shared package In a near-future change, I'll make it possible to optionally link to this from Robust.Client, which will allow JIT compiling XAML. Also upgrade it to a version of .NET that supports nullability annotations. * Re-namespace packages * Add a JIT compiler, plus hooks that call into it In Debug, after this change, all XAML will be hot reloaded once every time an assembly is reloaded. The new code is compiled with SRE and is _not_ sandboxed -- this is not suitable to run against prod. In Release, the hot reload path is totally skipped, using the same trick as SmugLeaf used in an earlier attempt to implement this functionality. * Hot reload: watcher This is a bit of a horror, but there's not in-engine support for identifying the source tree or the XAML files in it. * Put everything dangerous behind conditional comp * Code cleanup, docs * Fix a bad comment * Deal a little better with crashes in the watcher * Make reload failures Info, since they're expected They were previously causing the integration tests to flag, even though "a few types fail hot reloading because they're internal" is expected behavior. * Fix an unnecessary null check I removed the ability for CompileCore to return null. * injectors: null! strings, default primitives * Tidy documentation (thanks, PJB!) * Reinstate netstandard2.0, abolish Pidgin * Internal-ize all of Robust.Xaml * Add a cautionary note to Sandbox.yml * Shuffle around where conditional compilation occurs * Privatize fields in XamlImplementationStorage * Internalize XamlJitDelegate * Inline some remarks. No cond. comp in Robust.Xaml * Use file-scoped namespaces They aren't allowed at Language Level 8.0. (which I arbitrarily picked for Robust.Xaml because it's the oldest one that would work) * Bump language level for R.Xaml, file namespaces * Force hot reloading off for integration tests * Fix bizarre comment/behavior in XamlImplementationStorage * Consistently use interfaces, even in generated code * Update Robust.Client/ClientIoC.cs --------- Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Reflection.Emit;
|
|
using XamlX.Ast;
|
|
using XamlX.Emit;
|
|
using XamlX.IL;
|
|
using XamlX.TypeSystem;
|
|
|
|
namespace Robust.Xaml
|
|
{
|
|
internal abstract class RXamlVecLikeConstAstNode<T>
|
|
: XamlAstNode, IXamlAstValueNode, IXamlAstILEmitableNode
|
|
where T : unmanaged
|
|
{
|
|
private readonly IXamlConstructor _constructor;
|
|
protected readonly T[] Values;
|
|
|
|
public RXamlVecLikeConstAstNode(
|
|
IXamlLineInfo lineInfo,
|
|
IXamlType type, IXamlConstructor constructor,
|
|
IXamlType componentType, T[] values)
|
|
: base(lineInfo)
|
|
{
|
|
_constructor = constructor;
|
|
Values = values;
|
|
|
|
var @params = constructor.Parameters;
|
|
|
|
if (@params.Count != values.Length)
|
|
throw new ArgumentException("Invalid amount of parameters");
|
|
|
|
if (@params.Any(c => c != componentType))
|
|
throw new ArgumentException("Invalid constructor: not all parameters match component type");
|
|
|
|
Type = new XamlAstClrTypeReference(lineInfo, type, false);
|
|
}
|
|
|
|
public IXamlAstTypeReference Type { get; }
|
|
|
|
public virtual XamlILNodeEmitResult Emit(
|
|
XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context,
|
|
IXamlILEmitter codeGen)
|
|
{
|
|
codeGen.Newobj(_constructor);
|
|
|
|
return XamlILNodeEmitResult.Type(0, Type.GetClrType());
|
|
}
|
|
}
|
|
|
|
internal sealed class RXamlSingleVecLikeConstAstNode : RXamlVecLikeConstAstNode<float>
|
|
{
|
|
public RXamlSingleVecLikeConstAstNode(
|
|
IXamlLineInfo lineInfo,
|
|
IXamlType type, IXamlConstructor constructor,
|
|
IXamlType componentType, float[] values)
|
|
: base(lineInfo, type, constructor, componentType, values)
|
|
{
|
|
}
|
|
|
|
public override XamlILNodeEmitResult Emit(XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context,
|
|
IXamlILEmitter codeGen)
|
|
{
|
|
foreach (var value in Values)
|
|
{
|
|
codeGen.Emit(OpCodes.Ldc_R4, value);
|
|
}
|
|
|
|
return base.Emit(context, codeGen);
|
|
}
|
|
}
|
|
|
|
internal sealed class RXamlInt32VecLikeConstAstNode : RXamlVecLikeConstAstNode<int>
|
|
{
|
|
public RXamlInt32VecLikeConstAstNode(
|
|
IXamlLineInfo lineInfo,
|
|
IXamlType type, IXamlConstructor constructor,
|
|
IXamlType componentType, int[] values)
|
|
: base(lineInfo, type, constructor, componentType, values)
|
|
{
|
|
}
|
|
|
|
public override XamlILNodeEmitResult Emit(XamlEmitContext<IXamlILEmitter, XamlILNodeEmitResult> context,
|
|
IXamlILEmitter codeGen)
|
|
{
|
|
foreach (var value in Values)
|
|
{
|
|
codeGen.Emit(OpCodes.Ldc_I4, value);
|
|
}
|
|
|
|
return base.Emit(context, codeGen);
|
|
}
|
|
}
|
|
}
|