Skip to content

Commit

Permalink
feat: add lines function to std lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Ph0enixKM committed May 22, 2024
1 parent eedd681 commit d10f954
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 70 deletions.
82 changes: 41 additions & 41 deletions setup/install.sh
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
function has_failed__18_v0 {
function has_failed__19_v0 {
local command=$1
eval ${command} > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__AMBER_FUN_has_failed18_v0=$(echo $__AMBER_STATUS '!=' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
__AMBER_FUN_has_failed19_v0=$(echo $__AMBER_STATUS '!=' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
};
function exit__19_v0 {
function exit__20_v0 {
local code=$1
exit "${code}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi
};
function includes__20_v0 {
function includes__21_v0 {
local arr=("${!1}")
local value=$2
[[ "${arr[@]}" =~ "${value}" ]]
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__AMBER_FUN_includes20_v0=$(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
__AMBER_FUN_includes21_v0=$(echo $__AMBER_STATUS '==' 0 | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//');
return 0
}
__0_name="AmberNative";
__1_target="amber";
__2_tag="0.3.1-alpha";
__3_place="/opt/amber";
has_failed__18_v0 "uname -a";
__AMBER_FUN_has_failed18_v0__7=${__AMBER_FUN_has_failed18_v0};
has_failed__19_v0 "uname -a";
__AMBER_FUN_has_failed19_v0__7=${__AMBER_FUN_has_failed19_v0};
__AMBER_VAL_0=$(uname -a);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
:
fi;
__4_agent=$(if [ ${__AMBER_FUN_has_failed18_v0__7} != 0 ]; then echo "unknown"; else echo "${__AMBER_VAL_0}"; fi);
__4_agent=$(if [ ${__AMBER_FUN_has_failed19_v0__7} != 0 ]; then echo "unknown"; else echo "${__AMBER_VAL_0}"; fi);
echo "";

__AMBER_VAL_1=$(uname -s);
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to determine OS type.";
echo "Please try again or use another download method.";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__18=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__18} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__18=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__18} > /dev/null 2>&1
fi;
os_type="${__AMBER_VAL_1}";
os=$(if [ $([ "_${os_type}" != "_Darwin" ]; echo $?) != 0 ]; then echo "macos"; else echo "linux"; fi);
Expand All @@ -57,15 +57,15 @@ fi;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to determine architecture.";
echo "Please try again or use another download method.";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__28=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__28} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__28=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__28} > /dev/null 2>&1
fi;
arch_type="${__AMBER_VAL_2}";
__AMBER_ARRAY_0=("arm64" "aarch64");
includes__20_v0 __AMBER_ARRAY_0[@] "${arch_type}";
__AMBER_FUN_includes20_v0__30=${__AMBER_FUN_includes20_v0};
arch=$(if [ ${__AMBER_FUN_includes20_v0__30} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
includes__21_v0 __AMBER_ARRAY_0[@] "${arch_type}";
__AMBER_FUN_includes21_v0__30=${__AMBER_FUN_includes21_v0};
arch=$(if [ ${__AMBER_FUN_includes21_v0__30} != 0 ]; then echo "aarch64"; else echo "x86_64"; fi);
url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}";
test -d "${__3_place}"
__AMBER_STATUS=$?;
Expand All @@ -77,64 +77,64 @@ fi;
echo "It seems that Amber is already installed on your system. (${__3_place})";
echo "If you want to reinstall Amber, uninstall it first.";
echo "(Find out more at https://docs.amber-lang.com/getting_started/installation#uninstallation)";
exit__19_v0 2;
__AMBER_FUN_exit19_v0__45=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__45} > /dev/null 2>&1
exit__20_v0 2;
__AMBER_FUN_exit20_v0__45=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__45} > /dev/null 2>&1
fi;
has_failed__18_v0 "curl -V";
__AMBER_FUN_has_failed18_v0__49=${__AMBER_FUN_has_failed18_v0};
if [ ${__AMBER_FUN_has_failed18_v0__49} != 0 ]; then
has_failed__19_v0 "curl -V";
__AMBER_FUN_has_failed19_v0__49=${__AMBER_FUN_has_failed19_v0};
if [ ${__AMBER_FUN_has_failed19_v0__49} != 0 ]; then
echo "Curl is not installed on your system.";
echo "Please install \`curl\` and try again.";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__52=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__52} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__52=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__52} > /dev/null 2>&1
fi;
echo "Installing Amber... 🚀";
curl -L -o "${__1_target}" "${url}" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Curl failed to download amber.";
echo "Something went wrong. Please try again later.";
exit__19_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit19_v0__61=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__61} > /dev/null 2>&1
exit__20_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit20_v0__61=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__61} > /dev/null 2>&1
fi;
sudo mkdir "${__3_place}" > /dev/null 2>&1
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to create directory for amber.";
echo "Please make sure that root user can access /opt directory.";
exit__19_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit19_v0__68=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__68} > /dev/null 2>&1
exit__20_v0 1 > /dev/null 2>&1;
__AMBER_FUN_exit20_v0__68=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__68} > /dev/null 2>&1
fi;
sudo mv "${__1_target}" "${__3_place}/${__1_target}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to move amber to the installation directory.";
echo "Please make sure that root user can access /opt directory.";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__74=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__74} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__74=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__74} > /dev/null 2>&1
fi;
sudo chmod +x "${__3_place}/${__1_target}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to give permissions to execute amber.";
echo "Please make sure that root user can access /opt directory.";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__80=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__80} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__80=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__80} > /dev/null 2>&1
fi;
sudo ln -s "${__3_place}/${__1_target}" "/usr/local/bin/${__1_target}"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to create amber symbol link.";
echo "Please make sure that root user can access /usr/local/bin directory.";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__86=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__86} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__86=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__86} > /dev/null 2>&1
fi;
curl -G --data-urlencode "agent=${__4_agent}" --data-urlencode "name=download" "https://amber-lang.com/api/visit" > /dev/null 2>&1
__AMBER_STATUS=$?;
Expand Down
14 changes: 7 additions & 7 deletions setup/uninstall.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function exit__19_v0 {
function exit__20_v0 {
local code=$1
exit "${code}"
__AMBER_STATUS=$?;
Expand All @@ -20,18 +20,18 @@ __AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to remove Amber from ${__0_place}";
echo "Make sure root has the correct permissions to access this directory";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__14=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__14} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__14=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__14} > /dev/null 2>&1
fi;
sudo rm "/usr/local/bin/amber"
__AMBER_STATUS=$?;
if [ $__AMBER_STATUS != 0 ]; then
echo "Failed to remove Amber from /usr/local/bin";
echo "Make sure root has the correct permissions to access this directory";
exit__19_v0 1;
__AMBER_FUN_exit19_v0__19=${__AMBER_FUN_exit19_v0};
echo ${__AMBER_FUN_exit19_v0__19} > /dev/null 2>&1
exit__20_v0 1;
__AMBER_FUN_exit20_v0__19=${__AMBER_FUN_exit20_v0};
echo ${__AMBER_FUN_exit20_v0__19} > /dev/null 2>&1
fi;
echo "Uninstalled Amber successfully 🎉"
else
Expand Down
3 changes: 0 additions & 3 deletions src/modules/function/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::utils::function_cache::FunctionInstance;
use crate::utils::function_interface::FunctionInterface;
use crate::utils::metadata::{ParserMetadata, TranslateMetadata};
use crate::translate::module::TranslateModule;
use crate::modules::block::Block;
use crate::modules::types::parse_type;

