go-vise

Constrained Size Output Virtual Machine
Info | Log | Files | Refs | README | LICENSE

flag.go (1073B)


      1 package state
      2 
      3 const (
      4 	// Currently reading input. Set by first INCMP instruction encontered.
      5 	FLAG_READIN = iota
      6 	// Input matched a selector. Set by first INCMP matching input.
      7 	FLAG_INMATCH 
      8 	// The instruction HALT has been encountered.
      9 	FLAG_WAIT
     10 	// The last LOAD or RELOAD executed returneded an error.
     11 	FLAG_LOADFAIL
     12 	// A LOAD or RELOAD has returned fresh data.
     13 	FLAG_DIRTY
     14 	// Not currently in use.
     15 	FLAG_RESERVED
     16 	// VM execution is blocked.
     17 	FLAG_TERMINATE 
     18 	// The return value from a LOAD or RELOAD is a new language selection.
     19 	FLAG_LANG
     20 	// User-defined flags start here.
     21 	FLAG_USERSTART = 8
     22 )
     23 
     24 const (
     25 	nonwriteable_flag_threshold = FLAG_RESERVED
     26 )
     27 
     28 // IsWriteableFlag returns true if flag can be set by implementer code.
     29 func IsWriteableFlag(flag uint32) bool {
     30 	if flag > nonwriteable_flag_threshold {
     31 		return true
     32 	}
     33 	return false
     34 }
     35 
     36 // Retrieve the state of a state flag
     37 func getFlag(bitIndex uint32, bitField []byte) bool {
     38 	byteIndex := bitIndex / 8
     39 	localBitIndex := bitIndex % 8
     40 	b := bitField[byteIndex]
     41 	return (b & (1 << localBitIndex)) > 0
     42 }