Skip to content

Commit 9098b4e

Browse files
committed
print returns of funcs, or when u just give identifier, like python yk
1 parent 8130908 commit 9098b4e

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

lang/input.modu

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,2 @@
1-
import "os" as os
2-
3-
4-
fn fetch(url) {
5-
let req = "curl "+ url;
6-
let res = os.exec(req);
7-
print(res);
8-
return res;
9-
}
10-
11-
fn main() {
12-
let response = fetch("https://jsonplaceholder.typicode.com/todos/1");
13-
print(response);
14-
}
15-
16-
main();
1+
let a = 1+1
2+
a

lang/src/parser.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3041,10 +3041,6 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
30413041
} else {
30423042
ast.append(&mut temp_ast);
30433043
}
3044-
3045-
if verbose {
3046-
//dbg!(&ast);
3047-
}
30483044
}
30493045

30503046
if verbose {
@@ -3079,6 +3075,8 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
30793075
if result.is_err() {
30803076
return Err((result.err().unwrap(), line));
30813077
}
3078+
3079+
print_res(result.unwrap());
30823080
}
30833081

30843082
AST::PropertyCall { object, property, args, line } => {
@@ -3089,6 +3087,8 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
30893087
if result.is_err() {
30903088
return Err((result.err().unwrap(), line));
30913089
}
3090+
3091+
print_res(result.unwrap());
30923092
}
30933093

30943094
AST::Function { name, args, body, line } => {
@@ -3114,6 +3114,16 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
31143114
AST::Semicolon => {}
31153115
AST::Null => {}
31163116

3117+
AST::Identifer(name) => {
3118+
let result = eval(AST::Identifer(name), context);
3119+
3120+
if result.is_err() {
3121+
return Err((result.err().unwrap(), 1));
3122+
}
3123+
3124+
print_res(result.unwrap());
3125+
}
3126+
31173127
_ => {
31183128
if verbose {
31193129
println!("I'm not sure what to do with a {:?}", item);
@@ -3125,6 +3135,32 @@ pub fn parse(input: &str, context: &mut HashMap<String, AST>) -> Result<(), (Str
31253135
Ok(())
31263136
}
31273137

3138+
fn print_res(res: AST) {
3139+
match res {
3140+
AST::String(v) => {
3141+
println!("{}", v);
3142+
}
3143+
3144+
AST::Number(v) => {
3145+
println!("{}", v);
3146+
}
3147+
3148+
AST::Float(v) => {
3149+
println!("{}", v);
3150+
}
3151+
3152+
AST::Boolean(v) => {
3153+
println!("{}", v);
3154+
}
3155+
3156+
AST::Null => {
3157+
println!("null");
3158+
},
3159+
3160+
_ => {}
3161+
}
3162+
}
3163+
31283164
#[cfg(test)]
31293165
mod tests {
31303166
use super::*;

0 commit comments

Comments
 (0)