Skip to content

Instantly share code, notes, and snippets.

View WheretIB's full-sized avatar

Vyacheslav Egorov WheretIB

View GitHub Profile
#include "runtime.h"
// Typeid redirect table
static unsigned __nullcTR[170];
// Function pointer table
static __nullcFunctionArray* __nullcFM;
// Function pointer redirect table
static unsigned __nullcFR[183];
// Type prototypes
struct auto_ref;
@WheretIB
WheretIB / externacall.cpp
Last active March 21, 2019 19:03
nullc external function call with struct types using dyncall (not implemented in 1.0)
void FillCallStructType(DCstruct *&callType, FastVector<ExternTypeInfo> &typeInfo, FastVector<ExternMemberInfo> &memberInfo, ExternTypeInfo &type, unsigned count)
{
switch(type.subCat)
{
case ExternTypeInfo::CAT_NONE:
assert(callType);
switch(type.type)
{
@WheretIB
WheretIB / llvm_stub.cpp
Created March 24, 2019 13:43
llvm interface stubs
struct LLVMContextRefOpaque{};
struct LLVMModuleRefOpaque{};
struct LLVMBuilderRefOpaque{};
struct LLVMPassManagerRefOpaque{};
struct LLVMTypeRefOpaque{};
struct LLVMValueRefOpaque{};
struct LLVMBasicBlockRefOpaque{};
typedef LLVMContextRefOpaque* LLVMContextRef;
#define SHORT(X) typedef NullcCallBaseType<X>::type X##u; const unsigned X##s = NullcCallBaseType<X>::size
#define SHORTS_0 (void)argBuf
#define SHORTS_1 SHORT(A1)
#define SHORTS_2 SHORTS_1; SHORT(A2)
#define SHORTS_3 SHORTS_2; SHORT(A3)
#define SHORTS_4 SHORTS_3; SHORT(A4)
#define SHORTS_5 SHORTS_4; SHORT(A5)
#define SHORTS_6 SHORTS_5; SHORT(A6)
#define SHORTS_7 SHORTS_6; SHORT(A7)
__declspec(naked) void* self()
{
__asm mov eax, [esp]
__asm ret
}
int test()
{
DWORD unused = 0;
VirtualProtect(self(), 4096, PAGE_EXECUTE_READWRITE, &unused);
@WheretIB
WheretIB / t_nbody.nc
Created September 22, 2019 08:31
nullc tests
import std.io;
import std.math;
import std.time;
double PI = 3.141592653589793;
double SOLAR_MASS = 4 * PI * PI;
double DAYS_PER_YEAR = 365.24;
class Body {
double x, y, z, vx, vy, vz, mass;
#pragma once
#include <assert.h>
#include "Output.h"
namespace NULLCTime
{
void clockMicroInit();
unsigned clockMicro();
void TestEncoding()
{
TestRptrXmmEncoding(x86MOVSS);
TestXmmXmmEncoding(x86MOVSD);
TestRptrXmmEncoding(x86MOVSD);
TestXmmRptrEncoding(x86MOVSD);
TestRegXmmEncoding(x86MOVD);
; ------------------- Invalidation ----------------
0xc000156f: ; 5487
; 5487: less r9, r8, r6
mov eax, dword [rbx+64]
cmp eax, dword [rbx+48]
; 5488: jmpz r9, 5541 // kill late[r9]
jge '0xc00015a5'
// auto bi = this.bodies[i];
; 5489: loadq r9, [r4 + 0]
mov rax, qword [rbx+32]
0xc000156f:
mov eax, dword [rbx+64]
cmp eax, dword [rbx+48]
jge '0xc00015a5'
mov rax, qword [rbx+32]
mov rax, qword [rax]
mov rdx, qword [rbx+32]
mov edx, dword [rdx+8]
mov edi, dword [rbx+56]
cmp edi, edx