Skip to content

Commit d3319aa

Browse files
authored
Stdver (#82)
2 parents 69fdd0c + 8e89e20 commit d3319aa

21 files changed

+385
-12073
lines changed

Cargo.lock

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ clap_complete_command = "0.6.1"
1313
clap_derive = "4.5.18"
1414
colored = "2.1.0"
1515
csscolorparser = "0.7.0"
16+
directories = "6.0.0"
1617
fxhash = "0.2.1"
1718
glob = "0.3.1"
1819
lalrpop-util = "0.22.0"
1920
log = "0.4.22"
2021
logos = "0.14.2"
2122
md-5 = "0.10.6"
2223
pretty_env_logger = "0.5.0"
24+
semver = "1.0.25"
2325
serde = { version = "1.0.210", features = ["derive"] }
2426
serde_json = "1.0.128"
2527
toml = "0.8.19"

src/ast/const_expr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use logos::Span;
22

3-
use crate::blocks::{BinOp, UnOp};
4-
53
use super::Value;
4+
use crate::blocks::{
5+
BinOp,
6+
UnOp,
7+
};
68

79
#[derive(Debug, Clone)]
810
pub enum ConstExpr {

src/ast/list.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use logos::Span;
22

3-
use super::{type_::Type, ConstExpr};
3+
use super::{
4+
type_::Type,
5+
ConstExpr,
6+
};
47
use crate::misc::SmolStr;
58

69
#[derive(Debug)]

src/ast/value.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
mod binop;
22
mod unop;
3-
use std::fmt::{self, Display};
3+
use std::fmt::{
4+
self,
5+
Display,
6+
};
47

58
use logos::Span;
69

7-
use super::{ConstExpr, Expr};
10+
use super::{
11+
ConstExpr,
12+
Expr,
13+
};
814
use crate::misc::SmolStr;
915

1016
#[derive(Debug, Clone)]

src/codegen/mutation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
use std::fmt::{self, Display};
1+
use std::fmt::{
2+
self,
3+
Display,
4+
};
25

36
use super::node_id::NodeID;
4-
use crate::misc::{write_comma_fmt, SmolStr};
7+
use crate::misc::{
8+
write_comma_fmt,
9+
SmolStr,
10+
};
511

612
pub struct Mutation<'a> {
713
name: SmolStr,

src/codegen/sb3.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,49 @@
11
use core::str;
22
use std::{
33
fs::File,
4-
io::{self, Seek, Write},
4+
io::{
5+
self,
6+
Seek,
7+
Write,
8+
},
59
path::Path,
610
};
711

8-
use fxhash::{FxHashMap, FxHashSet};
12+
use fxhash::{
13+
FxHashMap,
14+
FxHashSet,
15+
};
916
use logos::Span;
10-
use md5::{Digest, Md5};
17+
use md5::{
18+
Digest,
19+
Md5,
20+
};
1121
use serde_json::json;
12-
use zip::{write::SimpleFileOptions, ZipWriter};
22+
use zip::{
23+
write::SimpleFileOptions,
24+
ZipWriter,
25+
};
1326

1427
use super::{
15-
cmd::cmd_to_list, node::Node, node_id::NodeID, node_id_factory::NodeIDFactory,
28+
cmd::cmd_to_list,
29+
node::Node,
30+
node_id::NodeID,
31+
node_id_factory::NodeIDFactory,
1632
turbowarp_config::TurbowarpConfig,
1733
};
1834
use crate::{
1935
ast::*,
2036
blocks::Block,
2137
codegen::mutation::Mutation,
2238
config::Config,
23-
diagnostic::{DiagnosticKind, SpriteDiagnostics},
24-
misc::{write_comma_io, SmolStr},
39+
diagnostic::{
40+
DiagnosticKind,
41+
SpriteDiagnostics,
42+
},
43+
misc::{
44+
write_comma_io,
45+
SmolStr,
46+
},
2547
};
2648

2749
const STAGE_NAME: &str = "Stage";
@@ -242,8 +264,7 @@ impl Stmt {
242264

243265
#[derive(Debug)]
244266
pub struct Sb3<T>
245-
where
246-
T: Write + Seek,
267+
where T: Write + Seek
247268
{
248269
pub zip: ZipWriter<T>,
249270
pub id: NodeIDFactory,
@@ -255,8 +276,7 @@ where
255276
}
256277

257278
impl<T> Write for Sb3<T>
258-
where
259-
T: Write + Seek,
279+
where T: Write + Seek
260280
{
261281
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
262282
self.zip.write(buf)
@@ -268,8 +288,7 @@ where
268288
}
269289

270290
impl<T> Sb3<T>
271-
where
272-
T: Write + Seek,
291+
where T: Write + Seek
273292
{
274293
pub fn new(file: T) -> Self {
275294
Self {

src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ use serde::{
33
Serialize,
44
};
55

6-
#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Clone, Copy)]
6+
#[derive(Debug, Serialize, Deserialize, Default, PartialEq, Clone)]
77
pub struct Config {
8+
#[serde(default)]
9+
pub std: Option<String>,
810
#[serde(default)]
911
pub frame_rate: Option<u64>,
1012
#[serde(default)]

src/diagnostic/sprite_diagnostics.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use super::{
1919
};
2020
use crate::{
2121
ast::Project,
22-
translation_unit::TranslationUnit,
22+
standard_library::StandardLibrary,
23+
translation_unit::{
24+
Owner,
25+
TranslationUnit,
26+
},
2327
};
2428

2529
pub struct SpriteDiagnostics {
@@ -29,11 +33,11 @@ pub struct SpriteDiagnostics {
2933
}
3034

3135
impl SpriteDiagnostics {
32-
pub fn new(path: PathBuf) -> Self {
36+
pub fn new(path: PathBuf, stdlib: &StandardLibrary) -> Self {
3337
let sprite_name = path.file_stem().unwrap().to_str().unwrap().to_string();
3438
let mut translation_unit = TranslationUnit::new(path);
3539
let mut diagnostics = vec![];
36-
if let Err(diagnostic) = translation_unit.pre_process() {
40+
if let Err(diagnostic) = translation_unit.pre_process(stdlib) {
3741
diagnostics.extend(diagnostic);
3842
}
3943
Self {
@@ -63,13 +67,12 @@ impl SpriteDiagnostics {
6367
let (start, include) = self
6468
.translation_unit
6569
.translate_position(diagnostic.span.start);
66-
// Do not display diagnostics for standard library headers.
67-
let Some(include_path) = &include.path else {
70+
if !matches!(include.owner, Owner::Local) {
6871
continue;
69-
};
72+
}
7073
// TODO: memoize this using a memoization crate.
71-
let text = fs::read_to_string(include_path).unwrap();
72-
let include_path = include_path.to_str().unwrap();
74+
let text = fs::read_to_string(&include.path).unwrap();
75+
let include_path = include.path.to_str().unwrap();
7376
if diagnostic.span.start == 0 && diagnostic.span.end == 0 {
7477
let mut message = level
7578
.title(&title)

src/frontend.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn frontend() -> ExitCode {
4343
}
4444
Command::New {
4545
name,
46+
std,
4647
frame_rate,
4748
max_clones,
4849
no_miscellaneous_limits,
@@ -55,6 +56,7 @@ pub fn frontend() -> ExitCode {
5556
match new::new(
5657
name,
5758
Config {
59+
std,
5860
frame_rate,
5961
max_clones,
6062
no_miscellaneous_limits: Some(no_miscellaneous_limits),

0 commit comments

Comments
 (0)