feat: add type reflection via ts-macros

This commit is contained in:
Glen Whitney 2024-09-29 22:10:09 -07:00
parent f575582879
commit a0324e5f2b
11 changed files with 215 additions and 14 deletions

View file

@ -1,2 +1,2 @@
export * as type_data from './type'
export * as arithmetic_functions from './arithmetic'
export * as type from './type'
export * as arithmetic from './arithmetic'

View file

@ -1,9 +1,10 @@
import {implementations} from '@/core/Dispatcher'
import {$reflect} from '@/interfaces/type'
import type {CommonSignature} from '@/interfaces/type'
const conservativeSqrt = (a: number) => isNaN(a) ? NaN : Math.sqrt(a)
export default implementations<CommonSignature<number>>()
export const common = implementations<CommonSignature<number>>()
.independent({
add: (a, b) => a + b,
unaryMinus: a => -a,
@ -24,3 +25,5 @@ export default implementations<CommonSignature<number>>()
}
}})
.ship()
$reflect!([common])

View file

@ -1,5 +1,6 @@
import type {Complex} from '@/Complex/type'
import {implementations} from '@/core/Dispatcher'
import {$reflect} from '@/interfaces/type'
import type {CommonSignature} from '@/interfaces/type'
export const number_type = {
@ -22,10 +23,12 @@ declare module "@/interfaces/type" {
}
}
export default implementations<CommonSignature<number>>()
export const common = implementations<CommonSignature<number>>()
.independent({
zero: a => 0,
one: a => 1,
nan: a => NaN,
re: a => a
}).ship()
$reflect!([common])