-
Notifications
You must be signed in to change notification settings - Fork 0
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
Implement Straight-Forward Operators of Two Variables #169
Comments
In previous versions, variable declarations have been implemented |
Like I said Above, redeclaring variable data types is inconvenient: ... // A very Inconvenient Syntax due to the need of redeclaring variable data types
Var
0@: Float
1@: Float
2@: Float
3@: Float
4@: Float
5@: Float
6@: Float
7@: Float
8@: Float
end
00a0=4,store_actor $PLAYER_ACTOR position_to 0@ 1@ 2@
00a0=4,store_actor 31@ position_to 3@ 4@ 5@
6@ = 3@
7@ = 4@
8@ = 5@
6@ -= 0@
7@ -= 1@
8@ -= 2@
...
... // Some long code
...
Var
0@: Int
1@: Int
2@: Int
3@: Int
4@: Int
5@: Int
9@: Int
10@: Int
11@: Int
end
092B: 0@ = group $PLAYER_GROUP member 0
092B: 1@ = group $PLAYER_GROUP member 1
092B: 2@ = group $PLAYER_GROUP member 2
092B: 3@ = group $PLAYER_GROUP member 3
092B: 4@ = group $PLAYER_GROUP member 4
092B: 5@ = group $PLAYER_GROUP member 5
9@ = 0@
10@ = 1@
11@ = 2@
9@ -= 3@
10@ -= 4@
11@ -= 5@
...
... // Some long code
...
Var
0@: Float
1@: Float
2@: Float
3@: Float
4@: Float
5@: Float
12@: Float
13@: Float
14@: Float
end
083D: get_actor $PLAYER_ACTOR velocity_in_direction_XYZ 0@ 1@ 2@
083D: get_actor 31@ velocity_in_direction_XYZ 3@ 4@ 5@
12@ = 3@
13@ = 4@
14@ = 5@
12@ += 0@
13@ += 1@
14@ += 2@ But instead Implement this Idea which does make sense and is easy and convenient to use: ... // A convenient way where the arithmetic operators decide what kind of data types it treats its variables
00a0=4,store_actor $PLAYER_ACTOR position_to 0@ 1@ 2@
00a0=4,store_actor 31@ position_to 3@ 4@ 5@
float 6@ = 3@
float 7@ = 4@
float 8@ = 5@
float 6@ -= 0@
float 7@ -= 1@
float 8@ -= 2@
...
... // Some long code
...
092B: 0@ = group $PLAYER_GROUP member 0
092B: 1@ = group $PLAYER_GROUP member 1
092B: 2@ = group $PLAYER_GROUP member 2
092B: 3@ = group $PLAYER_GROUP member 3
092B: 4@ = group $PLAYER_GROUP member 4
092B: 5@ = group $PLAYER_GROUP member 5
int 9@ = 0@
int 10@ = 1@
int 11@ = 2@
int 9@ -= 3@
int 10@ -= 4@
int 11@ -= 5@
...
... // Some long code
...
083D: get_actor $PLAYER_ACTOR velocity_in_direction_XYZ 0@ 1@ 2@
083D: get_actor 31@ velocity_in_direction_XYZ 3@ 4@ 5@
float 12@ = 3@
float 13@ = 4@
float 14@ = 5@
float 12@ += 0@
float 13@ += 1@
float 14@ += 2@ |
it's possible to declare a variable of a built-in type (Int, Float, String, LongString) using only the type name.
Any command such as assignment, mathematics, judging size, bit operation, etc. can use int, float in front to declare variable types, and it also supports custom variable names. I have a CLEO source code, maybe it can be used as your example: |
This is not implemented yet, and I tried to compile it and is gives an error(obvious). float 4@ -= 1@ Only inconvenient variable declarations before arithmetic operations is what I see on the document. I am pretty sure I haven't missed anything. |
For commands that use 2 variables, both variables need to be declared:
Or
|
Just to clarify, I did not said that Variable declarations wasn't implemented yet. I use variable declaration all the time in my cleo scripts, but it is just so inconvenient. I hope you get my point. |
That's what I am talking about, it is inconvenient. Wouldn't you agree? But if the compiler can understand something like this: int 0@ *= 1@
float 2@ /= 3@ Then cleo coding would be easier. |
I think it is very necessary to tell the compiler the data type of a variable behind. |
For: |
The compiler just needs to parse the parameters that are currently present on the currently line. I don't see anything wrong with that.
Here is an example: int $var += 0@
There are many ways to parse this parameters. My best suggestion is through RegEx . But it is up to the SB Dev team how they will parse it. |
I agree with the fact that declaring both variables in the expression is annoying. However what I don't really like in this proposal is the fact we may miss possible errors when the variable was explicitly defined with another type. Consider this example:
the developer wanted to write What would be really useful if the compiler could deduce the variable type from the assigned value, so you don't really need to declare its type in trivial cases like
this would require a proper control-flow analysis which we don't have yet. I can probably make another option for the compiler to let the shorthand syntax proposed here, but it will be disabled by default. |
You are right on this one, that is an advantage of declaring variables before a certain operation for syntax error checking. So those who will use this feature should already have it in mind. But I think that it will not be a big deal because we are just adding an extra syntax feature which is a good thing because it allows us to do straightforward operations like. int c += a while still preserving the current conventions existed. That does not mean that we will make this as a replacement of the current convention when coding a script. Coders can still do variable declarations, and compile the same as before. If this feature gets implemented, then coders can optionally use straightforward variable to variable operations.
Maybe Variable Data Type Tracking which automatically detects the data types of variables. The idea would be:
x = 0
// starting from this line, x is now declared as "Int"
y = 10
// starting from this line, y is now declared as "Int"
x += y // both variables are int => 005a
y = 1.0
// starting from this line, x is now declared as "Float"
x += y // Int += Float Warns due to Syntax Error
092B: 0@ = group $PLAYER_GROUP member 5
// starting from this line, 0@ is now declared as "Int"
092B: 1@ = group $PLAYER_GROUP member 4
// starting from this line, 1@ is now declared as "Int"
092B: 2@ = group $PLAYER_GROUP member 3
// starting from this line, 2@ is now declared as "Int"
092B: 3@ = group $PLAYER_GROUP member 2
// starting from this line, 3@ is now declared as "Int"
092B: 4@ = group $PLAYER_GROUP member 1
// starting from this line, 4@ is now declared as "Int"
092B: 5@ = group $PLAYER_GROUP member 0
// starting from this line, 5@ is now declared as "Int"
0@ += 1@ // Opcode 005A:
1@ -= 2@ // Opcode 0062:
2@ *= 3@ // Opcode 006A:
3@ /= 4@ // Opcode 0072:
00a0: store_actor $PLAYER_ACTOR position_to 0@ 1@ 2@
// starting from this line, 0@, 1@, and 2@ are now declared as "Float"
00a0: store_actor 31@ position_to 3@ 4@ 5@
// starting from this line, 3@, 4@, and 5@ are now declared as "Float"
3@ -= 0@ // Opcode 0063:
4@ -= 1@ // Opcode 0063:
5@ -= 2@ // Opcode 0063:
3@ += 0@ // Opcode 005B:
4@ += 1@ // Opcode 005B:
5@ += 2@ // Opcode 005B: That means that the Compiler must know all the data type of the returning variables of all possible Opcodes that exists then redeclare them automatically. |
Proposed bitwise operations syntax using examples from OP:
|
Another suggestion by @MiranDMC
|
Implemented in SB 4.0 |
Please Implement a Syntax regarding Arithmetic, Comparison, and Logical Operators. I would be super convenient for us Programmers if we can do something like this instead of relying on opcodes all the time for this simple variable to variable operations.
Inspiration for the Implementation:
I do not see any Syntax Collision towards the currently implemented syntax Versus the list of what I have proposed above
I know that there is a feature which you can declare a default data type of a variable using
var <var name>: <type> end // this can also be done outside the VAR END block: <type> <var name>
The problem here is that some programmers like me uses dynamic data type variables. An example case is that I sometimes store a float value on it, then an integer value on it. So defining default data types is useless towards it... Another workaround is to redefine the datatype of the variable
but this method is so incovenient.
Thats why I wanted a convenient syntax implementation where we can do it like this:
If there are any concerns or flaw towards my suggestion then I would be happy to hear it.
The text was updated successfully, but these errors were encountered: