Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""NodeForge Blender addon package."""

NODEFORGE_VERSION = (0, 98, 0)
NODEFORGE_VERSION = (0, 99, 0)

bl_info = {
"name": "NodeForge",
Expand Down
2 changes: 1 addition & 1 deletion blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema_version = "1.0.0"
id = "nodeforge"

version = "0.98.0"
version = "0.99.0"

name = "NodeForge"
tagline = "Compile a procedural DSL into Blender Geometry Nodes"
Expand Down
8 changes: 7 additions & 1 deletion dev/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -838,4 +838,10 @@ lifecycle.
- Enabled known inline String constants to populate literal-only Menu inputs through aliases, nested calls and multiple consumers, while rejecting runtime String connections and invalid Menu values.
- Retained one shared physical producer for multi-consumer non-String inline operands (including Bool Compare, points() count and cube() scale) and shared String producers for runtime-capable consumers.
- Consolidated duplicated scale/Euler conversion logic in geometry builtins and removed the unused legacy inline constant materializer.
- Added Blender 5.2 characterization, regression and package integration tests covering constant topology, native evaluation, type validation, inline sharing and graph updates.
- Added Blender 5.2 characterization, regression and package integration tests covering constant topology, native evaluation, type validation, inline sharing and graph updates.

## 0.99.0

- Added optional direct typed Extension API v2 parameters declared with `= None`, including compile-time, runtime, and mixed evaluation modes.
- Preserve omitted parameters as indexed static `None` operands through overload selection, semantic processing, dynamic result resolution, and inline/grouped Blender materialization.
- Added declaration, semantic, dynamic-result, Blender socket-default, and downstream `nodeforge.nodes` regression coverage.
50 changes: 46 additions & 4 deletions docs/EXTENSION_API.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ The marker classes are annotation tokens rather than runtime values to instantia

### Evaluation modes

| Mode | Accepted representation |
| Mode | Supplied argument representation |
| --- | --- |
| `EvaluationMode.COMPILE_TIME_ONLY` | Detached compile-time data only. |
| `EvaluationMode.RUNTIME_ONLY` | Runtime NodeForge value only; the backend receives an `ExtensionBackendValue`. |
| `EvaluationMode.COMPILE_TIME_OR_RUNTIME` | Detached data when known at compile time, otherwise the runtime representation. |

`RUNTIME_ONLY` parameters cannot have defaults. Compile-time and mixed parameters may default to detached `Bool`, signed-32 `Int`, `Float`, `String`, 3-component `Vector` or `Rotation`, or 4-component `Color` values. Vector, Rotation and Color defaults may be written as Python lists or tuples and are canonicalized by NodeForge. Color is linear RGBA `(R, G, B, A)` with finite nonnegative binary32 components, including alpha and valid HDR values. A Color-marked parameter receives an immutable RGBA tuple in its compile-time branch, or an `ExtensionBackendValue` in its runtime branch. Ordinary extension `list` and `tuple` semantic fields remain structural Python values.
`RUNTIME_ONLY` parameters accept only `None` as a default; see [Optional typed parameters](#optional-typed-parameters). Compile-time and mixed parameters may default to detached `Bool`, signed-32 `Int`, `Float`, `String`, 3-component `Vector` or `Rotation`, or 4-component `Color` values. Vector, Rotation and Color defaults may be written as Python lists or tuples and are canonicalized by NodeForge. Color is linear RGBA `(R, G, B, A)` with finite nonnegative binary32 components, including alpha and valid HDR values. A Color-marked parameter receives an immutable RGBA tuple in its compile-time branch, or an `ExtensionBackendValue` in its runtime branch. Ordinary extension `list` and `tuple` semantic fields remain structural Python values.

A declared `Rotation` default is an XYZ Euler-angle triple in radians, normalized to an immutable three-float binary32 tuple. Python integer components may exceed signed Int32 when their numeric values are representable as finite binary32 floats. A uniquely declared `Rotation` parameter interprets an untyped numeric triple as Rotation; `Vector` declarations interpret it as Vector. A parameter typed `Rotation | Vector` cannot use an untyped numeric triple as a default or static argument because both alternatives match. A typed runtime reference uses its exact declared type. Backend overloads with equally matching Rotation and Vector candidates also reject an untyped triple as ambiguous. See [Writing Functions](WRITING_FUNCTIONS.md#parameters-and-sockets) for the `.nf` source-default limits and explicit runtime Euler conversion.

Expand All @@ -159,6 +159,47 @@ def tint(value: Annotated[Color, EvaluationMode.COMPILE_TIME_OR_RUNTIME] = (0.2,

Use compile-time data for configuration that changes graph shape or node properties. Use runtime values for data that should remain connected as Geometry Nodes sockets or fields.

### Optional typed parameters

Use `= None` in `interface.py` to allow omission of a direct typed argument. All three evaluation modes support it.

| Declaration | Omitted argument |
| --- | --- |
| No default | Required; omission is an error. |
| Concrete default | Receives the declared value. |
| `= None` | Receives Python `None` in the backend and semantic function. |

For example, a Resample Curve wrapper can leave Count at Blender's default:

```python
# interface.py
from typing import Annotated
from NodeForge import EvaluationMode, Geometry, Int


def resample_curve(
curve: Annotated[Geometry, EvaluationMode.RUNTIME_ONLY],
*,
count: Annotated[Int, EvaluationMode.COMPILE_TIME_OR_RUNTIME] = None,
) -> Geometry:
...
```

In the backend, skip socket assignment and linking when the argument is `None`:

```python
# backend.py: after creating node and connecting Curve
from NodeForge.extension_api import ExtensionBackendValue

if count is not None:
if isinstance(count, ExtensionBackendValue):
context.group.links.new(count.socket, node.inputs['Count'])
else:
node.inputs['Count'].default_value = count
```

Omit the keyword in `.nf` calls to use this behavior. Explicit `.nf` arguments such as `count=None` and direct parameter annotations such as `Int | None` are unsupported. Supplied values retain their declared type and evaluation-mode checks.

### Direct results

A backend-only callable may return one exact direct type:
Expand Down Expand Up @@ -240,6 +281,7 @@ The resolver's `arguments` is a read-only mapping from parameter names to the fo
| --- | --- |
| Direct runtime value | `ResultRuntimeArg`: `.typ` is the actual `NFType`. |
| Direct compile-time value | `ResultStaticArg`: `.typ` and the canonical immutable `.value`. |
| Omitted parameter declared with `= None` | Python `None`. |
| Variadic parameter | A tuple of argument views, empty when no arguments were supplied. |
| Semantic record or list | A reconstructed semantic value with `RuntimeRef` runtime leaves. |

Expand All @@ -255,7 +297,7 @@ The backend must return a Python tuple of `ExtensionBackendValue` objects, inclu

### Overloads

Use `typing.overload` for a finite set of direct-value signatures. Alternatives are tried in source order.
Use `typing.overload` for a finite set of direct-value signatures. Exact type matches take precedence over compatible matches. Omitted `= None` parameters provide no type evidence; equally matching alternatives are ambiguous.

```python
from typing import Annotated, overload
Expand Down Expand Up @@ -456,7 +498,7 @@ Import the public backend types from:
from NodeForge.extension_api import ExtensionBackendContext, ExtensionBackendValue, NFType
```

Runtime direct arguments are `ExtensionBackendValue` instances. Compile-time arguments are detached Python data selected by the parameter's evaluation mode. The compiler consumes `__inline__`; semantic functions and backends receive only their declared arguments.
Supplied runtime direct arguments are `ExtensionBackendValue` instances. Compile-time arguments are detached Python data selected by the parameter's evaluation mode. The compiler consumes `__inline__`; semantic functions and backends receive only their declared arguments.

### `ExtensionBackendValue`

Expand Down
16 changes: 13 additions & 3 deletions extensions/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,24 @@ def __post_init__(self) -> None:
raise ValueError("semantic RECORD/LIST extension parameter cannot carry EvaluationMode")
else:
raise TypeError("public extension parameters support only NF_SET or semantic RECORD/LIST")
if self.default is inspect.Parameter.empty:
if self.kind is inspect.Parameter.VAR_KEYWORD:
raise ValueError("extension parameters cannot use **kwargs")
if self.kind is inspect.Parameter.VAR_POSITIONAL and self.default is not inspect.Parameter.empty:
raise ValueError("variadic extension parameter cannot declare a default")
if self.default is inspect.Parameter.empty or self.default is None:
if self.default_type is not None:
raise ValueError("extension parameter without default cannot carry default_type")
raise ValueError("extension parameter without concrete default cannot carry default_type")
if self.default is None and self.type_spec.kind != "NF_SET":
raise ValueError("semantic RECORD/LIST extension parameters cannot declare defaults")
else:
if self.type_spec.kind != "NF_SET":
raise ValueError("semantic RECORD/LIST extension parameters cannot declare defaults")
if self.evaluation_mode is EvaluationMode.RUNTIME_ONLY:
raise ValueError("RUNTIME_ONLY extension parameter cannot declare a concrete default")
if not isinstance(self.default_type, NFType):
raise TypeError("extension parameter default requires canonical NFType")
raise TypeError("extension parameter concrete default requires canonical NFType")
if self.default_type not in self.type_spec.nf_types:
raise ValueError("extension parameter default NFType is not declared")


@dataclass(frozen=True)
Expand Down
7 changes: 4 additions & 3 deletions extensions/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,10 @@ def _normalize_declaration(
raise CompileError(f"{callable_id.name}() variadic parameter cannot declare a default")
if type_spec.kind != "NF_SET":
raise CompileError(f"{callable_id.name}() semantic parameter {parameter.name!r} cannot declare a default")
if mode is EvaluationMode.RUNTIME_ONLY:
raise CompileError(f"{callable_id.name}() RUNTIME_ONLY parameter {parameter.name!r} cannot declare a default")
default, default_type = _normalize_default(default, type_spec, context=f"{callable_id.name}() parameter {parameter.name!r}")
if default is not None:
if mode is EvaluationMode.RUNTIME_ONLY:
raise CompileError(f"{callable_id.name}() RUNTIME_ONLY parameter {parameter.name!r} cannot declare a concrete default")
default, default_type = _normalize_default(default, type_spec, context=f"{callable_id.name}() parameter {parameter.name!r}")
parameters.append(ExtensionParameterSpec(parameter.name, parameter.kind, type_spec, mode, default, default_type))
return_annotation = annotations.get("return", signature.return_annotation)
if return_annotation is inspect.Signature.empty:
Expand Down
24 changes: 19 additions & 5 deletions semantic/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,9 @@ def candidate_matches(item, *, exact: bool) -> bool:
except CompileError:
return False
else:
if occurrence is None and parameter.default is None:
# Omitted typed inputs carry no type evidence for overload selection.
continue
if parameter.default_type is None:
raise CompileError("Internal error: extension bound default lost canonical type")
actual_type = parameter.default_type
Expand Down Expand Up @@ -581,9 +584,14 @@ def candidate_matches(item, *, exact: bool) -> bool:
occurrences = tuple(value) if parameter.kind is inspect.Parameter.VAR_POSITIONAL else (value,)
resolved_items = []
for variadic_index, occurrence in enumerate(occurrences):
if occurrence is None and parameter.kind is not inspect.Parameter.VAR_POSITIONAL:
raise CompileError("Internal error: selected extension binding lost fixed parameter")
transport_variadic = variadic_index if parameter.kind is inspect.Parameter.VAR_POSITIONAL else None
if occurrence is None:
if parameter.default is not None or parameter.kind is inspect.Parameter.VAR_POSITIONAL:
raise CompileError("Internal error: selected extension binding lost fixed parameter")
# A fixed positional slot is retained for physical signature reconstruction.
static_operands.append(AnalyzedStaticCallOperand(parameter_index, None, None))
resolved_items.append(None)
continue
if isinstance(occurrence, ast.AST):
representation, payload, actual_type = acquired[id(occurrence)]
if representation == "runtime":
Expand Down Expand Up @@ -809,8 +817,12 @@ def _analyze_extension_semantic_call(
acquired_items: list[object] = []
type_spec = parameter.type_spec
for occurrence in occurrences:
if occurrence is None and parameter.kind is not inspect.Parameter.VAR_POSITIONAL:
raise CompileError("Internal error: semantic extension binding lost fixed parameter")
if occurrence is None:
if type_spec.kind != "NF_SET" or parameter.default is not None:
raise CompileError("Internal error: semantic extension binding lost fixed parameter")
# An omitted typed parameter has no semantic dependency or type.
acquired_items.append(None)
continue
if isinstance(occurrence, ExtensionSemanticPayload):
payload = occurrence
if type_spec.kind not in {"RECORD", "LIST"}:
Expand Down Expand Up @@ -884,7 +896,9 @@ def _analyze_extension_semantic_call(
occurrences = tuple(value) if parameter.kind is inspect.Parameter.VAR_POSITIONAL else (value,)
argument_items = []
for item in occurrences:
if parameter.type_spec.kind != "NF_SET":
if item is None and parameter.type_spec.kind == "NF_SET" and parameter.default is None:
argument_items.append(None)
elif parameter.type_spec.kind != "NF_SET":
argument_items.append(invocation.clone_semantic_argument(parameter.type_spec, item))
elif isinstance(item, RuntimeRef):
argument_items.append(ResultRuntimeArg(item.typ))
Expand Down
Loading
Loading