Writing to windows console through foreign calls!
This commit is contained in:
11
Windows.kl
11
Windows.kl
@@ -6,6 +6,9 @@ HINSTANCE :: *void
|
|||||||
LPVOID :: *void
|
LPVOID :: *void
|
||||||
SIZE_T :: U64
|
SIZE_T :: U64
|
||||||
BOOL :: int
|
BOOL :: int
|
||||||
|
HANDLE :: *void
|
||||||
|
VOID :: void
|
||||||
|
LPDWORD :: *DWORD
|
||||||
|
|
||||||
CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND
|
CreateWindowA :: #foreign (dwExStyle: DWORD, lpClassName: *char, lpWindowName: *char, dwStyle: DWORD, X: int, Y: int, nWidth: int, nHeight: int, hWndParent: HWND, hMenu: HMENU, hInstance: HINSTANCE, lpParam: *void): HWND
|
||||||
|
|
||||||
@@ -28,4 +31,10 @@ PAGE_EXECUTE_READWRITE :: 0x40
|
|||||||
PAGE_EXECUTE_WRITECOPY :: 0x80
|
PAGE_EXECUTE_WRITECOPY :: 0x80
|
||||||
|
|
||||||
VirtualAlloc :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD): LPVOID
|
VirtualAlloc :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, flAllocationType: DWORD, flProtect: DWORD): LPVOID
|
||||||
VirtualFree :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, dwFreeType: DWORD): BOOL
|
VirtualFree :: #foreign (lpAddress: LPVOID, dwSize: SIZE_T, dwFreeType: DWORD): BOOL
|
||||||
|
|
||||||
|
STD_INPUT_HANDLE :: 4294967286//(-10)->DWORD
|
||||||
|
STD_OUTPUT_HANDLE :: 4294967285//(-11)->DWORD
|
||||||
|
//STD_ERROR_HANDLE :: (-12)->DWORD
|
||||||
|
GetStdHandle :: #foreign (nStdHandle: DWORD): HANDLE
|
||||||
|
WriteConsoleA :: #foreign (hConsoleOutput: HANDLE,lpBuffer: *VOID,nNumberOfCharsToWrite: DWORD,lpNumberOfCharsWritten: LPDWORD,lpReserve: LPVOID): BOOL
|
||||||
3
main.cpp
3
main.cpp
@@ -50,7 +50,7 @@ want to export all the symbols, we can namespace them optionally.
|
|||||||
[ ] - Some way to take slice of data
|
[ ] - Some way to take slice of data
|
||||||
[ ] - slices should be properly displayed in debugger
|
[ ] - slices should be properly displayed in debugger
|
||||||
[ ] - elif
|
[ ] - elif
|
||||||
[ ] - Hex 0x42
|
[ ] - Imports inside of import shouldn't spill outside
|
||||||
|
|
||||||
[ ] - #assert that handles constants at compile time and vars at runtime
|
[ ] - #assert that handles constants at compile time and vars at runtime
|
||||||
[ ] - Comma notation when declaring variables thing1, thing2: S32
|
[ ] - Comma notation when declaring variables thing1, thing2: S32
|
||||||
@@ -76,6 +76,7 @@ want to export all the symbols, we can namespace them optionally.
|
|||||||
|
|
||||||
@donzo
|
@donzo
|
||||||
[x] - Scope
|
[x] - Scope
|
||||||
|
[x] - Hex 0x42
|
||||||
[x] - Rewrite where # happen,
|
[x] - Rewrite where # happen,
|
||||||
[x] - cast ->
|
[x] - cast ->
|
||||||
[x] - Remodel compound from call to {}
|
[x] - Remodel compound from call to {}
|
||||||
|
|||||||
7
main.kl
7
main.kl
@@ -1,6 +1,9 @@
|
|||||||
Base :: #load "base.kl"
|
Base :: #load "base.kl"
|
||||||
|
Win :: #load "Windows.kl"
|
||||||
CONSTANT :: 0xabCAFAAABCDAEAA
|
|
||||||
|
|
||||||
main :: (argc: int, argv: **char): int
|
main :: (argc: int, argv: **char): int
|
||||||
memory := Base.reserve(size = 10000)
|
memory := Base.reserve(size = 10000)
|
||||||
|
handle := Win.GetStdHandle(Win.STD_OUTPUT_HANDLE)
|
||||||
|
|
||||||
|
string: *char = "hello world"
|
||||||
|
Win.WriteConsoleA(handle, string->*void, 11, 0, 0)
|
||||||
|
|||||||
71
program.c
71
program.c
@@ -1,71 +0,0 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
typedef int8_t S8;
|
|
||||||
typedef int16_t S16;
|
|
||||||
typedef int32_t S32;
|
|
||||||
typedef int64_t S64;
|
|
||||||
typedef uint8_t U8;
|
|
||||||
typedef uint16_t U16;
|
|
||||||
typedef uint32_t U32;
|
|
||||||
typedef uint64_t U64;
|
|
||||||
typedef S8 B8;
|
|
||||||
typedef S16 B16;
|
|
||||||
typedef S32 B32;
|
|
||||||
typedef S64 B64;
|
|
||||||
typedef U64 SizeU;
|
|
||||||
typedef S64 SizeS;
|
|
||||||
typedef float F32;
|
|
||||||
typedef double F64;
|
|
||||||
typedef S32 Bool;
|
|
||||||
#define true 1
|
|
||||||
#define false 0
|
|
||||||
|
|
||||||
typedef struct Slice{
|
|
||||||
S64 len;
|
|
||||||
void *data;
|
|
||||||
}Slice;
|
|
||||||
|
|
||||||
typedef struct String{
|
|
||||||
U8 *str;
|
|
||||||
S64 len;
|
|
||||||
}String;
|
|
||||||
#define LIT(x) (String){.str=(U8 *)x, .len=sizeof(x)-1}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Type SizeU = base_
|
|
||||||
|
|
||||||
typedef struct base_OS_Memory{
|
|
||||||
U64 base_commit;
|
|
||||||
U64 base_reserve;
|
|
||||||
U8 *base_data;
|
|
||||||
}base_OS_Memory;
|
|
||||||
U64 base_get_align_offset(U64 base_size, U64 base_align){
|
|
||||||
U64 base_mask = (base_align-1);
|
|
||||||
U64 base_val = (base_size&base_mask);
|
|
||||||
if((base_val!=0)){
|
|
||||||
base_val=(base_align-base_val);
|
|
||||||
}
|
|
||||||
return base_val;
|
|
||||||
}
|
|
||||||
U64 base_align_up(U64 base_size, U64 base_align){
|
|
||||||
U64 base_result = (base_size+base_get_align_offset(base_size, base_align));
|
|
||||||
return base_result;
|
|
||||||
}
|
|
||||||
// constant int OS_PAGE_SIZE = 4096
|
|
||||||
|
|
||||||
// Type LPVOID = (*Windows_)
|
|
||||||
// Type SIZE_T = Windows_
|
|
||||||
|
|
||||||
// Type DWORD = Windows_
|
|
||||||
/*foreign*/void *VirtualAlloc(void *Windows_lpAddress, U64 Windows_dwSize, U32 Windows_flAllocationType, U32 Windows_flProtect);
|
|
||||||
// constant int MEM_RESERVE = 2
|
|
||||||
// constant int PAGE_READWRITE = 4
|
|
||||||
base_OS_Memory base_reserve(U64 base_size){
|
|
||||||
base_OS_Memory base_result = (base_OS_Memory ){base_align_up(base_size, 4096)};
|
|
||||||
base_result.base_data=((U8 *)VirtualAlloc(0, base_result.base_reserve, 2, 4));
|
|
||||||
return base_result;
|
|
||||||
}
|
|
||||||
int main(int main_argc, char **main_argv){
|
|
||||||
Reference in New Issue
Block a user