diff --git a/src/components/Note.astro b/src/components/Note.astro index d639795..6c2bc82 100644 --- a/src/components/Note.astro +++ b/src/components/Note.astro @@ -32,9 +32,9 @@ const { mode } = Astro.props; Yaksha Programming Language Mascot ) } - + diff --git a/src/pages/docs/0001-features.mdx b/src/pages/docs/0001-features.mdx index 44accbf..9031028 100644 --- a/src/pages/docs/0001-features.mdx +++ b/src/pages/docs/0001-features.mdx @@ -181,7 +181,9 @@ def get_arg(n: int) -> str: def get_global_arg(n: int) -> str: ccode "yk__sdsdup(global_args[yy__n])" ``` -If `ccode` is there instead of an argument, then it is used as the message body. + +* If `ccode` is there instead of an argument, then it is used as the message body. +
Click to see output C code @@ -572,7 +574,40 @@ def main() -> int: * ✅ `hmget(Array[MEntry[K,T]], K) -> T` - Get item from an `Array[MEntry[K,T]]` * ✅ `hmgeti(Array[MEntry[K,T]], K) -> int` - Get item index from an `Array[MEntry[K,T]]` (-1 if not found) * ✅ `cast("T", X) -> T` - Data type casting builtin -* ✅ `qsort(Array[T],Function[In[Const[AnyPtrToConst],Const[AnyPtrToConst]],Out[int]]) -> bool` - Sort an array, returns True if successful +* ✅ `qsort(Array[T], COMP) -> bool` - Sort an array, returns True if successful + +```yaksha + +# Comparision is a function of type: +# Function[In[Const[AnyPtrToConst],Const[AnyPtrToConst]],Out[int]]) +# +# Example: +def cmp_int(a: Const[AnyPtrToConst], b: Const[AnyPtrToConst]) -> int: + # Compare two given integers + val_a: int = unref(cast("Ptr[int]", a)) + val_b: int = unref(cast("Ptr[int]", b)) + return val_b - val_a + +def print_array(x: Array[int]) -> None: + print("len=") + println(len(x)) + pos = 0 + length: int = len(x) + while pos < length: + print(x[pos]) + print(" ") + pos = pos + 1 + println("") + +def main() -> int: + x1 = array("int", 1, 2, 3, 3, 2, 1, 5, 4) + println("before x1:") + print_array(x1) + qsort(x1, cmp_int) + println("after x1:") + print_array(x1) +``` + * ✅ `iif(bool, T, T) -> T` - Ternary functionality * ✅ `foreach(Array[T],Function[In[T,V],Out[bool]],V) -> bool` - For each element in array execute given function * ✅ `countif(Array[T],Function[In[T,V],Out[bool]],V) -> int` - For each element in array count if function returns true @@ -582,7 +617,9 @@ def main() -> int: * ✅ `make("T") -> Ptr[T]` - Allocate a single object. * ✅ `inlinec("T", "code") -> T` - Inline `C` code resulting in `T` data type. Example - `inlinec("int", "sizeof(char)")` -Builtin functions may call different implementations based on input. + +* Builtin functions may call different implementations based on input. + @@ -607,7 +644,9 @@ def main() -> int: return 0 ``` -Must ensure array elements are freed. `int` need not be deleted as they are primitive types. + +* Must ensure array elements are freed. `int` need not be deleted as they are primitive types. + diff --git a/src/pages/docs/0005-grammar.mdx b/src/pages/docs/0005-grammar.mdx index 80d0f15..7778aa9 100644 --- a/src/pages/docs/0005-grammar.mdx +++ b/src/pages/docs/0005-grammar.mdx @@ -119,7 +119,9 @@ primary: "True" | "False" | "None" | number | string | triple_quote_string | nam "(" expr ")" ``` -Based on [lox grammar](https://craftinginterpreters.com/appendix-i.html) and [Python operator precedence](https://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html). + +* Based on [lox grammar](https://craftinginterpreters.com/appendix-i.html) and [Python operator precedence](https://www.mathcs.emory.edu/~valerie/courses/fall10/155/resources/op_precedence.html). + @@ -138,5 +140,7 @@ eof: "end of file" ba_indent: "increase in indentation" ba_dedent: "decrease is indentation" ``` -`ba_indent` and `ba_dedent` gets calculated before parsing in `block_analyzer` phase. + +* `ba_indent` and `ba_dedent` gets calculated before parsing in `block_analyzer` phase. +