Skip to content

Commit

Permalink
Trying to understand why format blows up
Browse files Browse the repository at this point in the history
  • Loading branch information
itowlson committed Oct 22, 2021
1 parent a1da27f commit d41414c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/crt.rs
@@ -1,5 +1,6 @@
#[no_mangle]
pub extern "C" fn strcmp(first: *const u8, second: *const u8) -> bool {
print("crt::strcmp");
todo!()
}

Expand Down Expand Up @@ -50,40 +51,60 @@ pub extern "C" fn truncf(f: f32) -> f32 {

#[no_mangle]
pub extern "C" fn trunc(f: f64) -> f64 {
print("crt::trunc");
todo!()
}

#[no_mangle]
pub extern "C" fn sqrtf(f: f32) -> f32 {
print("crt::sqrtf");
todo!()
}

#[no_mangle]
pub extern "C" fn sqrt(f: f64) -> f64 {
print("crt::sqrt");
todo!()
}

#[no_mangle]
pub extern "C" fn rintf(f: f32) -> f32 {
print("crt::rintf");
todo!()
}

#[no_mangle]
pub extern "C" fn rint(f: f64) -> f64 {
print("crt::rint");
todo!()
}

#[no_mangle]
pub extern "C" fn __popcountdi2(num: u32) -> u32 {
print("crt::popcount");
todo!()
}

#[no_mangle]
pub extern "C" fn abort() {
print("crt::abort");
todo!()
}

#[no_mangle]
pub extern "C" fn vsnprintf(buffer: *mut u8, count: usize, format: *const u8, args: *const u8 /* TODO: va_list */) -> f64 {
pub extern "C" fn vsnprintf(buffer: *mut u8, count: usize, format: *const u8, args: *const u8 /* TODO: va_list */) -> u32 {
print("crt::vsnprinf");
todo!()
}

fn print(s: &str) {
for c in s.as_bytes() {
outb(42, *c);
}
}

fn outb(_port: u8, value: u8) {
unsafe {
asm!("out 42, al", /* in(reg_byte) port, */ in("al") value);
}
}
32 changes: 31 additions & 1 deletion src/main.rs
Expand Up @@ -5,9 +5,13 @@
#![feature(alloc_error_handler)]
#![feature(asm)]

#![feature(fmt_internals)]

extern crate alloc;

use core::panic::PanicInfo;
use core::{ops::Add, panic::PanicInfo};

use alloc::{borrow::ToOwned, format};

// use wasm3::Environment;
// use wasm3::Module;
Expand Down Expand Up @@ -37,6 +41,32 @@ pub extern "C" fn _start() -> ! {
allocator::init();
print("Inited allocator\r\n");

let mut s = "foo\r\n".to_owned();
s.make_ascii_uppercase();
let s1 = s.add("bar\r\n");
print(&s1);

let t = "arse\r\n";
// let t1 = format!("{}:{}", s1, t);

print("ARGING ALL THE THINGS\r\n");

let s1_ = ::core::fmt::ArgumentV1::new(&s1, ::core::fmt::Display::fmt);
print("made first args arg\r\n");
let t_ = ::core::fmt::ArgumentV1::new(&t, ::core::fmt::Display::fmt);
print("made args args\r\n");

let slicey = [s1_, t_];

let fmtargs = ::core::fmt::Arguments::new_v1(&["", ":"], &slicey);
print("made args struct\r\n");

print("CALLING FORMAT\r\n");
let t1 = ::alloc::fmt::format(fmtargs);

print("PRINTING THE THING\r\n");
print(&t1);

// let env = Environment::new()
// .expect("Unable to create environment");
// let rt = env
Expand Down

0 comments on commit d41414c

Please sign in to comment.