Skip to content

Commit

Permalink
0.9.511
Browse files Browse the repository at this point in the history
- Main entry fixes
- Live terminal fixed
- Organization + QoL
- Continuity
- Rust update
  • Loading branch information
RobbyV2 committed Dec 6, 2024
1 parent c495117 commit ca08e88
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

[package]
name = "fplc"
version = "0.9.510"
version = "0.9.511"
edition = "2021"
description = "A pseudolang interpreter written in Rust"
repository = "https://github.com/PseudoLang-Software-Foundation/Pseudolang"
license = "MIT"

[lib]
crate-type = ["cdylib", "rlib", "staticlib"]
crate-type = ["cdylib", "rlib"]

[[bin]]
name = "fplc"
path = "src/main.rs"

[package.metadata.wasm-pack]
profile.release.wasm-opt = ["-Oz"]
Expand Down Expand Up @@ -48,11 +52,11 @@ libc = "0.2"
wasm-bindgen = { version = "0.2", optional = true }
console_error_panic_hook = { version = "0.1", optional = true }
getrandom = { version = "0.2", features = ["js"] }
wasi = "0.11"
wasi = { version = "0.11", optional = true }

[features]
default = ["native"]
native = ["chrono", "chrono-tz"]
wasm = []
wasi = []
wasm = ["wasm-bindgen", "console_error_panic_hook"]
wasi = ["dep:wasi"]
bindgen = ["wasm-bindgen", "console_error_panic_hook"]
4 changes: 2 additions & 2 deletions Pseudolang.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,9 @@ Boolean

A special value representing the absence of a value.

`NaN`
`NAN`

A special numeric value representing an undefined or unrepresentable value. Any arithmetic operation involving NaN results in NaN. Comparing NaN with any value (including another NaN) returns false, except for NaN NOT= NaN which returns true.
A special numeric value representing an undefined or unrepresentable value. Any arithmetic operation involving NAN results in NAN. Comparing NAN with any value (including another NAN) returns false, except for NAN NOT= NAN which returns true.

## Methods

Expand Down
23 changes: 16 additions & 7 deletions build_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ set -e

chmod +x build_release.sh

mkdir -p release/installer
mkdir -p release/wasi
mkdir -p release/wasm/raw
mkdir -p release/wasm/bindgen
mkdir -p release/installer release/wasi release/wasm/raw release/wasm/bindgen

echo "Building native targets..."

Expand All @@ -26,23 +23,35 @@ rustup target add wasm32-unknown-unknown

echo "Building raw WASM..."
cargo build --release --target wasm32-unknown-unknown --features wasm
cp target/wasm32-unknown-unknown/release/fplc.wasm release/wasm/raw/

