Handle calling conventions correctly

This commit is contained in:
Ginger Bill
2016-12-22 23:06:31 +00:00
parent 923b039cf6
commit d714bece47
19 changed files with 290 additions and 203 deletions
+8 -8
View File
@@ -1,10 +1,10 @@
#shared_global_scope;
import (
import {
"os.odin";
"fmt.odin";
"mem.odin";
)
}
// IMPORTANT NOTE(bill): `type_info` & `type_info_val` cannot be used within a
// #shared_global_scope due to the internals of the compiler.
@@ -14,7 +14,7 @@ import (
// IMPORTANT NOTE(bill): Do not change the order of any of this data
// The compiler relies upon this _exact_ order
type (
type {
Type_Info_Member struct #ordered {
name string; // can be empty if tuple
type_info ^Type_Info;
@@ -74,7 +74,7 @@ type (
Union Type_Info_Record;
Raw_Union Type_Info_Record;
}
)
}
proc type_info_base(info ^Type_Info) -> ^Type_Info {
if info == nil {
@@ -113,13 +113,13 @@ proc fmuladd64(a, b, c f64) -> f64 #foreign "llvm.fmuladd.f64"
type Allocator_Mode u8;
const (
const {
ALLOCATOR_ALLOC Allocator_Mode = iota;
ALLOCATOR_FREE;
ALLOCATOR_FREE_ALL;
ALLOCATOR_RESIZE;
);
type (
}
type {
Allocator_Proc proc(allocator_data rawptr, mode Allocator_Mode,
size, alignment int,
old_memory rawptr, old_size int, flags u64) -> rawptr;
@@ -136,7 +136,7 @@ type (
user_data rawptr;
user_index int;
}
);
}
#thread_local var __context Context;
+2 -2
View File
@@ -1,8 +1,8 @@
import (
import {
"os.odin";
"mem.odin";
"utf8.odin";
)
}
const PRINT_BUF_SIZE = 1<<12;
+4 -4
View File
@@ -1,4 +1,4 @@
const (
const {
TAU = 6.28318530717958647692528676655900576;
PI = 3.14159265358979323846264338327950288;
ONE_OVER_TAU = 0.636619772367581343075535053490057448;
@@ -16,9 +16,9 @@ const (
τ = TAU;
π = PI;
)
}
type (
type {
Vec2 [vector 2]f32;
Vec3 [vector 3]f32;
Vec4 [vector 4]f32;
@@ -26,7 +26,7 @@ type (
Mat2 [2]Vec2;
Mat3 [3]Vec3;
Mat4 [4]Vec4;
)
}
proc sqrt32(x f32) -> f32 #foreign "llvm.sqrt.f32"
proc sqrt64(x f64) -> f64 #foreign "llvm.sqrt.f64"
+4 -4
View File
@@ -1,7 +1,7 @@
import (
import {
"fmt.odin";
"os.odin";
)
}
proc set(data rawptr, value i32, len int) -> rawptr #link_name "__mem_set" {
proc llvm_memset_64bit(dst rawptr, val byte, len int, align i32, is_volatile bool) #foreign "llvm.memset.p0i8.i64"
@@ -116,7 +116,7 @@ proc allocation_header(data rawptr) -> ^Allocation_Header {
// Custom allocators
type (
type {
Arena struct {
backing Allocator;
memory []byte;
@@ -127,7 +127,7 @@ type (
arena ^Arena;
original_count int;
}
)
}
+50 -50
View File
@@ -32,7 +32,7 @@ proc GetIntegerv(name i32, v ^i32) #foreign "glGetIntegerv"
var _libgl = win32.LoadLibraryA(("opengl32.dll\x00" as string).data);
proc GetProcAddress(name string) -> proc() {
proc GetProcAddress(name string) -> proc() #cc_c {
assert(name[name.count-1] == 0);
var res = win32.wglGetProcAddress(name.data);
if res == nil {
@@ -41,68 +41,68 @@ proc GetProcAddress(name string) -> proc() {
return res;
}
var (
GenBuffers proc(count i32, buffers ^u32);
GenVertexArrays proc(count i32, buffers ^u32);
GenSamplers proc(count i32, buffers ^u32);
BindBuffer proc(target i32, buffer u32);
BindVertexArray proc(buffer u32);
BindSampler proc(position i32, sampler u32);
BufferData proc(target i32, size int, data rawptr, usage i32);
BufferSubData proc(target i32, offset, size int, data rawptr);
var {
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);
DrawElements proc(mode i32, count u32, type_ i32, indices rawptr);
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;
UnmapBuffer proc(target i32);
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);
EnableVertexAttribArray proc(index u32);
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;
ShaderSource proc(shader u32, count u32, str ^^byte, length ^i32);
CompileShader proc(shader u32);
CreateProgram proc() -> u32;
AttachShader proc(program, shader u32);
DetachShader proc(program, shader u32);
DeleteShader proc(shader u32);
LinkProgram proc(program u32);
UseProgram proc(program u32);
DeleteProgram proc(program u32);
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);
GetProgramiv proc(program u32, pname i32, params ^i32);
GetShaderInfoLog proc(shader u32, max_length u32, length ^u32, info_long ^byte);
GetProgramInfoLog proc(program u32, max_length u32, length ^u32, info_long ^byte);
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);
GenerateMipmap proc(target i32);
ActiveTexture proc(texture i32) #cc_c;
GenerateMipmap proc(target i32) #cc_c;
SamplerParameteri proc(sampler u32, pname i32, param i32);
SamplerParameterf proc(sampler u32, pname i32, param f32);
SamplerParameteriv proc(sampler u32, pname i32, params ^i32);
SamplerParameterfv proc(sampler u32, pname i32, params ^f32);
SamplerParameterIiv proc(sampler u32, pname i32, params ^i32);
SamplerParameterIuiv proc(sampler u32, pname i32, params ^u32);
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);
Uniform2i proc(loc i32, v0, v1 i32);
Uniform3i proc(loc i32, v0, v1, v2 i32);
Uniform4i proc(loc i32, v0, v1, v2, v3 i32);
Uniform1f proc(loc i32, v0 f32);
Uniform2f proc(loc i32, v0, v1 f32);
Uniform3f proc(loc i32, v0, v1, v2 f32);
Uniform4f proc(loc i32, v0, v1, v2, v3 f32);
UniformMatrix4fv proc(loc i32, count u32, transpose i32, value ^f32);
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;
);
GetUniformLocation proc(program u32, name ^byte) -> i32 #cc_c;
}
proc init() {
proc set_proc_address(p rawptr, name string) #inline { (p as ^proc())^ = GetProcAddress(name); }
proc set_proc_address(p rawptr, name string) #inline { (p as ^(proc() #cc_c))^ = GetProcAddress(name); }
set_proc_address(^GenBuffers, "glGenBuffers\x00");
set_proc_address(^GenVertexArrays, "glGenVertexArrays\x00");
+2 -2
View File
@@ -1,4 +1,4 @@
const (
const {
FALSE = 0;
TRUE = 1;
@@ -1382,4 +1382,4 @@ const (
DEBUG_SEVERITY_HIGH_ARB = 0x9146;
DEBUG_SEVERITY_MEDIUM_ARB = 0x9147;
DEBUG_SEVERITY_LOW_ARB = 0x9148;
);
}
+8 -8
View File
@@ -1,9 +1,9 @@
import (
import {
win32 "sys/windows.odin";
"fmt.odin";
)
}
type (
type {
File_Time u64;
File_Handle raw_union {
@@ -15,7 +15,7 @@ type (
handle File_Handle;
last_write_time File_Time;
}
)
}
proc open(name string) -> (File, bool) {
using win32;
@@ -87,15 +87,15 @@ proc last_write_time_by_name(name string) -> File_Time {
const (
const {
FILE_STANDARD_INPUT = iota;
FILE_STANDARD_OUTPUT;
FILE_STANDARD_ERROR;
FILE_STANDARD_COUNT;
)
}
// NOTE(bill): Uses startup to initialize it
var (
var {
__std_files = [FILE_STANDARD_COUNT]File{
{handle = win32.GetStdHandle(win32.STD_INPUT_HANDLE) transmute File_Handle },
{handle = win32.GetStdHandle(win32.STD_OUTPUT_HANDLE) transmute File_Handle },
@@ -105,7 +105,7 @@ var (
stdin = ^__std_files[FILE_STANDARD_INPUT];
stdout = ^__std_files[FILE_STANDARD_OUTPUT];
stderr = ^__std_files[FILE_STANDARD_ERROR];
)
}
proc read_entire_file(name string) -> ([]byte, bool) {
+4 -4
View File
@@ -1,9 +1,9 @@
import (
import {
win32 "sys/windows.odin" when ODIN_OS == "windows";
"atomic.odin";
)
}
type (
type {
Semaphore struct {
handle win32.HANDLE;
}
@@ -14,7 +14,7 @@ type (
owner i32;
recursion i32;
}
)
}
proc current_thread_id() -> i32 {
return win32.GetCurrentThreadId() as i32;
+23 -23
View File
@@ -1,7 +1,7 @@
#foreign_system_library "user32" when ODIN_OS == "windows";
#foreign_system_library "gdi32" when ODIN_OS == "windows";
type (
type {
HANDLE rawptr;
HWND HANDLE;
HDC HANDLE;
@@ -18,9 +18,9 @@ type (
ATOM i16;
BOOL i32;
WNDPROC proc(hwnd HWND, msg u32, wparam WPARAM, lparam LPARAM) -> LRESULT;
)
}
const (
const {
INVALID_HANDLE_VALUE = (-1 as int) as HANDLE;
CS_VREDRAW = 0x0001;
@@ -52,9 +52,9 @@ const (
SM_CYSCREEN = 1;
SW_SHOW = 5;
)
}
type (
type {
POINT struct #ordered {
x, y i32;
}
@@ -114,11 +114,11 @@ type (
}
GET_FILEEX_INFO_LEVELS i32;
)
const (
}
const {
GetFileExInfoStandard = 0 as GET_FILEEX_INFO_LEVELS;
GetFileExMaxInfoLevel = 1 as GET_FILEEX_INFO_LEVELS;
)
}
proc GetLastError () -> i32 #foreign #dll_import
proc ExitProcess (exit_code u32) #foreign #dll_import
@@ -183,7 +183,7 @@ proc GetFileSizeEx (file_handle HANDLE, file_size ^i64) -> BOOL #for
proc GetFileAttributesExA (filename ^u8, info_level_id GET_FILEEX_INFO_LEVELS, file_info rawptr) -> BOOL #foreign #dll_import
proc GetFileInformationByHandle(file_handle HANDLE, file_info ^BY_HANDLE_FILE_INFORMATION) -> BOOL #foreign #dll_import
const (
const {
FILE_SHARE_READ = 0x00000001;
FILE_SHARE_WRITE = 0x00000002;
FILE_SHARE_DELETE = 0x00000004;
@@ -201,7 +201,7 @@ const (
OPEN_EXISTING = 3;
OPEN_ALWAYS = 4;
TRUNCATE_EXISTING = 5;
)
}
@@ -248,7 +248,7 @@ proc ReadBarrier () #foreign
// GDI
type (
type {
BITMAPINFOHEADER struct #ordered {
size u32;
width, height i32;
@@ -269,13 +269,13 @@ type (
RGBQUAD struct #ordered {
blue, green, red, reserved byte;
}
)
}
const (
const {
BI_RGB = 0;
DIB_RGB_COLORS = 0x00;
SRCCOPY = 0x00cc0020 as u32;
)
}
proc StretchDIBits(hdc HDC,
x_dst, y_dst, width_dst, height_dst i32,
@@ -295,7 +295,7 @@ proc GetClientRect(hwnd HWND, rect ^RECT) -> BOOL #foreign
// Windows OpenGL
const (
const {
PFD_TYPE_RGBA = 0;
PFD_TYPE_COLORINDEX = 1;
PFD_MAIN_PLANE = 0;
@@ -317,11 +317,11 @@ const (
PFD_DEPTH_DONTCARE = 0x20000000;
PFD_DOUBLEBUFFER_DONTCARE = 0x40000000;
PFD_STEREO_DONTCARE = 0x80000000;
)
}
type (
type {
HGLRC HANDLE;
PROC proc();
PROC proc() #cc_c;
wglCreateContextAttribsARBType proc(hdc HDC, hshareContext rawptr, attribList ^i32) -> HGLRC;
@@ -355,7 +355,7 @@ type (
visible_mask,
damage_mask u32;
}
)
}
proc GetDC (h HANDLE) -> HDC #foreign
proc SetPixelFormat (hdc HDC, pixel_format i32, pfd ^PIXELFORMATDESCRIPTOR ) -> BOOL #foreign #dll_import
@@ -363,13 +363,13 @@ proc ChoosePixelFormat(hdc HDC, pfd ^PIXELFORMATDESCRIPTOR) -> i32 #foreign #dll
proc SwapBuffers (hdc HDC) -> BOOL #foreign #dll_import
proc ReleaseDC (wnd HWND, hdc HDC) -> i32 #foreign #dll_import
const (
const {
WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
WGL_CONTEXT_MINOR_VERSION_ARB = 0x2092;
WGL_CONTEXT_PROFILE_MASK_ARB = 0x9126;
WGL_CONTEXT_CORE_PROFILE_BIT_ARB = 0x0001;
WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x0002;
)
}
proc wglCreateContext (hdc HDC) -> HGLRC #foreign #dll_import
proc wglMakeCurrent (hdc HDC, hglrc HGLRC) -> BOOL #foreign #dll_import
@@ -383,7 +383,7 @@ proc GetAsyncKeyState(v_key i32) -> i16 #foreign #dll_import
proc is_key_down(key i32) -> bool #inline { return GetAsyncKeyState(key) < 0; }
const (
const {
KEY_LBUTTON = 0x01;
KEY_RBUTTON = 0x02;
KEY_CANCEL = 0x03;
@@ -535,5 +535,5 @@ const (
KEY_NONAME = 0xFC;
KEY_PA1 = 0xFD;
KEY_OEM_CLEAR = 0xFE;
)
}
+6 -6
View File
@@ -1,4 +1,4 @@
const (
const {
RUNE_ERROR = '\ufffd';
RUNE_SELF = 0x80;
RUNE_BOM = 0xfeff;
@@ -8,13 +8,13 @@ const (
SURROGATE_MIN = 0xd800;
SURROGATE_MAX = 0xdfff;
)
}
type Accept_Range struct {
lo, hi u8;
}
var (
var {
accept_ranges = [5]Accept_Range{
{0x80, 0xbf},
{0xa0, 0xbf},
@@ -42,7 +42,7 @@ var (
0x13, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x23, 0x03, 0x03, // 0xe0-0xef
0x34, 0x04, 0x04, 0x04, 0x44, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, 0xf1, // 0xf0-0xff
};
)
}
proc encode_rune(r rune) -> ([4]byte, int) {
var buf [4]byte;
@@ -99,12 +99,12 @@ proc decode_rune(s string) -> (rune, int) {
return RUNE_ERROR, 1;
}
const (
const {
MASK_X = 0b00111111;
MASK_2 = 0b00011111;
MASK_3 = 0b00001111;
MASK_4 = 0b00000111;
)
}
if size == 2 {
return (b0&MASK_2) as rune <<6 | (b1&MASK_X) as rune, 2;