174 lines
6.4 KiB
Org Mode
174 lines
6.4 KiB
Org Mode
#+TITLE: Undâr Programming Language
|
|
#+AUTHOR: Zongor
|
|
#+EMAIL: archive@undar-lang.org
|
|
#+DATE: [2025-04-05]
|
|
#+LANGUAGE: en
|
|
#+OPTIONS: H:4 num:t toc:t \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t
|
|
#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate
|
|
#+TAGS: { TODO(t) NEXT(n) DONE(d) | HOLD(h) WAITING(w) CANCELLED(c) }
|
|
#+PROPERTY: header-args :tangle-mode (identity #o0644)
|
|
|
|
#+BEGIN_SRC
|
|
[ᚢ ᛫ ᛫ ᛫
|
|
᛫ ᚾ ᛫ ᛫
|
|
᛫ ᛫ ᛞ ᛫
|
|
᛫ ᛫ ᛫ ᚱ]
|
|
#+END_SRC
|
|
|
|
* Undâr
|
|
|
|
Undâr is a programming language for the purpose of creating 3D games and graphical user traits that work on constrained systems, microcontrollers, retro consoles, and the web using emscripten. The language emphasizes hardware longevity, energy efficiency, and the preservation of digital art and games for future generations.
|
|
|
|
It has an internal REPL that allows for quick development as well as the ability to dump the program to a binary rom for preserving that program/game/etc.
|
|
|
|
It runs on the =Reality Engine=, a VM written in freestanding C89, has a CISC like instruction format of one byte opcode and a variable byte operand. 32 local variables per frame.
|
|
|
|
* Philosophy
|
|
|
|
Undâr conforms to permacomputing principles.
|
|
|
|
"permacomputing encourages the maximization of hardware lifespan, minimization of energy usage and focuses on the use of already available computational resources.
|
|
it values maintenance and refactoring of systems to keep them efficient, instead of planned obsolescence, permacomputing practices planned longevity.
|
|
it is about using computation only when it has a strengthening effect on ecosystems." [[https://wiki.xxiivv.com/site/permacomputing.html][source]]
|
|
|
|
Undâr is designed to ensure that programs created today will remain executable for a very long time, even through technological collapse.
|
|
|
|
This is achieved through:
|
|
- A standardized bytecode format that maps 1:1 to human-readable assembly
|
|
- A VM specification that can be implemented easily
|
|
- Hardware abstractions for the VM implementation
|
|
- ROM files that contain all necessary information for execution
|
|
- A friendly syntax which focuses on maintaining code without obscuring functionality.
|
|
|
|
* Getting Started
|
|
|
|
**Build the Reality Engine**
|
|
|
|
#+BEGIN_SRC sh
|
|
git clone https://git.alfrescocavern.com/zongor/undar-lang.git
|
|
cd undar-lang && make
|
|
#+END_SRC
|
|
=Sċieppan= is a intermediate representation.
|
|
You can view some examples in the =.ul.ir= files in =/test=
|
|
|
|
**Sample Program: =hello.ul.ir=**
|
|
|
|
#+BEGIN_SRC sh
|
|
function main ()
|
|
str hello is $0
|
|
|
|
malloc_immediate "nuqneH 'u'?" -> hello
|
|
call pln hello
|
|
exit 0
|
|
|
|
function pln (str message is $0)
|
|
str ts is $1
|
|
int msg_length is $2
|
|
str nl is $3
|
|
int nl_length is $4
|
|
int mode is $5
|
|
|
|
malloc_immediate "/dev/term/0" -> ts # get terminal device
|
|
load_immediate 0 -> mode
|
|
syscall OPEN ts mode -> ts
|
|
strlen message -> msg_length
|
|
syscall WRITE ts message msg_length
|
|
malloc_immediate "\n" -> nl
|
|
strlen nl -> nl_length
|
|
syscall WRITE ts nl nl_length
|
|
return
|
|
#+END_SRC
|
|
|
|
#+BEGIN_SRC sh
|
|
./build/linux/undar-linux-debug ./test/hello.asm.lisp
|
|
#+END_SRC
|
|
|
|
Running the compiler without arguments will put it in "REPL" mode. It will function similar to a LISP repl.
|
|
|
|
* Memory Management
|
|
|
|
memory is managed via frame based arenas. function scopes defines a memory frame.
|
|
|
|
heap allocations using the internal malloc opcode push pointers within this frame. when a frame exits, the pointer is reset like stack based gc.
|
|
|
|
#+BEGIN_SRC sh
|
|
function main ()
|
|
int mode is $11
|
|
str term is $10
|
|
|
|
malloc_immediate "/dev/term/0" -> term
|
|
load_immediate 0 -> mode
|
|
syscall OPEN term mode -> term # Terminal term = open("/dev/term/0", 0);
|
|
|
|
malloc_immediate "Enter a string:" -> $7
|
|
string_length $7 -> $8
|
|
syscall WRITE term $7 $8 # print prompt
|
|
|
|
str user_string is $9
|
|
load_immediate 32 -> $8
|
|
malloc $8 -> user_string
|
|
syscall READ term user_string $8 # read in max 32 byte string
|
|
|
|
call pln user_string
|
|
exit 0
|
|
|
|
function pln (str message is $0)
|
|
str ts is $1
|
|
int mode is $5
|
|
int msg_length is $2
|
|
str nl is $3
|
|
int nl_length is $4
|
|
|
|
malloc_immediate "/dev/term/0" -> ts
|
|
load_immediate 0 -> mode
|
|
syscall OPEN ts mode -> ts # get terminal device
|
|
strlen message -> msg_length
|
|
syscall WRITE ts message msg_length
|
|
malloc_immediate "\n" -> nl
|
|
strlen nl -> nl_length
|
|
syscall WRITE ts nl nl_length
|
|
|
|
#+END_SRC
|
|
|
|
values passed to functions must be explicitly returned to propagate. heap values are copy on write, so if a value is modified in a child function it will change the parents value, unless the size of the structure changes then it will copy the parents value and append it to its own frame with the modification. this allows for the low resource usage of a C but the convenience of a Java/Go without the garbage collection.
|
|
|
|
**Core Types**
|
|
|
|
| Type | Description |
|
|
|------+------------------------------------|
|
|
| =int= | 32-bit signed integer |
|
|
| =nat= | 32-bit natural number |
|
|
| =real= | Q16.16 fixed-point real number |
|
|
| =str= | fat pointer [length + data] string |
|
|
| =bool= | true/false |
|
|
| =byte= | Character/8 bit unsigned int |
|
|
|
|
A ref type allows pass by reference similar to a pointer in c. most types will be pass by value with some types being explicitly pass by reference.
|
|
|
|
primitive types like int, nat, real, etc. will always be safe to change in child frames.
|
|
|
|
* Roadmap
|
|
|
|
[[./ROADMAP.org][Compiler, Plex, Immidate mode GUI, Constructive solid geometry, Tunnels, Actor model]]
|
|
|
|
* License
|
|
|
|
MIT-0
|
|
|
|
* Inspirations
|
|
|
|
- [[https://wiki.xxiivv.com/site/uxn.html][Uxn]] - The ideal system for permacomputing
|
|
- [[https://plan9.io/][Plan 9]] / 9P - Unified I/O, Tunnels
|
|
- [[https://forth-standard.org/][Forth]] - Shadowing
|
|
- [[https://en.wikipedia.org/wiki/Lisp_(programming_language)][Lisp]] - Live coding, REPL, introspection
|
|
- [[https://fortran-lang.org/][Fortran]] - Array semantics, scientific clarity
|
|
- [[https://en.wikipedia.org/wiki/C_(programming_language)][C]] / [[https://ziglang.org/][Zig]] - Control, minimalism
|
|
- [[https://lua.org][Lua]] - Languages can be portable and expressive without being complicated.
|
|
- [[https://www.craftinginterpreters.com/the-lox-language.html][Lox]] - The start of my programming language creation journey
|
|
- [[https://www.permacomputing.net][Permacomputing wiki]] - Core ideology
|
|
- [[http://duskos.org/][Dusk OS]] - A much better system for doing permacomputing
|
|
- [[https://doc.cat-v.org/inferno/4th_edition/dis_VM_specification][Dis VM]] - CISC VM structure
|
|
- Retro Systems - N64, PS1, Mac Classic, Windows 95 - UI esthetics
|
|
|