Implementation:Google deepmind Mujoco WASM Functions Generator
| Knowledge Sources | |
|---|---|
| Domains | WebAssembly, Code Generation, Function Bindings |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
Generates C++ wrapper functions and Embind bindings for MuJoCo API functions, handling parameter unpacking and null checks.
Description
functions.py provides the code generation logic for wrapping MuJoCo C functions as JavaScript-callable Embind functions. It includes param_is_primitive_value for checking if parameters are simple value types, get_const_qualifier for determining return type qualifiers, and generate_function_wrapper for producing complete C++ wrapper functions with parameter validation (CHECK_VAL for non-nullable params), parameter unpacking (converting JavaScript types to C types), bounds checking (from constants), and return value conversion. The generator handles pointer types, array types, and value types with appropriate null checking and type conversion strategies.
Usage
Called during the WASM code generation pipeline to produce function wrapper sections of the bindings.cc file, ensuring each MuJoCo API function is safely callable from JavaScript.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: wasm/codegen/generators/functions.py
- Lines: 1-283
Key Functions
def param_is_primitive_value(param: ast_nodes.FunctionParameterDecl) -> bool:
def get_const_qualifier(func: ast_nodes.FunctionDecl) -> str:
def generate_function_wrapper(func: ast_nodes.FunctionDecl) -> str:
def get_param_notnullable(p: ast_nodes.FunctionParameterDecl) -> str:
def get_param_unpack_statement(p: ast_nodes.FunctionParameterDecl) -> str:
def get_compatible_return_type(func: ast_nodes.FunctionDecl) -> str:
def get_compatible_return_code(func: ast_nodes.FunctionDecl) -> str:
Import
from wasm.codegen.generators import functions
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| func | ast_nodes.FunctionDecl | Yes | Parsed MuJoCo function declaration from AST introspection |
| param | ast_nodes.FunctionParameterDecl | Yes | Individual function parameter for type analysis |
Outputs
| Name | Type | Description |
|---|---|---|
| str | str | Generated C++ wrapper function code with parameter validation and conversion |
| bool | bool | Whether a parameter is a primitive value type |