Skip to content

Commit 9010fce

Browse files
authored
Merge pull request #54 from Ph0enixKM/A75
A75 Create ability to get mangled names of variables and more
2 parents e7ec916 + 486f813 commit 9010fce

32 files changed

+623
-399
lines changed

build.ab

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
let macos_arm = 'aarch64-apple-darwin'
2-
let linux_arm = 'aarch64-unknown-linux-musl'
3-
let macos_x64 = 'x86_64-apple-darwin'
4-
let linux_x64 = 'x86_64-unknown-linux-musl'
1+
let targets = [
2+
'aarch64-apple-darwin',
3+
'aarch64-unknown-linux-musl',
4+
'x86_64-apple-darwin',
5+
'x86_64-unknown-linux-musl'
6+
]
57

6-
# Check if such directory exists
7-
$test -f "Cargo.toml" > /dev/null$
8+
// Check if such directory exists
9+
$test -f "Cargo.toml" > /dev/null$ failed {
10+
echo 'Please run this command in the project root directory'
11+
unsafe $exit 1$
12+
}
813

9-
if $echo \$?$ == '0' {
10-
$cargo build --release
11-
--target {macos_arm}
12-
--target {linux_arm}
13-
--target {macos_x64}
14-
--target {linux_x64}
15-
$
16-
# Move ambers to the release directory
17-
$mv target/aarch64-apple-darwin/release/amber target/release/amber_macos_aarch64$
18-
$mv target/aarch64-unknown-linux-musl/release/amber target/release/amber_linux_aarch64$
19-
$mv target/x86_64-apple-darwin/release/amber target/release/amber_macos_x86_64$
20-
$mv target/x86_64-unknown-linux-musl/release/amber target/release/amber_linux_x86_64$
21-
# Recompile installer scripts
22-
$cargo run -- setup/install.ab setup/install.sh$
23-
$cargo run -- setup/uninstall.ab setup/uninstall.sh$
24-
} else {
25-
$echo "Please run this command in the project root directory"$
26-
}
14+
unsafe {
15+
if status == 0 {
16+
let target_str = ''
17+
loop target in targets {
18+
target_str += '--target {target} '
19+
}
20+
$cargo build --release {target_str}$
21+
// Move ambers to the release directory
22+
$mv target/aarch64-apple-darwin/release/amber target/release/amber_macos_aarch64$
23+
$mv target/aarch64-unknown-linux-musl/release/amber target/release/amber_linux_aarch64$
24+
$mv target/x86_64-apple-darwin/release/amber target/release/amber_macos_x86_64$
25+
$mv target/x86_64-unknown-linux-musl/release/amber target/release/amber_linux_x86_64$
26+
// Recompile installer scripts
27+
$cargo run -- setup/install.ab setup/install.sh$
28+
$cargo run -- setup/uninstall.ab setup/uninstall.sh$
29+
} else {
30+
echo 'Please run this command in the project root directory'
31+
}
32+
}

setup/install.ab

Lines changed: 56 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,67 @@
11
let name = 'AmberNative'
22
let target = 'amber'
3-
let tag = 'v0.1.1-alpha'
3+
let tag = '0.2.0-alpha'
44
let place = '/opt/amber'
55

