Skip to content

Simplified inter-variable calculations #58

Closed

Description

@MatiDragon-YT

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. 👍

Activity

  1. x87 commented on Aug 21, 2020

    @x87
    Collaborator

    @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.

  2. added
    discussion
    on Aug 21, 2020
  3. x87 commented on Aug 21, 2020

    @x87
    Collaborator

    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.

  4. MatiDragon-YT commented on Aug 21, 2020

    @MatiDragon-YT
    MemberAuthor

    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)

  5. x87 commented on Aug 21, 2020

    @x87
    Collaborator

    @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.

  6. MatiDragon-YT commented on Aug 21, 2020

    @MatiDragon-YT
    MemberAuthor

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

  7. MatiDragon-YT commented on Sep 25, 2020

    @MatiDragon-YT
    MemberAuthor

    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
    
  8. x87 commented on Nov 7, 2020

    @x87
    Collaborator

    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
    
  9. added
    priority:p2
    type:feature
    and removed
    discussion
    on Nov 7, 2020
  10. added this to the v3.6.0 milestone on Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:p2scope:compilertype:feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions