Skip to content

Commit

Permalink
rename docs, add notes, add internals page
Browse files Browse the repository at this point in the history
  • Loading branch information
JaDogg committed Dec 21, 2023
1 parent 764b24b commit a9af8f7
Show file tree
Hide file tree
Showing 6 changed files with 347 additions and 49 deletions.
Binary file added public/imgs/yaka-mascot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 39 additions & 3 deletions src/components/Note.astro
Original file line number Diff line number Diff line change
@@ -1,4 +1,40 @@
<div class="flex bg-info text-info-content rounded-lg p-2 w-fit my-2">
<svg xmlns="http://www.w3.org/2000/svg" class="my-auto mx-2 stroke-current shrink-0 h-6 w-6" fill="none" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
---
interface Props {
mode: "mascot" | "icon";
}
const { mode } = Astro.props;
---

<div
class="flex bg-info text-info-content rounded-lg p-2 w-fit my-2 prose-a:invert prose-a:mx-1 prose-code:mx-1 prose-code:bg-base-100 prose-code:text-base-content prose-ul:list-none"
>
{
mode == "icon" && (
<svg
xmlns="http://www.w3.org/2000/svg"
class="my-auto mx-2 stroke-current shrink-0 h-6 w-6"
fill="none"
viewBox="0 0 24 24"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
)
}

{
mode == "mascot" && (
<img
alt="Yaksha Programming Language Mascot"
src="/imgs/yaka-mascot.png"
class="${iconStshrink-0 h-24 w-24"
/>
)
}
<slot />
</div>
</div>
85 changes: 48 additions & 37 deletions src/pages/docs/features.mdx → src/pages/docs/0001-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ layout: '../../layouts/DocsLayout.astro'
---

import Status from '../../components/Status.astro';
import Note from '../../components/Note.astro';

# Language Features

Expand Down Expand Up @@ -61,11 +62,11 @@ String literals are automatically converted to `sr` or `str`.
* Use `libs.strings.array.del_str_array()` to delete a string array.
* Supports `+` operator to join two `str` values.

; Data Type - `str`

; Internally this is a binary string.

; `sds` library (part of runtime lib) takes care of the heavy lifting.
<Note mode="mascot">
* Data Type - `str`
* Internally this is a binary string.
* `sds` library (part of runtime lib) takes care of the heavy lifting.
</Note>

```yaksha
a: str = "hello world"
Expand All @@ -79,9 +80,11 @@ println(a)
### Standard integers
</Status>

*Default integer is a 32bit signed integer.
*This is compiled to `int32_t` on all platforms.
;Data Type - `int` or `i32`
* Default integer is a 32bit signed integer.
* This is compiled to `int32_t` on all platforms.

<Note mode="icon">Data Type - `int` or `i32`</Note>

```yaksha
a: int = 4 # datatype ✅ | literal ✅
print("Four =")
Expand Down Expand Up @@ -121,7 +124,8 @@ j: u64 = 5u64 # datatype ✅ | literal ✅

* `f32` or `float` - single precision floats.
* `f64` - double precision floats.
;Data Type - `f32`, `float` and `f64`

<Note mode="icon">Data Type - `f32`, `float` and `f64`</Note>

```yaksha
a: f32 = 1.0f # datatype ✅ | literal ✅
Expand All @@ -141,7 +145,7 @@ c: float = 3.0f # datatype ✅ | literal ✅
* If you want to assign to a variable, it needs to be created.
* If no value is provided default value for data type is used.

; Default value for `str` is an empty string.
<Note mode="icon">Default value for `str` is an empty string.</Note>

```yaksha
def main() -> int:
Expand Down Expand Up @@ -187,7 +191,7 @@ 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.
<Note mode="icon">If `ccode` is there instead of an argument, then it is used as the message body.</Note>

<details>
<summary>Click to see output C code</summary>
Expand Down Expand Up @@ -261,14 +265,14 @@ def new(count: int, s: str) -> Array[str]:

---

<Status status="done">
<Status status="not-started">
### Template functions
</Status>

* Return type can also be a template-arg if that template-arg is used in parameters.
* String passed inside `@template(` should be single upper case characters separated by commas.

;This means it is limited to 26 template arguments max.
<Note mode="icon">This means it is limited to 26 template arguments max.</Note>

```yaksha
@native("yk__arrput")
Expand Down Expand Up @@ -312,8 +316,11 @@ def calculate(n: int) -> int:
* This behaviour is different from what you see in go-lang.
* Before end of `if` body or end of `else` body.

;`defer` works as a stack. \
;That means deferred expressions are executed in last deferred first executed order.
<Note mode="mascot">
* `defer` works as a stack.
* That means deferred expressions are executed in last deferred first executed order.
* Please note that this is not compatible with how `go` programming language `defer` works.
</Note>

```yaksha
def onexit() -> int:
Expand Down Expand Up @@ -351,7 +358,7 @@ def main() -> int:
println(a[0])
return 0
```
; Compiles to `free` or other runtime functions.
<Note mode="icon">Compiles to `free` or other runtime functions.</Note>

---

Expand Down Expand Up @@ -423,9 +430,9 @@ def main() -> int:
class Something:
something_id: int
# Use @dotaccess for purely stack allocated structs
# Use @onstack for purely stack allocated structs
@nativedefine("Color")
@dotaccess
@onstack
class Color:
r: int
g: int
Expand Down Expand Up @@ -462,7 +469,7 @@ def main() -> int:
return 0
```

;Name mangling takes place for this.
<Note mode="icon">Name mangling takes place for this.</Note>

---