6-
# Determine OS type
7-
let os = $uname -s$ == 'Darwin'
8-
then 'macos'
9-
else 'linux'
6+
unsafe {
7+
// Determine OS type
8+
let os = $uname -s$ == 'Darwin'
9+
then 'macos'
10+
else 'linux'
1011

11-
# Determine architecture
12-
let arch = $uname -m$ == 'arm64'
13-
then 'aarch64'
14-
else 'x86_64'
12+
// Determine architecture
13+
let arch = $uname -m$ == 'arm64'
14+
then 'aarch64'
15+
else 'x86_64'
1516

16-
# Set the download link
17-
let url = 'https://github.com/Ph0enixKM/{name}/releases/download/{tag}/amber_{os}_{arch}'
17+
// Set the download link
18+
let url = 'https://github.com/Ph0enixKM/{name}/releases/download/{tag}/amber_{os}_{arch}'
1819

19-
# Check if such directory exists
20-
$test -d "{place}"$
20+
// Check if such directory exists
21+
$test -d "{place}"$
2122

22-
if $echo \$?$ == '0' {
23-
echo 'Amber already installed'
24-
echo 'It seems that Amber is already installed on your system. ({place})'
25-
echo 'If you want to reinstall Amber, uninstall it first.'
26-
echo '(Find out more at https://amber.marbl.cc)'
27-
$exit 0$
28-
}
23+
if $echo \$?$ == '0' {
24+
echo 'Amber already installed'
25+
echo 'It seems that Amber is already installed on your system. ({place})'
26+
echo 'If you want to reinstall Amber, uninstall it first.'
27+
echo '(Find out more at https://amber.marbl.cc)'
28+
$exit 0$
29+
}
2930

30-
echo 'Installing Amber'
31+
echo 'Installing Amber'
3132

32-
# Download Amber
33-
if {
34-
# Check if ruby is installed
35-
$ruby -v > /dev/null; echo \$?$ == '0' {
36-
let code = 'require "open-uri"; open("{target}", "wb") do |file|; file << open("{url}").read; end'
37-
echo 'Using ruby as a download method...'
38-
$ruby -e "{code}"$
39-
}
40-
# Check if curl is installed
41-
$curl -v > /dev/null; echo \$?$ == '0' {
42-
echo 'Using curl as a download method...'
43-
$curl -o "{target}" "{url}"$
44-
}
45-
# Check if wget is installed
46-
$wget -v > /dev/null; echo \$?$ == '0' {
47-
echo 'Using wget as a download method...'
48-
$wget -O "{target}" "{url}"$
49-
}
50-
else {
51-
echo 'Neither ruby, curl or wget are installed on your system.'
52-
echo 'Please install one of them and try again.'
53-
$exit 1$
33+
// Download Amber
34+
if {
35+
// Check if ruby is installed
36+
$ruby -v > /dev/null; echo \$?$ == '0' {
37+
let code = 'require "open-uri"; open("{target}", "wb") do |file|; file << open("{url}").read; end'
38+
echo 'Using ruby as a download method...'
39+
$ruby -e "{code}"$
40+
}
41+
// Check if curl is installed
42+
$curl -v > /dev/null; echo \$?$ == '0' {
43+
echo 'Using curl as a download method...'
44+
$curl -o "{target}" "{url}"$
45+
}
46+
// Check if wget is installed
47+
$wget -v > /dev/null; echo \$?$ == '0' {
48+
echo 'Using wget as a download method...'
49+
$wget -O "{target}" "{url}"$
50+
}
51+
else {
52+
echo 'Neither ruby, curl or wget are installed on your system.'
53+
echo 'Please install one of them and try again.'
54+
$exit 1$
55+
}
5456
}
55-
}
56-
# Create directory for amber
57-
$sudo mkdir "{place}" > /dev/null$
58-
# Move zipped version of amber
59-
$sudo mv "{target}" "{place}/{target}"$
60-
# Give permissions to execute amber
61-
$sudo chmod +x "{place}/{target}"$
62-
# Create amber symbol link
63-
$sudo ln -s "{place}/{target}" "/usr/local/bin/{target}"$
64-
# Send success message
65-
echo 'Amber has been installed successfully. 🎉'
57+
// Create directory for amber
58+
$sudo mkdir "{place}" > /dev/null$
59+
// Move zipped version of amber
60+
$sudo mv "{target}" "{place}/{target}"$
61+
// Give permissions to execute amber
62+
$sudo chmod +x "{place}/{target}"$
63+
// Create amber symbol link
64+
$sudo ln -s "{place}/{target}" "/usr/local/bin/{target}"$
65+
// Send success message
66+
echo 'Amber has been installed successfully. 🎉'
67+
}

setup/install.sh

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,35 @@ __0_name="AmberNative";
22
__1_target="amber";
33
__2_tag="v0.1.1-alpha";
44
__3_place="/opt/amber";
5-
__4_os=$(if [ $([ "_$(uname -s)" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi);
6-
__5_arch=$(if [ $([ "_$(uname -m)" != "_arm64" ]; echo $?) != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
7-
__6_url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${__4_os}_${__5_arch}";
8-
test -d "${__3_place}" > /dev/null;
9-
if [ $([ "_$(echo $?)" != "_0" ]; echo $?) != 0 ]; then
10-
echo "Amber already installed";
11-
echo "It seems that Amber is already installed on your system. (${__3_place})";
12-
echo "If you want to reinstall Amber, uninstall it first.";
13-
echo "(Find out more at https://amber.marbl.cc)";
14-
exit 0
5+
os=$(if [ $([ "_$(uname -s)" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi);
6+
arch=$(if [ $([ "_$(uname -m)" != "_arm64" ]; echo $?) != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
7+
url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}";
8+
test -d "${__3_place}" > /dev/null 2>&1;
9+
if [ $([ "_$(echo $?)" != "_0" ]; echo $?) != 0 ]; then
10+
echo "Amber already installed";
11+
echo "It seems that Amber is already installed on your system. (${__3_place})";
12+
echo "If you want to reinstall Amber, uninstall it first.";
13+
echo "(Find out more at https://amber.marbl.cc)";
14+
exit 0 > /dev/null 2>&1
1515
fi;
16-
echo "Installing Amber";
17-
if [ $([ "_$(ruby -v > /dev/null; echo $?)" != "_0" ]; echo $?) != 0 ]; then
18-
__7_code="require \"open-uri\"; open(\"${__1_target}\", \"wb\") do |file|; file << open(\"${__6_url}\").read; end";
19-
echo "Using ruby as a download method...";
20-
ruby -e "${__7_code}"
16+
echo "Installing Amber";
17+
if [ $([ "_$(ruby -v > /dev/null; echo $?)" != "_0" ]; echo $?) != 0 ]; then
18+
code="require \"open-uri\"; open(\"${__1_target}\", \"wb\") do |file|; file << open(\"${url}\").read; end";
19+
echo "Using ruby as a download method...";
20+
ruby -e "${code}" > /dev/null 2>&1
2121
elif [ $([ "_$(curl -v > /dev/null; echo $?)" != "_0" ]; echo $?) != 0 ]; then
22-
echo "Using curl as a download method...";
23-
curl -o "${__1_target}" "${__6_url}"
22+
echo "Using curl as a download method...";
23+
curl -o "${__1_target}" "${url}" > /dev/null 2>&1
2424
elif [ $([ "_$(wget -v > /dev/null; echo $?)" != "_0" ]; echo $?) != 0 ]; then
25-
echo "Using wget as a download method...";
26-
wget -O "${__1_target}" "${__6_url}"
25+
echo "Using wget as a download method...";
26+
wget -O "${__1_target}" "${url}" > /dev/null 2>&1
2727
else
28-
echo "Neither ruby, curl or wget are installed on your system.";
29-
echo "Please install one of them and try again.";
30-
exit 1
28+
echo "Neither ruby, curl or wget are installed on your system.";
29+
echo "Please install one of them and try again.";
30+
exit 1 > /dev/null 2>&1
3131
fi;
32-
sudo mkdir ${__3_place} > /dev/null;
33-
sudo mv ${__1_target} ${__3_place}/${__1_target};
34-
sudo chmod +x ${__3_place}/${__1_target};
35-
sudo ln -s ${__3_place}/${__1_target} /usr/local/bin/${__1_target};
36-
echo "Amber has been installed successfully. 🎉"
32+
sudo mkdir "${__3_place}" > /dev/null > /dev/null 2>&1;
33+
sudo mv "${__1_target}" "${__3_place}/${__1_target}" > /dev/null 2>&1;
34+
sudo chmod +x "${__3_place}/${__1_target}" > /dev/null 2>&1;
35+
sudo ln -s "${__3_place}/${__1_target}" "/usr/local/bin/${__1_target}" > /dev/null 2>&1;
36+
echo "Amber has been installed successfully. 🎉"

setup/uninstall.ab

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
let place = '/opt/amber'
1+
unsafe {
2+
let place = '/opt/amber'
23

3-
$test -d "{place}" > /dev/null$
4+
$test -d "{place}" > /dev/null$
45

5-
if $echo \$?$ == '0' {
6-
$sudo rm -rf "{place}"$
7-
$sudo rm '/usr/local/bin/amber'$
8-
echo 'Uninstalled Amber successfully 🎉'
9-
}
10-
else {
11-
echo 'Amber is not installed'
6+
if $echo \$?$ == '0' {
7+
$sudo rm -rf "{place}"$
8+
$sudo rm '/usr/local/bin/amber'$
9+
echo 'Uninstalled Amber successfully 🎉'
10+
}
11+
else {
12+
echo 'Amber is not installed'
13+
}
1214
}

setup/uninstall.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
__0_place="/opt/amber";
2-
test -d "${__0_place}" > /dev/null;
3-
if [ $([ "_$(echo $?)" != "_0" ]; echo $?) != 0 ]; then
4-
sudo rm -rf "${__0_place}";
5-
sudo rm '/usr/local/bin/amber';
6-
echo "Uninstalled Amber successfully 🎉"
1+
place="/opt/amber";
2+
test -d "${place}" > /dev/null > /dev/null 2>&1;
3+
if [ $([ "_$(echo $?)" != "_0" ]; echo $?) != 0 ]; then
4+
sudo rm -rf "${place}" > /dev/null 2>&1;
5+
sudo rm '/usr/local/bin/amber' > /dev/null 2>&1;
6+
echo "Uninstalled Amber successfully 🎉"
77
else
8-
echo "Amber is not installed"
8+
echo "Amber is not installed"
99
fi

src/modules/builtin/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
pub mod echo;
2-
pub mod silent;
2+
pub mod nameof;

src/modules/builtin/nameof.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
use heraclitus_compiler::prelude::*;
2+
use crate::modules::variable::variable_name_extensions;
3+
use crate::translate::module::TranslateModule;
4+
use crate::utils::{ParserMetadata, TranslateMetadata};
5+
use crate::modules::types::{Type, Typed};
6+
7+
#[derive(Debug, Clone)]
8+
pub struct Nameof {
9+
name: String
10+
}
11+
12+
impl Typed for Nameof {
13+
fn get_type(&self) -> Type {
14+
Type::Text
15+
}
16+
}
17+
18+
impl SyntaxModule<ParserMetadata> for Nameof {
19+
syntax_name!("Nameof");
20+
21+
fn new() -> Self {
22+
Nameof {
23+
name: String::new()
24+
}
25+
}
26+
27+
fn parse(&mut self, meta: &mut ParserMetadata) -> SyntaxResult {
28+
token(meta, "nameof")?;
29+
let name = variable(meta, variable_name_extensions())?;
30+
match meta.get_var(&name) {
31+
Some(var_decl) => {
32+
self.name = var_decl.name.clone();
33+
if let Some(id) = var_decl.global_id {
34+
self.name = format!("__{id}_{}", self.name);
35+
}
36+
Ok(())
37+
},
38+
None => {
39+
let tok = meta.get_current_token();
40+
error!(meta, tok, format!("Variable '{name}' not found"))
41+
}
42+
}
43+
}
44+
}
45+
46+
impl TranslateModule for Nameof {
47+
fn translate(&self, meta: &mut TranslateMetadata) -> String {
48+
let quote = meta.gen_quote();
49+
let name = &self.name;
50+
format!("{quote}{name}{quote}")
51+
}
52+
}

src/modules/builtin/silent.rs

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)