Skip to content

Commit 1d8d4ff

Browse files
author
Arthur Melton
committed
Merge remote-tracking branch 'origin/main'
2 parents 1c57e54 + a2f6aec commit 1d8d4ff

File tree

5 files changed

+215
-29
lines changed

5 files changed

+215
-29
lines changed

examples/Get File Extension.nys

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
log(last(split(last(arg()), ".")))

examples/Tic Tack Toe.nys

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
dec arr places: "1", "2", "3", "4", "5", "6", "7", "8", "9";
22
dec str who_first: "x";
3-
dec int player_pick: 0;
43
loop(9) {
54
log("
65
"places(0)" | "places(1)" | "places(2)"
@@ -10,7 +9,7 @@ loop(9) {
109
"places(6)" | "places(7)" | "places(8)"
1110
");
1211
log("Player "who_first" pick a space where you want to go")
13-
player_pick: input();
12+
dec int player_pick: input();
1413
if(places(player_pick-1) != "x" && places(player_pick-1) != "o") {
1514
places(player_pick-1): who_first;
1615
}

examples/test.nys

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
use audio;
2-
audio();
1+
func(count(number)) {
2+
dec int new_number: number+1;
3+
log(new_number);
4+
count(count(new_number));
5+
}
6+
count(0);

src/run.rs

Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -441,31 +441,38 @@ pub fn run(
441441
let mut types = false;
442442
let mut position = x + 1;
443443
let _square_brackets = 0;
444+
let mut exists = memory_names.len();
445+
446+
if memory_names.contains(&contents[position + 1]) {
447+
for item in 0..memory_names.len() {
448+
if memory_names[item] == contents[position + 1] {
449+
exists = item;
450+
}
451+
}
452+
}
444453

445454
// get type
446-
if contents[position] == "int" {
447-
memory_types.push(String::from("int"));
448-
memory_names.push(contents[position + 1].clone());
449-
position += 1;
450-
} else if contents[position] == "str" {
451-
memory_types.push(String::from("str"));
452-
memory_names.push(contents[position + 1].clone());
453-
position += 1;
454-
} else if contents[position] == "arr" {
455-
memory_types.push(String::from("arr"));
456-
memory_names.push(contents[position + 1].clone());
457-
position += 1;
458-
} else if contents[position] == "grp" {
459-
memory_types.push(String::from("grp"));
460-
memory_names.push(contents[position + 1].clone());
461-
position += 1;
462-
} else if contents[position] == "inf" {
463-
memory_types.push(String::from("inf"));
464-
memory_names.push(contents[position + 1].clone());
455+
if contents[position] == "int"
456+
|| contents[position] == "str"
457+
|| contents[position] == "arr"
458+
|| contents[position] == "grp"
459+
|| contents[position] == "inf"
460+
{
461+
if exists != memory_names.len() {
462+
memory_types[exists] = contents[position].to_string();
463+
memory_names[exists] = contents[position + 1].clone();
464+
} else {
465+
memory_types.push(contents[position].to_string());
466+
memory_names.push(contents[position + 1].clone());
467+
}
465468
position += 1;
466469
} else if contents[position] == "anon" {
467-
memory_types.push(String::from("anon"));
468470
types = true;
471+
if exists != memory_names.len() {
472+
memory_types[exists] = "anon".to_string();
473+
} else {
474+
memory_types.push(String::from("anon"));
475+
}
469476
}
470477

471478
//more vars
@@ -487,6 +494,10 @@ pub fn run(
487494
let mut pass_vec: Vec<String> = Vec::new();
488495
pass_vec.push("a".to_string());
489496
pass_vec.push("(".to_string());
497+
if contents[x + 1] == "int" {
498+
pass_vec.push("math".to_string());
499+
pass_vec.push("(".to_string());
500+
}
490501
loop {
491502
if contents[position] == "\n" || contents[position] == ";" {
492503
break;
@@ -537,23 +548,41 @@ pub fn run(
537548
}
538549
}
539550
name.push_str(&*group_memory[location]);
540-
memory_names.push(name.clone());
541-
memory_values.push(value_group[d].clone());
542-
memory_types.push("str".parse().unwrap());
551+
if exists != memory_names.len() {
552+
memory_names[exists] = name.clone();
553+
memory_values[exists] = value_group[d].clone();
554+
memory_types[exists] = "str".parse().unwrap();
555+
} else {
556+
memory_names.push(name.clone());
557+
memory_values.push(value_group[d].clone());
558+
memory_types.push("str".parse().unwrap());
559+
}
543560
}
544561
} else if memory_types[memory_types.len() - 1] == "int" {
545562
let number = meval::eval_str(value.clone().as_str());
546563
if number.is_ok() {
547-
memory_values.push(number.unwrap().to_string());
564+
if exists != memory_values.len() {
565+
memory_values[exists] = number.unwrap().to_string();
566+
} else {
567+
memory_values.push(number.unwrap().to_string());
568+
}
569+
} else if exists != memory_values.len() {
570+
memory_values[exists] = value.clone();
548571
} else {
549572
memory_values.push(value.clone());
550573
}
574+
} else if exists != memory_values.len() {
575+
memory_values[exists] = value.clone();
551576
} else {
552577
memory_values.push(value.clone());
553578
}
554579

555580
if types {
556-
memory_names.push(value.clone());
581+
if exists != memory_names.len() {
582+
memory_names[exists] = value.clone();
583+
} else {
584+
memory_names.push(value.clone());
585+
}
557586
}
558587
if dev {
559588
println!("memory_names: {:?}", memory_names);

src/run/functions.rs

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,86 @@ pub fn getstring(
291291
}
292292
}
293293
skips = leng;
294+
} else if vec[y] == "split" {
295+
imput_s.push_str(
296+
split(
297+
y,
298+
vec.to_vec(),
299+
memory_names.clone(),
300+
memory_values.clone(),
301+
memory_types.clone(),
302+
func_names.clone(),
303+
func_par.clone(),
304+
func_code.clone(),
305+
dev,
306+
uses.clone(),
307+
)
308+
.to_string()
309+
.as_str(),
310+
);
311+
let mut leng = 0;
312+
let mut n2 = 0;
313+
let mut skip1 = false;
314+
for elem in y + 1..vec.len() {
315+
if !skip1 {
316+
if vec[y + 1] != "(" {
317+
println!("You have to put a parentheses after a log");
318+
std::process::exit(1);
319+
}
320+
if contents[elem] == "(" {
321+
n2 += 1;
322+
} else if contents[elem] == ")" {
323+
n2 -= 1;
324+
}
325+
if n2 == 0 {
326+
skip1 = true;
327+
for _z in y + 1..elem + 1 {
328+
leng += 1;
329+
}
330+
}
331+
}
332+
}
333+
skips = leng;
334+
} else if vec[y] == "splitK" {
335+
imput_s.push_str(
336+
split_k(
337+
y,
338+
vec.to_vec(),
339+
memory_names.clone(),
340+
memory_values.clone(),
341+
memory_types.clone(),
342+
func_names.clone(),
343+
func_par.clone(),
344+
func_code.clone(),
345+
dev,
346+
uses.clone(),
347+
)
348+
.to_string()
349+
.as_str(),
350+
);
351+
let mut leng = 0;
352+
let mut n2 = 0;
353+
let mut skip1 = false;
354+
for elem in y + 1..vec.len() {
355+
if !skip1 {
356+
if vec[y + 1] != "(" {
357+
println!("You have to put a parentheses after a log");
358+
std::process::exit(1);
359+
}
360+
if contents[elem] == "(" {
361+
n2 += 1;
362+
} else if contents[elem] == ")" {
363+
n2 -= 1;
364+
}
365+
if n2 == 0 {
366+
skip1 = true;
367+
for _z in y + 1..elem + 1 {
368+
leng += 1;
369+
}
370+
}
371+
}
372+
}
373+
skips = leng;
294374
} else if vec[y] == "length" {
295375
imput_s.push_str(
296376
length(
@@ -1430,6 +1510,79 @@ pub fn round(
14301510
.round() as i32
14311511
}
14321512

1513+
pub fn split(
1514+
x: usize,
1515+
contents: Vec<String>,
1516+
memory_names: Vec<String>,
1517+
memory_values: Vec<String>,
1518+
memory_types: Vec<String>,
1519+
func_names: Vec<String>,
1520+
func_par: Vec<String>,
1521+
func_code: Vec<String>,
1522+
dev: bool,
1523+
uses: Vec<String>,
1524+
) -> String {
1525+
let mut items = getstring(
1526+
x,
1527+
contents,
1528+
memory_names,
1529+
memory_values,
1530+
memory_types,
1531+
func_names,
1532+
func_par,
1533+
func_code,
1534+
dev,
1535+
uses,
1536+
0,
1537+
);
1538+
let replacer: String = items.last().unwrap().to_string();
1539+
items.pop();
1540+
items
1541+
.join("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
1542+
.replace(&replacer, "zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
1543+
}
1544+
1545+
pub fn split_k(
1546+
x: usize,
1547+
contents: Vec<String>,
1548+
memory_names: Vec<String>,
1549+
memory_values: Vec<String>,
1550+
memory_types: Vec<String>,
1551+
func_names: Vec<String>,
1552+
func_par: Vec<String>,
1553+
func_code: Vec<String>,
1554+
dev: bool,
1555+
uses: Vec<String>,
1556+
) -> String {
1557+
let mut items = getstring(
1558+
x,
1559+
contents,
1560+
memory_names,
1561+
memory_values,
1562+
memory_types,
1563+
func_names,
1564+
func_par,
1565+
func_code,
1566+
dev,
1567+
uses,
1568+
0,
1569+
);
1570+
let replacer: String = items.last().unwrap().to_string();
1571+
items.pop();
1572+
let mut replaced: String = "zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v".to_string();
1573+
replaced.push_str(&*replacer);
1574+
replaced.push_str("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v");
1575+
items
1576+
.join("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
1577+
.replace(&replacer, &replaced)
1578+
1579+
.strip_prefix("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
1580+
.unwrap()
1581+
.strip_suffix("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
1582+
.unwrap()
1583+
.to_string()
1584+
}
1585+
14331586
pub fn length(
14341587
x: usize,
14351588
contents: Vec<String>,

0 commit comments

Comments
 (0)