Skip to content
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

Constant-type pointers, readonly ports #6

Open
kiedtl opened this issue Feb 15, 2024 · 1 comment
Open

Constant-type pointers, readonly ports #6

kiedtl opened this issue Feb 15, 2024 · 1 comment
Labels
lang-new New language feature proposal

Comments

@kiedtl
Copy link
Owner

kiedtl commented Feb 15, 2024

The idea is that pointers are marked as const using some method, and are then prohibited from being passed to words that (indirectly or directly) call STA (i.e. takes a non-const pointer).

("Marking" pointers in this case means modifying their type signature. I'm not settled on what the signature for this is -- could be @const Type, @@Type, &Type, (Cons @Type), or something else.)

Pointers can be made const in a few ways:

  • (const) to constify the pointer on TOS
  • (const foo) to constify a variable
  • #const (let CONSTANT [ 0x0 ]) to declare a variable constant.
    • Not a fan of this one, as it encourages abusing variables to hold constant values (words should be used for that).

Same principle for device ports -- writing a readonly port literal results in Const_Dev16/Const_Dev8, which cannot be passed to words that require a non-readonly port. (Not sure if adding this particular feature is worth the extra complexity. I mean, how often would one accidentally try to write to a readonly port?)

@kiedtl kiedtl added the lang-new New language feature proposal label Feb 15, 2024
@kiedtl
Copy link
Owner Author

kiedtl commented Sep 11, 2024

Should probably use different terminology to differentiate from const words, which will be added at some point (to enable compile-time calculations etc).

immut/readonly would be good for this.

  • (immutify)
  • (immutify foo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-new New language feature proposal
Projects
None yet
Development

No branches or pull requests

1 participant