From d1f65097c48afe6d869949cc5ede76a8b14401a9 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Tue, 14 Feb 2017 15:19:29 +0000 Subject: [PATCH] Fix immutable rules; add some general documentation immutable is still a little weird and not completely what you'd expect. Maybe just not having it is better. --- code/demo.odin | 12 +-- core/hash.odin | 8 +- core/opengl.odin | 174 +++++++++++++++++++++--------------------- core/sys/windows.odin | 13 ++-- core/utf8.odin | 4 +- src/build_settings.c | 8 +- src/check_expr.c | 11 ++- src/checker.c | 68 +++++++++-------- src/common.c | 3 + src/entity.c | 9 ++- src/map.c | 3 + src/parser.c | 4 +- src/string.c | 1 + src/types.c | 17 +++-- 14 files changed, 181 insertions(+), 154 deletions(-) diff --git a/code/demo.odin b/code/demo.odin index 5d2e53636..caee21a05 100644 --- a/code/demo.odin +++ b/code/demo.odin @@ -2,16 +2,9 @@ main :: proc() { - { - - x := [...]int{1, 2, 3, 4}; - immutable y := ^x; - fmt.println(y^[0]); - } - /* /* - Version 0.1.0 + Version 0.1.1 Added: * Dynamic Arrays `[...]Type` @@ -24,10 +17,11 @@ main :: proc() { * Entities prefixes with an underscore do not get exported on imports * Overloaded `free` for pointers, slices, strings, dynamic arrays, and dynamic maps * enum types have an implict `names` field, a []string of all the names in that enum + * immutable variables are "completely immutable" + * `slice_to_bytes` - convert any slice to a slice of bytes Removed: * Maybe/option types - * immutable variables * Remove `type` keyword and other "reserved" keywords * `compile_assert` and `assert`return the value of the condition for semantic reasons diff --git a/core/hash.odin b/core/hash.odin index ac421cda9..de1ffd0b6 100644 --- a/core/hash.odin +++ b/core/hash.odin @@ -1,14 +1,14 @@ crc32 :: proc(data: []byte) -> u32 { result := ~cast(u32)0; for b in data { - result = result>>8 ~ __CRC32_TABLE[(result ~ cast(u32)b) & 0xff]; + result = result>>8 ~ _crc32_table[(result ~ cast(u32)b) & 0xff]; } return ~result; } crc64 :: proc(data: []byte) -> u64 { result := ~cast(u64)0; for b in data { - result = result>>8 ~ __CRC64_TABLE[(result ~ cast(u64)b) & 0xff]; + result = result>>8 ~ _crc64_table[(result ~ cast(u64)b) & 0xff]; } return ~result; } @@ -202,7 +202,7 @@ murmur64 :: proc(data: []byte) -> u64 { } -__CRC32_TABLE := [256]u32{ +immutable _crc32_table := [256]u32{ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, @@ -268,7 +268,7 @@ __CRC32_TABLE := [256]u32{ 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d, }; -__CRC64_TABLE := [256]u64{ +immutable _crc64_table := [256]u64{ 0x0000000000000000, 0x42f0e1eba9ea3693, 0x85e1c3d753d46d26, 0xc711223cfa3e5bb5, 0x493366450e42ecdf, 0x0bc387aea7a8da4c, 0xccd2a5925d9681f9, 0x8e224479f47cb76a, 0x9266cc8a1c85d9be, 0xd0962d61b56fef2d, 0x17870f5d4f51b498, 0x5577eeb6e6bb820b, diff --git a/core/opengl.odin b/core/opengl.odin index e76e63f06..2821740b4 100644 --- a/core/opengl.odin +++ b/core/opengl.odin @@ -20,13 +20,13 @@ Viewport :: proc(x, y, width, height: i32) #foreign lib "gl Ortho :: proc(left, right, bottom, top, near, far: f64) #foreign lib "glOrtho"; Color3f :: proc(r, g, b: f32) #foreign lib "glColor3f"; Vertex3f :: proc(x, y, z: f32) #foreign lib "glVertex3f"; +GetError :: proc() -> i32 #foreign lib "glGetError"; +GetString :: proc(name: i32) -> ^byte #foreign lib "glGetString"; +GetIntegerv :: proc(name: i32, v: ^i32) #foreign lib "glGetIntegerv"; +TexCoord2f :: proc(x, y: f32) #foreign lib "glTexCoord2f"; TexImage2D :: proc(target, level, internal_format, width, height, border, - format, _type: i32, pixels: rawptr) #foreign lib "glTexImage2D"; - -GetError :: proc() -> i32 #foreign lib "glGetError"; -GetString :: proc(name: i32) -> ^byte #foreign lib "glGetString"; -GetIntegerv :: proc(name: i32, v: ^i32) #foreign lib "glGetIntegerv"; + format, type: i32, pixels: rawptr) #foreign lib "glTexImage2D"; string_data :: proc(s: string) -> ^u8 #inline { return ^s[0]; } @@ -42,114 +42,114 @@ GetProcAddress :: proc(name: string) -> proc() #cc_c { return res; } -GenBuffers: proc(count: i32, buffers: ^u32) #cc_c; -GenVertexArrays: proc(count: i32, buffers: ^u32) #cc_c; -GenSamplers: proc(count: i32, buffers: ^u32) #cc_c; -BindBuffer: proc(target: i32, buffer: u32) #cc_c; -BindVertexArray: proc(buffer: u32) #cc_c; -BindSampler: proc(position: i32, sampler: u32) #cc_c; -BufferData: proc(target: i32, size: int, data: rawptr, usage: i32) #cc_c; -BufferSubData: proc(target: i32, offset, size: int, data: rawptr) #cc_c; +GenBuffers: proc(count: i32, buffers: ^u32) #cc_c; +GenVertexArrays: proc(count: i32, buffers: ^u32) #cc_c; +GenSamplers: proc(count: i32, buffers: ^u32) #cc_c; +BindBuffer: proc(target: i32, buffer: u32) #cc_c; +BindVertexArray: proc(buffer: u32) #cc_c; +BindSampler: proc(position: i32, sampler: u32) #cc_c; +BufferData: proc(target: i32, size: int, data: rawptr, usage: i32) #cc_c; +BufferSubData: proc(target: i32, offset, size: int, data: rawptr) #cc_c; -DrawArrays: proc(mode, first: i32, count: u32) #cc_c; -DrawElements: proc(mode: i32, count: u32, type_: i32, indices: rawptr) #cc_c; +DrawArrays: proc(mode, first: i32, count: u32) #cc_c; +DrawElements: proc(mode: i32, count: u32, type_: i32, indices: rawptr) #cc_c; -MapBuffer: proc(target, access: i32) -> rawptr #cc_c; -UnmapBuffer: proc(target: i32) #cc_c; +MapBuffer: proc(target, access: i32) -> rawptr #cc_c; +UnmapBuffer: proc(target: i32) #cc_c; -VertexAttribPointer: proc(index: u32, size, type_: i32, normalized: i32, stride: u32, pointer: rawptr) #cc_c; +VertexAttribPointer: proc(index: u32, size, type_: i32, normalized: i32, stride: u32, pointer: rawptr) #cc_c; EnableVertexAttribArray: proc(index: u32) #cc_c; -CreateShader: proc(shader_type: i32) -> u32 #cc_c; -ShaderSource: proc(shader: u32, count: u32, str: ^^byte, length: ^i32) #cc_c; -CompileShader: proc(shader: u32) #cc_c; -CreateProgram: proc() -> u32 #cc_c; -AttachShader: proc(program, shader: u32) #cc_c; -DetachShader: proc(program, shader: u32) #cc_c; -DeleteShader: proc(shader: u32) #cc_c; -LinkProgram: proc(program: u32) #cc_c; -UseProgram: proc(program: u32) #cc_c; -DeleteProgram: proc(program: u32) #cc_c; +CreateShader: proc(shader_type: i32) -> u32 #cc_c; +ShaderSource: proc(shader: u32, count: u32, str: ^^byte, length: ^i32) #cc_c; +CompileShader: proc(shader: u32) #cc_c; +CreateProgram: proc() -> u32 #cc_c; +AttachShader: proc(program, shader: u32) #cc_c; +DetachShader: proc(program, shader: u32) #cc_c; +DeleteShader: proc(shader: u32) #cc_c; +LinkProgram: proc(program: u32) #cc_c; +UseProgram: proc(program: u32) #cc_c; +DeleteProgram: proc(program: u32) #cc_c; -GetShaderiv: proc(shader: u32, pname: i32, params: ^i32) #cc_c; -GetProgramiv: proc(program: u32, pname: i32, params: ^i32) #cc_c; -GetShaderInfoLog: proc(shader: u32, max_length: u32, length: ^u32, info_long: ^byte) #cc_c; -GetProgramInfoLog: proc(program: u32, max_length: u32, length: ^u32, info_long: ^byte) #cc_c; +GetShaderiv: proc(shader: u32, pname: i32, params: ^i32) #cc_c; +GetProgramiv: proc(program: u32, pname: i32, params: ^i32) #cc_c; +GetShaderInfoLog: proc(shader: u32, max_length: u32, length: ^u32, info_long: ^byte) #cc_c; +GetProgramInfoLog: proc(program: u32, max_length: u32, length: ^u32, info_long: ^byte) #cc_c; -ActiveTexture: proc(texture: i32) #cc_c; -GenerateMipmap: proc(target: i32) #cc_c; +ActiveTexture: proc(texture: i32) #cc_c; +GenerateMipmap: proc(target: i32) #cc_c; -SamplerParameteri: proc(sampler: u32, pname: i32, param: i32) #cc_c; -SamplerParameterf: proc(sampler: u32, pname: i32, param: f32) #cc_c; -SamplerParameteriv: proc(sampler: u32, pname: i32, params: ^i32) #cc_c; -SamplerParameterfv: proc(sampler: u32, pname: i32, params: ^f32) #cc_c; -SamplerParameterIiv: proc(sampler: u32, pname: i32, params: ^i32) #cc_c; -SamplerParameterIuiv: proc(sampler: u32, pname: i32, params: ^u32) #cc_c; +SamplerParameteri: proc(sampler: u32, pname: i32, param: i32) #cc_c; +SamplerParameterf: proc(sampler: u32, pname: i32, param: f32) #cc_c; +SamplerParameteriv: proc(sampler: u32, pname: i32, params: ^i32) #cc_c; +SamplerParameterfv: proc(sampler: u32, pname: i32, params: ^f32) #cc_c; +SamplerParameterIiv: proc(sampler: u32, pname: i32, params: ^i32) #cc_c; +SamplerParameterIuiv: proc(sampler: u32, pname: i32, params: ^u32) #cc_c; -Uniform1i: proc(loc: i32, v0: i32) #cc_c; -Uniform2i: proc(loc: i32, v0, v1: i32) #cc_c; -Uniform3i: proc(loc: i32, v0, v1, v2: i32) #cc_c; -Uniform4i: proc(loc: i32, v0, v1, v2, v3: i32) #cc_c; -Uniform1f: proc(loc: i32, v0: f32) #cc_c; -Uniform2f: proc(loc: i32, v0, v1: f32) #cc_c; -Uniform3f: proc(loc: i32, v0, v1, v2: f32) #cc_c; -Uniform4f: proc(loc: i32, v0, v1, v2, v3: f32) #cc_c; -UniformMatrix4fv: proc(loc: i32, count: u32, transpose: i32, value: ^f32) #cc_c; +Uniform1i: proc(loc: i32, v0: i32) #cc_c; +Uniform2i: proc(loc: i32, v0, v1: i32) #cc_c; +Uniform3i: proc(loc: i32, v0, v1, v2: i32) #cc_c; +Uniform4i: proc(loc: i32, v0, v1, v2, v3: i32) #cc_c; +Uniform1f: proc(loc: i32, v0: f32) #cc_c; +Uniform2f: proc(loc: i32, v0, v1: f32) #cc_c; +Uniform3f: proc(loc: i32, v0, v1, v2: f32) #cc_c; +Uniform4f: proc(loc: i32, v0, v1, v2, v3: f32) #cc_c; +UniformMatrix4fv: proc(loc: i32, count: u32, transpose: i32, value: ^f32) #cc_c; -GetUniformLocation: proc(program: u32, name: ^byte) -> i32 #cc_c; +GetUniformLocation: proc(program: u32, name: ^byte) -> i32 #cc_c; init :: proc() { set_proc_address :: proc(p: rawptr, name: string) #inline { (cast(^(proc() #cc_c))p)^ = GetProcAddress(name); } - set_proc_address(^GenBuffers, "glGenBuffers\x00"); - set_proc_address(^GenVertexArrays, "glGenVertexArrays\x00"); - set_proc_address(^GenSamplers, "glGenSamplers\x00"); - set_proc_address(^BindBuffer, "glBindBuffer\x00"); - set_proc_address(^BindSampler, "glBindSampler\x00"); - set_proc_address(^BindVertexArray, "glBindVertexArray\x00"); - set_proc_address(^BufferData, "glBufferData\x00"); - set_proc_address(^BufferSubData, "glBufferSubData\x00"); + set_proc_address(^GenBuffers, "glGenBuffers\x00"); + set_proc_address(^GenVertexArrays, "glGenVertexArrays\x00"); + set_proc_address(^GenSamplers, "glGenSamplers\x00"); + set_proc_address(^BindBuffer, "glBindBuffer\x00"); + set_proc_address(^BindSampler, "glBindSampler\x00"); + set_proc_address(^BindVertexArray, "glBindVertexArray\x00"); + set_proc_address(^BufferData, "glBufferData\x00"); + set_proc_address(^BufferSubData, "glBufferSubData\x00"); - set_proc_address(^DrawArrays, "glDrawArrays\x00"); - set_proc_address(^DrawElements, "glDrawElements\x00"); + set_proc_address(^DrawArrays, "glDrawArrays\x00"); + set_proc_address(^DrawElements, "glDrawElements\x00"); - set_proc_address(^MapBuffer, "glMapBuffer\x00"); - set_proc_address(^UnmapBuffer, "glUnmapBuffer\x00"); + set_proc_address(^MapBuffer, "glMapBuffer\x00"); + set_proc_address(^UnmapBuffer, "glUnmapBuffer\x00"); set_proc_address(^VertexAttribPointer, "glVertexAttribPointer\x00"); set_proc_address(^EnableVertexAttribArray, "glEnableVertexAttribArray\x00"); - set_proc_address(^CreateShader, "glCreateShader\x00"); - set_proc_address(^ShaderSource, "glShaderSource\x00"); - set_proc_address(^CompileShader, "glCompileShader\x00"); - set_proc_address(^CreateProgram, "glCreateProgram\x00"); - set_proc_address(^AttachShader, "glAttachShader\x00"); - set_proc_address(^DetachShader, "glDetachShader\x00"); - set_proc_address(^DeleteShader, "glDeleteShader\x00"); - set_proc_address(^LinkProgram, "glLinkProgram\x00"); - set_proc_address(^UseProgram, "glUseProgram\x00"); - set_proc_address(^DeleteProgram, "glDeleteProgram\x00"); + set_proc_address(^CreateShader, "glCreateShader\x00"); + set_proc_address(^ShaderSource, "glShaderSource\x00"); + set_proc_address(^CompileShader, "glCompileShader\x00"); + set_proc_address(^CreateProgram, "glCreateProgram\x00"); + set_proc_address(^AttachShader, "glAttachShader\x00"); + set_proc_address(^DetachShader, "glDetachShader\x00"); + set_proc_address(^DeleteShader, "glDeleteShader\x00"); + set_proc_address(^LinkProgram, "glLinkProgram\x00"); + set_proc_address(^UseProgram, "glUseProgram\x00"); + set_proc_address(^DeleteProgram, "glDeleteProgram\x00"); - set_proc_address(^GetShaderiv, "glGetShaderiv\x00"); - set_proc_address(^GetProgramiv, "glGetProgramiv\x00"); - set_proc_address(^GetShaderInfoLog, "glGetShaderInfoLog\x00"); - set_proc_address(^GetProgramInfoLog, "glGetProgramInfoLog\x00"); + set_proc_address(^GetShaderiv, "glGetShaderiv\x00"); + set_proc_address(^GetProgramiv, "glGetProgramiv\x00"); + set_proc_address(^GetShaderInfoLog, "glGetShaderInfoLog\x00"); + set_proc_address(^GetProgramInfoLog, "glGetProgramInfoLog\x00"); - set_proc_address(^ActiveTexture, "glActiveTexture\x00"); - set_proc_address(^GenerateMipmap, "glGenerateMipmap\x00"); + set_proc_address(^ActiveTexture, "glActiveTexture\x00"); + set_proc_address(^GenerateMipmap, "glGenerateMipmap\x00"); - set_proc_address(^Uniform1i, "glUniform1i\x00"); - set_proc_address(^UniformMatrix4fv, "glUniformMatrix4fv\x00"); + set_proc_address(^Uniform1i, "glUniform1i\x00"); + set_proc_address(^UniformMatrix4fv, "glUniformMatrix4fv\x00"); - set_proc_address(^GetUniformLocation, "glGetUniformLocation\x00"); + set_proc_address(^GetUniformLocation, "glGetUniformLocation\x00"); - set_proc_address(^SamplerParameteri, "glSamplerParameteri\x00"); - set_proc_address(^SamplerParameterf, "glSamplerParameterf\x00"); - set_proc_address(^SamplerParameteriv, "glSamplerParameteriv\x00"); - set_proc_address(^SamplerParameterfv, "glSamplerParameterfv\x00"); - set_proc_address(^SamplerParameterIiv, "glSamplerParameterIiv\x00"); - set_proc_address(^SamplerParameterIuiv, "glSamplerParameterIuiv\x00"); + set_proc_address(^SamplerParameteri, "glSamplerParameteri\x00"); + set_proc_address(^SamplerParameterf, "glSamplerParameterf\x00"); + set_proc_address(^SamplerParameteriv, "glSamplerParameteriv\x00"); + set_proc_address(^SamplerParameterfv, "glSamplerParameterfv\x00"); + set_proc_address(^SamplerParameterIiv, "glSamplerParameterIiv\x00"); + set_proc_address(^SamplerParameterIuiv, "glSamplerParameterIuiv\x00"); } diff --git a/core/sys/windows.odin b/core/sys/windows.odin index 4c32cbd3e..165a0f761 100644 --- a/core/sys/windows.odin +++ b/core/sys/windows.odin @@ -41,11 +41,14 @@ WS_CAPTION :: 0x00C00000; WS_VISIBLE :: 0x10000000; WS_OVERLAPPEDWINDOW :: WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX; -WM_DESTROY :: 0x0002; -WM_CLOSE :: 0x0010; -WM_QUIT :: 0x0012; -WM_KEYDOWN :: 0x0100; -WM_KEYUP :: 0x0101; +WM_DESTROY :: 0x0002; +WM_SIZE :: 0x0005; +WM_CLOSE :: 0x0010; +WM_ACTIVATEAPP :: 0x001C; +WM_QUIT :: 0x0012; +WM_KEYDOWN :: 0x0100; +WM_KEYUP :: 0x0101; +WM_SIZING :: 0x0214; PM_REMOVE :: 1; diff --git a/core/utf8.odin b/core/utf8.odin index d1798547d..8720e1f20 100644 --- a/core/utf8.odin +++ b/core/utf8.odin @@ -30,7 +30,7 @@ HICB :: 0b1011_1111; Accept_Range :: struct { lo, hi: u8 } -accept_ranges := [5]Accept_Range{ +immutable accept_ranges := [5]Accept_Range{ {0x80, 0xbf}, {0xa0, 0xbf}, {0x80, 0x9f}, @@ -38,7 +38,7 @@ accept_ranges := [5]Accept_Range{ {0x80, 0x8f}, }; -accept_sizes := [256]byte{ +immutable accept_sizes := [256]byte{ 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x00-0x0f 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x10-0x1f 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, 0xf0, // 0x20-0x2f diff --git a/src/build_settings.c b/src/build_settings.c index fd4af92c2..d1dcecf6e 100644 --- a/src/build_settings.c +++ b/src/build_settings.c @@ -1,4 +1,6 @@ +// This stores the information for the specify architecture of this build typedef struct BuildContext { + // Constants String ODIN_OS; // target operating system String ODIN_ARCH; // target architecture String ODIN_ENDIAN; // target endian @@ -6,8 +8,10 @@ typedef struct BuildContext { String ODIN_VERSION; // compiler version String ODIN_ROOT; // Odin ROOT - i64 word_size; - i64 max_align; + // In bytes + i64 word_size; // Size of a pointer, must be >= 4 + i64 max_align; // max alignment, must be >= 1 (and typically >= word_size) + String llc_flags; String link_flags; bool is_dll; diff --git a/src/check_expr.c b/src/check_expr.c index 25576ae85..355f4016e 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -4103,7 +4103,8 @@ void check_set_mode_with_indirection(Operand *o, bool indirection) { if (o->mode != Addressing_Immutable) { if (indirection) { o->mode = Addressing_Variable; - } else if (o->mode != Addressing_Variable) { + } else if (o->mode != Addressing_Variable && + o->mode != Addressing_Constant) { o->mode = Addressing_Value; } } @@ -4139,7 +4140,9 @@ bool check_set_index_data(Operand *o, Type *type, bool indirection, i64 *max_cou case Type_Slice: o->type = t->Slice.elem; - o->mode = Addressing_Variable; + if (o->mode != Addressing_Immutable) { + o->mode = Addressing_Variable; + } return true; case Type_DynamicArray: @@ -5132,7 +5135,9 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint goto error; } - o->mode = Addressing_Value; + if (o->mode != Addressing_Immutable) { + o->mode = Addressing_Value; + } i64 indices[2] = {0}; AstNode *nodes[2] = {se->low, se->high}; diff --git a/src/checker.c b/src/checker.c index 5ae1460ad..c2fd9e672 100644 --- a/src/checker.c +++ b/src/checker.c @@ -6,22 +6,6 @@ typedef enum ExprKind { Expr_Stmt, } ExprKind; -typedef enum AddressingMode { - Addressing_Invalid, - - Addressing_NoValue, - Addressing_Value, - Addressing_Variable, - Addressing_Immutable, - Addressing_Constant, - Addressing_Type, - Addressing_Builtin, - Addressing_Overload, - Addressing_MapIndex, - - Addressing_Count, -} AddressingMode; - // Statements and Declarations typedef enum StmtFlag { Stmt_BreakAllowed = 1<<0, @@ -124,11 +108,26 @@ gb_global BuiltinProc builtin_procs[BuiltinProc_Count] = { #include "types.c" -#define MAP_TYPE Entity * -#define MAP_PROC map_entity_ -#define MAP_NAME MapEntity -#include "map.c" +typedef enum AddressingMode { + Addressing_Invalid, // invalid addressing mode + Addressing_NoValue, // no value (void in C) + Addressing_Value, // computed value (rvalue) + Addressing_Immutable, // immutable computed value (const rvalue) + Addressing_Variable, // addressable variable (lvalue) + Addressing_Constant, // constant & type will be a of Type_Basic (stripping Type_Named) + Addressing_Type, // type + Addressing_Builtin, // built in procedure + Addressing_Overload, // overloaded procedure + Addressing_MapIndex, // map index expression + // lhs: acts like a Variable + // ths: acts like a value with an optional boolean part (for existence check) +} AddressingMode; +// Operand is used as an intermediate value whilst checking +// Operands store an addressing mode, the expression being evaluated, +// its type and node, and other specific information for certain +// addressing modes +// Its zero-value is a valid "invalid operand" typedef struct Operand { AddressingMode mode; Type * type; @@ -161,7 +160,7 @@ bool is_operand_nil(Operand o) { } - +// DeclInfo is used to store information of certain declarations to allow for "any order" usage typedef struct DeclInfo { Scope *scope; @@ -175,6 +174,17 @@ typedef struct DeclInfo { MapBool deps; // Key: Entity * } DeclInfo; +// ProcedureInfo stores the information needed for checking a procedure +typedef struct ProcedureInfo { + AstFile * file; + Token token; + DeclInfo *decl; + Type * type; // Type_Procedure + AstNode * body; // AstNode_BlockStmt + u32 tags; +} ProcedureInfo; + +// ExprInfo stores information used for "untyped" expressions typedef struct ExprInfo { bool is_lhs; // Debug info AddressingMode mode; @@ -187,14 +197,12 @@ ExprInfo make_expr_info(bool is_lhs, AddressingMode mode, Type *type, ExactValue return ei; } -typedef struct ProcedureInfo { - AstFile * file; - Token token; - DeclInfo *decl; - Type * type; // Type_Procedure - AstNode * body; // AstNode_BlockStmt - u32 tags; -} ProcedureInfo; + + +#define MAP_TYPE Entity * +#define MAP_PROC map_entity_ +#define MAP_NAME MapEntity +#include "map.c" typedef struct Scope { Scope * parent; @@ -258,7 +266,7 @@ typedef struct CheckerContext { Type * type_hint; } CheckerContext; -// NOTE(bill): Symbol tables +// CheckerInfo stores all the symbol information for a type-checked program typedef struct CheckerInfo { MapTypeAndValue types; // Key: AstNode * | Expression -> Type (and value) MapEntity definitions; // Key: AstNode * | Identifier -> Entity diff --git a/src/common.c b/src/common.c index f09282b5a..2c40e22ed 100644 --- a/src/common.c +++ b/src/common.c @@ -131,6 +131,9 @@ i16 f32_to_f16(f32 value) { // //////////////////////////////////////////////////////////////// +typedef Array(i32) Array_i32; +typedef Array(isize) Array_isize; + #define MAP_TYPE String #define MAP_PROC map_string_ diff --git a/src/entity.c b/src/entity.c index 04ef323a1..99acef870 100644 --- a/src/entity.c +++ b/src/entity.c @@ -40,12 +40,15 @@ typedef enum EntityFlag { EntityFlag_TypeField = 1<<8, } EntityFlag; +// Zero value means the overloading process is not yet done typedef enum OverloadKind { - Overload_No = -1, - Overload_Unknown = 0, - Overload_Yes = +1, + Overload_Unknown, + Overload_No, + Overload_Yes, } OverloadKind; + +// An Entity is a named "thing" in the language typedef struct Entity Entity; struct Entity { EntityKind kind; diff --git a/src/map.c b/src/map.c index 60af7f668..83c9ce95a 100644 --- a/src/map.c +++ b/src/map.c @@ -6,6 +6,9 @@ #define MAP_NAME MapString #include "map.c" */ +// A `Map` is an unordered hash table which can allow for a key to point to multiple values +// with the use of the `multi_*` procedures. +// TODO(bill): I should probably allow the `multi_*` stuff to be #ifdefed out #ifndef MAP_UTIL_STUFF #define MAP_UTIL_STUFF diff --git a/src/parser.c b/src/parser.c index 69ea32c48..fedde531e 100644 --- a/src/parser.c +++ b/src/parser.c @@ -111,7 +111,9 @@ AstNodeArray make_ast_node_array(AstFile *f) { } - +// NOTE(bill): This massive define is so it is possible to create a discriminated union (and extra debug info) +// for the AstNode. I personally prefer discriminated unions over subtype polymorphism as I can preallocate +// all the nodes and even memcpy in a different kind of node #define AST_NODE_KINDS \ AST_NODE_KIND(Ident, "identifier", Token) \ AST_NODE_KIND(Implicit, "implicit", Token) \ diff --git a/src/string.c b/src/string.c index 38874a7d5..19161de93 100644 --- a/src/string.c +++ b/src/string.c @@ -19,6 +19,7 @@ typedef struct String { #define str_lit(c_str) (String){cast(u8 *)c_str, gb_size_of(c_str)-1} +// NOTE(bill): String16 is only used for Windows due to its file directories typedef struct String16 { wchar_t *text; isize len; diff --git a/src/types.c b/src/types.c index 6c0524955..06a407576 100644 --- a/src/types.c +++ b/src/types.c @@ -178,8 +178,9 @@ typedef struct Type { bool failure; } Type; -typedef Array(i32) Array_i32; +// TODO(bill): Should I add extra information here specifying the kind of selection? +// e.g. field, constant, vector field, type field, etc. typedef struct Selection { Entity * entity; Array_i32 index; @@ -195,6 +196,7 @@ Selection make_selection(Entity *entity, Array_i32 index, bool indirect) { void selection_add_index(Selection *s, isize index) { // IMPORTANT NOTE(bill): this requires a stretchy buffer/dynamic array so it requires some form // of heap allocation + // TODO(bill): Find a way to use a backing buffer for initial use as the general case is probably .count<3 if (s->index.e == NULL) { array_init(&s->index, heap_allocator()); } @@ -277,6 +279,7 @@ gb_global Type *t_byte_slice = NULL; gb_global Type *t_string_slice = NULL; +// Type generated for the "preload" file gb_global Type *t_type_info = NULL; gb_global Type *t_type_info_record = NULL; gb_global Type *t_type_info_enum_value = NULL; @@ -303,7 +306,6 @@ gb_global Type *t_type_info_raw_union = NULL; gb_global Type *t_type_info_enum = NULL; gb_global Type *t_type_info_map = NULL; - gb_global Type *t_type_info_named_ptr = NULL; gb_global Type *t_type_info_integer_ptr = NULL; gb_global Type *t_type_info_float_ptr = NULL; @@ -323,8 +325,6 @@ gb_global Type *t_type_info_raw_union_ptr = NULL; gb_global Type *t_type_info_enum_ptr = NULL; gb_global Type *t_type_info_map_ptr = NULL; - - gb_global Type *t_allocator = NULL; gb_global Type *t_allocator_ptr = NULL; gb_global Type *t_context = NULL; @@ -337,14 +337,15 @@ gb_global Type *t_map_header = NULL; -i64 type_size_of (gbAllocator allocator, Type *t); -i64 type_align_of (gbAllocator allocator, Type *t); -i64 type_offset_of(gbAllocator allocator, Type *t, i32 index); - +i64 type_size_of (gbAllocator allocator, Type *t); +i64 type_align_of (gbAllocator allocator, Type *t); +i64 type_offset_of (gbAllocator allocator, Type *t, i32 index); gbString type_to_string(Type *type); + + Type *base_type(Type *t) { for (;;) { if (t == NULL) {