Skip to content

Commit

Permalink
refactor(compiler): restructure compiler architecture and update entr…
Browse files Browse the repository at this point in the history
…y hashing

- Added `//go:build experimental` and `+build experimental` tags to `mo_compiler.go`.
- Refactored `compiler` namespace in `structure.puml`:
  - Replaced `Compiler` class with an interface.
  - Introduced `MoCompiler` and `PoCompiler` classes to separate responsibilities.
  - Updated relationships and structure to reflect new design.
- Updated `Entry.Hash()` method in `entry.go` to include a comment clarifying the EOT byte usage.
- Updated binary files (`structure.png`) to reflect changes in the UML diagrams.
  • Loading branch information
Tom5521 committed Mar 1, 2025
1 parent 76290c7 commit 5430431
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
3 changes: 3 additions & 0 deletions pkg/po/compiler/mo_compiler.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build experimental
// +build experimental

package compiler

import (
Expand Down
Binary file modified pkg/po/compiler/structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 28 additions & 12 deletions pkg/po/compiler/structure.puml
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
@startuml
namespace compiler {
class Compiler << (S,Aquamarine) >> {
+ File *po.File
+ Config Config

- applyOptions(opts ...Option)
- formatHeader() string
- formatEntry(t po.Entry) string

+ ToWriter(w io.Writer, options ...Option) error
+ ToFile(f string, options ...Option) error
+ ToString(options ...Option) string
+ ToBytes(options ...Option) []byte
interface Compiler {
+ ToWriter( io.Writer, ...Option) error
+ ToFile( string, ...Option) error
+ ToString( ...Option) string
+ ToBytes( ...Option) []byte

}
class Config << (S,Aquamarine) >> {
Expand All @@ -31,13 +24,36 @@ namespace compiler {

+ Validate() error

}
class MoCompiler << (S,Aquamarine) >> {
+ File *po.File
+ Config Config

- applyOptions(opts ...Option)
- createBinary()

}
class PoCompiler << (S,Aquamarine) >> {
+ File *po.File
+ Config Config

- applyOptions(opts ...Option)
- formatHeader() string
- formatEntry(t po.Entry) string

+ ToWriter(w io.Writer, options ...Option) error
+ ToFile(f string, options ...Option) error
+ ToString(options ...Option) string
+ ToBytes(options ...Option) []byte

}
class compiler.LocationMode << (T, #FF7700) >> {
}
class compiler.Option << (T, #FF7700) >> {
}
}

"compiler.Compiler" <|-- "compiler.PoCompiler"

"__builtin__.string" #.. "compiler.LocationMode"
"compiler.<font color=blue>func</font>(*Config) " #.. "compiler.Option"
Expand Down
2 changes: 1 addition & 1 deletion pkg/po/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (e Entry) Hash() uint {

if e.Context != "" {
b.WriteString(e.Context)
b.WriteByte('4')
b.WriteByte('4') // EOT byte.
}
b.WriteString(e.ID)

Expand Down
Binary file modified pkg/po/structure.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions pkg/po/structure.puml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace po {
+ Str string
+ Locations []Location

+ Hash() uint
+ String() string

}
Expand Down

0 comments on commit 5430431

Please sign in to comment.