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

Allow int/float variable type specifying in same way as it is supported for strings. #218

Open
MiranDMC opened this issue Mar 10, 2023 · 4 comments
Labels
discussion Further discussion is requested status:in dev triage

Comments

@MiranDMC
Copy link

MiranDMC commented Mar 10, 2023

Currently when working with string variables following syntax can be used:
1@s, 1@v for local variables
s$1, v$1 for global variables

I propose to make it possible to mark in same way intention to use variable as integer or float, so it would be possible:
4@i = i$40
f$1200 = 400@f

I know variable type can be defined using var-end block, but it only allows one type at the time peer variable, and this also can not be walked around with using constants names.

This feature would eliminate need to specify variable type globally, or painfully searching and using opcodes for every assignment and arithmetic operations.
Decompiled code would look cleaner too, without opcodes and "// (int)" comments in many cases.

@MiranDMC MiranDMC changed the title Allow variable type specifying in same way as it is supported for strings. Allow int/float variable type specifying in same way as it is supported for strings. Mar 10, 2023
@MiranDMC
Copy link
Author

Ok, this ticket seems to be almost duplicate of
#169
where OP request solution for the same problem.
Said topic is years old, so guess no high hopes for solution soon.

@MiranDMC
Copy link
Author

MiranDMC commented Mar 14, 2023

After some code developing later I have to say this is pain.
Argument from #169 against feature like this was that it can lead to errors when already defined variable is reused with wrong type.
Current solution is to declare type for variable in separated line like int 0@ but problem is this can not be used in limited scope, so type declaration leaks till end of the code.
So the only way to "inline" solve the issue is to find and type opcode explicitly, which then ignores declared types of all operands and can lead to errors mentioned above.

@MiranDMC MiranDMC reopened this Mar 14, 2023
@x87
Copy link
Collaborator

x87 commented Mar 15, 2023

Current solution is to declare type for variable in separated line like int 0@ but problem is this can not be used in limited scope, so type declaration leaks till end of the code.

This is a valid point. If variable declaration becomes scoped (i.e. available till next end), would it solve the problem?

Float 0@
While true
int 0@ 
// 0@ is integer
end
// 0@ is float

@MiranDMC
Copy link
Author

MiranDMC commented Mar 16, 2023

Scope support would be helpful. There should be also way to create scope on demand, like:
scope (...) end

Routines with return could be problematic to handle, but it can be assumed they are not creating scope by itself. Then 'scope' block can be used inside if necessary.

It would be nice to be able to define type and constant name for variable in single line:
int counter = 1 at 0@
or
int 0@ = 1 alias counter

I have searched my code for actual places where I was forced to specify opcodes, and it turns out it usually is case that naming variables is inconvenient so it end looking like:
0085: 0@ = 9@ // file handle
when it could look like:
0@ = file_handle

@x87 x87 added discussion Further discussion is requested status:in dev triage labels Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Further discussion is requested status:in dev triage
Projects
None yet
Development

No branches or pull requests

2 participants