sannybuilder / dev

Sanny Builder Bug Tracker and Roadmap development
https://sannybuilder.com
49 stars 0 forks source link

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

Open MiranDMC opened 1 year ago

MiranDMC commented 1 year ago

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 commented 1 year ago

Ok, this ticket seems to be almost duplicate of https://github.com/sannybuilder/dev/issues/169 where OP request solution for the same problem. Said topic is years old, so guess no high hopes for solution soon.

MiranDMC commented 1 year ago

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.

x87 commented 1 year ago

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 commented 1 year ago

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