interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / src / physics0 / pd0_world_main.om

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