Skip to content

Commit

Permalink
bugfixies
Browse files Browse the repository at this point in the history
  • Loading branch information
Spu7Nix committed Jan 6, 2021
1 parent b97e7ec commit d082a9e
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 26 deletions.
1 change: 1 addition & 0 deletions spwn-lang/libraries/std/control_flow.spwn
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ call_with_delay = #[desc("Call a function after a delay")] (

i.item.if_is(LARGER_THAN, range.end - 1, !{
if reset {
wait()
i.reset(reset_speed)
}
-> return
Expand Down
2 changes: 1 addition & 1 deletion spwn-lang/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl SpwnFmt for ValueBody {
TypeIndicator(x) => format!("@{}", x),
Null => "null".to_string(),
SelfVal => "self".to_string(),
Switch(_, _) => "switch".to_string()
Switch(_, _) => "switch".to_string(),
}
}
}
Expand Down
24 changes: 11 additions & 13 deletions spwn-lang/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ const ERROR_EXIT_CODE: i32 = 1;
use std::io::Write;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};


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



fn print_with_color(text: &str, color: Color) {
let mut stdout = StandardStream::stdout(ColorChoice::Always);
stdout
Expand Down Expand Up @@ -81,23 +78,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut live_editor = false;

let mut save_file = None;
let mut included_paths = vec![std::env::current_dir().expect("Cannot access current directory")];
let mut included_paths = vec![
std::env::current_dir().expect("Cannot access current directory"),
std::env::current_exe().expect("Cannot access directory of executable"),
];
//change to current_exe before release (from current_dir)


while let Some(arg) = args_iter.next() {
match arg.as_ref() {
"--console-output" | "-c" => gd_enabled = false,
"--no-level" | "-l" => {
gd_enabled = false;
compile_only = true;
},
}
"--no-optimize" | "-o" => opti_enabled = false,
"--level-name" | "-n" => level_name = args_iter.next().cloned(),
"--live-editor" | "-e" => live_editor = true,
"--save-file" | "-s" => save_file = args_iter.next().cloned(),
"--included-path" | "-i" => included_paths.push({
let path = PathBuf::from(args_iter.next().cloned().expect("No path provided"));
let path = PathBuf::from(
args_iter.next().cloned().expect("No path provided"),
);
if path.exists() {
path
} else {
Expand Down Expand Up @@ -132,9 +133,9 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}

let gd_path = if gd_enabled {
Some( if save_file != None{
Some(if save_file != None {
PathBuf::from(save_file.expect("what"))
}else if cfg!(target_os = "windows") {
} else if cfg!(target_os = "windows") {
PathBuf::from(std::env::var("localappdata").expect("No local app data"))
.join("GeometryDash/CCLocalLevels.dat")
} else if cfg!(target_os = "macos") {
Expand Down Expand Up @@ -231,10 +232,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
std::process::exit(ERROR_EXIT_CODE);
}
Ok(_) => {
print_with_color(
"Pasted into the editor!",
Color::Green,
);
print_with_color("Pasted into the editor!", Color::Green);
}
}
} else {
Expand Down
23 changes: 12 additions & 11 deletions spwn-lang/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1066,19 +1066,9 @@ fn fix_precedence(mut expr: ast::Expression) -> ast::Expression {
values: Vec::new(),
};

for (i, op) in expr.operators.iter().enumerate() {
for (i, op) in expr.operators.iter().enumerate().rev() {
if operator_precedence(op) == lowest {
new_expr.operators.push(*op);
new_expr.values.push(if i == 0 {
expr.values[0].clone()
} else {
fix_precedence(ast::Expression {
operators: expr.operators[..i].to_vec(),
values: expr.values[..(i + 1)].to_vec(),
})
.to_variable()
});

new_expr.values.push(if i == expr.operators.len() - 1 {
expr.values.last().unwrap().clone()
} else {
Expand All @@ -1090,10 +1080,21 @@ fn fix_precedence(mut expr: ast::Expression) -> ast::Expression {
})
.to_variable()
});
new_expr.values.push(if i == 0 {
expr.values[0].clone()
} else {
fix_precedence(ast::Expression {
operators: expr.operators[..i].to_vec(),
values: expr.values[..(i + 1)].to_vec(),
})
.to_variable()
});

break;
}
}
new_expr.operators.reverse();
new_expr.values.reverse();

new_expr
}
Expand Down
77 changes: 76 additions & 1 deletion spwn-lang/test/test.spwn
Original file line number Diff line number Diff line change
@@ -1,4 +1,79 @@
extract obj_props;

type @binaryCalculator;

$.print(@string(1000))
impl @binaryCalculator {

new: (bits: @number, x: @number, y: @number) {
let bitCounters = [];

for i in ..bits {
item = ?i;

$.add(obj {
OBJ_ID: 1615,
X: x + i * 30,
Y: y,
ITEM: item,
GROUPS: 999g
});

bitCounters.push(counter(item));
}

return {
bitCounters: bitCounters,
type: @binaryCalculator
}
},
binaryToDecimal: (self, target: @counter) {
target = 0;
wait(1);

for i in ..self.bitCounters.length {
if self.bitCounters[self.bitCounters.length - 1 - i] as @bool {
target += 2 ^ i;
}
}
},
decimalToBinary: (self, source: @counter, calcSpeed: @number = 5) {
let tempcounters = [];

for i in ..self.bitCounters.length {
tempcounters.push(counter());
}

source.copy_to(tempcounters, speed = 10);

for i in ..self.bitCounters.length {
-> () {
tempcounters[i].divide(2 ^ i, speed = calcSpeed);
tempcounters[i].divide(2, remainder = self.bitCounters[self.bitCounters.length - 1 - i], speed = calcSpeed);
}();
}
},
prettyDecimalToBinary: (self, source: @counter, calcSpeed: @number = 10) {

for i in ..self.bitCounters.length {
source.divide(2, remainder = self.bitCounters[self.bitCounters.length - 1 - i], speed = calcSpeed);
}

self.binaryToDecimal(source);
}
}

decimal = ?i;
decimalCounter = counter(decimal);
calculator = @binaryCalculator::new(12, 300, 300);

$.add(obj {
OBJ_ID: 1615,
X: 300,
Y: 330,
ITEM: decimal,
GROUPS: 999g
});

decimalCounter += 1234;
wait(1);
calculator.decimalToBinary(decimalCounter);

0 comments on commit d082a9e

Please sign in to comment.