cxcore

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2021 License: BSD-1-Clause Imports: 20 Imported by: 5

Documentation

Index

Constants

View Source
const (
	PARAM_DEFAULT = iota
	PARAM_SLICE
	PARAM_STRUCT
)
View Source
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
)
View Source
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
)
View Source
const (
	SCOPE_NEW = iota + 1 // 1
	SCOPE_REM            // 2
)

create a new scope or return to the previous scope

View Source
const (
	PASSBY_VALUE = iota
	PASSBY_REFERENCE
)

what to write

View Source
const (
	DEREF_ARRAY   = iota // 0
	DEREF_FIELD          // 1
	DEREF_POINTER        // 2
	DEREF_DEREF          // 3
	DEREF_SLICE          // 4
)
View Source
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
)
View Source
const (
	MEM_STACK = iota
	MEM_HEAP
	MEM_DATA
)

memory locations

View Source
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

View Source
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

View Source
const CALLSTACK_SIZE = 1000
View Source
const DBG_GOLANG_STACK_TRACE = true
View Source
const FORWARDING_ADDRESS_SIZE = 4
View Source
const HEAP_EXHAUSTED_ERROR = "heap exhausted"
View Source
const I32_SIZE = 4
View Source
const I64_SIZE = 8
View Source
const ID_FN = "identity"
View Source
const INIT_FN = "initDef"
View Source
const LABEL_PREFIX = "*lbl"
View Source
const LITERAL_PLACEHOLDER = "*lit"

Used in `PrintProgram` to represent literals (`CXArgument`s with no name).

View Source
const LOCAL_PREFIX = "*tmp"
View Source
const MAIN_FUNC = "main"
View Source
const MAIN_PKG = "main"
View Source
const MARK_SIZE = 1
View Source
const MAX_INT32 = int(MAX_UINT32 >> 1)
View Source
const MAX_UINT32 = ^uint32(0)
View Source
const MIN_INT32 = -MAX_INT32 - 1
View Source
const MIN_UINT32 = 0
View Source
const NON_ASSIGN_PREFIX = "nonAssign"
View Source
const NULL_HEAP_ADDRESS = 0
View Source
const NULL_HEAP_ADDRESS_OFFSET = 4
View Source
const OBJECT_GC_HEADER_SIZE = 5
View Source
const OBJECT_HEADER_SIZE = 9
View Source
const OBJECT_SIZE = 4
View Source
const OS_ARGS = "Args"
View Source
const OS_PKG = "os"
View Source
const SLICE_HEADER_SIZE = 8
View Source
const STACK_OVERFLOW_ERROR = "stack overflow"
View Source
const STDLIB_PKG = "stdlib"
View Source
const STR_HEADER_SIZE = 4
View Source
const STR_SIZE = 4
View Source
const SYS_INIT_FUNC = "*init"
View Source
const TYPE_POINTER_SIZE = 4

Variables

View Source
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

View Source
var (
	// OpNames ...
	OpNames = map[int]string{}

	// OpCodes ...
	OpCodes = map[string]int{}

	// Natives ...
	Natives = map[int]*CXFunction{}
)
View Source
var AAFF = Param(TYPE_AFF)

AAFF Default aff parameter

View Source
var ABOOL = Param(TYPE_BOOL)

ABOOL Default bool parameter

View Source
var AF32 = Param(TYPE_F32)

AF32 Default f32 parameter

View Source
var AF64 = Param(TYPE_F64)

AF64 Default f64 parameter

View Source
var AI16 = Param(TYPE_I16)

AI16 Default i16 parameter

View Source
var AI32 = Param(TYPE_I32)

AI32 Default i32 parameter

View Source
var AI64 = Param(TYPE_I64)

AI64 Default i64 parameter

AI8 Default i8 parameter

View Source
var ASTR = Param(TYPE_STR)

ASTR Default str parameter

View Source
var AUI16 = Param(TYPE_UI16)

AUI16 Default ui16 parameter

View Source
var AUI32 = Param(TYPE_UI32)

AUI32 Default ui32 parameter

View Source
var AUI64 = Param(TYPE_UI64)

