From: Brendan Hansen Date: Fri, 18 Sep 2020 19:38:34 +0000 (-0500) Subject: changed overloaded function syntax; () are required on procs now X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=11cc9ed0e4482c0ba67d7bc705b961506edefcf1;p=onyx.git changed overloaded function syntax; () are required on procs now --- diff --git a/core/alloc.onyx b/core/alloc.onyx index 243e568c..3d6614aa 100644 --- a/core/alloc.onyx +++ b/core/alloc.onyx @@ -18,7 +18,7 @@ heap_block :: struct { 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; @@ -173,6 +173,6 @@ alloc_slice :: proc (sl: ^[] $T, count: i32) { -memory_init :: proc { +memory_init :: proc () { heap_init(); } diff --git a/core/file.onyx b/core/file.onyx index 3a0e5ea5..a93e28ac 100644 --- a/core/file.onyx +++ b/core/file.onyx @@ -10,7 +10,7 @@ use package wasi OpenMode :: enum { Read; Write; - Append; + Append; } File :: struct { @@ -99,7 +99,7 @@ file_get_contents_from_file :: proc (file: File) -> string { 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); @@ -108,7 +108,7 @@ file_get_contents_from_file :: proc (file: File) -> string { return data[0 .. size]; } -file_get_contents :: proc #overloaded { +file_get_contents :: proc { file_get_contents_from_file, proc (path: string) -> string { diff --git a/core/intrinsics.onyx b/core/intrinsics.onyx index 38aa0f00..6aee93e9 100644 --- a/core/intrinsics.onyx +++ b/core/intrinsics.onyx @@ -1,6 +1,6 @@ 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 --- diff --git a/core/js/webgl.onyx b/core/js/webgl.onyx index dbbe978b..428a1263 100644 --- a/core/js/webgl.onyx +++ b/core/js/webgl.onyx @@ -738,7 +738,7 @@ blendFuncSeparate :: proc (srcRGB: GLenum, dstRGB: GLenum, srcAlpha 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" --- @@ -753,13 +753,13 @@ compressedTexSubImage2D :: proc (target: GLenum, level: GLint, internalfo 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" --- @@ -780,8 +780,8 @@ drawElements :: proc (mode: GLenum, count: GLsizei, type: GLen 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" --- @@ -793,7 +793,7 @@ getActiveUniform :: proc (program: GLProgram, index: GLuint, out: 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" --- diff --git a/core/stdio.onyx b/core/stdio.onyx index ed57856c..12248e00 100644 --- a/core/stdio.onyx +++ b/core/stdio.onyx @@ -7,7 +7,7 @@ use package system as system #private print_buffer : StringBuilder; -stdio_init :: proc { +stdio_init :: proc () { print_buffer = string_builder_make(2048); } @@ -30,7 +30,7 @@ print_range :: proc (r: range, sep := " ") { print("\n"); } -print :: proc #overloaded { +print :: proc { print_string, print_cstring, print_i64, print_i32, print_bool, print_ptr, @@ -52,7 +52,7 @@ print_array :: proc (arr: $T, sep := " ") { print("\n"); } -print_buffer_flush :: proc { +print_buffer_flush :: proc () { if print_buffer.len == 0 do return; ^print_buffer diff --git a/core/string.onyx b/core/string.onyx index 405ede87..0603bf6c 100644 --- a/core/string.onyx +++ b/core/string.onyx @@ -1,15 +1,12 @@ 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; @@ -233,7 +230,7 @@ string_builder_add_bool :: proc (use sb: ^StringBuilder, b: bool) -> ^StringBuil return null; } -string_builder_append :: proc #overloaded { +string_builder_append :: proc { string_builder_add_string, string_builder_add_cstring, string_builder_add_i64, @@ -292,6 +289,6 @@ string_advance_line :: proc (str: ^string) { str.count -= adv; } -string_read :: proc #overloaded { +string_read :: proc { string_read_u32, string_read_char } diff --git a/core/sys/js.onyx b/core/sys/js.onyx index 5f9be60b..9bccbb2a 100644 --- a/core/sys/js.onyx +++ b/core/sys/js.onyx @@ -8,7 +8,7 @@ output_string :: proc (s: string) -> u32 #foreign "host" "print_str" --- // The builtin _start proc. // Sets up everything needed for execution. -proc #export "_start" { +proc () #export "_start" { memory_init(); context.allocator = heap_allocator; diff --git a/core/sys/wasi.onyx b/core/sys/wasi.onyx index 85d26044..00c82145 100644 --- a/core/sys/wasi.onyx +++ b/core/sys/wasi.onyx @@ -19,7 +19,7 @@ output_string :: proc (s: string) -> u32 { // The builtin _start proc. // Sets up everything needed for execution. -proc #export "_start" { +proc () #export "_start" { memory_init(); context.allocator = heap_allocator; diff --git a/core/wasi.onyx b/core/wasi.onyx index 307007a3..128cbe4d 100644 --- a/core/wasi.onyx +++ b/core/wasi.onyx @@ -418,7 +418,7 @@ poll_oneoff :: proc (in: ^Subscription, out: ^Event, nsubscriptions: Size, neven 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" --- diff --git a/onyx b/onyx index ead1c3ce..cf796673 100755 Binary files a/onyx and b/onyx differ diff --git a/progs/odin_example.onyx b/progs/odin_example.onyx index 62a688d8..a4239cba 100644 --- a/progs/odin_example.onyx +++ b/progs/odin_example.onyx @@ -47,7 +47,7 @@ print_bar :: proc (bar: ^Bar) { print("\n"); } -make_bar :: proc -> Bar { +make_bar :: proc () -> Bar { bar : Bar; bar.data1 = 1234; bar.data2 = 12.34f; diff --git a/progs/poly_test.onyx b/progs/poly_test.onyx index 69c014b8..eed3495d 100644 --- a/progs/poly_test.onyx +++ b/progs/poly_test.onyx @@ -85,7 +85,7 @@ print_v2 :: proc (v: V2) #add_overload print { print(")"); } -switch_demo :: proc { +switch_demo :: proc () { switch a := 4; a { case 4, 5, 6 { print("a was 4, 5, or 6\n"); diff --git a/progs/wasi_test.onyx b/progs/wasi_test.onyx index 01e3b829..3f3783a7 100644 --- a/progs/wasi_test.onyx +++ b/progs/wasi_test.onyx @@ -79,7 +79,7 @@ readdir :: proc (fd: FileDescriptor) { } } -timer_start :: proc -> Timestamp { +timer_start :: proc () -> Timestamp { curr_time: Timestamp; clock_time_get(ClockID.Realtime, cast(Timestamp) 1, ^curr_time); return curr_time; diff --git a/src/onyxparser.c b/src/onyxparser.c index 38c47363..5519ee02 100644 --- a/src/onyxparser.c +++ b/src/onyxparser.c @@ -1443,9 +1443,6 @@ static AstStructType* parse_struct(OnyxParser* parser) { // e // '(' (: ,?)* ')' static void parse_function_params(OnyxParser* parser, AstFunction* func) { - if (parser->curr->type != '(') - return; - expect_token(parser, '('); if (parser->curr->type == ')') { @@ -1543,8 +1540,32 @@ static b32 parse_possible_directive(OnyxParser* parser, const char* dir) { // 'proc' ('->' )? * 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); @@ -1565,28 +1586,6 @@ static AstFunction* parse_function_definition(OnyxParser* parser) { 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."); diff --git a/tests/general1.onyx b/tests/general1.onyx index 7b61fa43..cea27431 100644 --- a/tests/general1.onyx +++ b/tests/general1.onyx @@ -76,7 +76,7 @@ by :: proc (r: range, s: u32) -> range { 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");