Documentation ¶
Index ¶
- Constants
- Variables
- func AddConstCode(code int, name string, typ int, value []byte)
- func AllocateSeq(size int) (offset int)
- func AssertFailed() bool
- func CXCreateFile(filename string) (*os.File, error)
- func CXLogFile(enable bool)
- func CXMkdirAll(path string, perm os.FileMode) error
- func CXOpenFile(filename string) (*os.File, error)
- func CXReadFile(path string) ([]byte, error)
- func CXRemoveFile(path string) error
- func CXSetWorkingDir(dir string)
- func CXStatFile(path string) (os.FileInfo, error)
- func CalculateDereferences(arg *CXArgument, finalOffset *int, fp int, dbg bool)
- func CallAffPredicate(fn *CXFunction, predValue []byte) byte
- func CheckArithmeticOp(expr *CXExpression) bool
- func CompilationError(currentFile string, lineNo int) string
- func ConstI32(code int, name string, value int32)
- func CopyProgramState(sPrgrm1, sPrgrm2 *[]byte)
- func Debug(args ...interface{})
- func DebugHeap()
- func DisplaceReferences(prgrm *CXProgram, off int, numPkgs int)
- func ErrorHeader(currentFile string, lineNo int) string
- func ErrorString(code int) string
- func EscapeAnalysis(fp int, inpOffset, outOffset int, arg *CXArgument)
- func ExprOpName(expr *CXExpression) string
- func ExtractBlockchainProgram(sPrgrm1, sPrgrm2 []byte) []byte
- func ExtractTransactionProgram(sPrgrm1, sPrgrm2 []byte) []byte
- func FromBool(in bool) []byte
- func FromF32(in float32) []byte
- func FromF64(in float64) []byte
- func FromI16(in int16) []byte
- func FromI32(in int32) []byte
- func FromI64(in int64) []byte
- func FromI8(in int8) []byte
- func FromStr(in string) []byte
- func FromUI16(in uint16) []byte
- func FromUI32(in uint32) []byte
- func FromUI64(in uint64) []byte
- func FromUI8(in uint8) []byte
- func GetArgSize(typ int) int
- func GetArgSizeFromTypeName(typeName string) int
- func GetDerefSize(arg *CXArgument) int
- func GetFinalOffset(fp int, arg *CXArgument) int
- func GetFormattedName(arg *CXArgument, includePkg bool) string
- func GetFormattedType(arg *CXArgument) string
- func GetInferActions(inp *CXArgument, fp int) []string
- func GetObjectHeader(offset int32) []byte
- func GetOpCodeCount() int
- func GetPointerOffset(pointer int32) int32
- func GetPrintableValue(fp int, arg *CXArgument) string
- func GetSerializedDataSize(sPrgrm []byte) int
- func GetSerializedMemoryOffset(sPrgrm []byte) int
- func GetSerializedStackSize(sPrgrm []byte) int
- func GetSize(arg *CXArgument) int
- func GetSlice(offset int32, sizeofElement int) []byte
- func GetSliceData(offset int32, sizeofElement int) []byte
- func GetSliceHeader(offset int32) []byte
- func GetSliceLen(offset int32) int32
- func GetSliceOffset(fp int, arg *CXArgument) int32
- func GetStrOffset(fp int, arg *CXArgument) int
- func IsCorePackage(ident string) bool
- func IsPointer(sym *CXArgument) bool
- func IsTempVar(name string) bool
- func IsValidSliceIndex(offset int, index int, sizeofElement int) bool
- func MakeDefaultValue(typName string) []byte
- func MakeElementID() uuid.UUID
- func MakeGenSym(name string) string
- func MakeIdentityOpName(typeName string) string
- func MakeValue(value string) *[]byte
- func Mark(prgrm *CXProgram, heapOffset int32)
- func MarkAndCompact(prgrm *CXProgram)
- func MarkObjectsTree(prgrm *CXProgram, offset int, baseType int, declSpecs []int)
- func MergeTransactionAndBlockchain(sPrgrm1, sPrgrm2 []byte) []byte
- func NewWriteObj(obj []byte) int
- func Op(code int, name string, handler OpcodeHandler, inputs []*CXArgument, ...)
- func ParseArgsForCX(args []string, alsoSubdirs bool) (cxArgs []string, sourceCode []*os.File, fileNames []string)
- func QueryArgument(fn *CXFunction, expr *CXExpression, argOffsetB []byte, affOffset *int)
- func QueryCaller(fn *CXFunction, expr *CXExpression, callerOffsetB []byte, affOffset *int)
- func QueryExpressions(fn *CXFunction, expr *CXExpression, exprOffsetB []byte, affOffset *int)
- func QueryFunction(fn *CXFunction, expr *CXExpression, fnOffsetB []byte, affOffset *int)
- func QueryProgram(fn *CXFunction, expr *CXExpression, prgrmOffsetB []byte, affOffset *int)
- func QueryStructure(fn *CXFunction, expr *CXExpression, strctOffsetB []byte, affOffset *int)
- func ReadArray(fp int, inp *CXArgument, dataType int) interface{}
- func ReadBool(fp int, inp *CXArgument) (out bool)
- func ReadData(fp int, inp *CXArgument, dataType int) interface{}
- func ReadF32(fp int, inp *CXArgument) float32
- func ReadF64(fp int, inp *CXArgument) float64
- func ReadI16(fp int, inp *CXArgument) int16
- func ReadI32(fp int, inp *CXArgument) int32
- func ReadI64(fp int, inp *CXArgument) int64
- func ReadI8(fp int, inp *CXArgument) int8
- func ReadMemory(offset int, arg *CXArgument) []byte
- func ReadObject(fp int, inp *CXArgument, dataType int) interface{}
- func ReadSlice(fp int, inp *CXArgument, dataType int) interface{}
- func ReadSliceBytes(fp int, inp *CXArgument, dataType int) []byte
- func ReadStr(fp int, inp *CXArgument) (out string)
- func ReadStringFromObject(off int32) string
- func ReadUI16(fp int, inp *CXArgument) uint16
- func ReadUI32(fp int, inp *CXArgument) uint32
- func ReadUI64(fp int, inp *CXArgument) uint64
- func ReadUI8(fp int, inp *CXArgument) uint8
- func RegisterPackage(pkgName string)
- func ResizeMemory(prgrm *CXProgram, newMemSize int, isExpand bool)
- func RuntimeError()
- func Serialize(prgrm *CXProgram, split int) (byts []byte)
- func SignatureStringOfFunction(pkg *CXPackage, f *CXFunction) string
- func SignatureStringOfStruct(s *CXStruct) string
- func SliceAppendResize(fp int, out *CXArgument, inp *CXArgument, sizeofElement int) int32
- func SliceAppendWrite(outputSliceOffset int32, object []byte, index int32)
- func SliceAppendWriteByte(outputSliceOffset int32, object []byte, index int32)
- func SliceCopy(fp int, outputSliceOffset int32, inp *CXArgument, count int32, ...)
- func SliceCopyEx(outputSliceOffset int32, inputSliceOffset int32, count int32, ...)
- func SliceInsert(fp int, out *CXArgument, inp *CXArgument, index int32, object []byte) int
- func SliceRemove(fp int, out *CXArgument, inp *CXArgument, index int32, sizeofElement int32) int
- func SliceResize(fp int, out *CXArgument, inp *CXArgument, count int32, sizeofElement int) int
- func SliceResizeEx(outputSliceOffset int32, count int32, sizeofElement int) int
- func WriteBool(offset int, b bool)
- func WriteF32(offset int, f float32)
- func WriteF64(offset int, f float64)
- func WriteI16(offset int, v int16)
- func WriteI32(offset int, v int32)
- func WriteI64(offset int, v int64)
- func WriteI8(offset int, v int8)
- func WriteMemF32(mem []byte, offset int, f float32)
- func WriteMemF64(mem []byte, offset int, f float64)
- func WriteMemI16(mem []byte, offset int, v int16)
- func WriteMemI32(mem []byte, offset int, v int32)
- func WriteMemI64(mem []byte, offset int, v int64)
- func WriteMemI8(mem []byte, offset int, v int8)
- func WriteMemUI16(mem []byte, offset int, v uint16)
- func WriteMemUI32(mem []byte, offset int, v uint32)
- func WriteMemUI64(mem []byte, offset int, v uint64)
- func WriteMemUI8(mem []byte, offset int, v uint8)
- func WriteMemory(offset int, byts []byte)
- func WriteObject(out1Offset int, obj []byte)
- func WriteObjectRetOff(obj []byte) int
- func WriteString(fp int, str string, out *CXArgument)
- func WriteStringObj(str string) int
- func WriteToSlice(off int, inp []byte) int
- func WriteUI16(offset int, v uint16)
- func WriteUI32(offset int, v uint32)
- func WriteUI64(offset int, v uint64)
- func WriteUI8(offset int, v uint8)
- type CXArgument
- func GetAssignmentElement(arg *CXArgument) *CXArgument
- func In(params ...*CXArgument) []*CXArgument
- func MakeArgument(name string, fileName string, fileLine int) *CXArgument
- func MakeField(name string, typ int, fileName string, fileLine int) *CXArgument
- func MakeGlobal(name string, typ int, fileName string, fileLine int) *CXArgument
- func Out(params ...*CXArgument) []*CXArgument
- func Param(typCode int) *CXArgument
- func ParamEx(paramData ParamData) *CXArgument
- func Pointer(arg *CXArgument) *CXArgument
- func Slice(typCode int) *CXArgument
- func Struct(pkgName, strctName, argName string) *CXArgument
- type CXCall
- type CXConstant
- type CXExpression
- func (expr *CXExpression) AddInput(param *CXArgument) *CXExpression
- func (expr *CXExpression) AddLabel(lbl string) *CXExpression
- func (expr *CXExpression) AddOutput(param *CXArgument) *CXExpression
- func (expr *CXExpression) GetInputs() ([]*CXArgument, error)
- func (expr *CXExpression) RemoveInput()
- func (expr *CXExpression) RemoveOutput()
- type CXFunction
- func (fn *CXFunction) AddExpression(expr *CXExpression) *CXFunction
- func (fn *CXFunction) AddInput(param *CXArgument) *CXFunction
- func (fn *CXFunction) AddOutput(param *CXArgument) *CXFunction
- func (fn *CXFunction) GetCurrentExpression() (*CXExpression, error)
- func (fn *CXFunction) GetExpressionByLabel(lbl string) (*CXExpression, error)
- func (fn *CXFunction) GetExpressionByLine(line int) (*CXExpression, error)
- func (fn *CXFunction) GetExpressions() ([]*CXExpression, error)
- func (fn *CXFunction) RemoveExpression(line int)
- func (fn *CXFunction) RemoveInput(inpName string)
- func (fn *CXFunction) RemoveOutput(outName string)
- func (fn *CXFunction) SelectExpression(line int) (*CXExpression, error)
- type CXPackage
- func (pkg *CXPackage) AddFunction(fn *CXFunction) *CXPackage
- func (pkg *CXPackage) AddGlobal(def *CXArgument) *CXPackage
- func (pkg *CXPackage) AddImport(imp *CXPackage) *CXPackage
- func (pkg *CXPackage) AddStruct(strct *CXStruct) *CXPackage
- func (pkg *CXPackage) GetCurrentFunction() (*CXFunction, error)
- func (pkg *CXPackage) GetCurrentStruct() (*CXStruct, error)
- func (pkg *CXPackage) GetFunction(fnName string) (*CXFunction, error)
- func (pkg *CXPackage) GetFunctions() ([]*CXFunction, error)
- func (pkg *CXPackage) GetGlobal(defName string) (*CXArgument, error)
- func (pkg *CXPackage) GetImport(impName string) (*CXPackage, error)
- func (pkg *CXPackage) GetMethod(fnName string, receiverType string) (*CXFunction, error)
- func (pkg *CXPackage) GetStruct(strctName string) (*CXStruct, error)
- func (pkg *CXPackage) RemoveFunction(fnName string)
- func (pkg *CXPackage) RemoveGlobal(defName string)
- func (pkg *CXPackage) RemoveImport(impName string)
- func (pkg *CXPackage) RemoveStruct(strctName string)
- func (pkg *CXPackage) SelectExpression(line int) (*CXExpression, error)
- func (pkg *CXPackage) SelectFunction(name string) (*CXFunction, error)
- func (pkg *CXPackage) SelectStruct(name string) (*CXStruct, error)
- type CXProgram
- func (prgrm *CXProgram) AddPackage(mod *CXPackage) *CXProgram
- func (prgrm *CXProgram) Callback(fn *CXFunction, inputs [][]byte) (outputs [][]byte)
- func (prgrm *CXProgram) EnsureHeap()
- func (prgrm *CXProgram) GetCall() *CXCall
- func (prgrm *CXProgram) GetCurrentExpression() (*CXExpression, error)
- func (prgrm *CXProgram) GetCurrentFunction() (*CXFunction, error)
- func (prgrm *CXProgram) GetCurrentPackage() (*CXPackage, error)
- func (prgrm *CXProgram) GetCurrentStruct() (*CXStruct, error)
- func (prgrm *CXProgram) GetExpr() *CXExpression
- func (prgrm *CXProgram) GetFramePointer() int
- func (prgrm *CXProgram) GetFunction(fnName string, pkgName string) (*CXFunction, error)
- func (prgrm *CXProgram) GetGlobal(name string) (*CXArgument, error)
- func (prgrm *CXProgram) GetOpCode() int
- func (prgrm *CXProgram) GetPackage(modName string) (*CXPackage, error)
- func (prgrm *CXProgram) GetStruct(strctName string, modName string) (*CXStruct, error)
- func (prgrm *CXProgram) PrintAllObjects()
- func (prgrm *CXProgram) PrintProgram()
- func (prgrm *CXProgram) PrintStack()
- func (prgrm *CXProgram) RemovePackage(modName string)
- func (prgrm *CXProgram) Run(untilEnd bool, nCalls *int, untilCall int) error
- func (prgrm *CXProgram) RunCompiled(nCalls int, args []string) error
- func (prgrm *CXProgram) SelectExpression(line int) (*CXExpression, error)
- func (prgrm *CXProgram) SelectFunction(name string) (*CXFunction, error)
- func (prgrm *CXProgram) SelectPackage(name string) (*CXPackage, error)
- func (prgrm *CXProgram) SelectProgram() (*CXProgram, error)
- func (prgrm *CXProgram) SelectStruct(name string) (*CXStruct, error)
- func (prgrm *CXProgram) ToCall() *CXExpression
- func (prgrm *CXProgram) UnRun(nCalls int)
- type CXStruct
- type OpcodeHandler
- type ParamData
Constants ¶
const ( PARAM_DEFAULT = iota PARAM_SLICE PARAM_STRUCT )
const ( CX_SUCCESS = iota CX_COMPILATION_ERROR CX_PANIC // 2 CX_INTERNAL_ERROR CX_ASSERT CX_RUNTIME_ERROR CX_RUNTIME_STACK_OVERFLOW_ERROR CX_RUNTIME_HEAP_EXHAUSTED_ERROR CX_RUNTIME_INVALID_ARGUMENT CX_RUNTIME_SLICE_INDEX_OUT_OF_RANGE CX_RUNTIME_NOT_IMPLEMENTED )
const ( DECL_POINTER = iota // 0 DECL_DEREF // 1 DECL_ARRAY // 2 DECL_SLICE // 3 DECL_STRUCT // 4 DECL_INDEXING // 5 DECL_BASIC // 6 DECL_FUNC // 7 )
const ( SCOPE_NEW = iota + 1 // 1 SCOPE_REM // 2 )
create a new scope or return to the previous scope
const ( PASSBY_VALUE = iota PASSBY_REFERENCE )
what to write
const ( DEREF_ARRAY = iota // 0 DEREF_FIELD // 1 DEREF_POINTER // 2 DEREF_DEREF // 3 DEREF_SLICE // 4 )
const ( TYPE_UNDEFINED = iota TYPE_AFF TYPE_BOOL TYPE_STR TYPE_F32 TYPE_F64 TYPE_I8 TYPE_I16 TYPE_I32 TYPE_I64 TYPE_UI8 TYPE_UI16 TYPE_UI32 TYPE_UI64 TYPE_FUNC TYPE_CUSTOM TYPE_POINTER TYPE_ARRAY TYPE_SLICE TYPE_IDENTIFIER )
const ( MEM_STACK = iota MEM_HEAP MEM_DATA )
memory locations
const ( // cx CONST_CX_SUCCESS = iota CONST_CX_COMPILATION_ERROR CONST_CX_PANIC CONST_CX_INTERNAL_ERROR CONST_CX_ASSERT CONST_CX_RUNTIME_ERROR CONST_CX_RUNTIME_STACK_OVERFLOW_ERROR CONST_CX_RUNTIME_HEAP_EXHAUSTED_ERROR CONST_CX_RUNTIME_INVALID_ARGUMENT CONST_CX_RUNTIME_SLICE_INDEX_OUT_OF_RANGE CONST_CX_RUNTIME_NOT_IMPLEMENTED )
constant codes nolint golint
const ( OP_IDENTITY = iota + 1 OP_JMP OP_DEBUG OP_SERIALIZE OP_DESERIALIZE OP_UND_EQUAL OP_UND_UNEQUAL OP_UND_BITAND OP_UND_BITXOR OP_UND_BITOR OP_UND_BITCLEAR OP_UND_MUL OP_UND_DIV OP_UND_MOD OP_UND_ADD OP_UND_SUB OP_UND_NEG OP_UND_BITSHL OP_UND_BITSHR OP_UND_LT OP_UND_GT OP_UND_LTEQ OP_UND_GTEQ OP_UND_LEN OP_UND_PRINTF OP_UND_SPRINTF OP_UND_READ START_PARSE_OPS OP_I8_STR OP_I8_I16 OP_I8_I32 OP_I8_I64 OP_I8_UI8 OP_I8_UI16 OP_I8_UI32 OP_I8_UI64 OP_I8_F32 OP_I8_F64 OP_I16_STR OP_I16_I8 OP_I16_I32 OP_I16_I64 OP_I16_UI8 OP_I16_UI16 OP_I16_UI32 OP_I16_UI64 OP_I16_F32 OP_I16_F64 OP_I32_STR OP_I32_I8 OP_I32_I16 OP_I32_I64 OP_I32_UI8 OP_I32_UI16 OP_I32_UI32 OP_I32_UI64 OP_I32_F32 OP_I32_F64 OP_I64_STR OP_I64_I8 OP_I64_I16 OP_I64_I32 OP_I64_UI8 OP_I64_UI16 OP_I64_UI32 OP_I64_UI64 OP_I64_F32 OP_I64_F64 OP_UI8_STR OP_UI8_I8 OP_UI8_I16 OP_UI8_I32 OP_UI8_I64 OP_UI8_UI16 OP_UI8_UI32 OP_UI8_UI64 OP_UI8_F32 OP_UI8_F64 OP_UI16_STR OP_UI16_I8 OP_UI16_I16 OP_UI16_I32 OP_UI16_I64 OP_UI16_UI8 OP_UI16_UI32 OP_UI16_UI64 OP_UI16_F32 OP_UI16_F64 OP_UI32_STR OP_UI32_I8 OP_UI32_I16 OP_UI32_I32 OP_UI32_I64 OP_UI32_UI8 OP_UI32_UI16 OP_UI32_UI64 OP_UI32_F32 OP_UI32_F64 OP_UI64_STR OP_UI64_I8 OP_UI64_I16 OP_UI64_I32 OP_UI64_I64 OP_UI64_UI8 OP_UI64_UI16 OP_UI64_UI32 OP_UI64_F32 OP_UI64_F64 OP_F32_STR OP_F32_I8 OP_F32_I16 OP_F32_I32 OP_F32_I64 OP_F32_UI8 OP_F32_UI16 OP_F32_UI32 OP_F32_UI64 OP_F32_F64 OP_F64_STR OP_F64_I8 OP_F64_I16 OP_F64_I32 OP_F64_I64 OP_F64_UI8 OP_F64_UI16 OP_F64_UI32 OP_F64_UI64 OP_F64_F32 OP_STR_I8 OP_STR_I16 OP_STR_I32 OP_STR_I64 OP_STR_UI8 OP_STR_UI16 OP_STR_UI32 OP_STR_UI64 OP_STR_F32 OP_STR_F64 END_PARSE_OPS OP_BOOL_PRINT OP_BOOL_EQUAL OP_BOOL_UNEQUAL OP_BOOL_NOT OP_BOOL_OR OP_BOOL_AND OP_I8_PRINT OP_I8_ADD OP_I8_SUB OP_I8_NEG OP_I8_MUL OP_I8_DIV OP_I8_MOD OP_I8_ABS OP_I8_GT OP_I8_GTEQ OP_I8_LT OP_I8_LTEQ OP_I8_EQ OP_I8_UNEQ OP_I8_BITAND OP_I8_BITOR OP_I8_BITXOR OP_I8_BITCLEAR OP_I8_BITSHL OP_I8_BITSHR OP_I8_MAX OP_I8_MIN OP_I8_RAND OP_I16_PRINT OP_I16_ADD OP_I16_SUB OP_I16_NEG OP_I16_MUL OP_I16_DIV OP_I16_MOD OP_I16_ABS OP_I16_GT OP_I16_GTEQ OP_I16_LT OP_I16_LTEQ OP_I16_EQ OP_I16_UNEQ OP_I16_BITAND OP_I16_BITOR OP_I16_BITXOR OP_I16_BITCLEAR OP_I16_BITSHL OP_I16_BITSHR OP_I16_MAX OP_I16_MIN OP_I16_RAND OP_I32_PRINT OP_I32_ADD OP_I32_SUB OP_I32_NEG OP_I32_MUL OP_I32_DIV OP_I32_MOD OP_I32_ABS OP_I32_GT OP_I32_GTEQ OP_I32_LT OP_I32_LTEQ OP_I32_EQ OP_I32_UNEQ OP_I32_BITAND OP_I32_BITOR OP_I32_BITXOR OP_I32_BITCLEAR OP_I32_BITSHL OP_I32_BITSHR OP_I32_MAX OP_I32_MIN OP_I32_RAND OP_I64_PRINT OP_I64_ADD OP_I64_SUB OP_I64_NEG OP_I64_MUL OP_I64_DIV OP_I64_MOD OP_I64_ABS OP_I64_GT OP_I64_GTEQ OP_I64_LT OP_I64_LTEQ OP_I64_EQ OP_I64_UNEQ OP_I64_BITAND OP_I64_BITOR OP_I64_BITXOR OP_I64_BITCLEAR OP_I64_BITSHL OP_I64_BITSHR OP_I64_MAX OP_I64_MIN OP_I64_RAND OP_UI8_PRINT OP_UI8_ADD OP_UI8_SUB OP_UI8_MUL OP_UI8_DIV OP_UI8_MOD OP_UI8_GT OP_UI8_GTEQ OP_UI8_LT OP_UI8_LTEQ OP_UI8_EQ OP_UI8_UNEQ OP_UI8_BITAND OP_UI8_BITOR OP_UI8_BITXOR OP_UI8_BITCLEAR OP_UI8_BITSHL OP_UI8_BITSHR OP_UI8_MAX OP_UI8_MIN OP_UI8_RAND OP_UI16_PRINT OP_UI16_ADD OP_UI16_SUB OP_UI16_MUL OP_UI16_DIV OP_UI16_MOD OP_UI16_GT OP_UI16_GTEQ OP_UI16_LT OP_UI16_LTEQ OP_UI16_EQ OP_UI16_UNEQ OP_UI16_BITAND OP_UI16_BITOR OP_UI16_BITXOR OP_UI16_BITCLEAR OP_UI16_BITSHL OP_UI16_BITSHR OP_UI16_MAX OP_UI16_MIN OP_UI16_RAND OP_UI32_PRINT OP_UI32_ADD OP_UI32_SUB OP_UI32_MUL OP_UI32_DIV OP_UI32_MOD OP_UI32_GT OP_UI32_GTEQ OP_UI32_LT OP_UI32_LTEQ OP_UI32_EQ OP_UI32_UNEQ OP_UI32_BITAND OP_UI32_BITOR OP_UI32_BITXOR OP_UI32_BITCLEAR OP_UI32_BITSHL OP_UI32_BITSHR OP_UI32_MAX OP_UI32_MIN OP_UI32_RAND OP_UI64_PRINT OP_UI64_ADD OP_UI64_SUB OP_UI64_MUL OP_UI64_DIV OP_UI64_MOD OP_UI64_GT OP_UI64_GTEQ OP_UI64_LT OP_UI64_LTEQ OP_UI64_EQ OP_UI64_UNEQ OP_UI64_BITAND OP_UI64_BITOR OP_UI64_BITXOR OP_UI64_BITCLEAR OP_UI64_BITSHL OP_UI64_BITSHR OP_UI64_MAX OP_UI64_MIN OP_UI64_RAND OP_F32_IS_NAN OP_F32_PRINT OP_F32_ADD OP_F32_SUB OP_F32_NEG OP_F32_MUL OP_F32_DIV OP_F32_MOD OP_F32_ABS OP_F32_POW OP_F32_GT OP_F32_GTEQ OP_F32_LT OP_F32_LTEQ OP_F32_EQ OP_F32_UNEQ OP_F32_ACOS OP_F32_COS OP_F32_ASIN OP_F32_SIN OP_F32_SQRT OP_F32_LOG OP_F32_LOG2 OP_F32_LOG10 OP_F32_MAX OP_F32_MIN OP_F32_RAND OP_F64_IS_NAN OP_F64_PRINT OP_F64_ADD OP_F64_SUB OP_F64_NEG OP_F64_MUL OP_F64_DIV OP_F64_MOD OP_F64_ABS OP_F64_POW OP_F64_GT OP_F64_GTEQ OP_F64_LT OP_F64_LTEQ OP_F64_EQ OP_F64_UNEQ OP_F64_ACOS OP_F64_COS OP_F64_ASIN OP_F64_SIN OP_F64_SQRT OP_F64_LOG OP_F64_LOG2 OP_F64_LOG10 OP_F64_MAX OP_F64_MIN OP_F64_RAND OP_STR_PRINT OP_STR_CONCAT OP_STR_SUBSTR OP_STR_INDEX OP_STR_LAST_INDEX OP_STR_TRIM_SPACE OP_STR_EQ OP_APPEND OP_RESIZE OP_INSERT OP_REMOVE OP_COPY OP_ASSERT OP_TEST OP_PANIC OP_PANIC_IF OP_PANIC_IF_NOT OP_STRERROR OP_AFF_PRINT OP_AFF_QUERY OP_AFF_ON OP_AFF_OF OP_AFF_INFORM OP_AFF_REQUEST OP_HTTP_SERVE OP_HTTP_LISTEN_AND_SERVE OP_HTTP_NEW_REQUEST OP_HTTP_DO OP_HTTP_HANDLE OP_HTTP_CLOSE OP_DMSG_DO OP_EVOLVE_EVOLVE END_OF_CORE_OPS )
op codes nolint golint
const CALLSTACK_SIZE = 1000
const DBG_GOLANG_STACK_TRACE = true
const FORWARDING_ADDRESS_SIZE = 4
const HEAP_EXHAUSTED_ERROR = "heap exhausted"
const I32_SIZE = 4
const I64_SIZE = 8
const ID_FN = "identity"
const INIT_FN = "initDef"
const LABEL_PREFIX = "*lbl"
const LITERAL_PLACEHOLDER = "*lit"
Used in `PrintProgram` to represent literals (`CXArgument`s with no name).
const LOCAL_PREFIX = "*tmp"
const MAIN_FUNC = "main"
const MAIN_PKG = "main"
const MARK_SIZE = 1
const MAX_INT32 = int(MAX_UINT32 >> 1)
const MAX_UINT32 = ^uint32(0)
const MIN_INT32 = -MAX_INT32 - 1
const MIN_UINT32 = 0
const NON_ASSIGN_PREFIX = "nonAssign"
const NULL_HEAP_ADDRESS = 0
const NULL_HEAP_ADDRESS_OFFSET = 4
const OBJECT_GC_HEADER_SIZE = 5
const OBJECT_HEADER_SIZE = 9
const OBJECT_SIZE = 4
const OS_ARGS = "Args"
const OS_PKG = "os"
const SLICE_HEADER_SIZE = 8
const STACK_OVERFLOW_ERROR = "stack overflow"
const STDLIB_PKG = "stdlib"
const STR_HEADER_SIZE = 4
const STR_SIZE = 4
const SYS_INIT_FUNC = "*init"
const TYPE_POINTER_SIZE = 4
Variables ¶
var ( ConstNames = map[int]string{} ConstCodes = map[string]int{} Constants = map[int]CXConstant{} )
For the parser. These shouldn't be used in the runtime for performance reasons
var ( // OpNames ... OpNames = map[int]string{} // OpCodes ... OpCodes = map[string]int{} // Natives ... Natives = map[int]*CXFunction{} )
var AAFF = Param(TYPE_AFF)
AAFF Default aff parameter
var ABOOL = Param(TYPE_BOOL)
ABOOL Default bool parameter
var AF32 = Param(TYPE_F32)
AF32 Default f32 parameter
var AF64 = Param(TYPE_F64)
AF64 Default f64 parameter
var AI16 = Param(TYPE_I16)
AI16 Default i16 parameter
var AI32 = Param(TYPE_I32)
AI32 Default i32 parameter
var AI64 = Param(TYPE_I64)
AI64 Default i64 parameter
var AI8 = Param(TYPE_I8)
AI8 Default i8 parameter
var ASTR = Param(TYPE_STR)
ASTR Default str parameter
var AUI16 = Param(TYPE_UI16)
AUI16 Default ui16 parameter
var AUI32 = Param(TYPE_UI32)
AUI32 Default ui32 parameter
var AUI64 = Param(TYPE_UI64)
AUI64 Default ui64 parameter
var AUI8 = Param(TYPE_UI8)
AUI8 Default ui8 parameter
var AUND = Param(TYPE_UNDEFINED)
AUND Default und parameter
var BASIC_TYPES []string = []string{
"bool", "str", "i8", "i16", "i32", "i64", "ui8", "ui16", "ui32", "ui64", "f32", "f64",
"[]bool", "[]str", "[]i8", "[]i16", "[]i32", "[]i64", "[]ui8", "[]ui16", "[]ui32", "[]ui64", "[]f32", "[]f64",
}
var BINPATH = CXPATH + "bin/" // TODO @evanlinjin: Not used.
var CXPATH = os.Getenv("CXPATH") + "/"
var CorePackages = []string{
"al", "gl", "glfw", "time", "http", "os", "explorer", "aff", "gltext", "cx", "json", "regexp", "cipher",
}
CorePackages ...
var ErrorStrings map[int]string = map[int]string{ CX_SUCCESS: "CX_SUCCESS", CX_COMPILATION_ERROR: "CX_COMPILATION_ERROR", CX_PANIC: "CX_PANIC", CX_INTERNAL_ERROR: "CX_INTERNAL_ERROR", CX_ASSERT: "CX_ASSERT", CX_RUNTIME_ERROR: "CX_RUNTIME_ERROR", CX_RUNTIME_STACK_OVERFLOW_ERROR: "CX_RUNTIME_STACK_OVERFLOW_ERROR", CX_RUNTIME_HEAP_EXHAUSTED_ERROR: "CX_RUNTIME_HEAP_EXHAUSTED_ERROR", CX_RUNTIME_INVALID_ARGUMENT: "CX_RUNTIME_INVALID_ARGUMENT", CX_RUNTIME_SLICE_INDEX_OUT_OF_RANGE: "CX_RUNTIME_SLICE_INDEX_OUT_OF_RANGE", CX_RUNTIME_NOT_IMPLEMENTED: "CX_RUNTIME_NOT_IMPLEMENTED", }
var FoundCompileErrors bool
var (
HeapOffset int
)
Var
var INIT_HEAP_SIZE = 2097152 // 2 Mb
var InREPL bool = false
var MAX_HEAP_FREE_RATIO float32 = 0.7
var MAX_HEAP_SIZE = 67108864 // 64 Mb
var MIN_HEAP_FREE_RATIO float32 = 0.4
var PKGPATH = CXPATH + "pkg/" // TODO @evanlinjin: Not used.
var SRCPATH = CXPATH + "src/"
var STACK_SIZE = 1048576 // 1 Mb
var TypeCodes map[string]int = map[string]int{ "ident": TYPE_IDENTIFIER, "aff": TYPE_AFF, "bool": TYPE_BOOL, "str": TYPE_STR, "f32": TYPE_F32, "f64": TYPE_F64, "i8": TYPE_I8, "i16": TYPE_I16, "i32": TYPE_I32, "i64": TYPE_I64, "ui8": TYPE_UI8, "ui16": TYPE_UI16, "ui32": TYPE_UI32, "ui64": TYPE_UI64, "und": TYPE_UNDEFINED, "func": TYPE_FUNC, }
var TypeCounter int
var TypeNames map[int]string = map[int]string{ TYPE_IDENTIFIER: "ident", TYPE_AFF: "aff", TYPE_BOOL: "bool", TYPE_STR: "str", TYPE_F32: "f32", TYPE_F64: "f64", TYPE_I8: "i8", TYPE_I16: "i16", TYPE_I32: "i32", TYPE_I64: "i64", TYPE_UI8: "ui8", TYPE_UI16: "ui16", TYPE_UI32: "ui32", TYPE_UI64: "ui64", TYPE_FUNC: "func", TYPE_UNDEFINED: "und", }
Functions ¶
func AddConstCode ¶
AddConstCode ...
func CXCreateFile ¶
CXCreateFile ... TODO @evanlinjin: This should be in a module named 'util'.
func CXLogFile ¶
func CXLogFile(enable bool)
CXLogFile ... TODO @evanlinjin: This should be in a module named 'util'.
func CXMkdirAll ¶
CXMkdirAll ... TODO @evanlinjin: This should be in a module named 'util'.
func CXOpenFile ¶
CXOpenFile ... TODO @evanlinjin: This should be in a module named 'util'.
func CXReadFile ¶
CXReadFile ... TODO @evanlinjin: This should be in a module named 'util'.
func CXRemoveFile ¶
CXRemoveFile ... TODO @evanlinjin: This should be in a module named 'util'.
func CXSetWorkingDir ¶
func CXSetWorkingDir(dir string)
CXSetWorkingDir ... TODO @evanlinjin: This should be in a module named 'util'.
func CXStatFile ¶
CXStatFile ... TODO @evanlinjin: This should be in a module named 'util'.
func CalculateDereferences ¶
func CalculateDereferences(arg *CXArgument, finalOffset *int, fp int, dbg bool)
CalculateDereferences ...
func CallAffPredicate ¶
func CallAffPredicate(fn *CXFunction, predValue []byte) byte
CallAffPredicate ...
func CompilationError ¶
CompilationError is a helper function that concatenates the `currentFile` and `lineNo` data to a error header and returns the full error string.
func CopyProgramState ¶
func CopyProgramState(sPrgrm1, sPrgrm2 *[]byte)
CopyProgramState copies the program state from `prgrm1` to `prgrm2`.
func DebugHeap ¶
func DebugHeap()
DebugHeap prints the symbols that are acting as pointers in a CX program at certain point during the execution of the program along with the addresses they are pointing. Additionally, a list of the objects in the heap is printed, which shows their address in the heap, if they are marked as alive or as dead by the garbage collector, the address where they used to live after a garbage collector call, the full size of the object, the object itself as a slice of bytes and the pointers that are pointing to that object.
func DisplaceReferences ¶
DisplaceReferences displaces all the pointer-like variables, slice elements or field structures by `off`. `numPkgs` tells us the number of packages to consider for the reference desplacement (this number should equal to the number of packages that represent the blockchain code in a CX chain).
func EscapeAnalysis ¶
func EscapeAnalysis(fp int, inpOffset, outOffset int, arg *CXArgument)
EscapeAnalysis ...
func ExtractBlockchainProgram ¶
ExtractBlockchainProgram extracts the blockchain program from `sPrgrm2` by removing the contents of `sPrgrm1` from `sPrgrm2`. TxnPrgrm = sPrgrm2 - sPrgrm1.
func ExtractTransactionProgram ¶
ExtractTransactionProgram extracts the transaction code (serialized) from a full CX program.
func GetArgSizeFromTypeName ¶
GetArgSizeFromTypeName ...
func GetFormattedName ¶
func GetFormattedName(arg *CXArgument, includePkg bool) string
GetFormattedName reads `arg.DereferenceOperations` and builds a string that depicts how an argument is being accessed. Example outputs: "foo[3]", "**bar", "foo.bar[0]". If `includePkg` is `true`, the argument name will include the package name that contains it, such as in "pkg.foo".
func GetFormattedType ¶
func GetFormattedType(arg *CXArgument) string
GetFormattedType builds a string with the CXGO type representation of `arg`.
func GetOpCodeCount ¶
func GetOpCodeCount() int
GetOpCodeCount returns an op code that is available for usage on the CX standard library.
func GetPrintableValue ¶
func GetPrintableValue(fp int, arg *CXArgument) string
GetPrintableValue ...
func GetSerializedDataSize ¶
GetSerializedDataSize returns the size of the data segment of a serialized CX program.
func GetSerializedMemoryOffset ¶
GetSerializedMemoryOffset returns the offset at which the memory of a serialized CX program starts.
func GetSerializedStackSize ¶
GetSerializedStackSize returns the stack size of a serialized CX program starts.
func IsPointer ¶
func IsPointer(sym *CXArgument) bool
IsPointer checks if `sym` is a candidate for the garbage collector to check. For example, if `sym` is a slice, the garbage collector will need to check if the slice on the heap needs to be relocated.
func IsValidSliceIndex ¶
IsValidSliceIndex ...
func MakeDefaultValue ¶
MakeDefaultValue Used only for native types
func Mark ¶
Mark marks the object located at `heapOffset` as alive and sets the object's referencing address to `heapOffset`.
func MarkObjectsTree ¶
MarkObjectsTree traverses and marks a possible tree of heap objects (slices of slices, slices of pointers, etc.).
func MergeTransactionAndBlockchain ¶
MergeTransactionAndBlockchain merges the serialized CX programs that represent a transaction and the program state stored on the blockchain.
func NewWriteObj ¶
NewWriteObj refactoring reuse in WriteObject and WriteObjectRetOff
func Op ¶
func Op(code int, name string, handler OpcodeHandler, inputs []*CXArgument, outputs []*CXArgument)
Op ...
func ParseArgsForCX ¶
func ParseArgsForCX(args []string, alsoSubdirs bool) (cxArgs []string, sourceCode []*os.File, fileNames []string)
ParseArgsForCX parses the arguments and returns:
- []arguments
- []file pointers open files
- []sting filenames
func QueryArgument ¶
func QueryArgument(fn *CXFunction, expr *CXExpression, argOffsetB []byte, affOffset *int)
QueryArgument ...
func QueryCaller ¶
func QueryCaller(fn *CXFunction, expr *CXExpression, callerOffsetB []byte, affOffset *int)
QueryCaller ...
func QueryExpressions ¶
func QueryExpressions(fn *CXFunction, expr *CXExpression, exprOffsetB []byte, affOffset *int)
QueryExpressions ...
func QueryFunction ¶
func QueryFunction(fn *CXFunction, expr *CXExpression, fnOffsetB []byte, affOffset *int)
QueryFunction ...
func QueryProgram ¶
func QueryProgram(fn *CXFunction, expr *CXExpression, prgrmOffsetB []byte, affOffset *int)
QueryProgram ...
func QueryStructure ¶
func QueryStructure(fn *CXFunction, expr *CXExpression, strctOffsetB []byte, affOffset *int)
QueryStructure ...
func ReadSliceBytes ¶
func ReadSliceBytes(fp int, inp *CXArgument, dataType int) []byte
ReadSliceBytes ...
func ReadStringFromObject ¶
ReadStringFromObject reads the string located at offset `off`.
func RegisterPackage ¶
func RegisterPackage(pkgName string)
RegisterPackage registers a package on the CX standard library. This does not create a `CXPackage` structure, it only tells the CX runtime that `pkgName` will exist by the time a CX program is run.
func ResizeMemory ¶
ResizeMemory ...
func SignatureStringOfFunction ¶
func SignatureStringOfFunction(pkg *CXPackage, f *CXFunction) string
SignatureStringOfFunction returns the signature string of a function.
func SignatureStringOfStruct ¶
SignatureStringOfStruct returns the signature string of a struct.
func SliceAppendResize ¶
func SliceAppendResize(fp int, out *CXArgument, inp *CXArgument, sizeofElement int) int32
SliceAppendResize prepares a slice to be able to store a new object of length `sizeofElement`. It checks if the slice needs to be relocated in memory, and if it is needed it relocates it and a new `outputSliceOffset` is calculated for the new slice.
func SliceAppendWrite ¶
SliceAppendWrite writes `object` to a slice that is guaranteed to be able to hold `object`, i.e. it had to be checked by `SliceAppendResize` first in case it needed to be resized.
func SliceAppendWriteByte ¶
SliceAppendWriteByte writes `object` to a slice that is guaranteed to be able to hold `object`, i.e. it had to be checked by `SliceAppendResize` first in case it needed to be resized.
func SliceCopy ¶
func SliceCopy(fp int, outputSliceOffset int32, inp *CXArgument, count int32, sizeofElement int)
SliceCopy copies the contents from the slice located at `inputSliceOffset` to the slice located at `outputSliceOffset`.
func SliceCopyEx ¶
SliceCopyEx does the logic required by `SliceCopy`. It is separated because some other functions might have access to the offsets of the slices, but not the `CXArgument`s.
func SliceInsert ¶
func SliceInsert(fp int, out *CXArgument, inp *CXArgument, index int32, object []byte) int
SliceInsert ...
func SliceRemove ¶
func SliceRemove(fp int, out *CXArgument, inp *CXArgument, index int32, sizeofElement int32) int
SliceRemove ...
func SliceResize ¶
func SliceResize(fp int, out *CXArgument, inp *CXArgument, count int32, sizeofElement int) int
SliceResize ...
func SliceResizeEx ¶
SliceResizeEx does the logic required by `SliceResize`. It is separated because some other functions might have access to the offsets of the slices, but not the `CXArgument`s.
func WriteString ¶
func WriteString(fp int, str string, out *CXArgument)
WriteString writes the string `str` on memory, starting at byte number `fp`.
func WriteStringObj ¶
WriteStringObj writes `str` to the heap as an object and returns its absolute offset.
func WriteToSlice ¶
WriteToSlice is used to create slices in the backend, i.e. not by calling `append` in a CX program, but rather by the CX code itself. This function is used by affordances, serialization and to store OS input arguments.
Types ¶
type CXArgument ¶
type CXArgument struct { Lengths []int // declared lengths at compile time DereferenceOperations []int // offset by array index, struct field, pointer DeclarationSpecifiers []int // used to determine finalSize Indexes []*CXArgument Fields []*CXArgument // strct.fld1.fld2().fld3 Inputs []*CXArgument // Input parameters in case `CXArgument` is of type TYPE_FUNC Outputs []*CXArgument // Output parameters in case `CXArgument` is of type TYPE_FUNC Name string FileName string Type int Size int // size of underlaying basic type TotalSize int // total size of an array, performance reasons Offset int IndirectionLevels int DereferenceLevels int PassBy int // pass by value or reference FileLine int CustomType *CXStruct Package *CXPackage IsSlice bool IsArray bool IsArrayFirst bool // and then dereference IsPointer bool IsReference bool IsDereferenceFirst bool // and then array IsStruct bool IsRest bool // pkg.var <- var is rest IsLocalDeclaration bool IsShortDeclaration bool IsInnerReference bool // for example: &slice[0] or &struct.field PreviouslyDeclared bool DoesEscape bool }
The CXArgument struct contains a variable, i.e. a combination of a name and a type.
It is used when declaring variables and in function parameters.
func GetAssignmentElement ¶
func GetAssignmentElement(arg *CXArgument) *CXArgument
GetAssignmentElement ...
func In ¶
func In(params ...*CXArgument) []*CXArgument
In Returns a slice of arguments from an argument list
func MakeArgument ¶
func MakeArgument(name string, fileName string, fileLine int) *CXArgument
MakeArgument ...
func MakeField ¶
func MakeField(name string, typ int, fileName string, fileLine int) *CXArgument
MakeField ...
func MakeGlobal ¶
func MakeGlobal(name string, typ int, fileName string, fileLine int) *CXArgument
MakeGlobal ...
func Out ¶
func Out(params ...*CXArgument) []*CXArgument
Out Returns a slice of arguments from an argument list
func ParamEx ¶
func ParamEx(paramData ParamData) *CXArgument
ParamEx Helper function for creating parameters for standard library operators. The current standard library only uses basic types and slices. If more options are needed, modify this function
func Pointer ¶
func Pointer(arg *CXArgument) *CXArgument
Pointer takes an already defined `CXArgument` and turns it into a pointer.
func Slice ¶
func Slice(typCode int) *CXArgument
Slice Helper function for creating parameters for standard library operators. The current standard library only uses basic types and slices. If more options are needed, modify this function
func Struct ¶
func Struct(pkgName, strctName, argName string) *CXArgument
Struct helper for creating a struct parameter. It creates a `CXArgument` named `argName`, that represents a structure instane of `strctName`, from package `pkgName`.
func (*CXArgument) AddInput ¶
func (arg *CXArgument) AddInput(inp *CXArgument) *CXArgument
AddInput adds input parameters to `arg` in case arg is of type `TYPE_FUNC`.
func (*CXArgument) AddOutput ¶
func (arg *CXArgument) AddOutput(out *CXArgument) *CXArgument
AddOutput adds output parameters to `arg` in case arg is of type `TYPE_FUNC`.
func (*CXArgument) AddPackage ¶
func (arg *CXArgument) AddPackage(pkg *CXPackage) *CXArgument
AddPackage assigns CX package `pkg` to CX argument `arg`.
type CXCall ¶
type CXCall struct { Operator *CXFunction // What CX function will be called when running this CXCall in the runtime Line int // What line in the CX function is currently being executed FramePointer int // Where in the stack is this function call's local variables stored }
CXCall ...
type CXConstant ¶
type CXConstant struct { // native constants. only used for pre-packaged constants (e.g. math package's PI) // these fields are used to feed WritePrimary Value []byte Type int }
CXConstant ...
type CXExpression ¶
type CXExpression struct { // Contents Inputs []*CXArgument Outputs []*CXArgument Label string Operator *CXFunction Function *CXFunction Package *CXPackage // debugging FileName string FileLine int // used for jmp statements ThenLines int ElseLines int // 1 = start new scope; -1 = end scope; 0 = just regular expression ScopeOperation int IsMethodCall bool IsStructLiteral bool IsArrayLiteral bool IsUndType bool IsBreak bool IsContinue bool }
CXExpression is used represent a CX expression.
All statements in CX are expressions, including for loops and other control flow.
func MakeExpression ¶
func MakeExpression(op *CXFunction, fileName string, fileLine int) *CXExpression
MakeExpression ...
func (*CXExpression) AddInput ¶
func (expr *CXExpression) AddInput(param *CXArgument) *CXExpression
AddInput ...
func (*CXExpression) AddLabel ¶
func (expr *CXExpression) AddLabel(lbl string) *CXExpression
AddLabel ...
func (*CXExpression) AddOutput ¶
func (expr *CXExpression) AddOutput(param *CXArgument) *CXExpression
AddOutput ...
func (*CXExpression) GetInputs ¶
func (expr *CXExpression) GetInputs() ([]*CXArgument, error)
GetInputs ...
type CXFunction ¶
type CXFunction struct { // Metadata Name string // Name of the function Package *CXPackage // The package it's a member of IsNative bool // True if the function is native to CX, e.g. int32.add() OpCode int // opcode if IsNative = true // Contents Inputs []*CXArgument // Input parameters to the function Outputs []*CXArgument // Output parameters from the function Expressions []*CXExpression // Expressions, including control flow statements, in the function Length int // number of expressions, pre-computed for performance Size int // automatic memory size // Debugging FileName string FileLine int // Used by the GC ListOfPointers []*CXArgument // Root pointers for the GC algorithm // Used by the REPL and parser CurrentExpression *CXExpression }
CXFunction is used to represent a CX function.
func MakeFunction ¶
func MakeFunction(name string, fileName string, fileLine int) *CXFunction
MakeFunction creates an empty function.
Later, parameters and contents can be added.
func MakeNativeFunction ¶
func MakeNativeFunction(opCode int, inputs []*CXArgument, outputs []*CXArgument) *CXFunction
MakeNativeFunction creates a native function such as i32.add()
func (*CXFunction) AddExpression ¶
func (fn *CXFunction) AddExpression(expr *CXExpression) *CXFunction
AddExpression ...
func (*CXFunction) AddInput ¶
func (fn *CXFunction) AddInput(param *CXArgument) *CXFunction
AddInput ...
func (*CXFunction) AddOutput ¶
func (fn *CXFunction) AddOutput(param *CXArgument) *CXFunction
AddOutput ...
func (*CXFunction) GetCurrentExpression ¶
func (fn *CXFunction) GetCurrentExpression() (*CXExpression, error)
GetCurrentExpression ...
func (*CXFunction) GetExpressionByLabel ¶
func (fn *CXFunction) GetExpressionByLabel(lbl string) (*CXExpression, error)
GetExpressionByLabel ...
func (*CXFunction) GetExpressionByLine ¶
func (fn *CXFunction) GetExpressionByLine(line int) (*CXExpression, error)
GetExpressionByLine ...
func (*CXFunction) GetExpressions ¶
func (fn *CXFunction) GetExpressions() ([]*CXExpression, error)
GetExpressions ...
func (*CXFunction) RemoveExpression ¶
func (fn *CXFunction) RemoveExpression(line int)
RemoveExpression ...
func (*CXFunction) RemoveOutput ¶
func (fn *CXFunction) RemoveOutput(outName string)
RemoveOutput ...
func (*CXFunction) SelectExpression ¶
func (fn *CXFunction) SelectExpression(line int) (*CXExpression, error)
SelectExpression ...
type CXPackage ¶
type CXPackage struct { // Metadata Name string // Name of the package // Contents Imports []*CXPackage // imported packages Functions []*CXFunction // declared functions in this package Structs []*CXStruct // declared structs in this package Globals []*CXArgument // declared global variables in this package // Used by the REPL and parser CurrentFunction *CXFunction CurrentStruct *CXStruct }
CXPackage is used to represent a CX package.
func MakePackage ¶
MakePackage creates a new empty CXPackage.
It can be filled in later with imports, structs, globals and functions.
func (*CXPackage) AddFunction ¶
func (pkg *CXPackage) AddFunction(fn *CXFunction) *CXPackage
AddFunction ...
func (*CXPackage) AddGlobal ¶
func (pkg *CXPackage) AddGlobal(def *CXArgument) *CXPackage
AddGlobal ...
func (*CXPackage) GetCurrentFunction ¶
func (pkg *CXPackage) GetCurrentFunction() (*CXFunction, error)
GetCurrentFunction ...
func (*CXPackage) GetCurrentStruct ¶
GetCurrentStruct ...
func (*CXPackage) GetFunction ¶
func (pkg *CXPackage) GetFunction(fnName string) (*CXFunction, error)
GetFunction ...
func (*CXPackage) GetFunctions ¶
func (pkg *CXPackage) GetFunctions() ([]*CXFunction, error)
GetFunctions ...
func (*CXPackage) GetGlobal ¶
func (pkg *CXPackage) GetGlobal(defName string) (*CXArgument, error)
GetGlobal ...
func (*CXPackage) GetMethod ¶
func (pkg *CXPackage) GetMethod(fnName string, receiverType string) (*CXFunction, error)
GetMethod ...
func (*CXPackage) RemoveFunction ¶
RemoveFunction ...
func (*CXPackage) RemoveGlobal ¶
RemoveGlobal ...
func (*CXPackage) RemoveImport ¶
RemoveImport ...
func (*CXPackage) RemoveStruct ¶
RemoveStruct ...
func (*CXPackage) SelectExpression ¶
func (pkg *CXPackage) SelectExpression(line int) (*CXExpression, error)
SelectExpression ...
func (*CXPackage) SelectFunction ¶
func (pkg *CXPackage) SelectFunction(name string) (*CXFunction, error)
SelectFunction ...
type CXProgram ¶
type CXProgram struct { // Metadata Path string // Path to the CX project in the filesystem // Contents Packages []*CXPackage // Packages in a CX program // Runtime information Inputs []*CXArgument // OS input arguments Outputs []*CXArgument // outputs to the OS Memory []byte // Used when running the program StackSize int // This field stores the size of a CX program's stack HeapSize int // This field stores the size of a CX program's heap HeapStartsAt int // Offset at which the heap starts in a CX program's memory StackPointer int // At what byte the current stack frame is CallStack []CXCall // Collection of function calls CallCounter int // What function call is the currently being executed in the CallStack HeapPointer int // At what offset a CX program can insert a new object to the heap Terminated bool // Utility field for the runtime. Indicates if a CX program has already finished or not. BCPackageCount int // In case of a CX chain, how many packages of this program are part of blockchain code. Version string // CX version used to build this CX program. // Used by the REPL and parser CurrentPackage *CXPackage // Represents the currently active package in the REPL or when parsing a CX file. }
CXProgram is used to represent a full CX program.
It is the root data structure for the declarations of all functions, variables and data structures.
var PROGRAM *CXProgram
global reference to our program
func Deserialize ¶
Deserialize deserializes a serialized CX program back to its golang struct representation.
func GetProgram ¶
GetProgram returns the CX program assigned to global variable `PROGRAM`. This function is mainly used for CX chains.
func MergePrograms ¶
MergePrograms merges `prgrm1` and `prgrm2`, favoring `prgrm1` (if both have a package with the same name, `prgrm1`'s is used). Note: `prgrm2` is permanently altered.
func (*CXProgram) AddPackage ¶
AddPackage ...
func (*CXProgram) Callback ¶
func (prgrm *CXProgram) Callback(fn *CXFunction, inputs [][]byte) (outputs [][]byte)
Callback ...
func (*CXProgram) EnsureHeap ¶
func (prgrm *CXProgram) EnsureHeap()
EnsureHeap ensures that `prgrm` has `minHeapSize()` bytes allocated after the data segment.
func (*CXProgram) GetCurrentExpression ¶
func (prgrm *CXProgram) GetCurrentExpression() (*CXExpression, error)
GetCurrentExpression ...
func (*CXProgram) GetCurrentFunction ¶
func (prgrm *CXProgram) GetCurrentFunction() (*CXFunction, error)
GetCurrentFunction ...
func (*CXProgram) GetCurrentPackage ¶
GetCurrentPackage ...
func (*CXProgram) GetCurrentStruct ¶
GetCurrentStruct ...
func (*CXProgram) GetExpr ¶
func (prgrm *CXProgram) GetExpr() *CXExpression
GetExpr returns the current CXExpression
func (*CXProgram) GetFramePointer ¶
GetFramePointer returns the current frame pointer
func (*CXProgram) GetFunction ¶
func (prgrm *CXProgram) GetFunction(fnName string, pkgName string) (*CXFunction, error)
GetFunction ...
func (*CXProgram) GetGlobal ¶
func (prgrm *CXProgram) GetGlobal(name string) (*CXArgument, error)
GetGlobal ...
func (*CXProgram) GetPackage ¶
GetPackage ...
func (*CXProgram) PrintAllObjects ¶
func (prgrm *CXProgram) PrintAllObjects()
PrintAllObjects prints all objects in a program
func (*CXProgram) PrintProgram ¶
func (prgrm *CXProgram) PrintProgram()
PrintProgram prints the abstract syntax tree of a CX program in a human-readable format.
func (*CXProgram) RemovePackage ¶
RemovePackage ...
func (*CXProgram) RunCompiled ¶
RunCompiled ...
func (*CXProgram) SelectExpression ¶
func (prgrm *CXProgram) SelectExpression(line int) (*CXExpression, error)
SelectExpression ...
func (*CXProgram) SelectFunction ¶
func (prgrm *CXProgram) SelectFunction(name string) (*CXFunction, error)
SelectFunction ...
func (*CXProgram) SelectPackage ¶
SelectPackage ...
func (*CXProgram) SelectProgram ¶
SelectProgram sets `PROGRAM` to the the receiver `prgrm`. This is a utility function used mainly by CX chains. `PROGRAM` is used in multiple parts of the CX runtime as a convenience; instead of having to pass around a parameter of type CXProgram, the CX program currently being run is accessible through `PROGRAM`.
func (*CXProgram) SelectStruct ¶
SelectStruct ...
type CXStruct ¶
type CXStruct struct { // Metadata Name string // Name of the struct Package *CXPackage // The package this struct belongs to Size int // The size in memory that this struct takes. // Contents Fields []*CXArgument // The fields of the struct }
CXStruct is used to represent a CX struct.
func (*CXStruct) GetField ¶
func (strct *CXStruct) GetField(name string) (*CXArgument, error)
GetField ...
func (*CXStruct) GetFields ¶
func (strct *CXStruct) GetFields() ([]*CXArgument, error)
GetFields ...
Source Files ¶
- config.go
- constcodes.go
- cxargument.go
- cxexpression.go
- cxfunction.go
- cxpackage.go
- cxprogram.go
- cxstruct.go
- execute.go
- file.go
- garbage_collector.go
- makers.go
- op.go
- op_aff.go
- op_bool.go
- op_f32.go
- op_f64.go
- op_http.go
- op_i16.go
- op_i32.go
- op_i64.go
- op_i8.go
- op_misc.go
- op_str.go
- op_testing.go
- op_ui16.go
- op_ui32.go
- op_ui64.go
- op_ui8.go
- op_und.go
- opcodes.go
- serialize.go
- structs.go
- utilities.go