AUI64 Default ui64 parameter

View Source
var AUI8 = Param(TYPE_UI8)

AUI8 Default ui8 parameter

AUND Default und parameter

View Source
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",
}
View Source
var BINPATH = CXPATH + "bin/" // TODO @evanlinjin: Not used.
View Source
var CXPATH = os.Getenv("CXPATH") + "/"
View Source
var CorePackages = []string{

	"al", "gl", "glfw", "time", "http", "os", "explorer", "aff", "gltext", "cx", "json", "regexp", "cipher",
}

CorePackages ...

View Source
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",
}
View Source
var FoundCompileErrors bool
View Source
var (
	HeapOffset int
)

Var

View Source
var INIT_HEAP_SIZE = 2097152 // 2 Mb
View Source
var InREPL bool = false
View Source
var MAX_HEAP_FREE_RATIO float32 = 0.7
View Source
var MAX_HEAP_SIZE = 67108864 // 64 Mb
View Source
var MIN_HEAP_FREE_RATIO float32 = 0.4
View Source
var PKGPATH = CXPATH + "pkg/" // TODO @evanlinjin: Not used.
View Source
var SRCPATH = CXPATH + "src/"
View Source
var STACK_SIZE = 1048576 // 1 Mb
View Source
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,
}
View Source
var TypeCounter int
View Source
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

func AddConstCode(code int, name string, typ int, value []byte)

AddConstCode ...

func AllocateSeq

func AllocateSeq(size int) (offset int)

AllocateSeq allocates memory in the heap

func AssertFailed

func AssertFailed() bool

AssertFailed ...

func CXCreateFile

func CXCreateFile(filename string) (*os.File, error)

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

func CXMkdirAll(path string, perm os.FileMode) error

CXMkdirAll ... TODO @evanlinjin: This should be in a module named 'util'.

func CXOpenFile

func CXOpenFile(filename string) (*os.File, error)

CXOpenFile ... TODO @evanlinjin: This should be in a module named 'util'.

func CXReadFile

func CXReadFile(path string) ([]byte, error)

CXReadFile ... TODO @evanlinjin: This should be in a module named 'util'.

func CXRemoveFile

func CXRemoveFile(path string) error

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

func CXStatFile(path string) (os.FileInfo, error)

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 CheckArithmeticOp

func CheckArithmeticOp(expr *CXExpression) bool

CheckArithmeticOp ...

func CompilationError

func CompilationError(currentFile string, lineNo int) string

CompilationError is a helper function that concatenates the `currentFile` and `lineNo` data to a error header and returns the full error string.

func ConstI32

func ConstI32(code int, name string, value int32)

ConstI32 ...

func CopyProgramState

func CopyProgramState(sPrgrm1, sPrgrm2 *[]byte)

CopyProgramState copies the program state from `prgrm1` to `prgrm2`.

func Debug

func Debug(args ...interface{})

Debug ...

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

func DisplaceReferences(prgrm *CXProgram, off int, numPkgs int)

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 ErrorHeader

func ErrorHeader(currentFile string, lineNo int) string

ErrorHeader ...

func ErrorString

func ErrorString(code int) string

ErrorString ...

func EscapeAnalysis

func EscapeAnalysis(fp int, inpOffset, outOffset int, arg *CXArgument)

EscapeAnalysis ...

func ExprOpName

func ExprOpName(expr *CXExpression) string

ExprOpName ...

func ExtractBlockchainProgram

func ExtractBlockchainProgram(sPrgrm1, sPrgrm2 []byte) []byte

ExtractBlockchainProgram extracts the blockchain program from `sPrgrm2` by removing the contents of `sPrgrm1` from `sPrgrm2`. TxnPrgrm = sPrgrm2 - sPrgrm1.

func ExtractTransactionProgram

func ExtractTransactionProgram(sPrgrm1, sPrgrm2 []byte) []byte

ExtractTransactionProgram extracts the transaction code (serialized) from a full CX program.

func FromBool

func FromBool(in bool) []byte

FromBool ...

func FromF32

func FromF32(in float32) []byte

FromF32 ...

func FromF64

func FromF64(in float64) []byte

FromF64 ...

func FromI16

func FromI16(in int16) []byte

FromI16 ...

func FromI32

func FromI32(in int32) []byte

FromI32 ...

func FromI64

func FromI64(in int64) []byte

FromI64 ...

func FromI8

func FromI8(in int8) []byte

FromI8 ...

func FromStr

func FromStr(in string) []byte

FromStr ...

func FromUI16

func FromUI16(in uint16) []byte

FromUI16 ...

func FromUI32

func FromUI32(in uint32) []byte

FromUI32 ...

func FromUI64

func FromUI64(in uint64) []byte

FromUI64 ...

func FromUI8

func FromUI8(in uint8) []byte

FromUI8 ...

func GetArgSize

func GetArgSize(typ int) int

GetArgSize ...

func GetArgSizeFromTypeName

func GetArgSizeFromTypeName(typeName string) int

GetArgSizeFromTypeName ...

func GetDerefSize

func GetDerefSize(arg *CXArgument) int

GetDerefSize ...

func GetFinalOffset

func GetFinalOffset(fp int, arg *CXArgument) int

GetFinalOffset ...

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 GetInferActions

func GetInferActions(inp *CXArgument, fp int) []string

GetInferActions ...

func GetObjectHeader

func GetObjectHeader(offset int32) []byte

GetObjectHeader ...

func GetOpCodeCount

func GetOpCodeCount() int

GetOpCodeCount returns an op code that is available for usage on the CX standard library.

func GetPointerOffset

func GetPointerOffset(pointer int32) int32

GetPointerOffset ...

func GetPrintableValue

func GetPrintableValue(fp int, arg *CXArgument) string

GetPrintableValue ...

func GetSerializedDataSize

func GetSerializedDataSize(sPrgrm []byte) int

GetSerializedDataSize returns the size of the data segment of a serialized CX program.

func GetSerializedMemoryOffset

func GetSerializedMemoryOffset(sPrgrm []byte) int

GetSerializedMemoryOffset returns the offset at which the memory of a serialized CX program starts.

func GetSerializedStackSize

func GetSerializedStackSize(sPrgrm []byte) int

GetSerializedStackSize returns the stack size of a serialized CX program starts.

func GetSize

func GetSize(arg *CXArgument) int

GetSize ...

func GetSlice

func GetSlice(offset int32, sizeofElement int) []byte

GetSlice ...

func GetSliceData

func GetSliceData(offset int32, sizeofElement int) []byte

GetSliceData ...

func GetSliceHeader

func GetSliceHeader(offset int32) []byte

GetSliceHeader ...

func GetSliceLen

func GetSliceLen(offset int32) int32

GetSliceLen ...

func GetSliceOffset

func GetSliceOffset(fp int, arg *CXArgument) int32

GetSliceOffset ...

func GetStrOffset

func GetStrOffset(fp int, arg *CXArgument) int

GetStrOffset ...

func IsCorePackage

func IsCorePackage(ident string) bool

IsCorePackage ...

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 IsTempVar

func IsTempVar(name string) bool

IsTempVar ...

func IsValidSliceIndex

func IsValidSliceIndex(offset int, index int, sizeofElement int) bool

IsValidSliceIndex ...

func MakeDefaultValue

func MakeDefaultValue(typName string) []byte

MakeDefaultValue Used only for native types

func MakeElementID

func MakeElementID() uuid.UUID

MakeElementID ...

func MakeGenSym

func MakeGenSym(name string) string

MakeGenSym ...

func MakeIdentityOpName

func MakeIdentityOpName(typeName string) string

MakeIdentityOpName ...

func MakeValue

func MakeValue(value string) *[]byte

MakeValue ...

func Mark

func Mark(prgrm *CXProgram, heapOffset int32)

Mark marks the object located at `heapOffset` as alive and sets the object's referencing address to `heapOffset`.

func MarkAndCompact

func MarkAndCompact(prgrm *CXProgram)

MarkAndCompact ...

func MarkObjectsTree

func MarkObjectsTree(prgrm *CXProgram, offset int, baseType int, declSpecs []int)

