interplane.Get Omega
Read in your language

synapse-claims

aien-dev/synapse-claims

Brought by drakestapleton

GitHub aien-dev/synapse-claims#3 (code only)

closed derived 9a633b88e1f06073 #3

Imported from GitHub aien-dev/synapse-claims#3 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 7679a5235e6ce5b3d040b498bde38b1e0e9f483d · Head 71e4f7588f92c160ab755febd2fc104e7aacc3d5

Apply it

git checkout -b patch-9a633b88e1f06073 7679a5235e6ce5b3d040b498bde38b1e0e9f483d
curl -fsSL https://interplane.io/drakestapleton/synapse-claims/patches/9a633b88e1f06073.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/synapse-claims
3
71e4f7588f92c160ab755febd2fc104e7aacc3d5
{"kind":"github-import","owner":"aien-dev","repo":"synapse-claims","number":3,"url":"https://github.com/aien-dev/synapse-claims/pull/3","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:50Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/src/10_base.om b/src/10_base.om
index 4d12d0f..3450fc4 100644
--- a/src/10_base.om
+++ b/src/10_base.om
@@ -7,6 +7,7 @@ const lncap ulong 65536
 const ncl ulong 131072
 const nf ulong 24
 const arcap ulong 33554432
+const arbank ulong 16777216
 const pecap ulong 8388608
 const outcap ulong 524288
 const errcap ulong 8192
@@ -66,7 +67,9 @@ const xkind ulong 45
 
 global gout uchar 524288
 global gerr uchar 8192
-global gar uchar 33554432
+note gar0/gar1: the arcap-byte string arena as two banks; one global holds at most 16777216 elements
+global gar0 uchar 16777216
+global gar1 uchar 16777216
 global gcl ulong 3145728
 global ght ulong 262144
 global ghk ulong 262144
@@ -131,22 +134,22 @@ end
 ret sub e s
 end
 
+note tw_eqat: s equals t[p .. p+len s)
+fn tw_eqat s edit uchar * t view uchar * p ulong to bool
+for i ulong len s
+if ne get s i get t add p i
+ret false
+end
+end
+ret true
+end
+
 note tw_find: index of the word in t[base .. base+cnt) equal to s (whole slice), or tbad
 fn tw_find s edit uchar * t view uchar * base ulong cnt ulong to ulong
-l = len s
-o = ulong 0
 for k ulong cnt
 w = add base k
-p = tw_off t w
-if eq tw_len t w l
-eqv = true
-for i ulong l
-if ne get s add o i get t add p i
-eqv = false
-break
-end
-end
-if eqv
+if eq tw_len t w len s
+if tw_eqat s t tw_off t w
 ret w
 end
 end
@@ -214,7 +217,7 @@ end
 
 fn o_ar off ulong n ulong to void
 for i ulong n
-o_b get gar add off i
+o_b ar_g add off i
 end
 end
 
@@ -272,31 +275,55 @@ n = get gx xarn
 if ge n arcap
 die 70 mfull
 end
-put gar n c
+if lt n arbank
+put gar0 n c
+else
+put gar1 sub n arbank c
+end
 put gx xarn add n 1
 end
 
-fn ar_t t view uchar * to ulong
-s = get gx xarn
+fn ar_g n ulong to uchar
+if lt n arbank
+ret get gar0 n
+end
+ret get gar1 sub n arbank
+end
+
+note ar_tv/ar_lnv/ar_cpv append to the arena; ar_t/ar_ln/ar_cp also return the start offset
+fn ar_tv t view uchar * to void
 for i ulong len t
 ar_b get t i
 end
+end
+
+fn ar_t t view uchar * to ulong
+s = get gx xarn
+ar_tv t
 ret s
 end
 
-fn ar_ln s edit uchar * off ulong n ulong to ulong
-st = get gx xarn
+fn ar_lnv s edit uchar * off ulong n ulong to void
 for i ulong n
 ar_b get s add off i
 end
-ret st
 end
 
-fn ar_cp off ulong n ulong to ulong
+fn ar_ln s edit uchar * off ulong n ulong to ulong
 st = get gx xarn
+ar_lnv s off n
+ret st
+end
+
+fn ar_cpv off ulong n ulong to void
 for i ulong n
-ar_b get gar add off i
+ar_b ar_g add off i
 end
+end
+
+fn ar_cp off ulong n ulong to ulong
+st = get gx xarn
+ar_cpv off n
 ret st
 end
 
@@ -305,7 +332,7 @@ if ne an bn
 ret false
 end
 for i ulong an
-if ne get gar add a i get gar add b i
+if ne ar_g add a i ar_g add b i
 ret false
 end
 end
@@ -324,7 +351,7 @@ if ne an bn
 ret false
 end
 for i ulong an
-if ne lower get gar add a i lower get gar add b i
+if ne lower ar_g add a i lower ar_g add b i
 ret false
 end
 end
diff --git a/src/20_time_io.om b/src/20_time_io.om
index 535dfea..de5d244 100644
--- a/src/20_time_io.om
+++ b/src/20_time_io.om
@@ -18,7 +18,8 @@ if gt m 2
 mm = sub m 3
 end
 doy = add div add mul 153 mm 2 5 sub d 1
-doe = add sub add mul yoe 365 div yoe 4 div yoe 100 doy
+doe = add mul yoe 365 div yoe 4
+doe = add sub doe div yoe 100 doy
 ret sub add mul era 146097 doe 719468
 end
 
@@ -27,9 +28,11 @@ fn t_civ days ulong to ulong
 z = add days 719468
 era = div z 146097
 doe = sub z mul era 146097
-yoe = div sub add sub doe div doe 1460 div doe 36524 div doe 146096 365
+yoe = sub add sub doe div doe 1460 div doe 36524 div doe 146096
+yoe = div yoe 365
 y = add yoe mul era 400
-doy = sub doe sub add mul 365 yoe div yoe 4 div yoe 100
+doy = sub add mul 365 yoe div yoe 4 div yoe 100
+doy = sub doe doy
 mp = div add mul 5 doy 2 153
 d = add sub doy div add mul 153 mp 2 5 1
 m = add mp 3
@@ -87,30 +90,48 @@ end
 ret v
 end
 
-note ts_parse: s[off..off+20) strict YYYY-MM-DDTHH:MM:SSZ, 1970..9999, round-trip exact; else tbad
-fn ts_parse s edit uchar * off ulong to ulong
+note ts_ymd: days since 1970-01-01 of s[off..off+10) YYYY-MM-DD, 1970..9999; else tbad
+fn ts_ymd s edit uchar * off ulong to ulong
 y = t_num s off 4
 m = t_num s add off 5 2
 d = t_num s add off 8 2
-hh = t_num s add off 11 2
-mi = t_num s add off 14 2
-se = t_num s add off 17 2
 if or or eq y tbad eq m tbad eq d tbad
 ret tbad
 end
+if or or lt y 1970 lt m 1 gt m 12
+ret tbad
+end
+if or lt d 1 gt d 31
+ret tbad
+end
+ret t_days y m d
+end
+
+note ts_hms: seconds of day of s[off..off+8) HH:MM:SS; else tbad
+fn ts_hms s edit uchar * off ulong to ulong
+hh = t_num s off 2
+mi = t_num s add off 3 2
+se = t_num s add off 6 2
 if or or eq hh tbad eq mi tbad eq se tbad
 ret tbad
 end
-if or or lt y 1970 lt m 1 gt m 12
+if or or ge hh 24 ge mi 60 ge se 60
 ret tbad
 end
-if or or lt d 1 gt d 31 ge hh 24
+ret add add mul hh 3600 mul mi 60 se
+end
+
+note ts_parse: s[off..off+20) strict YYYY-MM-DDTHH:MM:SSZ, 1970..9999, round-trip exact; else tbad
+fn ts_parse s edit uchar * off ulong to ulong
+dy = ts_ymd s off
+if eq dy tbad
 ret tbad
 end
-if or ge mi 60 ge se 60
+sd = ts_hms s add off 11
+if eq sd tbad
 ret tbad
 end
-v = add mul t_days y m d 86400 add add mul hh 3600 mul mi 60 se
+v = add mul dy 86400 sd
 ts_fmt v
 for i ulong 20
 if ne get gtb i get s add off i
@@ -191,7 +212,7 @@ end
 fn pk_ar off ulong n ulong to void
 p = pk_rec n
 for i ulong n
-put gpk add p i get gar add off i
+put gpk add p i ar_g add off i
 end
 end
 
diff --git a/src/40_state.om b/src/40_state.om
index 8ce11ad..a1dec01 100644
--- a/src/40_state.om
+++ b/src/40_state.om
@@ -122,22 +122,9 @@ end
 ret or or eq c 46 eq c 95 eq c 45
 end
 
-note tg_canon: canonical copy of target s[o..o+n) appended to the arena; returns its offset (length
-note in gx[xpos]) and the kind in gx[xkind]; tbad (arena unchanged) when the target is invalid.
-fn tg_canon s edit uchar * o ulong n ulong to ulong
-if eq sf_ok part s o n false
-ret tbad
-end
-kd = tg_kind s o n
-if eq kd tbad
-ret tbad
-end
-put gx xkind kd
-st = get gx xarn
-w = tw_len wall add kd 13
-i = add w 1
-ar_ln s o i
-if eq kd 4
+note tg_ext: appends the lowercased ext scheme of s[o+i..o+n); returns the index of its ':' or tbad
+fn tg_ext s edit uchar * o ulong n ulong i0 ulong to ulong
+i = i0
 scl = ulong 0
 while lt i n bound 300
 c = lower get s add o i
@@ -145,7 +132,6 @@ if eq c 58
 break
 end
 if eq or rp_ch c eq c 43 false
-put gx xarn st
 ret tbad
 end
 ar_b c
@@ -153,13 +139,14 @@ scl = add scl 1
 i = add i 1
 end
 if or or eq scl 0 ge i n eq add i 1 n
-put gx xarn st
 ret tbad
 end
-ar_ln s add o i sub n i
-put gx xpos sub get gx xarn st
-ret st
+ret i
 end
+
+note tg_own: appends the lowercased OWNER/REPO of s[o+i..o+n); returns the index after it or tbad
+fn tg_own s edit uchar * o ulong n ulong i0 ulong to ulong
+i = i0
 sl = ulong 0
 rl = ulong 0
 while lt i n bound 300
@@ -169,13 +156,14 @@ break
 end
 if eq c 47
 sl = add sl 1
-if or eq rl 0 eq get s add o sub i 1 47
-put gx xarn st
+if eq rl 0
+ret tbad
+end
+if eq get s add o sub i 1 47
 ret tbad
 end
 else
 if eq rp_ch c false
-put gx xarn st
 ret tbad
 end
 end
@@ -183,41 +171,75 @@ ar_b c
 rl = add rl 1
 i = add i 1
 end
-if or ne sl 1 eq get s add o sub i 1 47
-put gx xarn st
+if ne sl 1
 ret tbad
 end
-if eq kd 0
-if lt i n
-put gx xarn st
+if eq get s add o sub i 1 47
 ret tbad
 end
-put gx xpos sub get gx xarn st
-ret st
+ret i
 end
+
+note tg_sfx: s[o+i..o+n) is a valid branch/pr/path suffix for kind kd (separator plus non-empty rest)
+fn tg_sfx s edit uchar * o ulong n ulong i ulong kd ulong to bool
 if ge add i 1 n
-put gx xarn st
-ret tbad
+ret false
 end
 c = get s add o i
 if and eq kd 2 ne c 58
-put gx xarn st
-ret tbad
+ret false
 end
 if and ne kd 2 ne c 35
-put gx xarn st
-ret tbad
+ret false
 end
 if eq kd 3
 for j ulong sub sub n i 1
 d = get s add add o i add j 1
 if or lt d 48 gt d 57
+ret false
+end
+end
+end
+ret true
+end
+
+note tg_canon: canonical copy of target s[o..o+n) appended to the arena; returns its offset (length
+note in gx[xpos]) and the kind in gx[xkind]; tbad (arena unchanged) when the target is invalid.
+fn tg_canon s edit uchar * o ulong n ulong to ulong
+if eq sf_ok part s o n false
+ret tbad
+end
+kd = tg_kind s o n
+if eq kd tbad
+ret tbad
+end
+put gx xkind kd
+st = get gx xarn
+i = add tw_len wall add kd 13 1
+ar_lnv s o i
+if eq kd 4
+i = tg_ext s o n i
+else
+i = tg_own s o n i
+end
+if eq i tbad
 put gx xarn st
 ret tbad
 end
+if eq kd 0
+if lt i n
+put gx xarn st
+ret tbad
 end
+else
+if ne kd 4
+if eq tg_sfx s o n i kd false
+put gx xarn st
+ret tbad
 end
-ar_ln s add o i sub n i
+end
+end
+ar_lnv s add o i sub n i
 put gx xpos sub get gx xarn st
 ret st
 end
@@ -226,7 +248,7 @@ note end of the owner/repo part of arena target t (kind code k, kind word skippe
 fn tg_rend k ulong t ulong n ulong to ulong
 i = add tw_len wall add k 13 1
 while lt i n bound 300
-c = get gar add t i
+c = ar_g add t i
 if or eq c 35 eq c 58
 ret i
 end
@@ -239,7 +261,7 @@ note literal prefix (bytes before the first '*') length of the glob part from of
 fn gl_pre t ulong g ulong n ulong to ulong
 i = g
 while lt i n bound 300
-if eq get gar add t i 42
+if eq ar_g add t i 42
 ret sub i g
 end
 i = add i 1
@@ -247,6 +269,22 @@ end
 ret sub n g
 end
 
+note ov_path: 3 when the literal glob prefixes of two path targets (repo part ending at ea/eb) agree, else 0
+fn ov_path ta ulong ea ulong la ulong tb ulong eb ulong lb ulong to ulong
+pa = gl_pre ta add ea 1 la
+pb = gl_pre tb add eb 1 lb
+m = pa
+if lt pb m
+m = pb
+end
+ga = add ta add ea 1
+gb = add tb add eb 1
+if ar_eq ga m gb m
+ret 3
+end
+ret 0
+end
+
 note ov: overlap reason of two canonical arena targets: 0 none 1 same_target 2 repo_covers
 note 3 path_overlap 4 ext_casefold
 fn ov ka ulong ta ulong la ulong kb ulong tb ulong lb ulong to ulong
@@ -278,16 +316,7 @@ end
 if or ne ka 2 ne kb 2
 ret 0
 end
-pa = gl_pre ta add ea 1 la
-pb = gl_pre tb add eb 1 lb
-m = pa
-if lt pb m
-m = pb
-end
-if ar_eq add ta add ea 1 m add tb add eb 1 m
-ret 3
-end
-ret 0
+ret ov_path ta ea la tb eb lb
 end
 
 fn c_act i ulong to bool
@@ -307,7 +336,7 @@ if ne an n
 ret false
 end
 for i ulong n
-if ne get gar add a i get s add o i
+if ne ar_g add a i get s add o i
 ret false
 end
 end
@@ -329,11 +358,11 @@ if gt add add ol add1 n evcap
 ret
 end
 st = get gx xarn
-ar_cp c_get i cev ol
+ar_cpv c_get i cev ol
 if gt ol 0
 ar_b 44
 end
-ar_ln s get gp qev n
+ar_lnv s get gp qev n
 c_put i cev st
 c_put i cevl add add ol add1 n
 end
diff --git a/src/50_event.om b/src/50_event.om
index 7badabf..54c4bcc 100644
--- a/src/50_event.om
+++ b/src/50_event.om
@@ -49,7 +49,7 @@ end
 
 fn l_ar s edit uchar * off ulong n ulong to void
 for i ulong n
-l_b s get gar add off i
+l_b s ar_g add off i
 end
 end
 
@@ -174,6 +174,7 @@ l_b s 34
 for i ulong 64
 l_b s 48
 end
+l_b s 34
 l_t s ksig
 l_b s 34
 for j ulong 128
diff --git a/src/70_cmds.om b/src/70_cmds.om
index a71d464..c8bb9d9 100644
--- a/src/70_cmds.om
+++ b/src/70_cmds.om
@@ -122,6 +122,23 @@ end
 ret sub w base
 end
 
+note u8_cont: the k continuation bytes after av[p] are 128..191, the first one within lo..hi
+fn u8_cont av edit uchar * p ulong k ulong lo ulong hi ulong to bool
+for j ulong k
+d = ulong get av add p add j 1
+if eq j 0
+if or lt d lo gt d hi
+ret false
+end
+else
+if or lt d 128 gt d 191
+ret false
+end
+end
+end
+ret true
+end
+
 note UTF-8 check (RFC 3629: no overlongs, no surrogates, max U+10FFFF) of av[o..o+n)
 fn utf8_ok av edit uchar * o ulong n ulong to bool
 i = ulong 0
@@ -161,18 +178,9 @@ end
 if gt add i k sub n 1
 ret false
 end
-for j ulong k
-d = ulong get av add add o i add j 1
-if eq j 0
-if or lt d lo gt d hi
-ret false
-end
-else
-if or lt d 128 gt d 191
+if eq u8_cont av add o i k lo hi false
 ret false
 end
-end
-end
 i = add add i k 1
 end
 ret true
@@ -243,7 +251,7 @@ if gt i 0
 ar_b 44
 end
 ar_b 34
-ar_ln av o n
+ar_lnv av o n
 ar_b 34
 end
 put gx xpos sub get gx xarn st
@@ -273,9 +281,9 @@ end
 end
 end
 if eq pre false
-ar_t timp
+ar_tv timp
 end
-ar_ln av o n
+ar_lnv av o n
 put gx xpos sub get gx xarn st
 if gt get gx xpos 256
 die 64 mmimp
@@ -310,7 +318,7 @@ o_b 32
 o_b 40
 o_id c_get i cid
 o_t tuntil
-o_tsq c_get i cexp
+o_ts c_get i cexp
 o_b 58
 o_b 32
 o_ar c_get i cin c_get i cinl
@@ -443,6 +451,26 @@ put gev eev 0
 put gev eevl 0
 end
 
+note hd_live: renew needs a lease that has not expired yet (exit 4 otherwise)
+fn hd_live i ulong to void
+if le c_get i cexp get gx xnow
+die 4 mna
+end
+end
+
+note hd_fin: sets the renew/release expiry of the event in gev, appends it and prints the result
+fn hd_fin ln edit uchar * op ulong ttl ulong to void
+if eq op 1
+put gev ettl ttl
+put gev eexp add get gx xnow ttl
+end
+if eq op 2
+put gev eexp get gx xnow
+end
+ev_emit ln false
+o_ok get gev eid get gx xseq get gev eexp
+end
+
 note cm_hold: renew (op 1), release (op 2), state (op 3)
 fn cm_hold av edit uchar * ln edit uchar * op ulong to void
 ttl = ulong 0
@@ -463,8 +491,8 @@ orl = get gx xpos
 lk_take 2
 ld_all ln
 i = cl_mine av
-if and eq op 1 le c_get i cexp get gx xnow
-die 4 mna
+if eq op 1
+hd_live i
 end
 ev_from i
 put gev eop op
@@ -475,15 +503,7 @@ put gev eevl evl
 if ne stc tbad
 put gev est stc
 end
-if eq op 1
-put gev ettl ttl
-put gev eexp add get gx xnow ttl
-end
-if eq op 2
-put gev eexp get gx xnow
-end
-ev_emit ln false
-o_ok get gev eid get gx xseq get gev eexp
+hd_fin ln op ttl
 end
 
 fn cm_who av edit uchar * ln edit uchar * to void
@@ -521,14 +541,14 @@ if lt al n
 ret false
 end
 for k ulong n
-if ne get gar add a k get av add o k
+if ne ar_g add a k get av add o k
 ret false
 end
 end
 if eq al n
 ret true
 end
-ret eq get gar add a n 46
+ret eq ar_g add a n 46
 end
 
 fn cm_list av edit uchar * ln edit uchar * to void
@@ -545,22 +565,24 @@ end
 end
 end
 
-fn cm_conf ln edit uchar * to void
-lk_take 1
-ld_all ln
-found = false
-nc = get gx xnc
-for i ulong nc
-if c_act i
-if eq c_get i cmode 0
-for j ulong sub nc add i 1
-k = add add i j 1
-if c_act k
-if eq c_get k cmode 0
-if eq ar_eq c_get i cag c_get i cagl c_get k cag c_get k cagl false
-r = ov c_get i ckind c_get i ctg c_get i ctgl c_get k ckind c_get k ctg c_get k ctgl
-if ne r 0
-found = true
+note cf_pair: prints the conflict line of exclusive claims i and k (k active, other agent, overlapping)
+fn cf_pair i ulong k ulong to bool
+if eq c_act k false
+ret false
+end
+if ne c_get k cmode 0
+ret false
+end
+if ar_eq c_get i cag c_get i cagl c_get k cag c_get k cagl
+ret false
+end
+ka = c_get k ckind
+kt = c_get k ctg
+kl = c_get k ctgl
+r = ov c_get i ckind c_get i ctg c_get i ctgl ka kt kl
+if eq r 0
+ret false
+end
 o_t ta
 o_claim i
 o_t tb
@@ -570,9 +592,20 @@ o_wd wreason sub r 1
 o_q
 o_b 125
 o_b 10
+ret true
 end
-end
-end
+
+fn cm_conf ln edit uchar * to void
+lk_take 1
+ld_all ln
+found = false
+nc = get gx xnc
+for i ulong nc
+if c_act i
+if eq c_get i cmode 0
+for j ulong sub nc add i 1
+if cf_pair i add add i j 1
+found = true
 end
 end
 end
diff --git a/src/90_main.om b/src/90_main.om
index f847732..b142796 100644
--- a/src/90_main.om
+++ b/src/90_main.om
@@ -56,6 +56,16 @@ put gx slot st
 put gx add slot 1 sub get gx xlp st
 end
 
+note env_pre: av[65536..) starts with t
+fn env_pre av edit uchar * t view uchar * to bool
+for j ulong len t
+if ne get av add 65536 j get t j
+ret false
+end
+end
+ret true
+end
+
 note env_find: environment entry starting with prefix t, copied to av[65536..); length or tbad
 fn env_find av edit uchar * t view uchar * to ulong
 for i ulong ulong envcnt
@@ -63,13 +73,7 @@ n = envread i av 65536 65536
 if ge n 0
 k = ulong n
 if ge k len t
-m = true
-for j ulong len t
-if ne get av add 65536 j get t j
-m = false
-end
-end
-if m
+if env_pre av t
 ret k
 end
 end