adam-mcdaniel/oakc

Why are IO functions declared in Core but defined in Std?

Closed this issue · 4 comments

Wouldn't it make more sense to declare and define IO functions in Std?

I'm confused about what you mean. Currently, when the user wants to use the standard library, the std.ok code is included and the target.std backend foreign code is used.

Here is the std.ok file:

fn putstr(s: &char) -> void { prs!(s); }
fn putstrln(s: &char) -> void { putstr(s); prend!(); }

fn putnum(n: num) -> void { prn!(n); }
fn putnumln(n: num) -> void { putnum(n); prend!(); }

fn putchar(ch: char) -> void { prc!(ch); }
fn putcharln(ch: char) -> void { putchar(ch); prend!(); }

fn putbool(b: bool) -> void {
    if b {
        putchar('t');
        putchar('r');
        putchar('u');
        putchar('e');
    }
    else {
        putchar('f');
        putchar('a');
        putchar('l');
        putchar('s');
        putchar('e');
    }
}

fn putboolln(b: bool) -> void { putbool(b); prend!(); }

fn get_char() -> char { return getch!() as char; }

Without requiring the standard library, these functions are not declared or defined.

Ahh, I see. I think your backend implementation uses the old architecture of the std and core libraries. It's been adjusted somewhat recently.

Ah sorry, I should have been more specific. I meant in core.c and std.c

This was fixed a while ago so I'm gonna go ahead and close it