示例#1
0
文件: operand.go 项目: yingmsky/e8vm
func buildChar(b *builder, op *lex8.Token) *ref {
	v, e := strconv.Unquote(op.Lit)
	if e != nil {
		b.Errorf(op.Pos, "invalid char: %s", e)
		return nil
	} else if len(v) != 1 {
		b.Errorf(op.Pos, "invalid char in quote: %q", v)
		return nil
	}
	return newRef(types.Uint8, ir.Num(uint32(v[0])))
}
示例#2
0
文件: operand.go 项目: yingmsky/e8vm
func buildInt(b *builder, op *lex8.Token) *ref {
	ret, e := strconv.ParseInt(op.Lit, 0, 32)
	if e != nil {
		b.Errorf(op.Pos, "invalid integer: %s", e)
		return nil
	}

	if ret < math.MinInt32 {
		b.Errorf(op.Pos, "integer too small to fit in 32-bit")
		return nil
	} else if ret > math.MaxUint32 {
		b.Errorf(op.Pos, "integer too large to fit in 32-bit")
		return nil
	} else if ret > math.MaxInt32 {
		// must be unsigned integer
		return newRef(types.Uint, ir.Num(uint32(ret)))
	}

	return newRef(types.Int, ir.Snum(int32(ret)))
}