From: unknown <> Date: Mon, 17 Nov 2014 20:15:22 +0000 (+0000) Subject: autocommit for files dated 2014-11-17 20:15:22 X-Git-Url: https://pd.if.org/git/?p=lice;a=commitdiff_plain;h=26a5ccbbaa15538494b95ac540e84b4d8bd76c4b autocommit for files dated 2014-11-17 20:15:22 --- diff --git a/list.h b/list.h new file mode 100644 index 0000000..98c8971 --- /dev/null +++ b/list.h @@ -0,0 +1,133 @@ +#ifndef LICE_UTIL_LIST_HDR +#define LICE_UTIL_LIST_HDR +#include + +/* + * Macro: SENTINEL_LIST + * Initialize an empty list in place + */ +#define SENTINEL_LIST ((list_t) { \ + .length = 0, \ + .head = NULL, \ + .tail = NULL \ +}) + +/* + * Type: list_iterator_t + * A type capable of representing an itrator for a + */ +typedef struct list_iterator_s list_iterator_t; + +/* + * Type: list_t + * A standard double-linked list + */ +typedef struct list_s list_t; + +/* + * Function: list_create + * Creates a new list + */ +list_t *list_create(void); + +/* + * Function: list_push + * Push an element onto a list + */ +void list_push(list_t *list, void *element); + +/* + * Function: list_pop + * Pop an element from a list + */ +void *list_pop(list_t *list); + +/* + * Function: list_length + * Used to retrieve length of a list object + */ +int list_length(list_t *list); + +/* + * Function: list_shift + * Like a list_pop but shift from the head (instead of the tail) + */ +void *list_shift(list_t *list); + +/* + * Function: list_reverse + * Reverse the contents of a list + */ +list_t *list_reverse(list_t *list); + +/* + * Function: list_iterator + * Create an iterator for a given list object + */ +list_iterator_t *list_iterator(list_t *list); + +/* + * Function: list_iterator_next + * Increment the list iterator while returning the given element + */ +void *list_iterator_next(list_iterator_t *iter); + +/* + * Function: list_iterator_end + * Test if the iterator is at the end of the list + */ +bool list_iterator_end(list_iterator_t *iter); + +/* + * Function: list_tail + * Get the last element in a list + * + * Parameters: + * list - The list in question to get the last element of. + * + * Returns: + * The last element in the list. + */ +void *list_tail(list_t *list); + +/* + * Function: list_head + * Get the first element in a list + * + * Parameters: + * list - The list in question to get the first element of. + * + * Returns: + * The first element in the list. + */ +void *list_head(list_t *list); + +/* + * Function: list_empty + * Empty the contents of a list + * + * Parameters: + * list - The list to empty the contents of. + */ +void list_empty(list_t *list); + +/* + * Function: list_default + * Create a new list default initializing the first element with + * an item. + * + * Parameters: + * item - The first item to default initialize the list with. + * + * Returns: + * A new list containing one element holding `item`. + */ +list_t *list_default(void *item); + +struct list_s { + int length; + struct list_node_s *head; + struct list_node_s *tail; +}; + +#endif diff --git a/misc/index.html b/misc/index.html new file mode 100644 index 0000000..b69bb78 --- /dev/null +++ b/misc/index.html @@ -0,0 +1,8 @@ +/misc/ + +

/misc/

