aboutsummaryrefslogtreecommitdiff
path: root/notes/stdlib_in_slul.txt
diff options
context:
space:
mode:
authorSamuel Lidén Borell <samuel@kodafritt.se>2025-06-08 21:57:24 +0200
committerSamuel Lidén Borell <samuel@kodafritt.se>2025-06-08 21:57:24 +0200
commitc6f75f73fa52eba4cf945f9a6454fc26af1e69bc (patch)
tree51030ed2eb7258b28be8b0dc9aa90830a0960a6b /notes/stdlib_in_slul.txt
parentc7356ef88bde007abe6b0a3deac9a0e6b30f894c (diff)
downloadslul-try2-main.tar.gz
slul-try2-main.tar.bz2
slul-try2-main.zip
Notes: arenas, backend, linear types, interface in .so/.dll, stdlib implHEADmain
Diffstat (limited to 'notes/stdlib_in_slul.txt')
-rw-r--r--notes/stdlib_in_slul.txt129
1 files changed, 129 insertions, 0 deletions
diff --git a/notes/stdlib_in_slul.txt b/notes/stdlib_in_slul.txt
index 0479024..99c7953 100644
--- a/notes/stdlib_in_slul.txt
+++ b/notes/stdlib_in_slul.txt
@@ -32,6 +32,27 @@ Write those things in:
e.g. Hare uses QBE, which has somewhat limited target support)
* Formally-verified IR/assembler (see below)
+Discourage people from writing in the unsafe language
+-----------------------------------------------------
+
+It would be sad if the safe SLUL language loses out to an unsafe cousin
+language. So IF an unsafe cousin language is ever created, it should
+1) be very clear that it is NOT slul, and 2) discourage it's use by making
+it an "unappealing" language.
+
+Make it explicitly a different language:
+* Different name (uhoh? oops? noo? slunsafe?)
+* Different file extension (.rtlc? .stdlib? .lul? .uhoh? .rtlu? .noo? .rsy? .slunsafe?)
+* Different syntax
+
+Make it ugly but still readable:
+* Use uppercase keywords?
+* Or use some sigill?
+
+Make unsafe stuff really stand out:
+* Maybe require an UNSAFE_xxx keyword around anything unsafe
+
+
Hard-core solution: formally verified IR/assembler
--------------------------------------------------
@@ -55,3 +76,111 @@ For registers, and for fields in structs in memory:
* not null
* length of field F
* etc.
+
+Hard-code solution 2: write a C compiler in SLUL
+------------------------------------------------
+
+Could write a C compiler in SLUL, using the same backend as the SLUL
+compiler will use.
+
+This could even be a subset of C89 (+ some things like uint64_t etc.).
+Candidates for things to remove/forbid:
+* digraphs/trigraphs
+* float/double
+* varargs (both usage, declarations and va_list etc.)
+* multi-char chars
+* octal literals and escape sequences
+* assuming char is either signed or unsigned, i.e. assigning < 0 or >= 128
+* strange control structures:
+ - case not directly under switch
+ - statements between switch and first case
+ - not using {} when block comes on a separate line
+* some types:
+ - void *
+ - wchat_t
+* several casts:
+ - pointer to/from int
+ - function ptr to/from other data pointer types
+* depending on operator precedence of:
+ - & vs && levels
+* declarations:
+ - * vs [] precedence
+ - prototypes: `f()`
+ - auto/register storage classes
+ - common initialization: `static int i;` or `int i;` at top-level.
+ - volatile
+ - new struct/enum inside function parameter list
+* unwanted macros:
+ - __DATE__, __TIME__
+ - #pragma
+* stdlib except for:
+ - memset, memcmp, memcpy, strlen
+
+
+Syntax test
+-----------
+
+Using UNSAFE_ everywhere to make unsafe stuff stand out and to make the
+language more ugly.
+
+Using __ in identifiers to avoid collisions and also for increased ugliness.
+
+Using % before all keywords for even more ugliness.
+
+
+ %func __init_arena
+ %code
+ [UNSAFEPointer base_ptr, UNSAFESize pgsize] = __sys_mmap 1
+ ArenaBase base_info %UNSAFE_OVERLAY base_ptr
+ .chunk = [
+ # ability to merge base pointers and offsets?
+ #.info = %UNSAFE_ADDROF .base %UNSAFE_PTRADD %UNSAFE_OFFSETOF .freespace
+ .baseptr = %UNSAFE_ADDROF .base
+ .alloced = %UNSAFE_OFFSETOF .freespace
+ .size = pgsize
+ ]
+ .base = [
+ # capability info, list of chunks, ...
+ ]
+ .freespace = []
+ %end
+ %end
+
+ %UNSAFE_GLOBAL __pagesize
+
+ %func __sys_mmap
+ int npages
+ %code
+ %%SYS_if os linux
+ __syscall6 NR_mmap2 ...
+ %%SYS_elif os windows
+ __sys_VirtualAlloc ...
+ %%SYS_endif
+ %end
+
+ %%SYS_switch os
+ %%SYS_case linux
+ %func __syscall6
+ int syscall_number
+ unsigned long arg1
+ ...
+ unsigned long arg6
+ %code
+ %SYS_switch cpu
+ %SYS_case aarch64
+ %UNSAFE_asmdef $sysc($n) $w32_le(...)
+ ...
+ %SYS_case i386
+ %UNSAFE_asmdef $int($n) CD $n
+ # Should probably use the vdso instead...
+ %UNSAFE_machinecode $int(80)
+ %SYS_case x86_64
+ ...
+ %SYS_endswitch
+ %end
+ %%SYS_case windows
+ %func __sys_VirtualAlloc
+ ...
+ %dllimport "kernel32.dll" "VirtualAlloc"
+ %end
+ %%SYS_endswitch