echo "Building WASM with bindgen..."
if command -v wasm-pack >/dev/null 2>&1; then
wasm-pack build --target web --release -- --features "wasm bindgen"
cp pkg/* release/wasm/bindgen/
else
echo "wasm-pack not found, skipping bindgen WASM build"
fi

echo "Building WASI target..."
rustup target add wasm32-wasip1
cargo build --release --target wasm32-wasip1 --features wasi
cp target/wasm32-wasip1/release/fplc.wasm release/wasi/

echo "Building Windows installer..."
if command -v makensis >/dev/null 2>&1; then
cd installer
makensis pseudolang.nsi
cd ..
echo "Windows installer built successfully"
else
echo "makensis not found, skipping installer build"
echo "To build the installer, please install NSIS (Nullsoft Scriptable Install System)"
fi

echo "Copying binaries to release folder..."

cp target/wasm32-unknown-unknown/release/fplc.wasm release/wasm/raw/
cp pkg/* release/wasm/bindgen/
cp target/wasm32-wasip1/release/fplc.wasm release/wasi/

if [ -f "target/x86_64-pc-windows-gnu/release/fplc.exe" ]; then
cp target/x86_64-pc-windows-gnu/release/fplc.exe release/fplc-x64.exe
cp release/fplc-x64.exe installer/fplc.exe
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.510"
Name "PseudoLang Installer v0.9.511"
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.510"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Pseudolang" "DisplayVersion" "0.9.511"
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
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
<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.510-green" alt="Version">
<img src="https://img.shields.io/badge/Version-0.9.511-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>

Welcome to Pseudolang! Pseudolang is a simple programming language written in Rust, inspired by College Board's Pseudocode.

This project aims to fully support 64-bit Windows, Linux, and WebAssembly (WASI Package, Raw WASM).
This project aims to fully support 64-bit Windows, Linux, and WebAssembly (WASI Package, Raw WASM, WASM Bindgen).

## Releases

Expand Down
10 changes: 8 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::{interpreter, lexer::Lexer, parser};
use std::fmt::Write;

include!(concat!(env!("OUT_DIR"), "/version.rs"));

pub fn execute_code(input: &str, debug: bool, return_output: bool) -> Result<String, String> {
let mut lexer = Lexer::new(input);
let tokens = lexer.tokenize();
Expand All @@ -20,8 +22,8 @@ pub fn execute_code(input: &str, debug: bool, return_output: bool) -> Result<Str
}

let output = interpreter::run(ast)?;
if !return_output && !output.is_empty() {
print!("{}", output);
if !return_output {
// placeholder for now
}
Ok(output)
}
Expand Down Expand Up @@ -102,3 +104,7 @@ pub fn format_invalid_extension_error(file: &str) -> String {
USAGE_TIP
)
}

pub fn get_version() -> String {
VERSION.to_string()
}
54 changes: 41 additions & 13 deletions src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,39 +236,66 @@ fn evaluate_node(
}

AstNode::Display(expr) => {
let value = if let Some(expr) = expr {
if let Some(expr) = expr {
let result = evaluate_node(expr, Rc::clone(&env), debug)?;
let output = value_to_string(&result);
if !std::thread::current()
.name()
.map_or(false, |name| name.starts_with("test"))
{
print!("{}\n", output);
io::stdout().flush().unwrap();
}
env.borrow_mut().output.push_str(&output);
env.borrow_mut().output.push('\n');
result
Ok(result)
} else {
if !std::thread::current()
.name()
.map_or(false, |name| name.starts_with("test"))
{
println!();
}
env.borrow_mut().output.push('\n');
Value::Unit
};
Ok(value)
Ok(Value::Unit)
}
}

AstNode::DisplayInline(expr) => {
let value = evaluate_node(expr, Rc::clone(&env), debug)?;
let output = value_to_string(&value);
if !std::thread::current()
.name()
.map_or(false, |name| name.starts_with("test"))
{
print!("{}", output);
io::stdout().flush().unwrap();
}
env.borrow_mut().output.push_str(&output);
Ok(Value::Unit)
}

AstNode::Input(prompt) => {
let mut input_str = String::new();

if let Some(prompt_expr) = prompt {
let prompt_val = evaluate_node(prompt_expr, Rc::clone(&env), debug)?;
env.borrow_mut()
.output
.push_str(&value_to_string(&prompt_val));
let prompt_str = value_to_string(&prompt_val);
print!("{}", prompt_str);
io::stdout().flush().unwrap();
}
io::stdout().flush().map_err(|e| e.to_string())?;
let mut input = String::new();

io::stdin()
.read_line(&mut input)
.read_line(&mut input_str)
.map_err(|e| e.to_string())?;
Ok(Value::String(input.trim().to_string()))
let input = input_str.trim().to_string();

if prompt.is_none() {
env.borrow_mut().output.push_str(&input);
env.borrow_mut().output.push('\n');
}

Ok(Value::String(input))
}

AstNode::ProcedureDecl(name, params, body) => {
Expand All @@ -288,6 +315,7 @@ fn evaluate_node(
if args.len() != 1 {
return Err("SLEEP requires one argument".to_string());
}
io::stdout().flush().unwrap();
let seconds = evaluate_node(&args[0], Rc::clone(&env), debug)?;
match seconds {
Value::Integer(n) => {
Expand Down Expand Up @@ -1491,7 +1519,7 @@ fn value_to_string(value: &Value) -> String {
}
Value::Unit => "".to_string(),
Value::Null => "NULL".to_string(),
Value::NaN => "NaN".to_string(),
Value::NaN => "NAN".to_string(),
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ impl<'a> Lexer<'a> {

match identifier.as_str() {
"NULL" => Some(Token::Null),
"NaN" => Some(Token::NaN),
"NAN" => Some(Token::NaN),
"NOT" => {
if self.chars.peek() == Some(&'=') {
self.chars.next();
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<'a> Lexer<'a> {

match identifier.as_str() {
"NULL" => Some(Token::Null),
"NaN" => Some(Token::NaN),
"NAN" => Some(Token::NaN),
"MOD" => Some(Token::Modulo),
"DISPLAY" => {
while let Some(&c) = self.chars.peek() {
Expand Down
4 changes: 1 addition & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ pub mod lexer;
pub mod parser;
#[cfg(test)]
mod tests;
#[cfg(all(target_arch = "wasm32", feature = "wasi"))]
pub mod wasi;
#[cfg(all(target_arch = "wasm32", not(feature = "wasi")))]
#[cfg(target_arch = "wasm32")]
pub mod wasm;
23 changes: 12 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod core;
mod interpreter;
mod lexer;
mod parser;
#[cfg(target_arch = "wasm32")]
mod wasm;

use core::*;

Expand Down Expand Up @@ -106,8 +108,10 @@ fn run_program(input_file: &str, debug: bool) -> Result<(), String> {
file.read_to_string(&mut source_code)
.map_err(|e| format!("Error reading file {}: {}", input_file, e))?;

execute_code(&source_code, debug, false)?;
Ok(())
match execute_code(&source_code, debug, false) {
Ok(_) => Ok(()),
Err(e) => Err(e),
}
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -125,22 +129,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

if config.show_version {
println!("PseudoLang version {}", VERSION);
println!("PseudoLang version {}", get_version());
return Ok(());
}

if config.debug {
println!("\n=== Debug Mode Enabled ===\n");
}

let result = match config.command {
Command::Run => run_program(&config.input_file, config.debug),
Command::None => Ok(()),
};

if let Err(error) = result {
eprintln!("Error: {}", error);
std::process::exit(1);
if let Command::Run = config.command {
if let Err(error) = run_program(&config.input_file, config.debug) {
eprintln!("Error: {}", error);
std::process::exit(1);
}
}

Ok(())
Expand Down
Loading

0 comments on commit ca08e88

Please sign in to comment.