weirdnet-code-spaces 0.1.0

Weirdnet code spaces: math, Polars, Rust and typed Python sources compiled into plugins against the weirdnet-plugin SDK, content-addressed builds, ABI-checked loading, trust hashes and space line-ups, under an application profile.
Documentation
use proc_macro2::TokenStream;
use serde::{Deserialize, Serialize};

use crate::python_ast::{CodeGen, CodeGenContext, ExprType, Node, PythonOptions, SymbolTableScopes};

/// Starred expression for unpacking (*args)
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)]
pub struct Starred {
    /// The expression being unpacked
    pub value: Box<ExprType>,
    /// Context (Load, Store, etc.) - not used in Rust generation
    pub ctx: Option<String>,
    /// Position information
    pub lineno: Option<usize>,
    pub col_offset: Option<usize>,
    pub end_lineno: Option<usize>,
    pub end_col_offset: Option<usize>,
}

impl Node for Starred {
    fn lineno(&self) -> Option<usize> {
        self.lineno
    }
    fn col_offset(&self) -> Option<usize> {
        self.col_offset
    }
    fn end_lineno(&self) -> Option<usize> {
        self.end_lineno
    }
    fn end_col_offset(&self) -> Option<usize> {
        self.end_col_offset
    }
}

impl CodeGen for Starred {
    type Context = CodeGenContext;
    type Options = PythonOptions;
    type SymbolTable = SymbolTableScopes;

    fn find_symbols(self, symbols: Self::SymbolTable) -> Self::SymbolTable {
        (*self.value).clone().find_symbols(symbols)
    }

    fn to_rust(self, _ctx: Self::Context, _options: Self::Options, _symbols: Self::SymbolTable) -> Result<TokenStream, Box<dyn std::error::Error>> {
        // Emitting the bare value would pass the whole collection as ONE
        // argument/element — silently different from unpacking it.
        Err("starred unpacking (`*expr`) is not supported yet: it would \
             silently pass the collection as a single value instead of \
             spreading its elements. Spell the elements out explicitly."
            .to_string()
            .into())
    }
}

#[cfg(python_ast_upstream_tests)]
mod tests {
    // Note: These tests will likely fail until full starred expression support is added
    // create_parse_test!(test_starred_args, "*args", "test.py");
    // create_parse_test!(test_starred_in_call, "func(*args)", "test.py");
}