Eliot Miranda uploaded a new version of VMMaker to project VM Maker: http://source.squeak.org/VMMaker/VMMaker.oscog-eem.2490.mcz ==================== Summary ==================== Name: VMMaker.oscog-eem.2490 Author: eem Time: 6 December 2018, 3:03:09.631666 pm UUID: 8b3a39b0-5b6b-48bd-b8e9-19b8bc388d7c Ancestors: VMMaker.oscog-eem.2489 Tidy up the SerialPlugin. FIx a bug in primitiveSerialPortCloseByName: =============== Diff against VMMaker.oscog-eem.2489 =============== Item was added: + ----- Method: SerialPlugin>>copyPortNameToCString: (in category 'private-support') ----- + copyPortNameToCString: portName + <returnTypeC: #'char *'> + | port portNameSize | + <inline: #always> + <var: 'port' type: #'char *'> + portNameSize := interpreterProxy slotSizeOf: (portName asOop: String). + port := self alloca: portNameSize + 1 _: (self sizeof: #char). + self memcpy: port _: portName _: portNameSize. + port at: portNameSize put: 0. + ^port! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortCloseByName: (in category 'primitives') ----- primitiveSerialPortCloseByName: portName + | port | - self primitive: 'primitiveSerialPortCloseByName' parameters: #(String). + port := self copyPortNameToCString: portName. + self serialPortCloseByName: port! - self serialPortCloseByName: portName! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortOpen:baudRate:stopBitsType:parityType:dataBits:inFlowControlType:outFlowControlType:xOnByte:xOffByte: (in category 'primitives') ----- primitiveSerialPortOpen: portNum baudRate: baudRate stopBitsType: stopBitsType parityType: parityType dataBits: dataBits inFlowControlType: inFlowControl outFlowControlType: outFlowControl xOnByte: xOnChar xOffByte: xOffChar self primitive: 'primitiveSerialPortOpen' + parameters: #(SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger). - parameters: #(SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger ). + self serialPortOpen: portNum _: baudRate _: stopBitsType _: parityType _: dataBits + _: inFlowControl _: outFlowControl _: xOnChar _: xOffChar! - self cCode: 'serialPortOpen( - portNum, baudRate, stopBitsType, parityType, dataBits, - inFlowControl, outFlowControl, xOnChar, xOffChar)'! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortOpenByName:baudRate:stopBitsType:parityType:dataBits:inFlowControlType:outFlowControlType:xOnByte:xOffByte: (in category 'primitives') ----- primitiveSerialPortOpenByName: portName baudRate: baudRate stopBitsType: stopBitsType parityType: parityType dataBits: dataBits inFlowControlType: inFlowControl outFlowControlType: outFlowControl xOnByte: xOnChar xOffByte: xOffChar - <var: #port type: 'char *'> + | port | - | port portNameSize | - self primitive: 'primitiveSerialPortOpenByName' + parameters: #(String SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger). - parameters: #(String SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger SmallInteger ). + port := self copyPortNameToCString: portName. + self serialPortOpenByName: port _: baudRate _: stopBitsType _: parityType _: dataBits + _: inFlowControl _: outFlowControl _: xOnChar _: xOffChar! - portNameSize := interpreterProxy slotSizeOf: (portName asOop: String). - port := self cCode: 'calloc(portNameSize+1, sizeof(char))'. - self cCode: 'memcpy(port, portName, portNameSize)'. - - self cCode: 'serialPortOpenByName( - port, baudRate, stopBitsType, parityType, dataBits, - inFlowControl, outFlowControl, xOnChar, xOffChar)'. - - self free: port.! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortRead:into:startingAt:count: (in category 'primitives') ----- primitiveSerialPortRead: portNum into: array startingAt: startIndex count: count + | bytesRead | - | bytesRead arrayPtr | self primitive: 'primitiveSerialPortRead' + parameters: #(SmallInteger ByteArray SmallInteger SmallInteger). - parameters: #(SmallInteger ByteArray SmallInteger SmallInteger ). + (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]) ifTrue: + [bytesRead := self serialPortReadInto: portNum _: count _: array + startIndex - 1. + ^bytesRead asSmallIntegerObj]. + interpreterProxy success: false! - interpreterProxy success: (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]). - "adjust for zero-origin indexing" - arrayPtr := array asInteger + startIndex - 1. - bytesRead := self cCode: 'serialPortReadInto( portNum, count, arrayPtr)'. - ^ bytesRead asSmallIntegerObj! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortReadByName:into:startingAt:count: (in category 'primitives') ----- + primitiveSerialPortReadByName: portName into: array startingAt: startIndex count: count + | port bytesRead | + <var: #port type: #'char *'> - primitiveSerialPortReadByName: portName into: array startingAt: startIndex count: count - <var: #port type: 'char *'> - - | port portNameSize bytesRead arrayPtr | - self primitive: 'primitiveSerialPortReadByName' + parameters: #(String ByteArray SmallInteger SmallInteger). - parameters: #(String ByteArray SmallInteger SmallInteger ). + (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]) ifTrue: + [port := self copyPortNameToCString: portName. + bytesRead := self serialPortReadIntoByName: port _: count _: array + startIndex - 1. + ^bytesRead asSmallIntegerObj]. + interpreterProxy success: false! - interpreterProxy success: (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]). - "adjust for zero-origin indexing" - - portNameSize := interpreterProxy slotSizeOf: (portName asOop: String). - port := self cCode: 'calloc(portNameSize+1, sizeof(char))'. - self cCode: 'memcpy(port, portName, portNameSize)'. - - arrayPtr := array + startIndex - 1. - bytesRead := self cCode: 'serialPortReadIntoByName( port, count, arrayPtr)'. - - self free: port. - - ^ bytesRead asSmallIntegerObj! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortWrite:from:startingAt:count: (in category 'primitives') ----- primitiveSerialPortWrite: portNum from: array startingAt: startIndex count: count + | bytesWritten | - | bytesWritten arrayPtr | self primitive: 'primitiveSerialPortWrite' + parameters: #(SmallInteger ByteArray SmallInteger SmallInteger). - parameters: #(SmallInteger ByteArray SmallInteger SmallInteger ). + (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]) ifTrue: + [bytesWritten := self serialPort: portNum Write: count From: array + startIndex - 1. + ^bytesWritten asSmallIntegerObj]. + interpreterProxy success: false! - interpreterProxy success: (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]). - interpreterProxy failed - ifFalse: [arrayPtr := array + startIndex - 1. - bytesWritten := self - serialPort: portNum - Write: count - From: arrayPtr]. - ^ bytesWritten asSmallIntegerObj! Item was changed: ----- Method: SerialPlugin>>primitiveSerialPortWriteByName:from:startingAt:count: (in category 'primitives') ----- primitiveSerialPortWriteByName: portName from: array startingAt: startIndex count: count + | bytesWritten port | - <var: #port type: 'char *'> - - | bytesWritten arrayPtr portNameSize port | - self primitive: 'primitiveSerialPortWriteByName' + parameters: #(String ByteArray SmallInteger SmallInteger). - parameters: #(String ByteArray SmallInteger SmallInteger ). + (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]) ifTrue: + [port := self copyPortNameToCString: portName. + bytesWritten := self serialPortWriteFromByName: port _: count _: array + startIndex - 1. + ^bytesWritten asSmallIntegerObj]. + interpreterProxy success: false! - portNameSize := interpreterProxy slotSizeOf: (portName asOop: String). - port := self cCode: 'calloc(portNameSize+1, sizeof(char))'. - self cCode: 'memcpy(port, portName, portNameSize)'. - - interpreterProxy success: (startIndex >= 1 and: [startIndex + count - 1 <= (interpreterProxy byteSizeOf: array cPtrAsOop)]). - interpreterProxy failed - ifFalse: [arrayPtr := array + startIndex - 1. - bytesWritten := self cCode: 'serialPortWriteFromByName(port, count, arrayPtr)' ]. - - self free: port. - - ^ bytesWritten asSmallIntegerObj! |
Free forum by Nabble | Edit this page |