updated assembler to write to binary files correctly 🤦
This commit is contained in:
+21
-44
@@ -4,6 +4,10 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use crate::templates::{Dsa, Dsc, Template};
|
||||
|
||||
mod templates;
|
||||
|
||||
/// Run a command and exit on failure.
|
||||
fn run(cmd: &mut Command) {
|
||||
let status = cmd.status().expect("failed to execute command");
|
||||
@@ -39,6 +43,8 @@ fn cmd_new(args: &[String]) {
|
||||
}
|
||||
}
|
||||
|
||||
let lib = args.contains(&"--lib".to_string());
|
||||
|
||||
// Determine project root: a subdirectory named after the supplied --name argument.
|
||||
let mut name_opt = None;
|
||||
for i in 0..args.len() {
|
||||
@@ -64,57 +70,16 @@ fn cmd_new(args: &[String]) {
|
||||
"dsa" => {
|
||||
// Minimal DSA binary template.
|
||||
let path = src_path.join(format!("main.dsa"));
|
||||
let template = format!(
|
||||
r#"
|
||||
// GENERATED BY DSX-BUILD
|
||||
// Generated at: {timestamp}
|
||||
// Project name: {project_name}
|
||||
|
||||
// Imports
|
||||
include print: "./lib/io/print.dsa"
|
||||
let template = Dsa::create(&project_name, lib);
|
||||
|
||||
// Globals & Reserved Memory
|
||||
dw stack: 0x10000
|
||||
db message: "Process Exited with code:"
|
||||
|
||||
// Entry Point
|
||||
_init:
|
||||
ldw stack, bpr
|
||||
mov bpr, spr
|
||||
push zero
|
||||
call main
|
||||
call print::print_newline
|
||||
lwi message, rg0
|
||||
push rg0
|
||||
call print::print
|
||||
pop zero
|
||||
call print::print_hex_word
|
||||
pop zero
|
||||
hlt
|
||||
|
||||
main:
|
||||
push bpr
|
||||
mov spr, bpr
|
||||
|
||||
lli 0, rg0
|
||||
stw rg0, bpr, 8
|
||||
|
||||
mov bpr, spr
|
||||
pop bpr
|
||||
return"#,
|
||||
project_name = project_name,
|
||||
timestamp = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S").to_string()
|
||||
);
|
||||
fs::write(path, template).expect("Unable to write DSA file");
|
||||
}
|
||||
"dsc" => {
|
||||
let path = src_path.join(format!("main.dsc"));
|
||||
let template = r#"
|
||||
include print: "./lib/io/print.dsa";
|
||||
|
||||
fn main() -> u32 {
|
||||
return 0;
|
||||
}"#;
|
||||
let template = Dsc::create(&project_name, lib);
|
||||
|
||||
fs::write(path, template).expect("Unable to write DSC file");
|
||||
}
|
||||
_ => {
|
||||
@@ -123,6 +88,18 @@ fn main() -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
fs::create_dir_all(src_path.join("lib")).expect("Failed to create lib directory");
|
||||
fs::write(
|
||||
src_path.join("lib/print.dsa"),
|
||||
templates::create_print_lib(),
|
||||
)
|
||||
.expect("Failed to create print.dsa");
|
||||
fs::write(
|
||||
src_path.join("lib/maths.dsa"),
|
||||
templates::create_maths_lib(),
|
||||
)
|
||||
.expect("Failed to create maths.dsa");
|
||||
|
||||
println!(
|
||||
"Created new {} project in {}.",
|
||||
lang,
|
||||
|
||||
Reference in New Issue
Block a user