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

[Feature] Loop used with range should compile to for loop #120

Open
daoanhthanh opened this issue May 28, 2024 · 2 comments
Open

[Feature] Loop used with range should compile to for loop #120

daoanhthanh opened this issue May 28, 2024 · 2 comments
Assignees
Labels
compiler enhancement New feature or request

Comments

@daoanhthanh
Copy link

Hi, I read your documentation and noticed that one of Amber's features is adding Shebang at the top of the compiled file.

However, in my case, it does not work.

My .ab file:

let target = "my friend"

let message = "Hello, {target}! Want some Shawarma?"
let repeated_times = 3

loop i in 0..repeated_times {
    echo message
}

and my .sh file generated by amber input.ab output.sh

__0_target="my friend";
__1_message="Hello, ${__0_target}! Want some Shawarma?";
__2_repeated_times=3;
for i in $(seq 0 $(echo ${__2_repeated_times} '-' 1 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//'))
do
    echo "${__1_message}"
done

Notice that there is no shebang at the top.

Is this a bug, or did I miss some information here?

@daoanhthanh
Copy link
Author

Also, I think the syntax for the for-loop is not optimized, since it relies on the external command (bc). Why don't you use something like:

for ((i=0; i<repeated_times; i++)); do
...

@Ph0enixKM
Copy link
Member

@daoanhthanh this is fixed in #107. Stay tuned. The optimisation features will come soon. I'll rename this issue title to be focused on the for-loop optimisation.

@Ph0enixKM Ph0enixKM changed the title Does not add shebang after compiling. ✨ Loop used with range should compile to for loop May 28, 2024
@Ph0enixKM Ph0enixKM added this to the Amber 0.4.0-alpha milestone Jun 17, 2024
@Mte90 Mte90 added the enhancement New feature or request label Jun 24, 2024
@Ph0enixKM Ph0enixKM changed the title ✨ Loop used with range should compile to for loop [Feature] Loop used with range should compile to for loop Jul 7, 2024
@Mte90 Mte90 added the compiler label Jul 19, 2024
@b1ek b1ek self-assigned this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants