M type_stack_calc/call/if_call.py => type_stack_calc/call/if_call.py +3 -3
@@ 49,9 49,10 @@ class IfCall:
f"Only one boolean-like value, got: {cond_got}"
cond_val = cond_got[0]
if isinstance(cond_val, BaseComponent): # (not using variables)
- cond_val = cond_val.val # TODO can it even happen?
+ cond_val = cond_val.val
- if isinstance(cond_val, TpIntersection):
+ # TODO `None` and `False` are false, rest is true. (even 0)
+ if isinstance(cond_val, TpIntersection): # Must be boolean.
assert len(cond_val) == 1
cond_val = cond_val[0]
assert isinstance(cond_val, TpBool), cond_val
@@ 69,4 70,3 @@ class IfCall:
ret_stack = ret_stack_smoosh(if_t, if_f)
return ret_stack, IfBlock(tc_cond, tc_t, tc_f, ret_stack)
-
M type_stack_calc/intro/tp.py => type_stack_calc/intro/tp.py +2 -2
@@ 5,13 5,13 @@ from type_stack_calc.tp.range import TpRange
from type_stack_calc.tp.stepping import TpStepping
from type_stack_calc.tp.float import TpFloat
from type_stack_calc.tp.intersection import TpIntersection, TypeTpIntersection
+
tti = TypeTpIntersection
+
class IntersectionsIntro(WithParams):
"""Exposes a bunch of functions to make intersection types."""
is_const = True
- # TODO lowercase them, it's not really the type with one that makes it..
-
def param_Float(n, self):
if isinstance(n, TpIntersection):
assert len(n) == 1
M type_stack_calc/tp_calc.py => type_stack_calc/tp_calc.py +12 -13
@@ 5,15 5,6 @@
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
-from type_stack_calc.base.component import BaseComponent, ReturnStop
-from type_stack_calc.ib.scope import ScopeVariable
-
-from type_stack_calc.tp.range import TpRange
-from type_stack_calc.tp.intersection import TpIntersection
-from type_stack_calc.tp.str import ConstStr
-
-from type_stack_calc.util.stack_check import assert_acceptable_vals
-
import re
def interpret_num_word(word):
@@ 25,8 16,13 @@ def interpret_num_word(word):
return float(word)
assert word not in "0123456789"
+from type_stack_calc.tp.range import TpRange
+from type_stack_calc.tp.intersection import TpIntersection
+
def const_num(x): return TpIntersection(TpRange(x, x),)
+from type_stack_calc.tp.str import ConstStr
+
def interpret_word(word):
"""Interprets constant values."""
x = interpret_num_word(word)
@@ 35,9 31,12 @@ def interpret_word(word):
elif word[0] == '"': # Constant string.
return ConstStr(word[1:])
-def concat_gen(*gen):
- for el in gen:
- yield from el
+from type_stack_calc.base.component import BaseComponent, ReturnStop
+
+from type_stack_calc.ib.scope import ScopeVariable
+
+from type_stack_calc.util.stack_check import assert_acceptable_vals
+from type_stack_calc.util.various import concat_gen
class StackCalc:
"""Calculates types, heart of the implementation, basically."""
@@ 98,7 97,7 @@ class StackCalc:
fun(relevant_comp, inp)
el.relevant_comp = relevant_comp
- return (rest + stack, *tc_code)
+ return rest + stack, *tc_code
return stack[:-1] + [var], var # No calculation needed.
M type_stack_calc/util/various.py => type_stack_calc/util/various.py +4 -4
@@ 12,10 12,6 @@ def first_or_none(gen, alt=None):
assert next(gen, None) is None
return ret
-def filter_none(lst):
- """Filter all the `None` values."""
- return (el for el in lst if el is not None)
-
def list_flatten(gen):
"""If an item in `gen` is a list yield it flatly, and continue so recursively."""
for el in gen:
@@ 23,3 19,7 @@ def list_flatten(gen):
yield from list_flatten(el)
else:
yield el
+
+def concat_gen(*gen):
+ for el in gen:
+ yield from el