Namespace: go.std.go.constant
v1.0Contents
Summary
Provides a low-level interface to the go/constant package.
Package constant implements Values representing untyped
Go constants and their corresponding operations.
A special Unknown value may be used when a value
is unknown due to an error. Operations on unknown
values produce unknown values unless specified
otherwise.
Index
- *Kind
- BinaryOp
- BitLen
- Bool
- BoolVal
- Bytes
- Compare
- Complex
- Denom
- Float
- Float32Val
- Float64Val
- Imag
- Int
- Int64Val
- Kind
- Make
- MakeBool
- MakeFloat64
- MakeFromBytes
- MakeFromLiteral
- MakeImag
- MakeInt64
- MakeString
- MakeUint64
- MakeUnknown
- Num
- Real
- Shift
- Sign
- String
- StringVal
- ToComplex
- ToFloat
- ToInt
- Uint64Val
- UnaryOp
- Unknown
- Val
- Value
- arrayOfKind
- arrayOfValue
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
Bool
GoObject v1.0non-numeric values
-
Complex
GoObject v1.0 -
Float
GoObject v1.0 -
Int
GoObject v1.0numeric values
-
String
GoObject v1.0 -
Unknown
GoObject v1.0unknown values
Functions, Macros, and Special Forms
-
BinaryOp
Function v1.0(BinaryOp x_ op y_)
BinaryOp returns the result of the binary expression x op y.
The operation must be defined for the operands. If one of the
operands is Unknown, the result is Unknown.
BinaryOp doesn't handle comparisons or shifts; use Compare
or Shift instead.
To force integer division of Int operands, use op == token.QUO_ASSIGN
instead of token.QUO; the result is guaranteed to be Int in this case.
Division by zero leads to a run-time panic.
Go input arguments: (x_ Value, op go/token.Token, y_ Value)
Go returns: Value
Joker input arguments: [^Value x_, ^go.std.go.token/Token op, ^Value y_]
Joker returns: ^Value -
BitLen
Function v1.0(BitLen x)
BitLen returns the number of bits required to represent
the absolute value x in binary representation; x must be an Int or an Unknown.
If x is Unknown, the result is 0.
Go input arguments: (x Value)
Go returns: int
Joker input arguments: [^Value x]
Joker returns: ^Int -
BoolVal
Function v1.0(BoolVal x)
BoolVal returns the Go boolean value of x, which must be a Bool or an Unknown.
If x is Unknown, the result is false.
Go input arguments: (x Value)
Go returns: bool
Joker input arguments: [^Value x]
Joker returns: ^Boolean -
Bytes
Function v1.0(Bytes x)
Bytes returns the bytes for the absolute value of x in little-
endian binary representation; x must be an Int.
Go input arguments: (x Value)
Go returns: []byte
Joker input arguments: [^Value x]
Joker returns: ^arrayOfByte -
Compare
Function v1.0(Compare x_ op y_)
Compare returns the result of the comparison x op y.
The comparison must be defined for the operands.
If one of the operands is Unknown, the result is
false.
Go input arguments: (x_ Value, op go/token.Token, y_ Value)
Go returns: bool
Joker input arguments: [^Value x_, ^go.std.go.token/Token op, ^Value y_]
Joker returns: ^Boolean -
Denom
Function v1.0(Denom x)
Denom returns the denominator of x; x must be Int, Float, or Unknown.
If x is Unknown, or if it is too large or small to represent as a
fraction, the result is Unknown. Otherwise the result is an Int >= 1.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
Float32Val
Function v1.0(Float32Val x)
Float32Val is like Float64Val but for float32 instead of float64.
Go input arguments: (x Value)
Go returns: (float32, bool)
Joker input arguments: [^Value x]
Joker returns: [^Double, ^Boolean] -
Float64Val
Function v1.0(Float64Val x)
Float64Val returns the nearest Go float64 value of x and whether the result is exact;
x must be numeric or an Unknown, but not Complex. For values too small (too close to 0)
to represent as float64, Float64Val silently underflows to 0. The result sign always
matches the sign of x, even for 0.
If x is Unknown, the result is (0, false).
Go input arguments: (x Value)
Go returns: (float64, bool)
Joker input arguments: [^Value x]
Joker returns: [^Double, ^Boolean] -
Imag
Function v1.0(Imag x)
Imag returns the imaginary part of x, which must be a numeric or unknown value.
If x is Unknown, the result is Unknown.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
Int64Val
Function v1.0(Int64Val x)
Int64Val returns the Go int64 value of x and whether the result is exact;
x must be an Int or an Unknown. If the result is not exact, its value is undefined.
If x is Unknown, the result is (0, false).
Go input arguments: (x Value)
Go returns: (int64, bool)
Joker input arguments: [^Value x]
Joker returns: [^BigInt, ^Boolean] -
Make
Function v1.0(Make x)
Make returns the Value for x.
type of x result Kind
----------------------------
bool Bool
string String
int64 Int
*big.Int Int
*big.Float Float
*big.Rat Float
anything else Unknown
Go input arguments: (x any)
Go returns: Value
Joker input arguments: [^GoObject x]
Joker returns: ^Value -
MakeBool
Function v1.0(MakeBool b)
MakeBool returns the Bool value for b.
Go input arguments: (b bool)
Go returns: Value
Joker input arguments: [^Boolean b]
Joker returns: ^Value -
MakeFloat64
Function v1.0(MakeFloat64 x)
MakeFloat64 returns the Float value for x.
If x is -0.0, the result is 0.0.
If x is not finite, the result is an Unknown.
Go input arguments: (x float64)
Go returns: Value
Joker input arguments: [^Double x]
Joker returns: ^Value -
MakeFromBytes
Function v1.0(MakeFromBytes bytes)
MakeFromBytes returns the Int value given the bytes of its little-endian
binary representation. An empty byte slice argument represents 0.
Go input arguments: (bytes []byte)
Go returns: Value
Joker input arguments: [^arrayOfByte bytes]
Joker returns: ^Value -
MakeFromLiteral
Function v1.0(MakeFromLiteral lit tok zero)
MakeFromLiteral returns the corresponding integer, floating-point,
imaginary, character, or string value for a Go literal string. The
tok value must be one of token.INT, token.FLOAT, token.IMAG,
token.CHAR, or token.STRING. The final argument must be zero.
If the literal string syntax is invalid, the result is an Unknown.
Go input arguments: (lit string, tok go/token.Token, zero uint)
Go returns: Value
Joker input arguments: [^String lit, ^go.std.go.token/Token tok, ^Number zero]
Joker returns: ^Value -
MakeImag
Function v1.0(MakeImag x)
MakeImag returns the Complex value x*i;
x must be Int, Float, or Unknown.
If x is Unknown, the result is Unknown.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
MakeInt64
Function v1.0(MakeInt64 x)
MakeInt64 returns the Int value for x.
Go input arguments: (x int64)
Go returns: Value
Joker input arguments: [^BigInt x]
Joker returns: ^Value -
MakeString
Function v1.0(MakeString s)
MakeString returns the String value for s.
Go input arguments: (s string)
Go returns: Value
Joker input arguments: [^String s]
Joker returns: ^Value -
MakeUint64
Function v1.0(MakeUint64 x)
MakeUint64 returns the Int value for x.
Go input arguments: (x uint64)
Go returns: Value
Joker input arguments: [^Number x]
Joker returns: ^Value -
MakeUnknown
Function v1.0(MakeUnknown)
MakeUnknown returns the Unknown value.
Go returns: Value
Joker input arguments: []
Joker returns: ^Value -
Num
Function v1.0(Num x)
Num returns the numerator of x; x must be Int, Float, or Unknown.
If x is Unknown, or if it is too large or small to represent as a
fraction, the result is Unknown. Otherwise the result is an Int
with the same sign as x.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
Real
Function v1.0(Real x)
Real returns the real part of x, which must be a numeric or unknown value.
If x is Unknown, the result is Unknown.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
Shift
Function v1.0(Shift x op s)
Shift returns the result of the shift expression x op s
with op == token.SHL or token.SHR (<< or >>). x must be
an Int or an Unknown. If x is Unknown, the result is x.
Go input arguments: (x Value, op go/token.Token, s uint)
Go returns: Value
Joker input arguments: [^Value x, ^go.std.go.token/Token op, ^Number s]
Joker returns: ^Value -
Sign
Function v1.0(Sign x)
Sign returns -1, 0, or 1 depending on whether x < 0, x == 0, or x > 0;
x must be numeric or Unknown. For complex values x, the sign is 0 if x == 0,
otherwise it is != 0. If x is Unknown, the result is 1.
Go input arguments: (x Value)
Go returns: int
Joker input arguments: [^Value x]
Joker returns: ^Int -
StringVal
Function v1.0(StringVal x)
StringVal returns the Go string value of x, which must be a String or an Unknown.
If x is Unknown, the result is "".
Go input arguments: (x Value)
Go returns: string
Joker input arguments: [^Value x]
Joker returns: ^String -
ToComplex
Function v1.0(ToComplex x)
ToComplex converts x to a Complex value if x is representable as a Complex.
Otherwise it returns an Unknown.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
ToFloat
Function v1.0(ToFloat x)
ToFloat converts x to a Float value if x is representable as a Float.
Otherwise it returns an Unknown.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
ToInt
Function v1.0(ToInt x)
ToInt converts x to an Int value if x is representable as an Int.
Otherwise it returns an Unknown.
Go input arguments: (x Value)
Go returns: Value
Joker input arguments: [^Value x]
Joker returns: ^Value -
Uint64Val
Function v1.0(Uint64Val x)
Uint64Val returns the Go uint64 value of x and whether the result is exact;
x must be an Int or an Unknown. If the result is not exact, its value is undefined.
If x is Unknown, the result is (0, false).
Go input arguments: (x Value)
Go returns: (uint64, bool)
Joker input arguments: [^Value x]
Joker returns: [^Number, ^Boolean] -
UnaryOp
Function v1.0(UnaryOp op y prec)
UnaryOp returns the result of the unary expression op y.
The operation must be defined for the operand.
If prec > 0 it specifies the ^ (xor) result size in bits.
If y is Unknown, the result is Unknown.
Go input arguments: (op go/token.Token, y Value, prec uint)
Go returns: Value
Joker input arguments: [^go.std.go.token/Token op, ^Value y, ^Number prec]
Joker returns: ^Value -
Val
Function v1.0(Val x)
Val returns the underlying value for a given constant. Since it returns an
interface, it is up to the caller to type assert the result to the expected
type. The possible dynamic return types are:
x Kind type of result
-----------------------------------------
Bool bool
String string
Int int64 or *big.Int
Float *big.Float or *big.Rat
everything else nil
Go input arguments: (x Value)
Go returns: any
Joker input arguments: [^Value x]
Joker returns: ^GoObject
Types
-
*Kind
Concrete Type v1.0Kind specifies the kind of value represented by a Value.
-
Kind
Concrete Type v1.0Kind specifies the kind of value represented by a Value.
-
String
Receiver for Kind v1.0([])
-
Value
Abstract Type v1.0A Value represents the value of a Go constant.
-
ExactString
Method for Value v1.0([])
-
Kind
Method for Value v1.0([])
-
String
Method for Value v1.0([])
-
arrayOfKind
Concrete Type v1.0Kind specifies the kind of value represented by a Value.
-
arrayOfValue
Concrete Type v1.0A Value represents the value of a Go constant.