Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
Co-authored-by: TheHackerChampion <TheHackerChampion@users.noreply.gi…
Browse files Browse the repository at this point in the history
…thub.com>
  • Loading branch information
Thepigcat76 committed Dec 18, 2023
1 parent 4848417 commit 3af0e94
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
1 change: 0 additions & 1 deletion src/builtin/builtins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ impl BuiltinFunction {
}

pub fn read_input(func: &object::BuiltInFunction) -> String {
Self::print_val(func);
input()
}
}
28 changes: 22 additions & 6 deletions src/evaluator/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,10 @@ impl Evaluator {
let mut block: Object = Object::None(NoneLit);

for case in cases {
if case._type != CaseType::ELSE && self.eval_expression(compare_value) == self.eval_expression(case.case_condition.as_ref().unwrap()) {
if case._type != CaseType::ELSE
&& self.eval_expression(compare_value)
== self.eval_expression(case.case_condition.as_ref().unwrap())
{
block = self.eval_block_statement(&case.case_consequence);
}
}
Expand All @@ -428,6 +431,7 @@ impl Evaluator {
}

fn eval_loop_expression(&mut self, node: &LoopExpression) -> Object {
let mut for_val = (&String::new(), 0.0);
let condition = match node.loop_type {
LoopType::WHILE => self.eval_expression(&*node.condition),
LoopType::FOR => {
Expand All @@ -441,6 +445,12 @@ impl Evaluator {
};
let right = self.eval_expression(&range.right);

self.env
.set(&left.value, &Object::Num(Num::new(0.0)), true, false);

for_val.0 = &left.value;
for_val.1 = 0.0;

match right {
// FIXME: Replace as conversion with null save conversion
Object::Range(range) => {
Expand All @@ -452,11 +462,14 @@ impl Evaluator {
Object::Num(num) => num.value as i32,
_ => todo!(),
};

for _ in left_val..right_val {
self.env
.modify(&for_val.0, Object::Num(Num::new(for_val.1)));
self.eval_block_statement(&node.consequence);
for_val.1 += 1.0;
}

return self.eval_block_statement(&node.consequence);
}
Object::List(list) => todo!(),
Expand Down Expand Up @@ -523,6 +536,7 @@ impl Evaluator {
let func = BuiltInFunction {
func: builtins::BuiltinFunction::PRINT,
args,
ret_val: None,
};
builtins::BuiltinFunction::print_val(&func);
Object::BuiltInFunction(func)
Expand All @@ -533,11 +547,13 @@ impl Evaluator {
let evaluated_arg = self.eval_expression(&arg);
args.push(evaluated_arg)
}
let func = BuiltInFunction {
let mut func = BuiltInFunction {
func: builtins::BuiltinFunction::PRINT,
args,
ret_val: None,
};
builtins::BuiltinFunction::read_input(&func);
let input = builtins::BuiltinFunction::read_input(&func);
func.ret_val = Some(Box::from(Object::Str(Str { value: input })));
Object::BuiltInFunction(func)
}
_ => {
Expand Down Expand Up @@ -667,4 +683,4 @@ impl Evaluator {
_ => right,
}
}
}
}
1 change: 1 addition & 0 deletions src/evaluator/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ pub struct UnmetExpr;
pub struct BuiltInFunction {
pub func: builtins::BuiltinFunction,
pub args: Vec<Object>,
pub ret_val: Option<Box<Object>>
}

#[derive(Debug, PartialEq, PartialOrd, Clone)]
Expand Down
3 changes: 3 additions & 0 deletions test/main.nx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var input = input()

print(input)
18 changes: 0 additions & 18 deletions test/test.nx

This file was deleted.

0 comments on commit 3af0e94

Please sign in to comment.