diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2018-03-08 12:35:00 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-03-08 12:35:00 -0800 |
| commit | a22b7520745334ecef3cbd920a0331f01c905935 (patch) | |
| tree | f5ecf29f957f6b40f3fb5a4f987b2a1d00dd3bed /source/slang/core.meta.slang.h | |
| parent | ed718ba1048ef856efbf0d02902e4d60f173b207 (diff) | |
Cleanups on slang-generate (#437)
* Cleanups on slang-generate
There is nothing too significant in these changes, but I'm trying to get
things in place so that we can:
- Clean up the stdlib code to do less explicit `StringBuilder`
operations and instead to use more of the "template engine" approach
- Start using slang-generate for code other than the slang stdlib, so
that we can generate more of our boilerplate.
The main new functionality here is that in a template/meta file, you can
now enclose an expression in `$(...)` to indicate that is should be
spliced into the result. E.g. instead of:
class ${{ sb << someClassName; }}
{
...
}
We can now write:
class $(someClassName)
{
...
}
The other bit of new functionality is support for a whole-line statement
escape, so that instead of:
${{ for( auto a : someCollection ) { }}
void $(a)() { ... }
${{ } }}
We can instead write:
$: for(auto a : someCollection) {
void $(a)() { ... }
$: }
I haven't yet tried to use that functionality in the stdlib meta-code,
but doing so would be an obvious next step.
* Fixup: change some $P to $p
The capitalization on some of the GLSL intrinsic mappings got messed up during a find-and-replace operation when removing the double `$` that used to be required to escape things.
Diffstat (limited to 'source/slang/core.meta.slang.h')
| -rw-r--r-- | source/slang/core.meta.slang.h | 131 |
1 files changed, 59 insertions, 72 deletions
diff --git a/source/slang/core.meta.slang.h b/source/slang/core.meta.slang.h index 1e1c25788..974607a75 100644 --- a/source/slang/core.meta.slang.h +++ b/source/slang/core.meta.slang.h @@ -1,39 +1,38 @@ -sb << "// Slang `core` library\n"; -sb << "\n"; -sb << "// Modifier for variables that must resolve to compile-time constants\n"; -sb << "// as part of translation.\n"; -sb << "syntax constexpr : ConstExprModifier;\n"; -sb << "\n"; -sb << "// A type that can be used as an operand for builtins\n"; -sb << "interface __BuiltinType {}\n"; -sb << "\n"; -sb << "// A type that can be used for arithmetic operations\n"; -sb << "interface __BuiltinArithmeticType : __BuiltinType {}\n"; -sb << "\n"; -sb << "// A type that logically has a sign (positive/negative/zero)\n"; -sb << "interface __BuiltinSignedArithmeticType : __BuiltinArithmeticType {}\n"; -sb << "\n"; -sb << "// A type that can represent integers\n"; -sb << "interface __BuiltinIntegerType : __BuiltinArithmeticType\n"; -sb << "{}\n"; -sb << "\n"; -sb << "// A type that can represent non-integers\n"; -sb << "interface __BuiltinRealType : __BuiltinArithmeticType {}\n"; -sb << "\n"; -sb << "// A type that uses a floating-point representation\n"; -sb << "interface __BuiltinFloatingPointType : __BuiltinRealType, __BuiltinSignedArithmeticType\n"; -sb << "{\n"; -sb << " // A builtin floating-point type must have an initializer that takes\n"; -sb << " // a floating-point value...\n"; -sb << " __init(float value);\n"; -sb << "}\n"; -sb << "\n"; -sb << "__generic<T,U> __intrinsic_op(Sequence) U operator,(T left, U right);\n"; -sb << "\n"; -sb << "__generic<T> __intrinsic_op(select) T operator?:(bool condition, T ifTrue, T ifFalse);\n"; -sb << "__generic<T, let N : int> __intrinsic_op(select) vector<T,N> operator?:(vector<bool,N> condition, vector<T,N> ifTrue, vector<T,N> ifFalse);\n"; -sb << "\n"; -sb << ""; +SLANG_RAW("// Slang `core` library\n") +SLANG_RAW("\n") +SLANG_RAW("// Modifier for variables that must resolve to compile-time constants\n") +SLANG_RAW("// as part of translation.\n") +SLANG_RAW("syntax constexpr : ConstExprModifier;\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can be used as an operand for builtins\n") +SLANG_RAW("interface __BuiltinType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can be used for arithmetic operations\n") +SLANG_RAW("interface __BuiltinArithmeticType : __BuiltinType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that logically has a sign (positive/negative/zero)\n") +SLANG_RAW("interface __BuiltinSignedArithmeticType : __BuiltinArithmeticType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can represent integers\n") +SLANG_RAW("interface __BuiltinIntegerType : __BuiltinArithmeticType\n") +SLANG_RAW("{}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that can represent non-integers\n") +SLANG_RAW("interface __BuiltinRealType : __BuiltinArithmeticType {}\n") +SLANG_RAW("\n") +SLANG_RAW("// A type that uses a floating-point representation\n") +SLANG_RAW("interface __BuiltinFloatingPointType : __BuiltinRealType, __BuiltinSignedArithmeticType\n") +SLANG_RAW("{\n") +SLANG_RAW(" // A builtin floating-point type must have an initializer that takes\n") +SLANG_RAW(" // a floating-point value...\n") +SLANG_RAW(" __init(float value);\n") +SLANG_RAW("}\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<T,U> __intrinsic_op(Sequence) U operator,(T left, U right);\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<T> __intrinsic_op(select) T operator?:(bool condition, T ifTrue, T ifFalse);\n") +SLANG_RAW("__generic<T, let N : int> __intrinsic_op(select) vector<T,N> operator?:(vector<bool,N> condition, vector<T,N> ifTrue, vector<T,N> ifFalse);\n") +SLANG_RAW("\n") // We are going to use code generation to produce the // declarations for all of our base types. @@ -98,27 +97,23 @@ for (int tt = 0; tt < kBaseTypeCount; ++tt) // Declare built-in pointer type // (eventually we can have the traditional syntax sugar for this) - -sb << "\n"; -sb << "\n"; -sb << "__generic<T>\n"; -sb << "__magic_type(PtrType)\n"; -sb << "struct Ptr\n"; -sb << "{};\n"; -sb << "\n"; -sb << "__generic<T>\n"; -sb << "__magic_type(OutType)\n"; -sb << "struct Out\n"; -sb << "{};\n"; -sb << "\n"; -sb << "__generic<T>\n"; -sb << "__magic_type(InOutType)\n"; -sb << "struct InOut\n"; -sb << "{};\n"; -sb << "\n"; -sb << ""; - - +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<T>\n") +SLANG_RAW("__magic_type(PtrType)\n") +SLANG_RAW("struct Ptr\n") +SLANG_RAW("{};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<T>\n") +SLANG_RAW("__magic_type(OutType)\n") +SLANG_RAW("struct Out\n") +SLANG_RAW("{};\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<T>\n") +SLANG_RAW("__magic_type(InOutType)\n") +SLANG_RAW("struct InOut\n") +SLANG_RAW("{};\n") +SLANG_RAW("\n") // Declare vector and matrix types @@ -134,18 +129,12 @@ sb << " __init(T value);\n"; sb << " __init(vector<T,N> value);\n"; sb << "};\n"; - -// TODO: Probably need to do similar -sb << "\n"; -sb << "\n"; -sb << "__generic<T = float, let R : int = 4, let C : int = 4>\n"; -sb << "__magic_type(Matrix)\n"; -sb << "struct matrix {};\n"; -sb << "\n"; -sb << ""; - - - +SLANG_RAW("\n") +SLANG_RAW("\n") +SLANG_RAW("__generic<T = float, let R : int = 4, let C : int = 4>\n") +SLANG_RAW("__magic_type(Matrix)\n") +SLANG_RAW("struct matrix {};\n") +SLANG_RAW("\n") static const struct { char const* name; @@ -1038,6 +1027,4 @@ for (auto op : binaryOps) sb << "__intrinsic_op(" << int(op.opCode) << ") matrix<" << resultType << ",N,M> operator" << op.opName << "(" << leftQual << "matrix<" << leftType << ",N,M> left, " << rightType << " right);\n"; } } - -sb << "\n"; -sb << ""; +SLANG_RAW("\n") |
