ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

NOTES.md (3795B)


      1 
      2 [https://github.com/gingerBill/titania]
      3 [https://news.ycombinator.com/item?id=45243925]
      4 [https://people.inf.ethz.ch/wirth/Oberon/Oberon07.Report.pdf]
      5 [https://people.inf.ethz.ch/wirth/ProjectOberon/PO.System.pdf]
      6 
      7 add_operator = "+" | "-" | "xor" | "or".
      8 mul_operator = "*" | "/" | "%"   | "and".
      9 
     10 see
     11     Tokenizer Semicolon Insertion Rules
     12 
     13     When a newline is seen after the following token kind, a semicolon is inserted, otherwise no semicolon is inserted:
     14 
     15     ...list
     16 
     17 
     18 Gleam my new obsession
     19 I love Rust, but...
     20 [https://ericcodes.io/blog/gleam-my-new-obsession.html]
     21 
     22 (`antirez/sds` for dynamic strings, `nothings/stb_ds` for dynamic arrays and hashmaps, and `cxong/tinydir` for reading the filesystem).
     23 [https://old.reddit.com/r/Compilers/comments/1nmc3r9/i_wrote_a_compiler_for_a_large_subset_of_c_in_c/]
     24 
     25 How to make stuff private and discussion on design (just mangle the names if needed)
     26 [http://journal.stuffwithstuff.com/2025/05/26/access-control-syntax]
     27 
     28 
     29 # symbols
     30 
     31 - jack      int             1
     32 - test      void->void      1
     33     alice   float           2
     34 - main      void->void      1
     35     peter   strings         2
     36 - jill      int             1
     37 
     38 # Zed
     39 
     40 [https://zed.dev/docs/extensions/developing-extensions]
     41 
     42 # libgccjit doco
     43 
     44 [https://gcc.gnu.org/onlinedocs/gcc-15.1.0/jit/]
     45 
     46 # license
     47 
     48   the hare license at the bottom
     49   https://sr.ht/~sircmpwn/hare/
     50   the standard library is under MPL, the compiler and executables are under GPL3
     51 
     52 # walk down, compute bubbling up
     53 
     54 RDP (Root‑Descend‑Process)
     55 
     56 - Push "stacks" as you descend, nodes and local state
     57 - Process and pop the frame off on the way back up and merge or "combine" result with its parent.
     58 
     59 Expr ::= Add(Expr, Expr)
     60        | Mul(Expr, Expr)
     61        | Num(Int)
     62 
     63 R‑D‑P Application
     64 
     65 1. Root: Add( Mul(Num(2), Num(3)), Num(4) )
     66 2. Descend:
     67   - Push Add frame.
     68   - Push left child Mul.
     69   - Push left child Num(2) → leaf → Process → result = 2.
     70   - Push right child Num(3) → leaf → Process → result = 3.
     71   - Process Mul → result = 6.
     72   - Push right child Num(4) → leaf → Process → result = 4.
     73 3. Process Add → result = 10.
     74 
     75 ** Forget the whole tree, focus on this node and reason locally. **
     76 
     77 R‑D‑P (Root‑Descend‑Process) turns recursive AST evaluation into a clear, iterative algorithm.
     78 Pair it with bottom‑up traversal, the visitor pattern, or an explicit stack to keep state explicit.
     79 This approach reduces cognitive load by isolating each node’s processing and avoiding hidden call‑stack dependencies.
     80 
     81 Keep a whiteboard model of the tree shapes.
     82 
     83 - Base case – literals and identifiers return a value immediately.
     84 - Recursive step – always evaluate child nodes before applying the operator at the current node.
     85 - After return – combine child results according to the operation; this is where side‑effects (e.g., assignment) may occur.
     86 
     87 see [[TODO]]
     88 
     89 ## Only pure constant expressions are evaluated at compile time
     90 
     91 print has side effects so it doesn't
     92 
     93 2 + 3 is not run by the compiler, but it may be constant-folded in the optimizer.
     94 
     95 you lower print to a runtime call printf
     96 
     97 ### CTFE compile time function execution
     98 
     99 - constant expression, constant folding and propagation
    100 - evaluator / constant interpreter
    101 - restricted evaluator in the compiler, with env and CT heap
    102 - try_ctfe on expression nodes
    103 - lowering: emit literal value to IR once folded
    104 - C++: consteval, Zig: comptime, Rust: constfn
    105 - gate with fuel(?), depth restriction and memory limits
    106 
    107 
    108 add_to_scope is used during semc
    109 add_symbol is used during genc, feels wrong
    110 
    111 
    112 when we semc we need to build the scope and symbols list for each
    113 but then in gen we need to fetch the symbols and pad them with pointers
    114 
    115 separate the gccjit impl to a separate tree than the symbols table of semantic analysis