[Vm-dev] VM Maker: ImageFormat-eem.41.mcz

Levente Uzonyi leves at caesar.elte.hu
Sat Apr 11 20:03:49 UTC 2020


Hi Eliot,

There's a slight difference between #forceNewFileNamed: and 
#newFileNamed:. The latter will not overwrite the file if exists but 
will ask the user what to do. I don't know which behavior is desirable 
here but it's a change not mentioned in the commit message.

Also, #storeCkFormatOnFile should use either #newFileNamed:do: 
or #forceNewFileNamed:do: instead of #newFileNamed:/#forceNewFileNamed:. 
There's no need to duplicate file handling logic there. It could be 
something like this:

 	FileStream newFileNamed: fileName do: [ :file |
 		file lineEndConvention: #lf.
 		self generateCkFormatProgram: 'ckformat' on: file ]


Levente

On Fri, 10 Apr 2020, commits at source.squeak.org wrote:

> 
> Eliot Miranda uploaded a new version of ImageFormat to project VM Maker:
> http://source.squeak.org/VMMaker/ImageFormat-eem.41.mcz
>
> ==================== Summary ====================
>
> Name: ImageFormat-eem.41
> Author: eem
> Time: 10 April 2020, 3:37:29.573579 pm
> UUID: d4217463-f4f7-4df4-96a1-e922eb61cace
> Ancestors: ImageFormat-dtl.40
>
> Revert back to the previous version of generateCkFormatProgram:on: (losing a period at the end of the comment, sorry Dave!!).  Use the correct way of creating a file stream to generate an lf terminated C source file: (MultiByteFileStream forceNewFileNamed: fileName)
> 			lineEndConvention: #lf;
> 			yourself
>
> =============== Diff against ImageFormat-dtl.40 ===============
>
> Item was changed:
>  ----- Method: ImageFormat class>>generateCkFormatProgram:on: (in category 'ckformat') -----
>  generateCkFormatProgram: programName on: stream
>  	"Generate source code for an image format version reader. The program
>  	is intended for testing image file format from a unix shell script such that
> + 	the shell script can decide what VM to run based on image requirements."
> - 	the shell script can decide what VM to run based on image requirements"
>
>  	| formatNumber |
> + 	stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; cr;
> + 			nextPutAll: '/* for use in a shell script to test image format requirements. */'; cr;
> + 			nextPutAll: '/* A non-zero return status code indicates failure. */'; cr; cr;
> + 			nextPutAll: '/* Usage: ', programName, ' imageFileName */'; cr; cr;
> + 			nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr;
> + 			nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; cr;
> + 			nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; cr;
> + 			nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; cr; cr;
> + 			nextPutAll: '#include <stdio.h>'; cr;
> + 			nextPutAll: '#include <stdlib.h>'; cr;
> + 			nextPutAll: '#include <string.h>'; cr; cr;
> + 			nextPutAll: 'int main(int argc, char **argv) {'; cr;
> + 			tab; nextPutAll: 'FILE *f;'; cr;
> + 			tab; nextPutAll: 'unsigned char buf[8];'; cr; 
> + 			tab; nextPutAll: 'int formatNumber;'; cr; 
> + 			tab; nextPutAll: 'unsigned char c;'; cr; 
> + 			tab; nextPutAll: 'int match;'; cr; 
> + 			tab; nextPutAll: 'if (argc !!= 2) {'; cr;
> + 			tab; tab; nextPutAll: 'printf("usage: ', programName,  ' imageFileName\n");'; cr;
> + 			tab; tab; nextPutAll: 'exit(1);'; cr;
> + 			tab; nextPutAll: '}'; cr;
> + 			tab; nextPutAll: 'f = fopen(argv[1], "r");'; cr;
> + 			tab; nextPutAll: 'if (f == NULL) {'; cr;
> + 			tab; tab; nextPutAll: 'perror(argv[1]);'; cr;
> + 			tab; tab; nextPutAll: 'exit(2);'; cr;
> + 			tab; nextPutAll: '}'; cr.
> - 	stream nextPutAll: '/* ', programName, ': Print the image format number on standard output */'; lf;
> - 			nextPutAll: '/* for use in a shell script to test image format requirements. */'; lf;
> - 			nextPutAll: '/* A non-zero return status code indicates failure. */'; lf; lf;
> - 			nextPutAll: '/* Usage: ', programName, ' imageFileName */'; lf; lf;
> - 			nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; lf;
> - 			nextPutAll: '/* --- Automatically generated from class ', self name, ' ', DateAndTime now asString, '--- */'; lf;
> - 			nextPutAll: '/* --- Source code is in package ImageFormat in the VMMaker repository --- */'; lf;
> - 			nextPutAll: '/* --- DO NOT EDIT THIS FILE --- */'; lf; lf;
> - 			nextPutAll: '#include <stdio.h>'; lf;
> - 			nextPutAll: '#include <stdlib.h>'; lf;
> - 			nextPutAll: '#include <string.h>'; lf; lf;
> - 			nextPutAll: 'int main(int argc, char **argv) {'; lf;
> - 			tab; nextPutAll: 'FILE *f;'; lf;
> - 			tab; nextPutAll: 'unsigned char buf[8];'; lf; 
> - 			tab; nextPutAll: 'int formatNumber;'; lf; 
> - 			tab; nextPutAll: 'unsigned char c;'; lf; 
> - 			tab; nextPutAll: 'int match;'; lf; 
> - 			tab; nextPutAll: 'if (argc !!= 2) {'; lf;
> - 			tab; tab; nextPutAll: 'printf("usage: ', programName,  ' imageFileName\n");'; lf;
> - 			tab; tab; nextPutAll: 'exit(1);'; lf;
> - 			tab; nextPutAll: '}'; lf;
> - 			tab; nextPutAll: 'f = fopen(argv[1], "r");'; lf;
> - 			tab; nextPutAll: 'if (f == NULL) {'; lf;
> - 			tab; tab; nextPutAll: 'perror(argv[1]);'; lf;
> - 			tab; tab; nextPutAll: 'exit(2);'; lf;
> - 			tab; nextPutAll: '}'; lf.
>  	{ 0. 512 } do: [:offset |
>  		stream
> + 			tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';cr;
> + 			tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; cr;
> + 			tab; tab; nextPutAll: 'exit(3);'; cr;
> + 			tab; nextPutAll: '}'; cr;
> + 			tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8) {'; cr;
> + 			tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; cr;
> + 			tab; tab; nextPutAll: 'exit(3);'; cr;
> + 			tab; nextPutAll: '}'; cr.
> - 			tab; nextPutAll: 'if(fseek(f, '; nextPutAll: offset asString; nextPutAll: 'L, SEEK_SET) !!= 0) {';lf;
> - 			tab; tab; nextPutAll: 'fprintf(stderr, "cannot go to pos %d in %s\n", '; nextPutAll: offset asString; nextPutAll: ', argv[1]);'; lf;
> - 			tab; tab; nextPutAll: 'exit(3);'; lf;
> - 			tab; nextPutAll: '}'; lf;
> - 			tab; nextPutAll: 'if (fread(buf, 1, 8, f) < 8) {'; lf;
> - 			tab; tab; nextPutAll: 'fprintf(stderr, "cannot read %s\n", argv[1]);'; lf;
> - 			tab; tab; nextPutAll: 'exit(3);'; lf;
> - 			tab; nextPutAll: '}'; lf.
>  		self versionNumberByteArrays withIndexDo: [ :v :tag | | b |
>  			formatNumber := (self fromBytes: v) asInteger.
>  			b := 'b_', formatNumber asString, '_', tag asString.
> + 			stream tab; nextPutAll: '{'; cr; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '.
> - 			stream tab; nextPutAll: '{'; lf; tab; nextPutAll: 'unsigned char ', b, '[', v size asString, ']= { '.
>  			v inject: true into: [:first : elem |
>  				first ifFalse: [stream nextPutAll: ', '].
>  				stream nextPutAll: elem asString.
>  				false].
> + 			stream nextPutAll: '};'; cr;
> + 					tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; cr;
> + 					tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; cr;
> + 					tab; tab; nextPutAll: 'exit(0);'; cr;
> + 					tab; nextPutAll: '}'; cr; tab; nextPutAll: '}'; cr]].
> + 	stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';cr;
> + 			tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; cr;
> + 			nextPutAll: '}'; cr
> - 			stream nextPutAll: '};'; lf;
> - 					tab; nextPutAll: 'if (memcmp(buf, ', b, ', ', v size asString, ') == 0) {'; lf;
> - 					tab; tab; nextPutAll: 'printf("%d\n", ', formatNumber, ');'; lf;
> - 					tab; tab; nextPutAll: 'exit(0);'; lf;
> - 					tab; nextPutAll: '}'; lf; tab; nextPutAll: '}'; lf]].
> - 	stream tab; nextPutAll: 'printf("0\n"); /* print an invalid format number */';lf;
> - 			tab; nextPutAll: 'exit (-1); /* not found, exit with error code */'; lf;
> - 			nextPutAll: '}'; lf
>  !
>
> Item was changed:
>  ----- Method: ImageFormat class>>storeCkFormatOnFile: (in category 'ckformat') -----
>  storeCkFormatOnFile: fileName
>  	"Store source code for an image format version reader in a file. The program
>  	is intended for testing image file format from a unix shell script such that
>  	the shell script can decide what VM to run based on image requirements."
>
>  	| f |
> + 	f := (MultiByteFileStream forceNewFileNamed: fileName)
> + 			lineEndConvention: #lf;
> + 			yourself.
> - 	f := FileStream newFileNamed: fileName.
>  	[self generateCkFormatProgram: 'ckformat' on: f]
>  		ensure: [f ifNotNil: [f close]].
>  	^fileName!


More information about the Vm-dev mailing list