ποΈ DevLog: Full Class Support - Object-Oriented Pascal to Modern C++23 #14
jarroddavis68
started this conversation in
DevLog
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Version: JetPascal 0.3.0+
π What's New
JetPascal now supports complete Object Pascal class syntax with full inheritance chains, virtual methods, constructors, destructors, and the
Selfkeyword - all transpiled to clean, modern C++23.Write Pascal classes. Get native C++ performance.
π‘ What This Means
You can now:
β Define classes with fields and methods
β Use single inheritance with unlimited depth
β Declare virtual and override methods
β Write constructors with
inheritedcallsβ Implement destructors with automatic chaining
β Use
Selfkeyword for explicit instance accessβ Create objects with
TClass.Create()syntaxβ Free objects with
.FreemethodAll transpiled to efficient C++23 with zero runtime overhead.
π What Class Support Looks Like
Here's a complete inheritance hierarchy:
And here's what gets generated:
Notice:
class TDog : public TAnimalinherited Create()β C++ initializer list: TDog(...)Self.GetNameβthis->GetName()#linedirectives for source-level debuggingπ¬ Real Features We've Implemented
1. Multi-Level Inheritance
The Magic: Unlimited inheritance depth with proper constructor chaining.
Generated Output:
Each constructor in the chain runs in order. Parent first, then child.
Why It Matters: Build complex class hierarchies naturally. The transpiler handles all the C++ plumbing.
2. Virtual Methods & Polymorphism
Dynamic Dispatch: Override behavior in child classes.
Runtime Output:
Same method name, different behavior based on actual object type.
Why It Matters: True OOP polymorphism. Write generic code that works with any subclass.
3. The Self Keyword
Explicit Instance Access: Reference the current object.
Generated C++:
Selfβthis- Clean, idiomatic C++.Why It Matters: Access methods from parent classes. Make intent explicit. Standard Pascal OOP.
4. Constructor Inheritance
The Magic:
inherited Create()becomes C++ initializer lists.Generated C++:
The transpiler:
inherited Create(args)as the first statementWhy It Matters: Correct C++ initialization order. Parent constructed before child fields accessed. Efficient code generation.
5. Destructor Chaining
Automatic Cleanup: Destructors run in reverse order.
Runtime Output:
Child destructor runs first, then parent, then grandparent.
Why It Matters: Resources freed in correct order. No leaks. Proper cleanup semantics.
6. Object Creation & Destruction
Pascal Syntax, C++ Smart Pointers:
Generated C++:
Mapping:
TClass.Create(args)βjp::create<TClass>(args)obj.Method()βobj->Method()obj.Freeβobj.reset()Why It Matters: Automatic memory management via smart pointers. No manual
delete. No leaks.7. If-Then-Else Without Begin-End
Natural Pascal Syntax:
Generated C++:
Single statements without
begin-endwork perfectly.Why It Matters: Write natural Pascal. No forced verbosity. Clean transpilation.
8. String Escaping
Embedded Quotes Handled:
WriteLn('Counter "{}" initialized to {} with step {}', FName, FValue, FStep);Generated C++:
Pascal single-quoted strings with embedded
"β properly escaped C++ strings.Why It Matters: Format strings work. No manual escaping. Just write Pascal.
π» Complete Test Output
Here's the full test suite output proving everything works:
9 test categories. 6 classes. Multi-level inheritance. Virtual methods. Self keyword. All working.
π― What Makes This Special
"Just Works" Philosophy
Add new classes. They automatically work with:
No special handling required. Pascal class syntax maps directly to C++ class syntax.
Clean C++ Output
The generated code is:
#linedirectives map to Pascal source)Smart Pointer Memory Management
Uses
jp::Ref<T>(smart pointers) under the hood. Memory automatically managed. No leaks possible.Full Virtual Dispatch
Pascal
virtualandoverridekeywords work exactly as expected. Polymorphism is real - not simulated.Source-Level Debugging
Thanks to
#linedirectives, you can:Even though it's running compiled C++.
π¦ Current Status
β Fully Working
These are planned features, not limitations. The core OOP foundation is solid.
π Performance
JetPascal classes compile to native C++ classes. The performance characteristics are identical to hand-written C++:
π Summary
TDog = class(TAnimal)class TDog : public TAnimalprocedure Speak; virtual;virtual void Speak();procedure Speak; override;void Speak() override;inherited Create(args): ParentClass(args)(initializer list)Self.GetNamethis->GetName()TDog.Create(args)jp::create<TDog>(args)obj.Freeobj.reset()destructor Destroy; override;virtual ~TDog()Write Pascal. Get C++. Ship native.
Happy Coding! ποΈ
JetPascalβ’ - Accelerate Your Code!
Technical Note: JetPascal's class support leverages C++23's powerful type system while maintaining Pascal's familiar syntax. The transpiler performs intelligent analysis to generate proper initializer lists, virtual method tables, and destructor chains. All objects are managed via
jp::Ref<T>smart pointers (based onstd::shared_ptr) ensuring automatic memory management without garbage collection overhead. The#linedirective generation ensures that debugging, profiling, and error messages all reference the original Pascal source, not the generated C++.Beta Was this translation helpful? Give feedback.
All reactions