Skip to content

Commit

Permalink
Thinking about how to format slices.
Browse files Browse the repository at this point in the history
It requires writing LLVM IR functions or functors in a way that is hard to do with my current llvm-sys generator.rs setup.
  • Loading branch information
SLiV9 committed Jan 14, 2024
1 parent ee654dc commit 6bdb82b
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions penne.todo
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ Documentation:
☐ Simplify wasm4 saving-data.md using cast

Development:
☐ Drop llvm-sys and generate LLVM BC and textual IR by hand
☐ Release 0.4.0
☐ Flesh out core and vendor/libc
☐ Add/check documentation for E359, E553
Expand Down
12 changes: 12 additions & 0 deletions src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2640,8 +2640,20 @@ fn format_slice(
}
else
{
// let n = ?
// for i in 0..n {
//
// }
// create format string that is n times %.*s
// for i in 0..n {
// TODO call the same llvm IR snippet for multiple Expressions
// TODO my Generator currently doesn't have a nice way to do that
// }
buffer.add_text("[");
// TODO print elements
// buffer.add_specifier("%.*s");
// buffer.insert(formatted_elements_len);
// buffer.insert(formatted_elements_ptr);
buffer.add_text("]");
Ok(())
}
Expand Down
10 changes: 10 additions & 0 deletions tests/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,16 @@ fn execute_builtin_format_array() -> Result<(), anyhow::Error>
Ok(())
}

#[test]
fn execute_builtin_format_slice() -> Result<(), anyhow::Error>
{
let output = execute("tests/samples/valid/builtin_format_slice.pn")?;
let stdout = stdout_from_output(output)?;
let expected = "[]\n[200]\n[12, 34]\n[1, 22, 333, 4444, 55555, -6]\n";
assert_eq!(stdout, expected);
Ok(())
}

#[test]
fn execute_builtin_format_struct() -> Result<(), anyhow::Error>
{
Expand Down
17 changes: 17 additions & 0 deletions tests/samples/valid/builtin_format_slice.pn
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

fn main() -> u8
{
var empty: []i32 = [];
var one: []i32 = [200];
var two: []i32 = [12, 34];
print_slice(empty);
print_slice(one);
print_slice(two);
print_slice([1, 22, 333, 4444, 55555, -6]);
return: 0
}

fn print_slice(data: []i32)
{
print!(data, "\n");
}

0 comments on commit 6bdb82b

Please sign in to comment.