MarkObjectsTree traverses and marks a possible tree of heap objects (slices of slices, slices of pointers, etc.).

func MergeTransactionAndBlockchain

func MergeTransactionAndBlockchain(sPrgrm1, sPrgrm2 []byte) []byte

MergeTransactionAndBlockchain merges the serialized CX programs that represent a transaction and the program state stored on the blockchain.

func NewWriteObj

func NewWriteObj(obj []byte) int

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 ReadArray

func ReadArray(fp int, inp *CXArgument, dataType int) interface{}

ReadArray ...

func ReadBool

func ReadBool(fp int, inp *CXArgument) (out bool)

ReadBool ...

func ReadData

func ReadData(fp int, inp *CXArgument, dataType int) interface{}

ReadData ...

func ReadF32

func ReadF32(fp int, inp *CXArgument) float32

ReadF32 ...

func ReadF64

func ReadF64(fp int, inp *CXArgument) float64

ReadF64 ...

func ReadI16

func ReadI16(fp int, inp *CXArgument) int16

ReadI16 ...

func ReadI32

func ReadI32(fp int, inp *CXArgument) int32

ReadI32 ...

func ReadI64

func ReadI64(fp int, inp *CXArgument) int64

ReadI64 ...

func ReadI8

func ReadI8(fp int, inp *CXArgument) int8

ReadI8 ...

func ReadMemory

func ReadMemory(offset int, arg *CXArgument) []byte

ReadMemory ...

func ReadObject

func ReadObject(fp int, inp *CXArgument, dataType int) interface{}

ReadObject ...

func ReadSlice

func ReadSlice(fp int, inp *CXArgument, dataType int) interface{}

ReadSlice ...

func ReadSliceBytes

func ReadSliceBytes(fp int, inp *CXArgument, dataType int) []byte

ReadSliceBytes ...

func ReadStr

func ReadStr(fp int, inp *CXArgument) (out string)

ReadStr ...

func ReadStringFromObject

func ReadStringFromObject(off int32) string

ReadStringFromObject reads the string located at offset `off`.

func ReadUI16

func ReadUI16(fp int, inp *CXArgument) uint16

ReadUI16 ...

func ReadUI32

func ReadUI32(fp int, inp *CXArgument) uint32

ReadUI32 ...

func ReadUI64

func ReadUI64(fp int, inp *CXArgument) uint64

ReadUI64 ...

func ReadUI8

func ReadUI8(fp int, inp *CXArgument) uint8

ReadUI8 ...

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

func ResizeMemory(prgrm *CXProgram, newMemSize int, isExpand bool)

ResizeMemory ...

func RuntimeError

func RuntimeError()

RuntimeError ...

func Serialize

func Serialize(prgrm *CXProgram, split int) (byts []byte)

Serialize ...

func SignatureStringOfFunction

func SignatureStringOfFunction(pkg *CXPackage, f *CXFunction) string

SignatureStringOfFunction returns the signature string of a function.

func SignatureStringOfStruct

func SignatureStringOfStruct(s *CXStruct) string

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

func SliceAppendWrite(outputSliceOffset int32, object []byte, index int32)

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

func SliceAppendWriteByte(outputSliceOffset int32, object []byte, index int32)

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

func SliceCopyEx(outputSliceOffset int32, inputSliceOffset int32, count int32, sizeofElement int)

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

func SliceResizeEx(outputSliceOffset int32, count int32, sizeofElement int) int

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 WriteBool

func WriteBool(offset int, b bool)

WriteBool ...

func WriteF32

func WriteF32(offset int, f float32)

WriteF32 ...

func WriteF64

func WriteF64(offset int, f float64)

WriteF64 ...

func WriteI16

func WriteI16(offset int, v int16)

WriteI16 ...

func WriteI32

func WriteI32(offset int, v int32)

WriteI32 ...

func WriteI64

func WriteI64(offset int, v int64)

WriteI64 ...

func WriteI8

func WriteI8(offset int, v int8)

WriteI8 ...

func WriteMemF32

func WriteMemF32(mem []byte, offset int, f float32)

WriteMemF32 ...

func WriteMemF64

func WriteMemF64(mem []byte, offset int, f float64)

