Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline functions redo #95

Merged
merged 15 commits into from
Apr 5, 2024

Conversation

hexaredecimal
Copy link
Contributor

I have followed your advice and implemented inline functions from the parser. I also added a function/method for creating hints. I had some time on my hands so I also decide to start working on the run command for qbe. I'm thinking of refactoring the code to a function to reduce the code size of the match expression.

@hexaredecimal hexaredecimal changed the title Inline functions Inline functions redo Mar 21, 2024
@garritfra garritfra mentioned this pull request Mar 21, 2024
4 tasks
Comment on lines 54 to 87
Target::Qbe => {
let dir_path = "./"; // TODO: Use this for changind build directory
let filename = in_file.file_stem().unwrap().to_str().unwrap();
let ssa_path = format!("{dir_path}{}.ssa", filename);
let asm_path = format!("{dir_path}{}.s", filename);
let exe_path = format!("{dir_path}{}.exe", filename);

let mut ssa_file = OpenOptions::new()
.read(true)
.write(true)
.create(true)
.open(&ssa_path).unwrap();
let buff = *buf;
ssa_file.write_all(&buff).unwrap();


// SSA to ASM
Command::new("qbe")
.arg(&ssa_path)
.arg("-o")
.arg(&asm_path)
.spawn().unwrap();

// ASM to EXE
Command::new("gcc")
.arg(&asm_path)
.arg("-o")
.arg(&exe_path)
.spawn().unwrap();

// Run the EXE
Command::new(exe_path)
.spawn().unwrap();
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in a different PR as it's not a requirement for the shorthand returns

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't mind the addition here. Saves time and trouble. ✌️

src/parser/parser.rs Outdated Show resolved Hide resolved
src/parser/rules.rs Outdated Show resolved Hide resolved
src/parser/rules.rs Show resolved Hide resolved
@garritfra
Copy link
Collaborator

I get an Error: Expected token when running this function:

fn main() {
    println(greet("World"))
}

fn greet(name: string) = "Hello " + name

Could you add some tests to the tests/ directory, and to the parser?

I created a parser test that I used to debug the error:

#[test]
fn test_parse_inline_function() {
    let raw = "
    fn main() = 1 
    ";
    let tokens = tokenize(raw).unwrap();
    let tree = parse(tokens, Some(raw.to_string()), "".into());
    assert!(tree.is_ok())
}

I didn't have enough time to investigate this further though. Trying again later.

@garritfra
Copy link
Collaborator

Okay, it seems like the error is an issue with how the parse_expression function peeks tokens. I added a test stub to investigate this later.

@garritfra
Copy link
Collaborator

I think this is ready to merge. Thanks @hexaredecimal for your work, I love this feature!

@garritfra garritfra merged commit eafd354 into antimony-lang:master Apr 5, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants