Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setup for core types #86

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Added setup for core types #86

wants to merge 5 commits into from

Conversation

adam-mcdaniel
Copy link
Owner

This PR implements the String type in core.ok, and adds some extensions to the core.target files to make memory management more efficient.

@adam-mcdaniel
Copy link
Owner Author

Example usage of the new additions to the standard library:

#[std]

struct Date {
    let m: num, d: num, y: num;

    fn now() -> Date {
        return [get_month_now() + 1, get_day_now(), get_year_now()];
    }

    fn puts(self: &Date) {
        putnum(self->m); putchar('\\'); putnum(self->d); putchar('\\'); putnum(self->y);
    }

    fn putln(self: &Date) { self.puts(); prend(); }
}


struct Time {
    let h: num, m: num, s: num;

    fn now() -> Time {
        return [get_hour_now(), get_minute_now(), get_second_now()];
    }

    fn puts(self: &Time) {
        putnum(self->h); putchar(':'); putnum(self->m); putchar(':'); putnum(self->s);
    }

    fn putln(self: &Time) { self.puts(); prend(); }
}


fn main() {
    putstr("Today is "); Date::now().putln();
    putstr("And the time is "); Time::now().putln();
}

Here are the actual definitions of these new functions in std.ok.

// Date
extern fn __oak_std__get_month_now as get_month_now() -> num;
extern fn __oak_std__get_day_now   as get_day_now()   -> num;
extern fn __oak_std__get_year_now  as get_year_now()  -> num;

// Time
extern fn __oak_std__get_hour_now   as get_hour_now()   -> num;
extern fn __oak_std__get_minute_now as get_minute_now() -> num;
extern fn __oak_std__get_second_now as get_second_now() -> num;

Additionally, it renames the core.ok externed functions like so:

extern fn __oak_core__memcpy as memcpy(dst: &char, src: &char, size: num);
extern fn __oak_core__memset as memset(dst: &char, val: num, size: num);
extern fn __oak_core__strlen as strlen(src: &char) -> num;
extern fn __oak_core__strcpy as strcpy(dst: &char, src: &char);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant