MCPcopy Create free account
hub / github.com/dylan-sutton-chavez/edge-python / partition_bindings

Function partition_bindings

compiler/src/modules/packages/mod.rs:50–75  ·  view source on GitHub ↗

Splits native bindings by export-name convention: `__class_` methods, `__const_` values, rest free functions. */

(all: Vec<NativeBinding>)

Source from the content-addressed store, hash-verified

48
49/* Splits native bindings by export-name convention: `__class_` methods, `__const_` values, rest free functions. */
50pub fn partition_bindings(all: Vec<NativeBinding>) -> (Vec<NativeBinding>, Vec<NativeClass>, Vec<NativeBinding>) {
51 let mut bindings = Vec::new();
52 let mut class_map: Vec<(String, Vec<NativeBinding>)> = Vec::new();
53 let mut consts = Vec::new();
54 for b in all {
55 if let Some(name) = b.name.strip_prefix("__fn_") {
56 let name = name.to_string();
57 bindings.push(NativeBinding { name, ..b });
58 } else if let Some(name) = b.name.strip_prefix("__const_") {
59 let name = name.to_string();
60 consts.push(NativeBinding { name, ..b });
61 } else if let Some((class_name, method)) = parse_class_export(&b.name) {
62 let (class_name, method) = (class_name.to_string(), method.to_string());
63 let m = NativeBinding { name: method, ..b };
64 if let Some(e) = class_map.iter_mut().find(|(n, _)| *n == class_name) {
65 e.1.push(m);
66 } else {
67 class_map.push((class_name, alloc::vec![m]));
68 }
69 } else {
70 bindings.push(b);
71 }
72 }
73 let classes = class_map.into_iter().map(|(name, methods)| NativeClass { name, methods }).collect();
74 (bindings, classes, consts)
75}
76
77/* Returns (class_name, method_name) when export matches `__class_<Name>_<method>`, else None. */
78fn parse_class_export(export: &str) -> Option<(&str, &str)> {

Callers 2

resolve_canonicalMethod · 0.85
with_nativeMethod · 0.85

Calls 3

parse_class_exportFunction · 0.85
pushMethod · 0.80
collectMethod · 0.80

Tested by 1

with_nativeMethod · 0.68