Fix bugs, add propper tests
This commit is contained in:
2
std/core.mcl
Normal file
2
std/core.mcl
Normal file
@@ -0,0 +1,2 @@
|
||||
include "std/str.mcl";
|
||||
include "std/io/mod.mcl";
|
||||
12
std/io/mod.mcl
Normal file
12
std/io/mod.mcl
Normal file
@@ -0,0 +1,12 @@
|
||||
|
||||
fn write_str(fd: usize, s: &str) -> usize {
|
||||
return __INTERNAL_syscall3(1, fd as &void, s->inner as &void, s->len as &void);
|
||||
}
|
||||
|
||||
fn puts(s: &str) {
|
||||
write_str(1, s);
|
||||
}
|
||||
|
||||
fn eputs(s: &str) {
|
||||
write_str(2, s);
|
||||
}
|
||||
107
std/lib/beaker.mcl
Normal file
107
std/lib/beaker.mcl
Normal file
@@ -0,0 +1,107 @@
|
||||
|
||||
|
||||
const MAX_CONTEXT_VARS: usize = 32;
|
||||
const MAX_KEY_LEN: usize = 64;
|
||||
const MAX_VALUE_LEN: usize = 256;
|
||||
const MAX_PATH_LEN: usize = 256;
|
||||
const MAX_HANDLERS: usize = 32;
|
||||
const BUFFER_SIZE: usize = 4096;
|
||||
const MAX_URL_PARAMS: usize = 16;
|
||||
const MAX_COOKIES: usize = 10;
|
||||
const MAX_OUTER_ARRAY_ITEMS: usize = 100;
|
||||
const MAX_INNER_ARRAY_ITEMS: usize = 200;
|
||||
|
||||
const TEMPLATES_DIR: &str = "templates/";
|
||||
const STATIC_DIR: &str = "static/";
|
||||
/*
|
||||
enum ContextType {
|
||||
CONTEXT_TYPE_STRING,
|
||||
CONTEXT_TYPE_STRING_ARRAY,
|
||||
CONTEXT_TYPE_STRING_2D_ARRAY,
|
||||
};
|
||||
*/
|
||||
type ContextType = i32;
|
||||
struct CV_array_data {
|
||||
values: &&char,
|
||||
count: i32,
|
||||
}
|
||||
|
||||
struct CV_2d_array_data {
|
||||
values: &&&char,
|
||||
count: i32,
|
||||
}
|
||||
|
||||
|
||||
struct ContextVarStr {
|
||||
key: char[MAX_KEY_LEN],
|
||||
typ: ContextType,
|
||||
value: char[MAX_VALUE_LEN]
|
||||
}
|
||||
|
||||
struct ContextVarArr {
|
||||
key: char[MAX_KEY_LEN],
|
||||
typ: ContextType,
|
||||
value: CV_array_data,
|
||||
}
|
||||
|
||||
struct ContextVar2dArr {
|
||||
key: char[MAX_KEY_LEN],
|
||||
typ: ContextType,
|
||||
value: CV_2d_array_data,
|
||||
}
|
||||
|
||||
struct ContextVar {
|
||||
key: char[MAX_KEY_LEN],
|
||||
typ: ContextType,
|
||||
value: char[MAX_VALUE_LEN]
|
||||
}
|
||||
|
||||
struct TemplateContext {
|
||||
vars: ContextVar[MAX_CONTEXT_VARS],
|
||||
count: i32,
|
||||
}
|
||||
|
||||
struct UrlParam {
|
||||
key: char[MAX_KEY_LEN],
|
||||
value: char[MAX_VALUE_LEN],
|
||||
}
|
||||
|
||||
struct UrlParams {
|
||||
params: UrlParam[MAX_URL_PARAMS],
|
||||
count: i32
|
||||
}
|
||||
struct Cookie {
|
||||
name: char[MAX_KEY_LEN],
|
||||
value: char[MAX_VALUE_LEN],
|
||||
expires: char[MAX_VALUE_LEN],
|
||||
path: char[MAX_KEY_LEN],
|
||||
http_only: bool,
|
||||
secure: bool
|
||||
}
|
||||
|
||||
type RequestHandler = fn(params: &UrlParams);
|
||||
|
||||
struct RouteHandler {
|
||||
path: char[MAX_PATH_LEN],
|
||||
handler: RequestHandler
|
||||
}
|
||||
|
||||
extern fn new_context() -> TemplateContext;
|
||||
extern fn context_set(ctx: &mut TemplateContext, key: &cstr, value: &cstr);
|
||||
extern fn context_set_string_array(ctx: &mut TemplateContext, key: &cstr, values: &cstr, count: i32);
|
||||
extern fn context_set_array_of_arrays(ctx: &mut TemplateContext, key: &cstr, values: &cstr[][], outer_count: i32, inner_count: i32);
|
||||
extern fn free_context(ctx: &mut TemplateContext);
|
||||
extern fn render_template(template_file: &cstr, ctx: &mut TemplateContext) -> &cstr;
|
||||
|
||||
extern fn send_response(html: &cstr);
|
||||
extern fn send_redirect(location: &cstr);
|
||||
extern fn set_cookie(name: &cstr, value: &cstr, expires: &cstr, path: &cstr, http_only: bool, secure: bool);
|
||||
extern fn get_cookie(name: &cstr) -> &cstr;
|
||||
|
||||
extern fn set_handler(path: &cstr, handler: RequestHandler);
|
||||
extern fn parse_request_url(request_buffer: &cstr, params: &UrlParams) -> &cstr;
|
||||
extern fn get_mime_type(file_path: &cstr) -> &cstr;
|
||||
extern fn serve_static_file(request_path_relative_to_static: &cstr) -> bool;
|
||||
|
||||
extern fn beaker_run(ip: &cstr, port: i32) -> i32;
|
||||
|
||||
14
std/str.mcl
Normal file
14
std/str.mcl
Normal file
@@ -0,0 +1,14 @@
|
||||
type cstr = [u8];
|
||||
|
||||
|
||||
struct str {
|
||||
len: usize,
|
||||
inner: &cstr
|
||||
}
|
||||
|
||||
fn str.len(&self) -> usize {
|
||||
return self.len;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user