use super::declaration_utils::*;
Expand All @@ -22,7 +21,6 @@ pub struct FunctionDeclaration {
pub arg_names: Vec<String>,
pub arg_types: Vec<Type>,
pub returns: Type,
pub body: Block,
pub id: usize,
pub is_public: bool
}
Expand Down Expand Up @@ -59,7 +57,6 @@ impl SyntaxModule<ParserMetadata> for FunctionDeclaration {
arg_types: vec![],
arg_refs: vec![],
returns: Type::Generic,
body: Block::new(),
id: 0,
is_public: false
}
Expand Down
3 changes: 0 additions & 3 deletions src/modules/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ impl Display for Type {

pub trait Typed {
fn get_type(&self) -> Type;
fn has_echo(&self) -> bool {
false
}
}

// Tries to parse the type - if it fails, it fails loudly
Expand Down
9 changes: 8 additions & 1 deletion src/std/main.ab
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub fun input(): Text {
pub fun input(prompt: Text): Text {
unsafe $printf "\${nameof prompt}"$
unsafe $read$
return "$REPLY"
}
Expand Down Expand Up @@ -33,6 +34,12 @@ pub fun split(text: Text, delimiter: Text): [Text] {
return result
}

pub fun lines(text: Text): [Text] {
let result = [Text]
unsafe $IFS=\$'\n' read -rd '' -a {nameof result} <<<"\${nameof text}"$
return result
}

pub fun join(list: [Text], delimiter: Text): Text {
return unsafe $IFS="{delimiter}" ; echo "\$\{{nameof list}[*]}"$
}
Expand Down
36 changes: 21 additions & 15 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,12 @@ fn function_ref_swap() {
a = b
b = temp
}
let a = 12
let b = 24
swap(a, b)
echo a
echo b
";
Expand All @@ -517,7 +517,7 @@ fn function_ref_text_escaped() {
fun test(ref a) {
a = \"Hello World\"
}
let a = \"Goodbye World\"
test(a)
echo a
Expand Down Expand Up @@ -561,7 +561,7 @@ fn array_pass_by_copy() {
a[2] = 42
echo a[2]
}
let a = [1, 2, 3, 4, 5]
test(a)
echo a
Expand All @@ -576,7 +576,7 @@ fn array_pass_by_ref() {
a[2] = 42
echo a[1]
}
let a = [1, 2, 3, 4, 5]
test(a)
echo a
Expand Down Expand Up @@ -673,14 +673,14 @@ fn failed() {
let code = "
import { sum } from \"std\"
let requirements = [true, true, true]
main {
silent {
$make -v$ failed: requirements[0] = false
$gcc -v$ failed: requirements[1] = false
$you don\\'t have this$ failed: requirements[2] = false
}
if sum(requirements as [Num]) == 3 {
echo \"All requirements are met\"
} else {
Expand All @@ -699,17 +699,17 @@ fn nested_failed() {
echo \"inner_c\"
fail
}
fun inner_b() {
inner_c()?
echo \"inner_b\"
}
fun inner_a() {
inner_b()?
echo \"inner_a\"
}
main {
inner_a()?
echo \"main\"
Expand Down Expand Up @@ -752,6 +752,10 @@ fn test_std_library() {
echo chars(\"hello world\")
// Split a string into a list of strings by a delimiter
echo split(\"hello world\", \"l\")
// Split a multiline string to lines of string
loop line in lines(\"hello\nworld\") {
echo line
}
// Join a list of strings into a string
echo join(split(\"hello world\", \"l\"), \"l\")
// Transform string into a lowercase string
Expand Down Expand Up @@ -784,6 +788,8 @@ fn test_std_library() {
test_amber!(code, vec![
"h e l l o w o r l d",
"he o wor d",
"hello",
"world",
"hello world",
"hello world",
"HELLO WORLD",
Expand Down Expand Up @@ -841,7 +847,7 @@ fn chained_modifiers_functions() {
fun bar() {
echo \"this should not appear\"
}
unsafe foo(\"one\")
unsafe {
foo(\"two\")
Expand Down Expand Up @@ -1083,7 +1089,7 @@ fn variable_ref_command() {
fun foo(ref a) {
a = $echo Test$?
}
let a = \"\"
unsafe foo(a)
echo a
Expand All @@ -1097,11 +1103,11 @@ fn variable_ref_function_invocation() {
fun reverse(input: Text): Text {
return unsafe $echo {input} | rev$
}
fun foo(ref a) {
a = reverse(\"mars\")
}
let a = \"\"
unsafe foo(a)
echo a
Expand Down

0 comments on commit d10f954

Please sign in to comment.