Compare commits
3 Commits
main
...
a1d7b54479
| Author | SHA1 | Date | |
|---|---|---|---|
| a1d7b54479 | |||
| 7117b927f3 | |||
| 4ed5da259e |
@@ -19,6 +19,11 @@
|
||||
"command": "cargo run --bin dsx-build",
|
||||
"use_new_terminal": true,
|
||||
},
|
||||
{
|
||||
"label": "Check All",
|
||||
"command": "cargo clippy --all-targets",
|
||||
"use_new_terminal": false,
|
||||
},
|
||||
{
|
||||
"label": "Build All (Release)",
|
||||
"command": "cargo build --release",
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
cargo-features = ["codegen-backend"]
|
||||
|
||||
[workspace]
|
||||
members = ["emulator", "common", "assembler", "dsa_editor", "compiler", "dsx-build"]
|
||||
members = ["emulator", "common", "assembler", "dsa_editor", "compiler", "dsx_server"]
|
||||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
|
||||
@@ -10,7 +10,10 @@ use std::{
|
||||
};
|
||||
|
||||
pub use common::logging::log;
|
||||
use common::prelude::Instruction;
|
||||
use common::{
|
||||
build::{BuildError, Builder},
|
||||
prelude::Instruction,
|
||||
};
|
||||
|
||||
// Module declarations
|
||||
#[macro_use]
|
||||
@@ -37,17 +40,27 @@ pub use self::{
|
||||
|
||||
use crate::util::logging::{Entry, Logger};
|
||||
|
||||
pub struct CompilerEngine {
|
||||
result_tx: mpsc::Sender<Result<Vec<Instruction>, AssembleError>>,
|
||||
result_rx: Option<mpsc::Receiver<Result<Vec<Instruction>, AssembleError>>>,
|
||||
pub struct Assembler {
|
||||
src_path: PathBuf,
|
||||
result_tx: mpsc::Sender<Result<Vec<u8>, AssembleError>>,
|
||||
result_rx: Option<mpsc::Receiver<Result<Vec<u8>, AssembleError>>>,
|
||||
is_running: bool,
|
||||
}
|
||||
|
||||
impl CompilerEngine {
|
||||
impl From<AssembleError> for BuildError {
|
||||
fn from(err: AssembleError) -> Self {
|
||||
Self::Generic(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl Builder for Assembler {
|
||||
type Output = Vec<u8>;
|
||||
|
||||
#[must_use]
|
||||
pub fn new() -> Self {
|
||||
fn new(src_path: impl Into<PathBuf>) -> Self {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
Self {
|
||||
src_path: src_path.into(),
|
||||
result_tx: tx,
|
||||
result_rx: Some(rx),
|
||||
is_running: false,
|
||||
@@ -55,25 +68,29 @@ impl CompilerEngine {
|
||||
}
|
||||
|
||||
/// Start the compilation process in a separate thread
|
||||
pub fn start_compilation(&mut self, src: &Path) {
|
||||
fn start(&mut self) {
|
||||
if self.is_running {
|
||||
return;
|
||||
}
|
||||
|
||||
let src = src.to_path_buf();
|
||||
let src = self.src_path.clone();
|
||||
let tx = self.result_tx.clone();
|
||||
|
||||
thread::spawn(move || {
|
||||
let result = assemble(&src);
|
||||
tx.send(result)
|
||||
.expect("Failed to send compilation result from worker thread");
|
||||
if let Ok(res) = assemble(&src) {
|
||||
let buffer: Vec<u8> = res
|
||||
.iter()
|
||||
.flat_map(|instruction| instruction.encode().to_be_bytes())
|
||||
.collect();
|
||||
tx.send(Ok(buffer))
|
||||
.expect("Failed to send compilation result from worker thread");
|
||||
}
|
||||
});
|
||||
|
||||
self.is_running = true;
|
||||
}
|
||||
|
||||
/// Check if compilation is complete and get the result
|
||||
pub fn try_get_result(&mut self) -> Option<Result<Vec<Instruction>, AssembleError>> {
|
||||
fn poll(&mut self) -> Option<Result<Self::Output, common::build::BuildError>> {
|
||||
if !self.is_running {
|
||||
return None;
|
||||
}
|
||||
@@ -86,22 +103,20 @@ impl CompilerEngine {
|
||||
{
|
||||
Ok(result) => {
|
||||
self.is_running = false;
|
||||
Some(result)
|
||||
Some(result.map_err(std::convert::Into::into))
|
||||
}
|
||||
Err(mpsc::TryRecvError::Empty) => None,
|
||||
Err(mpsc::TryRecvError::Disconnected) => {
|
||||
self.is_running = false;
|
||||
Some(Err(AssembleError::Generic))
|
||||
Some(Err(BuildError::Generic(String::from(
|
||||
"Compilation terminated before a result was returned",
|
||||
))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Block until compilation is complete and return the result
|
||||
pub fn wait_for_result(&mut self) -> Result<Vec<Instruction>, AssembleError> {
|
||||
if !self.is_running {
|
||||
return Err(AssembleError::Generic);
|
||||
}
|
||||
|
||||
fn output(&mut self) -> Result<Self::Output, common::build::BuildError> {
|
||||
if let Ok(result) = self
|
||||
.result_rx
|
||||
.take()
|
||||
@@ -109,14 +124,18 @@ impl CompilerEngine {
|
||||
.recv()
|
||||
{
|
||||
self.is_running = false;
|
||||
result
|
||||
result.map_err(std::convert::Into::into)
|
||||
} else {
|
||||
self.is_running = false;
|
||||
Err(AssembleError::Generic)
|
||||
Err(BuildError::Generic(String::from(
|
||||
"Compilation terminated before a result was returned",
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Assembler {}
|
||||
|
||||
fn assemble(src: &Path) -> Result<Vec<Instruction>, AssembleError> {
|
||||
let mut modules = HashSet::new();
|
||||
let mut program = Program::new();
|
||||
@@ -142,12 +161,6 @@ fn assemble(src: &Path) -> Result<Vec<Instruction>, AssembleError> {
|
||||
Ok(instructions)
|
||||
}
|
||||
|
||||
impl Default for CompilerEngine {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
fn prepare_dependency(
|
||||
path: &Path,
|
||||
modules: &mut HashSet<u64>,
|
||||
|
||||
+1
-26
@@ -18,33 +18,8 @@ pub mod tooling;
|
||||
mod util;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::assembler::CompilerEngine;
|
||||
pub use crate::assembler::Assembler;
|
||||
pub use crate::image_builder;
|
||||
pub use crate::tooling::brainf;
|
||||
pub use crate::tooling::project;
|
||||
}
|
||||
|
||||
use std::{fs, path::Path};
|
||||
|
||||
use num_cpus as _;
|
||||
use threadpool as _;
|
||||
|
||||
use crate::prelude::CompilerEngine;
|
||||
|
||||
pub fn assemble_file(input: &str, output: &str) -> Result<(), std::io::Error> {
|
||||
let mut engine = CompilerEngine::new();
|
||||
engine.start_compilation(Path::new(input));
|
||||
let result = engine.wait_for_result().expect("assembler failed.");
|
||||
|
||||
let buffer: Vec<u8> = result
|
||||
.iter()
|
||||
.flat_map(|instruction| instruction.encode().to_be_bytes())
|
||||
.collect();
|
||||
|
||||
if let Err(e) = fs::write(output, buffer) {
|
||||
eprintln!("Failed to write to output file: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+10
-5
@@ -1,9 +1,6 @@
|
||||
use common as _;
|
||||
use num_cpus as _;
|
||||
use threadpool as _;
|
||||
use common::{self as _, build::Builder};
|
||||
|
||||
use assembler::{
|
||||
assemble_file,
|
||||
prelude::*,
|
||||
tooling::{brainf, project},
|
||||
};
|
||||
@@ -47,5 +44,13 @@ fn main() {
|
||||
|
||||
let input_path = &args[2];
|
||||
let output_path = &args[4];
|
||||
assemble_file(input_path, output_path).unwrap();
|
||||
|
||||
let mut engine = Assembler::new(PathBuf::from(input_path));
|
||||
engine.start();
|
||||
let result = engine.output().expect("assembler failed.");
|
||||
|
||||
if let Err(e) = fs::write(output_path, result) {
|
||||
eprintln!("Failed to write to output file: {e}");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
use std::{
|
||||
fmt,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum BuildError {
|
||||
IoError(String),
|
||||
Generic(String),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for BuildError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
Self::IoError(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Box<dyn std::error::Error>> for BuildError {
|
||||
fn from(err: Box<dyn std::error::Error>) -> Self {
|
||||
Self::Generic(err.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for BuildError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::IoError(err) => write!(f, "IO Error: {err}"),
|
||||
Self::Generic(err) => write!(f, "Generic Error: {err}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Builder {
|
||||
type Output: Clone + std::convert::AsRef<[u8]>;
|
||||
|
||||
fn new(src_path: impl Into<PathBuf>) -> Self;
|
||||
|
||||
// starts compilation
|
||||
fn start(&mut self);
|
||||
|
||||
// non-blocking function, returns output if completed
|
||||
fn poll(&mut self) -> Option<Result<Self::Output, BuildError>>;
|
||||
|
||||
// blocking function, returns output when completed.
|
||||
fn output(&mut self) -> Result<Self::Output, BuildError>;
|
||||
|
||||
fn write_result(&mut self, path: impl AsRef<Path>) -> Result<(), BuildError> {
|
||||
let output = self.output()?;
|
||||
std::fs::write(path.as_ref(), output)
|
||||
.map_err(|e| BuildError::IoError(e.to_string()))
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@
|
||||
clippy::match_wildcard_for_single_variants
|
||||
)]
|
||||
|
||||
pub mod build;
|
||||
pub mod instructions;
|
||||
pub mod logging;
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ mod codegen;
|
||||
mod instruction;
|
||||
mod registers;
|
||||
mod scope;
|
||||
mod variable;
|
||||
|
||||
pub fn generate_code(ast: &Program) -> Result<String, CompilerError> {
|
||||
let mut codegen = codegen::CodeGenerator::new(ast.clone());
|
||||
|
||||
+273
-166
@@ -1,49 +1,211 @@
|
||||
use std::{cell::RefCell, collections::HashMap, ops::Deref, rc::Rc};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
backend::dsa::{
|
||||
instruction::{InsBlock, Instruction},
|
||||
registers::{Register, RegisterAllocator},
|
||||
variable::Variable,
|
||||
},
|
||||
model::CompilerError,
|
||||
error,
|
||||
model::{CompilerError, Name, TypeId},
|
||||
};
|
||||
|
||||
/// scope object
|
||||
pub struct Scope<'a> {
|
||||
/// outer scope, for a function this will be the global scope.
|
||||
parent: Option<&'a mut Scope<'a>>,
|
||||
alloc: Rc<RefCell<Allocator>>,
|
||||
|
||||
/// is the scope a function body or just a loop?
|
||||
/// depending on the type, ending a scope will have different behaviour
|
||||
r#type: ScopeType,
|
||||
|
||||
/// variables
|
||||
variables: HashMap<String, Variable>,
|
||||
|
||||
entry_stack_offset: i32,
|
||||
}
|
||||
|
||||
impl<'a> Scope<'a> {
|
||||
pub fn new() -> Scope<'a> {
|
||||
let alloc = Rc::new(RefCell::new(Allocator::new()));
|
||||
let entry_stack_offset = alloc.borrow().get_stack_offset();
|
||||
|
||||
Self {
|
||||
alloc,
|
||||
entry_stack_offset,
|
||||
parent: None,
|
||||
r#type: ScopeType::Function,
|
||||
variables: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_from(parent: &'a mut Scope<'a>, r#type: ScopeType) -> Scope<'a> {
|
||||
let alloc = Rc::clone(&parent.alloc);
|
||||
let entry_stack_offset = alloc.borrow().get_stack_offset();
|
||||
|
||||
Self {
|
||||
alloc,
|
||||
entry_stack_offset,
|
||||
parent: Some(parent),
|
||||
r#type,
|
||||
variables: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn create_var(
|
||||
&mut self,
|
||||
name: String,
|
||||
r#type: TypeId,
|
||||
) -> Result<(), CompilerError> {
|
||||
let mut var = Variable::new(name, r#type.clone());
|
||||
|
||||
if r#type.size() > 4 {
|
||||
let slot = self.alloc.borrow_mut().allocate_stack_slot(r#type.size());
|
||||
var.stack_slot = Some(slot);
|
||||
} else {
|
||||
let reg = self.alloc.borrow_mut().allocate_var()?;
|
||||
var.register = Some(reg);
|
||||
}
|
||||
|
||||
self.variables.insert(var.name.clone(), var);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn alloc_temp(&mut self) -> Result<TempReg, CompilerError> {
|
||||
self.alloc.borrow_mut().allocate_temp()
|
||||
}
|
||||
|
||||
pub fn free_temp(&mut self, temp: &TempReg) {
|
||||
self.alloc.borrow_mut().free_temp(temp)
|
||||
}
|
||||
|
||||
pub fn free_var(&mut self, reg: &AssignedReg) {
|
||||
self.alloc.borrow_mut().free_var(reg);
|
||||
}
|
||||
|
||||
pub fn close(&mut self) {
|
||||
// tell the allocator that this scope is closing
|
||||
// this reverts the stack offset to what it was before this scope was created.
|
||||
self.alloc.clone().borrow_mut().destroy_scope(self);
|
||||
|
||||
for var in self.variables.clone().values() {
|
||||
if let Some(reg) = var.register {
|
||||
self.free_var(®);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn get_var(&mut self, var: &str) -> Option<&mut Variable> {
|
||||
self.variables.get_mut(var)
|
||||
}
|
||||
|
||||
pub fn offset_read(
|
||||
&mut self,
|
||||
var: &str,
|
||||
offset: i32,
|
||||
) -> Result<(TempReg, Instruction), CompilerError> {
|
||||
if let Some(var) = self.get_var(var) {
|
||||
let slot = var.stack_slot.ok_or_else(|| {
|
||||
error("Attempt to read from a var without a stack slot!")
|
||||
})?;
|
||||
|
||||
return self.alloc.borrow_mut().offset_read(&slot, offset);
|
||||
}
|
||||
|
||||
Err(CompilerError::Undefined(Name::new(var, None)))
|
||||
}
|
||||
|
||||
pub fn offset_write(
|
||||
&mut self,
|
||||
reg: &TempReg,
|
||||
var: &str,
|
||||
offset: i32,
|
||||
) -> Result<Instruction, CompilerError> {
|
||||
if let Some(var) = self.get_var(var) {
|
||||
let slot = var.stack_slot.ok_or_else(|| {
|
||||
error("Attempt to write to a var without a stack slot!")
|
||||
})?;
|
||||
|
||||
return Ok(self.alloc.borrow_mut().offset_write(reg, &slot, offset));
|
||||
}
|
||||
|
||||
Err(CompilerError::Undefined(Name::new(var, None)))
|
||||
}
|
||||
|
||||
pub fn load_var(
|
||||
&mut self,
|
||||
var: &str,
|
||||
) -> Result<(AssignedReg, Instruction), CompilerError> {
|
||||
if let Some(v) = self.get_var(var).cloned()
|
||||
&& let Some(slot) = v.stack_slot
|
||||
{
|
||||
let res = self.alloc.borrow_mut().load_var(&slot)?;
|
||||
self.get_var(var).unwrap().register = Some(res.0);
|
||||
return Ok(res);
|
||||
}
|
||||
|
||||
panic!("e")
|
||||
}
|
||||
|
||||
pub fn spill_var(&mut self, var: &str) -> Result<Instruction, CompilerError> {
|
||||
if let Some(v) = self.get_var(var).cloned()
|
||||
&& let Some(rg) = v.register
|
||||
{
|
||||
let mut slot = v.stack_slot;
|
||||
let res = self.alloc.borrow_mut().spill_var(&rg, &mut slot);
|
||||
self.get_var(var).unwrap().stack_slot = slot;
|
||||
return res;
|
||||
}
|
||||
|
||||
Err(CompilerError::Undefined(Name::new(var, None)))
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Scope<'_> {
|
||||
fn drop(&mut self) {
|
||||
self.close()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
pub enum ScopeType {
|
||||
Function,
|
||||
IfBlock,
|
||||
LoopBlock,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Variable {
|
||||
pub name: String,
|
||||
|
||||
/// the type of the variable.
|
||||
r#type: TypeId,
|
||||
|
||||
/// size taken up in bytes.
|
||||
/// if size > 4, value must be stored on the stack.
|
||||
pub size: usize,
|
||||
|
||||
pub stack_slot: Option<StackSlot>,
|
||||
pub register: Option<AssignedReg>,
|
||||
}
|
||||
|
||||
impl Variable {
|
||||
pub fn new(name: String, r#type: TypeId) -> Self {
|
||||
Self {
|
||||
name,
|
||||
size: r#type.size(),
|
||||
r#type,
|
||||
stack_slot: None,
|
||||
register: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Allocator {
|
||||
stack_offset: i32,
|
||||
in_use: [(Register, bool); 16],
|
||||
}
|
||||
|
||||
pub struct TempReg(Register);
|
||||
pub struct AssignedReg(Register);
|
||||
pub struct StackSlot(i32);
|
||||
|
||||
impl Deref for TempReg {
|
||||
type Target = Register;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for AssignedReg {
|
||||
type Target = Register;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for StackSlot {
|
||||
type Target = i32;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Allocator {
|
||||
pub fn new() -> Self {
|
||||
let mut in_use = [(Register::Null, false); 16];
|
||||
@@ -64,7 +226,7 @@ impl Allocator {
|
||||
|
||||
for var in scope.variables.drain() {
|
||||
if let Some(assigned) = var.1.register {
|
||||
self.free_assigned(&assigned);
|
||||
self.free_var(&assigned);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,71 +244,74 @@ impl Allocator {
|
||||
//
|
||||
// - read / write bytes from the stack+offset in a larger variable into a register.
|
||||
|
||||
pub fn read_var(&mut self, var: &mut Variable) -> Result<InsBlock, CompilerError> {
|
||||
if let Some(slot) = &mut var.stack_slot {
|
||||
if var.register.is_none() {
|
||||
var.register = Some(self.allocate_var()?);
|
||||
}
|
||||
pub fn offset_read(
|
||||
&mut self,
|
||||
slot: &StackSlot,
|
||||
offset: i32,
|
||||
) -> Result<(TempReg, Instruction), CompilerError> {
|
||||
let register = self.allocate_temp()?;
|
||||
|
||||
if let Some(reg) = &var.register {
|
||||
return Ok(InsBlock::from(Instruction::ldw_reg_offset(
|
||||
**reg,
|
||||
Register::Spr,
|
||||
**slot - self.stack_offset,
|
||||
)));
|
||||
}
|
||||
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
Err(CompilerError::Generic(format!(
|
||||
"Tried to write var {} to stack but var was not assigned a reg and/or stack slot",
|
||||
var.name
|
||||
)))
|
||||
// instruction: reg = *(&var + offset)
|
||||
Ok((
|
||||
register.clone(),
|
||||
Instruction::ldw_reg_offset(
|
||||
Register::Spr,
|
||||
*register,
|
||||
(**slot + offset) - self.stack_offset,
|
||||
),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn write_var(&mut self, var: &mut Variable) -> Result<InsBlock, CompilerError> {
|
||||
if let Some(slot) = &var.stack_slot {
|
||||
if let Some(reg) = &var.register {
|
||||
return Ok(InsBlock::from(Instruction::stw_reg_offset(
|
||||
**reg,
|
||||
Register::Spr,
|
||||
**slot - self.stack_offset,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
Err(CompilerError::Generic(format!(
|
||||
"Tried to write var {} to stack but var was not assigned a reg and/or stack slot",
|
||||
var.name
|
||||
)))
|
||||
pub fn offset_write(
|
||||
&mut self,
|
||||
reg: &TempReg,
|
||||
slot: &StackSlot,
|
||||
offset: i32,
|
||||
) -> Instruction {
|
||||
// instruction: *(&var + offset) = reg
|
||||
Instruction::stw_reg_offset(
|
||||
**reg,
|
||||
Register::Spr,
|
||||
(**slot + offset) - self.stack_offset,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn spill_var(&mut self, var: &mut Variable) -> Result<InsBlock, CompilerError> {
|
||||
if let Some(slot) = &var.stack_slot {
|
||||
let block = self.write_var(var)?;
|
||||
if let Some(reg) = &var.register {
|
||||
self.free_assigned(reg);
|
||||
var.register = None;
|
||||
}
|
||||
pub fn load_var(
|
||||
&mut self,
|
||||
slot: &StackSlot,
|
||||
) -> Result<(AssignedReg, Instruction), CompilerError> {
|
||||
let reg = self.allocate_var()?;
|
||||
|
||||
Ok((
|
||||
reg.clone(),
|
||||
Instruction::ldw_reg_offset(Register::Spr, *reg, **slot - self.stack_offset),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn spill_var(
|
||||
&mut self,
|
||||
reg: &AssignedReg,
|
||||
slot: &mut Option<StackSlot>,
|
||||
// var: &mut Variable,
|
||||
) -> Result<Instruction, CompilerError> {
|
||||
if let Some(slot) = &slot {
|
||||
let block = Instruction::stw_reg_offset(
|
||||
**reg,
|
||||
Register::Spr,
|
||||
**slot - self.stack_offset,
|
||||
);
|
||||
|
||||
self.free_var(reg);
|
||||
return Ok(block);
|
||||
}
|
||||
|
||||
// var doesn't have a stack slot so we need to create one
|
||||
if let Some(reg) = &var.register {
|
||||
let slot = self.allocate_stack_slot(var.size);
|
||||
let block = InsBlock::from(Instruction::push(**reg));
|
||||
let new_slot = self.allocate_stack_slot(4); // alloc 4 bytes for reg value.
|
||||
let block = Instruction::push(**reg);
|
||||
|
||||
self.free_assigned(reg);
|
||||
var.register = None;
|
||||
var.stack_slot = Some(slot);
|
||||
return Ok(block);
|
||||
}
|
||||
|
||||
return Err(CompilerError::Generic(
|
||||
"spill_var called on a variable without a register".to_string(),
|
||||
));
|
||||
self.free_var(reg);
|
||||
*slot = Some(new_slot);
|
||||
Ok(block)
|
||||
}
|
||||
|
||||
pub fn allocate_stack_slot(&mut self, size: usize) -> StackSlot {
|
||||
@@ -179,7 +344,7 @@ impl Allocator {
|
||||
self.in_use[**temp as usize].1 = false;
|
||||
}
|
||||
|
||||
fn free_assigned(&mut self, reg: &AssignedReg) {
|
||||
pub fn free_var(&mut self, reg: &AssignedReg) {
|
||||
// frees a register.
|
||||
self.in_use[**reg as usize].1 = false;
|
||||
}
|
||||
@@ -197,91 +362,33 @@ impl Allocator {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FunctionContext {
|
||||
name: String,
|
||||
allocator: RefCell<Allocator>,
|
||||
}
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct TempReg(Register);
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct AssignedReg(Register);
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct StackSlot(i32);
|
||||
|
||||
impl FunctionContext {
|
||||
pub fn new(name: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
allocator: RefCell::new(Allocator::new()),
|
||||
}
|
||||
}
|
||||
impl Deref for TempReg {
|
||||
type Target = Register;
|
||||
|
||||
pub fn get_stack_offset(&self) -> i32 {
|
||||
self.allocator.borrow().get_stack_offset()
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// scope object
|
||||
pub struct Scope<'a> {
|
||||
/// outer scope, for a function this will be the global scope.
|
||||
parent: Option<&'a mut Scope<'a>>,
|
||||
impl Deref for AssignedReg {
|
||||
type Target = Register;
|
||||
|
||||
context: Rc<FunctionContext>,
|
||||
|
||||
/// is the scope a function body or just a loop?
|
||||
/// depending on the type, ending a scope will have different behaviour
|
||||
r#type: ScopeType,
|
||||
|
||||
/// variables
|
||||
variables: HashMap<Uuid, Variable>,
|
||||
|
||||
entry_stack_offset: i32,
|
||||
}
|
||||
|
||||
impl<'a> Scope<'a> {
|
||||
pub fn new(parent: &'a mut Scope<'a>, r#type: ScopeType) -> Scope<'a> {
|
||||
Self {
|
||||
entry_stack_offset: parent.context.get_stack_offset(),
|
||||
context: Rc::clone(&parent.context),
|
||||
parent: Some(parent),
|
||||
r#type,
|
||||
variables: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn close(&mut self) -> Result<(), CompilerError> {
|
||||
// closing a scope means we need to drop all variables in scope and free
|
||||
// registers.
|
||||
for (name, var) in self.variables.iter() {
|
||||
todo!()
|
||||
// if let Some(reg) = var.allocated_register {}
|
||||
|
||||
// if let Some(offset) = var.bpr_offset {
|
||||
// self.stack_offset -= offset;
|
||||
// }
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn alloc_temp_reg(&mut self) -> Result<(Register, InsBlock), CompilerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn alloc_var_reg(&mut self) -> Result<(Register, InsBlock), CompilerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn alloc_var_stack(&mut self) -> Result<(Register, InsBlock), CompilerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn free_var_stack(&mut self) -> Result<(Register, InsBlock), CompilerError> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub fn free_temp_reg(&mut self) -> Result<(Register, InsBlock), CompilerError> {
|
||||
todo!()
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
pub enum ScopeType {
|
||||
Function,
|
||||
IfBlock,
|
||||
LoopBlock,
|
||||
impl Deref for StackSlot {
|
||||
type Target = i32;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
use std::{collections::HashMap, hash::Hash, rc::Rc};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
backend::dsa::{
|
||||
instruction::InsBlock,
|
||||
registers::Register,
|
||||
scope::{AssignedReg, FunctionContext, Scope, StackSlot},
|
||||
},
|
||||
model::{CompilerError, TypeId},
|
||||
};
|
||||
|
||||
pub struct Variable {
|
||||
pub name: String,
|
||||
pub uuid: Uuid,
|
||||
|
||||
/// the type of the variable.
|
||||
r#type: TypeId,
|
||||
|
||||
/// size taken up in bytes.
|
||||
/// if size > 4, value must be stored on the stack.
|
||||
pub size: usize,
|
||||
|
||||
pub stack_slot: Option<StackSlot>,
|
||||
pub register: Option<AssignedReg>,
|
||||
}
|
||||
|
||||
impl Variable {
|
||||
pub fn new_uninit(name: String, r#type: TypeId) -> Self {
|
||||
Self {
|
||||
name,
|
||||
uuid: Uuid::new_v4(),
|
||||
size: r#type.size(),
|
||||
r#type,
|
||||
stack_slot: None,
|
||||
register: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
name: String,
|
||||
r#type: TypeId,
|
||||
scope: &'_ mut Scope,
|
||||
) -> Result<Self, CompilerError> {
|
||||
let mut var = Self::new_uninit(name, r#type);
|
||||
var.alloc_default(scope);
|
||||
|
||||
Ok(var)
|
||||
}
|
||||
|
||||
fn alloc_default(&mut self, scope: &'_ mut Scope) {
|
||||
if self.size > 4 {
|
||||
self.alloc_stack(scope).unwrap();
|
||||
} else {
|
||||
self.alloc_register(scope).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn alloc_register(
|
||||
&mut self,
|
||||
scope: &'_ mut Scope,
|
||||
) -> Result<Register, CompilerError> {
|
||||
if self.size > 4 {
|
||||
return Err(CompilerError::Generic(format!(
|
||||
"Type {} cannot be allocated a register as it has a size of {} bytes",
|
||||
self.r#type, self.size
|
||||
)));
|
||||
}
|
||||
|
||||
todo!("integrate with register alloc logic")
|
||||
|
||||
// self.allocated_register = Some(...)
|
||||
}
|
||||
|
||||
fn alloc_stack(&mut self, scope: &'_ mut Scope) -> Result<usize, CompilerError> {
|
||||
todo!("integrate with stack alloc logic")
|
||||
|
||||
// self.bpr_offset = Some(...)
|
||||
}
|
||||
|
||||
pub fn load(&mut self, scope: &'_ mut Scope) -> Result<Register, CompilerError> {
|
||||
todo!("load var from stack to reg (if possible)")
|
||||
}
|
||||
|
||||
pub fn drop(&mut self, scope: &'_ mut Scope) -> Result<(), CompilerError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn spill(&mut self, scope: &'_ mut Scope) -> Result<(), CompilerError> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
+64
-50
@@ -1,72 +1,86 @@
|
||||
#![feature(try_trait_v2)]
|
||||
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use common::logging::log;
|
||||
use common::{
|
||||
build::{BuildError, Builder},
|
||||
logging::log,
|
||||
};
|
||||
|
||||
use crate::specialised::build_specialised;
|
||||
use crate::{model::CompilerError, specialised::build_specialised};
|
||||
|
||||
mod backend;
|
||||
mod frontend;
|
||||
mod model;
|
||||
mod specialised;
|
||||
|
||||
pub fn compile_file(
|
||||
input_path: &Path,
|
||||
output_path: &Path,
|
||||
) -> Result<(), Box<dyn std::error::Error>> {
|
||||
let input = std::fs::read_to_string(input_path).expect("Failed to read input file");
|
||||
pub struct Compiler {
|
||||
src_path: PathBuf,
|
||||
result: Option<Result<String, BuildError>>,
|
||||
}
|
||||
|
||||
let input_ext = input_path
|
||||
.extension()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("");
|
||||
impl Compiler {
|
||||
fn build(&mut self) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let input =
|
||||
std::fs::read_to_string(&self.src_path).expect("Failed to read input file");
|
||||
|
||||
// check if we're using a specialised compiler
|
||||
if let Some(output) = build_specialised(input_ext, &input) {
|
||||
let result = match output {
|
||||
Ok(output) => output,
|
||||
let input_ext = self
|
||||
.src_path
|
||||
.extension()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("");
|
||||
|
||||
// check if we're using a specialised compiler
|
||||
if let Some(output) = build_specialised(input_ext, &input) {
|
||||
return output.map_err(|err| format!("Compilation failed: {err:?}").into());
|
||||
}
|
||||
|
||||
// Parse the input using the frontend, providing the file extension and data.
|
||||
let ast = match frontend::compiler_frontend(input_ext, &input) {
|
||||
Ok(ast) => ast,
|
||||
Err(err) => return Err(format!("Compilation failed: {err:?}").into()),
|
||||
};
|
||||
|
||||
std::fs::write(output_path, &result).expect("Failed to write output");
|
||||
// println!("Parsed AST: {:#?}", ast);
|
||||
|
||||
log(&format!(
|
||||
"Compilation Successful ✅ \n\tSource: {}\n\tOutput: {}\n",
|
||||
input_path.display(),
|
||||
output_path.display(),
|
||||
));
|
||||
// Generate the output using the backend with the parsed result.
|
||||
let result = match backend::compiler_backend("dsa", &ast) {
|
||||
Ok(result) => result,
|
||||
Err(err) => return Err(format!("Compilation failed: {err:?}").into()),
|
||||
};
|
||||
|
||||
return Ok(());
|
||||
Ok(result)
|
||||
}
|
||||
}
|
||||
|
||||
impl Builder for Compiler {
|
||||
type Output = String;
|
||||
|
||||
fn new(src_path: impl Into<PathBuf>) -> Self {
|
||||
Self {
|
||||
src_path: src_path.into(),
|
||||
result: None,
|
||||
}
|
||||
}
|
||||
|
||||
// Parse the input using the frontend, providing the file extension and data.
|
||||
let ast = match frontend::compiler_frontend(input_ext, &input) {
|
||||
Ok(ast) => ast,
|
||||
Err(err) => return Err(format!("Compilation failed: {err:?}").into()),
|
||||
};
|
||||
fn start(&mut self) {
|
||||
match self.build() {
|
||||
Ok(x) => self.result = Some(Ok(x)),
|
||||
Err(err) => self.result = Some(Err(err.into())),
|
||||
}
|
||||
}
|
||||
|
||||
println!("Parsed AST: {:#?}", ast);
|
||||
fn poll(&mut self) -> Option<Result<Self::Output, BuildError>> {
|
||||
self.result.take()
|
||||
}
|
||||
|
||||
let output_ext = output_path
|
||||
.extension()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or("");
|
||||
|
||||
// Generate the output using the backend with the parsed result.
|
||||
let result = match backend::compiler_backend(output_ext, &ast) {
|
||||
Ok(result) => result,
|
||||
Err(err) => return Err(format!("Compilation failed: {err:?}").into()),
|
||||
};
|
||||
|
||||
// println!("{result}");
|
||||
std::fs::write(output_path, &result).expect("Failed to write output");
|
||||
|
||||
log(&format!(
|
||||
"Compilation Successful ✅ \n\tSource: {}\n\tOutput: {}\n",
|
||||
input_path.display(),
|
||||
output_path.display(),
|
||||
));
|
||||
|
||||
Ok(())
|
||||
fn output(&mut self) -> Result<Self::Output, BuildError> {
|
||||
self.result.clone().ok_or(BuildError::Generic(String::from(
|
||||
"Compiler was never started",
|
||||
)))?
|
||||
}
|
||||
}
|
||||
|
||||
pub fn error(msg: impl Into<String>) -> CompilerError {
|
||||
CompilerError::Generic(msg.into())
|
||||
}
|
||||
|
||||
+16
-2
@@ -1,4 +1,7 @@
|
||||
use std::path::Path;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use common::{build::Builder, logging::log};
|
||||
use compiler::Compiler;
|
||||
|
||||
fn main() {
|
||||
// read from input file: syntax "c_compiler <src.c> [output.dsa]"
|
||||
@@ -15,5 +18,16 @@ fn main() {
|
||||
"output.dsa"
|
||||
};
|
||||
|
||||
compiler::compile_file(Path::new(input_file), Path::new(output_file)).unwrap();
|
||||
{
|
||||
let mut builder = Compiler::new(PathBuf::from(input_file));
|
||||
builder.start();
|
||||
let result = builder.output().unwrap();
|
||||
|
||||
std::fs::write(output_file, &result).expect("Failed to write output");
|
||||
|
||||
log(&format!(
|
||||
"Compilation Successful ✅ \n\tSource: {}\n\tOutput: {}\n",
|
||||
input_file, output_file,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use core::fmt;
|
||||
|
||||
use common::build::BuildError;
|
||||
|
||||
#[allow(unused)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum CompilerError {
|
||||
@@ -14,6 +16,12 @@ pub enum CompilerError {
|
||||
Unimplemented(String),
|
||||
}
|
||||
|
||||
impl From<CompilerError> for BuildError {
|
||||
fn from(err: CompilerError) -> Self {
|
||||
BuildError::Generic(format!("{:?}", err))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone)]
|
||||
pub struct Name {
|
||||
pub name: String,
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
[package]
|
||||
name = "dsx-build"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
authors.workspace = true
|
||||
|
||||
[dependencies]
|
||||
compiler = { path = "../compiler" }
|
||||
assembler = { path = "../assembler" }
|
||||
chrono = "0.4.43"
|
||||
@@ -1,200 +0,0 @@
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{
|
||||
env, fs,
|
||||
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");
|
||||
if !status.success() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Very small CLI – only three sub‑commands.
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() < 2 {
|
||||
eprintln!("Usage: dsx-build <new|build|package> [options]");
|
||||
std::process::exit(1);
|
||||
}
|
||||
match args[1].as_str() {
|
||||
"new" => cmd_new(&args[2..]),
|
||||
"build" => cmd_build(),
|
||||
"package" => todo!("Package manager stub – not implemented yet."),
|
||||
_ => {
|
||||
eprintln!("Unknown command: {}", args[1]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- new project ----------------------------------------------------
|
||||
fn cmd_new(args: &[String]) {
|
||||
let mut lang = "dsa";
|
||||
for i in 0..args.len() {
|
||||
if args[i] == "--lang" && i + 1 < args.len() {
|
||||
lang = &args[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
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() {
|
||||
if args[i] == "--name" && i + 1 < args.len() {
|
||||
name_opt = Some(&args[i + 1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let project_name = match name_opt {
|
||||
Some(name) => name.to_string(),
|
||||
None => {
|
||||
eprintln!("Error: --name argument required");
|
||||
std::process::exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
let cwd = env::current_dir().unwrap();
|
||||
let src_path = cwd.join(&project_name).join("src");
|
||||
fs::create_dir_all(&src_path).expect("Failed to create project directory");
|
||||
|
||||
match lang {
|
||||
"dsa" => {
|
||||
// Minimal DSA binary template.
|
||||
let path = src_path.join(format!("main.dsa"));
|
||||
|
||||
let template = Dsa::create(&project_name, lib);
|
||||
|
||||
fs::write(path, template).expect("Unable to write DSA file");
|
||||
}
|
||||
"dsc" => {
|
||||
let path = src_path.join(format!("main.dsc"));
|
||||
|
||||
let template = Dsc::create(&project_name, lib);
|
||||
|
||||
fs::write(path, template).expect("Unable to write DSC file");
|
||||
}
|
||||
_ => {
|
||||
eprintln!("Unsupported language: {}", lang);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
src_path.parent().unwrap().display()
|
||||
);
|
||||
}
|
||||
|
||||
// ---------- build ----------------------------------------------------------
|
||||
fn cmd_build() {
|
||||
let cwd = env::current_dir().unwrap();
|
||||
|
||||
// Detect .dsc or .dsa files in current directory.
|
||||
let mut has_dsc = false;
|
||||
let mut has_dsa = false;
|
||||
for entry in fs::read_dir(&cwd.join("src")).expect("unable to read dir") {
|
||||
if let Ok(entry) = entry {
|
||||
let path = entry.path();
|
||||
if path.extension().and_then(|s| s.to_str()) == Some("dsc") {
|
||||
has_dsc = true;
|
||||
} else if path.extension().and_then(|s| s.to_str()) == Some("dsa") {
|
||||
has_dsa = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !has_dsc && !has_dsa {
|
||||
eprintln!("No .dsc or .dsa source found in src directory.");
|
||||
std::process::exit(1);
|
||||
}
|
||||
|
||||
// Assemble main.dsa to a dsb binary.
|
||||
println!("Assembling Project to a DSB binary...");
|
||||
let build_dir = cwd.join("build");
|
||||
fs::create_dir_all(&build_dir).expect("Failed to create build directory");
|
||||
|
||||
// Copy everything from `cwd/src` to the build directory.
|
||||
fn copy_recursively(src: &Path, dst: &Path) {
|
||||
if src.is_file() {
|
||||
fs::create_dir_all(dst.parent().unwrap())
|
||||
.expect("Failed to create parent directory");
|
||||
fs::copy(src, dst).expect("Failed to copy file");
|
||||
} else if src.is_dir() {
|
||||
for entry in fs::read_dir(src).expect("Unable to read source dir") {
|
||||
let entry = entry.expect("Failed to read entry");
|
||||
let child_src = entry.path();
|
||||
let child_dst = dst.join(entry.file_name());
|
||||
copy_recursively(&child_src, &child_dst);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let src_dir = cwd.join("src");
|
||||
if src_dir.exists() {
|
||||
copy_recursively(&src_dir, &build_dir);
|
||||
}
|
||||
|
||||
// Change current working directory to the build directory.
|
||||
env::set_current_dir(&build_dir).expect("Failed to change to build directory");
|
||||
|
||||
if has_dsc {
|
||||
println!("Compiling DSC to DSA...");
|
||||
fn compile_recursive(path: &Path) {
|
||||
if path.is_dir() {
|
||||
for entry in fs::read_dir(path).expect("unable to read dir") {
|
||||
let entry = entry.expect("failed to read entry");
|
||||
compile_recursive(&entry.path());
|
||||
}
|
||||
} else if path.extension().and_then(|s| s.to_str()) == Some("dsc") {
|
||||
let input_path = path;
|
||||
let output_path = path.with_extension("dsa");
|
||||
compiler::compile_file(&input_path, &output_path).unwrap_or_else(|e| {
|
||||
eprintln!("Failed to compile {:?}: {}", input_path, e);
|
||||
std::process::exit(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
compile_recursive(&build_dir);
|
||||
}
|
||||
|
||||
// Replace .dsc with .dsa only in include statements, recursively for each file.
|
||||
let mut sed_cmd = Command::new("bash");
|
||||
sed_cmd.args(&[
|
||||
"-c",
|
||||
&format!(
|
||||
"find \"{}\" -type f -name '*.dsa' -exec sed -i '/^include/ s/\\.dsc/.dsa/g' {{}} +",
|
||||
build_dir.display()
|
||||
),
|
||||
]);
|
||||
run(&mut sed_cmd);
|
||||
|
||||
fs::create_dir_all(&cwd.join("artifacts")).expect("Failed to create build directory");
|
||||
assembler::assemble_file("./main.dsa", "../artifacts/out.dsb").unwrap_or_else(|e| {
|
||||
eprintln!("Failed to assemble {:?}: {}", "./main.dsa", e);
|
||||
std::process::exit(1);
|
||||
});
|
||||
|
||||
println!("Build finished. Binary at {}/main.dsb", build_dir.display());
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
[package]
|
||||
name = "dsx"
|
||||
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"
|
||||
|
||||
[dependencies]
|
||||
compiler = { path = "../compiler" }
|
||||
assembler = { path = "../assembler" }
|
||||
common = { path = "../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"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
toml = "1.0.3"
|
||||
tracing = "0.1.44"
|
||||
tracing-subscriber = { version = "0.3.22", features = ["env-filter"] }
|
||||
chrono = "0.4.43"
|
||||
tar = "0.4.44"
|
||||
flate2 = "1.1.9"
|
||||
walkdir = "2.5.0"
|
||||
@@ -0,0 +1,106 @@
|
||||
default_job = "check"
|
||||
env.CARGO_TERM_COLOR = "always"
|
||||
|
||||
[jobs.check]
|
||||
command = ["cargo", "check"]
|
||||
need_stdout = false
|
||||
|
||||
[jobs.check-all]
|
||||
command = ["cargo", "check", "--all-targets"]
|
||||
need_stdout = false
|
||||
|
||||
# Run clippy on the default target
|
||||
[jobs.clippy]
|
||||
command = ["cargo", "clippy"]
|
||||
need_stdout = false
|
||||
|
||||
[jobs.clippy-all]
|
||||
command = ["cargo", "clippy", "--all-targets"]
|
||||
need_stdout = false
|
||||
|
||||
# Run clippy in pedantic mode
|
||||
# The 'dismiss' feature may come handy
|
||||
[jobs.pedantic]
|
||||
command = [
|
||||
"cargo", "clippy",
|
||||
"--",
|
||||
"-W", "clippy::pedantic",
|
||||
]
|
||||
need_stdout = false
|
||||
|
||||
# This job lets you run
|
||||
# - all tests: bacon test
|
||||
# - a specific test: bacon test -- config::test_default_files
|
||||
# - the tests of a package: bacon test -- -- -p config
|
||||
[jobs.test]
|
||||
command = ["cargo", "test"]
|
||||
need_stdout = true
|
||||
|
||||
[jobs.nextest]
|
||||
command = [
|
||||
"cargo", "nextest", "run",
|
||||
"--hide-progress-bar", "--failure-output", "final"
|
||||
]
|
||||
need_stdout = true
|
||||
analyzer = "nextest"
|
||||
|
||||
[jobs.doc]
|
||||
command = ["cargo", "doc", "--no-deps"]
|
||||
need_stdout = false
|
||||
|
||||
# If the doc compiles, then it opens in your browser and bacon switches
|
||||
# to the previous job
|
||||
[jobs.doc-open]
|
||||
command = ["cargo", "doc", "--no-deps", "--open"]
|
||||
need_stdout = false
|
||||
on_success = "back" # so that we don't open the browser at each change
|
||||
|
||||
# You can run your application and have the result displayed in bacon,
|
||||
# if it makes sense for this crate.
|
||||
[jobs.run]
|
||||
command = [
|
||||
"cargo", "run", "--bin", "dsx_server"
|
||||
# put launch parameters for your program behind a `--` separator
|
||||
]
|
||||
need_stdout = true
|
||||
allow_warnings = true
|
||||
background = true
|
||||
|
||||
# Run your long-running application (eg server) and have the result displayed in bacon.
|
||||
# For programs that never stop (eg a server), `background` is set to false
|
||||
# to have the cargo run output immediately displayed instead of waiting for
|
||||
# program's end.
|
||||
# 'on_change_strategy' is set to `kill_then_restart` to have your program restart
|
||||
# on every change (an alternative would be to use the 'F5' key manually in bacon).
|
||||
# If you often use this job, it makes sense to override the 'r' key by adding
|
||||
# a binding `r = job:run-long` at the end of this file .
|
||||
# A custom kill command such as the one suggested below is frequently needed to kill
|
||||
# long running programs (uncomment it if you need it)
|
||||
[jobs.run-long]
|
||||
command = [
|
||||
"cargo", "run",
|
||||
# put launch parameters for your program behind a `--` separator
|
||||
]
|
||||
need_stdout = true
|
||||
allow_warnings = true
|
||||
background = false
|
||||
on_change_strategy = "kill_then_restart"
|
||||
# kill = ["pkill", "-TERM", "-P"]
|
||||
|
||||
# This parameterized job runs the example of your choice, as soon
|
||||
# as the code compiles.
|
||||
# Call it as
|
||||
# bacon ex -- my-example
|
||||
[jobs.ex]
|
||||
command = ["cargo", "run", "--example"]
|
||||
need_stdout = true
|
||||
allow_warnings = true
|
||||
|
||||
# You may define here keybindings that would be specific to
|
||||
# a project, for example a shortcut to launch a specific job.
|
||||
# Shortcuts to internal functions (scrolling, toggling, etc.)
|
||||
# should go in your personal global prefs.toml file instead.
|
||||
[keybindings]
|
||||
# alt-m = "job:my-job"
|
||||
c = "job:clippy-all" # comment this to have 'c' run clippy on only the default target
|
||||
p = "job:pedantic"
|
||||
@@ -0,0 +1 @@
|
||||
id="example"
|
||||
@@ -0,0 +1 @@
|
||||
name = "example"
|
||||
@@ -0,0 +1,105 @@
|
||||
|
||||
// multiply.dsa
|
||||
// usage:
|
||||
//
|
||||
// include multiply "<relative path>"
|
||||
//
|
||||
// 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
|
||||
@@ -0,0 +1,332 @@
|
||||
|
||||
// lib:
|
||||
// print.dsa
|
||||
|
||||
// usage:
|
||||
//
|
||||
// include print "<relative path>""
|
||||
//
|
||||
// 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
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
// GENERATED BY DSX-BUILD
|
||||
// Generated at: 2026-02-21 02:50:14
|
||||
// Project name: example
|
||||
|
||||
// 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
|
||||
@@ -0,0 +1,19 @@
|
||||
|
||||
# Endpoints
|
||||
|
||||
let n be the repo name.
|
||||
|
||||
## Web view
|
||||
GET /packages/ # home page listing packages - simple search bar.
|
||||
GET /packages?q=<query> # search for a package
|
||||
GET /packages/<name> # main page for a repository, shows status, files, name etc.
|
||||
GET /packages/<name>/~repo/<path> # path for a file within a repo
|
||||
GET /packages/<name>/~repo?q=<query> # search within a package's files
|
||||
GET /packages/<name>/~artifact/ # page listing repo artifacts by date
|
||||
GET /packages/<name>/~artifact/<id> # page for a specific artifact and status/logs
|
||||
|
||||
POST /api/pkg # create repo
|
||||
GET /api/pkg/<name> # repo status/metadata
|
||||
POST /api/pkg/<name>/push # upload source tarball
|
||||
GET /api/pkg/<name>/pull # download source tarball
|
||||
GET /api/pkg/<name>/artifact # download compiled binary
|
||||
@@ -0,0 +1,15 @@
|
||||
# Folder structure
|
||||
|
||||
data/
|
||||
repos/
|
||||
<repo_name>/
|
||||
repo/
|
||||
Dsx.toml
|
||||
README.md
|
||||
src/
|
||||
artifacts/
|
||||
<repo_name>.dsb
|
||||
<repo_name-lib>.dsb
|
||||
docs/
|
||||
<repo_name-lib>.md
|
||||
index/
|
||||
@@ -0,0 +1,53 @@
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{
|
||||
env, fs,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use dsx::common::builder;
|
||||
|
||||
pub mod new;
|
||||
|
||||
fn main() {
|
||||
// Very small CLI – only three sub‑commands.
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() < 2 {
|
||||
eprintln!("Usage: dsx-build <new|build|package> [options]");
|
||||
std::process::exit(1);
|
||||
}
|
||||
match args[1].as_str() {
|
||||
"new" => new::new_project(&args[2..]),
|
||||
"build" => {
|
||||
if let Some(dir) = find_project_root() {
|
||||
builder::build_project(&dir).expect("Build failed!");
|
||||
} else {
|
||||
eprintln!("No Dsx.toml found");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
"package" => todo!("Package manager stub – not implemented yet."),
|
||||
_ => {
|
||||
eprintln!("Unknown command: {}", args[1]);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn find_project_root() -> Option<PathBuf> {
|
||||
// check if current dir has Dsx.toml otherwise check parent dir recursively
|
||||
let mut cwd = env::current_dir().unwrap();
|
||||
loop {
|
||||
let dsx_toml = cwd.join("Dsx.toml");
|
||||
if dsx_toml.exists() {
|
||||
return Some(cwd);
|
||||
}
|
||||
|
||||
if let Some(parent) = cwd.parent() {
|
||||
cwd = parent.to_path_buf();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
use std::{env, fmt, fs, path::PathBuf};
|
||||
|
||||
use dsx::common::{
|
||||
config::DsxConfig,
|
||||
templates::{self, Dsa, Dsc, Template},
|
||||
};
|
||||
|
||||
// ---------- new project ----------------------------------------------------
|
||||
pub fn new_project(args: &[String]) {
|
||||
// get project details from args.
|
||||
let lang = Language::from_args(args);
|
||||
let lib = args.contains(&"--lib".to_string());
|
||||
let name = project_name(args).unwrap_or_else(|| {
|
||||
eprintln!("Error: --name argument required");
|
||||
std::process::exit(1);
|
||||
});
|
||||
|
||||
let project_path = env::current_dir().unwrap().join(name);
|
||||
let src_path = project_path.join("src");
|
||||
|
||||
fs::create_dir_all(&src_path).expect("Failed to create project directory");
|
||||
|
||||
let config_template = DsxConfig::new(name);
|
||||
fs::write(
|
||||
project_path.join("Dsx.toml"),
|
||||
toml::to_string(&config_template).unwrap(),
|
||||
)
|
||||
.expect("Unable to write default config");
|
||||
|
||||
let (path, template) = match lang {
|
||||
Language::Unknown | Language::Dsa => {
|
||||
(src_path.join("main.dsa"), Dsa::create(name, lib))
|
||||
}
|
||||
Language::Dsc => (src_path.join("main.dsc"), Dsc::create(name, lib)),
|
||||
};
|
||||
|
||||
fs::write(path, template).expect("Unable to write DSA file");
|
||||
|
||||
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,
|
||||
src_path.parent().unwrap().display()
|
||||
);
|
||||
}
|
||||
|
||||
// helpers
|
||||
|
||||
enum Language {
|
||||
Unknown,
|
||||
Dsa,
|
||||
Dsc,
|
||||
}
|
||||
|
||||
impl Language {
|
||||
fn from_args(args: &[String]) -> Self {
|
||||
let mut lang = Language::Unknown;
|
||||
for i in 0..args.len() {
|
||||
if args[i] == "--lang" && i + 1 < args.len() {
|
||||
match args[i + 1].as_str() {
|
||||
"dsa" => lang = Language::Dsa,
|
||||
"dsc" => lang = Language::Dsc,
|
||||
_ => {
|
||||
eprintln!("Error: Invalid language argument");
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lang
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Language {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Unknown => write!(f, "Unknown"),
|
||||
Self::Dsa => write!(f, "Dsa"),
|
||||
Self::Dsc => write!(f, "Dsc"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn project_name(args: &[String]) -> Option<&str> {
|
||||
for i in 0..args.len() {
|
||||
if args[i] == "--name" && i + 1 < args.len() {
|
||||
return Some(&args[i + 1]);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
use std::{
|
||||
env, fs, io,
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
};
|
||||
|
||||
use crate::common::config::DsxConfig;
|
||||
|
||||
use assembler::prelude::Assembler;
|
||||
use common::build::{BuildError, Builder};
|
||||
use compiler::Compiler;
|
||||
|
||||
// ---------- build ----------------------------------------------------------
|
||||
pub fn build_project(cwd: &Path) -> Result<(), BuildError> {
|
||||
let config: DsxConfig = toml::from_str(&fs::read_to_string(cwd.join("Dsx.toml"))?)
|
||||
.map_err(|deser_err| {
|
||||
io::Error::new(io::ErrorKind::InvalidData, deser_err.to_string())
|
||||
})?;
|
||||
|
||||
let src_dir = cwd.join("src");
|
||||
if !src_dir.exists() {
|
||||
return Err(BuildError::Generic(String::from(
|
||||
"Source Directory does not exist",
|
||||
)));
|
||||
}
|
||||
|
||||
// make sure there's a main file to assemble later.
|
||||
if !main_exists(&src_dir)? {
|
||||
return Err(BuildError::Generic(String::from(
|
||||
"No main.dsa or main.dsc file found in top level of src directory.",
|
||||
)));
|
||||
}
|
||||
|
||||
// check is redundant as we're already checking for main files.
|
||||
// if !has_dsc && !has_dsa {
|
||||
// return Err(io::Error::new(
|
||||
// io::ErrorKind::NotFound,
|
||||
// "No .dsc or .dsa source found in src directory.",
|
||||
// ));
|
||||
// }
|
||||
|
||||
// detect src.
|
||||
let (has_dsa, has_dsc) = detect_source_language(&src_dir);
|
||||
|
||||
// create a build dir and copy all files across
|
||||
let build_dir = cwd.join("build");
|
||||
fs::create_dir_all(&build_dir)?;
|
||||
env::set_current_dir(&build_dir)?;
|
||||
|
||||
copy_recursively(&src_dir, &build_dir)?;
|
||||
|
||||
if has_dsc {
|
||||
build_all_dsc(&build_dir)?;
|
||||
}
|
||||
|
||||
// Replace .dsc with .dsa only in include statements, recursively for each file.
|
||||
let mut sed_cmd = Command::new("bash");
|
||||
sed_cmd.args([
|
||||
"-c",
|
||||
&format!(
|
||||
"find \"{}\" -type f -name '*.dsa' -exec sed -i '/^include/ s/\\.dsc/.dsa/g' {{}} +",
|
||||
build_dir.display()
|
||||
),
|
||||
]);
|
||||
run(&mut sed_cmd);
|
||||
|
||||
// assemble result
|
||||
{
|
||||
fs::create_dir_all(cwd.join("artifacts"))?;
|
||||
let mut asm = Assembler::new("./main.dsa");
|
||||
asm.start();
|
||||
asm.write_result("../artifacts/out.dsb")?;
|
||||
}
|
||||
|
||||
println!("Build finished. Binary at {}/main.dsb", build_dir.display());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// ----- Helpers -------------------------------
|
||||
|
||||
struct BuildStep;
|
||||
impl BuildStep {
|
||||
pub fn compiling(path: &Path) {
|
||||
println!("Compiling {}", path.display());
|
||||
}
|
||||
|
||||
pub fn assembling(path: &Path) {
|
||||
println!("Assembling {}", path.display());
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks what source languages are used in the project.
|
||||
fn detect_source_language(src_dir: &Path) -> (bool, bool) {
|
||||
let mut contains_dsc = false;
|
||||
let mut contains_dsa = false;
|
||||
|
||||
for entry in walkdir::WalkDir::new(src_dir).into_iter().flatten() {
|
||||
match entry.path().extension().and_then(|s| s.to_str()) {
|
||||
Some("dsc") => contains_dsc = true,
|
||||
Some("dsa") => contains_dsa = true,
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
(contains_dsa, contains_dsc)
|
||||
}
|
||||
|
||||
// Checks if either main.dsa or main.dsc exist in the source directory
|
||||
fn main_exists(src_dir: &Path) -> Result<bool, std::io::Error> {
|
||||
for entry in fs::read_dir(src_dir).into_iter().flatten() {
|
||||
match entry?.path().file_name().and_then(|s| s.to_str()) {
|
||||
Some("main.dsc") => return Ok(true),
|
||||
Some("main.dsa") => return Ok(true),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
// Copy contents of one directory to another
|
||||
fn copy_recursively(src: &Path, dst: &Path) -> Result<(), std::io::Error> {
|
||||
if src.is_file() {
|
||||
fs::create_dir_all(dst.parent().unwrap())?;
|
||||
fs::copy(src, dst)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if src.is_dir() {
|
||||
for entry in fs::read_dir(src)? {
|
||||
let entry = entry?;
|
||||
let child_src = entry.path();
|
||||
let child_dst = dst.join(entry.file_name());
|
||||
copy_recursively(&child_src, &child_dst)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn build_all_dsc(path: &Path) -> Result<(), BuildError> {
|
||||
if path.is_dir() {
|
||||
for entry in fs::read_dir(path)? {
|
||||
let entry = entry?;
|
||||
build_all_dsc(&entry.path())?;
|
||||
}
|
||||
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if path.extension().and_then(|s| s.to_str()) == Some("dsc") {
|
||||
let input_path = path;
|
||||
let output_path = path.with_extension("dsa");
|
||||
|
||||
let mut compiler = Compiler::new(input_path);
|
||||
compiler.start();
|
||||
compiler.write_result(output_path.clone())?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Run a command and exit on failure.
|
||||
fn run(cmd: &mut Command) {
|
||||
let status = cmd.status().expect("failed to execute command");
|
||||
if !status.success() {
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
use rocket::serde;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct DsxConfig {
|
||||
pub name: String,
|
||||
|
||||
#[serde(default)]
|
||||
pub description: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub remote_url: Option<String>,
|
||||
|
||||
#[serde(default)]
|
||||
pub binaries: Vec<Binary>,
|
||||
// todo!
|
||||
// #[serde(default)]
|
||||
// pub libraries: Vec<Library>,
|
||||
}
|
||||
|
||||
impl DsxConfig {
|
||||
pub fn new(name: &str) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
description: None,
|
||||
remote_url: None,
|
||||
binaries: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Binary {
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
impl Binary {
|
||||
pub fn new(name: &str, path: &str) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
path: path.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
pub mod builder;
|
||||
pub mod config;
|
||||
pub mod templates;
|
||||
@@ -0,0 +1 @@
|
||||
pub mod common;
|
||||
@@ -0,0 +1,38 @@
|
||||
use common::build::BuildError;
|
||||
use rocket::{Response, http::Status, response::Responder};
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Debug, Serialize, Responder)]
|
||||
pub enum ApiError {
|
||||
#[response(status = 404)]
|
||||
NotFound(String),
|
||||
|
||||
#[response(status = 500)]
|
||||
InternalServerError(()),
|
||||
|
||||
#[response(status = 500)]
|
||||
ServerError(String),
|
||||
|
||||
#[response(status = 401)]
|
||||
Unauthorized(String),
|
||||
#[response(status = 403)]
|
||||
Forbidden(String),
|
||||
|
||||
#[response(status = 400)]
|
||||
BadRequest(String),
|
||||
}
|
||||
|
||||
impl From<std::io::Error> for ApiError {
|
||||
fn from(err: std::io::Error) -> Self {
|
||||
ApiError::InternalServerError(())
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BuildError> for ApiError {
|
||||
fn from(err: BuildError) -> Self {
|
||||
match err {
|
||||
BuildError::IoError(err) => ApiError::ServerError(err.to_string()),
|
||||
BuildError::Generic(err) => ApiError::ServerError(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use dsx::common::config::DsxConfig;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{DATA_DIR, error::ApiError};
|
||||
|
||||
// stored as a Config.toml above the repository root.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct PackageMeta {
|
||||
pub id: String,
|
||||
|
||||
#[serde(default)]
|
||||
pub latest_build_date: Option<String>,
|
||||
#[serde(default)]
|
||||
pub latest_build_status: Option<String>,
|
||||
#[serde(default)]
|
||||
pub latest_build_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Package {
|
||||
pub config: DsxConfig,
|
||||
pub meta: PackageMeta,
|
||||
pub files: Vec<FileObj>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FileObj {
|
||||
pub name: String,
|
||||
pub path: String,
|
||||
pub is_dir: bool,
|
||||
pub size: u64,
|
||||
pub extension: String,
|
||||
}
|
||||
|
||||
impl Package {
|
||||
pub fn load(name: &str) -> Result<Self, ApiError> {
|
||||
let repo_path = DATA_DIR.join("repos").join(name);
|
||||
|
||||
let config_contents = fs::read_to_string(repo_path.join("repo/Dsx.toml"))
|
||||
.map_err(|e| {
|
||||
warn!("unable to read config for repo, {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
let config: DsxConfig = toml::from_str(&config_contents).map_err(|e| {
|
||||
warn!("Invalid config file for repo! {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
let meta_contents =
|
||||
fs::read_to_string(repo_path.join("Package.toml")).map_err(|e| {
|
||||
warn!("unable to read config for repo, {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
let meta: PackageMeta = toml::from_str(&meta_contents).map_err(|e| {
|
||||
warn!("Invalid meta file for repo! {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
let dir = fs::read_dir(repo_path.join("repo")).map_err(|e| {
|
||||
warn!("unable to read files for repo, {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
let mut files = Vec::new();
|
||||
for entry in dir {
|
||||
let entry = entry.map_err(|e| {
|
||||
warn!("unable to read file entry for repo, {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
let path = entry.path();
|
||||
let metadata = fs::metadata(&path).map_err(|e| {
|
||||
warn!("unable to read file metadata for repo, {e}");
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
let is_dir = metadata.is_dir();
|
||||
let size = metadata.len();
|
||||
let extension = path
|
||||
.extension()
|
||||
.map_or(String::new(), |ext| ext.to_string_lossy().to_string());
|
||||
files.push(FileObj {
|
||||
path: path.to_string_lossy().to_string(),
|
||||
name: path.file_name().unwrap().to_string_lossy().to_string(),
|
||||
is_dir,
|
||||
size,
|
||||
extension,
|
||||
});
|
||||
}
|
||||
|
||||
Ok(Self {
|
||||
config,
|
||||
meta,
|
||||
files,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn unpack(archive: &std::path::Path) -> Result<Self, ApiError> {
|
||||
let repo_name = archive.file_name().unwrap().to_str().unwrap();
|
||||
let dest = DATA_DIR.join("repos").join(repo_name).join("repo");
|
||||
unpack_tarball(archive, &dest)?;
|
||||
let package = Self::load(repo_name)?;
|
||||
Ok(package)
|
||||
}
|
||||
|
||||
pub fn tarball(&self) -> Result<Vec<u8>, ApiError> {
|
||||
let src_dir = self.path().join("repo");
|
||||
pack_tarball(&src_dir)
|
||||
}
|
||||
|
||||
pub fn path(&self) -> PathBuf {
|
||||
DATA_DIR.join("repos").join(&self.meta.id)
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tar helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
use flate2::read::GzDecoder;
|
||||
use flate2::{Compression, write::GzEncoder};
|
||||
use std::fs::File;
|
||||
use tar::Builder;
|
||||
|
||||
fn unpack_tarball(
|
||||
archive: &std::path::Path,
|
||||
dest: &std::path::Path,
|
||||
) -> Result<(), ApiError> {
|
||||
let file = File::open(archive)?;
|
||||
let gz = GzDecoder::new(file);
|
||||
let mut tar = tar::Archive::new(gz);
|
||||
tar.unpack(dest)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn pack_tarball(src_dir: &std::path::Path) -> Result<Vec<u8>, ApiError> {
|
||||
let buf = Vec::new();
|
||||
let gz = GzEncoder::new(buf, Compression::default());
|
||||
let mut tar = Builder::new(gz);
|
||||
tar.append_dir_all(".", src_dir)?;
|
||||
let gz = tar.into_inner()?;
|
||||
Ok(gz.finish()?)
|
||||
}
|
||||
@@ -0,0 +1,270 @@
|
||||
#[macro_use]
|
||||
extern crate rocket;
|
||||
|
||||
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;
|
||||
use rocket::{fs::FileServer, serde::Deserialize};
|
||||
|
||||
use rocket_dyn_templates::{Template, context};
|
||||
|
||||
use dotenv::dotenv;
|
||||
use serde::Serialize;
|
||||
use tracing::{info, warn};
|
||||
|
||||
use crate::error::ApiError;
|
||||
use crate::model::{Package, PackageMeta};
|
||||
use dsx::common::config::DsxConfig;
|
||||
|
||||
mod error;
|
||||
mod model;
|
||||
|
||||
static DATA_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
|
||||
PathBuf::from(std::env::var("$DATA_DIR").unwrap_or("./data".to_string()))
|
||||
});
|
||||
|
||||
// Search for a package
|
||||
#[get("/?<q>")]
|
||||
fn search_packages(q: Option<String>) -> Result<Template, ApiError> {
|
||||
#[derive(Serialize)]
|
||||
struct Package {
|
||||
name: String,
|
||||
description: String,
|
||||
updated_at: String,
|
||||
}
|
||||
|
||||
let mut packages = Vec::new();
|
||||
|
||||
let dir = match fs::read_dir(DATA_DIR.join("repos")) {
|
||||
Ok(dir) => dir,
|
||||
Err(e) => {
|
||||
warn!("failed to read repos directory: {}", e);
|
||||
return Err(ApiError::InternalServerError(()));
|
||||
}
|
||||
};
|
||||
|
||||
for entry in dir {
|
||||
let entry = entry.map_err(|e| {
|
||||
warn!("failed to read entry: {}", e);
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
let config_path = entry.path().join("repo").join("Dsx.toml");
|
||||
if config_path.exists() {
|
||||
let text = fs::read_to_string(&config_path).map_err(|e| {
|
||||
warn!("failed to read config file: {}", e);
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
let config: DsxConfig = toml::from_str(&text).map_err(|e| {
|
||||
warn!("failed to parse config file: {}", e);
|
||||
ApiError::InternalServerError(())
|
||||
})?;
|
||||
|
||||
error!("{}", config.description.clone().unwrap_or_default());
|
||||
|
||||
// skip repo if it doesnt match query params
|
||||
if let Some(query) = &q
|
||||
&& !(config.name.contains(query)
|
||||
|| config
|
||||
.description
|
||||
.clone()
|
||||
.unwrap_or_default()
|
||||
.contains(query))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
packages.push(Package {
|
||||
name: config.name,
|
||||
description: config.description.unwrap_or_default(),
|
||||
updated_at: String::from("0:00"),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Template::render(
|
||||
"packages",
|
||||
context! {
|
||||
packages,
|
||||
query: q.clone().unwrap_or_default()
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
// Main page for a repository, shows status, files, name etc.
|
||||
#[get("/<name>")]
|
||||
fn package_main(name: &str) -> Result<Template, ApiError> {
|
||||
// get package info
|
||||
let package = Package::load(name)?;
|
||||
|
||||
println!("{}", package.config.name);
|
||||
|
||||
Ok(Template::render(
|
||||
"package_home",
|
||||
context! {
|
||||
parent_path: String::new(),
|
||||
current_path: String::from("/"),
|
||||
package: package,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
// Path for a file within a repo
|
||||
#[get("/<name>/~repo/<path..>")]
|
||||
fn repo_file(name: &str, path: std::path::PathBuf) -> Result<Template, ApiError> {
|
||||
let package = Package::load(name)?;
|
||||
|
||||
Ok(Template::render(
|
||||
"file",
|
||||
context! {
|
||||
package: package,
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
// Search within a package's files
|
||||
#[get("/<name>/~repo?<q>")]
|
||||
fn search_repo_files(name: &str, q: Option<String>) -> String {
|
||||
format!("Search within {} for {:?}", name, q)
|
||||
}
|
||||
|
||||
// Page listing repo artifacts by date
|
||||
#[get("/<name>/artifacts")]
|
||||
fn list_artifacts(name: &str) -> String {
|
||||
format!("Artifacts for package {}", name)
|
||||
}
|
||||
|
||||
// Page for a specific artifact and status/logs
|
||||
#[get("/<name>/artifacts/<id>")]
|
||||
fn artifact_detail(name: &str, id: u64) -> String {
|
||||
format!("Artifact {} details for package {}", id, name)
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(crate = "rocket::serde")]
|
||||
struct NewRepo<'r> {
|
||||
name: &'r str,
|
||||
}
|
||||
|
||||
// Create repo
|
||||
#[post("/pkg", data = "<repo>")]
|
||||
fn create_repo(repo: Json<NewRepo<'_>>) -> Result<(), &'static str> {
|
||||
let path = DATA_DIR.join("repos").join(repo.name);
|
||||
|
||||
if repo.name.is_empty() {
|
||||
return Err("Repository name cannot be empty!");
|
||||
}
|
||||
|
||||
if path.exists() {
|
||||
tracing::info!(
|
||||
"Attempt to create repository '{}' which already exists.",
|
||||
repo.name
|
||||
);
|
||||
return Err("This repository already exists!");
|
||||
}
|
||||
|
||||
if let Err(e) = fs::create_dir_all(path) {
|
||||
tracing::error!(
|
||||
"Attempted to create package with name {} - Error: {e},",
|
||||
repo.name
|
||||
);
|
||||
return Err("Internal server error");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Repo status/metadata
|
||||
#[get("/pkg/<name>")]
|
||||
fn get_pkg(name: &str) -> Result<Json<(PackageMeta, DsxConfig)>, ApiError> {
|
||||
let package = Package::load(name).map_err(|e| {
|
||||
ApiError::NotFound(String::from("repo with name {name} does not exist"))
|
||||
})?;
|
||||
|
||||
Ok(Json((package.meta, package.config)))
|
||||
}
|
||||
|
||||
// Upload source tarball
|
||||
#[post("/pkg/<name>/push", data = "<data>")]
|
||||
async fn push_tarball(name: &str, data: Data<'_>) -> Result<(), ApiError> {
|
||||
let repo_dir = DATA_DIR.join("repos").join(name);
|
||||
let tmp_path = repo_dir.join("upload.tar.gz");
|
||||
let stream = data
|
||||
.open(256.mebibytes())
|
||||
.into_file(&tmp_path)
|
||||
.await
|
||||
.map_err(|e| ApiError::InternalServerError(()))?;
|
||||
|
||||
if !stream.is_complete() {
|
||||
return Err(ApiError::BadRequest("Incomplete upload".to_string()));
|
||||
}
|
||||
|
||||
// Unpack over the existing repo dir.
|
||||
if repo_dir.exists() {
|
||||
fs::remove_dir_all(&repo_dir).map_err(|e| ApiError::InternalServerError(()))?;
|
||||
}
|
||||
fs::create_dir_all(&repo_dir).map_err(|e| ApiError::InternalServerError(()))?;
|
||||
|
||||
let _ = Package::unpack(&tmp_path)?;
|
||||
fs::remove_file(&tmp_path).ok();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Download source tarball
|
||||
#[get("/pkg/<name>/pull")]
|
||||
fn pull_tarball(
|
||||
name: &str,
|
||||
) -> Result<(rocket::http::ContentType, Vec<u8>), Json<ApiError>> {
|
||||
if let Ok(package) = Package::load(name) {
|
||||
let tarball = package.tarball()?;
|
||||
Ok((
|
||||
rocket::http::ContentType::new("application", "octet-stream"),
|
||||
tarball,
|
||||
))
|
||||
} else {
|
||||
Err(Json(ApiError::NotFound(format!(
|
||||
"repo with name {name} does not exist"
|
||||
))))
|
||||
}
|
||||
}
|
||||
|
||||
// Download compiled binary
|
||||
#[get("/pkg/<name>/artifact")]
|
||||
fn download_artifact(name: &str) -> &'static str {
|
||||
"Download artifact"
|
||||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> _ {
|
||||
dotenv().unwrap();
|
||||
|
||||
rocket::build()
|
||||
.mount(
|
||||
"/packages",
|
||||
routes![
|
||||
search_packages,
|
||||
package_main,
|
||||
repo_file,
|
||||
search_repo_files,
|
||||
list_artifacts,
|
||||
artifact_detail,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/api",
|
||||
routes![
|
||||
create_repo,
|
||||
get_pkg,
|
||||
push_tarball,
|
||||
pull_tarball,
|
||||
download_artifact
|
||||
],
|
||||
)
|
||||
.attach(Template::fairing())
|
||||
.mount("/static", FileServer::from("./static"))
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 201 KiB |
@@ -0,0 +1,360 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block title %}#{{ artifact.id }} · {{ package.name }}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<style>
|
||||
/* ── Artifact layout ────────────────────────── */
|
||||
.artifact-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 220px;
|
||||
gap: 24px;
|
||||
align-items: start;
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.artifact-layout { grid-template-columns: 1fr; }
|
||||
.artifact-sidebar { order: -1; }
|
||||
}
|
||||
|
||||
/* ── Artifact header ────────────────────────── */
|
||||
.artifact-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.artifact-header h1 {
|
||||
font-family: var(--mono);
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.artifact-trigger-line {
|
||||
font-size: 13px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
/* ── Steps list ─────────────────────────────── */
|
||||
.steps-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.step-card { overflow: hidden; }
|
||||
|
||||
.step-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 10px 14px;
|
||||
cursor: pointer;
|
||||
background: var(--surface);
|
||||
border-radius: var(--radius);
|
||||
transition: background .1s;
|
||||
user-select: none;
|
||||
}
|
||||
.step-card.open .step-header {
|
||||
border-radius: var(--radius) var(--radius) 0 0;
|
||||
background: var(--surface2);
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
.step-header:hover { background: var(--surface2); }
|
||||
|
||||
.step-name {
|
||||
flex: 1;
|
||||
font-family: var(--mono);
|
||||
font-size: 13px;
|
||||
}
|
||||
.step-duration {
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
}
|
||||
.step-chevron {
|
||||
color: var(--muted);
|
||||
transition: transform .2s;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.step-card.open .step-chevron { transform: rotate(90deg); }
|
||||
|
||||
/* ── Log output ─────────────────────────────── */
|
||||
.step-log {
|
||||
display: none;
|
||||
background: #080808;
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
border-radius: 0 0 var(--radius) var(--radius);
|
||||
overflow: hidden;
|
||||
}
|
||||
.step-card.open .step-log { display: block; }
|
||||
|
||||
.log-line {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
.log-line:hover { background: rgba(255,255,255,.03); }
|
||||
.log-num {
|
||||
min-width: 48px;
|
||||
padding: 0 12px;
|
||||
text-align: right;
|
||||
color: var(--muted);
|
||||
user-select: none;
|
||||
border-right: 1px solid #1a1a1a;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.log-text {
|
||||
padding: 0 16px;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
flex: 1;
|
||||
}
|
||||
.log-text.err { color: var(--red); }
|
||||
.log-text.warn { color: var(--yellow); }
|
||||
|
||||
/* ── Sidebar ────────────────────────────────── */
|
||||
.sidebar-card { overflow: hidden; margin-bottom: 12px; }
|
||||
.sidebar-card-title {
|
||||
font-size: 11px;
|
||||
font-family: var(--mono);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .8px;
|
||||
color: var(--muted);
|
||||
padding: 10px 14px 8px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--surface2);
|
||||
}
|
||||
.sidebar-card-body { padding: 12px 14px; }
|
||||
.sidebar-stat {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 4px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.sidebar-stat-label { color: var(--text-dim); }
|
||||
.sidebar-stat-value { font-family: var(--mono); font-size: 12px; }
|
||||
|
||||
/* ── Navigation between artifacts ──────────── */
|
||||
.artifact-nav {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.artifact-nav a {
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
padding: 5px 12px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
color: var(--text-dim);
|
||||
transition: border-color .15s, color .15s;
|
||||
}
|
||||
.artifact-nav a:hover { color: var(--text); border-color: #3a3a3a; text-decoration: none; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="breadcrumb">
|
||||
<a href="/packages/">packages</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<a href="/packages/{{ package.name }}">{{ package.name }}</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<a href="/packages/{{ package.name }}/~artifact/">artifacts</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<span>#{{ artifact.id }}</span>
|
||||
</div>
|
||||
|
||||
<div class="artifact-header">
|
||||
<h1>
|
||||
#{{ artifact.id }}
|
||||
{% if artifact.status == "success" %}
|
||||
<span class="badge badge-success"><span class="dot"></span>passed</span>
|
||||
{% elif artifact.status == "failure" %}
|
||||
<span class="badge badge-failure"><span class="dot"></span>failed</span>
|
||||
{% elif artifact.status == "running" %}
|
||||
<span class="badge badge-running"><span class="dot dot-pulse"></span>running</span>
|
||||
{% elif artifact.status == "pending" %}
|
||||
<span class="badge badge-pending"><span class="dot"></span>queued</span>
|
||||
{% else %}
|
||||
<span class="badge badge-unknown"><span class="dot"></span>{{ artifact.status }}</span>
|
||||
{% endif %}
|
||||
</h1>
|
||||
<p class="artifact-trigger-line">
|
||||
{{ artifact.trigger | default(value="Triggered manually") }}
|
||||
{% if artifact.commit_sha %} · <span class="mono" style="font-size:12px">{{ artifact.commit_sha }}</span>{% endif %}
|
||||
{% if artifact.branch %} on <strong>{{ artifact.branch }}</strong>{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div class="artifact-layout">
|
||||
|
||||
<!-- Steps + logs -->
|
||||
<div>
|
||||
{% if artifact.steps and artifact.steps | length > 0 %}
|
||||
<p class="section-title">Steps</p>
|
||||
<div class="steps-list">
|
||||
{% for step in artifact.steps %}
|
||||
<div class="card step-card {% if step.status == 'failure' or loop.first %}open{% endif %}" id="step-{{ loop.index }}">
|
||||
<div class="step-header" onclick="toggleStep(this)">
|
||||
<span class="step-status">
|
||||
{% if step.status == "success" %}
|
||||
<span style="color:var(--green)">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><polyline points="20 6 9 17 4 12"/></svg>
|
||||
</span>
|
||||
{% elif step.status == "failure" %}
|
||||
<span style="color:var(--red)">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
||||
</span>
|
||||
{% elif step.status == "running" %}
|
||||
<span style="color:var(--accent)" class="dot-pulse">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||
</span>
|
||||
{% elif step.status == "skipped" %}
|
||||
<span style="color:var(--muted)">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="5" y1="12" x2="19" y2="12"/></svg>
|
||||
</span>
|
||||
{% else %}
|
||||
<span style="color:var(--muted)">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="10"/></svg>
|
||||
</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="step-name">{{ step.name }}</span>
|
||||
{% if step.duration %}<span class="step-duration">{{ step.duration }}</span>{% endif %}
|
||||
<svg class="step-chevron" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="9 18 15 12 9 6"/></svg>
|
||||
</div>
|
||||
<div class="step-log">
|
||||
{% if step.log_lines and step.log_lines | length > 0 %}
|
||||
{% for line in step.log_lines %}
|
||||
<div class="log-line">
|
||||
<span class="log-num">{{ loop.index }}</span>
|
||||
<span class="log-text {% if line.level == 'error' %}err{% elif line.level == 'warn' %}warn{% endif %}">{{ line.text | default(value=line) | escape }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% elif step.log %}
|
||||
{% for raw_line in step.log | split(pat="\n") %}
|
||||
<div class="log-line">
|
||||
<span class="log-num">{{ loop.index }}</span>
|
||||
<span class="log-text">{{ raw_line | escape }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<div class="log-line">
|
||||
<span class="log-num">1</span>
|
||||
<span class="log-text dim">No output.</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="card" style="padding:32px;text-align:center;color:var(--text-dim);font-size:13px">
|
||||
No steps recorded for this artifact.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="artifact-nav">
|
||||
{% if artifact.prev_id %}
|
||||
<a href="/packages/{{ package.name }}/~artifact/{{ artifact.prev_id }}">← #{{ artifact.prev_id }}</a>
|
||||
{% endif %}
|
||||
{% if artifact.next_id %}
|
||||
<a href="/packages/{{ package.name }}/~artifact/{{ artifact.next_id }}">#{{ artifact.next_id }} →</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sidebar -->
|
||||
<aside class="artifact-sidebar">
|
||||
|
||||
<div class="card sidebar-card">
|
||||
<div class="sidebar-card-title">Summary</div>
|
||||
<div class="sidebar-card-body">
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Status</span>
|
||||
<span>
|
||||
{% if artifact.status == "success" %}
|
||||
<span class="badge badge-success"><span class="dot"></span>passed</span>
|
||||
{% elif artifact.status == "failure" %}
|
||||
<span class="badge badge-failure"><span class="dot"></span>failed</span>
|
||||
{% elif artifact.status == "running" %}
|
||||
<span class="badge badge-running"><span class="dot dot-pulse"></span>running</span>
|
||||
{% else %}
|
||||
<span class="badge badge-unknown">{{ artifact.status }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
{% if artifact.duration %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Duration</span>
|
||||
<span class="sidebar-stat-value">{{ artifact.duration }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if artifact.created_at %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Started</span>
|
||||
<span class="sidebar-stat-value">{{ artifact.created_at }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if artifact.finished_at %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Finished</span>
|
||||
<span class="sidebar-stat-value">{{ artifact.finished_at }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if artifact.steps %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Steps</span>
|
||||
<span class="sidebar-stat-value">{{ artifact.steps | length }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if artifact.commit_sha or artifact.branch %}
|
||||
<div class="card sidebar-card">
|
||||
<div class="sidebar-card-title">Commit</div>
|
||||
<div class="sidebar-card-body">
|
||||
{% if artifact.branch %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Branch</span>
|
||||
<span class="sidebar-stat-value">{{ artifact.branch }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if artifact.commit_sha %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">SHA</span>
|
||||
<span class="sidebar-stat-value">{{ artifact.commit_sha | truncate(length=8, end="") }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if artifact.commit_message %}
|
||||
<div style="font-size:12px;color:var(--text-dim);margin-top:8px;line-height:1.5">{{ artifact.commit_message }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div style="margin-top:4px">
|
||||
<a href="/packages/{{ package.name }}/~artifact/" style="font-size:12px;font-family:var(--mono)">← all artifacts</a>
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function toggleStep(header) {
|
||||
const card = header.closest('.step-card');
|
||||
card.classList.toggle('open');
|
||||
}
|
||||
</script>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,189 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block title %}Artifacts · {{ package.name }}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<style>
|
||||
.artifacts-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.artifacts-header h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
margin: 0;
|
||||
font-family: var(--mono);
|
||||
}
|
||||
|
||||
.artifact-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.artifact-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
padding: 12px 16px;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
transition: border-color .15s, background .15s;
|
||||
}
|
||||
.artifact-row:hover {
|
||||
background: var(--surface2);
|
||||
border-color: #3a3a3a;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.artifact-id {
|
||||
font-family: var(--mono);
|
||||
font-size: 13px;
|
||||
color: var(--accent);
|
||||
flex-shrink: 0;
|
||||
min-width: 48px;
|
||||
}
|
||||
|
||||
.artifact-info { flex: 1; min-width: 0; }
|
||||
.artifact-trigger {
|
||||
font-size: 13px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.artifact-meta {
|
||||
font-size: 11px;
|
||||
color: var(--text-dim);
|
||||
font-family: var(--mono);
|
||||
margin-top: 2px;
|
||||
}
|
||||
|
||||
.artifact-status { flex-shrink: 0; }
|
||||
.artifact-duration {
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
flex-shrink: 0;
|
||||
min-width: 48px;
|
||||
text-align: right;
|
||||
}
|
||||
.artifact-date {
|
||||
font-size: 11px;
|
||||
color: var(--muted);
|
||||
font-family: var(--mono);
|
||||
flex-shrink: 0;
|
||||
min-width: 90px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 64px 0;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
/* Stats strip at top */
|
||||
.stats-strip {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
margin-bottom: 20px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.stat-chip {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
padding: 8px 14px;
|
||||
font-size: 12px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
}
|
||||
.stat-chip-val {
|
||||
font-family: var(--mono);
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
}
|
||||
.stat-chip-label { color: var(--text-dim); }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="breadcrumb">
|
||||
<a href="/packages/">packages</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<a href="/packages/{{ package.name }}">{{ package.name }}</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<span>artifacts</span>
|
||||
</div>
|
||||
|
||||
<div class="artifacts-header">
|
||||
<h1>{{ package.name }} / artifacts</h1>
|
||||
</div>
|
||||
|
||||
{% if stats is defined %}
|
||||
<div class="stats-strip">
|
||||
<div class="stat-chip">
|
||||
<span class="stat-chip-val">{{ stats.total | default(value=0) }}</span>
|
||||
<span class="stat-chip-label">Total</span>
|
||||
</div>
|
||||
<div class="stat-chip">
|
||||
<span class="stat-chip-val" style="color:var(--green)">{{ stats.success | default(value=0) }}</span>
|
||||
<span class="stat-chip-label">Passed</span>
|
||||
</div>
|
||||
<div class="stat-chip">
|
||||
<span class="stat-chip-val" style="color:var(--red)">{{ stats.failure | default(value=0) }}</span>
|
||||
<span class="stat-chip-label">Failed</span>
|
||||
</div>
|
||||
{% if stats.avg_duration is defined %}
|
||||
<div class="stat-chip">
|
||||
<span class="stat-chip-val">{{ stats.avg_duration }}</span>
|
||||
<span class="stat-chip-label">Avg duration</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if artifacts and artifacts | length > 0 %}
|
||||
<div class="artifact-list">
|
||||
{% for artifact in artifacts %}
|
||||
<a class="card artifact-row" href="/packages/{{ package.name }}/~artifact/{{ artifact.id }}">
|
||||
<span class="artifact-id">#{{ artifact.id }}</span>
|
||||
<div class="artifact-info">
|
||||
<div class="artifact-trigger">{{ artifact.trigger | default(value="manual") }}</div>
|
||||
<div class="artifact-meta">{{ artifact.commit_sha | default(value="") }}{% if artifact.branch %} on {{ artifact.branch }}{% endif %}</div>
|
||||
</div>
|
||||
<span class="artifact-status">
|
||||
{% if artifact.status == "success" %}
|
||||
<span class="badge badge-success"><span class="dot"></span>passed</span>
|
||||
{% elif artifact.status == "failure" %}
|
||||
<span class="badge badge-failure"><span class="dot"></span>failed</span>
|
||||
{% elif artifact.status == "running" %}
|
||||
<span class="badge badge-running"><span class="dot dot-pulse"></span>running</span>
|
||||
{% elif artifact.status == "pending" %}
|
||||
<span class="badge badge-pending"><span class="dot"></span>queued</span>
|
||||
{% else %}
|
||||
<span class="badge badge-unknown"><span class="dot"></span>{{ artifact.status }}</span>
|
||||
{% endif %}
|
||||
</span>
|
||||
{% if artifact.duration %}<span class="artifact-duration">{{ artifact.duration }}</span>{% endif %}
|
||||
<span class="artifact-date">{{ artifact.created_at | default(value="") }}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="color:var(--border)"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||
<p style="margin-top:10px">No artifacts yet.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,198 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}Packages{% endblock %} · depot</title>
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link href="https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@300;400;500&display=swap" rel="stylesheet">
|
||||
<style>
|
||||
:root {
|
||||
--bg: #0d0d0d;
|
||||
--surface: #161616;
|
||||
--surface2: #1f1f1f;
|
||||
--border: #2a2a2a;
|
||||
--muted: #555;
|
||||
--text: #ddd;
|
||||
--text-dim: #888;
|
||||
--accent: #4f8ef7;
|
||||
--green: #3ecf6a;
|
||||
--yellow: #f0b429;
|
||||
--red: #f25c5c;
|
||||
--radius: 6px;
|
||||
--mono: 'IBM Plex Mono', monospace;
|
||||
--sans: 'IBM Plex Sans', sans-serif;
|
||||
}
|
||||
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: var(--sans);
|
||||
font-size: 14px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
a { color: var(--accent); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
/* ── Top nav ─────────────────────────────── */
|
||||
.topbar {
|
||||
position: fixed;
|
||||
top: 0; left: 0;
|
||||
width: 100%;
|
||||
height: 52px;
|
||||
background: var(--surface);
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 0 24px;
|
||||
z-index: 1000;
|
||||
}
|
||||
|
||||
.topbar-logo {
|
||||
font-family: var(--mono);
|
||||
font-size: 15px;
|
||||
font-weight: 500;
|
||||
color: var(--text);
|
||||
letter-spacing: -0.5px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.topbar-logo span { color: var(--accent); }
|
||||
|
||||
.topbar-search {
|
||||
flex: 1;
|
||||
max-width: 420px;
|
||||
position: relative;
|
||||
}
|
||||
.topbar-search input {
|
||||
width: 100%;
|
||||
padding: 6px 12px 6px 32px;
|
||||
background: var(--surface2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
color: var(--text);
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
transition: border-color .15s;
|
||||
}
|
||||
.topbar-search input:focus { border-color: var(--accent); }
|
||||
.topbar-search input::placeholder { color: var(--muted); }
|
||||
.topbar-search-icon {
|
||||
position: absolute;
|
||||
left: 10px;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--muted);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ── Page wrapper ───────────────────────── */
|
||||
.page {
|
||||
padding-top: 52px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.container {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
padding: 32px 24px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* ── Breadcrumb ─────────────────────────── */
|
||||
.breadcrumb {
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.breadcrumb a { color: var(--text-dim); }
|
||||
.breadcrumb a:hover { color: var(--text); text-decoration: none; }
|
||||
.breadcrumb-sep { color: var(--border); }
|
||||
|
||||
/* ── Status badges ──────────────────────── */
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 20px;
|
||||
font-family: var(--mono);
|
||||
font-size: 11px;
|
||||
font-weight: 500;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .4px;
|
||||
}
|
||||
.badge-success { background: rgba(62,207,106,.12); color: var(--green); }
|
||||
.badge-failure { background: rgba(242,92,92,.12); color: var(--red); }
|
||||
.badge-running { background: rgba(79,142,247,.12); color: var(--accent); }
|
||||
.badge-pending { background: rgba(240,180,41,.12); color: var(--yellow); }
|
||||
.badge-unknown { background: rgba(136,136,136,.12); color: var(--muted); }
|
||||
|
||||
.dot {
|
||||
width: 6px; height: 6px;
|
||||
border-radius: 50%;
|
||||
background: currentColor;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.dot-pulse {
|
||||
animation: pulse 1.4s ease-in-out infinite;
|
||||
}
|
||||
@keyframes pulse {
|
||||
0%,100% { opacity: 1; }
|
||||
50% { opacity: .3; }
|
||||
}
|
||||
|
||||
/* ── Generic card ───────────────────────── */
|
||||
.card {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
/* ── Section heading ────────────────────── */
|
||||
.section-title {
|
||||
font-size: 11px;
|
||||
font-family: var(--mono);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .8px;
|
||||
color: var(--muted);
|
||||
margin: 0 0 12px;
|
||||
}
|
||||
|
||||
/* ── Utility ────────────────────────────── */
|
||||
.mono { font-family: var(--mono); }
|
||||
.dim { color: var(--text-dim); }
|
||||
.small { font-size: 12px; }
|
||||
</style>
|
||||
{% block extra_head %}{% endblock %}
|
||||
</head>
|
||||
<body>
|
||||
<div class="page">
|
||||
|
||||
<nav class="topbar">
|
||||
<a class="topbar-logo" href="/packages/"><span>//</span>DSA Packages</a>
|
||||
<div class="topbar-search">
|
||||
<svg class="topbar-search-icon" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
||||
<form method="get" action="/packages/">
|
||||
<input type="text" name="q" placeholder="Search packages…" value="{{ query | default(value='') }}">
|
||||
</form>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<div class="page">
|
||||
{% block content %}{% endblock %}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,16 @@
|
||||
{% macro file_view(package, file) %}
|
||||
<div class="file-row">
|
||||
<span class="file-icon">
|
||||
{% if file.is_dir %}
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" style="color:#4f8ef7" ><path d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"/></svg>
|
||||
{% else %}
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="file-name">
|
||||
<a href="/packages/{{ package }}/~repo/{{ file.path }}">{{ file.name }}</a>
|
||||
</span>
|
||||
<!--<span class="file-commit">{{ file.last_commit_message | default(value="") }}</span>
|
||||
<span class="file-age">{{ file.last_modified | default(value="") }}</span>-->
|
||||
</div>
|
||||
{% endmacro %}
|
||||
@@ -0,0 +1,35 @@
|
||||
<!-- File tree -->
|
||||
<div class="pkg-main">
|
||||
<div class="file-tree">
|
||||
<div class="file-toolbar">
|
||||
<div class="file-toolbar-search">
|
||||
<svg class="file-toolbar-search-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
||||
<form method="get" action="/packages/{{ package.config.name }}/~repo">
|
||||
<input type="text" name="q" placeholder="Filter files…" value="{{ query | default(value='') }}">
|
||||
</form>
|
||||
</div>
|
||||
<span class="dim small mono">{{ current_path | default(value="/") }}</span>
|
||||
</div>
|
||||
|
||||
{% if package.files and package.files | length > 0 %}
|
||||
<div class="file-tree-body">
|
||||
{% if current_path %}
|
||||
<a class="file-row" href="/packages/{{ package.config.name }}/~repo/{{ parent_path | default(value='') }}">
|
||||
<span class="file-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/></svg>
|
||||
</span>
|
||||
<span class="file-name" style="color:var(--text-dim)">..</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
|
||||
|
||||
{% for file in package.files %}
|
||||
{{ files::file_view(package = package.config.name, file = file) }}
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="file-tree-empty">No files found.</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,81 @@
|
||||
<!-- Sidebar -->
|
||||
<aside class="pkg-sidebar">
|
||||
|
||||
<!-- Build status -->
|
||||
<div class="card sidebar-card">
|
||||
<div class="sidebar-card-title">Latest Build</div>
|
||||
<div class="sidebar-card-body">
|
||||
<div class="build-status-row">
|
||||
{% if package.meta.latest_build_status == "success" %}
|
||||
<span class="badge badge-success"><span class="dot"></span>passing</span>
|
||||
{% elif package.meta.latest_build_status == "failure" %}
|
||||
<span class="badge badge-failure"><span class="dot"></span>failing</span>
|
||||
{% elif package.meta.latest_build_status == "running" %}
|
||||
<span class="badge badge-running"><span class="dot dot-pulse"></span>running</span>
|
||||
{% elif package.meta.latest_build_status == "pending" %}
|
||||
<span class="badge badge-pending"><span class="dot"></span>pending</span>
|
||||
{% else %}
|
||||
<span class="dim small">No builds yet</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if package.meta.latest_build_id %}
|
||||
<a class="build-link" href="/packages/{{ package.config.name }}/~artifact/{{ package.meta.latest_build_id }}">
|
||||
#{{ package.meta.latest_build_id }} — view logs →
|
||||
</a>
|
||||
{% endif %}
|
||||
{% if package.meta.latest_build_date %}
|
||||
<div class="dim small mono" style="margin-top:6px">{{ package.meta.latest_build_date }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- About -->
|
||||
<div class="card sidebar-card">
|
||||
<div class="sidebar-card-title">About</div>
|
||||
<div class="sidebar-card-body">
|
||||
{% if package.language %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Language</span>
|
||||
<span class="lang-pill">
|
||||
<span class="lang-color-dot" {% if package.language_color %}style="background:{{ package.language_color }}"{% endif %}></span>
|
||||
{{ package.language }}
|
||||
</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if package.version %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Version</span>
|
||||
<span class="sidebar-stat-value">{{ package.version }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if package.license %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">License</span>
|
||||
<span class="sidebar-stat-value">{{ package.license }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if package.created_at %}
|
||||
<div class="sidebar-stat">
|
||||
<span class="sidebar-stat-label">Created</span>
|
||||
<span class="sidebar-stat-value dim">{{ package.created_at }}</span>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Quick links -->
|
||||
<div class="card sidebar-card">
|
||||
<div class="sidebar-card-title">Links</div>
|
||||
<div class="sidebar-card-body" style="display:flex;flex-direction:column;gap:6px">
|
||||
<a href="/packages/{{ package.config.name }}/~repo" style="font-size:13px">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="vertical-align:middle;margin-right:4px"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
|
||||
Browse files
|
||||
</a>
|
||||
<a href="/packages/{{ package.config.name }}/~artifact/" style="font-size:13px">
|
||||
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" style="vertical-align:middle;margin-right:4px"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>
|
||||
Build history
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</aside>
|
||||
@@ -0,0 +1,204 @@
|
||||
{% extends "base" %}
|
||||
{% import 'components/file' as files %}
|
||||
|
||||
{% block title %}{{ package.config.name }}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<style>
|
||||
/* ── Layout: main + sidebar ─────────────────── */
|
||||
.pkg-layout {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 240px;
|
||||
gap: 24px;
|
||||
align-items: start;
|
||||
}
|
||||
@media (max-width: 768px) {
|
||||
.pkg-layout { grid-template-columns: 1fr; }
|
||||
.pkg-sidebar { order: -1; }
|
||||
}
|
||||
|
||||
/* ── Repo header ────────────────────────────── */
|
||||
.pkg-header {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.pkg-header h1 {
|
||||
font-family: var(--mono);
|
||||
font-size: 22px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.pkg-desc {
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* ── Toolbar above file tree ────────────────── */
|
||||
.file-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--surface2);
|
||||
border-radius: var(--radius) var(--radius) 0 0;
|
||||
}
|
||||
.file-toolbar-search {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
max-width: 260px;
|
||||
}
|
||||
.file-toolbar-search input {
|
||||
width: 100%;
|
||||
padding: 5px 10px 5px 28px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
color: var(--text);
|
||||
font-size: 12px;
|
||||
font-family: var(--sans);
|
||||
outline: none;
|
||||
}
|
||||
.file-toolbar-search input:focus { border-color: var(--accent); }
|
||||
.file-toolbar-search input::placeholder { color: var(--muted); }
|
||||
.file-toolbar-search-icon {
|
||||
position: absolute;
|
||||
left: 8px; top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--muted);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
/* ── File tree ──────────────────────────────── */
|
||||
.file-tree { border-radius: var(--radius); overflow: hidden; }
|
||||
.file-tree-body { border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); }
|
||||
|
||||
.file-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 7px 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
font-family: var(--mono);
|
||||
font-size: 13px;
|
||||
transition: background .1s;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
}
|
||||
.file-row:last-child { border-bottom: none; }
|
||||
.file-row:hover { background: var(--surface2); text-decoration: none; }
|
||||
|
||||
.file-icon { color: var(--muted); flex-shrink: 0; }
|
||||
.file-name { flex: 1; }
|
||||
.file-name a { color: var(--text); }
|
||||
.file-name a:hover { color: var(--accent); text-decoration: none; }
|
||||
.file-commit { font-size: 11px; color: var(--text-dim); flex: 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.file-age { font-size: 11px; color: var(--muted); flex-shrink: 0; }
|
||||
|
||||
/* ── Sidebar ────────────────────────────────── */
|
||||
.pkg-sidebar {}
|
||||
.sidebar-card {
|
||||
margin-bottom: 12px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.sidebar-card-title {
|
||||
font-size: 11px;
|
||||
font-family: var(--mono);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: .8px;
|
||||
color: var(--muted);
|
||||
padding: 10px 14px 8px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
background: var(--surface2);
|
||||
}
|
||||
.sidebar-card-body { padding: 12px 14px; }
|
||||
|
||||
.sidebar-stat {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 4px 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
.sidebar-stat-label { color: var(--text-dim); }
|
||||
.sidebar-stat-value { font-family: var(--mono); }
|
||||
|
||||
.build-status-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 13px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.build-link {
|
||||
font-size: 11px;
|
||||
font-family: var(--mono);
|
||||
margin-top: 6px;
|
||||
display: inline-block;
|
||||
}
|
||||
.lang-pill {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.lang-color-dot {
|
||||
width: 10px; height: 10px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
}
|
||||
|
||||
/* ── Empty file state ───────────────────────── */
|
||||
.file-tree-empty {
|
||||
padding: 32px;
|
||||
text-align: center;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
border-radius: 0 0 var(--radius) var(--radius);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="breadcrumb">
|
||||
<a href="/packages/">packages</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<span>{{ package.config.name }}</span>
|
||||
</div>
|
||||
|
||||
<div class="pkg-header">
|
||||
<h1>
|
||||
{{ package.config.name }}
|
||||
{% if package.meta.latest_build_status == "success" %}
|
||||
<span class="badge badge-success"><span class="dot"></span>passing</span>
|
||||
{% elif package.meta.latest_build_status == "failure" %}
|
||||
<span class="badge badge-failure"><span class="dot"></span>failing</span>
|
||||
{% elif package.meta.latest_build_status == "running" %}
|
||||
<span class="badge badge-running"><span class="dot dot-pulse"></span>running</span>
|
||||
{% elif package.meta.latest_build_status == "pending" %}
|
||||
<span class="badge badge-pending"><span class="dot"></span>pending</span>
|
||||
{% endif %}
|
||||
</h1>
|
||||
{% if package.config.description %}
|
||||
<p class="pkg-desc">{{ package.config.description }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="pkg-layout">
|
||||
|
||||
<!-- File tree -->
|
||||
{% include 'components/file_tree' %}
|
||||
|
||||
<!-- Sidebar (Package info incl build status and releases) -->
|
||||
{% include 'components/sidebar' %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,174 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block title %}{% if query %}Search: {{ query }}{% else %}All Packages{% endif %}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<style>
|
||||
.home-header {
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.home-header h1 {
|
||||
font-size: 20px;
|
||||
font-weight: 500;
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
.home-header p {
|
||||
color: var(--text-dim);
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.repo-grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.repo-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
padding: 14px 18px;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
transition: border-color .15s, background .15s;
|
||||
}
|
||||
.repo-item:hover {
|
||||
border-color: #3a3a3a;
|
||||
background: var(--surface2);
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.repo-item-avatar {
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background: var(--surface2);
|
||||
background-image: url("/static/placeholder.jpg");
|
||||
background-size: cover;
|
||||
background-position: center;
|
||||
flex-shrink: 0;
|
||||
border: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.repo-item-main {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.repo-item-name {
|
||||
font-family: var(--mono);
|
||||
font-size: 14px;
|
||||
color: var(--accent);
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.repo-item-desc {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
margin-top: 2px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.repo-item-meta {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
flex-shrink: 0;
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.repo-item-lang {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 5px;
|
||||
}
|
||||
.lang-dot {
|
||||
width: 8px; height: 8px;
|
||||
border-radius: 50%;
|
||||
background: var(--accent);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 64px 0;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.empty-state p { margin: 6px 0 0; font-size: 13px; }
|
||||
|
||||
.result-count {
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
margin-bottom: 16px;
|
||||
font-family: var(--mono);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
<div class="home-header">
|
||||
{% if query %}
|
||||
<h1>Results for <span style="color:var(--accent)">"{{ query }}"</span></h1>
|
||||
{% else %}
|
||||
<h1>Packages</h1>
|
||||
<p>{{ packages | length }} package{% if packages | length != 1 %}s{% endif %} available</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if query %}
|
||||
<div class="result-count">{{ packages | length }} result{% if packages | length != 1 %}s{% endif %}</div>
|
||||
{% endif %}
|
||||
|
||||
{% if packages | length > 0 %}
|
||||
<div class="repo-grid">
|
||||
{% for pkg in packages %}
|
||||
<a class="card repo-item" href="/packages/{{ pkg.name }}">
|
||||
<div class="repo-item-avatar" {% if pkg.avatar_url %}style="background-image:url('{{ pkg.avatar_url }}')"{% endif %}></div>
|
||||
<div class="repo-item-main">
|
||||
<span class="repo-item-name">{{ pkg.name }}</span>
|
||||
{% if pkg.description %}
|
||||
<div class="repo-item-desc">{{ pkg.description }}</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="repo-item-meta">
|
||||
{% if pkg.language %}
|
||||
<span class="repo-item-lang">
|
||||
<span class="lang-dot" style="{% if pkg.language_color %}background:{{ pkg.language_color }}{% endif %}"></span>
|
||||
{{ pkg.language }}
|
||||
</span>
|
||||
{% endif %}
|
||||
{% if pkg.latest_build_status %}
|
||||
{% if pkg.latest_build_status == "success" %}
|
||||
<span class="badge badge-success"><span class="dot"></span>passing</span>
|
||||
{% elif pkg.latest_build_status == "failure" %}
|
||||
<span class="badge badge-failure"><span class="dot"></span>failing</span>
|
||||
{% elif pkg.latest_build_status == "running" %}
|
||||
<span class="badge badge-running"><span class="dot dot-pulse"></span>running</span>
|
||||
{% elif pkg.latest_build_status == "pending" %}
|
||||
<span class="badge badge-pending"><span class="dot"></span>pending</span>
|
||||
{% else %}
|
||||
<span class="badge badge-unknown"><span class="dot"></span>unknown</span>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
<span class="dim small">{{ pkg.updated_at }}</span>
|
||||
</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="color:var(--border)"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
||||
{% if query %}
|
||||
<p>No packages match <strong>"{{ query }}"</strong></p>
|
||||
{% else %}
|
||||
<p>No packages yet.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,281 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block title %}{{ file.name }} · {{ package.name }}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<style>
|
||||
/* ── Path breadcrumb ────────────────────────── */
|
||||
.file-path-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0;
|
||||
background: var(--surface2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius) var(--radius) 0 0;
|
||||
padding: 8px 14px;
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
}
|
||||
.file-path-bar a { color: var(--accent); }
|
||||
.file-path-bar a:hover { text-decoration: underline; }
|
||||
.file-path-sep { color: var(--border); margin: 0 3px; }
|
||||
.file-path-current { color: var(--text); }
|
||||
|
||||
/* ── File metadata row ──────────────────────── */
|
||||
.file-meta-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 7px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
background: var(--surface);
|
||||
font-size: 12px;
|
||||
color: var(--text-dim);
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
.file-meta-bar .mono { font-family: var(--mono); }
|
||||
|
||||
/* ── Directory listing (same as package home but nested) */
|
||||
.file-tree-body {
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
border-radius: 0 0 var(--radius) var(--radius);
|
||||
overflow: hidden;
|
||||
}
|
||||
.file-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 7px 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
font-family: var(--mono);
|
||||
font-size: 13px;
|
||||
transition: background .1s;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
}
|
||||
.file-row:last-child { border-bottom: none; }
|
||||
.file-row:hover { background: var(--surface2); }
|
||||
.file-icon { color: var(--muted); flex-shrink: 0; }
|
||||
.file-name { flex: 1; }
|
||||
.file-name a { color: var(--text); }
|
||||
.file-name a:hover { color: var(--accent); text-decoration: none; }
|
||||
.file-commit { font-size: 11px; color: var(--text-dim); flex: 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
||||
.file-age { font-size: 11px; color: var(--muted); flex-shrink: 0; }
|
||||
|
||||
/* ── File content / code viewer ─────────────── */
|
||||
.code-viewer {
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
border-radius: 0 0 var(--radius) var(--radius);
|
||||
overflow: hidden;
|
||||
}
|
||||
.code-viewer pre {
|
||||
margin: 0;
|
||||
padding: 16px 20px;
|
||||
overflow-x: auto;
|
||||
background: #0a0a0a;
|
||||
font-family: var(--mono);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: #c8ccd4;
|
||||
}
|
||||
/* Line numbers */
|
||||
.code-table { width: 100%; border-collapse: collapse; }
|
||||
.code-table tr:hover .code-line { background: rgba(255,255,255,.03); }
|
||||
.code-table tr:hover .line-num { background: rgba(255,255,255,.03); }
|
||||
.line-num {
|
||||
user-select: none;
|
||||
text-align: right;
|
||||
padding: 0 16px 0 16px;
|
||||
color: var(--muted);
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
width: 1%;
|
||||
white-space: nowrap;
|
||||
vertical-align: top;
|
||||
border-right: 1px solid var(--border);
|
||||
}
|
||||
.code-line {
|
||||
padding: 0 16px;
|
||||
font-family: var(--mono);
|
||||
font-size: 13px;
|
||||
white-space: pre;
|
||||
color: #c8ccd4;
|
||||
}
|
||||
|
||||
/* ── Binary/image preview ───────────────────── */
|
||||
.file-preview-img {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
padding: 32px;
|
||||
background: #0a0a0a;
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
border-radius: 0 0 var(--radius) var(--radius);
|
||||
}
|
||||
.file-preview-img img { max-width: 100%; max-height: 600px; border-radius: 4px; }
|
||||
|
||||
.file-binary-msg {
|
||||
padding: 40px;
|
||||
text-align: center;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
border-radius: 0 0 var(--radius) var(--radius);
|
||||
}
|
||||
|
||||
.toolbar-search {
|
||||
position: relative;
|
||||
max-width: 260px;
|
||||
}
|
||||
.toolbar-search input {
|
||||
width: 100%;
|
||||
padding: 5px 10px 5px 28px;
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
color: var(--text);
|
||||
font-size: 12px;
|
||||
font-family: var(--sans);
|
||||
outline: none;
|
||||
}
|
||||
.toolbar-search input:focus { border-color: var(--accent); }
|
||||
.toolbar-search input::placeholder { color: var(--muted); }
|
||||
.toolbar-search-icon {
|
||||
position: absolute;
|
||||
left: 8px; top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: var(--muted);
|
||||
pointer-events: none;
|
||||
}
|
||||
.dir-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
border: 1px solid var(--border);
|
||||
border-top: none;
|
||||
background: var(--surface2);
|
||||
}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="breadcrumb">
|
||||
<a href="/packages/">packages</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<a href="/packages/{{ package.name }}">{{ package.name }}</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<span>files</span>
|
||||
</div>
|
||||
|
||||
<!-- Path bar -->
|
||||
<div class="file-path-bar">
|
||||
<a href="/packages/{{ package.name }}/~repo">{{ package.name }}</a>
|
||||
{% for segment in path_segments %}
|
||||
<span class="file-path-sep">/</span>
|
||||
{% if loop.last %}
|
||||
<span class="file-path-current">{{ segment.name }}</span>
|
||||
{% else %}
|
||||
<a href="/packages/{{ package.name }}/~repo/{{ segment.path }}">{{ segment.name }}</a>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% if file.is_dir %}
|
||||
<!-- Directory: optional search toolbar + listing -->
|
||||
<div class="dir-toolbar">
|
||||
<div class="toolbar-search">
|
||||
<svg class="toolbar-search-icon" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
||||
<form method="get" action="/packages/{{ package.name }}/~repo">
|
||||
<input type="text" name="q" placeholder="Filter files…" value="{{ query | default(value='') }}">
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="file-tree-body">
|
||||
{% if file.parent_path is defined %}
|
||||
<a class="file-row" href="/packages/{{ package.name }}/~repo/{{ file.parent_path }}">
|
||||
<span class="file-icon">
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polyline points="15 18 9 12 15 6"/></svg>
|
||||
</span>
|
||||
<span class="file-name" style="color:var(--text-dim)">..</span>
|
||||
</a>
|
||||
{% endif %}
|
||||
{% for entry in file.children %}
|
||||
<div class="file-row">
|
||||
<span class="file-icon">
|
||||
{% if entry.is_dir %}
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor" style="color:#4f8ef7"><path d="M3 7a2 2 0 012-2h4l2 2h8a2 2 0 012 2v9a2 2 0 01-2 2H5a2 2 0 01-2-2V7z"/></svg>
|
||||
{% else %}
|
||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
|
||||
{% endif %}
|
||||
</span>
|
||||
<span class="file-name">
|
||||
<a href="/packages/{{ package.name }}/~repo/{{ entry.path }}">{{ entry.name }}</a>
|
||||
</span>
|
||||
<span class="file-commit">{{ entry.last_commit_message | default(value="") }}</span>
|
||||
<span class="file-age">{{ entry.last_modified | default(value="") }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
{% elif file.is_image %}
|
||||
<!-- Image preview -->
|
||||
<div class="file-meta-bar">
|
||||
<span>{{ file.size | default(value="unknown size") }}</span>
|
||||
<a href="{{ file.raw_url }}" class="mono" style="font-size:11px">raw ↗</a>
|
||||
</div>
|
||||
<div class="file-preview-img">
|
||||
<img src="{{ file.raw_url }}" alt="{{ file.name }}">
|
||||
</div>
|
||||
|
||||
{% elif file.is_binary %}
|
||||
<!-- Binary file -->
|
||||
<div class="file-meta-bar">
|
||||
<span>{{ file.size | default(value="unknown size") }} · binary file</span>
|
||||
{% if file.raw_url %}<a href="{{ file.raw_url }}" class="mono" style="font-size:11px">download ↗</a>{% endif %}
|
||||
</div>
|
||||
<div class="file-binary-msg">
|
||||
<svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="color:var(--border);margin-bottom:8px"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>
|
||||
<p>Binary file — cannot be displayed.</p>
|
||||
</div>
|
||||
|
||||
{% else %}
|
||||
<!-- Text / code file -->
|
||||
<div class="file-meta-bar">
|
||||
<span class="mono">{{ file.name }}</span>
|
||||
<span>
|
||||
<span class="mono">{{ file.line_count | default(value="?") }} lines</span>
|
||||
<span style="margin: 0 8px">·</span>
|
||||
<span>{{ file.size | default(value="") }}</span>
|
||||
{% if file.raw_url %}<span style="margin: 0 8px">·</span><a href="{{ file.raw_url }}" style="font-size:11px" class="mono">raw ↗</a>{% endif %}
|
||||
</span>
|
||||
</div>
|
||||
<div class="code-viewer">
|
||||
<pre><table class="code-table">
|
||||
{% if file.lines %}
|
||||
{% for line in file.lines %}
|
||||
<tr>
|
||||
<td class="line-num">{{ loop.index }}</td>
|
||||
<td class="code-line">{{ line | escape }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
<tr><td class="code-line" style="padding:16px 20px">{{ file.content | default(value="") | escape }}</td></tr>
|
||||
{% endif %}
|
||||
</table></pre>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -0,0 +1,161 @@
|
||||
{% extends "base" %}
|
||||
|
||||
{% block title %}Search "{{ query }}" · {{ package.name }}{% endblock %}
|
||||
|
||||
{% block extra_head %}
|
||||
<style>
|
||||
.search-header { margin-bottom: 20px; }
|
||||
.search-header h1 {
|
||||
font-size: 18px;
|
||||
font-weight: 500;
|
||||
font-family: var(--mono);
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
.result-count { font-size: 12px; color: var(--text-dim); font-family: var(--mono); margin-bottom: 16px; }
|
||||
|
||||
.search-result {
|
||||
padding: 12px 16px;
|
||||
transition: background .1s, border-color .1s;
|
||||
text-decoration: none;
|
||||
color: var(--text);
|
||||
display: block;
|
||||
}
|
||||
.search-result:hover { background: var(--surface2); border-color: #3a3a3a; text-decoration: none; }
|
||||
.search-result + .search-result { border-top: 1px solid var(--border); }
|
||||
|
||||
.result-path {
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
color: var(--accent);
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.result-matches { margin-top: 6px; }
|
||||
.match-line {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-family: var(--mono);
|
||||
font-size: 12px;
|
||||
padding: 2px 0;
|
||||
color: var(--text-dim);
|
||||
line-height: 1.6;
|
||||
}
|
||||
.match-lineno {
|
||||
min-width: 36px;
|
||||
text-align: right;
|
||||
color: var(--muted);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.match-text {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
flex: 1;
|
||||
}
|
||||
.match-text mark {
|
||||
background: rgba(79,142,247,.25);
|
||||
color: var(--accent);
|
||||
border-radius: 2px;
|
||||
padding: 0 1px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 64px 0;
|
||||
color: var(--text-dim);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.search-form-inline {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.search-form-inline input[type="text"] {
|
||||
flex: 1;
|
||||
max-width: 400px;
|
||||
padding: 7px 12px;
|
||||
background: var(--surface2);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: var(--radius);
|
||||
color: var(--text);
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
outline: none;
|
||||
}
|
||||
.search-form-inline input:focus { border-color: var(--accent); }
|
||||
.search-form-inline button {
|
||||
padding: 7px 16px;
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
border: none;
|
||||
border-radius: var(--radius);
|
||||
font-family: var(--sans);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.search-form-inline button:hover { opacity: .9; }
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="container">
|
||||
|
||||
<div class="breadcrumb">
|
||||
<a href="/packages/">packages</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<a href="/packages/{{ package.name }}">{{ package.name }}</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<a href="/packages/{{ package.name }}/~repo">files</a>
|
||||
<span class="breadcrumb-sep">/</span>
|
||||
<span>search</span>
|
||||
</div>
|
||||
|
||||
<div class="search-header">
|
||||
<h1>Search in {{ package.name }}</h1>
|
||||
</div>
|
||||
|
||||
<form class="search-form-inline" method="get" action="/packages/{{ package.name }}/~repo">
|
||||
<input type="text" name="q" value="{{ query | default(value='') }}" placeholder="Search files and content…" autofocus>
|
||||
<button type="submit">Search</button>
|
||||
</form>
|
||||
|
||||
{% if query %}
|
||||
<div class="result-count">
|
||||
{% if results and results | length > 0 %}
|
||||
{{ results | length }} file{% if results | length != 1 %}s{% endif %} matched "{{ query }}"
|
||||
{% else %}
|
||||
No results for "{{ query }}"
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if results and results | length > 0 %}
|
||||
<div class="card" style="overflow:hidden">
|
||||
{% for result in results %}
|
||||
<div class="search-result">
|
||||
<div class="result-path">
|
||||
<a href="/packages/{{ package.name }}/~repo/{{ result.path }}">{{ result.path }}</a>
|
||||
</div>
|
||||
{% if result.matches and result.matches | length > 0 %}
|
||||
<div class="result-matches">
|
||||
{% for match in result.matches %}
|
||||
<div class="match-line">
|
||||
<span class="match-lineno">{{ match.line_number }}</span>
|
||||
<span class="match-text">{{ match.text | escape }}</span>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="empty-state">
|
||||
<svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" style="color:var(--border)"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
|
||||
<p style="margin-top:10px">No files match <strong>"{{ query }}"</strong>.</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
||||
@@ -5,7 +5,9 @@ use std::{
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
use common::build::Builder;
|
||||
use common::prelude::Instruction;
|
||||
use compiler::Compiler;
|
||||
use egui::{Align, Context, Key, Layout, Ui};
|
||||
|
||||
use dsa_editor::{CodeEditor, ColorTheme, Syntax};
|
||||
@@ -423,45 +425,39 @@ impl Editor {
|
||||
if let Some(path) = &self.path {
|
||||
match path.extension().and_then(|ext| ext.to_str()) {
|
||||
Some("dsa") => {
|
||||
let mut compiler = CompilerEngine::new();
|
||||
compiler.start_compilation(path);
|
||||
let mut assembler = Assembler::new(path);
|
||||
assembler.start();
|
||||
|
||||
// Or block until done
|
||||
let instructions = match compiler.wait_for_result() {
|
||||
self.output = match assembler.output() {
|
||||
Ok(instructions) => instructions,
|
||||
Err(e) => {
|
||||
self.error = Some(e.to_string());
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.output = instructions
|
||||
.iter()
|
||||
.flat_map(|i| i.encode().to_be_bytes().to_vec())
|
||||
.collect();
|
||||
}
|
||||
Some("dsc") => {
|
||||
let output_path = Path::new(path).with_extension("dsa");
|
||||
if let Err(e) = compiler::compile_file(path, &output_path) {
|
||||
self.error = Some(format!("Compiler error: {e}"));
|
||||
let dsa_path = Path::new(path).with_extension("dsa");
|
||||
let mut compiler = Compiler::new(path);
|
||||
compiler.start();
|
||||
|
||||
if let Err(e) = compiler.write_result(&dsa_path) {
|
||||
self.error = Some(e.to_string());
|
||||
return;
|
||||
}
|
||||
|
||||
let mut compiler = CompilerEngine::new();
|
||||
compiler.start_compilation(&output_path);
|
||||
let mut assembler = Assembler::new(&dsa_path);
|
||||
compiler.start();
|
||||
|
||||
// Or block until done
|
||||
let instructions = match compiler.wait_for_result() {
|
||||
self.output = match assembler.output() {
|
||||
Ok(instructions) => instructions,
|
||||
Err(e) => {
|
||||
self.error = Some(format!("Assembler error: {e}"));
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
self.output = instructions
|
||||
.iter()
|
||||
.flat_map(|i| i.encode().to_be_bytes().to_vec())
|
||||
.collect();
|
||||
}
|
||||
Some("dsb") => {
|
||||
if let Ok(bytes) = fs::read(path) {
|
||||
|
||||
Reference in New Issue
Block a user