Skip to content

Conversation

@Scheremo
Copy link
Contributor

@Scheremo Scheremo commented Oct 24, 2025

Adds class method declarations, wires it into the importer, and supports implicit this, inherited property access, and upcasting.

  • New ops

    • moore.class.methoddecl: declare methods inside classdecl (FunctionType).
  • Importer

    • Lowers t.m(...) and unqualified m(...) (inside methods) to func.call.
    • Adds implicit %this : !moore.class<@C> as first block arg for methods.
    • Performs implicit upcast of the receiver when needed.
    • Resolves class properties via class.property_ref (now also for implicit this).
    • Clearer diag: prints SV type for unsupported member-access bases.
  • Lowering plumbing

    • declareFunction split into declareCallableImpl to share logic; supports methods (qualified name @"Pkg::Class"::method).
    • Tracks currentThisRef in Context for implicit this in expressions.
    • ClassDeclVisitor emits class.methoddecl in source order after lowering the method body.
  • Verifiers / build

    • ClassDeclOp verifier accepts class.methoddecl.
    • Includes/linkage for call interfaces (MooreOps.h, CMake).
  • Tests

    • classes.sv: calls on concrete classes, inherited property access through upcast, and method decls reflected in IR.

@Scheremo Scheremo force-pushed the pr-moore-class-methods branch 5 times, most recently from b970ca9 to 9dd6aed Compare October 24, 2025 15:53
@Scheremo Scheremo force-pushed the pr-moore-class-methods branch 8 times, most recently from 46e17e5 to 483803b Compare October 28, 2025 21:05
@Scheremo Scheremo marked this pull request as ready for review October 28, 2025 21:07
@Scheremo Scheremo force-pushed the pr-moore-class-methods branch from 483803b to 21ecdc8 Compare October 28, 2025 21:36
Comment on lines -1034 to -1039
// Prefix the function name with the surrounding namespace to create somewhat
// sane names in the IR.
SmallString<64> funcName;
guessNamespacePrefix(subroutine.getParentScope()->asSymbol(), funcName);
funcName += subroutine.name;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just out of curiosity: does the namespace prefix guessing not work if there are classes or modules around the function/subroutine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems to not resolve package scope names or module scope names.

@Scheremo Scheremo force-pushed the pr-moore-class-methods branch 2 times, most recently from c0f5c6c to e00dc2a Compare October 29, 2025 06:23
Adds **class method declarations** and a **direct call op**, wires them into the importer, and supports implicit `this`, inherited property access, and upcasting.

- **New ops**
  - `moore.class.methoddecl`: declare methods inside `classdecl` (FunctionType).
  - `moore.class.call`: direct (non-virtual) method call; verifies callee, arity, and types.

- **Importer**
  - Lowers `t.m(...)` and unqualified `m(...)` (inside methods) to `class.call`.
  - Adds implicit `%this : !moore.class<@C>` as first block arg for methods.
  - Performs **implicit upcast** of the receiver when needed.
  - Resolves class properties via `class.property_ref` (now also for implicit `this`).
  - Clearer diag: prints SV type for unsupported member-access bases.

- **Lowering plumbing**
  - `declareFunction` split into `declareCallableImpl` to share logic; supports methods (qualified name `@"Pkg::Class"::method`).
  - Tracks `currentThisRef` in `Context` for implicit `this` in expressions.
  - `ClassDeclVisitor` emits `class.methoddecl` in source order after lowering the method body.

- **Verifiers / build**
  - `ClassDeclOp` verifier accepts `class.methoddecl`.
  - `ClassCallOp` verifier checks symbol -> function, FunctionType, operand types.
  - Includes/linkage for call interfaces (`MooreOps.h`, CMake).

- **Tests**
  - `classes.sv`: calls on concrete classes, inherited property access through upcast, and method decls reflected in IR.
@Scheremo Scheremo force-pushed the pr-moore-class-methods branch from e00dc2a to e313129 Compare October 29, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants