Reworks function lookup
# Conflicts: # phasm/prelude/__init__.py
This commit is contained in:
parent
c8bf5e7c59
commit
d908f3d432
@ -552,29 +552,9 @@ def expression(wgn: WasmGenerator, inp: ourlang.Expression) -> None:
|
||||
assert arg_expr.type3 is not None, TYPE3_ASSERTION_ERROR
|
||||
type_var_map[type_var] = arg_expr.type3
|
||||
|
||||
method_instance_key = (
|
||||
inp.function,
|
||||
tuple(
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
instance = PRELUDE_TYPE_CLASS_INSTANCE_METHODS.get(method_instance_key)
|
||||
if isinstance is not None:
|
||||
instance(wgn)
|
||||
return
|
||||
|
||||
instance_key = ','.join(
|
||||
f'{k.letter}={v.name}'
|
||||
for k, v in sorted(type_var_map.items(), key=lambda x: x[0].letter)
|
||||
)
|
||||
|
||||
instance = INSTANCES.get(inp.function, {}).get(instance_key, None)
|
||||
if instance is not None:
|
||||
instance(wgn)
|
||||
return
|
||||
|
||||
raise NotImplementedError(inp.function, instance_key)
|
||||
router = prelude.PRELUDE_TYPE_CLASS_INSTANCE_METHODS[inp.function]
|
||||
router(wgn, type_var_map)
|
||||
return
|
||||
|
||||
wgn.add_statement('call', '${}'.format(inp.function.name))
|
||||
return
|
||||
|
||||
@ -12,6 +12,7 @@ from ..type3.types import (
|
||||
IntType3,
|
||||
Type3,
|
||||
TypeApplication_Nullary,
|
||||
TypeApplicationRouter,
|
||||
TypeConstructor_StaticArray,
|
||||
TypeConstructor_Struct,
|
||||
TypeConstructor_Tuple,
|
||||
@ -19,9 +20,9 @@ from ..type3.types import (
|
||||
|
||||
PRELUDE_TYPE_CLASS_INSTANCES_EXISTING: set[tuple[Type3Class, tuple[Type3, ...]]] = set()
|
||||
|
||||
PRELUDE_TYPE_CLASS_INSTANCE_METHODS: dict[tuple[Type3ClassMethod, tuple[Type3, ...]], Callable[[Generator, Type3], None]] = {}
|
||||
PRELUDE_TYPE_CLASS_INSTANCE_METHODS: dict[Type3ClassMethod, TypeApplicationRouter[Generator, None]] = {}
|
||||
|
||||
def instance_type_class(cls: Type3Class, *typ: Type3, methods: dict[str, Callable[[Generator, Type3], None]] = {}) -> None:
|
||||
def instance_type_class(cls: Type3Class, *typ: Type3, methods: dict[str, Callable[[Generator], None]] = {}) -> None:
|
||||
global PRELUDE_TYPE_CLASS_INSTANCES_EXISTING
|
||||
global PRELUDE_TYPE_CLASS_INSTANCE_METHODS
|
||||
|
||||
@ -29,9 +30,15 @@ def instance_type_class(cls: Type3Class, *typ: Type3, methods: dict[str, Callabl
|
||||
|
||||
PRELUDE_TYPE_CLASS_INSTANCES_EXISTING.add((cls, tuple(typ), ))
|
||||
|
||||
for method, generator in methods.items():
|
||||
PRELUDE_TYPE_CLASS_INSTANCE_METHODS[(cls.methods[method], tuple(typ))] = generator
|
||||
for method_name, generator in methods.items():
|
||||
method = cls.methods[method_name]
|
||||
|
||||
router = PRELUDE_TYPE_CLASS_INSTANCE_METHODS.get(method)
|
||||
if router is None:
|
||||
router = TypeApplicationRouter[Generator, None]()
|
||||
PRELUDE_TYPE_CLASS_INSTANCE_METHODS[method] = router
|
||||
|
||||
router.add_n(typ, generator)
|
||||
|
||||
none = Type3('none', TypeApplication_Nullary(None, None))
|
||||
"""
|
||||
|
||||
@ -833,7 +833,7 @@ def f64_natnum_arithmic_shift_right(g: Generator) -> None:
|
||||
## ###
|
||||
## class IntNum
|
||||
|
||||
def i32_intnum_abs(g: Generator, t: Type3 | None = None) -> None:
|
||||
def i32_intnum_abs(g: Generator) -> None:
|
||||
g.add_statement('call $stdlib.types.__i32_intnum_abs__')
|
||||
|
||||
def i64_intnum_abs(g: Generator) -> None:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user