Skip to content

Commit

Permalink
0.9.517
Browse files Browse the repository at this point in the history
- More methods
  • Loading branch information
RobbyV2 committed Dec 16, 2024
1 parent 12a025d commit 4be0645
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[package]
name = "fplc"
version = "0.9.516"
version = "0.9.517"
edition = "2021"
description = "A pseudolang interpreter written in Rust"
repository = "https://github.com/PseudoLang-Software-Foundation/Pseudolang"
Expand Down
8 changes: 8 additions & 0 deletions Pseudolang.md
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,14 @@ Converts all characters in the string to uppercase.

Converts all characters in the string to lowercase.

`STARTSWITH(fullstring, substring)`

Returns TRUE if the fullstring starts with the given substring, FALSE otherwise.

`ENDSWITH(fullstring, substring)`

Returns TRUE if the fullstring ends with the given substring, FALSE otherwise.

## Data Types

`1`
Expand Down
4 changes: 2 additions & 2 deletions installer/pseudolang.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

!define MUI_ICON "Pseudolang-Logo.ico"

Name "PseudoLang Installer v0.9.516"
Name "PseudoLang Installer v0.9.517"
InstallDir "$PROGRAMFILES\PseudoLang\"
OutFile "../release/installer/pseudolang-setup-x64.exe"
BrandingText "(c) 2024 PseudoLang Software Foundation"
Expand Down Expand Up @@ -33,7 +33,7 @@ Section ""
WriteRegStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "Path" "$INSTDIR;$R0"

WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayName" "Pseudolang"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayVersion" "0.9.516"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayVersion" "0.9.517"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "Publisher" "Pseudolang Software Foundation"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayIcon" "$INSTDIR\Pseudolang-Logo.ico"

Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<div align="center">
<p>
<img src="https://github.com/PseudoLang-Software-Foundation/Pseudolang/actions/workflows/build.yml/badge.svg" alt="Build and Test Pseudolang">
<img src="https://img.shields.io/badge/Version-0.9.516-green" alt="Version">
<img src="https://img.shields.io/badge/Version-0.9.517-green" alt="Version">
<a href="https://nightly.link/PseudoLang-Software-Foundation/Pseudolang/workflows/build/main"><img src="https://img.shields.io/badge/Nightly-Releases-purple" alt="Nightly Releases"></a>
</p>
</div>
Expand Down
28 changes: 27 additions & 1 deletion src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Environment {
}
}

const MAX_STACK_DEPTH: usize = 1000;
const MAX_STACK_DEPTH: usize = 1000000;
static mut CURRENT_STACK_DEPTH: usize = 0;

pub fn run(ast: AstNode) -> Result<String, String> {
Expand Down Expand Up @@ -890,6 +890,32 @@ fn evaluate_node(
}
_ => Err("RANGE requires one or two arguments".to_string()),
},
"STARTSWITH" => {
if args.len() != 2 {
return Err("STARTSWITH requires two arguments".to_string());
}
let fullstring = evaluate_node(&args[0], Rc::clone(&env), debug)?;
let substring = evaluate_node(&args[1], Rc::clone(&env), debug)?;
match (fullstring, substring) {
(Value::String(s), Value::String(sub)) => {
Ok(Value::Boolean(s.starts_with(&sub)))
}
_ => Err("STARTSWITH requires two string arguments".to_string()),
}
}
"ENDSWITH" => {
if args.len() != 2 {
return Err("ENDSWITH requires two arguments".to_string());
}
let fullstring = evaluate_node(&args[0], Rc::clone(&env), debug)?;
let substring = evaluate_node(&args[1], Rc::clone(&env), debug)?;
match (fullstring, substring) {
(Value::String(s), Value::String(sub)) => {
Ok(Value::Boolean(s.ends_with(&sub)))
}
_ => Err("ENDSWITH requires two string arguments".to_string()),
}
}
_ => {
let procedure = env
.borrow()
Expand Down
52 changes: 48 additions & 4 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ mod test {

#[test]
fn test_return() {
assert_output(r#"
assert_output(
r#"
PROCEDURE test1(num) {
RETURN (num)
}
Expand All @@ -167,7 +168,9 @@ mod test {
DISPLAY(test2(6))
DISPLAY(test3())
DISPLAY(test4())
"#, "5\n6");
"#,
"5\n6",
);
}

#[test]
Expand Down Expand Up @@ -1007,13 +1010,13 @@ mod test {
}

#[test]
#[should_panic(expected = "List index out of bounds")]
#[should_panic(expected = "List index out of bounds: 4 (size: 3)")]
fn test_list_index_out_of_bounds_high() {
run_test("list <- [1, 2, 3]\nDISPLAY(list[4])").unwrap();
}

#[test]
#[should_panic(expected = "List index out of bounds")]
#[should_panic(expected = "List index out of bounds: index cannot be less than 1")]
fn test_list_index_out_of_bounds_low() {
run_test("list <- [1, 2, 3]\nDISPLAY(list[0])").unwrap();
}
Expand Down Expand Up @@ -2521,4 +2524,45 @@ DISPLAY(arr)"#,
assert!(run_test(r#"DISPLAY(EVAL("1 / 0"))"#).is_err());
assert!(run_test(r#"DISPLAY(EVAL("invalid"))"#).is_err());
}

#[test]
fn test_string_prefix_suffix() {
assert_output(
r#"
DISPLAY(STARTSWITH("Hello World", "Hello"))
DISPLAY(STARTSWITH("Hello World", "World"))
DISPLAY(STARTSWITH("", ""))
DISPLAY(STARTSWITH("Hello", "HelloWorld"))
DISPLAY(STARTSWITH("testing", "test"))
"#,
"true\nfalse\ntrue\nfalse\ntrue",
);

assert_output(
r#"
DISPLAY(ENDSWITH("Hello World", "World"))
DISPLAY(ENDSWITH("Hello World", "Hello"))
DISPLAY(ENDSWITH("", ""))
DISPLAY(ENDSWITH("World", "WorldLong"))
DISPLAY(ENDSWITH("testing", "ing"))
"#,
"true\nfalse\ntrue\nfalse\ntrue",
);

assert_output(
r#"
text <- "Hello World"
start <- "Hello"
end <- "World"
DISPLAY(STARTSWITH(text, start))
DISPLAY(ENDSWITH(text, end))
"#,
"true\ntrue",
);

assert!(run_test(r#"STARTSWITH(123, "abc")"#).is_err());
assert!(run_test(r#"STARTSWITH("abc", 123)"#).is_err());
assert!(run_test(r#"ENDSWITH(123, "abc")"#).is_err());
assert!(run_test(r#"ENDSWITH("abc", 123)"#).is_err());
}
}
2 changes: 1 addition & 1 deletion wapm.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

[package]
name = "pseudolang/fplc"
version = "0.9.516"
version = "0.9.517"
description = "A pseudolang interpreter written in Rust"
license = "MIT"
readme = "readme.md"
Expand Down

0 comments on commit 4be0645

Please sign in to comment.