Expand Down Expand Up @@ -552,9 +559,10 @@ def main() -> int:
return 0
```
;Note that Yaksha allows omitting `return`, assuming last expression matches the return data type.

;This is why `add` function does not have a return statement.
<Note mode="mascot">
* Note that Yaksha allows omitting `return`, assuming last expression matches the return data type.
* This is why `add` function does not have a return statement.
</Note>

---

Expand Down Expand Up @@ -593,7 +601,7 @@ 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.
<Note mode="icon">Builtin functions may call different implementations based on input.</Note>

---

Expand All @@ -618,16 +626,16 @@ def main() -> int:
return 0
```

; Must ensure array elements are freed. `int` need not be deleted as they are primitive types.
<Note mode="icon">Must ensure array elements are freed. `int` need not be deleted as they are primitive types.</Note>

---

<Status status="in-progress">
### String Hash Map
</Status>

HashMap with str keys and given data type values.
Values need to be deleted when no longer needed.
* HashMap with str keys and given data type values.
* Values need to be deleted when no longer needed.

```yaksha
def main() -> int:
Expand All @@ -640,9 +648,10 @@ def main() -> int:
return r
```

; `Array[SMEntry[?]]` keys are deleted automatically when `del` is invoked.

; `len` will give the total number of elements of the String Hash Map.
<Note mode="mascot">
* `Array[SMEntry[?]]` keys are deleted automatically when `del` is invoked.
* `len` will give the total number of elements of the String Hash Map.
</Note>

---

Expand All @@ -652,9 +661,10 @@ def main() -> int:

Simple single key single value hashmaps.

;Data type `Array[MEntry[K,T]]`.

;key and value both need to be deleted.
<Note mode="mascot">
* Data type `Array[MEntry[K,T]]`.
* key and value both need to be deleted.
</Note>

---

Expand All @@ -663,21 +673,22 @@ Simple single key single value hashmaps.
</Status>

YakshaLisp macros are one of the most important features of Yaksha. You can think of it as an interpreted language that lives in Yaksha compiler. \
; Because that is what it is!
<Note mode="icon">Because that is what it is!</Note>

It has it's own built in functions, can use `import`, read/write files and even use `metamacro` directive to create quoted input functions(similar to `defun`, except input args are not evaluated and returns quoted output that is immediately evaluated). Has multiple data types (list, map, callable, string, expression). Support's q-expressions `{1 2 3}` (inspired by build-your-own-lisp's lisp dialect), and special forms. A simple mark and sweep garbage collector is used. Provides a mediocre REPL and ability to execute standalone lisp code using a command. Not only that, it also support reflection using builtin callables such as `this` and `parent` (which returns a mutable current or parent scope as a map).

; Yo dog!, I heard you like macros, so I added meta-macro support in your macro processor.

; So you can meta-program while you meta-program.
<Note mode="mascot">
* Yo dog!, I heard you like macros, so I added meta-macro support in your macro processor.
* So you can meta-program while you meta-program.
</Note>

---

### Philosophy?
YakshaLisp provide the ability to write token-list to token-list conversion macros. One can use `my_macro!{t t t}` style expansion to achieve this. So why YakshaLisp? because it needs to process a list of tokens.
Additionally, Yaksha and YakshaLisp are polar opposites of each other, therefore I think they can compliment each other nicely.

; Think Yin-Yang!
<Note mode="icon">Think Yin-Yang!</Note>

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ layout: '../../layouts/DocsLayout.astro'
---

import Status from '../../components/Status.astro';
import Note from '../../components/Note.astro';

# Yaksha Library

Expand All @@ -13,7 +14,7 @@ Core parts of runtime library functionality starts with `yk__` or `YK__`.

Yaksha programming language preserves anything that starts with `yk__` or `YK__` while prefixing any other name with `yy__`.

; This avoids collisions with C standard library functions or keywords.
<Note mode="icon">This avoids collisions with C standard library functions or keywords.</Note>

---

Expand Down Expand Up @@ -73,4 +74,4 @@ def main() -> int:
cl.run(dvc, my_program)
```

; Placeholder code, API is not designed yet.
<Note mode="icon">Placeholder code, API is not designed yet.</Note>
17 changes: 10 additions & 7 deletions src/pages/docs/grammar.mdx → src/pages/docs/0003-grammar.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ layout: '../../layouts/DocsLayout.astro'

import Warning from '../../components/Warning.astro';
import Status from '../../components/Status.astro';
import Note from '../../components/Note.astro';

<Warning>this section needs rewriting</Warning>
<Warning>This section needs rewriting</Warning>

This describes Yaksha language grammar.
Lot learned from `Crafting Interpreters` book and Python grammar page.
Expand Down Expand Up @@ -74,9 +75,11 @@ c_code_statement: "ccode" (string | triple_quote_string) st_end
block: ":" (newline ba_indent standard_statement+ ba_dedent | simple_statement)
```

;`defer` statement is special, it can take either a `del` statement or any expression.

;This allows you to defer a `del`.
<Note mode="mascot">
* `defer` statement is special, it can take either a `del` statement or any expression.
* This allows you to defer a `del`.
* Example - `defer del my_element`
</Note>

---

Expand All @@ -91,7 +94,7 @@ primitive_data_type: "int" | "i8" | "i16" | "i32" | "i64" |
"f32" | "f64"
```

;Data type describes, primitives, custom data types and non primitives.
<Note mode="icon">Data type describes, primitives, custom data types and non primitives.</Note>

---

Expand All @@ -116,7 +119,7 @@ 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).
<Note mode="icon">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).</Note>

---

Expand All @@ -135,5 +138,5 @@ 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.
<Note mode="icon">`ba_indent` and `ba_dedent` gets calculated before parsing in `block_analyzer` phase.</Note>

Loading

0 comments on commit a9af8f7

Please sign in to comment.