mirror of
https://github.com/Dummi26/mers.git
synced 2025-12-16 12:07:50 +01:00
full rewrite, kinda works
This commit is contained in:
3
mers_old/tests/destructuring_assignment.mers
Executable file
3
mers_old/tests/destructuring_assignment.mers
Executable file
@@ -0,0 +1,3 @@
|
||||
[a, [b, c]] := [1, ["str", 12.5]]
|
||||
|
||||
a == 1 && b == "str" && c == 12.5
|
||||
3
mers_old/tests/force_output_type.mers
Executable file
3
mers_old/tests/force_output_type.mers
Executable file
@@ -0,0 +1,3 @@
|
||||
fn plus(a int, b int) -> int { a + b }
|
||||
|
||||
10.plus(20) == 30
|
||||
18
mers_old/tests/functions_double_definitions.mers
Executable file
18
mers_old/tests/functions_double_definitions.mers
Executable file
@@ -0,0 +1,18 @@
|
||||
type person [string int]
|
||||
fn name(p person/&person) p.0
|
||||
fn age(p person/&person) p.1
|
||||
|
||||
type village [[float float] string]
|
||||
fn name(v village/&village) v.1
|
||||
fn location(v village/&village) v.0
|
||||
fn x_coordinate(v village/&village) v.0.0
|
||||
fn y_coordinate(v village/&village) v.0.1
|
||||
|
||||
|
||||
|
||||
customer := ["Max M.", 43]
|
||||
home_town := [[12.3, 5.09], "Maxburg"]
|
||||
|
||||
customer.name() == "Max M."
|
||||
&& home_town.name() == "Maxburg"
|
||||
&& home_town.location() == [12.3, 5.09]
|
||||
10
mers_old/tests/get_ref.mers
Executable file
10
mers_old/tests/get_ref.mers
Executable file
@@ -0,0 +1,10 @@
|
||||
list := [1 2 3 4 5 6 7 8 9 ...]
|
||||
|
||||
// calling get on an &list will get a reference
|
||||
&list.get(2).assume1() = 24
|
||||
// calling get on a list will get a value
|
||||
should_not_be_changeable := list.get(3).assume1()
|
||||
&should_not_be_changeable = 24
|
||||
|
||||
list.get(2) == [24]
|
||||
&& list.get(3) != [24]
|
||||
36
mers_old/tests/lib_comms.rs
Executable file
36
mers_old/tests/lib_comms.rs
Executable file
@@ -0,0 +1,36 @@
|
||||
use std::io::Cursor;
|
||||
|
||||
use mers_libs::{prelude::*, GlobalScriptInfo};
|
||||
use mers_libs::{ByteData, ByteDataA};
|
||||
|
||||
#[test]
|
||||
fn list_type() {
|
||||
let a: Vec<i32> = vec![14, 26];
|
||||
let bytes = a.as_byte_data_vec();
|
||||
println!("{bytes:?}");
|
||||
assert_eq!(
|
||||
Vec::<i32>::from_byte_data(&mut Cursor::new(bytes)).unwrap(),
|
||||
a
|
||||
);
|
||||
|
||||
let a = VSingleType::List(VSingleType::Int.to()).to();
|
||||
assert!(
|
||||
VType::from_byte_data(&mut Cursor::new(a.as_byte_data_vec()))
|
||||
.unwrap()
|
||||
.eq(&a, &GlobalScriptInfo::default()),
|
||||
);
|
||||
|
||||
let a = VSingleType::Tuple(vec![
|
||||
VType {
|
||||
types: vec![VSingleType::Tuple(vec![]), VSingleType::Int],
|
||||
},
|
||||
VSingleType::String.to(),
|
||||
VSingleType::EnumVariant(12, VSingleType::Float.to()).to(),
|
||||
])
|
||||
.to();
|
||||
assert!(
|
||||
VType::from_byte_data(&mut Cursor::new(a.as_byte_data_vec()))
|
||||
.unwrap()
|
||||
.eq(&a, &GlobalScriptInfo::default())
|
||||
);
|
||||
}
|
||||
7
mers_old/tests/macro.mers
Executable file
7
mers_old/tests/macro.mers
Executable file
@@ -0,0 +1,7 @@
|
||||
val := !(mers {
|
||||
"macro returned value"
|
||||
})
|
||||
|
||||
val := !(mers "my_macro.mers")
|
||||
|
||||
true
|
||||
9
mers_old/tests/modify_variable.mers
Executable file
9
mers_old/tests/modify_variable.mers
Executable file
@@ -0,0 +1,9 @@
|
||||
// NOTE: Might change, but this is the current state of things
|
||||
x := 10
|
||||
t := thread(() {
|
||||
sleep(0.25)
|
||||
x
|
||||
})
|
||||
&x = 20 // -> 20 20 because it modifies the original variable x
|
||||
// x := 20 // -> 10 20 because it shadows the original variable x
|
||||
t.await() == x
|
||||
1
mers_old/tests/my_macro.mers
Executable file
1
mers_old/tests/my_macro.mers
Executable file
@@ -0,0 +1 @@
|
||||
true
|
||||
1
mers_old/tests/return_true.mers
Executable file
1
mers_old/tests/return_true.mers
Executable file
@@ -0,0 +1 @@
|
||||
true
|
||||
27
mers_old/tests/test_in_mers.rs
Executable file
27
mers_old/tests/test_in_mers.rs
Executable file
@@ -0,0 +1,27 @@
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use mers_libs::file::File;
|
||||
use mers_libs::{parse, VDataEnum};
|
||||
|
||||
#[test]
|
||||
fn run_all() {
|
||||
for file in fs::read_dir(Path::new(file!()).parent().unwrap())
|
||||
.unwrap()
|
||||
.filter_map(|v| v.ok())
|
||||
{
|
||||
if let Some(file_name) = file.file_name().to_str() {
|
||||
if file_name.ends_with(".mers") {
|
||||
eprintln!("Checking {}", file_name);
|
||||
let mut file = File::new(fs::read_to_string(file.path()).unwrap(), file.path());
|
||||
// has to return true, otherwise the test will fail
|
||||
assert!(
|
||||
matches!(
|
||||
parse::parse(&mut file).unwrap().run(vec![]).inner_cloned(),
|
||||
VDataEnum::Bool(true)
|
||||
),
|
||||
"{file_name} didn't return true!"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
38
mers_old/tests/thread_NOCHECK_ONLY_COMPILE.mers
Executable file
38
mers_old/tests/thread_NOCHECK_ONLY_COMPILE.mers
Executable file
@@ -0,0 +1,38 @@
|
||||
// this is true by default so the example doesn't finish too quickly or too slowly depending on your hardware.
|
||||
// you can set it to false and tweak the max value for a more authentic cpu-heavy workload.
|
||||
fake_delay := true
|
||||
|
||||
// this will be shared between the two threads to report the progress in percent (0-100%).
|
||||
progress := 0
|
||||
|
||||
// an anonymous function that sums all numbers from 0 to max.
|
||||
// it captures the progress variable and uses it to report its status to the main thread, which will periodically print the current progress.
|
||||
// once done, it returns a string with the sum of all numbers.
|
||||
calculator := (max int) {
|
||||
sum := 0
|
||||
for i max {
|
||||
i := i + 1
|
||||
// println("i: {0} s: {1}".format(i.to_string() sum.to_string()))
|
||||
&sum = sum + i
|
||||
// if fake_delay sleep(1)
|
||||
&progress = i * 100 / max
|
||||
}
|
||||
"the sum of all numbers from 0 to {0} is {1}!".format(max.to_string() sum.to_string())
|
||||
}
|
||||
|
||||
// start the thread. if fake_delay is true, calculate 1+2+3+4+5+6+7+8+9+10. if fake_delay is false, count up to some ridiculously large number.
|
||||
slow_calculation_thread := calculator.thread(if fake_delay 10 else 20000000)
|
||||
|
||||
// every second, print the progress. once it reaches 100%, stop
|
||||
loop {
|
||||
sleep(1)
|
||||
println("{0}%".format(progress.to_string()))
|
||||
progress == 100 // break from the loop
|
||||
}
|
||||
|
||||
// use await() to get the result from the thread. if the thread is still running, this will block until the thread finishes.
|
||||
result := slow_calculation_thread.await()
|
||||
|
||||
println("Thread finished, result: {0}".format(result))
|
||||
|
||||
true
|
||||
Reference in New Issue
Block a user