~jasper/type_stack_calc

ref: 6aca66fb1a7cf1e10f7dd3263f04537c8ff37590 type_stack_calc/type_stack_calc/base/n_args.py -rw-r--r-- 959 bytes
6aca66fb — Jasper den Ouden Apparently `to_c` can already read ahead one, hopefully its this simple... 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class BaseNArgs:
    """Basic no-argument extraction."""

    def extract(self, extractor, gen, _tp):
        ret = getattr(self, 'ret_stack', None)
        if ret is None or self.destructive or len(ret) > 1 \
            or not (len(ret) == 0 or ret[0].is_const):
            # Need the function.
            extractor[0](self)
        else:  # The result is adequate.
            if len(ret) == 1:
                extractor[0](ret[0])  # The result is adequate.
            # Ignore whatever else should be here.
            extractor = extractor.sub_ignore_here()

        # Now the rest of the extraction.
        n = getattr(self, 'extract_n', self.n)
        for i in range(n):
            try:
                extractor.extract_1(gen)
            except StopIteration:
                assert False, f"Nargs: Extraction exceeded generator at {i+1}/{n} {self}\n{type(self)}"
                
    extract_top = extract

class Base0Args(BaseNArgs): n = 0