Compare commits

...

12 Commits

Author SHA1 Message Date
Ed_
e2aba6db5f adjustments based on superluminal 2025-10-03 23:13:04 -04:00
Ed_
af38cda276 C-- lottes: drafting pass: removed all usages of star "*" dereference operator 2025-10-03 22:46:21 -04:00
Ed_
8df492399f Got lottes c-- version working 2025-10-03 22:09:11 -04:00
Ed_
2c0539e235 finish draft of lottes c-- veersion 2025-10-03 19:59:15 -04:00
Ed_
3223c0a0e1 Lottes C--: key tables... 2025-10-03 17:03:33 -04:00
Ed_
0bd68bccf0 lottes c--: arena impl 2025-10-03 16:18:03 -04:00
Ed_
5f03118a0d got to varenas (lottes c--)
Still not sure how hybrid I'm going to go (away from his more purist stance on typed info embedding).

If I were to codegen this and wanted typeless vs typed for debug it would be easier to malleablly switch between...
If I decide for this sample to go full asm (no C features almost we can still keep the type info for debug...
2025-10-03 15:56:42 -04:00
Ed_
288d661d65 started to work on c-- lottes impl 2025-10-03 03:19:50 -04:00
Ed_
40ee07e3cc finished header port for lottes c-- 2025-10-03 03:04:40 -04:00
Ed_
c5d19ae25b more crimes 2025-10-03 02:00:54 -04:00
Ed_
c8f0b34daf commiting more crimes with Lottes like 2025-10-03 01:46:28 -04:00
Ed_
fc032da21e Started to setup watl to mess around with lotte's C--
Not going to use GCC, too much of a pain in the ass on windows.
Going to do a slightly flavored dialect to make things a bit easier to translate...
2025-10-03 00:49:40 -04:00
7 changed files with 2550 additions and 17 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ C/watl.v0.msvc.c.listing.txt
watl_exercise.user watl_exercise.user
watl_exercise.proj watl_exercise.proj
Odin/watl.v0.win32.odin.listing.txt Odin/watl.v0.win32.odin.listing.txt
C/watl.v0.lottes.c.listing.txt

2
C++/watl.v0.msvc.cpp Normal file
View File

@@ -0,0 +1,2 @@
#pragma once

2328
C/watl.v0.lottes.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -383,7 +383,7 @@ cast(type*, varena__push(arena, 1, size_of(type), opt_args(Opts_varena, lit(stri
#define varena_push_array(arena, type, amount, ...) \ #define varena_push_array(arena, type, amount, ...) \
(tmpl(Slice,type)){ varena__push(arena, size_of(type), amount, opt_args(Opts_varena, lit(stringify(type)), __VA_ARGS__)).ptr, amount } (tmpl(Slice,type)){ varena__push(arena, size_of(type), amount, opt_args(Opts_varena, lit(stringify(type)), __VA_ARGS__)).ptr, amount }
#pragma endregion VArnea #pragma endregion VArena
#pragma region Arena (Casey-Ryan Composite Arenas) #pragma region Arena (Casey-Ryan Composite Arenas)
typedef Opts_varena Opts_arena; typedef Opts_varena Opts_arena;
@@ -1367,22 +1367,22 @@ void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
#pragma endregion Arena #pragma endregion Arena
#pragma region Key Table 1-Layer Linear (KT1L) #pragma region Key Table 1-Layer Linear (KT1L)
void kt1l__populate_slice_a2(KT1L_Byte* kt, AllocatorInfo backing, KT1L_Meta m, Slice_Byte values, SSIZE num_values ) { void kt1l__populate_slice_a2(KT1L_Byte*restrict kt, AllocatorInfo backing, KT1L_Meta m, Slice_Byte values, SSIZE num_values ) {
assert(kt != nullptr); assert(kt != nullptr);
if (num_values == 0) { return; } if (num_values == 0) { return; }
* kt = alloc_slice(backing, Byte, m.slot_size * num_values ); * kt = alloc_slice(backing, Byte, m.slot_size * num_values );
slice_assert(* kt); slice_assert(* kt);
for (span_iter(SSIZE, iter, 0, <, num_values)) { for (span_iter(SSIZE, iter, 0, <, num_values)) {
SSIZE slot_offset = iter.cursor * m.slot_size; // slot id SSIZE slot_offset = iter.cursor * m.slot_size; // slot id
Byte* slot_cursor = & kt->ptr[slot_offset]; // slots[id] type: KT1L_<Type> Byte*restrict slot_cursor = & kt->ptr[slot_offset]; // slots[id] type: KT1L_<Type>
U64* slot_key = (U64*)slot_cursor; // slots[id].key type: U64 U64*restrict slot_key = (U64*restrict)slot_cursor; // slots[id].key type: U64
Slice_Byte slot_value = { slot_cursor + m.kt_value_offset, m.type_width }; // slots[id].value type: <Type> Slice_Byte slot_value = { slot_cursor + m.kt_value_offset, m.type_width }; // slots[id].value type: <Type>
SSIZE a2_offset = iter.cursor * m.type_width * 2; // a2 entry id SSIZE a2_offset = iter.cursor * m.type_width * 2; // a2 entry id
Byte* a2_cursor = & values.ptr[a2_offset]; // a2_entries[id] type: A2_<Type> Byte*restrict a2_cursor = & values.ptr[a2_offset]; // a2_entries[id] type: A2_<Type>
Slice_Byte a2_key = * cast(Slice_Byte*, a2_cursor); // a2_entries[id].key type: <Type> Slice_Byte a2_key = * cast(Slice_Byte*restrict, a2_cursor); // a2_entries[id].key type: <Type>
Slice_Byte a2_value = { a2_cursor + m.type_width, m.type_width }; // a2_entries[id].value type: <Type> Slice_Byte a2_value = { a2_cursor + m.type_width, m.type_width }; // a2_entries[id].value type: <Type>
slice_copy(slot_value, a2_value); // slots[id].value = a2_entries[id].value slice_copy(slot_value, a2_value); // slots[id].value = a2_entries[id].value
* slot_key = 0; hash64_djb8(slot_key, a2_key); // slots[id].key = hash64_djb8(a2_entries[id].key) * slot_key = 0; hash64_djb8(slot_key, a2_key); // slots[id].key = hash64_djb8(a2_entries[id].key)
} }
kt->len = num_values; kt->len = num_values;
} }
@@ -1790,14 +1790,14 @@ void str8gen_append_str8(Str8Gen* gen, Str8 str){
} }
void str8gen__append_fmt(Str8Gen* gen, Str8 fmt_template, Slice_A2_Str8* entries){ void str8gen__append_fmt(Str8Gen* gen, Str8 fmt_template, Slice_A2_Str8* entries){
local_persist Byte tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem)); local_persist Byte tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
KT1L_Str8 kt = {0}; kt1l_populate_slice_a2(Str8, & kt, ainfo_farena(tbl_arena), *entries ); KT1L_Str8 kt = {0}; kt1l_populate_slice_a2(Str8, & kt, ainfo_farena(tbl_arena), *entries );
Slice_Byte buffer = { gen->ptr + gen->len, gen->cap - gen->len }; Slice_Byte buffer = { gen->ptr + gen->len, gen->cap - gen->len };
if (buffer.len < kilo(16)) { if (buffer.len < kilo(16)) {
Slice_Byte result = mem_grow(gen->backing, str8gen_slice_byte(* gen), kilo(16) + gen->cap ); Slice_Byte result = mem_grow(gen->backing, str8gen_slice_byte(* gen), kilo(16) + gen->cap );
slice_assert(result); slice_assert(result);
gen->ptr = result.ptr; gen->ptr = result.ptr;
gen->cap += kilo(16); gen->cap += kilo(16);
buffer = (Slice_Byte){ cast(Byte*, gen->ptr + gen->len), gen->cap - gen->len }; buffer = (Slice_Byte){ cast(Byte*, gen->ptr + gen->len), gen->cap - gen->len };
} }
Str8 result = str8__fmt_kt1l(gen->backing, & buffer, kt, fmt_template); Str8 result = str8__fmt_kt1l(gen->backing, & buffer, kt, fmt_template);
gen->len += result.len; gen->len += result.len;

View File

@@ -42,8 +42,8 @@ $flag_link_win_machine_64 = '/MACHINE:X64'
$flag_link_win_path_output = '/OUT:' $flag_link_win_path_output = '/OUT:'
$flag_link_win_rt_dll = '/MD' $flag_link_win_rt_dll = '/MD'
$flag_link_win_rt_dll_debug = '/MDd' $flag_link_win_rt_dll_debug = '/MDd'
$flag_link_win_rt_static = '/MT' $flag_link_win_rt_static = '/MT:STATIC'
$flag_link_win_rt_static_debug = '/MTd' $flag_link_win_rt_static_debug = '/MTd:STATIC'
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE' $flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS' $flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
$flag_no_optimization = '/Od' $flag_no_optimization = '/Od'
@@ -115,6 +115,7 @@ $compiler_args += $flag_full_src_path
# $compiler_args += $flag_asm_listing_file # $compiler_args += $flag_asm_listing_file
# $compiler_args += $flag_optimize_speed_max # $compiler_args += $flag_optimize_speed_max
# $compiler_args += $flag_optimize_fast
# $compiler_args += $flag_optimize_size # $compiler_args += $flag_optimize_size
# $compiler_args += $flag_optimize_intrinsics # $compiler_args += $flag_optimize_intrinsics
$compiler_args += $flag_no_optimization $compiler_args += $flag_no_optimization

200
scripts/build.c_lottes.ps1 Normal file
View File

@@ -0,0 +1,200 @@
$misc = Join-Path $PSScriptRoot 'helpers/misc.psm1'
import-module $misc
# This script now uses the LLVM toolchain (clang-cl, lld-link).
# Ensure these tools are available in your PATH.
# The original call to the MSVC devshell has been removed.
# & (join-path $PSScriptRoot 'helpers/devshell.ps1') -arch amd64
$path_root = Get-ScriptRepoRoot
$path_root = split-path -Path $PSScriptRoot -Parent
$path_toolchain = join-path $path_root 'toolchain'
$path_rad = join-path $path_toolchain 'rad'
# https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category?view=msvc-170
# Most cl.exe flags are compatible with clang-cl.exe
$flag_all_c = '/TC'
$flag_c11 = '/std:c11'
$flag_c23 = '/std:c23'
$flag_all_cpp = '/TP'
$flag_compile = '/c'
$flag_charset_utf8 = '/utf-8'
$flag_debug = '/Zi'
$flag_define = '/D'
$flag_exceptions_disabled = '/EHsc-'
$flag_RTTI_disabled = '/GR-'
$flag_include = '/I'
$flag_full_src_path = '/FC'
$flag_asm_listing_file = '/FAs'
$flag_nologo = '/nologo'
$flag_dll = '/LD'
$flag_dll_debug = '/LDd'
$flag_linker = '/link'
# $flag_link_lib = '/lib'
$flag_link_dll = '/DLL'
$flag_link_no_incremental = '/INCREMENTAL:NO'
$flag_link_mapfile = '/MAP:'
$flag_link_optimize_references = '/OPT:REF'
$flag_link_win_debug = '/DEBUG'
$flag_link_win_pdb = '/PDB:'
$flag_link_win_machine_32 = '/MACHINE:X86'
$flag_link_win_machine_64 = '/MACHINE:X64'
$flag_link_win_path_output = '/OUT:'
$flag_link_win_rt_dll = '/MD'
$flag_link_win_rt_dll_debug = '/MDd'
$flag_link_win_rt_static = '/MT'
$flag_link_win_rt_static_debug = '/MTd'
$flag_link_win_subsystem_console = '/SUBSYSTEM:CONSOLE'
$flag_link_win_subsystem_windows = '/SUBSYSTEM:WINDOWS'
$flag_no_optimization = '/Od'
$flag_optimize_speed_max = '/Ox'
$flag_optimize_fast = '/O2'
$flag_optimize_size = '/O1'
$flag_optimize_intrinsics = '/Oi'
$flag_optimized_debug_forceinline = '/d2Obforceinline'
$flag_optimized_debug = '/Zo'
$flag_preprocess_to_file = '/P'
$flag_preprocess_preserve_comments = '/C'
# $flag_out_name = '/OUT:'
$flag_path_interm = '/Fo'
$flag_path_debug = '/Fd'
$flag_path_output = '/Fe'
$flag_preprocess_conform = '/Zc:preprocessor'
$flag_sanitize_address = '/fsanitize=address'
$flag_updated_cpp_macro = "/Zc:__cplusplus"
$flag_set_stack_size = '/F'
$flag_syntax_only = '/Zs'
$flag_wall = '/Wall'
$flag_warnings_as_errors = '/WX'
$flag_lib_list = '/LIST'
$archiver = 'llvm-lib'
$compiler = 'clang-cl'
$linker = 'lld-link'
$radbin = join-path $path_rad 'radbin.exe'
$radlink = join-path $path_rad 'radlink.exe'
$path_build = join-path $path_root 'build'
if ( -not(test-path -Path $path_build) ) {
new-item -ItemType Directory -Path $path_build
}
push-location $path_build
write-host "Compiling with clang-cl"
$compiler_args = @()
$compiler_args += $flag_nologo
# Constraints on interpeting all files as C code
$compiler_args += $flag_all_c
$compiler_args += $flag_c11
# Constraints on C program code-gen
$compiler_args += $flag_exceptions_disabled
$compiler_args += $flag_RTTI_disabled
# $compiler_args += $flag_preprocess_conform
# $compiler_args += $flag_sanitize_address
$compiler_args += $flag_wall
# Set charset encoding for both execution and source to UTF-8
$compiler_args += $flag_charset_utf8
# Specifing output pathing
$compiler_args += ( $flag_path_interm + $path_build + '\' )
# $compiler_args += ( $flag_path_output + $path_build + '\' )
# Dump preprocess file
if ($false) {
$compiler_args += $flag_preprocess_to_file
$compiler_args += $flag_preprocess_preserve_comments
}
# Diagnostic logging
$compiler_args += $flag_full_src_path
# $compiler_args += $flag_asm_listing_file
# $compiler_args += $flag_optimize_speed_max
# $compiler_args += $flag_optimize_fast
# $compiler_args += $flag_optimize_size
# $compiler_args += $flag_optimize_intrinsics
$compiler_args += $flag_no_optimization
# Debug setup
$compiler_args += ($flag_define + 'BUILD_DEBUG')
$compiler_args += $flag_debug
$compiler_args += ( $flag_path_debug + $path_build + '\' )
# Use the static, multithreaded, debug runtime library
$compiler_args += $flag_link_win_rt_static_debug
# Include setup
$compiler_args += ($flag_include + $path_root)
$unit_name = "watl.v0.lottes"
# Specify unit to compile
$unit = join-path $path_root "C\$unit_name.c"
$compiler_args += $flag_compile, $unit
# Diagnoistc print for the args
$compiler_args | ForEach-Object { Write-Host $_ }
# Compile the unit
$compilation_time = Measure-Command {
& $compiler $compiler_args
}
write-host "Compilation took $($compilation_time.TotalMilliseconds)ms"
write-host
$binary = join-path $path_build "$unit_name.exe"
$object = join-path $path_build "$unit_name.obj"
$pdb = join-path $path_build "$unit_name.pdb"
$map = join-path $path_build "$unit_name.map"
$rdi = join-path $path_build "$unit_name.rdi"
$rdi_listing = join-path $path_build "$unit_name.rdi.list"
if ($true) {
write-host "Linking with lld-link"
$linker_args = @()
$linker_args += $flag_nologo
$linker_args += $flag_link_win_machine_64
$linker_args += $flag_link_no_incremental
$linker_args += ($flag_link_win_path_output + $binary)
$linker_args += "$flag_link_win_debug"
$linker_args += $flag_link_win_pdb + $pdb
$linker_args += $flag_link_mapfile + $map
$linker_args += $flag_link_win_subsystem_console
$linker_args += $object
# Add necessary libraries for a basic Windows application
$linker_args += "kernel32.lib", "user32.lib", "gdi32.lib"
# Diagnoistc print for the args
$linker_args | ForEach-Object { Write-Host $_ }
$linking_time = Measure-Command { & $linker $linker_args }
# & $radlink $linker_args
write-host "Linking took $($linking_time.TotalMilliseconds)ms"
write-host
}
if ($false) {
write-host "Dumping Debug Info"
$rbin_out = '--out:'
$rbin_dump = '--dump'
$nargs = @($pdb, ($rbin_out + $rdi))
& $radbin $nargs
$nargs = @($rbin_dump, $rdi)
$dump = & $radbin $nargs
$dump > $rdi_listing
}
Pop-Location

View File

@@ -106,7 +106,8 @@ main :: proc() {
file_source, file_source,
flag_file, flag_file,
join_str(flag_output_path, file_exe), join_str(flag_output_path, file_exe),
flag_optimize_none, // flag_optimize_none,
falg_optimize_aggressive,
flag_default_allocator_nil, flag_default_allocator_nil,
flag_debug, flag_debug,
flag_microarch_zen5, flag_microarch_zen5,