diff --git a/cx/cxprogram.go b/cx/cxprogram.go index dd9e84597..f57ff6665 100644 --- a/cx/cxprogram.go +++ b/cx/cxprogram.go @@ -26,18 +26,18 @@ type CXProgram struct { 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. - Version string // CX version used to build this CX program. + 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. + 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. @@ -423,7 +423,7 @@ func (prgrm *CXProgram) PrintAllObjects() { op := prgrm.CallStack[c].Operator for _, ptr := range op.ListOfPointers { - heapOffset := mustDeserializeI32(prgrm.Memory[fp+ptr.Offset : fp+ptr.Offset+TYPE_POINTER_SIZE]) + heapOffset := Deserialize_i32(prgrm.Memory[fp+ptr.Offset : fp+ptr.Offset+TYPE_POINTER_SIZE]) var byts []byte diff --git a/cx/fix_deserialize.go b/cx/fix_deserialize.go index 33ff694a4..1f8b50242 100644 --- a/cx/fix_deserialize.go +++ b/cx/fix_deserialize.go @@ -1,13 +1,14 @@ package cxcore -import( +import ( "math" + "github.com/skycoin/skycoin/src/cipher/encoder" ) //TODO: replace with unsafe -func mustDeserializeBool(b []byte) bool { +func DeserializeBool(b []byte) bool { switch b[0] { case 0: return false @@ -19,49 +20,49 @@ func mustDeserializeBool(b []byte) bool { } } -func mustDeserializeI8(b []byte) int8 { +func Deserialize_i8(b []byte) int8 { return int8(b[0]) } -func mustDeserializeI16(b []byte) int16 { +func Deserialize_i16(b []byte) int16 { return int16(b[0]) | int16(b[1])<<8 } -func mustDeserializeI32(b []byte) int32 { +func Deserialize_i32(b []byte) int32 { return int32(b[0]) | int32(b[1])<<8 | int32(b[2])<<16 | int32(b[3])<<24 } -func mustDeserializeI64(b []byte) int64 { +func Deserialize_i64(b []byte) int64 { return int64(b[0]) | int64(b[1])<<8 | int64(b[2])<<16 | int64(b[3])<<24 | int64(b[4])<<32 | int64(b[5])<<40 | int64(b[6])<<48 | int64(b[7])<<56 } -func mustDeserializeUI8(b []byte) uint8 { +func Deserialize_ui8(b []byte) uint8 { return uint8(b[0]) } -func mustDeserializeUI16(b []byte) uint16 { +func Deserialize_ui16(b []byte) uint16 { return uint16(b[0]) | uint16(b[1])<<8 } -func mustDeserializeUI32(b []byte) uint32 { +func Deserialize_ui32(b []byte) uint32 { return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 } -func mustDeserializeUI64(b []byte) uint64 { +func Deserialize_ui64(b []byte) uint64 { return uint64(b[0]) | uint64(b[1])<<8 | uint64(b[2])<<16 | uint64(b[3])<<24 | uint64(b[4])<<32 | uint64(b[5])<<40 | uint64(b[6])<<48 | uint64(b[7])<<56 } -func mustDeserializeF32(b []byte) float32 { - return math.Float32frombits(mustDeserializeUI32(b)) +func Deserialize_f32(b []byte) float32 { + return math.Float32frombits(Deserialize_ui32(b)) } -func mustDeserializeF64(b []byte) float64 { - return math.Float64frombits(mustDeserializeUI64(b)) +func Deserialize_f64(b []byte) float64 { + return math.Float64frombits(Deserialize_ui64(b)) } -func mustDeserializeRaw(byts []byte, item interface{}) { +func DeserializeRaw(byts []byte, item interface{}) { _, err := encoder.DeserializeRaw(byts, item) if err != nil { panic(err) diff --git a/cx/fix_mem2.go b/cx/fix_mem2.go index d2c06e578..f3b504fab 100644 --- a/cx/fix_mem2.go +++ b/cx/fix_mem2.go @@ -34,7 +34,7 @@ func CalculateDereferences(arg *CXArgument, finalOffset *int, fp int) { byts = PROGRAM.Memory[*finalOffset : *finalOffset+TYPE_POINTER_SIZE] - offset = mustDeserializeI32(byts) + offset = Deserialize_i32(byts) *finalOffset = int(offset) @@ -72,7 +72,7 @@ func CalculateDereferences(arg *CXArgument, finalOffset *int, fp int) { byts = PROGRAM.Memory[*finalOffset : *finalOffset+TYPE_POINTER_SIZE] - offset = mustDeserializeI32(byts) + offset = Deserialize_i32(byts) *finalOffset = int(offset) } diff --git a/cx/fix_mem4.go b/cx/fix_mem4.go index cdd41ad42..08d6ae121 100644 --- a/cx/fix_mem4.go +++ b/cx/fix_mem4.go @@ -1,14 +1,12 @@ package cxcore -import() - /* ./cxfx/op_opengl.go:437: obj := ReadMemory(GetFinalOffset(fp, inp1), inp1) ./cx/op_http.go:326: // reqByts := ReadMemory(GetFinalOffset(fp, inp1), inp1) ./cx/op_http.go:493: byts1 := ReadMemory(GetFinalOffset(fp, inp1), inp1) ./cx/fix_read3.go:110: array := ReadMemory(offset, inp) ./cx/fix_read3.go:119: array := ReadMemory(offset, inp) -./cx/fix_read3.go:128: out = mustDeserializeBool(ReadMemory(offset, inp)) +./cx/fix_read3.go:128: out = DeserializeBool(ReadMemory(offset, inp)) ./cx/op_aff.go:101: return ReadMemory(GetFinalOffset( ./cx/op_und.go:548: obj := ReadMemory(GetFinalOffset(fp, inp2), inp2) ./cx/op_und.go:588: obj := ReadMemory(GetFinalOffset(fp, inp3), inp3) @@ -16,16 +14,16 @@ import() ./cx/execute.go:424: mem := ReadMemory(GetFinalOffset(newFP, out), out) ./cx/op_testing.go:22: byts1 = ReadMemory(GetFinalOffset(fp, inp1), inp1) ./cx/op_testing.go:23: byts2 = ReadMemory(GetFinalOffset(fp, inp2), inp2) -./cx/fix_read.go:11: return mustDeserializeI8(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:16: return mustDeserializeI16(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:21: return mustDeserializeI32(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:26: return mustDeserializeI64(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:31: return mustDeserializeUI8(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:36: return mustDeserializeUI16(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:41: return mustDeserializeUI32(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:46: return mustDeserializeUI64(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:51: return mustDeserializeF32(ReadMemory(GetFinalOffset(fp, inp), inp)) -./cx/fix_read.go:56: return mustDeserializeF64(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:11: return Deserialize_i8(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:16: return Deserialize_i16(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:21: return Deserialize_i32(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:26: return Deserialize_i64(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:31: return Deserialize_ui8(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:36: return Deserialize_ui16(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:41: return Deserialize_ui32(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:46: return Deserialize_ui64(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:51: return Deserialize_f32(ReadMemory(GetFinalOffset(fp, inp), inp)) +./cx/fix_read.go:56: return Deserialize_f64(ReadMemory(GetFinalOffset(fp, inp), inp)) ./cx/op_misc.go:9: byts := ReadMemory(inpOffset, arg) ./cx/op_misc.go:41: WriteMemory(out1Offset, ReadMemory(inp1Offset, inp1)) ./cx/op.go:183:// ReadMemory ... diff --git a/cx/fix_read.go b/cx/fix_read.go index df5476169..cf1043a44 100644 --- a/cx/fix_read.go +++ b/cx/fix_read.go @@ -8,50 +8,50 @@ import() // ReadI8 ... func ReadI8(fp int, inp *CXArgument) int8 { - return mustDeserializeI8(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_i8(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadI16 ... func ReadI16(fp int, inp *CXArgument) int16 { - return mustDeserializeI16(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_i16(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadI32 ... func ReadI32(fp int, inp *CXArgument) int32 { - return mustDeserializeI32(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_i32(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadI64 ... func ReadI64(fp int, inp *CXArgument) int64 { - return mustDeserializeI64(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_i64(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadUI8 ... func ReadUI8(fp int, inp *CXArgument) uint8 { - return mustDeserializeUI8(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_ui8(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadUI16 ... func ReadUI16(fp int, inp *CXArgument) uint16 { - return mustDeserializeUI16(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_ui16(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadUI32 ... func ReadUI32(fp int, inp *CXArgument) uint32 { - return mustDeserializeUI32(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_ui32(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadUI64 ... func ReadUI64(fp int, inp *CXArgument) uint64 { - return mustDeserializeUI64(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_ui64(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadF32 ... func ReadF32(fp int, inp *CXArgument) float32 { - return mustDeserializeF32(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_f32(ReadMemory(GetFinalOffset(fp, inp), inp)) } // ReadF64 ... func ReadF64(fp int, inp *CXArgument) float64 { - return mustDeserializeF64(ReadMemory(GetFinalOffset(fp, inp), inp)) + return Deserialize_f64(ReadMemory(GetFinalOffset(fp, inp), inp)) } \ No newline at end of file diff --git a/cx/fix_read2.go b/cx/fix_read2.go index 5bdafd319..32455453b 100644 --- a/cx/fix_read2.go +++ b/cx/fix_read2.go @@ -1,7 +1,5 @@ package cxcore -import() - // ReadData ... func readDataI8(bytes []byte) (out []int8) { @@ -9,7 +7,7 @@ func readDataI8(bytes []byte) (out []int8) { if count > 0 { out = make([]int8, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeI8(bytes[i:]) + out[i] = Deserialize_i8(bytes[i:]) } } return @@ -20,7 +18,7 @@ func readDataUI8(bytes []byte) (out []uint8) { if count > 0 { out = make([]uint8, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeUI8(bytes[i:]) + out[i] = Deserialize_ui8(bytes[i:]) } } return @@ -31,7 +29,7 @@ func readDataI16(bytes []byte) (out []int16) { if count > 0 { out = make([]int16, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeI16(bytes[i*2:]) + out[i] = Deserialize_i16(bytes[i*2:]) } } return @@ -42,7 +40,7 @@ func readDataUI16(bytes []byte) (out []uint16) { if count > 0 { out = make([]uint16, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeUI16(bytes[i*2:]) + out[i] = Deserialize_ui16(bytes[i*2:]) } } return @@ -53,7 +51,7 @@ func readDataI32(bytes []byte) (out []int32) { if count > 0 { out = make([]int32, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeI32(bytes[i*4:]) + out[i] = Deserialize_i32(bytes[i*4:]) } } return @@ -64,7 +62,7 @@ func readDataUI32(bytes []byte) (out []uint32) { if count > 0 { out = make([]uint32, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeUI32(bytes[i*4:]) + out[i] = Deserialize_ui32(bytes[i*4:]) } } return @@ -75,7 +73,7 @@ func readDataI64(bytes []byte) (out []int64) { if count > 0 { out = make([]int64, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeI64(bytes[i*8:]) + out[i] = Deserialize_i64(bytes[i*8:]) } } return @@ -86,7 +84,7 @@ func readDataUI64(bytes []byte) (out []uint64) { if count > 0 { out = make([]uint64, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeUI64(bytes[i*8:]) + out[i] = Deserialize_ui64(bytes[i*8:]) } } return @@ -97,7 +95,7 @@ func readDataF32(bytes []byte) (out []float32) { if count > 0 { out = make([]float32, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeF32(bytes[i*4:]) + out[i] = Deserialize_f32(bytes[i*4:]) } } return @@ -108,10 +106,8 @@ func readDataF64(bytes []byte) (out []float64) { if count > 0 { out = make([]float64, count) for i := 0; i < count; i++ { - out[i] = mustDeserializeF64(bytes[i*8:]) + out[i] = Deserialize_f64(bytes[i*8:]) } } return } - - diff --git a/cx/fix_read3.go b/cx/fix_read3.go index e8efe6322..4f445f835 100644 --- a/cx/fix_read3.go +++ b/cx/fix_read3.go @@ -176,7 +176,7 @@ func ReadSliceBytes(fp int, inp *CXArgument, dataType int) []byte { // ReadBool ... func ReadBool(fp int, inp *CXArgument) (out bool) { offset := GetFinalOffset(fp, inp) - out = mustDeserializeBool(ReadMemory(offset, inp)) + out = DeserializeBool(ReadMemory(offset, inp)) return } @@ -188,7 +188,7 @@ func ReadStr(fp int, inp *CXArgument) (out string) { // Then it's a literal. offset = int32(off) } else { - offset = mustDeserializeI32(PROGRAM.Memory[off : off+TYPE_POINTER_SIZE]) + offset = Deserialize_i32(PROGRAM.Memory[off : off+TYPE_POINTER_SIZE]) } if offset == 0 { @@ -200,11 +200,11 @@ func ReadStr(fp int, inp *CXArgument) (out string) { // We need to check if the string lives on the data segment or on the // heap to know if we need to take into consideration the object header's size. if int(offset) > PROGRAM.HeapStartsAt { - size := mustDeserializeI32(PROGRAM.Memory[offset+OBJECT_HEADER_SIZE : offset+OBJECT_HEADER_SIZE+STR_HEADER_SIZE]) - mustDeserializeRaw(PROGRAM.Memory[offset+OBJECT_HEADER_SIZE:offset+OBJECT_HEADER_SIZE+STR_HEADER_SIZE+size], &out) + size := Deserialize_i32(PROGRAM.Memory[offset+OBJECT_HEADER_SIZE : offset+OBJECT_HEADER_SIZE+STR_HEADER_SIZE]) + DeserializeRaw(PROGRAM.Memory[offset+OBJECT_HEADER_SIZE:offset+OBJECT_HEADER_SIZE+STR_HEADER_SIZE+size], &out) } else { - size := mustDeserializeI32(PROGRAM.Memory[offset : offset+STR_HEADER_SIZE]) - mustDeserializeRaw(PROGRAM.Memory[offset:offset+STR_HEADER_SIZE+size], &out) + size := Deserialize_i32(PROGRAM.Memory[offset : offset+STR_HEADER_SIZE]) + DeserializeRaw(PROGRAM.Memory[offset:offset+STR_HEADER_SIZE+size], &out) } return out diff --git a/cx/garbage_collector.go b/cx/garbage_collector.go index 51180623c..2d57cb0b7 100644 --- a/cx/garbage_collector.go +++ b/cx/garbage_collector.go @@ -103,10 +103,10 @@ func MarkAndCompact(prgrm *CXProgram) { // Relocation of live objects. for c := prgrm.HeapStartsAt + NULL_HEAP_ADDRESS_OFFSET; c < prgrm.HeapStartsAt+prgrm.HeapPointer; { - objSize := mustDeserializeI32(prgrm.Memory[c+MARK_SIZE+FORWARDING_ADDRESS_SIZE : c+MARK_SIZE+FORWARDING_ADDRESS_SIZE+OBJECT_SIZE]) + objSize := Deserialize_i32(prgrm.Memory[c+MARK_SIZE+FORWARDING_ADDRESS_SIZE : c+MARK_SIZE+FORWARDING_ADDRESS_SIZE+OBJECT_SIZE]) if prgrm.Memory[c] == 1 { - forwardingAddress := mustDeserializeI32(prgrm.Memory[c+MARK_SIZE : c+MARK_SIZE+FORWARDING_ADDRESS_SIZE]) + forwardingAddress := Deserialize_i32(prgrm.Memory[c+MARK_SIZE : c+MARK_SIZE+FORWARDING_ADDRESS_SIZE]) // We update the pointers that are pointing to the just moved object. updatePointers(prgrm, forwardingAddress, int32(prgrm.HeapStartsAt)+faddr) @@ -136,7 +136,7 @@ func updateDisplaceReference(prgrm *CXProgram, updated *map[int]int, atOffset, p // Extracting the address being pointed by element at `atOffset` sCurrAddr := prgrm.Memory[atOffset : atOffset+TYPE_POINTER_SIZE] - dsCurrAddr := mustDeserializeI32(sCurrAddr) + dsCurrAddr := Deserialize_i32(sCurrAddr) // Adding `plusOff` to the address and updating the address pointed by // element at `atOffset`. @@ -152,7 +152,7 @@ func doDisplaceReferences(prgrm *CXProgram, updated *map[int]int, atOffset int, var numDeclSpecs = len(declSpecs) // Getting the offset to the object in the heap. - heapOffset := mustDeserializeI32(prgrm.Memory[atOffset : atOffset+TYPE_POINTER_SIZE]) + heapOffset := Deserialize_i32(prgrm.Memory[atOffset : atOffset+TYPE_POINTER_SIZE]) // The whole displacement process is needed because the objects on the heap were // displaced by additional data segment bytes. These additional bytes need to be @@ -183,12 +183,12 @@ func doDisplaceReferences(prgrm *CXProgram, updated *map[int]int, atOffset int, (numDeclSpecs == 1 && baseType == TYPE_STR) { // Then we need to iterate each of the slice objects // and check if we need to update their address. - sliceLen := mustDeserializeI32(GetSliceHeader(heapOffset + int32(condPlusOff))[4:8]) + sliceLen := Deserialize_i32(GetSliceHeader(heapOffset + int32(condPlusOff))[4:8]) offsetToElements := OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE for c := int32(0); c < sliceLen; c++ { - cHeapOffset := mustDeserializeI32(prgrm.Memory[int(heapOffset)+condPlusOff+offsetToElements+int(c*TYPE_POINTER_SIZE) : int(heapOffset)+condPlusOff+offsetToElements+int(c*TYPE_POINTER_SIZE)+4]) + cHeapOffset := Deserialize_i32(prgrm.Memory[int(heapOffset)+condPlusOff+offsetToElements+int(c*TYPE_POINTER_SIZE) : int(heapOffset)+condPlusOff+offsetToElements+int(c*TYPE_POINTER_SIZE)+4]) if int(cHeapOffset) <= prgrm.HeapStartsAt+condPlusOff { // Then it's pointing to null or data segment @@ -252,7 +252,7 @@ func MarkObjectsTree(prgrm *CXProgram, offset int, baseType int, declSpecs []int var numDeclSpecs = len(declSpecs) // Getting the offset to the object in the heap - heapOffset := mustDeserializeI32(prgrm.Memory[offset : offset+TYPE_POINTER_SIZE]) + heapOffset := Deserialize_i32(prgrm.Memory[offset : offset+TYPE_POINTER_SIZE]) // Then it's a pointer to an object in the stack and it should not be marked. if heapOffset <= int32(prgrm.HeapStartsAt) { @@ -274,11 +274,11 @@ func MarkObjectsTree(prgrm *CXProgram, offset int, baseType int, declSpecs []int declSpecs[1] == DECL_POINTER)) || (numDeclSpecs == 1 && baseType == TYPE_STR) { // Then we need to iterate each of the slice objects and mark them as alive - sliceLen := mustDeserializeI32(GetSliceHeader(heapOffset)[4:8]) + sliceLen := Deserialize_i32(GetSliceHeader(heapOffset)[4:8]) for c := int32(0); c < sliceLen; c++ { offsetToElements := OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE - cHeapOffset := mustDeserializeI32(prgrm.Memory[int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE) : int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE)+4]) + cHeapOffset := Deserialize_i32(prgrm.Memory[int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE) : int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE)+4]) if cHeapOffset <= int32(prgrm.HeapStartsAt) { // Then it's pointing to null or data segment @@ -302,7 +302,7 @@ func updatePointerTree(prgrm *CXProgram, atOffset int, oldAddr, newAddr int32, b var numDeclSpecs = len(declSpecs) // Getting the offset to the object in the heap - heapOffset := mustDeserializeI32(prgrm.Memory[atOffset : atOffset+TYPE_POINTER_SIZE]) + heapOffset := Deserialize_i32(prgrm.Memory[atOffset : atOffset+TYPE_POINTER_SIZE]) if heapOffset == oldAddr { // Updating the root pointer. @@ -323,12 +323,12 @@ func updatePointerTree(prgrm *CXProgram, atOffset int, oldAddr, newAddr int32, b (numDeclSpecs == 1 && baseType == TYPE_STR) { // Then we need to iterate each of the slice objects // and check if we need to update their address. - sliceLen := mustDeserializeI32(GetSliceHeader(heapOffset)[4:8]) + sliceLen := Deserialize_i32(GetSliceHeader(heapOffset)[4:8]) offsetToElements := OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE for c := int32(0); c < sliceLen; c++ { - cHeapOffset := mustDeserializeI32(prgrm.Memory[int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE) : int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE)+4]) + cHeapOffset := Deserialize_i32(prgrm.Memory[int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE) : int(heapOffset)+offsetToElements+int(c*TYPE_POINTER_SIZE)+4]) if cHeapOffset <= int32(prgrm.HeapStartsAt) { // Then it's pointing to null or data segment diff --git a/cx/mem1.go b/cx/mem1.go index e439370b1..f864c8891 100644 --- a/cx/mem1.go +++ b/cx/mem1.go @@ -12,7 +12,7 @@ func GetStrOffset(fp int, arg *CXArgument) int { strOffset := GetFinalOffset(fp, arg) if arg.Name != "" { // then it's not a literal - offset := mustDeserializeI32(PROGRAM.Memory[strOffset : strOffset+TYPE_POINTER_SIZE]) + offset := Deserialize_i32(PROGRAM.Memory[strOffset : strOffset+TYPE_POINTER_SIZE]) strOffset = int(offset) } return strOffset diff --git a/cx/op_aff.go b/cx/op_aff.go index c33b534da..138e93456 100644 --- a/cx/op_aff.go +++ b/cx/op_aff.go @@ -26,17 +26,17 @@ var ofMessages = map[string]string{ func GetInferActions(inp *CXArgument, fp int) []string { inpOffset := GetFinalOffset(fp, inp) - off := mustDeserializeI32(PROGRAM.Memory[inpOffset : inpOffset+TYPE_POINTER_SIZE]) + off := Deserialize_i32(PROGRAM.Memory[inpOffset : inpOffset+TYPE_POINTER_SIZE]) - l := mustDeserializeI32(GetSliceHeader(GetSliceOffset(fp, inp))[4:8]) + l := Deserialize_i32(GetSliceHeader(GetSliceOffset(fp, inp))[4:8]) result := make([]string, l) // for c := int(l); c > 0; c-- { for c := 0; c < int(l); c++ { - // elof := mustDeserializeI32(PROGRAM.Memory[int(off) + OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE + (c - 1) * TYPE_POINTER_SIZE : int(off) + OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE + c * STR_HEADER_SIZE]) - elOff := mustDeserializeI32(PROGRAM.Memory[int(off)+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE+c*TYPE_POINTER_SIZE : int(off)+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE+(c+1)*STR_HEADER_SIZE]) - // size := mustDeserializeI32(PROGRAM.Memory[elOff : elOff+STR_HEADER_SIZE]) + // elof := Deserialize_i32(PROGRAM.Memory[int(off) + OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE + (c - 1) * TYPE_POINTER_SIZE : int(off) + OBJECT_HEADER_SIZE + SLICE_HEADER_SIZE + c * STR_HEADER_SIZE]) + elOff := Deserialize_i32(PROGRAM.Memory[int(off)+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE+c*TYPE_POINTER_SIZE : int(off)+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE+(c+1)*STR_HEADER_SIZE]) + // size := Deserialize_i32(PROGRAM.Memory[elOff : elOff+STR_HEADER_SIZE]) // var res string // _, err := encoder.DeserializeRaw(PROGRAM.Memory[elOff:elOff+STR_HEADER_SIZE+size], &res) // if err != nil { diff --git a/cx/op_misc.go b/cx/op_misc.go index 1c50a6817..705202a06 100644 --- a/cx/op_misc.go +++ b/cx/op_misc.go @@ -54,7 +54,7 @@ func opJmp(expr *CXExpression, fp int) { inp1Offset := GetFinalOffset(fp, inp1) predicateB := PROGRAM.Memory[inp1Offset : inp1Offset+GetSize(inp1)] - predicate = mustDeserializeBool(predicateB) + predicate = DeserializeBool(predicateB) if predicate { call.Line = call.Line + expr.ThenLines diff --git a/cx/serialize.go b/cx/serialize.go index 766bf38ef..14f623027 100644 --- a/cx/serialize.go +++ b/cx/serialize.go @@ -838,10 +838,10 @@ func opDeserialize(expr *CXExpression, fp int) { inpOffset := GetFinalOffset(fp, inp) - off := mustDeserializeI32(PROGRAM.Memory[inpOffset : inpOffset+TYPE_POINTER_SIZE]) + off := Deserialize_i32(PROGRAM.Memory[inpOffset : inpOffset+TYPE_POINTER_SIZE]) _l := PROGRAM.Memory[off+OBJECT_HEADER_SIZE : off+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE] - l := mustDeserializeI32(_l[4:8]) + l := Deserialize_i32(_l[4:8]) Deserialize(PROGRAM.Memory[off+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE : off+OBJECT_HEADER_SIZE+SLICE_HEADER_SIZE+l]) // BUG : should be l * elt.TotalSize ? } @@ -852,7 +852,7 @@ func dsName(off int32, size int32, s *sAll) string { } var name string - mustDeserializeRaw(s.Names[off:off+size], &name) + DeserializeRaw(s.Names[off:off+size], &name) return name } @@ -1184,15 +1184,15 @@ func Deserialize(byts []byte) (prgrm *CXProgram) { var s sAll - mustDeserializeRaw(byts[:idxSize], &s.Index) - mustDeserializeRaw(byts[s.Index.ProgramOffset:s.Index.CallsOffset], &s.Program) - mustDeserializeRaw(byts[s.Index.CallsOffset:s.Index.PackagesOffset], &s.Calls) - mustDeserializeRaw(byts[s.Index.PackagesOffset:s.Index.StructsOffset], &s.Packages) - mustDeserializeRaw(byts[s.Index.StructsOffset:s.Index.FunctionsOffset], &s.Structs) - mustDeserializeRaw(byts[s.Index.FunctionsOffset:s.Index.ExpressionsOffset], &s.Functions) - mustDeserializeRaw(byts[s.Index.ExpressionsOffset:s.Index.ArgumentsOffset], &s.Expressions) - mustDeserializeRaw(byts[s.Index.ArgumentsOffset:s.Index.IntegersOffset], &s.Arguments) - mustDeserializeRaw(byts[s.Index.IntegersOffset:s.Index.NamesOffset], &s.Integers) + DeserializeRaw(byts[:idxSize], &s.Index) + DeserializeRaw(byts[s.Index.ProgramOffset:s.Index.CallsOffset], &s.Program) + DeserializeRaw(byts[s.Index.CallsOffset:s.Index.PackagesOffset], &s.Calls) + DeserializeRaw(byts[s.Index.PackagesOffset:s.Index.StructsOffset], &s.Packages) + DeserializeRaw(byts[s.Index.StructsOffset:s.Index.FunctionsOffset], &s.Structs) + DeserializeRaw(byts[s.Index.FunctionsOffset:s.Index.ExpressionsOffset], &s.Functions) + DeserializeRaw(byts[s.Index.ExpressionsOffset:s.Index.ArgumentsOffset], &s.Expressions) + DeserializeRaw(byts[s.Index.ArgumentsOffset:s.Index.IntegersOffset], &s.Arguments) + DeserializeRaw(byts[s.Index.IntegersOffset:s.Index.NamesOffset], &s.Integers) s.Names = byts[s.Index.NamesOffset:s.Index.MemoryOffset] s.Memory = byts[s.Index.MemoryOffset:] @@ -1210,14 +1210,14 @@ func CopyProgramState(sPrgrm1, sPrgrm2 *[]byte) { var index1 sIndex var index2 sIndex - mustDeserializeRaw((*sPrgrm1)[:idxSize], &index1) - mustDeserializeRaw((*sPrgrm2)[:idxSize], &index2) + DeserializeRaw((*sPrgrm1)[:idxSize], &index1) + DeserializeRaw((*sPrgrm2)[:idxSize], &index2) var prgrm1Info sProgram - mustDeserializeRaw((*sPrgrm1)[index1.ProgramOffset:index1.CallsOffset], &prgrm1Info) + DeserializeRaw((*sPrgrm1)[index1.ProgramOffset:index1.CallsOffset], &prgrm1Info) var prgrm2Info sProgram - mustDeserializeRaw((*sPrgrm2)[index2.ProgramOffset:index2.CallsOffset], &prgrm2Info) + DeserializeRaw((*sPrgrm2)[index2.ProgramOffset:index2.CallsOffset], &prgrm2Info) // the stack segment should be 0 for prgrm1, but just in case var prgrmState []byte @@ -1245,14 +1245,14 @@ func ExtractBlockchainProgram(sPrgrm1, sPrgrm2 []byte) []byte { var index1 sIndex var index2 sIndex - mustDeserializeRaw(sPrgrm1[:idxSize], &index1) - mustDeserializeRaw(sPrgrm2[:idxSize], &index2) + DeserializeRaw(sPrgrm1[:idxSize], &index1) + DeserializeRaw(sPrgrm2[:idxSize], &index2) var prgrm1Info sProgram - mustDeserializeRaw(sPrgrm1[index1.ProgramOffset:index1.CallsOffset], &prgrm1Info) + DeserializeRaw(sPrgrm1[index1.ProgramOffset:index1.CallsOffset], &prgrm1Info) var prgrm2Info sProgram - mustDeserializeRaw(sPrgrm2[index2.ProgramOffset:index2.CallsOffset], &prgrm2Info) + DeserializeRaw(sPrgrm2[index2.ProgramOffset:index2.CallsOffset], &prgrm2Info) var extracted []byte // must match the index from sPrgrm1 @@ -1260,7 +1260,7 @@ func ExtractBlockchainProgram(sPrgrm1, sPrgrm2 []byte) []byte { // Program var sPrgrm sProgram - mustDeserializeRaw(sPrgrm1[index1.ProgramOffset:index1.CallsOffset], &sPrgrm) + DeserializeRaw(sPrgrm1[index1.ProgramOffset:index1.CallsOffset], &sPrgrm) // We need the heap pointer calculated after running the program, which is // present in `sPrgrm2`. sPrgrm.HeapPointer = prgrm2Info.HeapPointer @@ -1305,14 +1305,14 @@ func ExtractTransactionProgram(sPrgrm1, sPrgrm2 []byte) []byte { var index1 sIndex var index2 sIndex - mustDeserializeRaw(sPrgrm1[:idxSize], &index1) - mustDeserializeRaw(sPrgrm2[:idxSize], &index2) + DeserializeRaw(sPrgrm1[:idxSize], &index1) + DeserializeRaw(sPrgrm2[:idxSize], &index2) var prgrm1Info sProgram - mustDeserializeRaw(sPrgrm1[index1.ProgramOffset:index1.CallsOffset], &prgrm1Info) + DeserializeRaw(sPrgrm1[index1.ProgramOffset:index1.CallsOffset], &prgrm1Info) var prgrm2Info sProgram - mustDeserializeRaw(sPrgrm2[index2.ProgramOffset:index2.CallsOffset], &prgrm2Info) + DeserializeRaw(sPrgrm2[index2.ProgramOffset:index2.CallsOffset], &prgrm2Info) var extracted []byte // must match the index from sPrgrm2 @@ -1345,7 +1345,7 @@ func ExtractTransactionProgram(sPrgrm1, sPrgrm2 []byte) []byte { func GetSerializedMemoryOffset(sPrgrm []byte) int { idxSize := encoder.Size(sIndex{}) var index sIndex - mustDeserializeRaw(sPrgrm[:idxSize], &index) + DeserializeRaw(sPrgrm[:idxSize], &index) return int(index.MemoryOffset) } @@ -1353,10 +1353,10 @@ func GetSerializedMemoryOffset(sPrgrm []byte) int { func GetSerializedStackSize(sPrgrm []byte) int { idxSize := encoder.Size(sIndex{}) var index sIndex - mustDeserializeRaw(sPrgrm[:idxSize], &index) + DeserializeRaw(sPrgrm[:idxSize], &index) var prgrmInfo sProgram - mustDeserializeRaw(sPrgrm[index.ProgramOffset:index.CallsOffset], &prgrmInfo) + DeserializeRaw(sPrgrm[index.ProgramOffset:index.CallsOffset], &prgrmInfo) return int(prgrmInfo.StackSize) } @@ -1365,10 +1365,10 @@ func GetSerializedStackSize(sPrgrm []byte) int { func GetSerializedDataSize(sPrgrm []byte) int { idxSize := encoder.Size(sIndex{}) var index sIndex - mustDeserializeRaw(sPrgrm[:idxSize], &index) + DeserializeRaw(sPrgrm[:idxSize], &index) var prgrmInfo sProgram - mustDeserializeRaw(sPrgrm[index.ProgramOffset:index.CallsOffset], &prgrmInfo) + DeserializeRaw(sPrgrm[index.ProgramOffset:index.CallsOffset], &prgrmInfo) return int(prgrmInfo.HeapStartsAt - prgrmInfo.StackSize) } diff --git a/cx/utilities.go b/cx/utilities.go index 7421e08b3..dcac7a8e9 100644 --- a/cx/utilities.go +++ b/cx/utilities.go @@ -154,7 +154,7 @@ func getFormattedDerefs(arg *CXArgument, includePkg bool) string { idxValue := "" if idx.Offset > PROGRAM.StackSize { // Then it's a literal. - idxI32 := mustDeserializeI32(PROGRAM.Memory[idx.Offset : idx.Offset+TYPE_POINTER_SIZE]) + idxI32 := Deserialize_i32(PROGRAM.Memory[idx.Offset : idx.Offset+TYPE_POINTER_SIZE]) idxValue = fmt.Sprintf("%d", idxI32) } else { // Then let's just print the variable name. @@ -622,7 +622,7 @@ func IsValidSliceIndex(offset int, index int, sizeofElement int) bool { // GetPointerOffset ... func GetPointerOffset(pointer int32) int32 { - return mustDeserializeI32(PROGRAM.Memory[pointer : pointer+TYPE_POINTER_SIZE]) + return Deserialize_i32(PROGRAM.Memory[pointer : pointer+TYPE_POINTER_SIZE]) } // GetSliceOffset ... @@ -648,7 +648,7 @@ func GetSliceHeader(offset int32) []byte { // GetSliceLen ... func GetSliceLen(offset int32) int32 { sliceHeader := GetSliceHeader(offset) - return mustDeserializeI32(sliceHeader[4:8]) + return Deserialize_i32(sliceHeader[4:8]) } // GetSlice ... @@ -683,7 +683,7 @@ func SliceResizeEx(outputSliceOffset int32, count int32, sizeofElement int) int if outputSliceOffset > 0 { outputSliceHeader = GetSliceHeader(outputSliceOffset) - outputSliceCap = mustDeserializeI32(outputSliceHeader[0:4]) + outputSliceCap = Deserialize_i32(outputSliceHeader[0:4]) } var newLen = count @@ -1101,7 +1101,7 @@ func DebugHeap() { for _, pkg := range PROGRAM.Packages { for _, glbl := range pkg.Globals { if glbl.IsPointer || glbl.IsSlice { - heapOffset := mustDeserializeI32(PROGRAM.Memory[glbl.Offset : glbl.Offset+TYPE_POINTER_SIZE]) + heapOffset := Deserialize_i32(PROGRAM.Memory[glbl.Offset : glbl.Offset+TYPE_POINTER_SIZE]) symsToAddrs[heapOffset] = append(symsToAddrs[heapOffset], glbl.Name) } @@ -1137,7 +1137,7 @@ func DebugHeap() { offset += fp } - heapOffset := mustDeserializeI32(PROGRAM.Memory[offset : offset+TYPE_POINTER_SIZE]) + heapOffset := Deserialize_i32(PROGRAM.Memory[offset : offset+TYPE_POINTER_SIZE]) symsToAddrs[heapOffset] = append(symsToAddrs[heapOffset], symName) } @@ -1161,7 +1161,7 @@ func DebugHeap() { w = tabwriter.NewWriter(os.Stdout, 0, 0, 2, '.', 0) for c := PROGRAM.HeapStartsAt + NULL_HEAP_ADDRESS_OFFSET; c < PROGRAM.HeapStartsAt+PROGRAM.HeapPointer; { - objSize := mustDeserializeI32(PROGRAM.Memory[c+MARK_SIZE+FORWARDING_ADDRESS_SIZE : c+MARK_SIZE+FORWARDING_ADDRESS_SIZE+OBJECT_SIZE]) + objSize := Deserialize_i32(PROGRAM.Memory[c+MARK_SIZE+FORWARDING_ADDRESS_SIZE : c+MARK_SIZE+FORWARDING_ADDRESS_SIZE+OBJECT_SIZE]) // Setting a limit size for the object to be printed if the object is too large. // We don't want to print obscenely large objects to standard output. @@ -1342,7 +1342,7 @@ func ReadStringFromObject(off int32) string { plusOff += OBJECT_HEADER_SIZE } - size := mustDeserializeI32(PROGRAM.Memory[off+plusOff : off+plusOff+STR_HEADER_SIZE]) + size := Deserialize_i32(PROGRAM.Memory[off+plusOff : off+plusOff+STR_HEADER_SIZE]) str := "" _, err := encoder.DeserializeRaw(PROGRAM.Memory[off+plusOff:off+plusOff+STR_HEADER_SIZE+size], &str)