calculator.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 08 Feb 2010 03:04:29 -0500
branchcalculator-experiment
changeset 812 ac8e761569da
parent 811 307e3ab506fa
child 814 a2cf3f36ed1c
permissions -rw-r--r--
Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     1
#define __MOJOSHADER_INTERNAL__ 1
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     2
#include "mojoshader_internal.h"
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     3
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     4
#if DEBUG_COMPILER_PARSER
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     5
#define LEMON_SUPPORT_TRACING 1
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     6
#endif
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     7
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     8
typedef struct Context
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
     9
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    10
    int isfail;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    11
    int out_of_memory;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    12
    MOJOSHADER_malloc malloc;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    13
    MOJOSHADER_free free;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    14
    void *malloc_data;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    15
    int error_count;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    16
    ErrorList *errors;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    17
    Preprocessor *preprocessor;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    18
    const char *token;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    19
    unsigned int tokenlen;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    20
    Token tokenval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    21
    unsigned int parse_errors;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    22
} Context;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    23
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    24
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    25
// Convenience functions for allocators...
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    26
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    27
static inline void out_of_memory(Context *ctx)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    28
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    29
    ctx->isfail = ctx->out_of_memory = 1;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    30
} // out_of_memory
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    31
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    32
static inline void *Malloc(Context *ctx, const size_t len)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    33
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    34
    void *retval = ctx->malloc((int) len, ctx->malloc_data);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    35
    if (retval == NULL)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    36
        out_of_memory(ctx);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    37
    return retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    38
} // Malloc
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    39
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    40
static inline char *StrDup(Context *ctx, const char *str)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    41
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    42
    char *retval = (char *) Malloc(ctx, strlen(str) + 1);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    43
    if (retval != NULL)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    44
        strcpy(retval, str);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    45
    return retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    46
} // StrDup
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    47
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    48
static inline void Free(Context *ctx, void *ptr)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    49
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    50
    if (ptr != NULL)  // check for NULL in case of dumb free() impl.
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    51
        ctx->free(ptr, ctx->malloc_data);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    52
} // Free
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    53
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    54
typedef enum Operator
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    55
{
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    56
    OP_START_RANGE_UNARY_OPERATORS,
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    57
    OP_POSTINCREMENT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    58
    OP_POSTDECREMENT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    59
    OP_PREINCREMENT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    60
    OP_PREDECREMENT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    61
    OP_NEGATE,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    62
    OP_COMPLEMENT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    63
    OP_NOT,
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    64
    OP_END_RANGE_UNARY_OPERATORS,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    65
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    66
    OP_START_RANGE_BINARY_OPERATORS,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    67
    OP_DEREF_ARRAY,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    68
    OP_CALLFUNC,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    69
    OP_DEREF_STRUCT,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
    70
    OP_COMMA,
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    71
    OP_MULTIPLY,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    72
    OP_DIVIDE,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    73
    OP_MODULO,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    74
    OP_ADD,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    75
    OP_SUBTRACT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    76
    OP_LSHIFT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    77
    OP_RSHIFT,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    78
    OP_LESSTHAN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    79
    OP_GREATERTHAN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    80
    OP_LESSTHANOREQUAL,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    81
    OP_GREATERTHANOREQUAL,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    82
    OP_EQUAL,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    83
    OP_NOTEQUAL,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    84
    OP_BINARYAND,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    85
    OP_BINARYXOR,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    86
    OP_BINARYOR,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    87
    OP_LOGICALAND,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    88
    OP_LOGICALOR,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    89
    OP_ASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    90
    OP_MULASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    91
    OP_DIVASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    92
    OP_MODASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    93
    OP_ADDASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    94
    OP_SUBASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    95
    OP_LSHIFTASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    96
    OP_RSHIFTASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    97
    OP_ANDASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    98
    OP_XORASSIGN,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
    99
    OP_ORASSIGN,
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   100
    OP_END_RANGE_BINARY_OPERATORS,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   101
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   102
    OP_START_RANGE_TERNARY_OPERATORS,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   103
    OP_CONDITIONAL,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   104
    OP_END_RANGE_TERNARY_OPERATORS,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   105
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   106
    OP_START_RANGE_DATA,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   107
    OP_IDENTIFIER,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   108
    OP_INT_LITERAL,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   109
    OP_FLOAT_LITERAL,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   110
    OP_STRING_LITERAL,
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   111
    OP_END_RANGE_DATA,
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   112
} Operator;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   113
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   114
typedef struct Expression
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   115
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   116
    Operator op;  // operator
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   117
} Expression;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   118
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   119
#define NEW_EXPR(cls) \
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   120
    cls *retval = Malloc(ctx, sizeof (cls)); \
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   121
    if (retval == NULL) { return NULL; }
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   122
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   123
typedef struct ExpressionUnary
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   124
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   125
    Operator op;  // operator
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   126
    Expression *operand;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   127
} ExpressionUnary;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   128
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   129
typedef struct ExpressionBinary
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   130
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   131
    Operator op;  // operator
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   132
    Expression *left;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   133
    Expression *right;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   134
} ExpressionBinary;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   135
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   136
typedef struct ExpressionTernary
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   137
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   138
    Operator op;  // operator
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   139
    Expression *left;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   140
    Expression *center;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   141
    Expression *right;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   142
} ExpressionTernary;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   143
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   144
typedef struct ExpressionIdentifier
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   145
{
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   146
    Operator op;  // Always OP_IDENTIFIER
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   147
    const char *identifier;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   148
} ExpressionIdentifier;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   149
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   150
typedef struct ExpressionLiteralInt
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   151
{
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   152
    Operator op;  // Always OP_INT_LITERAL
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   153
    int64 value;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   154
} ExpressionLiteralInt;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   155
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   156
typedef struct ExpressionLiteralFloat
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   157
{
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   158
    Operator op;  // Always OP_FLOAT_LITERAL
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   159
    double value;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   160
} ExpressionLiteralFloat;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   161
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   162
typedef struct ExpressionLiteralString
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   163
{
812
ac8e761569da Cleaned up operator enumeration, put it into ranges, fixed data ops.
Ryan C. Gordon <icculus@icculus.org>
parents: 811
diff changeset
   164
    Operator op;  // Always OP_STRING_LITERAL
811
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   165
    const char *string;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   166
} ExpressionLiteralString;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   167
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   168
static const char *new_identifier(Context *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   169
static Expression *new_unary_expr(Context *, const Operator, Expression *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   170
static Expression *new_binary_expr(Context *, const Operator, Expression *, Expression *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   171
static Expression *new_ternary_expr(Context *, const Operator, Expression *, Expression *, Expression *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   172
static Expression *new_identifier_expr(Context *, const char *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   173
static Expression *new_literal_int_expr(Context *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   174
static Expression *new_literal_float_expr(Context *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   175
static Expression *new_literal_string_expr(Context *);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   176
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   177
static void parse_complete(const Expression *expr)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   178
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   179
    printf("parse complete!\n");
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   180
    
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   181
} // parse_complete
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   182
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   183
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   184
// This is where the actual parsing happens. It's Lemon-generated!
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   185
#define __MOJOSHADER_CALC_COMPILER__ 1
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   186
#include "calculator.h"
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   187
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   188
static const char *new_identifier(Context *ctx)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   189
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   190
    // !!! FIXME: this needs to cache strings.
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   191
    const unsigned int len = ctx->tokenlen;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   192
    char *retval = Malloc(ctx, len + 1);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   193
    if (retval == NULL)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   194
        return NULL;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   195
    memcpy(retval, ctx->token, len);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   196
    retval[len] = '\0';
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   197
    return retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   198
} // new_identifier
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   199
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   200
static Expression *new_unary_expr(Context *ctx, const Operator op,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   201
                                  Expression *operand)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   202
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   203
    NEW_EXPR(ExpressionUnary);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   204
    retval->op = op;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   205
    retval->operand = operand;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   206
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   207
} // new_unary_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   208
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   209
static Expression *new_binary_expr(Context *ctx, const Operator op,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   210
                                   Expression *left, Expression *right)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   211
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   212
    NEW_EXPR(ExpressionBinary);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   213
    retval->op = op;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   214
    retval->left = left;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   215
    retval->right = right;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   216
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   217
} // new_binary_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   218
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   219
static Expression *new_ternary_expr(Context *ctx, const Operator op,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   220
                                    Expression *left, Expression *center,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   221
                                    Expression *right)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   222
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   223
    NEW_EXPR(ExpressionTernary);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   224
    retval->op = op;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   225
    retval->left = left;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   226
    retval->center = center;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   227
    retval->right = right;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   228
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   229
} // new_ternary_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   230
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   231
static Expression *new_identifier_expr(Context *ctx, const char *identifier)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   232
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   233
    NEW_EXPR(ExpressionIdentifier);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   234
    retval->op = TOKEN_CALC_IDENTIFIER;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   235
    retval->identifier = identifier;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   236
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   237
} // new_identifier_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   238
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   239
static inline int64 strtoi64(const char *str, unsigned int len)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   240
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   241
    int64 retval = 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   242
    int64 mult = 1;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   243
    int i = 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   244
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   245
    while ((len) && (*str == ' '))
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   246
    {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   247
        str++;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   248
        len--;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   249
    } // while
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   250
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   251
    if ((len) && (*str == '-'))
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   252
    {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   253
        mult = -1;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   254
        str++;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   255
        len--;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   256
    } // if
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   257
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   258
    while (i < len)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   259
    {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   260
        const char ch = str[i];
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   261
        if ((ch < '0') || (ch > '9'))
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   262
            break;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   263
        i++;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   264
    } // while
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   265
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   266
    while (--i >= 0)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   267
    {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   268
        const char ch = str[i];
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   269
        retval += ((int64) (ch - '0')) * mult;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   270
        mult *= 10;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   271
    } // while
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   272
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   273
    return retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   274
} // strtoi64
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   275
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   276
static Expression *new_literal_int_expr(Context *ctx)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   277
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   278
    NEW_EXPR(ExpressionLiteralInt);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   279
    retval->op = TOKEN_CALC_INT_CONSTANT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   280
    retval->value = strtoi64(ctx->token, ctx->tokenlen);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   281
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   282
} // new_literal_int_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   283
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   284
static inline double strtodouble(const char *_str, unsigned int len)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   285
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   286
    // !!! FIXME: laziness prevails.
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   287
    char *str = (char *) alloca(len+1);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   288
    memcpy(str, _str, len);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   289
    str[len] = '\0';
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   290
    return strtod(str, NULL);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   291
} // strtodouble
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   292
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   293
static Expression *new_literal_float_expr(Context *ctx)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   294
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   295
    NEW_EXPR(ExpressionLiteralFloat);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   296
    retval->op = TOKEN_CALC_FLOAT_CONSTANT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   297
    retval->value = strtodouble(ctx->token, ctx->tokenlen);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   298
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   299
} // new_literal_float_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   300
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   301
static Expression *new_literal_string_expr(Context *ctx)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   302
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   303
    NEW_EXPR(ExpressionLiteralString);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   304
    retval->op = TOKEN_CALC_STRING_LITERAL;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   305
    retval->string = new_identifier(ctx);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   306
    return (Expression *) retval;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   307
} // new_string_literal_expr
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   308
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   309
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   310
static int convert_to_lemon_token(const Context *ctx)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   311
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   312
    switch (ctx->tokenval)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   313
    {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   314
        case ((Token) ','): return TOKEN_CALC_COMMA;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   315
        case ((Token) '='): return TOKEN_CALC_ASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   316
        case ((Token) TOKEN_ADDASSIGN): return TOKEN_CALC_ADDASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   317
        case ((Token) TOKEN_SUBASSIGN): return TOKEN_CALC_SUBASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   318
        case ((Token) TOKEN_MULTASSIGN): return TOKEN_CALC_MULASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   319
        case ((Token) TOKEN_DIVASSIGN): return TOKEN_CALC_DIVASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   320
        case ((Token) TOKEN_MODASSIGN): return TOKEN_CALC_MODASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   321
        case ((Token) TOKEN_LSHIFTASSIGN): return TOKEN_CALC_LSHIFTASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   322
        case ((Token) TOKEN_RSHIFTASSIGN): return TOKEN_CALC_RSHIFTASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   323
        case ((Token) TOKEN_ANDASSIGN): return TOKEN_CALC_ANDASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   324
        case ((Token) TOKEN_ORASSIGN): return TOKEN_CALC_ORASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   325
        case ((Token) TOKEN_XORASSIGN): return TOKEN_CALC_XORASSIGN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   326
        case ((Token) '?'): return TOKEN_CALC_QUESTION;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   327
        case ((Token) TOKEN_OROR): return TOKEN_CALC_OROR;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   328
        case ((Token) TOKEN_ANDAND): return TOKEN_CALC_ANDAND;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   329
        case ((Token) '|'): return TOKEN_CALC_OR;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   330
        case ((Token) '^'): return TOKEN_CALC_XOR;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   331
        case ((Token) '&'): return TOKEN_CALC_AND;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   332
        case ((Token) TOKEN_EQL): return TOKEN_CALC_EQL;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   333
        case ((Token) TOKEN_NEQ): return TOKEN_CALC_NEQ;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   334
        case ((Token) '<'): return TOKEN_CALC_LT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   335
        case ((Token) TOKEN_LEQ): return TOKEN_CALC_LEQ;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   336
        case ((Token) '>'): return TOKEN_CALC_GT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   337
        case ((Token) TOKEN_GEQ): return TOKEN_CALC_GEQ;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   338
        case ((Token) TOKEN_LSHIFT): return TOKEN_CALC_LSHIFT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   339
        case ((Token) TOKEN_RSHIFT): return TOKEN_CALC_RSHIFT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   340
        case ((Token) '+'): return TOKEN_CALC_PLUS;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   341
        case ((Token) '-'): return TOKEN_CALC_MINUS;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   342
        case ((Token) '*'): return TOKEN_CALC_STAR;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   343
        case ((Token) '/'): return TOKEN_CALC_SLASH;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   344
        case ((Token) '%'): return TOKEN_CALC_PERCENT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   345
        case ((Token) '!'): return TOKEN_CALC_EXCLAMATION;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   346
        case ((Token) '~'): return TOKEN_CALC_COMPLEMENT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   347
        case ((Token) TOKEN_DECREMENT): return TOKEN_CALC_MINUSMINUS;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   348
        case ((Token) TOKEN_INCREMENT): return TOKEN_CALC_PLUSPLUS;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   349
        case ((Token) '.'): return TOKEN_CALC_DOT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   350
        case ((Token) '['): return TOKEN_CALC_LBRACKET;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   351
        case ((Token) ']'): return TOKEN_CALC_RBRACKET;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   352
        case ((Token) '('): return TOKEN_CALC_LPAREN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   353
        case ((Token) ')'): return TOKEN_CALC_RPAREN;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   354
        case ((Token) TOKEN_INT_LITERAL): return TOKEN_CALC_INT_CONSTANT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   355
        case ((Token) TOKEN_FLOAT_LITERAL): return TOKEN_CALC_FLOAT_CONSTANT;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   356
        case ((Token) TOKEN_STRING_LITERAL): return TOKEN_CALC_STRING_LITERAL;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   357
        case ((Token) ':'): return TOKEN_CALC_COLON;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   358
        //case ((Token) ';'): return TOKEN_CALC_SEMICOLON;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   359
        //case ((Token) '{'): return TOKEN_CALC_LBRACE;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   360
        //case ((Token) '}'): return TOKEN_CALC_RBRACE;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   361
        case ((Token) TOKEN_IDENTIFIER): return TOKEN_CALC_IDENTIFIER;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   362
        case TOKEN_EOI: return 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   363
        case TOKEN_BAD_CHARS: printf("bad chars from lexer\n"); return 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   364
        case TOKEN_PREPROCESSING_ERROR: printf("error from lexer\n"); return 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   365
        default: assert(0 && "unexpected token from lexer\n"); return 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   366
    } // switch
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   367
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   368
    return 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   369
} // convert_to_lemon_token
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   370
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   371
static void MOJOSHADER_compile(const char *filename,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   372
                             const char *source, unsigned int sourcelen,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   373
                             const MOJOSHADER_preprocessorDefine *defines,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   374
                             unsigned int define_count,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   375
                             MOJOSHADER_includeOpen include_open,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   376
                             MOJOSHADER_includeClose include_close,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   377
                             MOJOSHADER_malloc m, MOJOSHADER_free f, void *d)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   378
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   379
    Context ctx;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   380
    if (m == NULL) m = MOJOSHADER_internal_malloc;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   381
    if (f == NULL) f = MOJOSHADER_internal_free;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   382
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   383
    memset(&ctx, '\0', sizeof (Context));
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   384
    ctx.malloc = m;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   385
    ctx.free = f;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   386
    ctx.malloc_data = d;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   387
    ctx.preprocessor = preprocessor_start(filename, source, sourcelen,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   388
                                           include_open, include_close,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   389
                                           defines, define_count, 0, m, f, d);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   390
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   391
    void *pParser = ParseCalculatorAlloc(m, d);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   392
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   393
    #if DEBUG_COMPILER_PARSER
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   394
    ParseCalculatorTrace(stdout, "COMPILER: ");
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   395
    #endif
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   396
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   397
    do {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   398
        ctx.token = preprocessor_nexttoken(ctx.preprocessor,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   399
                                                &ctx.tokenlen,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   400
                                                &ctx.tokenval);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   401
        ParseCalculator(pParser, convert_to_lemon_token(&ctx), 0, &ctx);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   402
    } while (ctx.tokenval != TOKEN_EOI);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   403
    ParseCalculatorFree(pParser, f, d);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   404
}
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   405
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   406
int main(int argc, char **argv)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   407
{
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   408
    const char *ln;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   409
    size_t len = 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   410
    FILE *io = stdin;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   411
    const char *filename = "<stdin>";
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   412
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   413
    while ((ln = fgetln(io, &len)) != NULL)
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   414
    {
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   415
        if ((len == 5) && (memcmp(ln, "quit\n", 5) == 0))
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   416
            break;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   417
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   418
        MOJOSHADER_compile(filename, ln, (unsigned int) len,
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   419
                           NULL, 0, NULL, NULL, NULL, NULL, NULL);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   420
    } // while
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   421
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   422
    fclose(io);
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   423
    return 0;
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   424
} // main
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   425
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   426
// end of calculator.c ...
307e3ab506fa Start of experiment with a basic calculator.
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
   427