None of the above is a bug and it should never throw..
Here's why:
'dsgsgsgs';
is actually declaring a constant compile time string. The string may not be used but it is certainly created. Compile time calculations and storage is actually a GOOD thing (most of the time.. not always). C++ and Assembly makes heavy use of this.
If you do:
int main()
{
"hello there";
return 0;
}
in any C compiler, you will notice that it compiled.. The assembly generated however would be different:
main:
push rbp
mov rbp, rsp
mov eax, 0
pop rbp
ret
In other words, the string that is created is actually not stored in the .data section because it is un-used and so the compiler optimises it out..
However, if you were to assign the string to a variable and use that variable, it will be stored in the .data section and the variable would hold the address of it.
The same exact logic applies to Simba. The string is created. Is it optimised out? I have no clue because we cannot currently view Simba's assembly. What I do know is this:
var
str, str2: String;
begin
str := 'hello'
str2 := str;
end;
Both str2 and str1 point to a constant string 'hello' that is stored somewhere (.data section for simba scripts). The reference count is thus "-1" for constants.. If the two strings were dynamically allocated (run-time), then str2 would still point to str1.. however, the reference would be "2" because 2 variables point to the same memory location..
When str2 is changed or str1 is changed, a new string might be allocated instead (run-time). If neither are changed, they should both be pointing to the exact same (compile-time) string if and only if Simba has that sort of optimisation.. Otherwise, they'd be pointing to two separate compile time strings..
Because of this logic, that constant string within your loop.. isn't created every single time. Instead, it is created only ONCE no matter how many times you loop. It is created at the start of your script..
You can verify this logic by doing:
var
str1, str2: String;
begin
str1 := 'hello';
str2 := str1;
(@Str1[1])^ := 'm';
writeln(str1); //prints 'mello'
writeln(str2); //prints 'mello'
end.
You ask why? Because like I said.. they both point to the exact same address! str2 is NOT a copy of str1!
Now here is the trick:
var
str1, str2: String;
begin
str1 := 'hello';
str2 := str1;
str1[1] := 'm';
writeln(str1); //prints 'mello'
writeln(str2); //prints 'hello'
end.
WTH? You ask? Well.. like I said. When one is "changed", a COPY is made and all changes are made to that COPY! This is known as "copy-on-write".
Now that you know how the optimisation side works.. THIS IS A GOOD THING.. This guarantees that your scripts run fast! Only ONE string is created because the compiler is smart enough to know that you're not changing it and that you're using the same string every loop. I thus believe that it will optimise out your string if it is unused. I'm sure you'll agree now that it shouldn't be removed and shouldn't throw.
Now for the loop:
The assembly for the loop however would look like:
main:
push rbp
mov rbp, rsp
.while_jump: ;begin loop
;the body of the loop goes here..
jmp .while_jump ;continue loop infinitely
It will simply "stall" the CPU and wait infinitely. Without a "sleep/wait", it "can possibly" use 100% CPU.