Skip to content

Vulkan shaders#14

Merged
ravituringworks merged 7 commits into
masterfrom
develop
Nov 22, 2025
Merged

Vulkan shaders#14
ravituringworks merged 7 commits into
masterfrom
develop

Conversation

@ravituringworks

Copy link
Copy Markdown
Collaborator

Vulkan shaders implementation

ravituringworks and others added 7 commits November 12, 2025 22:54
This commit completes the implementation of object-oriented method call
syntax (df->Method()) for XDL DataFrames, enabling the advanced syntax
used in demo scripts.

## Parser Changes (xdl-parser/src/parser.rs)
- Enhanced parse_postfix() to handle Arrow (->) operator for method calls
- Enhanced parse_postfix() to handle Dot (.) operator for struct field access
- Added proper argument parsing for method calls with parentheses
- Fixed error handling to use line/column fields

## Core Type System (xdl-core/src/types.rs)
- Added DataFrame(usize) variant to XdlValue enum
- Added Struct(HashMap<String, XdlValue>) variant to XdlValue enum
- Updated gdl_type() method to return ObjRef for DataFrame and Struct
- Updated to_string_repr() to display DataFrame and Struct values

## Context (xdl-interpreter/src/context.rs)
- Added DataFrame storage with HashMap<usize, DataFrame>
- Added auto-incrementing DataFrame ID management
- Implemented store_dataframe(), get_dataframe(), get_dataframe_mut()
- Implemented remove_dataframe() for cleanup

## Interpreter (xdl-interpreter/src/evaluator.rs)
- Implemented method dispatch based on object type
- Added call_dataframe_method() with 4 methods:
  * Shape() - Returns [rows, cols] array
  * ColumnNames() - Returns column count array
  * Column(name) - Extracts column as array
  * WriteCSV(filename) - Writes DataFrame to CSV
- Added XDLDATAFRAME_READ_CSV function for loading CSV files
- Uses CsvReaderOptions with configurable delimiter

## Dependencies (xdl-interpreter/Cargo.toml)
- Added xdl-dataframe dependency for DataFrame operations

## Standard Library (xdl-stdlib/src/string.rs)
- Updated STRING() function to handle DataFrame and Struct variants

## Tests
- Added examples/test_dataframe_methods.xdl - comprehensive test suite
- Added examples/test_dataframe_simple.xdl - basic CSV read test
- Both tests pass successfully

## Documentation
- Added docs/OBJECT_ORIENTED_SYNTAX_IMPLEMENTATION.md
- Moved Python visualization scripts to examples/ folder
- Added examples/README_VISUALIZATION_SCRIPTS.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit lays the groundwork for full OO support in XDL by adding the
necessary AST nodes and lexer tokens.

## Lexer Changes (xdl-parser/src/lexer.rs)
- Added `DoubleColon` token (::) for method definitions
- Added parsing logic for :: operator (must match before single :)

## AST Extensions (xdl-parser/src/ast.rs)
- Added `Statement::ClassDefinition` for PRO ClassName__define
- Added `Statement::MethodDefinition` for PRO/FUNCTION ClassName::MethodName
- Added `Statement::ObjectDestroy` for OBJ_DESTROY command
- Added `Expression::ObjectNew` for OBJ_NEW() function calls
- Updated location() methods to handle new variants

## Interpreter Stubs (xdl-interpreter/src/lib.rs)
- Added NotImplemented handlers for new statement types
- Clear error messages indicating implementation phases

## Design Documentation (docs/OBJECT_ORIENTED_DESIGN.md)
- Comprehensive OO system design based on IDL/GDL syntax
- Complete architecture for classes, objects, methods, and lifecycle
- Implementation phases and examples
- Reference syntax from official IDL documentation

## Progress
✅ Phase 1: Core Infrastructure (Lexer & AST) - COMPLETE
⏳ Phase 2: Parser Implementation - NEXT
⏳ Phase 3: Context & Storage - TODO
⏳ Phase 4: Evaluator Implementation - TODO
⏳ Phase 5: Testing & Documentation - TODO

This establishes the foundation for implementing IDL-compatible OOP features
including class definitions, method calls, object instantiation (OBJ_NEW),
and object destruction (OBJ_DESTROY).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit implements full parser support for IDL-style object-oriented
programming constructs including class definitions, method definitions,
object instantiation, and destruction.

## Parser Changes (xdl-parser/src/parser.rs)

### Class Definition Parsing
- Modified `parse_procedure_definition()` to detect `__define` suffix
- Added `parse_class_definition_body()` method
- Extracts class name by removing `__define` suffix
- Parses body until ENDPRO

### Method Definition Parsing
- Modified `parse_procedure_definition()` and `parse_function_definition()`
- Detects `::` separator in procedure/function names
- Added `parse_method_definition_body()` method
- Splits on `::` to extract class_name and method_name
- Handles both PRO (procedure) and FUNCTION methods
- Parses parameters and keywords like regular procedures/functions

### OBJ_NEW Expression Parsing
- Modified function call parsing in `parse_primary()`
- Detects `OBJ_NEW` calls (case-insensitive)
- Extracts class name from first argument (must be string literal)
- Remaining arguments become constructor arguments
- Creates `Expression::ObjectNew` instead of `FunctionCall`

### OBJ_DESTROY Statement Parsing
- Modified `parse_procedure_call()` to detect `OBJ_DESTROY`
- Collects object expressions as arguments
- Creates `Statement::ObjectDestroy` instead of `ProcedureCall`

## Example Syntax Now Supported

```xdl
; Class definition
PRO Point__define
    struct = {Point, x: 0.0, y: 0.0}
ENDPRO

; Method definition (function)
FUNCTION Point::Init, x, y
    self.x = x
    self.y = y
    RETURN, 1
ENDFUNCTION

; Method definition (procedure)
PRO Point::Move, dx, dy
    self.x = self.x + dx
    self.y = self.y + dy
ENDPRO

; Object creation
p = OBJ_NEW('Point', 3.0, 4.0)

; Method calls (already supported from Phase 1)
distance = p->Distance()
p->Move, 1.0, 1.0

; Object destruction
OBJ_DESTROY, p
```

## Progress
✅ Phase 1: Core Infrastructure (Lexer & AST) - COMPLETE
✅ Phase 2: Parser Implementation - COMPLETE
⏳ Phase 3: Context & Storage - NEXT
⏳ Phase 4: Evaluator Implementation - TODO
⏳ Phase 5: Testing & Documentation - TODO

All parser code compiles successfully. The parser can now recognize all
IDL OO syntax patterns. Next step is to implement the runtime storage
and evaluation logic.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit implements the core OO infrastructure and evaluator support:

Phase 3 - Context & Storage:
- Added Object(usize) variant to XdlValue enum in types.rs
- Updated to_string_repr(), is_zero() methods to handle Object type
- Created ClassDef, MethodDef, and ObjectInstance structs in context.rs
- Added class and object storage to Context with management methods:
  * define_class(), get_class(), get_class_mut()
  * create_object(), get_object(), get_object_mut(), remove_object()
- Objects use ID-based handles (0 = NULL) to avoid borrowing issues

Phase 4 - Evaluator Implementation:
- Implemented execute_class_definition() for PRO ClassName__define
- Implemented execute_method_definition() for PRO/FUNCTION ClassName::MethodName
- Implemented OBJ_NEW expression evaluation in evaluator
- Implemented OBJ_DESTROY statement execution with Cleanup method support
- Fixed non-exhaustive pattern match in xdl-stdlib string.rs
- Fixed clippy warning for collapsible if-let patterns

Note: User-defined method dispatch and SELF keyword support are
placeholder implementations pending full method execution with proper
scoping and field access.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit completes the core OO features for XDL:

SELF Keyword Support:
- Added current_self field to Context to track active object
- Implemented set_self(), clear_self(), get_self(), get_self_id()
- Modified evaluator to intercept "SELF" variable and return Object value
- SELF is automatically set/cleared during method execution

Field Access (obj.field and SELF.field):
- Implemented StructRef expression evaluation for Object types
- Objects can now access their fields via dot notation
- Case-insensitive field lookup matching IDL behavior
- Also works for regular Struct types

User-Defined Method Dispatch:
- Implemented call_user_method() in evaluator
- Methods look up class definition and method implementation
- Sets SELF context and creates method scope
- Binds parameters to arguments
- Returns method result (functions) or Undefined (procedures)

Note: Method body statement execution currently returns NotImplemented
as it requires interpreter-level access. This is a known limitation
that will be addressed in future iterations. The infrastructure is
complete and ready for integration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Added comprehensive TODO.md documenting all missing IDL features:
- Priority ranking (CRITICAL/HIGH/MEDIUM/LOW)
- 15 major feature categories with detailed task breakdowns
- Implementation order recommendation (10-week plan)
- Testing strategy

Implemented CASE/SWITCH AST infrastructure:
- Added Statement::Case and Statement::Switch variants
- Added CaseBranch struct for branch definitions
- Updated Statement::location() to handle new variants
- Added stub implementations in interpreter (NotImplemented)
- All tokens already exist in lexer (Case, Of, Endcase, Switch, Endswitch)

Features documented in TODO.md:
- CASE/SWITCH control structures (CRITICAL)
- Pointer operations (CRITICAL)
- Critical array functions (CRITICAL)
- File I/O improvements (HIGH)
- Structure functions (HIGH)
- Type inquiry functions (HIGH)
- String processing (MEDIUM)
- Mathematical functions (MEDIUM)
- And more...

Next steps: Implement parsers and evaluators for CASE/SWITCH,
then continue with other high-priority features systematically.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Implemented complete Vulkan compute backend with SPIR-V shaders
- Added 11 GLSL compute shaders (add, mul, sub, div, sin, cos, exp, log, sqrt, pow, matmul)
- Implemented optimized matrix multiplication (GEMM) with tiled 16x16 algorithm
- Added build script for SPIR-V shader compilation using glslangValidator
- Updated Vulkan backend with proper instance/device initialization
- Implemented GPU buffer management with device memory allocation
- Added compute pipeline infrastructure with descriptor sets
- Implemented fence-based synchronization for GPU operations
- Added Metal GEMM implementation with threadgroup memory optimization
- Updated README with Vulkan backend documentation
- Fixed test paths to use relative paths instead of hardcoded absolute paths

Technical details:
- Vulkan 1.2 API with compute queue support
- Shared memory tiling for cache efficiency
- 2D workgroup dispatch for matrix operations
- Push constants for operation parameters
- Host-visible buffers for CPU-GPU data transfer
- Works on macOS via MoltenVK translation layer
@ravituringworks ravituringworks merged commit 1595cb6 into master Nov 22, 2025
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant