Replies: 3 comments 4 replies
-
idk about this. do you really want to maintain a bash AST serializer/deserializer? maybe make it like as a separate library that we depend on. i wouldn't want to have that as a part of amber itself |
Beta Was this translation helpful? Give feedback.
-
I also dislike manipulating Bash code as a string; it's prone to developer error and unforeseen edge cases, and in some cases makes the code harder to modify with new features. For example, I'm currently implementing the new You mentioned removing additional Bash variables to efficiently implement the However, this will be a large piece of work, touching most of the source code tree; it will almost certainly interfere with other development work, so we would have to plan it out carefully. In particular, it would be helpful if the new layer could be implemented as an optional feature, with fallback to the old method, so that existing builtins can be upgraded over time. Once everything has been upgraded, we can remove the scaffolding. In order to better understand what you have in mind, can you provide pseudo-code for some typical use cases? |
Beta Was this translation helpful? Give feedback.
-
So what you want to achive is to be able to analyze and optimize the AST, so that you won't have create unnecessary boilerplate? Sounds pretty reasonable but the biggest question is about optimization. We would really need to study and benchmark these solutions to be sure that it doesn't break anything and makes things faster, not slower. Another thing is that this optimization could be optional. I think it's a good idea to better analyze what we will produce and what shortcuts can we make, but I think some mvp is needed |
Beta Was this translation helpful? Give feedback.
-
Preface
Hi all, it seems that as we add new features, a need arises to create a separate pass for manipulating translated Bash code. I encountered this problem recently when implementing the len built-in, which, if implemented efficiently, would require checking whether the translated expression is represented as a variable. The challenge is that checking the length in Bash involves using the ${#variable_name} syntax, which does not accept string literals for example - only variables. Without knowing if the expression in len is represented as a variable, we cannot efficiently implement this feature without creating additional temporary variables.
Proposition
Implementing another intermediate translation layer that will translate syntax module to a new translation module and then it to string just like we did before. This will come with a few improvements:
How will these translation modules look like?
This depends on the compiler’s needs. It’s not necessary to implement each shell feature as a separate module. There could be translation modules for variables, literals, arithmetic, etc., or a single module that represents some Bash. This is especially useful in contexts where precise syntax definition isn’t required. Built-in commands like echo are a good example, as they are self-sufficient statements that can likely be translated without a dedicated module. This also has a benefit of easier onboarding for new members. They don't have to learn all the translation modules to start contributing.
The architecture
The architecture that we have built so far looks as follows:
The proposition would modify the last block
Translate
by splitting it intoTranslate to AST
implemented on Syntax Modules andTranslate to String
which now will be implemented on the new Translation Modules.Summary
I believe that it's a step in a correct direction bringing us closer to making Amber output code that is more:
Beta Was this translation helpful? Give feedback.
All reactions