go-vise

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

parse.go (2160B)


      1 package debug
      2 
      3 import (
      4 	"git.defalsify.org/vise.git/logging"
      5 	"git.defalsify.org/vise.git/vm"
      6 )
      7 
      8 var (
      9 	logg = logging.NewVanilla().WithDomain("debug")
     10 )
     11 
     12 type NodeParseHandler struct {
     13 	*vm.ParseHandler
     14 	node            *Node
     15 	parentMOutFunc  func(string, string) error
     16 	parentMoveFunc  func(string) error
     17 	parentInCmpFunc func(string, string) error
     18 	parentCatchFunc func(string, uint32, bool) error
     19 }
     20 
     21 func NewNodeParseHandler(node *Node) *NodeParseHandler {
     22 	np := &NodeParseHandler{
     23 		ParseHandler: vm.NewParseHandler().WithDefaultHandlers(),
     24 	}
     25 	np.node = node
     26 	np.node.Name = node.Name
     27 	np.parentMoveFunc = np.ParseHandler.Move
     28 	np.parentInCmpFunc = np.ParseHandler.InCmp
     29 	np.parentCatchFunc = np.ParseHandler.Catch
     30 	np.parentMOutFunc = np.ParseHandler.MOut
     31 	np.Move = np.move
     32 	np.InCmp = np.incmp
     33 	np.Catch = np.catch
     34 	np.MOut = np.mout
     35 	return np
     36 }
     37 
     38 func (np *NodeParseHandler) mout(sym string, sel string) error {
     39 	c := AddMenu(sym)
     40 	logg.Infof("add MOUT", "sym", sym, "visited", c)
     41 	return np.parentMOutFunc(sym, sel)
     42 }
     43 
     44 func (np *NodeParseHandler) move(sym string) error {
     45 	var node Node
     46 
     47 	if sym == "<" || sym == ">" || sym == "^" || sym == "_" || sym == "." {
     48 		logg.Debugf("skip lateral move")
     49 		return np.parentMoveFunc(sym)
     50 	}
     51 
     52 	node.Name = sym
     53 	np.node.Connect(node)
     54 	logg.Infof("connect MOVE", "src", np.node.Name, "dst", node.Name)
     55 	return np.parentMoveFunc(sym)
     56 }
     57 
     58 func (np *NodeParseHandler) incmp(sym string, sel string) error {
     59 	var node Node
     60 
     61 	if sym == "<" || sym == ">" || sym == "^" || sym == "_" || sym == "." {
     62 		logg.Debugf("skip relative move")
     63 		return np.parentInCmpFunc(sym, sel)
     64 	}
     65 
     66 	node.Name = sym
     67 	np.node.Connect(node)
     68 	logg.Debugf("connect INCMP", "src", np.node.Name, "dst", node.Name)
     69 	return np.parentInCmpFunc(sym, sel)
     70 }
     71 
     72 func (np *NodeParseHandler) catch(sym string, flag uint32, inv bool) error {
     73 	var node Node
     74 
     75 	if sym == "<" || sym == ">" || sym == "^" || sym == "_" || sym == "." {
     76 		logg.Debugf("skip relative move")
     77 		return np.parentMoveFunc(sym)
     78 	}
     79 
     80 	node.Name = sym
     81 	np.node.Connect(node)
     82 	logg.Debugf("connect CATCH", "src", np.node.Name, "dst", node.Name)
     83 	return np.parentCatchFunc(sym, flag, inv)
     84 }