Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe committed Jul 14, 2024
1 parent 197f044 commit f4c3d95
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
tags: not @library
- name: stak-tools
- name: mstak
tags: not @process-context
tags: not @process-context and not @library
- name: mstak-tools
tags: not @process-context
exclude:
Expand Down
40 changes: 22 additions & 18 deletions sac/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,43 +84,47 @@ macro_rules! libc_main {
#![no_std]
#![cfg_attr(not(test), no_main)]

use mstak_util::Mmap;
use $crate::__private::{
clap::{self, Parser},
core::{ffi::CStr, mem::size_of, slice},
main_error::MainError,
stak_device::StdioDevice,
stak_file::OsFileSystem,
stak_device::libc::{ReadWriteDevice, Stderr, Stdin, Stdout},
stak_file::LibcFileSystem,
stak_macro::include_r7rs,
stak_primitive::SmallPrimitiveSet,
stak_process_context::VoidProcessContext,
stak_vm::Vm,
std::{env, error::Error},
};

#[derive(clap::Parser)]
#[command(about, version)]
struct Arguments {
#[arg()]
arguments: Vec<String>,
#[arg(short = 's', long, default_value_t = $heap_size)]
heap_size: usize,
}
#[cfg_attr(not(test), no_mangle)]
unsafe extern "C" fn main(argc: isize, argv: *const *const i8) -> isize {
let Some(&file) = &slice::from_raw_parts(argv, argc as _).get(1) else {
return 1;
};

fn main() -> Result<(), MainError> {
let arguments = Arguments::parse();
let heap = slice::from_raw_parts_mut(
libc::malloc(size_of::<Value>() * HEAP_SIZE) as *mut Value,
HEAP_SIZE,
);

let mut heap = vec![Default::default(); arguments.heap_size];
let mut vm = Vm::new(
&mut heap,
heap,
SmallPrimitiveSet::new(
StdioDevice::new(),
ReadWriteDevice::new(Stdin::new(), Stdout::new(), Stderr::new()),
LibcFileSystem::new(),
VoidProcessContext::new(),
),
)?;
)
.unwrap();

vm.initialize(include_r7rs!($path).iter().copied())?;
let mmap = Mmap::new(CStr::from_ptr(file));

Ok(vm.run()?)
vm.initialize(mmap.as_slice().iter().copied()).unwrap();
vm.run().unwrap();

0
}
};
}

0 comments on commit f4c3d95

Please sign in to comment.