From 35cd5929f388700c13dc90c3eecaecb4daf01751 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Mon, 16 Jun 2025 16:02:48 +0100 Subject: [PATCH] Add Damn Simple Code --- Damn-Simple-Code.md | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Damn-Simple-Code.md diff --git a/Damn-Simple-Code.md b/Damn-Simple-Code.md new file mode 100644 index 0000000..67cc98e --- /dev/null +++ b/Damn-Simple-Code.md @@ -0,0 +1,69 @@ + +# DSC: Damn Simple Code + +- This is a concept doc for the DSC programming language +- None of this is final and may change at any time, this is just a concept to figure out how a simple programming language could be implemented at a level that is just above assembly + +## Type System + +- as this is a very basic langauge, all variables will be of type int for now. +- statics have a constant size decided at compile time and are stored in a static memory region at the start of the compiled +binary +- constants will be stored in the same way as statics, however consts are immutable. + +## Variables + +- variables will use the general purpose registers within the CPU to store data. +- this means up to 8 variables can be declared in a given method with the current architecture. +- it may be worth changing this to 16 later on. + +## Syntax + +```dsc +// Function calls + +Proc main(param1, param2, param3): // does something random + + // you can invoke assembly methods. + // this is useful for operations where writing code at the lowest level is preferable + // !!! Warning !!! - this is equivalent to embedding assembly within the current function + // this may mess with registers so ensure you know what the ASM is doing. + Call @init; + + var0 = param1 + param2; + push(var0); + var1 = pop(); + + If (var0 == var1): + Return; + + Else: + var3 = var2 | var3; + Return; + + EndIf +EndProc + +// declare a constant. this can be an int, string, bool etc and is immutable. +// the type is inferred from the value + +Const message = "Hello World!" + +// statics are declared similarly however they are mutable + +Static err_flag = False; + +// Assembly blocks can be used when it's inconvenient to write higher level code + +Asm: + // set up the stack + @stack 0x10000 + @init + LDA @stack + MOV MDR, BPR + MOV MDR, SPR + RET +EndAsm + + +``` \ No newline at end of file