Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
karshPrime authored May 24, 2024
2 parents 49884fe + dc42f9b commit 027e91f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 112 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ curl -s "https://raw.githubusercontent.com/Ph0enixKM/AmberNative/master/setup/in
#### Via a package manager
Amber is packaged in the following distros:

Arch (AUR) - `amber-bash`
Arch (AUR) - `amber-bash-bin`

### Windows support
As windows does not come with bash installed it makes no sense to support it. Please install WSL 2 on your windows machine and install Linux version of Amber compiler inside.
Expand Down
178 changes: 83 additions & 95 deletions setup/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,135 +1,123 @@
function exit__20_v0 {
function exit__21_v0 {
local code=$1
exit "${code}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi
};
function includes__21_v0 {
__AS=$?
}
function includes__22_v0 {
local arr=("${!1}")
local value=$2
[[ "${arr[@]}" =~ "${value}" ]]
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__AMBER_FUN_includes21_v0=$(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
__AS=$?
__AF_includes22_v0=$(echo $__AS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
}
function includes__21_v1 {
function includes__22_v1 {
local arr=$1
local value=$2
[[ "${arr[@]}" =~ "${value}" ]]
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__AMBER_FUN_includes21_v1=$(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
__AS=$?
__AF_includes22_v1=$(echo $__AS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
}
function get_arch__27_v0 {
function get_arch__28_v0 {
__AMBER_VAL_0=$(uname -m);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to determine architecture.";
echo "Please try again or use another download method.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__22=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__22} > /dev/null 2>&1
__AS=$?;
if [ $__AS != 0 ]; then
echo "Failed to determine architecture."
echo "Please try again or use another download method."
exit__21_v0 1;
__AF_exit21_v0__22=$__AF_exit21_v0;
echo $__AF_exit21_v0__22 > /dev/null 2>&1
fi;
local arch_type="${__AMBER_VAL_0}";
local arch_type="${__AMBER_VAL_0}"
__AMBER_ARRAY_0=("arm64" "aarch64");
includes__21_v0 __AMBER_ARRAY_0[@] "${arch_type}";
__AMBER_FUN_includes21_v0__25=${__AMBER_FUN_includes21_v0};
local arch=$(if [ ${__AMBER_FUN_includes21_v0__25} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
__AMBER_FUN_get_arch27_v0="${arch}";
includes__22_v0 __AMBER_ARRAY_0[@] "${arch_type}";
__AF_includes22_v0__25=$__AF_includes22_v0;
local arch=$(if [ $__AF_includes22_v0__25 != 0 ]; then echo "aarch64"; else echo "x86_64"; fi)
__AF_get_arch28_v0="${arch}";
return 0
};
function get_home__28_v0 {
}
function get_home__29_v0 {
__AMBER_VAL_1=$(echo $HOME);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "User installation requested, but unable to retrieve home directory from $HOME environment.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__35=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__35} > /dev/null 2>&1
__AS=$?;
if [ $__AS != 0 ]; then
echo "User installation requested, but unable to retrieve home directory from $HOME environment."
exit__21_v0 1;
__AF_exit21_v0__35=$__AF_exit21_v0;
echo $__AF_exit21_v0__35 > /dev/null 2>&1
fi;
local home="${__AMBER_VAL_1}";
local home="${__AMBER_VAL_1}"
if [ $([ "_${home}" != "_" ]; echo $?) != 0 ]; then
echo "User installation requested, but unable to find home directory.";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__39=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__39} > /dev/null 2>&1
fi;
__AMBER_FUN_get_home28_v0="${home}";
echo "User installation requested, but unable to find home directory."
exit__21_v0 1;
__AF_exit21_v0__39=$__AF_exit21_v0;
echo $__AF_exit21_v0__39 > /dev/null 2>&1
fi
__AF_get_home29_v0="${home}";
return 0
};
function get_bins_folder__29_v0 {
}
function get_bins_folder__30_v0 {
local user_only=$1
if [ ${user_only} != 0 ]; then
get_home__28_v0 ;
__AMBER_FUN_get_home28_v0__46=${__AMBER_FUN_get_home28_v0};
__AMBER_FUN_get_bins_folder29_v0="${__AMBER_FUN_get_home28_v0__46}/.local/bin";
get_home__29_v0 ;
__AF_get_home29_v0__46=$__AF_get_home29_v0;
__AF_get_bins_folder30_v0="$__AF_get_home29_v0__46/.local/bin";
return 0
else
__AMBER_FUN_get_bins_folder29_v0="/usr/local/bin";
__AF_get_bins_folder30_v0="/usr/local/bin";
return 0
fi
};
function get_place__30_v0 {
}
function get_place__31_v0 {
local user_only=$1
if [ ${user_only} != 0 ]; then
get_home__28_v0 ;
__AMBER_FUN_get_home28_v0__54=${__AMBER_FUN_get_home28_v0};
get_arch__27_v0 ;
__AMBER_FUN_get_arch27_v0__54=${__AMBER_FUN_get_arch27_v0};
__AMBER_FUN_get_place30_v0="${__AMBER_FUN_get_home28_v0__54}/.local/lib/${__AMBER_FUN_get_arch27_v0__54}/amber";
get_home__29_v0 ;
__AF_get_home29_v0__54=$__AF_get_home29_v0;
get_arch__28_v0 ;
__AF_get_arch28_v0__54=$__AF_get_arch28_v0;
__AF_get_place31_v0="$__AF_get_home29_v0__54/.local/lib/$__AF_get_arch28_v0__54/amber";
return 0
else
__AMBER_FUN_get_place30_v0="/opt/amber";
__AF_get_place31_v0="/opt/amber";
return 0
fi
}
echo "";
echo ""
args=$1
get_arch__27_v0 ;
__AMBER_FUN_get_arch27_v0__8=${__AMBER_FUN_get_arch27_v0};
arch=${__AMBER_FUN_get_arch27_v0__8};
includes__21_v1 "${args}" "--user";
__AMBER_FUN_includes21_v1__10=${__AMBER_FUN_includes21_v1};
user_only_install=${__AMBER_FUN_includes21_v1__10};
get_place__30_v0 ${user_only_install};
__AMBER_FUN_get_place30_v0__11=${__AMBER_FUN_get_place30_v0};
place=${__AMBER_FUN_get_place30_v0__11};
get_bins_folder__29_v0 ${user_only_install};
__AMBER_FUN_get_bins_folder29_v0__12=${__AMBER_FUN_get_bins_folder29_v0};
bins_folder=${__AMBER_FUN_get_bins_folder29_v0__12};
get_arch__28_v0 ;
__AF_get_arch28_v0__8=$__AF_get_arch28_v0;
arch=$__AF_get_arch28_v0__8
includes__22_v1 "${args}" "--user";
__AF_includes22_v1__10=$__AF_includes22_v1;
user_only_install=$__AF_includes22_v1__10
get_place__31_v0 ${user_only_install};
__AF_get_place31_v0__11=$__AF_get_place31_v0;
place=$__AF_get_place31_v0__11
get_bins_folder__30_v0 ${user_only_install};
__AF_get_bins_folder30_v0__12=$__AF_get_bins_folder30_v0;
bins_folder=$__AF_get_bins_folder30_v0__12
test -d "${place}" > /dev/null
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
if [ $(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
sudo=$(if [ ${user_only_install} != 0 ]; then echo ""; else echo "sudo"; fi);
__AS=$?
if [ $(echo $__AS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//') != 0 ]; then
sudo=$(if [ ${user_only_install} != 0 ]; then echo ""; else echo "sudo"; fi)
${sudo} rm -rf "${place}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to remove Amber from ${place}";
echo "Make sure root has the correct permissions to access this directory";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__21=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__21} > /dev/null 2>&1
fi;
__AS=$?;
if [ $__AS != 0 ]; then
echo "Failed to remove Amber from ${place}"
echo "Make sure root has the correct permissions to access this directory"
exit__21_v0 1;
__AF_exit21_v0__21=$__AF_exit21_v0;
echo $__AF_exit21_v0__21 > /dev/null 2>&1
fi
${sudo} rm "${bins_folder}/amber"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to remove Amber symlink from ${bins_folder}";
echo "Make sure root has the correct permissions to access this directory";
exit__20_v0 1;
__AMBER_FUN_exit20_v0__26=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__26} > /dev/null 2>&1
fi;
__AS=$?;
if [ $__AS != 0 ]; then
echo "Failed to remove Amber symlink from ${bins_folder}"
echo "Make sure root has the correct permissions to access this directory"
exit__21_v0 1;
__AF_exit21_v0__26=$__AF_exit21_v0;
echo $__AF_exit21_v0__26 > /dev/null 2>&1
fi
echo "Uninstalled Amber successfully 🎉"
else
echo "Amber is not installed"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TranslateModule for Block {
self.statements.iter()
.map(|statement| statement.translate(meta))
.filter(|translation| !translation.trim().is_empty())
.collect::<Vec<_>>().join(";\n")
.collect::<Vec<_>>().join("\n")
};
meta.decrease_indent();
// Restore the old statement queue
Expand Down
20 changes: 12 additions & 8 deletions src/modules/condition/failed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,30 @@ impl TranslateModule for Failed {
fn translate(&self, meta: &mut TranslateMetadata) -> String {
if self.is_parsed {
let block = self.block.translate(meta);
let ret = if self.is_main { "exit $__AMBER_STATUS" } else { "return $__AMBER_STATUS" };
let ret = if self.is_main { "exit $__AS" } else { "return $__AS" };
// the condition of '$?' clears the status code thus we need to store it in a variable
if self.is_question_mark {
// if the failed expression is in the main block we need to clear the return value
let clear_return = if !self.is_main {
let (name, id, variant) = meta.fun_name.clone().expect("Function name not set");
format!("__AMBER_FUN_{name}{id}_v{variant}=''")
format!("__AF_{name}{id}_v{variant}=''")
} else {
String::new()
};
["__AMBER_STATUS=$?;",
"if [ $__AMBER_STATUS != 0 ]; then",
["__AS=$?;",
"if [ $__AS != 0 ]; then",
&clear_return,
ret,
"fi"].join("\n")
} else {
["__AMBER_STATUS=$?;",
"if [ $__AMBER_STATUS != 0 ]; then",
&block,
"fi"].join("\n")
if &block == ":" {
"__AS=$?".into()
} else {
["__AS=$?;",
"if [ $__AS != 0 ]; then",
&block,
"fi"].join("\n")
}
}
} else {
String::new()
Expand Down
2 changes: 1 addition & 1 deletion src/modules/expression/literal/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ impl SyntaxModule<ParserMetadata> for Status {

impl TranslateModule for Status {
fn translate(&self, _meta: &mut TranslateMetadata) -> String {
"$__AMBER_STATUS".to_string()
"$__AS".to_string()
}
}
2 changes: 1 addition & 1 deletion src/modules/function/fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl TranslateModule for Fail {
} else {
// Clean the return value if the function fails
let (name, id, variant) = meta.fun_name.clone().expect("Function name not set");
meta.stmt_queue.push_back(format!("__AMBER_FUN_{name}{id}_v{variant}=''"));
meta.stmt_queue.push_back(format!("__AF_{name}{id}_v{variant}=''"));
format!("return {translate}")
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/modules/function/invocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl FunctionInvocation {
let quote = meta.gen_quote();
format!("{quote}{dollar}{{{name}[@]}}{quote}")
} else {
format!("{dollar}{{{name}}}")
format!("{dollar}{name}")
}
}
}
Expand All @@ -122,15 +122,15 @@ impl TranslateModule for FunctionInvocation {
}
}).collect::<Vec<String>>().join(" ");
meta.stmt_queue.push_back(format!("{name} {args}{silent}"));
let invocation_return = &format!("__AMBER_FUN_{}{}_v{}", self.name, self.id, self.variant_id);
let invocation_instance = &format!("__AMBER_FUN_{}{}_v{}__{}", self.name, self.id, self.variant_id, self.line);
let invocation_return = &format!("__AF_{}{}_v{}", self.name, self.id, self.variant_id);
let invocation_instance = &format!("__AF_{}{}_v{}__{}", self.name, self.id, self.variant_id, self.line);
let parsed_invocation_return = self.get_variable(meta, invocation_return, true);
if self.is_failable {
let failed = self.failed.translate(meta);
meta.stmt_queue.push_back(failed);
}
meta.stmt_queue.push_back(
format!("__AMBER_FUN_{}{}_v{}__{}={}", self.name, self.id, self.variant_id, self.line, if matches!(self.kind, Type::Array(_)) {
format!("__AF_{}{}_v{}__{}={}", self.name, self.id, self.variant_id, self.line, if matches!(self.kind, Type::Array(_)) {
// If the function returns an array we have to store the intermediate result in a variable that is of type array
format!("({})", parsed_invocation_return)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/function/ret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl TranslateModule for Return {
let result = matches!(self.expr.get_type(), Type::Array(_))
.then(|| format!("({result})"))
.unwrap_or(result);
meta.stmt_queue.push_back(format!("__AMBER_FUN_{name}{id}_v{variant}={result}"));
meta.stmt_queue.push_back(format!("__AF_{name}{id}_v{variant}={result}"));
"return 0".to_string()
}
}

0 comments on commit 027e91f

Please sign in to comment.