labast v1.0.4
* Исправлен баг c "quit" * Исправлены "band", "bnand", "bor", "bxor" (спасибо Владу) * Переписан "args" (это вообще не надо было как оказывается, но зато код стал более читабельным) * Исправлен баг с парсером
This commit is contained in:
parent
4fb06f8f34
commit
0eb3af2c47
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -10,7 +10,7 @@ checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5"
|
||||
|
||||
[[package]]
|
||||
name = "labast"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"pico-args",
|
||||
|
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "labast"
|
||||
version = "1.0.3"
|
||||
version = "1.0.4"
|
||||
authors = [ "n3tael" ]
|
||||
edition = "2021"
|
||||
description = "A zero-dependencies Labaski interpreter written in Rust."
|
||||
|
@ -2,4 +2,7 @@
|
||||
A Labaski interpreter written in Rust. Fully supports Labashki specs 1.12.
|
||||
|
||||
## Examples
|
||||
See `scripts` directory.
|
||||
See `scripts` directory.
|
||||
|
||||
## Syntax highlighting
|
||||
* Notepad++: `syntax-highlighting/notepad++.xml` ([how to install](https://stackoverflow.com/questions/4913834/how-do-you-add-syntax-highlighting-for-less-in-notepad))
|
1
scripts/esolangs-program-forms/hello-world.lb
Normal file
1
scripts/esolangs-program-forms/hello-world.lb
Normal file
@ -0,0 +1 @@
|
||||
$println Hello, world!
|
@ -0,0 +1,4 @@
|
||||
; https://esolangs.org/wiki/User:XKCD_Random_Number
|
||||
|
||||
push 4
|
||||
meow
|
12
scripts/esolangs-program-forms/truth-machine.lb
Normal file
12
scripts/esolangs-program-forms/truth-machine.lb
Normal file
@ -0,0 +1,12 @@
|
||||
; Truth-machine on Labashki
|
||||
|
||||
@ 0
|
||||
scan
|
||||
kjnz 1
|
||||
meow
|
||||
quit
|
||||
|
||||
@ 1
|
||||
push 1
|
||||
meow
|
||||
jmp 1
|
16
scripts/std/print.lb
Normal file
16
scripts/std/print.lb
Normal file
@ -0,0 +1,16 @@
|
||||
;
|
||||
; BSD Zero Clause License
|
||||
;
|
||||
; Copyright (C) 2024 by Bedohswe
|
||||
;
|
||||
; Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
|
||||
;
|
||||
; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
@ 0
|
||||
args 1
|
||||
kjz 1
|
||||
putc
|
||||
jmp 0
|
||||
@ 1
|
||||
quit
|
@ -1,2 +0,0 @@
|
||||
size
|
||||
#exec std\unix\ВАРЁНЫЙНОСОК.lb
|
@ -1,5 +1,3 @@
|
||||
use std::io::Read;
|
||||
|
||||
use crate::{errors::RunError, instructions, stack::{Instruction, Stack}};
|
||||
|
||||
fn find_labels(stack: &mut Stack) {
|
||||
@ -133,7 +131,7 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
|
||||
"maxsize" => instructions::maxsize::maxsize(&mut stack.memory),
|
||||
"#expr" => instructions::expr::expr(&mut stack.memory, &instruction.arg),
|
||||
"nop" => continue,
|
||||
"quit" => std::process::exit(0),
|
||||
"quit" => break,
|
||||
"exit" => instructions::exit::exit(&instruction.data),
|
||||
|
||||
// Platform-specific
|
||||
@ -148,7 +146,5 @@ pub fn execute(stack: &mut Stack, mut origin_stack: Option<&mut Stack>, mod_name
|
||||
std::process::exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
std::io::stdin().bytes();
|
||||
}
|
||||
}
|
@ -1,21 +1,18 @@
|
||||
use crate::{errors::RunError, stack::Stack};
|
||||
|
||||
pub fn args(memory: &mut Vec<u16>, origin_stack: &mut Option<&mut Stack>, data: &u16) {
|
||||
let origin_memory = &mut origin_stack.as_mut().expect(&format!("{}", RunError::RequestArgsInMainModule)).memory;
|
||||
if let Some(origin_stack) = origin_stack.as_mut() {
|
||||
let mut data = *data;
|
||||
|
||||
if *origin_memory == *memory {
|
||||
if data == 0 {
|
||||
data = origin_stack.memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
}
|
||||
|
||||
for _ in 0..data {
|
||||
memory.push(origin_stack.memory.pop().expect(&format!("{}", RunError::MemoryEmpty)));
|
||||
}
|
||||
} else {
|
||||
eprintln!("{}", RunError::RequestArgsInMainModule);
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
let quanity: u16;
|
||||
if *data == 0 {
|
||||
quanity = origin_memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
} else {
|
||||
quanity = *data;
|
||||
}
|
||||
|
||||
for _ in 0..quanity {
|
||||
memory.push(origin_memory.pop().expect(&format!("{}", RunError::MemoryEmpty)));
|
||||
}
|
||||
}
|
@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn band(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if a & b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(a & b);
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn bnand(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if !(a & b) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(!(a & b));
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn bor(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if a | b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(a | b);
|
||||
}
|
||||
|
@ -1,14 +1,8 @@
|
||||
use crate::errors::RunError;
|
||||
|
||||
pub fn bxor(memory: &mut Vec<u16>) {
|
||||
let a: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let b: bool = memory.pop().expect(&format!("{}", RunError::MemoryEmpty)) == 1;
|
||||
let a: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
let b: u16 = memory.pop().expect(&format!("{}", RunError::MemoryEmpty));
|
||||
|
||||
let c: u16 = if a ^ b {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
|
||||
memory.push(c);
|
||||
}
|
||||
memory.push(a ^ b);
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ pub fn exec(mut stack: &mut Stack, arg: &String, mod_name: &String) {
|
||||
let mut temp_stack = Stack::new();
|
||||
|
||||
parse(&mut temp_stack, &lines);
|
||||
|
||||
execute(&mut temp_stack, Some(&mut stack), &arg.clone());
|
||||
|
||||
for item in temp_stack.memory {
|
||||
|
@ -14,8 +14,8 @@ pub fn parse(stack: &mut Stack, file_content: &str) {
|
||||
}
|
||||
|
||||
let command: [String; 2] = inst_line.split_once(char::is_whitespace)
|
||||
.map_or_else(|| [inst_line.to_string(), "".to_string()],
|
||||
|(first, second)| [first.to_string(), second.to_string()]);
|
||||
.map_or_else(|| [inst_line.trim().to_string(), "".to_string()],
|
||||
|(first, second)| [first.trim().to_string(), second.trim().to_string()]);
|
||||
|
||||
let name: String;
|
||||
let mut arg: String = String::new();
|
||||
|
Loading…
Reference in New Issue
Block a user