Skip to content
This repository was archived by the owner on Dec 8, 2025. It is now read-only.

Commit 955d827

Browse files
authored
patch: rename registernumber (#49)
1 parent ab3d636 commit 955d827

2 files changed

Lines changed: 20 additions & 15 deletions

File tree

compiler/src/specgen.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ import {
2222
import { jacdacDefaultSpecifications } from "./embedspecs"
2323
import { prelude } from "./prelude"
2424
import { camelize, upperCamel } from "./util"
25-
import { packetsToRegisters } from "../../runtime/jacdac-c/jacdac/spectool/jdutils"
25+
26+
const REGISTER_NUMBER = "RegisterNumber"
27+
const REGISTER_BOOL = "RegisterBool"
28+
const REGISTER_STRING = "RegisterString"
29+
const REGISTER_BUFFER = "RegisterBuffer"
30+
const REGISTER_ARRAY = "RegisterArray"
2631

2732
function isRegister(k: jdspec.PacketKind) {
2833
return k == "ro" || k == "rw" || k == "const"
@@ -114,18 +119,18 @@ function specToDeviceScript(info: jdspec.ServiceSpec): string {
114119
if (isRegister(pkt.kind)) {
115120
kw = "readonly "
116121
if (cmt.needsStruct) {
117-
tp = `RegisterArray`
122+
tp = REGISTER_ARRAY
118123
if (pkt.fields.length > 1) tp += ` & { ${fields} }`
119124
} else {
120125
if (pkt.fields.length == 1 && pkt.fields[0].type == "string")
121-
tp = "RegisterString"
126+
tp = REGISTER_STRING
122127
else if (
123128
pkt.fields.length == 1 &&
124129
pkt.fields[0].type == "bytes"
125130
)
126-
tp = "RegisterBuffer"
127-
else if (pkt.fields[0].type == "bool") tp = "RegisterBool"
128-
else tp = "RegisterNum"
131+
tp = REGISTER_BUFFER
132+
else if (pkt.fields[0].type == "bool") tp = REGISTER_BOOL
133+
else tp = REGISTER_NUMBER
129134
}
130135
} else if (pkt.kind == "event") {
131136
kw = "readonly "
@@ -277,19 +282,19 @@ ${varname}.${camelize(pkt.name)}(${fields}): void
277282
const isConst = pkt.kind === "const"
278283
let tp: string = undefined
279284
if (cmt.needsStruct) {
280-
tp = `RegisterArray`
285+
tp = REGISTER_ARRAY
281286
if (pkt.fields.length > 1) tp += ` & { ${fields} }`
282287
} else {
283288
if (pkt.fields.length == 1 && pkt.fields[0].type == "string")
284-
tp = "RegisterString"
289+
tp = REGISTER_STRING
285290
else if (pkt.fields.length == 1 && pkt.fields[0].type == "bytes")
286-
tp = "RegisterBuffer"
287-
else if (pkt.fields[0].type == "bool") tp = "RegisterBool"
288-
else tp = "RegisterNum"
291+
tp = REGISTER_BUFFER
292+
else if (pkt.fields[0].type == "bool") tp = REGISTER_BOOL
293+
else tp = REGISTER_NUMBER
289294
}
290-
const isNumber = tp === "RegisterNum"
291-
const isBoolean = tp === "RegisterBool"
292-
const isString = tp === "RegisterString"
295+
const isNumber = tp === REGISTER_NUMBER
296+
const isBoolean = tp === REGISTER_BOOL
297+
const isString = tp === REGISTER_STRING
293298
r.push(
294299
`### ${pname}
295300
`,

devs/lib/devicescript-core.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ declare module "@devicescript/core" {
1111

1212
export class Register extends PacketInfo {}
1313

14-
export class RegisterNum extends Register {
14+
export class RegisterNumber extends Register {
1515
read(): number
1616
write(v: number): void
1717
onChange(threshold: number, handler: (curr: number) => void): void

0 commit comments

Comments
 (0)