Generate slightly smaller code for switch and let
This commit is contained in:
parent
cd87c0fc08
commit
2238d363e5
4
ir.py
4
ir.py
|
@ -162,7 +162,7 @@ class LetBinding:
|
||||||
|
|
||||||
def codegen(self) -> str:
|
def codegen(self) -> str:
|
||||||
rhs_cg = self.rhs.codegen_named(self.lhs) if isinstance(self.rhs, Function) else self.rhs.codegen()
|
rhs_cg = self.rhs.codegen_named(self.lhs) if isinstance(self.rhs, Function) else self.rhs.codegen()
|
||||||
return f'(({self.lhs}) => {self.body.codegen()})({rhs_cg})'
|
return f'({self.lhs}={rhs_cg},{self.body.codegen()})'
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Application:
|
class Application:
|
||||||
|
@ -288,7 +288,7 @@ class Switch:
|
||||||
def codegen(self) -> str:
|
def codegen(self) -> str:
|
||||||
switching_on_code = self.switching_on.codegen()
|
switching_on_code = self.switching_on.codegen()
|
||||||
return ':'.join(
|
return ':'.join(
|
||||||
f'{switching_on_code}==={val}?({branch.codegen()})'
|
f'{switching_on_code}=={val}?({branch.codegen()})'
|
||||||
for val, branch in self.branches.items()
|
for val, branch in self.branches.items()
|
||||||
) + f':{self.fallback.codegen()}'
|
) + f':{self.fallback.codegen()}'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue