Menu

WFCOM

Phillip Kilgore

The WFCO Metacompiler is a tool which emits C code from files written in the WFCO language. This tool exists to make writing classes easier. Although WFCO classes can be authored manually, this tool simplifies authoring such classes.

Usage

A program named wfcom is included with WFCO to process WFCO language files into other code. Presently, only C and C++ will be supported.

Target Option

usage:
wfcom -t *target* *source-file*
wfcom --target=*target* *source-file*

The target option specifies for which target the code will be compiled. The code emitted is specifically defined by the target. By default, the target is both.

For the purposes of demonstration, the following class definition is provided. The example results below are not meant to be authoritative, but only to illustrate what a resulting implementation might look like.

namespace foo::bar;

class thingy {
    int value;

    this(int value) : value(value);

    void use() {
        value++;
    }
};

Target header

This function produces a C header. This target emits function prototypes, class definitions, enum and structure definitions, thunks for methods, and function definitions for inline functions. Implementation details are specifically omitted. If a namespace is defined, each symbol in the namespace is prefixed with the namespace name. By default, this function also generates C++ bindings in this file. Below is a possible result:

#include <wfco/object.h>
#ifdef __cplusplus
extern "C" {
#endif __cplusplus

WFCO_CLASS(foo_bar_thingy)
    int value;
WFCO_METHODS(foo_bar_thingy)
    WFCO_DECLARE_METHOD(foo_bar_thingy, use, void)
WFCO_END_CLASS(foo_bar_thingy)

WFCO_DECLARE_CTOR(wdmf_bar_thingy, 0, int value);

inline void foo_bar_thing_use(foo_bar_thing* obj) {
    WDMF_OBJ_CALL(obj, use);
}

#ifdef __cplusplus
}

namespace foo {
namespace bar {
    class thingy : public ::foo_bar_thingy {
        public:

           thingy(int value) {
               WFCO_CTOR_CALL(this, 0, value); 
           }

           inline ~thingy() {
                ::wfco_destroy(this);
           }

           inline void use() {
               WFCO_OBJ_CALL(this, use);
           }
    };
}
} 
#endif __cplusplus

Target c

This function produces the C language implementation of the WFCO language file. This assumes that a header corresponding to the name of the input file exists (e.g., if the WFCO file is named foo.wfco, then it expects a header named foo.h. The contents of the header are not duplicated in the resulting file, but instead, only the implementation is provided. Below is a possible result:

#include "foo.h"

WFCO_DEFINE_CTOR(foo_bar_thingy, 0, int value) {
    WFCO_THIS_DATA.value = value;
}

WFCO_METHOD(foo_bar_thingy, use) {
    WFCO_THIS_DATA.value++;
}

WFCO_DEFINE_VTABLE_DD(foo_bar_thingy)
    WFCO_ATTACH_METHOD(foo_bar_thingy, use);
WFCO_END_VTABLE(foo_bar_thingy)

Target both

This target combines the functionality of the header and c targets. It is equivalent to c, except that the contents of the header are directly copied into the file. This functionality exists so that private classes may be implemented.

Output Option

usage:
wfcom -o *dest-file* *source-file*
wfcom --output=*dest-file* *source-file*

The output option sets the file to which the output is written. By default, output is written to standard output. When this option is set, the output is directed into the value supplied by dest-file.