diff --git a/Cargo.toml b/Cargo.toml index b5efad1..18a76ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,11 @@ cargo-features = ["codegen-backend"] [workspace] -members = ["emulator", "common", "assembler", "dsa_editor", "compiler", "dsx_server"] +members = [ + "core/dsa_common", "core/assembler", "core/compiler", + "emulator", "emulator/dsa_editor", + "dsx/dsx_server", "dsx/dsx_common", "dsx/dsx" +] resolver = "3" [workspace.package] diff --git a/assembler/Cargo.toml b/core/assembler/Cargo.toml similarity index 87% rename from assembler/Cargo.toml rename to core/assembler/Cargo.toml index 0b577da..64cffb3 100644 --- a/assembler/Cargo.toml +++ b/core/assembler/Cargo.toml @@ -13,6 +13,6 @@ name = "assembler" path = "src/lib.rs" [dependencies] -common = { path = "../common" } +common = { path = "../dsa_common" } num_cpus = "1.17.0" threadpool = "1.8.1" diff --git a/assembler/brainf.dsb b/core/assembler/brainf.dsb similarity index 100% rename from assembler/brainf.dsb rename to core/assembler/brainf.dsb diff --git a/assembler/src/assembler/assembler.rs b/core/assembler/src/assembler/assembler.rs similarity index 100% rename from assembler/src/assembler/assembler.rs rename to core/assembler/src/assembler/assembler.rs diff --git a/assembler/src/assembler/codegen.rs b/core/assembler/src/assembler/codegen.rs similarity index 100% rename from assembler/src/assembler/codegen.rs rename to core/assembler/src/assembler/codegen.rs diff --git a/assembler/src/assembler/expand.rs b/core/assembler/src/assembler/expand.rs similarity index 100% rename from assembler/src/assembler/expand.rs rename to core/assembler/src/assembler/expand.rs diff --git a/assembler/src/assembler/lexer.rs b/core/assembler/src/assembler/lexer.rs similarity index 100% rename from assembler/src/assembler/lexer.rs rename to core/assembler/src/assembler/lexer.rs diff --git a/assembler/src/assembler/macros.rs b/core/assembler/src/assembler/macros.rs similarity index 100% rename from assembler/src/assembler/macros.rs rename to core/assembler/src/assembler/macros.rs diff --git a/assembler/src/assembler/mod.rs b/core/assembler/src/assembler/mod.rs similarity index 100% rename from assembler/src/assembler/mod.rs rename to core/assembler/src/assembler/mod.rs diff --git a/assembler/src/assembler/model.rs b/core/assembler/src/assembler/model.rs similarity index 100% rename from assembler/src/assembler/model.rs rename to core/assembler/src/assembler/model.rs diff --git a/assembler/src/assembler/parser.rs b/core/assembler/src/assembler/parser.rs similarity index 100% rename from assembler/src/assembler/parser.rs rename to core/assembler/src/assembler/parser.rs diff --git a/assembler/src/assembler/resolver.rs b/core/assembler/src/assembler/resolver.rs similarity index 100% rename from assembler/src/assembler/resolver.rs rename to core/assembler/src/assembler/resolver.rs diff --git a/assembler/src/image_builder/mod.rs b/core/assembler/src/image_builder/mod.rs similarity index 100% rename from assembler/src/image_builder/mod.rs rename to core/assembler/src/image_builder/mod.rs diff --git a/assembler/src/lib.rs b/core/assembler/src/lib.rs similarity index 100% rename from assembler/src/lib.rs rename to core/assembler/src/lib.rs diff --git a/assembler/src/main.rs b/core/assembler/src/main.rs similarity index 100% rename from assembler/src/main.rs rename to core/assembler/src/main.rs diff --git a/assembler/src/tooling/brainf.rs b/core/assembler/src/tooling/brainf.rs similarity index 100% rename from assembler/src/tooling/brainf.rs rename to core/assembler/src/tooling/brainf.rs diff --git a/assembler/src/tooling/mod.rs b/core/assembler/src/tooling/mod.rs similarity index 100% rename from assembler/src/tooling/mod.rs rename to core/assembler/src/tooling/mod.rs diff --git a/assembler/src/tooling/project.rs b/core/assembler/src/tooling/project.rs similarity index 100% rename from assembler/src/tooling/project.rs rename to core/assembler/src/tooling/project.rs diff --git a/assembler/src/util/logging.rs b/core/assembler/src/util/logging.rs similarity index 100% rename from assembler/src/util/logging.rs rename to core/assembler/src/util/logging.rs diff --git a/assembler/src/util/mod.rs b/core/assembler/src/util/mod.rs similarity index 100% rename from assembler/src/util/mod.rs rename to core/assembler/src/util/mod.rs diff --git a/compiler/Cargo.toml b/core/compiler/Cargo.toml similarity index 83% rename from compiler/Cargo.toml rename to core/compiler/Cargo.toml index a4b6a6f..e5d87a0 100644 --- a/compiler/Cargo.toml +++ b/core/compiler/Cargo.toml @@ -6,5 +6,5 @@ authors.workspace = true [dependencies] chrono = "0.4.43" -common = { path = "../common" } +common = { path = "../dsa_common" } uuid = { version = "1.20.0", features = ["v4"] } diff --git a/compiler/bacon.toml b/core/compiler/bacon.toml similarity index 100% rename from compiler/bacon.toml rename to core/compiler/bacon.toml diff --git a/compiler/src/backend/dsa/codegen.rs b/core/compiler/src/backend/dsa/codegen.rs similarity index 100% rename from compiler/src/backend/dsa/codegen.rs rename to core/compiler/src/backend/dsa/codegen.rs diff --git a/compiler/src/backend/dsa/instruction.rs b/core/compiler/src/backend/dsa/instruction.rs similarity index 100% rename from compiler/src/backend/dsa/instruction.rs rename to core/compiler/src/backend/dsa/instruction.rs diff --git a/compiler/src/backend/dsa/mod.rs b/core/compiler/src/backend/dsa/mod.rs similarity index 100% rename from compiler/src/backend/dsa/mod.rs rename to core/compiler/src/backend/dsa/mod.rs diff --git a/compiler/src/backend/dsa/registers.rs b/core/compiler/src/backend/dsa/registers.rs similarity index 100% rename from compiler/src/backend/dsa/registers.rs rename to core/compiler/src/backend/dsa/registers.rs diff --git a/compiler/src/backend/dsa/scope.rs b/core/compiler/src/backend/dsa/scope.rs similarity index 100% rename from compiler/src/backend/dsa/scope.rs rename to core/compiler/src/backend/dsa/scope.rs diff --git a/compiler/src/backend/mod.rs b/core/compiler/src/backend/mod.rs similarity index 100% rename from compiler/src/backend/mod.rs rename to core/compiler/src/backend/mod.rs diff --git a/compiler/src/frontend/c/lexer.rs b/core/compiler/src/frontend/c/lexer.rs similarity index 100% rename from compiler/src/frontend/c/lexer.rs rename to core/compiler/src/frontend/c/lexer.rs diff --git a/compiler/src/frontend/c/mod.rs b/core/compiler/src/frontend/c/mod.rs similarity index 100% rename from compiler/src/frontend/c/mod.rs rename to core/compiler/src/frontend/c/mod.rs diff --git a/compiler/src/frontend/c/parser.rs b/core/compiler/src/frontend/c/parser.rs similarity index 100% rename from compiler/src/frontend/c/parser.rs rename to core/compiler/src/frontend/c/parser.rs diff --git a/compiler/src/frontend/dsc/lexer.rs b/core/compiler/src/frontend/dsc/lexer.rs similarity index 100% rename from compiler/src/frontend/dsc/lexer.rs rename to core/compiler/src/frontend/dsc/lexer.rs diff --git a/compiler/src/frontend/dsc/mod.rs b/core/compiler/src/frontend/dsc/mod.rs similarity index 100% rename from compiler/src/frontend/dsc/mod.rs rename to core/compiler/src/frontend/dsc/mod.rs diff --git a/compiler/src/frontend/dsc/parser.rs b/core/compiler/src/frontend/dsc/parser.rs similarity index 100% rename from compiler/src/frontend/dsc/parser.rs rename to core/compiler/src/frontend/dsc/parser.rs diff --git a/compiler/src/frontend/dsc/semantic_analyser.rs b/core/compiler/src/frontend/dsc/semantic_analyser.rs similarity index 100% rename from compiler/src/frontend/dsc/semantic_analyser.rs rename to core/compiler/src/frontend/dsc/semantic_analyser.rs diff --git a/compiler/src/frontend/mod.rs b/core/compiler/src/frontend/mod.rs similarity index 100% rename from compiler/src/frontend/mod.rs rename to core/compiler/src/frontend/mod.rs diff --git a/compiler/src/lib.rs b/core/compiler/src/lib.rs similarity index 100% rename from compiler/src/lib.rs rename to core/compiler/src/lib.rs diff --git a/compiler/src/main.rs b/core/compiler/src/main.rs similarity index 100% rename from compiler/src/main.rs rename to core/compiler/src/main.rs diff --git a/compiler/src/model.rs b/core/compiler/src/model.rs similarity index 100% rename from compiler/src/model.rs rename to core/compiler/src/model.rs diff --git a/compiler/src/specialised/brainf.rs b/core/compiler/src/specialised/brainf.rs similarity index 100% rename from compiler/src/specialised/brainf.rs rename to core/compiler/src/specialised/brainf.rs diff --git a/compiler/src/specialised/mod.rs b/core/compiler/src/specialised/mod.rs similarity index 100% rename from compiler/src/specialised/mod.rs rename to core/compiler/src/specialised/mod.rs diff --git a/common/Cargo.toml b/core/dsa_common/Cargo.toml similarity index 100% rename from common/Cargo.toml rename to core/dsa_common/Cargo.toml diff --git a/common/src/build.rs b/core/dsa_common/src/build.rs similarity index 100% rename from common/src/build.rs rename to core/dsa_common/src/build.rs diff --git a/common/src/instructions.rs b/core/dsa_common/src/instructions.rs similarity index 100% rename from common/src/instructions.rs rename to core/dsa_common/src/instructions.rs diff --git a/common/src/instructions/args.rs b/core/dsa_common/src/instructions/args.rs similarity index 100% rename from common/src/instructions/args.rs rename to core/dsa_common/src/instructions/args.rs diff --git a/common/src/instructions/encode.rs b/core/dsa_common/src/instructions/encode.rs similarity index 100% rename from common/src/instructions/encode.rs rename to core/dsa_common/src/instructions/encode.rs diff --git a/common/src/instructions/encode/tests.rs b/core/dsa_common/src/instructions/encode/tests.rs similarity index 100% rename from common/src/instructions/encode/tests.rs rename to core/dsa_common/src/instructions/encode/tests.rs diff --git a/common/src/instructions/errors.rs b/core/dsa_common/src/instructions/errors.rs similarity index 100% rename from common/src/instructions/errors.rs rename to core/dsa_common/src/instructions/errors.rs diff --git a/common/src/instructions/tests.rs b/core/dsa_common/src/instructions/tests.rs similarity index 100% rename from common/src/instructions/tests.rs rename to core/dsa_common/src/instructions/tests.rs diff --git a/common/src/lib.rs b/core/dsa_common/src/lib.rs similarity index 100% rename from common/src/lib.rs rename to core/dsa_common/src/lib.rs diff --git a/common/src/logging.rs b/core/dsa_common/src/logging.rs similarity index 100% rename from common/src/logging.rs rename to core/dsa_common/src/logging.rs diff --git a/dsx/dsx/Cargo.toml b/dsx/dsx/Cargo.toml new file mode 100644 index 0000000..2fe2c45 --- /dev/null +++ b/dsx/dsx/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "dsx" +version.workspace = true +edition.workspace = true +authors.workspace = true + +[[bin]] +name = "dsx" +path = "src/main.rs" + +[dependencies] +compiler = { path = "../../core/compiler" } +assembler = { path = "../../core/assembler" } +common = { path = "../../core/dsa_common" } +dsx_common = { path = "../dsx_common" } +toml = "1.0.3" +chrono = "0.4.44" diff --git a/dsx_server/src/client/client.rs b/dsx/dsx/src/main.rs similarity index 91% rename from dsx_server/src/client/client.rs rename to dsx/dsx/src/main.rs index 6dfdf7b..c6a3689 100644 --- a/dsx_server/src/client/client.rs +++ b/dsx/dsx/src/main.rs @@ -1,12 +1,9 @@ -use std::process::{Command, Stdio}; -use std::{ - env, fs, - path::{Path, PathBuf}, -}; +use std::{env, path::PathBuf}; -use dsx::common::builder; +use dsx_common::builder; pub mod new; +pub mod templates; fn main() { // Very small CLI – only three sub‑commands. diff --git a/dsx_server/src/client/new.rs b/dsx/dsx/src/new.rs similarity index 95% rename from dsx_server/src/client/new.rs rename to dsx/dsx/src/new.rs index abe265a..8ff5d54 100644 --- a/dsx_server/src/client/new.rs +++ b/dsx/dsx/src/new.rs @@ -1,9 +1,8 @@ -use std::{env, fmt, fs, path::PathBuf}; +use std::{env, fmt, fs}; -use dsx::common::{ - config::DsxConfig, - templates::{self, Dsa, Dsc, Template}, -}; +use dsx_common::config::DsxConfig; + +use crate::templates::{self, Dsa, Dsc, Template}; // ---------- new project ---------------------------------------------------- pub fn new_project(args: &[String]) { diff --git a/dsx/dsx/src/templates.rs b/dsx/dsx/src/templates.rs new file mode 100644 index 0000000..bb997ab --- /dev/null +++ b/dsx/dsx/src/templates.rs @@ -0,0 +1,589 @@ +pub trait Template { + fn lib(project: &str) -> String; + fn bin(project: &str) -> String; + + fn create(project: &str, lib: bool) -> String { + if lib { + Self::lib(project) + } else { + Self::bin(project) + } + } +} + +pub struct Dsa; +pub struct Dsc; + +impl Template for Dsa { + fn lib(project: &str) -> String { + format!( + r#"// +lib.dsa +// usage: +// +// include {project} "" +// +// usage for {project}_main: +// push (arg1) +// push (arg0) +// call {project}::{project}_main +// pop (arg0) +// pop (arg1) + +// Example data declarations +// dw example_data: 0x0000 + +// Main function template +{project}_main: + // the correct way to start a function as defined by the calling convention + push bpr + mov spr, bpr + + // explanation of how to access args + ldw bpr, rg0, 8 // arg 0 + ldw bpr, rg0, 12 // arg 1 + + // your code goes here + // Example: load example_data into rg1 + // ldw example_data, rg1 + + // the correct way to end a function as defined by the calling convention + mov bpr, spr + pop bpr + return +"#, + ) + } + + fn bin(project: &str) -> String { + format!( + r#" +// GENERATED BY DSX-BUILD +// Generated at: {timestamp} +// Project name: {project} + +// Imports +include print: "./lib/print.dsa" + +// 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 + + // Your code goes here + + // Return zero + stw zero, bpr, 8 + + mov bpr, spr + pop bpr + return"#, + timestamp = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S") + ) + } +} + +impl Template for Dsc { + fn lib(project: &str) -> String { + format!( + r#" +// GENERATED BY DSX-BUILD +// Generated at: {timestamp} +// Project name: {project} + +// Imports +include print: "./lib/print.dsa"; + +// Main Function +fn {project}_main() -> u32 {{ + return 0; +}}"#, + timestamp = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S") + ) + } + + fn bin(project: &str) -> String { + format!( + r#" +// GENERATED BY DSX-BUILD +// Generated at: {timestamp} +// Project name: {project} + +// Imports +include print: "./lib/print.dsa"; + +// Main Function +fn main() -> u32 {{ + return 0; +}}"#, + timestamp = chrono::Utc::now().format("%Y-%m-%d %H:%M:%S") + ) + } +} + +pub fn create_print_lib() -> String { + String::from( + r#" +// lib: +// print.dsa + +// usage: +// +// include print """ +// +// usage for print: +// push (register containing address of string) +// push pcx +// jmp print::print +// +// usage for reset: +// push pcx +// jmp print::reset +// +// usage for clear: +// push pcx +// jmp print::clear +// +// usage for print_byte: +// push (register containing byte) +// push pcx +// jmp print::print_byte +// +// usage for print_word: +// push (register containing word) +// push pcx +// jmp print::print_word +// +// usage for print_num: +// push (register containing number to print in decimal) +// push pcx +// jmp print::print_num +// + +include maths "./maths.dsa" + +dw display: 0x20000 +dw current: 0x20000 + +// ------------------------------------------ +// prints the string at addr(arg[0]) to the screen. (no trailing whitespace unless explicitly provided) +print: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 + ldw current, rg1 + +_print_loop: + ldb rg0, acc + cmp acc, zero + jeq _end + stb acc, rg1 + + addi rg0, 1 + addi rg1, 1 + + jmp _print_loop + +// ------------------------------------------ +println: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 + ldw current, rg1 + +_println_loop: + ldb rg0, acc + cmp acc, zero + jeq _println_end + stb acc, rg1 + + addi rg0, 1 + addi rg1, 1 + + jmp _println_loop + +_println_end: + call print_newline + jmp _end + +// ------------------------------------------ +// prints the value of arg[0] to the screen. +print_word: + // initialise + push bpr + mov spr, bpr + + // load byte into acc + ldw bpr, rg0, 8 + ldw current, rg1 + + addi rg1, 3 + + stb rg0, rg1 + subi rg1, 1 + shr rg0, 8 + stb rg0, rg1 + subi rg1, 1 + shr rg0, 8 + stb rg0, rg1 + subi rg1, 1 + shr rg0, 8 + stb rg0, rg1 + + addi rg1, 4 + jmp _end + +// ------------------------------------------ +// prints the last byte of arg[0] to the screen. +print_byte: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 + ldw current, rg1 + + stb rg0, rg1 + addi rg1, 1 + jmp _end + +// ------------------------------------------ +// prints the value of arg[0] to the screen in hex. +print_hex_word: + push bpr + mov spr, bpr + + ldw current, rg1 + + ldb bpr, rg0, 8 + push rg0 + call _print_hex_byte + addi spr, 4 + + ldb bpr, rg0, 9 + push rg0 + call _print_hex_byte + addi spr, 4 + + ldb bpr, rg0, 10 + push rg0 + call _print_hex_byte + addi spr, 4 + + ldb bpr, rg0, 11 + push rg0 + call _print_hex_byte + addi spr, 4 + + jmp _end + +// ------------------------------------------ +// prints the last byte of arg[0] to the screen in hex. +print_hex_byte: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 + ldw current, rg1 + + call _print_hex_byte + jmp _end + +// function body +_print_hex_byte: + // mask to get lower nibble + lli 0xF, rg2 + // save rg0 state + push rg0 + + shr rg0, 4 + and rg0, rg2, rg0 + call _print_hex_nibble + pop rg0 + + and rg0, rg2, rg0 + call _print_hex_nibble + return + +// print a hex digit +_print_hex_nibble: + lli 10, rg3 + cmp rg0, rg3 + jlt _print_hex_nibble_number + addi rg0, 0x37, rg0 + stb rg0, rg1 + addi rg1, 1 + return + +// helper function. +_print_hex_nibble_number: + addi rg0, 0x30, rg0 + stb rg0, rg1 + addi rg1, 1 + return + +// ------------------------------------------ +// print whitespace +print_whitespace: + push bpr + mov spr, bpr + + ldw current, rg1 + lli 0x20, rg0 + stb rg0, rg1 + addi rg1, 1 + jmp _end + +// ------------------------------------------ +// print newline +print_newline: + push bpr + mov spr, bpr + + // load variables into registers + ldw display, rg0 + ldw current, rg1 + + // get the offset from the display base + sub rg1, rg0, rg0 + + lwi 80, rg2 + pusha 3 + push rg0 + push rg2 + call maths::divmod + pop zero // result + pop rg3 // remainder + popa 3 + + sub rg1, rg3, rg2 + addi rg2, 80, rg1 + + // _end saves the display state + jmp _end + +// ------------------------------------------ +// prints arg[0] as a decimal number to the screen. +print_num: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 // load number to print + lli 0, rg5 // rg5 = digit counter + + // check if number is zero + cmp rg0, zero + jne _print_num_extract_digits + + // special case: print '0' for zero + lli 0x30, rg6 + push rg6 // push digit to stack buffer + lli 1, rg5 // we have 1 digit + jmp _print_num_output + +_print_num_extract_digits: + // divide by 10 repeatedly to get digits + cmp rg0, zero + jeq _print_num_output + + // call divmod(rg0, 10) + push rg0 // dividend + lli 10, rg1 + push rg1 // divisor (10) + call maths::divmod + pop rg0 // quotient (continue dividing this) + pop rg1 // remainder (the digit) + + // convert digit to ASCII and push to stack buffer + addi rg1, 0x30, rg6 // convert to ASCII + push rg6 // push digit to stack + inc rg5 // increment digit counter + + jmp _print_num_extract_digits + +_print_num_output: + // now print digits (pop them off in reverse order) + ldw current, rg1 // get display pointer + +_print_num_output_loop: + // check if we've printed all digits + cmp rg5, zero + jeq _print_num_done + + // pop digit and print it + pop rg6 + stb rg6, rg1 + addi rg1, 1 + dec rg5 + + jmp _print_num_output_loop + +_print_num_done: + jmp _end + +// ------------------------------------------ +// resets the cursor position on the screen to 0x20000. (0,0) +reset: + push bpr + mov spr, bpr + ldw display, rg1 + jmp _end + +// ------------------------------------------ +// clears the screen +clear: + push bpr + mov spr, bpr + // display size = 2000 bytes / 500 words + lli 500 rg0 + ldw display, rg1 + +_clear_loop: + dec rg0 + stw zero, rg1 + addi rg1, 4 + cmp rg0, zero + jgt _clear_loop + jmp _end + +// ------------------------------------------ +// return +_end: + stw rg1, current + + mov bpr, spr + pop bpr + return +"#, + ) +} + +pub fn create_maths_lib() -> String { + String::from( + r#" +// multiply.dsa +// usage: +// +// include multiply "" +// +// usage for multiply: +// push (arg1) +// push (arg0) +// call multiply::multiply +// pop (arg0) +// pop (arg1) + +multiply: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 // load op 2 + ldw bpr, rg1, 12 // load op 1 + lwi 0, rg2 // initialise rg2 to zero + +_multiply_loop: + add rg2, rg0, rg2 + dec rg1 + + cmp rg1, zero + jgt _multiply_loop + +_multiply_end: + stw rg2, bpr, 8 + + mov bpr, spr + pop bpr + return + +divmod: + push bpr + mov spr, bpr + + ldw bpr, rg1, 8 // load op 2 + ldw bpr, rg0, 12 // load op 1 + + lli 0, rg3 + +_divmod_loop: + cmp rg0, rg1 + jlt _divmod_end + + sub rg0, rg1, rg0 + inc rg3 + + jmp _divmod_loop + +_divmod_end: + // store div in first arg + // store mod in second arg + stw rg3, bpr, 8 + stw rg0, bpr, 12 + + mov bpr, spr + pop bpr + return + +// multiply.dsa - improved version +// Multiplies two 32-bit numbers using shift-and-add +// +// Usage: +// push operand2 (multiplier) +// push operand1 (multiplicand) +// call multiply::multiply +// pop result +// pop zero (discard second argument) + +new_multiply: + push bpr + mov spr, bpr + + ldw bpr, rg0, 8 // rg0 = multiplicand + ldw bpr, rg1, 12 // rg1 = multiplier + + lli 0, rg2 // rg2 = result (accumulator) + lli 32, rg3 // rg3 = bit counter + +mult_loop: + // Check if lowest bit of multiplier is 1 + lli 1, acc + and rg1, acc, acc // acc = rg1 & 1 + cmp acc, zero + jeq skip_add // if (rg1 & 1) == 0, skip addition + + // Add multiplicand to result + add rg2, rg0, rg2 + +skip_add: + shl rg0, 1 // shift multiplicand left + shr rg1, 1 // shift multiplier right + + dec rg3 + cmp rg3, zero + jgt mult_loop + + stw rg2, bpr, 8 // store result + mov bpr, spr + pop bpr + return +"#, + ) +} diff --git a/dsx/dsx_common/Cargo.toml b/dsx/dsx_common/Cargo.toml new file mode 100644 index 0000000..7346c2c --- /dev/null +++ b/dsx/dsx_common/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "dsx_common" +version.workspace = true +edition.workspace = true +authors.workspace = true + +[dependencies] +compiler = { path = "../../core/compiler" } +assembler = { path = "../../core/assembler" } +common = { path = "../../core/dsa_common" } + +chrono = "0.4.44" +serde = { version = "1.0.228", features = ["derive"] } +toml = "1.0.3" +walkdir = "2.5.0" diff --git a/dsx_server/src/common/builder/mod.rs b/dsx/dsx_common/src/builder.rs similarity index 99% rename from dsx_server/src/common/builder/mod.rs rename to dsx/dsx_common/src/builder.rs index 62b0d15..914a638 100644 --- a/dsx_server/src/common/builder/mod.rs +++ b/dsx/dsx_common/src/builder.rs @@ -4,7 +4,7 @@ use std::{ process::Command, }; -use crate::common::config::DsxConfig; +use crate::config::DsxConfig; use assembler::prelude::Assembler; use common::build::{BuildError, Builder}; diff --git a/dsx_server/src/common/templates.rs b/dsx/dsx_common/src/common/templates.rs similarity index 99% rename from dsx_server/src/common/templates.rs rename to dsx/dsx_common/src/common/templates.rs index b5d9aba..0f5a443 100644 --- a/dsx_server/src/common/templates.rs +++ b/dsx/dsx_common/src/common/templates.rs @@ -140,7 +140,7 @@ fn main() -> u32 {{ } pub fn create_print_lib() -> String { - format!( + String::from( r#" // lib: // print.dsa @@ -473,12 +473,12 @@ _end: mov bpr, spr pop bpr return -"# +"#, ) } pub fn create_maths_lib() -> String { - format!( + String::from( r#" // multiply.dsa // usage: @@ -584,6 +584,6 @@ skip_add: mov bpr, spr pop bpr return -"# +"#, ) } diff --git a/dsx_server/src/common/config.rs b/dsx/dsx_common/src/config.rs similarity index 97% rename from dsx_server/src/common/config.rs rename to dsx/dsx_common/src/config.rs index be5da62..32be942 100644 --- a/dsx_server/src/common/config.rs +++ b/dsx/dsx_common/src/config.rs @@ -1,4 +1,3 @@ -use rocket::serde; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/dsx_server/src/common/mod.rs b/dsx/dsx_common/src/lib.rs similarity index 63% rename from dsx_server/src/common/mod.rs rename to dsx/dsx_common/src/lib.rs index d3d7265..5dc0a79 100644 --- a/dsx_server/src/common/mod.rs +++ b/dsx/dsx_common/src/lib.rs @@ -1,3 +1,2 @@ pub mod builder; pub mod config; -pub mod templates; diff --git a/dsx_server/Cargo.toml b/dsx/dsx_server/Cargo.toml similarity index 69% rename from dsx_server/Cargo.toml rename to dsx/dsx_server/Cargo.toml index 535509f..a7ba928 100644 --- a/dsx_server/Cargo.toml +++ b/dsx/dsx_server/Cargo.toml @@ -1,23 +1,19 @@ [package] -name = "dsx" +name = "dsx_server" version.workspace = true edition.workspace = true authors.workspace = true [[bin]] name = "dsx_server" -path = "src/server/server.rs" - -[[bin]] -name = "dsx" -path = "src/client/client.rs" +path = "src/main.rs" [dependencies] -compiler = { path = "../compiler" } -assembler = { path = "../assembler" } -common = { path = "../common" } +compiler = { path = "../../core/compiler" } +assembler = { path = "../../core/assembler" } +common = { path = "../../core/dsa_common" } +dsx_common = { path = "../dsx_common" } -anyhow = "1.0.102" dotenv = "0.15.0" rocket = { version = "0.5.1", features = ["json"] } rocket_dyn_templates = { version = "0.2.0", features = ["tera"] } diff --git a/dsx_server/bacon.toml b/dsx/dsx_server/bacon.toml similarity index 100% rename from dsx_server/bacon.toml rename to dsx/dsx_server/bacon.toml diff --git a/dsx_server/data/repos/example/Package.toml b/dsx/dsx_server/data/repos/example/Package.toml similarity index 100% rename from dsx_server/data/repos/example/Package.toml rename to dsx/dsx_server/data/repos/example/Package.toml diff --git a/dsx_server/data/repos/example/repo/Dsx.toml b/dsx/dsx_server/data/repos/example/repo/Dsx.toml similarity index 100% rename from dsx_server/data/repos/example/repo/Dsx.toml rename to dsx/dsx_server/data/repos/example/repo/Dsx.toml diff --git a/dsx_server/data/repos/example/repo/src/lib/maths.dsa b/dsx/dsx_server/data/repos/example/repo/src/lib/maths.dsa similarity index 100% rename from dsx_server/data/repos/example/repo/src/lib/maths.dsa rename to dsx/dsx_server/data/repos/example/repo/src/lib/maths.dsa diff --git a/dsx_server/data/repos/example/repo/src/lib/print.dsa b/dsx/dsx_server/data/repos/example/repo/src/lib/print.dsa similarity index 100% rename from dsx_server/data/repos/example/repo/src/lib/print.dsa rename to dsx/dsx_server/data/repos/example/repo/src/lib/print.dsa diff --git a/dsx_server/data/repos/example/repo/src/main.dsa b/dsx/dsx_server/data/repos/example/repo/src/main.dsa similarity index 100% rename from dsx_server/data/repos/example/repo/src/main.dsa rename to dsx/dsx_server/data/repos/example/repo/src/main.dsa diff --git a/dsx_server/doc/endpoints.md b/dsx/dsx_server/doc/endpoints.md similarity index 100% rename from dsx_server/doc/endpoints.md rename to dsx/dsx_server/doc/endpoints.md diff --git a/dsx_server/doc/structure.md b/dsx/dsx_server/doc/structure.md similarity index 100% rename from dsx_server/doc/structure.md rename to dsx/dsx_server/doc/structure.md diff --git a/dsx_server/src/server/error.rs b/dsx/dsx_server/src/error.rs similarity index 93% rename from dsx_server/src/server/error.rs rename to dsx/dsx_server/src/error.rs index 356fcdd..d7cdd0f 100644 --- a/dsx_server/src/server/error.rs +++ b/dsx/dsx_server/src/error.rs @@ -1,5 +1,5 @@ use common::build::BuildError; -use rocket::{Response, http::Status, response::Responder}; +use rocket::response::Responder; use serde::Serialize; #[derive(Debug, Serialize, Responder)] diff --git a/dsx_server/src/server/server.rs b/dsx/dsx_server/src/main.rs similarity index 98% rename from dsx_server/src/server/server.rs rename to dsx/dsx_server/src/main.rs index a42f35a..eb61fe6 100644 --- a/dsx_server/src/server/server.rs +++ b/dsx/dsx_server/src/main.rs @@ -5,7 +5,6 @@ use std::fs; use std::path::PathBuf; use std::sync::LazyLock; -use anyhow::anyhow; use rocket::Data; use rocket::data::ToByteUnit; use rocket::serde::json::Json; @@ -15,11 +14,11 @@ use rocket_dyn_templates::{Template, context}; use dotenv::dotenv; use serde::Serialize; -use tracing::{info, warn}; +use tracing::warn; use crate::error::ApiError; use crate::model::{Package, PackageMeta}; -use dsx::common::config::DsxConfig; +use dsx_common::config::DsxConfig; mod error; mod model; diff --git a/dsx_server/src/server/model.rs b/dsx/dsx_server/src/model.rs similarity index 99% rename from dsx_server/src/server/model.rs rename to dsx/dsx_server/src/model.rs index f152d14..1407d43 100644 --- a/dsx_server/src/server/model.rs +++ b/dsx/dsx_server/src/model.rs @@ -1,7 +1,7 @@ use std::fs; use std::path::PathBuf; -use dsx::common::config::DsxConfig; +use dsx_common::config::DsxConfig; use serde::{Deserialize, Serialize}; use crate::{DATA_DIR, error::ApiError}; diff --git a/dsx_server/static/placeholder.jpg b/dsx/dsx_server/static/placeholder.jpg similarity index 100% rename from dsx_server/static/placeholder.jpg rename to dsx/dsx_server/static/placeholder.jpg diff --git a/dsx_server/templates/artifact_detail.html.tera b/dsx/dsx_server/templates/artifact_detail.html.tera similarity index 100% rename from dsx_server/templates/artifact_detail.html.tera rename to dsx/dsx_server/templates/artifact_detail.html.tera diff --git a/dsx_server/templates/artifact_list.html.tera b/dsx/dsx_server/templates/artifact_list.html.tera similarity index 100% rename from dsx_server/templates/artifact_list.html.tera rename to dsx/dsx_server/templates/artifact_list.html.tera diff --git a/dsx_server/templates/base.html.tera b/dsx/dsx_server/templates/base.html.tera similarity index 100% rename from dsx_server/templates/base.html.tera rename to dsx/dsx_server/templates/base.html.tera diff --git a/dsx_server/templates/components/file.html.tera b/dsx/dsx_server/templates/components/file.html.tera similarity index 100% rename from dsx_server/templates/components/file.html.tera rename to dsx/dsx_server/templates/components/file.html.tera diff --git a/dsx_server/templates/components/file_tree.html.tera b/dsx/dsx_server/templates/components/file_tree.html.tera similarity index 100% rename from dsx_server/templates/components/file_tree.html.tera rename to dsx/dsx_server/templates/components/file_tree.html.tera diff --git a/dsx_server/templates/components/sidebar.html.tera b/dsx/dsx_server/templates/components/sidebar.html.tera similarity index 100% rename from dsx_server/templates/components/sidebar.html.tera rename to dsx/dsx_server/templates/components/sidebar.html.tera diff --git a/dsx_server/templates/package_home.html.tera b/dsx/dsx_server/templates/package_home.html.tera similarity index 100% rename from dsx_server/templates/package_home.html.tera rename to dsx/dsx_server/templates/package_home.html.tera diff --git a/dsx_server/templates/packages.html.tera b/dsx/dsx_server/templates/packages.html.tera similarity index 100% rename from dsx_server/templates/packages.html.tera rename to dsx/dsx_server/templates/packages.html.tera diff --git a/dsx_server/templates/repo_path.html.tera b/dsx/dsx_server/templates/repo_path.html.tera similarity index 100% rename from dsx_server/templates/repo_path.html.tera rename to dsx/dsx_server/templates/repo_path.html.tera diff --git a/dsx_server/templates/repo_search.html.tera b/dsx/dsx_server/templates/repo_search.html.tera similarity index 100% rename from dsx_server/templates/repo_search.html.tera rename to dsx/dsx_server/templates/repo_search.html.tera diff --git a/dsx_server/src/lib.rs b/dsx_server/src/lib.rs deleted file mode 100644 index 34994bf..0000000 --- a/dsx_server/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod common; diff --git a/.dsa.emulator.toml b/emulator/.dsa.emulator.toml similarity index 100% rename from .dsa.emulator.toml rename to emulator/.dsa.emulator.toml diff --git a/emulator/Cargo.toml b/emulator/Cargo.toml index 911b66e..83e43dc 100644 --- a/emulator/Cargo.toml +++ b/emulator/Cargo.toml @@ -14,10 +14,11 @@ name = "emulator" required-features = ["config"] [dependencies] -common = { path = "../common" } -assembler = { path = "../assembler" } -compiler = { path = "../compiler" } -dsa_editor = { path = "../dsa_editor" } +common = { path = "../core/dsa_common" } +assembler = { path = "../core/assembler" } +compiler = { path = "../core/compiler" } +dsa_editor = { path = "./dsa_editor" } + egui = "0.31.1" dirs = "6.0.0" discord-presence = { version = "2.0.0", optional = true } diff --git a/dsa_editor/Cargo.toml b/emulator/dsa_editor/Cargo.toml similarity index 100% rename from dsa_editor/Cargo.toml rename to emulator/dsa_editor/Cargo.toml diff --git a/dsa_editor/src/highlighting.rs b/emulator/dsa_editor/src/highlighting.rs similarity index 100% rename from dsa_editor/src/highlighting.rs rename to emulator/dsa_editor/src/highlighting.rs diff --git a/dsa_editor/src/lib.rs b/emulator/dsa_editor/src/lib.rs similarity index 100% rename from dsa_editor/src/lib.rs rename to emulator/dsa_editor/src/lib.rs diff --git a/dsa_editor/src/syntax/dsa.rs b/emulator/dsa_editor/src/syntax/dsa.rs similarity index 100% rename from dsa_editor/src/syntax/dsa.rs rename to emulator/dsa_editor/src/syntax/dsa.rs diff --git a/dsa_editor/src/syntax/dsc.rs b/emulator/dsa_editor/src/syntax/dsc.rs similarity index 100% rename from dsa_editor/src/syntax/dsc.rs rename to emulator/dsa_editor/src/syntax/dsc.rs diff --git a/dsa_editor/src/syntax/mod.rs b/emulator/dsa_editor/src/syntax/mod.rs similarity index 100% rename from dsa_editor/src/syntax/mod.rs rename to emulator/dsa_editor/src/syntax/mod.rs diff --git a/dsa_editor/src/themes/mod.rs b/emulator/dsa_editor/src/themes/mod.rs similarity index 100% rename from dsa_editor/src/themes/mod.rs rename to emulator/dsa_editor/src/themes/mod.rs diff --git a/dsa_editor/src/themes/theme.rs b/emulator/dsa_editor/src/themes/theme.rs similarity index 100% rename from dsa_editor/src/themes/theme.rs rename to emulator/dsa_editor/src/themes/theme.rs diff --git a/emulator/src/emulator/cli.rs b/emulator/src/emulator/cli.rs index 16de7cb..cf00453 100644 --- a/emulator/src/emulator/cli.rs +++ b/emulator/src/emulator/cli.rs @@ -1,10 +1,9 @@ -use std::path::Path; use std::thread::sleep; use std::time::Duration; use std::{env, fs}; +use crate::emulator::system::model::State; use crate::emulator::system::model::{Command, Running}; -use crate::emulator::{config::Config, system::model::State}; pub fn run_cli() -> Result<(), Box> { // Initialize channels and read in configuration. @@ -34,8 +33,11 @@ pub fn run_cli() -> Result<(), Box> { sleep(Duration::from_secs(1)); - state.update().unwrap(); - state.cmd_sender.send(Command::Start).unwrap(); + state.update().expect("state failed to update"); + state + .cmd_sender + .send(Command::Start) + .expect("state failed to update"); loop { sleep(Duration::from_millis(20)); state.send(Command::DisplayRequest); diff --git a/emulator/src/emulator/system/emulator.rs b/emulator/src/emulator/system/emulator.rs index eefed5f..a93aeae 100644 --- a/emulator/src/emulator/system/emulator.rs +++ b/emulator/src/emulator/system/emulator.rs @@ -114,7 +114,7 @@ pub fn run_emulator( processor.memory.write_range(offset, data); } Command::Interrupt(_interrupt) => { - update = true; + // update = true; todo!("implement interrupts") }