Skip to content

Watches with pointers #4279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Watches with pointers #4279

wants to merge 5 commits into from

Conversation

YoshiRulz
Copy link
Member

@YoshiRulz YoshiRulz commented Mar 28, 2025

With this PR, I aim to implement #377. My goal is to have a checkbox in the watch editor which swaps out the address box for a freeform textbox (that's all done), into which you can type semi-arbitrary expressions involving pointer arithmetic (see below). The editor will store this with a new Watch subclass, which holds onto an AST of the expression (should be done modulo parsing), re-evaluating the effective address each time RAM Watch calls Update (should be done modulo the peeks). Addresses are assumed to be in the sysbus, and the editor enforces this, disabling pointer mode when no sysbus exists (done).

For the expressions, I plan use a C-like mixed infix/prefix syntax with:

  • '0x'-prefixed hex literals (and only hex literals) for addresses;
  • '$'-prefixed decimal literals (or '$0x'-prefixed hex literals) for constants;
    • As feos points out below, '$' is used in e.g. 6502 disasm in place of '0x', with '#' used for constants there. So I agree we should not use '$', and '#' is as good as any replacement. There aren't many other available sigils anyway...
  • a pointer dereference operator;
  • grouping with parentheses;
  • addition, subtraction, and multiplication operators for offsets;
  • bitwise intersection and conjunction (AND and OR) operators and a right shift operator for masking.
  • Example: *(0x1234 + 2 * (*0xABCD & $7))
  • And, expressions will be typed—u32, either pointer- or non-pointer-coloured—and operators will only accept certain types of argument.
    • Actually I think only binary operations on two pointer arguments and dereferencing on non-pointers need to be blocked? No reason to block arithmetic with non-pointers.
  • I think I'll just copy C#'s operator precedence.
  • My plan was to distinguish multiplication and dereferencing by requiring whitespace around all binary operators. I believe it would be possible to have a consistent parser even without whitespace (like... C#'s), it's just simpler that way. Alternatively, we could change the sigil for dereferencing to something unique, maybe '@'.

@YoshiRulz YoshiRulz marked this pull request as draft March 28, 2025 23:48
@vadosnaprimer
Copy link
Contributor

In asm code I've seen, $ is usually a prefix for hexadecimal and specifically for addresses. For constants (immediate values), # is used on top.

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.

2 participants