omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / src / physics0 / pd0_world_main.om
| 1 | note SPDX-License-Identifier: Apache-2.0 |
| 2 | note src/physics0/pd0_world_main.om: pd0-world <level 0..6|null> <seed> |
| 3 | note Reads framed requests on stdin, writes framed responses on stdout, exits at EOF. |
| 4 | |
| 5 | text P0WM_USAGE "usage: pd0-world <level 0..6|null> <seed>\n" |
| 6 | text P0WM_BADLVL "pd0-world: bad level\n" |
| 7 | text P0WM_NULL "null" |
| 8 | |
| 9 | fn p0wm_parse_u64 buf view uchar * n ulong to ulong |
| 10 | v = ulong 0 |
| 11 | for i ulong n bound 32 |
| 12 | c = get buf i |
| 13 | if and ge c uchar 48 le c uchar 57 |
| 14 | v = add mul v ulong 10 ulong sub c uchar 48 |
| 15 | end |
| 16 | end |
| 17 | ret v |
| 18 | end |
| 19 | |
| 20 | fn main to int |
| 21 | ac = argcnt |
| 22 | if ne ac long 3 |
| 23 | pd0_puts 2 P0WM_USAGE |
| 24 | ret 2 |
| 25 | end |
| 26 | a1 = new uchar 32 0 |
| 27 | a2 = new uchar 32 0 |
| 28 | n1 = argread 1 a1 0 32 |
| 29 | n2 = argread 2 a2 0 32 |
| 30 | if or le n1 long 0 le n2 long 0 |
| 31 | pd0_puts 2 P0WM_USAGE |
| 32 | ret 2 |
| 33 | end |
| 34 | level = int -1 |
| 35 | if and eq n1 long 4 eq pd0_eq_bytes view a1 ulong 0 P0WM_NULL ulong 4 1 |
| 36 | level = PD0_LEVEL_NULL |
| 37 | else |
| 38 | if and eq n1 long 1 and ge get a1 0 uchar 48 le get a1 0 uchar 54 |
| 39 | level = int sub get a1 0 uchar 48 |
| 40 | end |
| 41 | end |
| 42 | seed = p0wm_parse_u64 view a2 ulong n2 |
| 43 | w = new Pd0World 0 0 0 0 0 0 0 0 0 0 0 0 0 |
| 44 | d = new Pd0Desc 0 0 0 0 0 0 0 0 0 0 |
| 45 | g = new Pd0Gen 0 0 0 0 0 0 0 |
| 46 | if ne pd0_world_init edit w edit d edit g level seed 0 |
| 47 | pd0_puts 2 P0WM_BADLVL |
| 48 | ret 2 |
| 49 | end |
| 50 | rc = pd0_world_serve edit w view d view g 0 1 |
| 51 | if eq rc 0 |
| 52 | ret 0 |
| 53 | end |
| 54 | ret 1 |
| 55 | end |