Language and working Interpreter using only TypeScript types (no JavaScript either written or emitted)
type Program<Bool extends True | False> = __<
Set<$<"returnValue">, String<"">>,
__<
Set<$<"test">, Bool>,
__<
If<
$<"test">,
Set<$<"returnValue">, String<"It's true!">>,
Set<$<"returnValue">, String<"unfortunately false :(">>
>,
Return<$<"returnValue">>
>
>
>;
const test1: RunProgram<Program<False>> = {
result: "unfortunately false :(",
error: {
$signal: "return"
}
};
const test2: RunProgram<Program<True>> = {
result: "It's true!",
error: {
$signal: "return"
}
};Yeah, this was a saturday project! So don't even think about production environment.
I love typelevel programming in TypeScript, so I thought... can I bring it to next level? Turned out that building a programming language and it's intepreter using only type definitions in TypeScript! :D
- ReturnStatement
- TrueKeyword
- FalseKeyword
- StringLiteral
- Not
- Equals
- And
- Expression
- Block
- Identifier
- VariableDeclaration
- ConditionalExpression
