MCPcopy Create free account
hub / github.com/djhworld/simple-computer / parseLabelledJump

Function parseLabelledJump

asm/parser.go:138–158  ·  view source on GitHub ↗
(name string, operands string)

Source from the content-addressed store, hash-verified

136}
137
138func parseLabelledJump(name string, operands string) (Instruction, error) {
139 arguments := LABEL_EXTRACTOR.FindStringSubmatch(operands)
140 if len(arguments) != 2 {
141 return nil, fmt.Errorf("Instruction %s is not valid", name)
142 }
143
144 switch name {
145 case "JMP":
146 return JMP{LABEL{arguments[1]}}, nil
147 case "CALL":
148 return CALL{LABEL{arguments[1]}}, nil
149 case "JMPZ", "JMPE", "JMPEZ", "JMPA", "JMPAZ", "JMPAE", "JMPAEZ", "JMPC", "JMPCZ", "JMPCE", "JMPCEZ", "JMPCA", "JMPCAZ", "JMPCAE", "JMPCAEZ":
150 flags, err := extractFlagsFrom(name)
151 if err != nil {
152 return nil, err
153 }
154 return JMPF{flags, LABEL{arguments[1]}}, nil
155 default:
156 return nil, fmt.Errorf("Unsupported labelled jump instruction %s", name)
157 }
158}
159
160func extractFlagsFrom(name string) ([]string, error) {
161 tokens := FLAGS_EXTRACTOR.FindStringSubmatch(name)

Callers 1

parseInstructionFunction · 0.85

Calls 1

extractFlagsFromFunction · 0.85

Tested by

no test coverage detected