Next Previous Contents

7. Support Code

Needs some more fleshing out This section lists the primitive functions and types that are required for the code produced by asdlGen to correctly compile. Note this is a language independent presentation.

7.1 Required for All Languages

All languages require the following

instream outstream

The input and output stream that the reader and writer functions expect.

int

The type of integers, possibly a "bignum" type.

string

The type of strings

identifier

The type of identifiers

read_tag write_tag

Read and write a constructor and length tags out in ASDL integer format. Both should use the languages standard integer types rather than a "bignum" types.

read_int write_int

Read and write the int type out in ASDL integer format.

read_string write_string

Read and write the string type out in the ASDL string format.

read_identifier write_identifier

Read and write the identifier type out in the ASDL identifier format.

die

Signal a fatal error.

7.2 BigNums

C and SML have libraries that use a bignum type rather than the a fixnum for the ASDL int type. To have the int type be a bignum in C use the flag --base_include cii_big_base.h. In SML the flags are --base_signature BIG_BASE and --base_structure BigBase.

7.3 Lists and Options

For code that does not use polymorphic list and option the following extra types are needed along with the corresponding read and write functions

int_list int_option

The list and option types for integers.

string_list string_option

The list an option types for strings.

identifier_list identifier_option

The list an option types for identifiers.

For code that supports polymorphic list and options the following extra functions are required

read_list write_list

Functions whose first argument is a read or write function for a specific type that reads or writes a list of that type.

read_option write_option

Functions whose first argument is a read or write function for a specific type that reads or writes a option of that type.

7.4 Note about --mono_types=false for C

For the --mono_types false option in C these function expect functions pointers that correspond to the following C typedefs

typedef void *(*generic_reader_ty)(instream_ty s);
typedef void (*generic_writer_ty)(void *x,outstream_ty s);

Function pointer with different argument types are distinct types in C that can not be safely cast between because they may differ in calling conventions. asdlGen solves this problem by automatically generating function stubs that internally cast the void* pointers for each option and list type. These reader and writer functions are prefixed generic_. There also should be list_ty and opt_ty typedefs.


Next Previous Contents