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

Simplified inter-variable calculations #58

Closed
1 of 2 tasks
MatiDragon-YT opened this issue Aug 21, 2020 · 7 comments
Closed
1 of 2 tasks

Simplified inter-variable calculations #58

MatiDragon-YT opened this issue Aug 21, 2020 · 7 comments
Labels
priority:p2 Medium priority scope:compiler type:feature New feature or request
Milestone

Comments

@MatiDragon-YT
Copy link
Member

MatiDragon-YT commented Aug 21, 2020

Hello, good afternoon colleagues.
Let's talk about a low level first.

Low level

As you already know, the compiler supports low-level arithmetic operations like...

$x += 1.5
$y -= 2
$x /= 3.1415

which save us some time searching for the opcode.
If you are like me, surely you quickly realized that these shortcuts only work to assign a static value, NOT VARIABLES!

$ += @  // ERROR
$ += 12 // ok

and if we change this for this....

var
   @ = 6
   $ = 7
end
$ += @
//EEEEEERROOOOOR!!!!!

Although there are the opcodes for them, which range from 0058 to 0077.
I was wondering if the compiler could extend that small capacity that goes from 0004 to 0046, to have fewer errors when jutar operations like...

$ += $  //nice!
$ += @//good!
@ += @//exelent!
@ += $ //PERFECT!!!

do you think it is possible to add that function?
And do you think that would be cool?

  • It'd be great!
  • First option!

High level

And if you could do long calculations and have the compiler cut them, to analyze which opcode they belong to?
Variables

var
   $321 : float = 0.1
   20@ : float = 2.5
   12@ : float = 46.324
   $482 : float = 3.333
end 

Syntax

calc
   1@ = $321 * 20@ + 12@ / $482 
end

Compilation -->

$321 *= 20@
12@ /= $482 
$321 * = 12@
1@ = $321 // 1@ = 14.1485899

Well, I don't know what language you use, but previously, at the university, they had told me to do something similar in C #, and I remember that it was done with System.Text.RegularExpressions. Also in JavaScript .... It is easy, but somewhat confusing the system, but it would be somewhat satisfactory if the IDE already has it by default, so as not to have to use an app that hosts on the internet... haha

Mi inglés es terrible, pero espero que lo entiendas todo. 👍

@x87
Copy link
Collaborator

x87 commented Aug 21, 2020

@MatiDragon-YT

var
   6@: int
   $7: int
end
$7 += 6@

this works, compiles to 005E.

complex expressions are fine and easy to implement until we got to the point where we need to introduce a temporary variable to calculate the result. consider:

$var = ($a + $a) * ($a - $a)

this should unwrap to:

$temp1 = $a
$temp1 += $a
$temp2 = $a
$temp2 -= $a
$var = $temp1
$var *= $temp2

which is again possible to implement but requires extra memory managements. Due to limits on variables the compiler can't arbitrarily add more hidden variables (neither global, as it affects the main.scm layout by increasing varspace in the header, nor local as their amount is very low). Here is the dilemma, how to circumvent it.

@x87 x87 added discussion Further discussion is requested scope:compiler labels Aug 21, 2020
@x87
Copy link
Collaborator

x87 commented Aug 21, 2020

custom local variables #32 is actually a one step closer towards supporting features like this as we hide some low-level details from the user and let the compiler deal with variables under the hood.

@MatiDragon-YT
Copy link
Member Author

MatiDragon-YT commented Aug 21, 2020

You are absolutely right @x87 , in fact the IDE compiles those opcodes well ..... Unless ..... heheheeee....... use variables from the constants.txt file... hohohoo~ 😱
the same is true of the {$ I} directive as well.
error-compiler1

is this a compiler error, or a programmer error? (me)

@x87
Copy link
Collaborator

x87 commented Aug 21, 2020

@MatiDragon-YT I see. You can't use constants defined in constants.txt in this way, as there is no type defined for them. They are simply aliases. You would need to first tell the compiler the type:

float j = 0.5
float v1 = 0.5

j += v1

although I think sometimes the compiler could infer the type from the value that has been assigned to it (0.5 means float), but Sanny is not that smart yet.

@MatiDragon-YT
Copy link
Member Author

uhmm... oh, okay... and thank you very much for your attention to my questions.

@MatiDragon-YT
Copy link
Member Author

These opcodes that you implemented in CLEO2 could be supported

0A8E: 4@ = 5@ + 6@ // int 
0A8F: $var = 0@ - 1 // int 
0A90: $var = 100 * 1@ // int 
0A91: $pre = 1 / 5 // int

so they can be used like this

4@ = 5@ + 6@
$var = 0@ - 1
$var = 100 * 1@
$pre = 1 / 5

@x87
Copy link
Collaborator

x87 commented Nov 7, 2020

These opcodes that you implemented in CLEO2 could be supported

0A8E: 4@ = 5@ + 6@ // int 
0A8F: $var = 0@ - 1 // int 
0A90: $var = 100 * 1@ // int 
0A91: $pre = 1 / 5 // int

so they can be used like this

4@ = 5@ + 6@
$var = 0@ - 1
$var = 100 * 1@
$pre = 1 / 5

this has been implemented in v3.6. now in statements like var = op1 (+-*/) op2 where var, op1 or op2 is an integer value or variable the compiler uses CLEO opcodes. e.g.

$var = 0@ - 1 // compiles to 0A9F as 1 is an integer number
$var = 0@ - 1@ // error, if no variables have been declared before as int
int $var = 0@ - 1@ // compiles to 0A9F as $var is integer variable

@x87 x87 added priority:p2 Medium priority type:feature New feature or request and removed discussion Further discussion is requested labels Nov 7, 2020
@x87 x87 added this to the v3.6.0 milestone Nov 7, 2020
@x87 x87 mentioned this issue Nov 7, 2020
46 tasks
@x87 x87 closed this as completed Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority:p2 Medium priority scope:compiler type:feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants