smlgen

所属分类:自动编程
开发工具:Standard ML
文件大小:0KB
下载次数:0
上传日期:2023-08-05 21:36:35
上 传 者sh-1993
说明:  标准ML的代码生成器,
(Code generator for Standard ML,)

文件列表:
BuildAst.sml (9578, 2023-10-10)
CompareGen.sml (13702, 2023-10-10)
Env.sml (1286, 2023-10-10)
FilesData.sml (22433, 2023-10-10)
FilesGen.sml (1805, 2023-10-10)
Fold.sml (2045, 2023-10-10)
FruGen.sml (4706, 2023-10-10)
FunctionalRecordUpdate.sml (2594, 2023-10-10)
GenericGen.sml (12274, 2023-10-10)
MutRecTy.sig (1501, 2023-10-10)
MutRecTy.sml (15343, 2023-10-10)
ShowGen.sml (9990, 2023-10-10)
Utils.sml (4144, 2023-10-10)
build.sml (11445, 2023-10-10)
build_mlkit.sh (1821, 2023-10-10)
build_polyml.sh (2222, 2023-10-10)
build_stacktrace.sh (46, 2023-10-10)
main.sml (16, 2023-10-10)
millet.toml (82, 2023-10-10)
smlfmt/ (0, 2023-10-10)
smlgen.cm (402, 2023-10-10)
smlgen.mlb (530, 2023-10-10)
smlgen.mlkit.mlb (2284, 2023-10-10)
smlgen.sml (13419, 2023-10-10)
test.sh (194, 2023-10-10)
test/ (0, 2023-10-10)
test/test1.sh (246, 2023-10-10)
test/test1.sml (710, 2023-10-10)
test/test1.sml.expected (4157, 2023-10-10)
test/test10.sh (269, 2023-10-10)
test/test10.sml.expected (1394, 2023-10-10)
test/test11.sh (215, 2023-10-10)
test/test11.sml (282, 2023-10-10)
test/test11.sml.expected (7496, 2023-10-10)
test/test12.sh (218, 2023-10-10)
test/test12.sml (956, 2023-10-10)
test/test12.sml.expected (23538, 2023-10-10)
... ...

smlgen ====== A code generator for Standard ML that generates boilerplate functions for things like converting types to strings, comparing types, etc. Building -------- After cloning the repo, run: ``` git submodule update --init --recursive ``` to clone the submodules, then run: ``` mlton smlgen.mlb ``` to build the project in MLton. To build the project in Poly/ML, run: ``` polyc build.sml -o smlgen ``` Running ------- The first argument is the path of the Standard ML file to run the generator on. The next arguments are the type name and generators to run on the type separated by colons. ``` ./smlgen foo.sml Ast.Str.strdec:g Parser.t:u Person.t:s ``` You can combine generators for a type like: ``` Ast.t:gu ``` The characters corresponding to each generator are listed below: | Option | Generator | |--------|-------------------------------------------------| | u | Functional record update | | g | [Generic](https://github.com/DarinM223/generic) | | s | Show | | c | Compare | smlgen will prompt you for every type name that matches to generate code for that type. It will then overwrite the file with the formatted and generated code. In order to print out the generated code without formatting and overwriting the file, you can pass in a `--print` option. To write to a test file, you can pass in a `--test` option. `smlgen --test file.sml ...` will create a `file.sml.test` file in the same directory as `file.sml`. smlgen also allows you to generate many commonly used files for things like array literal syntax, printf syntax, etc. To generate these files, run: ``` ./smlgen -gen ``` The list of file generators is shown below: | Generator | Description | |-----------|-------------------------------------------------------------------------| | fru | [Functional record update](http://www.mlton.org/FunctionalRecordUpdate) | | fold | [Fold](http://www.mlton.org/Fold) | | fold01n | [Fold01N](http://www.mlton.org/Fold01N) | | product | [Product](http://www.mlton.org/ProductType) | | printf | [Printf](http://www.mlton.org/Printf) | | num | [Numeric literals](http://www.mlton.org/NumericLiteral) | | literal | [Array & Vector literals](http://www.mlton.org/ArrayLiteral) | | optarg | [Optional arguments](http://www.mlton.org/OptionalArguments) | smlgen also allows you to generate an initial project with the `-proj` option. For example, to generate an initial project named `hello`, run: ``` ./smlgen -proj hello ``` And it will create a `hello` directory with initial project files. Testing ------- To run the tests, run: ``` sh test.sh ``` in the project directory. It should list the number of succeeded and failed tests and the diff between the generated code and the expected code for each failed test. Current limitations ------------------- Right now, the generic generation doesn't handle constructor names that conflict with the existing generic constructors like `T` or `C1`, etc. So this: ```sml datatype 'a t = T of 'a * 'a t * int t * string t (* BAD *) ``` will generate a function that doesn't compile. Instead, rename the constructor to not conflict: ```sml datatype 'a t = T' of 'a * 'a t * int t * string t ``` All of the generator functions handle some types of polymorphic recursive use inside its definition. In the above example, the constructor of `'a t` contains monomorphic uses of `t` (`int t` and `string t`), and a naive recursive function will not work with these, since it will unify `'a` with either `int` or `string`. The generator functions work around this by creating separate functions for `int t` and `string t`. However, if the type itself grows infinitely, the generator will skip the type and print the message `Max type size limit exceeded`. So a generator for something like this cannot be done: ```sml datatype 'a t = T' of 'a * 'a list t (* BAD *) ``` You may hit the maximum type size limit error unintentionally, from having a very large record or tuple. In that case you can increase the maximum type size with the `-maxsize` flag. For example: ``` ./smlgen file.sml ... -maxsize 1000 ``` will set the max type size limit to 1000. The default max type size is set at 100.

近期下载者

相关文件


收藏者