+ + diff --git a/opt.h b/opt.h new file mode 100644 index 0000000..440b851 --- /dev/null +++ b/opt.h @@ -0,0 +1,39 @@ +#ifndef LICE_OPT_HDR +#define LICE_OPT_HDR + +#include + +typedef enum { + STANDARD_LICEC, /* LICE variant (C11 with extensions) */ + STANDARD_GNUC, /* GNUC variant */ + STANDARD_KANDR, /* K&R C */ + STANDARD_C90, /* C90 (ISO/IEC 9899:1990) */ + STANDARD_C99, /* C99 (ISO/IEC 9899:1999) */ + STANDARD_C11 /* C11 (ISO/IEC 9889:2011) */ +} opt_std_t; + +typedef enum { + EXTENSION_DOLLAR = 1 << 1, /* Dollar signs in Identifier Names */ + EXTENSION_TYPEOF = 1 << 2, /* Referring to a Type with typeof */ + EXTENSION_OMITOPCOND = 1 << 3, /* Conditionals with Omitted Operands */ + EXTENSION_STATEMENTEXPRS = 1 << 4, /* Statements and Declarations in Expressions */ + EXTENSION_NOMEMBERSTRUCT = 1 << 5, /* Structures with No Members */ + EXTENSION_NONCONSTINIT = 1 << 6, /* Non-Constant Initializers */ + EXTENSION_CASERANGES = 1 << 7, /* Case Ranges */ + EXTENSION_ESCCHAR = 1 << 8, /* The Character in Constants */ + EXTENSION_INCOMPLETEENUM = 1 << 9, /* Incomplete enum Types */ + EXTENSION_BINARYCONSTANTS = 1 << 10, /* Binary constants using the '0b' prefix */ + EXTENSION_ARITHMETICVOID = 1 << 11, /* Arithmetic on void- and Function-Pointers */ + EXTENSION_LABELASVALUES = 1 << 12, /* Labels as Values */ + EXTENSION_ZEROARRAYS = 1 << 13, /* Arrays of Length Zero */ + + /* always the last in the list */ + EXTENSION_NONSTANDARD = 1 << 14 +} opt_extension_t; + +bool opt_std_test(opt_std_t std); +bool opt_extension_test(opt_extension_t ext); +void opt_std_set(opt_std_t std); +void opt_extension_set(opt_extension_t ext); + +#endif diff --git a/parse.h b/parse.h new file mode 100644 index 0000000..b2b4f4c --- /dev/null +++ b/parse.h @@ -0,0 +1,126 @@ +#ifndef LICE_PARSE_HDR +#define LICE_PARSE_HDR +#include "ast.h" + +/* + * Function: parse_enumeration + * Parse an enumeration + * + * Returns: + * A data type containing that enumeration definition + */ +data_type_t *parse_enumeration(void); + +/* + * Function: parse_union + * Parse a union + * + * Returns: + * A data type containing that union definition + */ +data_type_t *parse_union(void); + +/* + * Function: parse_structure + * Parse a structure + * + * Returns: + * A data type containing that structure definition + */ +data_type_t *parse_structure(void); + +/* + * Fucntion: parse_typeof + * Parse typeof operator + * + * Returns: + * The data type that represents the type of the expression supplied + * as the operand to the typeof operator. + */ +data_type_t *parse_typeof(void); + +/* + * Function: parse_typedef_find + * Search the parser typedef table for a typedef + * + * Parameters: + * string - The key of the type to search in the typedef table + * + * Returns: + * The data type representing that typedef if found, otherwise NULL. + */ +data_type_t *parse_typedef_find(const char *string); + +/* + * Function: parse_run + * Main entry point for the parser. + * + * Returns: + * Will produce a list of AST toplevel expressions which can be handed + * down to the code generator one at a time. + */ +list_t *parse_run(void); + +/* + * Function: parse_init + * Main initialization for the global parser context. + * + * Remarks: + * This must be called before calling . + */ +void parse_init(void); + +/* + * Function: parse_expect + * When expecting language punctuation, this function is assumed to + * ensure that the following lexer state does indeed contain that + * punctuator. + * + * Parameters: + * punct - A character literal of the punctuation. + * + * Remarks: + * If the passed punctuator isn't resolved as the current lexer state + * a lexer error is raised. + */ +void parse_expect(char punct); + +/* + * Function: parse_next + * Reads the next token in the token stream and determines if it's + * the token specified by the argument, ungetting the token if it is, + * ignoring it if it isn't. + * + * Parameters: + * ch - The token to check + * + * Returns: + * true if the token passed matches the next token in the token stream, + * false otherwise. + * + * Remarks: + * This will advance lexer state only if the token specified as a + * parameter isn't determined as the next token in the token stream. + */ +bool parse_next(int ch); + +/* + * Function: parse_expression_evaluate + * Reads a conditional expression and evaluates it as an integer constant + * expression if it one. + * + * Returns: + * An integer constant value of the evaluation of the integer constant + * expression. + * + * Remarks: + * Will raise a compilation error if it isn't a valid integer constant + * expression. + */ +int parse_expression_evaluate(void); + +/* TODO: remove */ +void parse_semantic_assignable(data_type_t *to, data_type_t *from); +ast_t *parse_expression_assignment(void); + +#endif