stage.go raw

   1  // Package iskra is the port of the iskra .mx tree: coord arithmetic, the token
   2  // dictionary, the .meta store and the verbs built on them.
   3  package iskra
   4  
   5  import "git.smesh.lol/go-iskra/lattice"
   6  
   7  // Stage tags, high byte of a code key.
   8  const (
   9  	StageSRC uint8 = 0x01
  10  	StageAST uint8 = 0x02
  11  	StageIR  uint8 = 0x03
  12  	StageASM uint8 = 0x04
  13  	StageBIN uint8 = 0x05
  14  )
  15  
  16  // StageName is the printed name of a stage.
  17  func StageName(s uint8) string {
  18  	switch s {
  19  	case StageSRC:
  20  		return "SRC"
  21  	case StageAST:
  22  		return "AST"
  23  	case StageIR:
  24  		return "IR"
  25  	case StageASM:
  26  		return "ASM"
  27  	case StageBIN:
  28  		return "BIN"
  29  	}
  30  	return "?"
  31  }
  32  
  33  // NameKey is the key for a named entity at a stage: stage byte over the FNV-1a
  34  // hash of the name.
  35  func NameKey(stage uint8, name string) lattice.Key {
  36  	return lattice.MakeCodeKey(stage, lattice.HashBytes([]byte(name)))
  37  }
  38  
  39  // SegmentKey is the key for segment content at a stage.
  40  func SegmentKey(stage uint8, content []byte) lattice.Key {
  41  	return lattice.MakeCodeKey(stage, lattice.HashBytes(content))
  42  }
  43