Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6670252

Browse files
committed
Port to windows
1 parent 47cd0f7 commit 6670252

File tree

9 files changed

+172
-21
lines changed

9 files changed

+172
-21
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
</b>
99

1010
## Installation
11-
### Install Pog.NET by running the `build.sh` script and the executables will be added to your linux /usr/bin/ folder
11+
### Install Pog.NET on Linux by running the `build.sh` script and the executables will be added to your linux /usr/bin/ folder
12+
### Install Pog.NET on Windows by running the `build.bat` script then add "\Program Files\pdn" to your PATH.
1213
## Running programs
1314
### You can run a program using `pognet run <program>` and you can turn it into an executable using `pognet deploy <program>`
1415
## Hello world:

build.bat

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
@echo off
2+
PUSHD %~dp0
3+
rd /s /q bin
4+
mkdir bin
5+
echo "Building."
6+
cd deployer
7+
cargo build --release
8+
copy target\release\deployer.exe ..\bin
9+
cd ..
10+
cd cli
11+
cargo build --release
12+
copy target\release\cli.exe ..\bin
13+
cd ..
14+
cd main
15+
cargo build --release
16+
copy target\release\pogdotnet.exe ..\bin
17+
cd ..
18+
echo "Getting ready for installation."
19+
mkdir \"Program Files"\pdn
20+
echo "src/main.rs -> /Program Files/pdn"
21+
echo "bin/* -> Program Files"
22+
copy main\src\main.rs "\Program Files\pdn"
23+
copy bin\pogdotnet.exe "\Program Files\pdn\pdn_exec.exe"
24+
copy bin\deployer.exe "\Program Files\pdn\pdn_deploy.exe"
25+
copy bin\cli.exe "\Program Files\pdn\pdn.exe"
26+
echo !! ADD "\Program Files\pdn" TO PATH !!
27+
timeout 30

build_artifacts/final

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
:main
2+
sout " Hello, world! "
3+
cout #10
4+
5+
:main
6+
sout " Hello, world! "
7+
cout #10

build_artifacts/main.pnet

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:main
2+
sout " Hello, world! "
3+
cout #10

cli/Cargo.lock

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

cli/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ edition = "2021"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[dependencies]
9-
rand="0.8.5"
9+
rand="0.8.5"
10+
enable-ansi-support="0.2.1"

cli/src/main.rs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const VERBOSE: bool = false;
2+
use enable_ansi_support::enable_ansi_support;
3+
use std::fs;
24
use rand::random;
35
use std::{
46
env::args,
@@ -76,16 +78,8 @@ fn preprocess(file: &str, out: &str) {
7678
write("build_artifacts/final", last_step).unwrap();
7779
}
7880
}
79-
fn main() {
80-
if args().len() != 3 {
81-
err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str())
82-
} else if args().nth(1).unwrap() != "run" && args().nth(1).unwrap() != "deploy" {
83-
err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str())
84-
} else if !std::path::Path::new(&args().nth(2).unwrap()).exists() {
85-
err(format!("File {} does not exist.", args().nth(2).unwrap()).as_str())
86-
} else if std::path::Path::new(&args().nth(2).unwrap()).is_dir() {
87-
err(format!("{} is a directory.", args().nth(2).unwrap()).as_str())
88-
}
81+
#[cfg(not(windows))]
82+
fn build(){
8983
match Command::new("rm")
9084
.args(["-rf", "build_artifacts"])
9185
.spawn()
@@ -126,3 +120,51 @@ fn main() {
126120
ok("Deployed");
127121
}
128122
}
123+
#[cfg(windows)]
124+
fn build(){
125+
if let Ok(_) = fs::remove_dir_all("build_artifacts") {
126+
} else {};
127+
create_dir("build_artifacts").unwrap();
128+
if args().nth(1).unwrap() == "run" {
129+
info("Preprocessing.");
130+
preprocess(args().nth(2).unwrap().as_str(), "main");
131+
info("Running");
132+
Command::new("pdn_exec")
133+
.args(["build_artifacts/final"])
134+
.spawn()
135+
.unwrap()
136+
.wait()
137+
.unwrap();
138+
} else if args().nth(1).unwrap() == "deploy" {
139+
info("Preprocessing.");
140+
preprocess(args().nth(2).unwrap().as_str(), "main");
141+
ok("Preprocessed");
142+
info("Deploying");
143+
Command::new("pdn_deploy")
144+
.args([
145+
"build_artifacts/final",
146+
args()
147+
.nth(2)
148+
.unwrap()
149+
.as_str()
150+
.replace(".pnet", ".out")
151+
.as_str(),
152+
])
153+
.output()
154+
.unwrap();
155+
ok("Deployed");
156+
}
157+
}
158+
fn main() {
159+
enable_ansi_support().unwrap();
160+
if args().len() != 3 {
161+
err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str())
162+
} else if args().nth(1).unwrap() != "run" && args().nth(1).unwrap() != "deploy" {
163+
err(format!("Usage: {} <run/deploy> <file>", args().nth(0).unwrap()).as_str())
164+
} else if !std::path::Path::new(&args().nth(2).unwrap()).exists() {
165+
err(format!("File {} does not exist.", args().nth(2).unwrap()).as_str())
166+
} else if std::path::Path::new(&args().nth(2).unwrap()).is_dir() {
167+
err(format!("{} is a directory.", args().nth(2).unwrap()).as_str())
168+
}
169+
build();
170+
}

deployer/src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
use std::{env::args, fs, process::exit};
2-
2+
#[cfg(not(windows))]
3+
fn read_main() -> String{
4+
std::fs::read_to_string("/etc/pdn/main.rs").unwrap()
5+
}
6+
#[cfg(windows)]
7+
fn read_main() -> String{
8+
std::fs::read_to_string("/Program Files/pdn/main.rs").unwrap()
9+
}
310
fn main() {
411
if args().count() != 3 {
512
println!("Pog.NET deployer\nUsage: pdnd <program> <out>");
613
exit(1);
714
}
815
let code = fs::read_to_string(args().nth(1).unwrap()).unwrap();
916
println!("Initializing file.");
10-
let _main = std::fs::read_to_string("/etc/pdn/main.rs").unwrap();
17+
let _main = read_main();
1118
let _main = _main.replace("fn main()", "fn _main()");
1219
let _main = _main.replace("fn _deployment() {", "fn main() {");
1320
let _main = _main.replace("\"_deployer_replace_me\"", format!("{:#?}", code).as_str());
@@ -22,11 +29,6 @@ fn main() {
2229
.wait()
2330
.unwrap();
2431
println!("Cleaning up.");
25-
std::process::Command::new("rm")
26-
.arg("./main.rs")
27-
.spawn()
28-
.unwrap()
29-
.wait()
30-
.unwrap();
32+
fs::remove_file("main.rs").unwrap();
3133
println!("Outputted \"{}\"", args().nth(2).unwrap())
3234
}

main/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ fn count_args(args: Split<&str>) -> i32 {
231231
}
232232
count
233233
}
234-
fn execute(mut stack: Vec<StackTypes>, mut registers: Registers, program: String) {
234+
fn execute(mut stack: Vec<StackTypes>, mut registers: Registers,mut program: String) {
235+
program = program.replace("\r","");
235236
let prog_split: Split<&str> = program.split("\n");
236237
let labels: HashMap<String, i16> = get_labels(prog_split.clone());
237238
if !labels.contains_key(":main") {

0 commit comments

Comments
 (0)