changed overloaded function syntax; () are required on procs now
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 18 Sep 2020 19:38:34 +0000 (14:38 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 18 Sep 2020 19:38:34 +0000 (14:38 -0500)
15 files changed:
core/alloc.onyx
core/file.onyx
core/intrinsics.onyx
core/js/webgl.onyx
core/stdio.onyx
core/string.onyx
core/sys/js.onyx
core/sys/wasi.onyx
core/wasi.onyx
onyx
progs/odin_example.onyx
progs/poly_test.onyx
progs/wasi_test.onyx
src/onyxparser.c
tests/general1.onyx

index 243e568c2abaa6bb8841b414fc997b73d230a2cb..3d6614aa871d1a0ac47ef6a7a4a212c3c34ed29c 100644 (file)
@@ -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();
 }
index 3a0e5ea5c62e73b18bdbc72adfb7c17cb87301ee..a93e28ac0b0f736fcc58bbe616f49fbd9f74cc09 100644 (file)
@@ -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 {
index 38aa0f002f86634b354d6b477eead3ebff25ed2b..6aee93e93e486d144a6c1a798fd41c400644bece 100644 (file)
@@ -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 ---
index dbbe978b84e0156ddd9938b4aeb5a3bcaf8b8023..428a12636202c11283a4ce14a790ee2b193718a4 100644 (file)
@@ -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" ---
index ed57856c9c59216ef01fee05cf5daf0243fc4928..12248e004181997e26953d0ac0734f1c50ae51e1 100644 (file)
@@ -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
index 405ede87214c53a5543bf9fd419944dfc6a10bc1..0603bf6c3b236ab1882312c5d8bf7188accf0c6d 100644 (file)
@@ -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
 }
index 5f9be60bd322510212344fbb9828639bfc31e9f5..9bccbb2a6bee25c1a6d667c891c0be14c49844f9 100644 (file)
@@ -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;
index 85d26044ff8ac6bd435d87477586badc74f7b071..00c8214540215826f718f90e1322d64a3cc8a50c 100644 (file)
@@ -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;
index 307007a340dc3605f8bdae10f7af0e14d33aa444..128cbe4da537f1798c16053d07afd51944f5ff1d 100644 (file)
@@ -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 ead1c3ce323fc67e9773ec9872641fdeb8c422f6..cf7966737a3f0ed1b3c1dcf67cf50888f3e75535 100755 (executable)
Binary files a/onyx and b/onyx differ
index 62a688d88d5d6375ac2edfdb27fcfd5c95328869..a4239cbad9fab843cf246b8cf24198a4e3a39a52 100644 (file)
@@ -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;
index 69c014b836cd85379addcf6fc3a2d844df85575e..eed3495da84a9c20499a016b11b3a8ff4eadd90c 100644 (file)
@@ -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");
index 01e3b829b39d1ac88db2405922cb2284dfb02a90..3f3783a7336fecb738d0e38e47941dd586234065 100644 (file)
@@ -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;
index 38c473638fc03b65bffafb42ca34c153f9c63b81..5519ee022fadd9c5a9dd245684473956648dfe53 100644 (file)
@@ -1443,9 +1443,6 @@ static AstStructType* parse_struct(OnyxParser* parser) {
 // e
 // '(' (<symbol>: <type>,?)* ')'
 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' <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);
@@ -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.");
index 7b61fa43a637a9aa3e72f209bc27b7cd34939ee7..cea27431ddb1c4e375583811f000a679e15190e3 100644 (file)
@@ -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");