next : ^heap_block;
}
-heap_init :: proc {
+heap_init :: proc () {
heap_state.free_list = null;
heap_state.next_alloc = __heap_start;
heap_state.remaining_space = (memory_size() << 16) - cast(u32) __heap_start;
-memory_init :: proc {
+memory_init :: proc () {
heap_init();
}
OpenMode :: enum {
Read;
Write;
- Append;
+ Append;
}
File :: struct {
dummy: i64;
fd_seek(file.fd, 0l, Whence.Set, ^dummy);
- dummy2: u32;
+ dummy2: u32;
buf := IOVec.{ data, size };
fd_pread(file.fd, IOVecArray.{ ^buf, 1 }, 0l, ^dummy2);
return data[0 .. size];
}
-file_get_contents :: proc #overloaded {
+file_get_contents :: proc {
file_get_contents_from_file,
proc (path: string) -> string {
package core
-memory_size :: proc -> i32 #intrinsic ---
+memory_size :: proc () -> i32 #intrinsic ---
memory_grow :: proc (val: i32) -> i32 #intrinsic ---
clz_i32 :: proc (val: i32) -> i32 #intrinsic ---
blitFramebuffer :: proc (sx0: GLint, sy0: GLint, sx1: GLint, sy1: GLint, dx0: GLint, dy0: GLint, dx1: GLint, dy1: GLint, mask: GLbitfield, filter: GLenum) #foreign "gl" "blitFramebuffer" ---
bufferDataWithData :: proc (target: GLenum, buffer: Buffer, usage: GLenum) #foreign "gl" "bufferDataWithData" ---
bufferDataNoData :: proc (target: GLenum, size: GLsizeiptr, usage: GLenum) #foreign "gl" "bufferDataNoData" ---
-bufferData :: proc #overloaded { bufferDataWithData, bufferDataNoData }
+bufferData :: proc { bufferDataWithData, bufferDataNoData }
bufferSubData :: proc (target: GLenum, offset: GLsizei, data: Buffer) #foreign "gl" "bufferSubData" ---
canvasSize :: proc (width: GLsizei, height: GLsizei) #foreign "gl" "canvasSize" ---
checkFrameBufferStatus :: proc (target: GLenum) -> GLenum #foreign "gl" "checkFrameBufferStatus" ---
copyBufferSubData :: proc (readTarget: GLenum, writeTarget: GLenum, readOffset: GLintptr, writeOffset: GLintptr, size: GLsizeiptr) #foreign "gl" "copyBufferSubData" ---
copyTexImage2D :: proc (target: GLenum, level: GLint, internalformat: GLenum, x: GLint, y: GLint, width: GLsizei, height: GLsizei, border: GLint) #foreign "gl" "copyTexImage2D" ---
copyTexSubImage2D :: proc (target: GLenum, level: GLint, xoff: GLint, yoff: GLint, x: GLint, y: GLint, width: GLsizei, height: GLsizei) #foreign "gl" "copyTexSubImage2D" ---
-createBuffer :: proc -> GLBuffer #foreign "gl" "createBuffer" ---
-createFramebuffer :: proc -> GLFramebuffer #foreign "gl" "createFramebuffer" ---
-createProgram :: proc -> GLProgram #foreign "gl" "createProgram" ---
-createRenderbuffer :: proc -> GLRenderbuffer #foreign "gl" "createRenderbuffer" ---
+createBuffer :: proc () -> GLBuffer #foreign "gl" "createBuffer" ---
+createFramebuffer :: proc () -> GLFramebuffer #foreign "gl" "createFramebuffer" ---
+createProgram :: proc () -> GLProgram #foreign "gl" "createProgram" ---
+createRenderbuffer :: proc () -> GLRenderbuffer #foreign "gl" "createRenderbuffer" ---
createShader :: proc (type: GLenum) -> GLShader #foreign "gl" "createShader" ---
-createTexture :: proc -> GLTexture #foreign "gl" "createTexture" ---
-createVertexArray :: proc -> GLVertexArrayObject #foreign "gl" "createVertexArray" ---
+createTexture :: proc () -> GLTexture #foreign "gl" "createTexture" ---
+createVertexArray :: proc () -> GLVertexArrayObject #foreign "gl" "createVertexArray" ---
cullFace :: proc (mode: GLenum) #foreign "gl" "cullFace" ---
deleteBuffer :: proc (buffer: GLBuffer) #foreign "gl" "deleteBuffer" ---
deleteFramebuffer :: proc (framebuffer: GLFramebuffer) #foreign "gl" "deleteFramebuffer" ---
drawElementsInstanced :: proc (mode: GLenum, count: GLsizei, type: GLenum, offset: GLint, instanceCount: GLsizei) #foreign "gl" "drawElementsInstanced" ---
enable :: proc (cap: GLenum) #foreign "gl" "enable" ---
enableVertexAttribArray :: proc (index: GLuint) #foreign "gl" "enableVertexAttribArray" ---
-finish :: proc #foreign "gl" "finish" ---
-flush :: proc #foreign "gl" "flush" ---
+finish :: proc () #foreign "gl" "finish" ---
+flush :: proc () #foreign "gl" "flush" ---
framebufferRenderbuffer :: proc (target: GLenum, attachment: GLenum, renderbuffertarget: GLenum, renderbuffer: GLRenderbuffer) #foreign "gl" "framebufferRenderbuffer" ---
framebufferTexture2D :: proc (target: GLenum, attachment: GLenum, textarget: GLenum, texture: GLTexture, level: GLint) #foreign "gl" "framebufferTexture2D" ---
framebufferTextureLayer :: proc (target: GLenum, attachment: GLenum, texture: GLTexture, level: GLint, layer: GLint) #foreign "gl" "framebufferTextureLayer" ---
getAttribLocation :: proc (program: GLProgram, name: string) -> GLint #foreign "gl" "getAttribLocation" ---
getBufferSubData :: proc (target: GLenum, srcByteOffset: GLintptr, dstBuffer: string, dstOffset: GLuint, length: GLuint) #foreign "gl" "getBufferSubData" ---
// getBufferParameter and getParameter do not work
-getError :: proc -> GLenum #foreign "gl" "getError" ---
+getError :: proc () -> GLenum #foreign "gl" "getError" ---
getInternalformatParameter :: proc (target: GLenum, internalFormat: GLenum, pname: GLenum) -> GLenum #foreign "gl" "getInternalformatParameter" ---
// many of the 'gets' don't work yet because they return very javascripty things
getProgramParameter :: proc (program: GLProgram, pname: GLenum) -> GLenum #foreign "gl" "getProgramParameter" ---
#private
print_buffer : StringBuilder;
-stdio_init :: proc {
+stdio_init :: proc () {
print_buffer = string_builder_make(2048);
}
print("\n");
}
-print :: proc #overloaded {
+print :: proc {
print_string, print_cstring,
print_i64, print_i32,
print_bool, print_ptr,
print("\n");
}
-print_buffer_flush :: proc {
+print_buffer_flush :: proc () {
if print_buffer.len == 0 do return;
^print_buffer
package core
-string_make :: proc #overloaded { string_make_from_cstring }
-
-#private
-string_make_from_cstring :: proc (s: cstring) -> string {
+string_make :: proc (s: cstring) -> string {
len :: string_length(s);
return string.{ count = len, data = s };
}
-string_length :: proc #overloaded {
+string_length :: proc {
proc (s: ^u8) -> u32 {
len := 0;
c := s;
return null;
}
-string_builder_append :: proc #overloaded {
+string_builder_append :: proc {
string_builder_add_string,
string_builder_add_cstring,
string_builder_add_i64,
str.count -= adv;
}
-string_read :: proc #overloaded {
+string_read :: proc {
string_read_u32, string_read_char
}
// The builtin _start proc.
// Sets up everything needed for execution.
-proc #export "_start" {
+proc () #export "_start" {
memory_init();
context.allocator = heap_allocator;
// The builtin _start proc.
// Sets up everything needed for execution.
-proc #export "_start" {
+proc () #export "_start" {
memory_init();
context.allocator = heap_allocator;
proc_exit :: proc (rval: ExitCode) #foreign "wasi_unstable" "proc_exit" ---
proc_raise :: proc (sig: Signal) -> Errno #foreign "wasi_unstable" "proc_raise" ---
-sched_yield :: proc -> Errno #foreign "wasi_unstable" "sched_yield" ---
+sched_yield :: proc () -> Errno #foreign "wasi_unstable" "sched_yield" ---
random_get :: proc (buf: ^u8, buf_len: Size) -> Errno #foreign "wasi_unstable" "random_get" ---
print("\n");
}
-make_bar :: proc -> Bar {
+make_bar :: proc () -> Bar {
bar : Bar;
bar.data1 = 1234;
bar.data2 = 12.34f;
print(")");
}
-switch_demo :: proc {
+switch_demo :: proc () {
switch a := 4; a {
case 4, 5, 6 {
print("a was 4, 5, or 6\n");
}
}
-timer_start :: proc -> Timestamp {
+timer_start :: proc () -> Timestamp {
curr_time: Timestamp;
clock_time_get(ClockID.Realtime, cast(Timestamp) 1, ^curr_time);
return curr_time;
// e
// '(' (<symbol>: <type>,?)* ')'
static void parse_function_params(OnyxParser* parser, AstFunction* func) {
- if (parser->curr->type != '(')
- return;
-
expect_token(parser, '(');
if (parser->curr->type == ')') {
// 'proc' <func_params> ('->' <type>)? <directive>* <block>
static AstFunction* parse_function_definition(OnyxParser* parser) {
+ OnyxToken* proc_token = expect_token(parser, Token_Type_Keyword_Proc);
+
+ if (parser->curr->type == '{') {
+ AstOverloadedFunction* ofunc = make_node(AstOverloadedFunction, Ast_Kind_Overloaded_Function);
+ ofunc->token = proc_token;
+
+ bh_arr_new(global_heap_allocator, ofunc->overloads, 4);
+
+ expect_token(parser, '{');
+ while (parser->curr->type != '}') {
+ if (parser->hit_unexpected_token) return (AstFunction *) ofunc;
+
+ AstTyped* o_node = parse_expression(parser);
+
+ bh_arr_push(ofunc->overloads, o_node);
+
+ if (parser->curr->type != '}')
+ expect_token(parser, ',');
+ }
+
+ consume_token(parser);
+ return (AstFunction *) ofunc;
+ }
+
AstFunction* func_def = make_node(AstFunction, Ast_Kind_Function);
- func_def->token = expect_token(parser, Token_Type_Keyword_Proc);
+ func_def->token = proc_token;
bh_arr_new(global_heap_allocator, func_def->locals, 4);
bh_arr_new(global_heap_allocator, func_def->params, 4);
func_def->return_type = return_type;
while (parser->curr->type == '#') {
- if (parse_possible_directive(parser, "overloaded")) {
- AstOverloadedFunction* ofunc = make_node(AstOverloadedFunction, Ast_Kind_Overloaded_Function);
- ofunc->token = func_def->token;
-
- bh_arr_new(global_heap_allocator, ofunc->overloads, 4);
-
- expect_token(parser, '{');
- while (parser->curr->type != '}') {
- if (parser->hit_unexpected_token) return (AstFunction *) ofunc;
-
- AstTyped* o_node = parse_expression(parser);
-
- bh_arr_push(ofunc->overloads, o_node);
-
- if (parser->curr->type != '}')
- expect_token(parser, ',');
- }
-
- consume_token(parser);
- return (AstFunction *) ofunc;
- }
-
if (parse_possible_directive(parser, "add_overload")) {
if (func_def->overloaded_function != NULL) {
onyx_report_error(parser->curr->pos, "cannot have multiple #add_overload directives on a single procedure.");
return range.{ low = r.low, high = r.high, step = s };
}
-switch_demo :: proc {
+switch_demo :: proc () {
switch a := 4; a {
case 4, 5, 6 {
println("a was 4, 5, or 6");