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

Commit

Permalink
Added slicing, quit/exit functions, fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnabRollin committed Oct 30, 2023
1 parent 898df32 commit a2b5d01
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 58 deletions.
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.12.0] - 2023-10-30

### Added

- Slicing of arrays and strings (store in variable first).
- `quit` and `exit` functions to immediately terminate the program with an optional code.

### Changed

- `run_tokens` now returns a `Result` to provide a base for the upcoming feature of error handling.

### Fixed

- Fixed bug where commas in in strings were evaluated as seperators.
- Errors in lexer now print on the correct line.

## [0.11.0] - 2023-10-27

### Added
Expand Down Expand Up @@ -139,7 +155,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Simple function and string parsing

[unreleased]: https://github.com/ArnabRollin/dwn/compare/v0.11.0...HEAD
[unreleased]: https://github.com/ArnabRollin/dwn/compare/v0.12.0...HEAD

[0.12.0]: https://github.com/ArnabRollin/dwn/compare/v0.11.0...v0.12.0

[0.11.0]: https://github.com/ArnabRollin/dwn/compare/v0.10.0...v0.11.0

Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dwn"
version = "0.11.0"
version = "0.12.0"
edition = "2021"

[dependencies]
Expand Down
4 changes: 3 additions & 1 deletion src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ fn byterun_lvl1(mut reader: BufReader<File>) {
scope_token: &mut scope_token,
current_tokens: &mut current_tokens,
},
);
false,
)
.ok();
}
}

Expand Down
28 changes: 26 additions & 2 deletions src/dwn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ lazy_static! {
"format_array",
format_array as for<'a> fn(Vec<Token>, &'a mut Metadata) -> Result<Token, String>,
);

m.insert(
"quit",
quit as for<'a> fn(Vec<Token>, &'a mut Metadata) -> Result<Token, String>,
);
m.insert(
"exit",
quit as for<'a> fn(Vec<Token>, &'a mut Metadata) -> Result<Token, String>,
);
RwLock::new(m)
};
}
Expand Down Expand Up @@ -300,7 +307,7 @@ fn run_scope(token: &Token, meta: &mut Metadata) -> Token {
return ret;
}
_ => {
eprintln!("Error on line {}: Expected scope!", meta.line_count);
eprintln!("Error on line {}: Expected scope!", meta.line_count + 1);
exit(1);
}
}
Expand Down Expand Up @@ -1333,3 +1340,20 @@ fn format_array(tokens: Vec<Token>, meta: &mut Metadata) -> Result<Token, String
val: "None".to_string(),
})
}

fn quit(tokens: Vec<Token>, meta: &mut Metadata) -> Result<Token, String> {
let args = get_args(tokens, meta);

let code: i32 = if args.len() > 0 {
match args[0].val.parse() {
Ok(n) => n,
Err(_) => {
return Err("(quit / exit) Error code is not a number".to_string());
}
}
} else {
0
};

exit(code);
}
Loading

0 comments on commit a2b5d01

Please sign in to comment.