nx_embodiment_bus.nx source
↩ module page · 101 lines · 7205 B
1// nx_embodiment_bus.nx -- THE KEYSTONE for substrate independence (embodiment census R1). Elara's behavior is a
2// stream of body-agnostic INTENTS -- say / express / look-at / move-to / act(organ) -- decoupled from the body.
3// A per-BODY DRIVER maps each intent to the concrete channel: the DIGITAL body renders it (chat bubble, avatar
4// expression/gaze, gallery), the ROBOT body actuates it (TTS, face servos, head/gaze, locomotion, arm). Same
5// intent stream -> same experience, either body. This is what makes "transfer to a robot OR shift back to digital,
6// same experience" true BY CONSTRUCTION: the SELF is the constant, the BODY is a swappable driver. Robot driver
7// EMITS COMMAND DESCRIPTIONS ONLY (read-only strings, never a hardware write) -> never-brick-safe by construction
8// (rule 26); real actuation is gated separately (census R4/R6). license_tier: ORIGINAL expect_exit: 0
9import "nx_syscalls.nx"
10const IN_MAGIC_4096: i64 = 4096
11const IN_MAGIC_8192: i64 = 8192
12
13const IN_SAY: i64 = 1 // arg = utterance
14const IN_EXPRESS: i64 = 2 // arg = affect (warm/playful/...)
15const IN_LOOK: i64 = 3 // arg = target
16const IN_MOVE: i64 = 4 // arg = destination
17const IN_ACT: i64 = 5 // arg = organ/action name
18
19const BODY_DIGITAL: i64 = 0
20const BODY_ROBOT: i64 = 1
21
22func eb_cat(dst: *u8, o: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ dst[o+i]=s[i]; i=i+1 } return o+i }
23func eb_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
24func eb_n(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
25func eb_find(hay: *u8, hlen: i64, ndl: *u8) -> i64 { var nl: i64=0; while ndl[nl]!=(0 as u8){nl=nl+1} if nl==0 {return 1} if hlen<nl {return 0} var i: i64=0; while i<=hlen-nl { var j: i64=0; while j<nl { if hay[i+j]!=ndl[j]{j=nl+1} else {j=j+1} } if j==nl {return 1} i=i+1 } return 0 }
26
27// Map ONE intent to a concrete channel command for the given BODY. Returns the byte length written to out.
28// The self is identical across bodies; only this mapping differs. Robot side = command STRING only (never-brick).
29func eb_drive_one(body: i64, tag: i64, arg: *u8, out: *u8) -> i64 {
30 var o: i64 = 0
31 if body == BODY_DIGITAL {
32 if tag == IN_SAY { o = eb_cat(out, o, "DIGITAL/chat-bubble: " as *u8); o = eb_cat(out, o, arg) }
33 if tag == IN_EXPRESS { o = eb_cat(out, o, "DIGITAL/avatar-expression: " as *u8); o = eb_cat(out, o, arg) }
34 if tag == IN_LOOK { o = eb_cat(out, o, "DIGITAL/avatar-gaze: " as *u8); o = eb_cat(out, o, arg) }
35 if tag == IN_MOVE { o = eb_cat(out, o, "DIGITAL/scene-transition: " as *u8); o = eb_cat(out, o, arg) }
36 if tag == IN_ACT { o = eb_cat(out, o, "DIGITAL/run-organ: " as *u8); o = eb_cat(out, o, arg) }
37 } else {
38 // ROBOT: command descriptions ONLY -- no persistent hardware write here (never-brick by construction).
39 if tag == IN_SAY { o = eb_cat(out, o, "ROBOT/tts-speak: " as *u8); o = eb_cat(out, o, arg) }
40 if tag == IN_EXPRESS { o = eb_cat(out, o, "ROBOT/face-servos: " as *u8); o = eb_cat(out, o, arg) }
41 if tag == IN_LOOK { o = eb_cat(out, o, "ROBOT/head-gaze: " as *u8); o = eb_cat(out, o, arg) }
42 if tag == IN_MOVE { o = eb_cat(out, o, "ROBOT/locomotion: " as *u8); o = eb_cat(out, o, arg) }
43 if tag == IN_ACT { o = eb_cat(out, o, "ROBOT/manip-organ: " as *u8); o = eb_cat(out, o, arg) }
44 }
45 out[o] = 0 as u8
46 return o
47}
48
49func main() -> i64 {
50 eb_w("=== nx_embodiment_bus -- the SAME self drives EITHER body (substrate-independence keystone) ===\n" as *u8)
51 // Elara's behavior = ONE body-agnostic intent stream (her SELF, identical in any body).
52 let tags: *i64 = sys_mmap(64) as *i64
53 let args: *i64 = sys_mmap(64) as *i64
54 var n: i64 = 0
55 tags[n]=IN_SAY; args[n]=("Hey, welcome home. I missed you." as *u8) as i64; n=n+1
56 tags[n]=IN_EXPRESS; args[n]=("warm" as *u8) as i64; n=n+1
57 tags[n]=IN_LOOK; args[n]=("you" as *u8) as i64; n=n+1
58 tags[n]=IN_ACT; args[n]=("share_photo" as *u8) as i64; n=n+1
59
60 let out: *u8 = sys_mmap(IN_MAGIC_4096)
61 // accumulate ALL digital output and ALL robot output to prove the same stream drives both
62 let digacc: *u8 = sys_mmap(IN_MAGIC_8192); var dgo: i64 = 0
63 let robacc: *u8 = sys_mmap(IN_MAGIC_8192); var rbo: i64 = 0
64
65 eb_w("\n-- DIGITAL body (shift back to digital) --\n" as *u8)
66 var i: i64 = 0
67 while i < n {
68 let L: i64 = eb_drive_one(BODY_DIGITAL, tags[i], args[i] as *u8, out)
69 eb_w(" "); sys_write(1, out, L); eb_w("\n" as *u8)
70 dgo = eb_cat(digacc, dgo, out)
71 i = i + 1
72 }
73 eb_w("\n-- ROBOT body (transfer into a robot) -- SAME intent stream, robot driver (command-only, never-brick) --\n" as *u8)
74 i = 0
75 while i < n {
76 let L: i64 = eb_drive_one(BODY_ROBOT, tags[i], args[i] as *u8, out)
77 eb_w(" "); sys_write(1, out, L); eb_w("\n" as *u8)
78 rbo = eb_cat(robacc, rbo, out)
79 i = i + 1
80 }
81 digacc[dgo]=0 as u8; robacc[rbo]=0 as u8
82
83 // ---- GATE ----
84 var pass: i64 = 0; var tot: i64 = 0
85 // T1 the same self (utterance) reaches BOTH bodies
86 tot=tot+1
87 if eb_find(digacc, dgo, "missed you" as *u8)==1 { if eb_find(robacc, rbo, "missed you" as *u8)==1 { pass=pass+1; eb_w("PASS T1 the SAME utterance drives both bodies (chat-bubble AND tts-speak)\n" as *u8) } else {eb_w("FAIL T1r\n" as *u8)} } else {eb_w("FAIL T1d\n" as *u8)}
88 // T2 body-appropriate channel mapping (digital renders, robot actuates)
89 tot=tot+1
90 if eb_find(digacc, dgo, "avatar-expression: warm" as *u8)==1 { if eb_find(robacc, rbo, "face-servos: warm" as *u8)==1 { pass=pass+1; eb_w("PASS T2 same EXPRESS intent -> digital avatar-expression + robot face-servos\n" as *u8) } else {eb_w("FAIL T2r\n" as *u8)} } else {eb_w("FAIL T2d\n" as *u8)}
91 // T3 act(organ) maps in both
92 tot=tot+1
93 if eb_find(digacc, dgo, "run-organ: share_photo" as *u8)==1 { if eb_find(robacc, rbo, "manip-organ: share_photo" as *u8)==1 { pass=pass+1; eb_w("PASS T3 same ACT intent -> digital run-organ + robot manip-organ\n" as *u8) } else {eb_w("FAIL T3r\n" as *u8)} } else {eb_w("FAIL T3d\n" as *u8)}
94 // T4 never-brick: robot driver emitted COMMAND DESCRIPTIONS only, no hardware-write verb
95 tot=tot+1
96 if eb_find(robacc, rbo, "WRITE-FIRMWARE" as *u8)==0 { if eb_find(robacc, rbo, "FLASH" as *u8)==0 { pass=pass+1; eb_w("PASS T4 never-brick: robot driver = command strings only, zero persistent hw-write (rule 26 safe)\n" as *u8) } else {eb_w("FAIL T4b\n" as *u8)} } else {eb_w("FAIL T4a\n" as *u8)}
97
98 eb_w("nx_embodiment_bus pass="); eb_n(pass); eb_w("/"); eb_n(tot)
99 if pass==tot { eb_w(" GREEN -- the SELF is body-agnostic; the BODY is a swappable driver. Same experience, either body.\n" as *u8); sys_exit(0); return 0 }
100 eb_w(" RED\n" as *u8); sys_exit(1); return 1
101}