-
Notifications
You must be signed in to change notification settings - Fork 96
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
Builtin lines function part I - Refactoring #565
Builtin lines function part I - Refactoring #565
Conversation
let id = meta.gen_array_id(); | ||
meta.stmt_queue.push_back(format!("__AMBER_ARRAY_ADD_{id}=({left} {right})")); | ||
format!("{quote}${{__AMBER_ARRAY_ADD_{id}[@]}}{quote}") | ||
let name = format!("__AMBER_ARRAY_ADD_{id}"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to pass name
into a new TranslateModule
function in the next PR, so it makes sense to store it in a local variable here.
} | ||
} | ||
Type::Array(_) => { | ||
if self.is_ref { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I unrolled some of the code which was previously shared across expression types in this match
statement; this is necessary so we can append additional code to the Array
case in the next PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also make it slightly easier to implement @Ph0enixKM's proposed new translation layer.
let name = match self.global_id { | ||
Some(id) => format!("__{id}_{}", self.var), | ||
None => if self.is_ref { format!("${{{}}}", self.var) } else { self.var.clone() } | ||
let name = if let Some(id) = self.global_id { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to match the shorthand add operator.
match self.global_id { | ||
Some(id) => format!("__{id}_{name}={expr}"), | ||
None => format!("{local}{name}={expr}") | ||
if let Some(id) = self.global_id { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We previously tested self.global_id
after self.is_fun_ctx
, but I switched the order to match the shorthand operators. I think this is safe, because global_id
and is_fun_ctx
cannot both be enabled at the same time.
.map(|index| format!("[{}]", self.is_ref | ||
.then(|| index.translate_eval(meta, true)) | ||
.unwrap_or_else(|| index.translate(meta)))) | ||
.map(|index| self.translate_eval_if_ref(index, meta)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added helper function translate_eval_if_ref()
to remove duplicated code here. I would have moved this new function to the definition of TranslateModule
, but it only seems to be required here.
} | ||
if self.is_ref { | ||
if let Some(id) = self.global_id { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We previously tested self.global_id
after self.is_ref
, but I switched the order to match the shorthand operators. I think this is safe, because global_id
and is_ref
cannot both be enabled at the same time.
@hdwalters should I wait for this PR until I implement the TranslationModules? |
Please wait for this PR and the next one, which I have not submitted yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Refactor the
+=
shorthand add operator, by consolidating the variousself.is_ref
tests for text, array and numeric addition. This is necessary because in a subsequent PR, we will append functionality for array addition only, and this is not possible with the current implementation. Make corresponding changes to other shorthand operators, initialisation and setter statements.