WriteMemF64 ...

func WriteMemI16

func WriteMemI16(mem []byte, offset int, v int16)

WriteMemI16 ...

func WriteMemI32

func WriteMemI32(mem []byte, offset int, v int32)

WriteMemI32 ...

func WriteMemI64

func WriteMemI64(mem []byte, offset int, v int64)

WriteMemI64 ...

func WriteMemI8

func WriteMemI8(mem []byte, offset int, v int8)

WriteMemI8 ...

func WriteMemUI16

func WriteMemUI16(mem []byte, offset int, v uint16)

WriteMemUI16 ...

func WriteMemUI32

func WriteMemUI32(mem []byte, offset int, v uint32)

WriteMemUI32 ...

func WriteMemUI64

func WriteMemUI64(mem []byte, offset int, v uint64)

WriteMemUI64 ...

func WriteMemUI8

func WriteMemUI8(mem []byte, offset int, v uint8)

WriteMemUI8 ...

func WriteMemory

func WriteMemory(offset int, byts []byte)

WriteMemory ...

func WriteObject

func WriteObject(out1Offset int, obj []byte)

WriteObject ...

func WriteObjectRetOff

func WriteObjectRetOff(obj []byte) int

WriteObjectRetOff ...

func WriteString

func WriteString(fp int, str string, out *CXArgument)

WriteString writes the string `str` on memory, starting at byte number `fp`.

func WriteStringObj

func WriteStringObj(str string) int

WriteStringObj writes `str` to the heap as an object and returns its absolute offset.

func WriteToSlice

func WriteToSlice(off int, inp []byte) int

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.

func WriteUI16

func WriteUI16(offset int, v uint16)

WriteUI16 ...

func WriteUI32

func WriteUI32(offset int, v uint32)

WriteUI32 ...

func WriteUI64

func WriteUI64(offset int, v uint64)

WriteUI64 ...

func WriteUI8

func WriteUI8(offset int, v uint8)

WriteUI8 ...

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 Param

func Param(typCode int) *CXArgument

