Skip to content

Commit d082a9e

Browse files
committed
bugfixies
1 parent b97e7ec commit d082a9e

File tree

5 files changed

+101
-26
lines changed

5 files changed

+101
-26
lines changed

spwn-lang/libraries/std/control_flow.spwn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ call_with_delay = #[desc("Call a function after a delay")] (
7777

7878
i.item.if_is(LARGER_THAN, range.end - 1, !{
7979
if reset {
80+
wait()
8081
i.reset(reset_speed)
8182
}
8283
-> return

spwn-lang/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl SpwnFmt for ValueBody {
266266
TypeIndicator(x) => format!("@{}", x),
267267
Null => "null".to_string(),
268268
SelfVal => "self".to_string(),
269-
Switch(_, _) => "switch".to_string()
269+
Switch(_, _) => "switch".to_string(),
270270
}
271271
}
272272
}

spwn-lang/src/main.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@ const ERROR_EXIT_CODE: i32 = 1;
3333
use std::io::Write;
3434
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
3535

36-
3736
const HELP: &str = include_str!("../help.txt");
3837

39-
40-
4138
fn print_with_color(text: &str, color: Color) {
4239
let mut stdout = StandardStream::stdout(ColorChoice::Always);
4340
stdout
@@ -81,23 +78,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
8178
let mut live_editor = false;
8279

8380
let mut save_file = None;
84-
let mut included_paths = vec![std::env::current_dir().expect("Cannot access current directory")];
81+
let mut included_paths = vec![
82+
std::env::current_dir().expect("Cannot access current directory"),
83+
std::env::current_exe().expect("Cannot access directory of executable"),
84+
];
8585
//change to current_exe before release (from current_dir)
8686

87-
8887
while let Some(arg) = args_iter.next() {
8988
match arg.as_ref() {
9089
"--console-output" | "-c" => gd_enabled = false,
9190
"--no-level" | "-l" => {
9291
gd_enabled = false;
9392
compile_only = true;
94-
},
93+
}
9594
"--no-optimize" | "-o" => opti_enabled = false,
9695
"--level-name" | "-n" => level_name = args_iter.next().cloned(),
9796
"--live-editor" | "-e" => live_editor = true,
9897
"--save-file" | "-s" => save_file = args_iter.next().cloned(),
9998
"--included-path" | "-i" => included_paths.push({
100-
let path = PathBuf::from(args_iter.next().cloned().expect("No path provided"));
99+
let path = PathBuf::from(
100+
args_iter.next().cloned().expect("No path provided"),
101+
);
101102
if path.exists() {
102103
path
103104
} else {
@@ -132,9 +133,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
132133
}
133134

134135
let gd_path = if gd_enabled {
135-
Some( if save_file != None{
136+
Some(if save_file != None {
136137
PathBuf::from(save_file.expect("what"))
137-
}else if cfg!(target_os = "windows") {
138+
} else if cfg!(target_os = "windows") {
138139
PathBuf::from(std::env::var("localappdata").expect("No local app data"))
139140
.join("GeometryDash/CCLocalLevels.dat")
140141
} else if cfg!(target_os = "macos") {
@@ -231,10 +232,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
231232
std::process::exit(ERROR_EXIT_CODE);
232233
}
233234
Ok(_) => {
234-
print_with_color(
235-
"Pasted into the editor!",
236-
Color::Green,
237-
);
235+
print_with_color("Pasted into the editor!", Color::Green);
238236
}
239237
}
240238
} else {

spwn-lang/src/parser.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,19 +1066,9 @@ fn fix_precedence(mut expr: ast::Expression) -> ast::Expression {
10661066
values: Vec::new(),
10671067
};
10681068

1069-
for (i, op) in expr.operators.iter().enumerate() {
1069+
for (i, op) in expr.operators.iter().enumerate().rev() {
10701070
if operator_precedence(op) == lowest {
10711071
new_expr.operators.push(*op);
1072-
new_expr.values.push(if i == 0 {
1073-
expr.values[0].clone()
1074-
} else {
1075-
fix_precedence(ast::Expression {
1076-
operators: expr.operators[..i].to_vec(),
1077-
values: expr.values[..(i + 1)].to_vec(),
1078-
})
1079-
.to_variable()
1080-
});
1081-
10821072
new_expr.values.push(if i == expr.operators.len() - 1 {
10831073
expr.values.last().unwrap().clone()
10841074
} else {
@@ -1090,10 +1080,21 @@ fn fix_precedence(mut expr: ast::Expression) -> ast::Expression {
10901080
})
10911081
.to_variable()
10921082
});
1083+
new_expr.values.push(if i == 0 {
1084+
expr.values[0].clone()
1085+
} else {
1086+
fix_precedence(ast::Expression {
1087+
operators: expr.operators[..i].to_vec(),
1088+
values: expr.values[..(i + 1)].to_vec(),
1089+
})
1090+
.to_variable()
1091+
});
10931092

10941093
break;
10951094
}
10961095
}
1096+
new_expr.operators.reverse();
1097+
new_expr.values.reverse();
10971098

10981099
new_expr
10991100
}

spwn-lang/test/test.spwn

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,79 @@
1+
extract obj_props;
12

3+
type @binaryCalculator;
24

3-
$.print(@string(1000))
5+
impl @binaryCalculator {
46

7+
new: (bits: @number, x: @number, y: @number) {
8+
let bitCounters = [];
9+
10+
for i in ..bits {
11+
item = ?i;
12+
13+
$.add(obj {
14+
OBJ_ID: 1615,
15+
X: x + i * 30,
16+
Y: y,
17+
ITEM: item,
18+
GROUPS: 999g
19+
});
20+
21+
bitCounters.push(counter(item));
22+
}
23+
24+
return {
25+
bitCounters: bitCounters,
26+
type: @binaryCalculator
27+
}
28+
},
29+
binaryToDecimal: (self, target: @counter) {
30+
target = 0;
31+
wait(1);
32+
33+
for i in ..self.bitCounters.length {
34+
if self.bitCounters[self.bitCounters.length - 1 - i] as @bool {
35+
target += 2 ^ i;
36+
}
37+
}
38+
},
39+
decimalToBinary: (self, source: @counter, calcSpeed: @number = 5) {
40+
let tempcounters = [];
41+
42+
for i in ..self.bitCounters.length {
43+
tempcounters.push(counter());
44+
}
45+
46+
source.copy_to(tempcounters, speed = 10);
47+
48+
for i in ..self.bitCounters.length {
49+
-> () {
50+
tempcounters[i].divide(2 ^ i, speed = calcSpeed);
51+
tempcounters[i].divide(2, remainder = self.bitCounters[self.bitCounters.length - 1 - i], speed = calcSpeed);
52+
}();
53+
}
54+
},
55+
prettyDecimalToBinary: (self, source: @counter, calcSpeed: @number = 10) {
56+
57+
for i in ..self.bitCounters.length {
58+
source.divide(2, remainder = self.bitCounters[self.bitCounters.length - 1 - i], speed = calcSpeed);
59+
}
60+
61+
self.binaryToDecimal(source);
62+
}
63+
}
64+
65+
decimal = ?i;
66+
decimalCounter = counter(decimal);
67+
calculator = @binaryCalculator::new(12, 300, 300);
68+
69+
$.add(obj {
70+
OBJ_ID: 1615,
71+
X: 300,
72+
Y: 330,
73+
ITEM: decimal,
74+
GROUPS: 999g
75+
});
76+
77+
decimalCounter += 1234;
78+
wait(1);
79+
calculator.decimalToBinary(decimalCounter);

0 commit comments

Comments
 (0)