Пример #1
0
func (a *Asm) readIs(fn *bytecode.Fn) {
	var l string
	var ok bool
	// While a new F section is not reached
	for l, ok = a.getLine(false); ok && l != "[f]"; l, ok = a.getLine(false) {
		// Split in three parts
		parts := strings.SplitN(l, " ", 3)
		if a.assertIParts(parts) {
			var ix uint64
			o := bytecode.NewOpcode(parts[0])
			f := bytecode.NewFlag(parts[1])
			ix, a.err = strconv.ParseUint(parts[2], 10, 64)
			fn.Is = append(fn.Is, bytecode.NewInstr(o, f, ix))
		}
	}
	if ok {
		a.readFn()
	}
}
Пример #2
0
i5
[l]
[i]
PUSH K 1 // Push constant value 5 on the stack
POP V 0  // Pop the value from the stack into variable identified by constant 0 (a)
PUSH V 0 // Push value of variable identified by constant 0 on the stack (a)
DUMP S 1
RET _ 0
`,
			exp: AppendAny(SigVer(bytecode.Version()), Int64ToByteSlice(4), 't', 'e', 's', 't',
				// StackSz - ExpArgs - ParentFnIx - LineStart - LineEnd
				Int64ToByteSlice(1), ExpZeroInt64, ExpZeroInt64, ExpZeroInt64, Int64ToByteSlice(2),
				// Ks - Ls - Is
				Int64ToByteSlice(2), 's', Int64ToByteSlice(1), 'a', 'i', Int64ToByteSlice(5), ExpZeroInt64, Int64ToByteSlice(5),
				// 5 ops
				UInt64ToByteSlice(uint64(bytecode.NewInstr(bytecode.NewOpcode("PUSH"), bytecode.NewFlag("K"), 1))),
				UInt64ToByteSlice(uint64(bytecode.NewInstr(bytecode.NewOpcode("POP"), bytecode.NewFlag("V"), 0))),
				UInt64ToByteSlice(uint64(bytecode.NewInstr(bytecode.NewOpcode("PUSH"), bytecode.NewFlag("V"), 0))),
				UInt64ToByteSlice(uint64(bytecode.NewInstr(bytecode.NewOpcode("DUMP"), bytecode.NewFlag("S"), 1))),
				UInt64ToByteSlice(uint64(bytecode.NewInstr(bytecode.NewOpcode("RET"), bytecode.NewFlag("_"), 0))),
			),
		},
		3: {
			// Unknown opcode
			id: "test",
			src: `
[f]
test
1
0
0