diff --git a/src/bind.inc.php b/src/bind.inc.php index 6e045fc..16bad56 100644 --- a/src/bind.inc.php +++ b/src/bind.inc.php @@ -220,6 +220,44 @@ function add_twig_support(\Twig\Environment $twig) return $arr; } )); + $twig->addFunction(new \Twig\TwigFunction('slice_units', + function(array $units, $max) + { + $pages = paginate(sizeof($units), $max); + + $sliced = array(); + + $units_keys = array_keys($units); + + foreach($pages as $idx => $page) + { + $slice = array(); + for($i = $page[0];$i<$page[1];++$i) + { + $slice[] = $units[$units_keys[$i]]; + } + $sliced[$idx] = $slice; + } + return $sliced; + } + )); +} + +function paginate($total, $step) +{ + //pages are returned as an array where each element is in interval [N, Y) + $pages = array(); + + $steps = (int)($total/$step); + $rest = $total % $step; + + for($i=1;$i<=$steps;++$i) + $pages[] = array(($i-1)*$step, $i*$step); + + if($rest != 0) + $pages[] = array(($i-1)*$step, ($i-1)*$step + $rest); + + return $pages; } function ns_last($name) diff --git a/tpl/codegen_autobind.twig b/tpl/codegen_autobind.twig index faf61cf..8a5a36b 100644 --- a/tpl/codegen_autobind.twig +++ b/tpl/codegen_autobind.twig @@ -27,10 +27,12 @@ public static void Register(Types types) BHL_Types.Type_GenericArray = new GenericArrayTypeSymbol(new Proxy()); {% block register %} - {{ macro.reg_units(meta.units) }} + {{ macro.call_reg_units(slice_units(meta.units, 20)) }} {% endblock %} } +{{ macro.decl_reg_units(slice_units(meta.units, 20)) }} + } } //namespace bhl diff --git a/tpl/macro.twig b/tpl/macro.twig index 295694f..b92e5fc 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -977,6 +977,21 @@ public partial class Script_{{u.object.name}} { {%- endmacro -%} +{%- macro call_reg_units(sliced_units) ~%} + {%- for idx,units in sliced_units -%} + Register_{{idx}}(types); + {%~ endfor -%} +{%- endmacro -%} + +{%- macro decl_reg_units(sliced_units) ~%} + {%- for idx,units in sliced_units -%} + public static void Register_{{idx}}(Types types) + { + {{ _self.reg_units(units) }} + } + {%~ endfor -%} +{%- endmacro -%} + {%- macro reg_units(units) ~%} {%- for u in units -%}