From 00b0f13d3eb865705d6e141b46a94d901ec77701 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Wed, 15 Oct 2025 00:58:14 -0400 Subject: [PATCH] generate: Implement bool in static system --- generate/generate.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/generate/generate.go b/generate/generate.go index f1bfbcf..2c64b33 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -47,6 +47,15 @@ func canAssign(destination, source tape.Tag) bool { } return false } + +// boolInt converts a bool to an integer. +func boolInt(input bool) int { + if input { + return 1 + } else { + return 0 + } +} ` // Generator converts protocols into Go code. @@ -315,6 +324,9 @@ func (this *Generator) generateMessage(method uint16, message Message) (n int, e // - nn int func (this *Generator) generateEncodeValue(typ Type, valueSource, tagSource string) (n int, err error) { switch typ := typ.(type) { + case TypeBool: + // SI: (none) + // SI stores the value in the tag, so we write nothing here case TypeInt: // SI: (none) // LI/LSI: @@ -518,6 +530,11 @@ func (this *Generator) generateEncodeValue(typ Type, valueSource, tagSource stri // for [Generator.generateDecodeBranch]. func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagSource string) (n int, err error) { switch typ := typ.(type) { + case TypeBool: + // SI: (none) + // SI stores the value in the tag + nn, err := this.iprintf("*%s = %s.CN() > 0\n", valueSource, tagSource) + n += nn; if err != nil { return n, err } case TypeInt: // SI: (none) // LI/LSI: @@ -944,6 +961,9 @@ func (this *Generator) generateBareErrorCheck() (n int, err error) { func (this *Generator) generateTag(typ Type, source string) (tagVar string, n int, err error) { tagVar = this.newTemporaryVar("tag") switch typ := typ.(type) { + case TypeBool: + nn, err := this.iprintf("%s := tape.SI.WithCN(boolInt(bool(%s)))\n", tagVar, source) + n += nn; if err != nil { return tagVar, n, err } case TypeInt: if typ.Bits <= 5 { nn, err := this.iprintf("%s := tape.SI.WithCN(int(%s))\n", tagVar, source) @@ -997,6 +1017,9 @@ func (this *Generator) generateTag(typ Type, source string) (tagVar string, n in // information is chosen. func (this *Generator) generateTN(typ Type) (n int, err error) { switch typ := typ.(type) { + case TypeBool: + nn, err := this.printf("tape.SI") + n += nn; if err != nil { return n, err } case TypeInt: if typ.Bits <= 5 { nn, err := this.printf("tape.SI") @@ -1040,6 +1063,9 @@ func (this *Generator) generateTN(typ Type) (n int, err error) { func (this *Generator) generateType(typ Type) (n int, err error) { switch typ := typ.(type) { + case TypeBool: + nn, err := this.printf("bool") + n += nn; if err != nil { return n, err } case TypeInt: if err := this.validateIntBitSize(typ.Bits); err != nil { return n, err