~jasper/type_stack_calc

c33354344e00df5df2858b4c6bc2a5ac92ffbbbe — Jasper den Ouden 4 months ago 9723b0a
Use WithParams instead of BaseType in exposing. WithParams also provides `callable_cls`. Also i forgot to commit bin/tsc.py. History is boring, too lazy to ammend.
M bin/tsc.py => bin/tsc.py +3 -3
@@ 11,7 11,7 @@ from type_stack_calc.extractor import extract
from type_stack_calc.to_c import ToC
from type_stack_calc.sc_parser import parser

from type_stack_calc.util.scopify import scopify
from type_stack_calc.ib.scope import scopify

import sys
import subprocess


@@ 89,8 89,8 @@ class Main(StackCalc):
                ofd.write(f"\n// start: {prev} {k} {v.val}")
                self._c_variants(ofd, sub_vars(), depth + 1, prev + [k])
                ofd.write(f"\n// end: {prev} {k}")
            else:
                ofd.write(f"\n// ignored: {k}: {v.val}")
#            else:
#                ofd.write(f"\n// ignored: {k}: {v.val}")

    def deal_argv_1(self, argv, i):
        a = argv[i]

M type_stack_calc/base/with_params.py => type_stack_calc/base/with_params.py +2 -1
@@ 8,11 8,12 @@
from inspect import signature

from type_stack_calc.ib.plain_component import PlainComponent
from type_stack_calc.ib.simple_ib_fun import SimpleInbuildFunction

class WithParams:
    """Helper providing `.get_param` method from `param_...` methods, and possibly `.get_param_final`."""

    callable_cls = None
    callable_cls = SimpleInbuildFunction

    def get_param(self, key):
        # NOTE: it gets the value of the `type` of itself! Otherwise it'll fill in the first value!

M type_stack_calc/intro/intersection.py => type_stack_calc/intro/intersection.py +3 -4
@@ 1,15 1,14 @@

from type_stack_calc.tp.base.base import BaseType
from type_stack_calc.tp.num import Range, Stepping, Float
from type_stack_calc.tp.intersection import TpIntersection, TypeTpIntersection

from type_stack_calc.ib.simple_ib_fun import SimpleInbuildFunction
from type_stack_calc.base.with_params import WithParams

tti = TypeTpIntersection

class IntersectionsIntro(BaseType):
class IntersectionsIntro(WithParams):
    """Exposes a bunch of functions to make intersection types."""
    is_const = True
    callable_cls = SimpleInbuildFunction

    def param_Float(n, self):
        if isinstance(n, TpIntersection):

M type_stack_calc/tp/intersection.py => type_stack_calc/tp/intersection.py +0 -3
@@ 6,7 6,6 @@
#  (at your option) any later version.

from type_stack_calc.tp.base.base import BaseType
from type_stack_calc.ib.simple_ib_fun import SimpleInbuildFunction

from type_stack_calc.tp.num import Range, Float
from type_stack_calc.sets.intersection import SetIntersection


@@ 50,8 49,6 @@ class TpIntersection(BaseType, SetIntersection):
                return False
        return True

    callable_cls = SimpleInbuildFunction

    def first_cls(self, Cls):
        return next(x for x in self if isinstance(x, Cls))