Param ...

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`.

func (*CXArgument) AddType

func (arg *CXArgument) AddType(typ string) *CXArgument

AddType ...

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 ...

func MakeCall

func MakeCall(op *CXFunction) CXCall

MakeCall ...

func MakeCallStack

func MakeCallStack(size int) []CXCall

MakeCallStack ...

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 ...

func (*CXExpression) RemoveInput

func (expr *CXExpression) RemoveInput()

RemoveInput ...

func (*CXExpression) RemoveOutput

func (expr *CXExpression) RemoveOutput()

RemoveOutput ...

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) RemoveInput

func (fn *CXFunction) RemoveInput(inpName string)

RemoveInput ...

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

func MakePackage(name string) *CXPackage

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) AddImport

func (pkg *CXPackage) AddImport(imp *CXPackage) *CXPackage

AddImport ...

func (*CXPackage) AddStruct

func (pkg *CXPackage) AddStruct(strct *CXStruct) *CXPackage

AddStruct ...

func (*CXPackage) GetCurrentFunction

func (pkg *CXPackage) GetCurrentFunction() (*CXFunction, error)

GetCurrentFunction ...

func (*CXPackage) GetCurrentStruct

func (pkg *CXPackage) GetCurrentStruct() (*CXStruct, error)

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) GetImport

func (pkg *CXPackage) GetImport(impName string) (*CXPackage, error)

GetImport ...

func (*CXPackage) GetMethod

func (pkg *CXPackage) GetMethod(fnName string, receiverType string) (*CXFunction, error)

GetMethod ...

func (*CXPackage) GetStruct

func (pkg *CXPackage) GetStruct(strctName string) (*CXStruct, error)

GetStruct ...

func (*CXPackage) RemoveFunction

func (pkg *CXPackage) RemoveFunction(fnName string)

RemoveFunction ...

func (*CXPackage) RemoveGlobal

func (pkg *CXPackage) RemoveGlobal(defName string)

RemoveGlobal ...

func (*CXPackage) RemoveImport

func (pkg *CXPackage) RemoveImport(impName string)

RemoveImport ...

func (*CXPackage) RemoveStruct

func (pkg *CXPackage) RemoveStruct(strctName string)

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 ...

func (*CXPackage) SelectStruct

func (pkg *CXPackage) SelectStruct(name string) (*CXStruct, error)

SelectStruct ...

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

func Deserialize(byts []byte) (prgrm *CXProgram)

Deserialize deserializes a serialized CX program back to its golang struct representation.

func GetProgram

func GetProgram() (*CXProgram, error)

GetProgram returns the CX program assigned to global variable `PROGRAM`. This function is mainly used for CX chains.

func MakeProgram

func MakeProgram() *CXProgram

MakeProgram ...

func MergePrograms

func MergePrograms(prgrm1, prgrm2 *CXProgram) *CXProgram

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

func (prgrm *CXProgram) AddPackage(mod *CXPackage) *CXProgram

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) GetCall

func (prgrm *CXProgram) GetCall() *CXCall

GetCall returns the current CXCall

func (*CXProgram) GetCurrentExpression

func (prgrm *CXProgram) GetCurrentExpression() (*CXExpression, error)

GetCurrentExpression ...

func (*CXProgram) GetCurrentFunction

func (prgrm *CXProgram) GetCurrentFunction() (*CXFunction, error)

GetCurrentFunction ...

func (*CXProgram) GetCurrentPackage

func (prgrm *CXProgram) GetCurrentPackage() (*CXPackage, error)

GetCurrentPackage ...

func (*CXProgram) GetCurrentStruct

func (prgrm *CXProgram) GetCurrentStruct() (*CXStruct, error)

GetCurrentStruct ...

func (*CXProgram) GetExpr

func (prgrm *CXProgram) GetExpr() *CXExpression

GetExpr returns the current CXExpression

func (*CXProgram) GetFramePointer

func (prgrm *CXProgram) GetFramePointer() int

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) GetOpCode

func (prgrm *CXProgram) GetOpCode() int

GetOpCode returns the current OpCode

func (*CXProgram) GetPackage

func (prgrm *CXProgram) GetPackage(modName string) (*CXPackage, error)

GetPackage ...

func (*CXProgram) GetStruct

func (prgrm *CXProgram) GetStruct(strctName string, modName string) (*CXStruct, error)

GetStruct ...

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) PrintStack

func (prgrm *CXProgram) PrintStack()

PrintStack ...

func (*CXProgram) RemovePackage

func (prgrm *CXProgram) RemovePackage(modName string)

RemovePackage ...

func (*CXProgram) Run

func (prgrm *CXProgram) Run(untilEnd bool, nCalls *int, untilCall int) error

Run ...

func (*CXProgram) RunCompiled

func (prgrm *CXProgram) RunCompiled(nCalls int, args []string) error

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

func (prgrm *CXProgram) SelectPackage(name string) (*CXPackage, error)

SelectPackage ...

func (*CXProgram) SelectProgram

func (prgrm *CXProgram) SelectProgram() (*CXProgram, error)

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

func (prgrm *CXProgram) SelectStruct(name string) (*CXStruct, error)

SelectStruct ...

func (*CXProgram) ToCall

func (prgrm *CXProgram) ToCall() *CXExpression

ToCall ...

func (*CXProgram) UnRun

func (prgrm *CXProgram) UnRun(nCalls int)

UnRun ...

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 MakeStruct

func MakeStruct(name string) *CXStruct

MakeStruct ...

func (*CXStruct) AddField

func (strct *CXStruct) AddField(fld *CXArgument) *CXStruct

AddField ...

func (*CXStruct) GetField

func (strct *CXStruct) GetField(name string) (*CXArgument, error)

GetField ...

func (*CXStruct) GetFields

func (strct *CXStruct) GetFields() ([]*CXArgument, error)

GetFields ...

func (*CXStruct) RemoveField

func (strct *CXStruct) RemoveField(fldName string)

RemoveField ...

type OpcodeHandler

type OpcodeHandler func(prgrm *CXProgram)

OpcodeHandler ...

type ParamData

type ParamData struct {
	// contains filtered or unexported fields
}

ParamData ...

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL