Compare commits

..

21 Commits

Author SHA1 Message Date
6f44567306 refactor: Extend reflection to all implementations so far
And also enhances the reflected type parsing so that the types of all
  implementations so far will parse.
2023-10-17 14:54:10 -07:00
d8199341e0 refactor: Settle on making all implementations (possibly vacuous) factories 2023-10-16 18:48:26 -07:00
ebe7cf831e refactor: Explore final patterns for runtime typing with ts-macros
The idea is to have a single macro which lets you reflect multiple
  implementations. That's provided in this commit. However, there
  is a hitch with implementations that have no dependencies: the
  reflectedType property did not exist on the Signature type. However,
  if you add it, then the Signature type becomes opaque, so we would
  have to look up signatures; but that appears to be tricky, as there
  doesn't seem to be a way to reflect the full generic type of the
  Signatures interface.

  So this commit provides three example resolutions:
  (A) Export a type RTT and all no-dependency implementations have to
      intersect with RTT (see 'add' in number/arithmetic.ts)
  (B) Write no-dependency implementations as functions of no arguments
      (representing no dependencies passed in) returning the actual
      implementation (see 'subtract' in number/arithmetic.ts)
  (C) Make a special DSignature<> generic type (short for "Direct Signature"
      used only (and always) for implementations with no dependencies, and
      a matching $Dreflect!() macro for generating their type info.

  Of course, there may be other possibilities I haven't thought of. But we
  need to pick one. I don't think it matters _too_ much, since there only
  a small fraction of all implementations have no dependencies.
2023-10-15 19:58:38 -07:00
49b1332917 feat: Add reflecTypes that allows multiple reflections at once 2023-10-09 21:10:15 -07:00
457b9cdc91 refactor: Possible alternate syntax for reflection 2023-09-30 15:52:14 -07:00
20236355c1 feat: do not generate export via macro but keep the export in TS for better DX 2023-09-29 15:36:22 +02:00
632c82966b chore: upgrade to ts-macros@5.2.0 instead of directly from git 2023-09-28 11:30:44 +02:00
2f7677c371 chore: output the reflected types enclosed in quotes for clarity 2023-09-21 21:09:04 +02:00
1ca0ac42d0 feate: implement a basic parser for the reflected types 2023-09-21 21:01:38 +02:00
fd4ecd70ba chore: use exact version numbers 2023-09-21 15:04:18 +02:00
0ebaaf35ee feat: convert sqrt for numbers 2023-09-21 15:02:42 +02:00
20078d2c87 use ts-macros directly from Github until v2.4.2 is published on npm 2023-09-21 14:58:51 +02:00
ce974e2a99 log the reflectedType of complex square root 2023-09-21 14:24:52 +02:00
4947a80cb4 chore: make pnpm go work cross platform 2023-09-21 14:11:10 +02:00
0e2a1e830a WIP: try to use ts-macros for more implementations 2023-09-18 10:14:11 -07:00
dc6cf5165d issue: ts-macros appears to be generating temp variable clashes 2023-08-26 12:19:32 -07:00
ae2303af7c chore: Update to ts-macros@2.4.0 2023-08-26 10:14:02 -07:00
9eff2bc265 feat: Demonstrate macros to encapsulate the type-reflection process 2023-08-25 19:19:01 -07:00
af02f1cb29 feat: Simplify the reflected type of an implementation 2023-08-25 19:19:01 -07:00
da5b2c3467 feat: Demonstrate a trick for further resolving the dep type at compiletime 2023-08-25 19:19:01 -07:00
770c302342 feat: Precisely reflect the type of an implementation at runtime (!!) 2023-08-25 19:18:54 -07:00

View File

@ -1,4 +1,4 @@
export type FunctionDef = { export type FunctionDef {
name: string, name: string,
aliasOf?: string, aliasOf?: string,
signatures: Array<{ signatures: Array<{
@ -11,7 +11,6 @@ export type FunctionDef = {
export type ImplementationDef = { export type ImplementationDef = {
fn: FunctionDef, fn: FunctionDef,
dependencies: Record<string, FunctionDef> dependencies: Record<string, FunctionDef>
genericParameter: string | null
} }
/** /**
@ -24,11 +23,6 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme
const [factoryArgs, fnsClause] = split(reflectedType, '=>', 2).map(trim) const [factoryArgs, fnsClause] = split(reflectedType, '=>', 2).map(trim)
const fn = parseAlias(name, fnsClause) const fn = parseAlias(name, fnsClause)
// extract the generic parameter like '<T>' at the start of the type
const genericParameter = factoryArgs.trim().startsWith('<')
? findBlockContents(factoryArgs, '<', '>')?.innerText || null
: null
const factoryArgsInner = findBlockContents(factoryArgs, '(', ')') const factoryArgsInner = findBlockContents(factoryArgs, '(', ')')
const depArg = split(factoryArgsInner.innerText, ':').map(trim)[1] const depArg = split(factoryArgsInner.innerText, ':').map(trim)[1]
const depArgBlocks: string[] = depArg ? split(depArg, '&').map(trim) : [] const depArgBlocks: string[] = depArg ? split(depArg, '&').map(trim) : []
@ -45,7 +39,7 @@ export function parseReflectedType(name: string, reflectedType: string): Impleme
const dependencies: Record<string, FunctionDef> = groupBy(deps, 'name') const dependencies: Record<string, FunctionDef> = groupBy(deps, 'name')
return {fn, dependencies, genericParameter } return {fn, dependencies}
} }
function parseDependencies(deps: string): FunctionDef[] { function parseDependencies(deps: string): FunctionDef[] {