~jasper/type_stack_calc

6be01cc49180e59fa8d38a3207f2618f9d43033e — Jasper den Ouden 2 years ago 03a9943
Filtering out `None` is not needed, theyre not in there
M type_stack_calc/Main.py => type_stack_calc/Main.py +3 -5
@@ 16,8 16,7 @@ from type_stack_calc.ib.scope import scopify
import type_stack_calc.intro.load as loader  # TODO stupid-side-effects-based.

import sys
from subprocess import Popen, PIPE
import subprocess
from subprocess import Popen, PIPE, call

class Finished(BaseException): pass



@@ 28,7 27,7 @@ class HighlightCmd(tuple):
        return [s.format_map(params) for s in self[1]]

    def available(self):
        return subprocess.Popen(['which', self[1][0]]).wait() == 0
        return Popen(['which', self[1][0]]).wait() == 0

class Main(StackCalc):
    """Class for main type stack calculation program."""


@@ 125,14 124,13 @@ class Main(StackCalc):
                s = fd.read()
                if self.stage('cat', a):  # Wants to see the original code.
                    if 'highlight_tsc' in self.want:
                        subprocess.call(self.highlight_with.params(lang=a))
                        call(self.highlight_with.params(lang=a))
                    else:
                        print(s)
                code = list(parser(s))
                self.stage('parsed', a, " ".join(code))

                *tc_code, stack = self.tp_calc(code, vs, [])
                tc_code = [c1 for c1 in tc_code if c1 is not None]
                for n, el in enumerate(tc_code):  # Note their existence.
                    if fun := getattr(el, 'notify_real', None): fun()


M type_stack_calc/extractor.py => type_stack_calc/extractor.py +2 -3
@@ 13,7 13,7 @@ def getattr_or_parent(obj, key):
    return getattr(getattr(obj, 'parent', None), key, None) \
        or getattr(obj, key, None)

from type_stack_calc.util.various import list_flatten, filter_none, ignore
from type_stack_calc.util.various import list_flatten, ignore

class Extractor(tuple):
    """Extracts things in arguments of functions to the body the function is called from.


@@ 97,8 97,7 @@ def extract(gen):
        ext._extract_1(gen, obj, 'extract_top')

        # Externalized first, then argument partion.
        ret = (list(filter_none(list_flatten(extlist))) +
               list(filter_none(list_flatten(ilist))))
        ret = [*list_flatten(extlist), *list_flatten(ilist)]
        # Drop:
        # * If any definitional parts => assumed comes back as variants.
        # * If entirely `is_const`, which does not do anything.

M type_stack_calc/ib/if_block.py => type_stack_calc/ib/if_block.py +2 -3
@@ 9,7 9,7 @@ from type_stack_calc.extractor import Extractor, extract, StopMarker

from type_stack_calc.pe.drop import PostExtractDrop

from type_stack_calc.util.various import list_flatten, filter_none
from type_stack_calc.util.various import list_flatten

class IfOneBranch:
    """If block, but after concluding only one."""


@@ 28,8 28,7 @@ class IfOneBranch:
class IfBlock:
    """`if_block.py`: `{..if..} {..else..} (..cond..).if` provider."""
    def __init__(self, cond, yes, no, ret_stack):
        self.cond, self.yes, self.no = \
            map(list, map(filter_none, [cond, yes, no]))
        self.cond, self.yes, self.no = cond, yes, no
        self.stack = ret_stack

    def extract_cond(self, extractor, gen):

M type_stack_calc/ib/tc_variant.py => type_stack_calc/ib/tc_variant.py +1 -4
@@ 31,9 31,7 @@ from type_stack_calc.base.component import ReturnStop
from type_stack_calc.extractor import Extractor
from type_stack_calc.to_c import ToC


# TODO it gets angry ifi remove BaseFunctionVariant? What am i still using?
from type_stack_calc.util.various import filter_none

class TCVariant(Ided, BaseFunctionVariant):
    """Instance of a code that can be type-calculated into different variants based on argument input types."""


@@ 113,7 111,6 @@ class TCVariant(Ided, BaseFunctionVariant):
            # Type-calculate the code under these conditions & strip nonse.
            # NOTE: `stack` is only used to see if `~r .set` must be run to get it.
            *tc_code, stack = stack_calc.tp_calc(code, vs, [])
            tc_code = list(filter_none(tc_code))

            # Already said return.
            if len(stack) > 0 and stack[-1] == ReturnStop: 


@@ 121,7 118,7 @@ class TCVariant(Ided, BaseFunctionVariant):
            # If stack left at the end, assume it is returned values.
            elif len(stack) > 0:
                *extra, _tp = stack_calc.tp_calc(['~r', '.set'], vs, stack)
                tc_code = tc_code + list(filter_none(extra))
                tc_code = tc_code + list(extra)

            assert isinstance(vs['~r'].val, ReturnCatchType), vs['~r']
            tp = vs['~r'].val.ret_stack()   # Fill return type.