Skip to content

Commit b9d362e

Browse files
authored
Merge branch 'aspizu:main' into main
2 parents d800567 + 0849753 commit b9d362e

25 files changed

+515
-12068
lines changed

Cargo.lock

Lines changed: 57 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "goboscript"
3-
version = "1.2.0"
3+
version = "2.0.0"
44
edition = "2021"
55

66
[dependencies]
@@ -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.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod arg;
2+
mod const_expr;
23
mod costume;
34
mod enum_;
45
mod enum_variant;
@@ -21,6 +22,7 @@ mod value;
2122
mod var;
2223

2324
pub use arg::*;
25+
pub use const_expr::*;
2426
pub use costume::*;
2527
pub use enum_::*;
2628
pub use enum_variant::*;

src/ast/const_expr.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
use logos::Span;
2+
3+
use super::Value;
4+
use crate::blocks::{
5+
BinOp,
6+
UnOp,
7+
};
8+
9+
#[derive(Debug, Clone)]
10+
pub enum ConstExpr {
11+
Value {
12+
value: Value,
13+
span: Span,
14+
},
15+
UnOp {
16+
op: UnOp,
17+
span: Span,
18+
opr: Box<ConstExpr>,
19+
},
20+
BinOp {
21+
op: BinOp,
22+
span: Span,
23+
lhs: Box<ConstExpr>,
24+
rhs: Box<ConstExpr>,
25+
},
26+
}
27+
28+
impl ConstExpr {
29+
pub fn span(&self) -> Span {
30+
match self {
31+
Self::Value { span, .. } => span.clone(),
32+
Self::UnOp { span, .. } => span.clone(),
33+
Self::BinOp { span, .. } => span.clone(),
34+
}
35+
}
36+
37+
pub fn evaluate(&self) -> Value {
38+
match self {
39+
Self::Value { value, .. } => value.clone(),
40+
Self::UnOp { op, opr, .. } => opr.evaluate().unop(*op).unwrap(),
41+
Self::BinOp { op, lhs, rhs, .. } => lhs.evaluate().binop(*op, &rhs.evaluate()).unwrap(),
42+
}
43+
}
44+
}
45+
46+
impl UnOp {
47+
pub fn to_const_expr(self, span: Span, expr: ConstExpr) -> ConstExpr {
48+
ConstExpr::UnOp {
49+
op: self,
50+
span,
51+
opr: Box::new(expr),
52+
}
53+
}
54+
}
55+
56+
impl BinOp {
57+
pub fn to_const_expr(self, span: Span, lhs: ConstExpr, rhs: ConstExpr) -> ConstExpr {
58+
ConstExpr::BinOp {
59+
op: self,
60+
span,
61+
lhs: Box::new(lhs),
62+
rhs: Box::new(rhs),
63+
}
64+
}
65+
}

src/ast/list.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use logos::Span;
22

33
use super::{
44
type_::Type,
5-
Value,
5+
ConstExpr,
66
};
77
use crate::misc::SmolStr;
88

@@ -17,7 +17,7 @@ pub struct List {
1717

1818
#[derive(Debug)]
1919
pub enum ListDefault {
20-
Literal(Vec<(Value, Span)>),
20+
ConstExprs(Vec<ConstExpr>),
2121
Cmd(Cmd),
2222
}
2323

@@ -55,12 +55,12 @@ impl List {
5555
}
5656
}
5757

58-
pub fn new_array(name: SmolStr, span: Span, type_: Type, default: Vec<(Value, Span)>) -> Self {
58+
pub fn new_array(name: SmolStr, span: Span, type_: Type, default: Vec<ConstExpr>) -> Self {
5959
Self {
6060
name,
6161
span,
6262
type_,
63-
default: Some(ListDefault::Literal(default)),
63+
default: Some(ListDefault::ConstExprs(default)),
6464
is_used: false,
6565
}
6666
}
@@ -72,9 +72,9 @@ impl List {
7272
}
7373
}
7474

75-
pub fn array(&self) -> Option<&[(Value, Span)]> {
75+
pub fn array(&self) -> Option<&[ConstExpr]> {
7676
match &self.default {
77-
Some(ListDefault::Literal(array)) => Some(array),
77+
Some(ListDefault::ConstExprs(array)) => Some(array),
7878
_ => None,
7979
}
8080
}

src/ast/value.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use std::fmt::{
77

88
use logos::Span;
99

10-
use super::Expr;
10+
use super::{
11+
ConstExpr,
12+
Expr,
13+
};
1114
use crate::misc::SmolStr;
1215

1316
#[derive(Debug, Clone)]
@@ -80,4 +83,9 @@ impl Value {
8083
pub fn to_expr(self, span: Span) -> Expr {
8184
Expr::Value { value: self, span }
8285
}
86+
87+
#[allow(clippy::wrong_self_convention)]
88+
pub fn to_const_expr(self, span: Span) -> ConstExpr {
89+
ConstExpr::Value { value: self, span }
90+
}
8391
}

src/ast/value/unop.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl Value {
2121
UnOp::Log => None,
2222
UnOp::AntiLn => None,
2323
UnOp::AntiLog => None,
24-
UnOp::Minus => None,
24+
UnOp::Minus => self.minus(),
2525
}
2626
}
2727

@@ -46,4 +46,12 @@ impl Value {
4646
_ => None,
4747
}
4848
}
49+
50+
fn minus(&self) -> Option<Value> {
51+
match self {
52+
Self::Int(int) => Some((-*int).into()),
53+
Self::Float(float) => Some((-*float).into()),
54+
_ => None,
55+
}
56+
}
4957
}

src/blocks.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,9 +1123,7 @@ impl Repr {
11231123
}
11241124

11251125
pub fn overloads(name: &str) -> &'static [Self] {
1126-
match name {
1127-
_ => &[],
1128-
}
1126+
&[]
11291127
}
11301128

11311129
pub fn from_shape(name: &str, args: usize) -> Option<Self> {

src/codegen/mutation.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ impl Display for Mutation<'_> {
4141
write!(f, r#","mutation":{{"tagName":"mutation","children":[]"#)?;
4242
write!(f, r#","warp":"{}""#, self.warp)?;
4343
write!(f, r#","proccode":"{}"#, self.name)?;
44-
for _ in 0..self.args.len() {
45-
write!(f, " %s")?;
44+
for (arg_name, _) in self.args {
45+
write!(f, " {arg_name}: %s")?;
4646
}
4747
write!(f, "\"")?;
4848
write!(f, r#","argumentids":"["#)?;

src/codegen/sb3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ where T: Write + Seek
708708
list.array().map(|array| {
709709
array
710710
.iter()
711-
.map(|(value, _)| value.to_string())
711+
.map(|const_expr| const_expr.evaluate().to_string())
712712
.collect::<Vec<_>>()
713713
})
714714
});

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: 12 additions & 9 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,12 +33,12 @@ 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() {
37-
diagnostics.push(diagnostic);
40+
if let Err(diagnostic) = translation_unit.pre_process(stdlib) {
41+
diagnostics.extend(diagnostic);
3842
}
3943
Self {
4044
sprite_name,
@@ -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)

0 commit comments

Comments
 (0)