0.5.0 -- tuples and more optimizations #12
11
.github/copilot-instructions.md
vendored
11
.github/copilot-instructions.md
vendored
@@ -83,7 +83,7 @@ cargo test --package compiler --lib -- test::tuple_literals::test::test_tuple_li
|
|||||||
```bash
|
```bash
|
||||||
cd rust_compiler
|
cd rust_compiler
|
||||||
# Compile Slang code to IC10 using current compiler changes
|
# Compile Slang code to IC10 using current compiler changes
|
||||||
echo 'let x = 5;' | cargo run --bin slang -
|
echo 'let x = 5;' | cargo run --bin slang --
|
||||||
# Or from file
|
# Or from file
|
||||||
cargo run --bin slang -- input.slang -o output.ic10
|
cargo run --bin slang -- input.slang -o output.ic10
|
||||||
# Optimize the output with -z flag
|
# Optimize the output with -z flag
|
||||||
@@ -99,8 +99,13 @@ Tests follow a macro pattern in [libs/compiler/src/test/mod.rs](rust_compiler/li
|
|||||||
```rust
|
```rust
|
||||||
#[test]
|
#[test]
|
||||||
fn test_name() -> Result<()> {
|
fn test_name() -> Result<()> {
|
||||||
let output = compile!("slang code here");
|
let output = compile!(debug "slang code here");
|
||||||
assert_eq!(expected_ic10, output);
|
assert_eq!(
|
||||||
|
output,
|
||||||
|
indoc! {
|
||||||
|
"Expected IC10 output here"
|
||||||
|
}
|
||||||
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ macro_rules! output {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Represents both compilation errors and compiled output
|
||||||
|
pub struct CompilationCheckResult {
|
||||||
|
pub errors: Vec<crate::Error<'static>>,
|
||||||
|
pub output: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg_attr(test, macro_export)]
|
#[cfg_attr(test, macro_export)]
|
||||||
macro_rules! compile {
|
macro_rules! compile {
|
||||||
($source:expr) => {{
|
($source:expr) => {{
|
||||||
@@ -37,6 +43,21 @@ macro_rules! compile {
|
|||||||
res.instructions.write(&mut writer)?;
|
res.instructions.write(&mut writer)?;
|
||||||
output!(writer)
|
output!(writer)
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
(check $source:expr) => {{
|
||||||
|
let mut writer = std::io::BufWriter::new(Vec::new());
|
||||||
|
let compiler = crate::Compiler::new(
|
||||||
|
parser::Parser::new(tokenizer::Tokenizer::from($source)),
|
||||||
|
Some(crate::CompilerConfig { debug: true }),
|
||||||
|
);
|
||||||
|
let res = compiler.compile();
|
||||||
|
res.instructions.write(&mut writer)?;
|
||||||
|
let output = output!(writer);
|
||||||
|
crate::test::CompilationCheckResult {
|
||||||
|
errors: res.errors,
|
||||||
|
output,
|
||||||
|
}
|
||||||
|
}};
|
||||||
}
|
}
|
||||||
mod binary_expression;
|
mod binary_expression;
|
||||||
mod branching;
|
mod branching;
|
||||||
|
|||||||
Reference in New Issue
Block a user