Skip to content

Commit 3073abd

Browse files
author
Arthur Melton
committed
go back one commit
1 parent 16ef882 commit 3073abd

File tree

3 files changed

+52
-47
lines changed

3 files changed

+52
-47
lines changed

examples/test.nys

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ func(count(number)) {
33
log(new_number);
44
count(count(new_number));
55
}
6-
count(0);
6+
count(0);

src/run.rs

Lines changed: 50 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -441,47 +441,37 @@ pub fn run(
441441
let mut types = false;
442442
let mut position = x + 1;
443443
let _square_brackets = 0;
444-
let mut infer = false;
445-
let mut find_int_str = false;
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+
}
446453

447454
// get type
448-
if contents[position] == "int" {
449-
memory_types.push(String::from("int"));
450-
memory_names.push(contents[position + 1].clone());
451-
position += 1;
452-
} else if contents[position] == "str" {
453-
memory_types.push(String::from("str"));
454-
memory_names.push(contents[position + 1].clone());
455-
position += 1;
456-
} else if contents[position] == "arr" {
457-
memory_types.push(String::from("arr"));
458-
memory_names.push(contents[position + 1].clone());
459-
position += 1;
460-
} else if contents[position] == "grp" {
461-
memory_types.push(String::from("grp"));
462-
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+
}
463468
position += 1;
464469
} else if contents[position] == "anon" {
465-
memory_types.push(String::from("anon"));
466470
types = true;
467-
} else {
468-
infer = true;
469-
}
470-
if infer == true {
471-
if contents[x + 3] == "[" {
472-
memory_types.push(String::from("arr"));
473-
memory_names.push(contents[position + 1].clone());
474-
position += 1;
475-
} else if contents[x + 3] == "\"" {
476-
memory_types.push(String::from("str"));
477-
memory_names.push(contents[position + 1].clone());
478-
position += 1;
479-
} else if contents[x + 3] == "{" {
480-
memory_types.push(String::from("grp"));
481-
memory_names.push(contents[position + 1].clone());
482-
position += 1;
471+
if exists != memory_names.len() {
472+
memory_types[exists] = "anon".to_string();
483473
} else {
484-
find_int_str = true
474+
memory_types.push(String::from("anon"));
485475
}
486476
}
487477

@@ -504,10 +494,9 @@ pub fn run(
504494
let mut pass_vec: Vec<String> = Vec::new();
505495
pass_vec.push("a".to_string());
506496
pass_vec.push("(".to_string());
507-
508-
if memory_types[memory_types.len() - 1] == "int" {
497+
if contents[x + 1] == "int" {
509498
pass_vec.push("math".to_string());
510-
pass_vec.push("(".to_string())
499+
pass_vec.push("(".to_string());
511500
}
512501
loop {
513502
if contents[position] == "\n" || contents[position] == ";" {
@@ -516,9 +505,6 @@ pub fn run(
516505
pass_vec.push(contents[position].clone().to_string());
517506
position += 1;
518507
}
519-
if memory_types[memory_types.len() - 1] == "int" {
520-
pass_vec.push(")".to_string());
521-
}
522508
pass_vec.push(")".to_string());
523509
let value = functions::getstring(
524510
0,
@@ -562,23 +548,41 @@ pub fn run(
562548
}
563549
}
564550
name.push_str(&*group_memory[location]);
565-
memory_names.push(name.clone());
566-
memory_values.push(value_group[d].clone());
567-
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+
}
568560
}
569561
} else if memory_types[memory_types.len() - 1] == "int" {
570562
let number = meval::eval_str(value.clone().as_str());
571563
if number.is_ok() {
572-
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();
573571
} else {
574572
memory_values.push(value.clone());
575573
}
574+
} else if exists != memory_values.len() {
575+
memory_values[exists] = value.clone();
576576
} else {
577577
memory_values.push(value.clone());
578578
}
579579

580580
if types {
581-
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+
}
582586
}
583587
if dev {
584588
println!("memory_names: {:?}", memory_names);

src/run/functions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,7 @@ pub fn split_k(
15751575
items
15761576
.join("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
15771577
.replace(&replacer, &replaced)
1578+
15781579
.strip_prefix("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")
15791580
.unwrap()
15801581
.strip_suffix("zzGVgfHaNtPMe7H9RRyx3rWC9JyyZdMkc2v")

0 commit comments

Comments
 (0)