-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #267 from NoiseStudio/feature/266/add-intrinsic-to…
…-compiled-default-shader Add intrinsic to compiled default shader
- Loading branch information
Showing
23 changed files
with
418 additions
and
50 deletions.
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
NoiseEngine.Tests/Nesl/CompilerTools/Parsing/Methods/AccessModifiers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using NoiseEngine.Tests.Environments; | ||
|
||
namespace NoiseEngine.Tests.Nesl.CompilerTools.Parsing.Methods; | ||
|
||
public class AccessModifiers : NeslParsingTestEnvironment { | ||
|
||
[Fact] | ||
public void Default() { | ||
CompileSingle(@" | ||
struct Kkard2 { | ||
Mock Method() { | ||
return new Mock(); | ||
} | ||
} | ||
struct Mock {} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void Local() { | ||
CompileSingle(@" | ||
struct Xori { | ||
local Mock Method() { | ||
return new Mock(); | ||
} | ||
} | ||
struct Mock {} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void Internal() { | ||
CompileSingle(@" | ||
struct Vixen { | ||
internal Mock Method() { | ||
return new Mock(); | ||
} | ||
} | ||
struct Mock {} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void Public() { | ||
CompileSingle(@" | ||
struct Pp { | ||
public Mock Method() { | ||
return new Mock(); | ||
} | ||
} | ||
struct Mock {} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void NotExists() { | ||
CompileSingleThrowAny(@" | ||
struct TerQ { | ||
NotExistsAccessModifier Mock Method() { | ||
return new Mock(); | ||
} | ||
} | ||
struct Mock {} | ||
"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
NoiseEngine.Tests/Nesl/CompilerTools/Parsing/Properties/AccessModifiers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using NoiseEngine.Tests.Environments; | ||
|
||
namespace NoiseEngine.Tests.Nesl.CompilerTools.Parsing.Properties; | ||
|
||
public class AccessModifiers : NeslParsingTestEnvironment { | ||
|
||
[Fact] | ||
public void Default() { | ||
CompileSingle(@" | ||
struct Kkard2 { | ||
f32 value { get; } | ||
} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void Local() { | ||
CompileSingle(@" | ||
struct Xori { | ||
local f32 value { get; } | ||
} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void Internal() { | ||
CompileSingle(@" | ||
struct Vixen { | ||
internal f32 value { get; } | ||
} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void Public() { | ||
CompileSingle(@" | ||
struct Pp { | ||
public f32 Value { get; } | ||
} | ||
"); | ||
} | ||
|
||
[Fact] | ||
public void NotExists() { | ||
CompileSingleThrowAny(@" | ||
struct TerQ { | ||
NotExistsAccessModifier f32 value { get; } | ||
} | ||
"); | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
NoiseEngine.Tests/Nesl/CompilerTools/Parsing/Properties/Universal.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using NoiseEngine.Nesl; | ||
using NoiseEngine.Nesl.Emit.Attributes.Internal; | ||
using NoiseEngine.Tests.Environments; | ||
using System.Linq; | ||
|
||
namespace NoiseEngine.Tests.Nesl.CompilerTools.Parsing.Properties; | ||
|
||
public class Universal : NeslParsingTestEnvironment { | ||
|
||
[Fact] | ||
public void Intrinsic() { | ||
NeslType type = CompileSingle(@" | ||
local static class Box { | ||
[Intrinsic] | ||
public static f32 TestProperty { get; } | ||
} | ||
").Types.Single(); | ||
|
||
string methodName = NeslOperators.PropertyGet + "TestProperty"; | ||
NeslMethod method = type.Methods.Single(x => x.Name == methodName); | ||
|
||
Assert.True(method.Attributes.HasAnyAttribute(IntrinsicAttribute.Create().FullName)); | ||
Assert.Empty(method.GetIlContainer().GetInstructions()); | ||
|
||
Assert.Empty(type.Fields); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
public static class ComputeUtils { | ||
|
||
[Intrinsic] | ||
public static u32v3 GlobalInvocation3 { get; } | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[PlatformDependentTypeRepresentation("OpTypeMatrix4`{&T}`4")] | ||
public struct Matrix4x4<T> { | ||
|
||
public Vector4<T> C0; | ||
public Vector4<T> C1; | ||
public Vector4<T> C2; | ||
public Vector4<T> C3; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[PlatformDependentTypeRepresentation("OpTypeArray`{&T}")] | ||
public class RwBuffer<T> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[PlatformDependentTypeRepresentation("OpTypeVector`{&T}`2")] | ||
public struct Vector2<T> { | ||
|
||
public T X; | ||
public T Y; | ||
public T X; | ||
public T Y; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
[PlatformDependentTypeRepresentation("OpTypeVector`{&T}`3")] | ||
public struct Vector3<T> { | ||
|
||
public T X; | ||
public T Y; | ||
public T Z; | ||
public T X; | ||
public T Y; | ||
public T Z; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
[PlatformDependentTypeRepresentation("OpTypeVector`{&T}`4")] | ||
public struct Vector4<T> { | ||
|
||
public T X; | ||
public T Y; | ||
public T Z; | ||
public T W; | ||
public T X; | ||
public T Y; | ||
public T Z; | ||
public T W; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
public static class VertexUtils { | ||
|
||
[Intrinsic] | ||
public static i32 Index { get; } | ||
|
||
[Intrinsic] | ||
public static f32v4 ObjectToClipPos(f32v3 position) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
NoiseEngine/Nesl/CompilerTools/Parsing/Expressions/PropertyDeclaration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using NoiseEngine.Nesl.CompilerTools.Parsing.Tokens; | ||
using System; | ||
|
||
namespace NoiseEngine.Nesl.CompilerTools.Parsing.Expressions; | ||
|
||
internal class PropertyDeclaration : ParserExpressionContainer { | ||
|
||
public PropertyDeclaration(Parser parser) : base(parser) { | ||
} | ||
|
||
[ParserExpression(ParserStep.TopLevel | ParserStep.Type)] | ||
[ParserExpressionParameter(ParserTokenType.Attributes)] | ||
[ParserExpressionParameter(ParserTokenType.AccessModifiers)] | ||
[ParserExpressionParameter(ParserTokenType.Modifiers)] | ||
[ParserExpressionParameter(ParserTokenType.TypeIdentifier)] | ||
[ParserExpressionParameter(ParserTokenType.Name)] | ||
[ParserExpressionParameter(ParserTokenType.CurlyBrackets)] | ||
public void Define( | ||
AttributesToken attribute, AccessModifiersToken accessModifiers, ModifiersToken modifiers, | ||
TypeIdentifierToken typeIdentifier, NameToken name, CurlyBracketsToken curlyBrackets | ||
) { | ||
TokenBuffer buffer = curlyBrackets.Buffer; | ||
bool hasWord = buffer.TryReadNext(TokenType.Word, out Token word); | ||
if (!hasWord || word.Value! != "get") | ||
Parser.Throw(new CompilationError(word, CompilationErrorType.ExpectedGetter)); | ||
if (hasWord && !SemicolonToken.Parse(buffer, Parser.ErrorMode, out _, out CompilationError semicolonError)) | ||
Parser.Throw(semicolonError); | ||
|
||
if (!hasWord) | ||
return; | ||
|
||
if (!Parser.TryDefineProperty(new PropertyDefinitionData( | ||
typeIdentifier, name, false, false, null, attribute.Compile(Parser, AttributeTargets.Method), null, | ||
Array.Empty<NeslAttribute>() | ||
))) { | ||
Parser.Throw(new CompilationError( | ||
name.Pointer, CompilationErrorType.FieldOrPropertyAlreadyExists, name.Name | ||
)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.