From 724261dda9167626102e715eb548b110c0bee328 Mon Sep 17 00:00:00 2001 From: zxq5 Date: Mon, 30 Jun 2025 20:39:17 +0100 Subject: [PATCH] added some concepts for custom lang --- src/dsc.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/src/dsc.md b/src/dsc.md index d295ab0..ade3343 100644 --- a/src/dsc.md +++ b/src/dsc.md @@ -14,3 +14,61 @@ - signed integer types (I8, I16, I32) - boolean type (Bool) - custom struct & dynamic types (Struct) + - pointer types (&Type) + - result, error and option types (Result, Err, Option) + +## Control Flow + +- we should support the following control flow + - if/else-if/else + - loop/break/continue + - for loops and while loops can be constructed with conditions in these loops + +```dsc +if condition { + // do something +} else if condition { + // do something else +} else { + // do something else +} + +``` + +## Functions + +- functions will be treated as types, rather than language features + +```dsc +add: Func = |x: U32, y: U32| -> U32 { + return x + y; +} +``` + +## Struct Definitions + +- we define the struct type as it's constructor. + +```dsc +// struct definition +Point: Struct = { + x: U32, + y: U32 +}; + +// constructor +Point.new = |x: U32, y: U32| -> Point { + return { + x: x, + y: y + }; +}; + +// method +Point.add = |p1: Point, p2: Point| -> Point { + return { + x: p1.x + p2.x, + y: p1.y + p2.y + }; +}; +```