Commit graph

85 commits

Author SHA1 Message Date
Randy Heit
e696fff0be Capitalize some names that weren't before.
- Since this caused several duplicate names to creep in, try to be more
  consistant abount name capitalization.
2013-10-29 22:05:49 -05:00
Randy Heit
b227a2f508 Add the basic types to the global symbol table 2013-10-29 22:05:16 -05:00
Randy Heit
03c4244fd8 Accept only one identifier for class names. 2013-10-29 22:05:09 -05:00
Randy Heit
2b96db5fac Do not share constant 1 for enum autoincrements.
- AST nodes cannot be shared, because type conversion changes them in
  place, and what's appropriate for one use is by no means appropriate for
  all uses.
2013-10-25 22:30:25 -05:00
Randy Heit
6384613487 Allow using constants in other constants before their definitions.
- Something like this is now valid:
    const foo = bar + 10;
    const bar = 1000;
2013-10-25 22:30:25 -05:00
Randy Heit
76d2e8cfc4 Set node type when nil-ing an id node.
- Nodes can't stay as type AST_ExprID if they don't also have the
  operation PEX_ID.
2013-10-25 22:30:25 -05:00
Randy Heit
850055a766 Add evaluation of constant unary and binary expressions
- Added ZCCCompiler class as a place to generate IR and symbols from an
  AST. Right now, all it does is simplify constant expressions into
  constant values.
- Do type promotion on the AST where appropriate.
- Added true and false tokens to the parser driver.
2013-10-25 22:30:24 -05:00
Randy Heit
d0968af9a6 Separate the AST from the parser state. 2013-10-25 22:30:24 -05:00
Randy Heit
4bd5bf310b Do not use GT, GTEQ, or NEQ operators in the AST.
- Since the VM doesn't directly support the GT, GTEQ, and NEQ comparisons,
  don't use them in the trees either. Instead, wrap them as LTEQ, LT, and
  EQEQ inside a BoolNot operator.
2013-10-02 23:28:06 -05:00
Randy Heit
a0dbcb5d5b Add TRUE and FALSE terminals to the zcc grammar
- I can't believe I completely forgot to let the parser handle true and
  false literals.
- Consolidate all the %include blocks in zcc-parse.lemon into a single
  one, because Lemon all of a sudden decided it didn't like me having more
  than one in the grammar file.
- Added a PBool type to represent boolean values with.
2013-09-28 21:16:44 -05:00
Randy Heit
743b05189e Give the parser knowledge of constants for unary - and +
- Since the tokenizer never gives the parser negative numbers but always a
  unary minus followed by a positive number, it seems reasonable to make
  the parser smart enough to turn these into negative constants without
  generating extra tree nodes.
- And since we're doing it for unary -, we might as well do it for unary +
  as well and avoid extra nodes when we know we don't need them.
2013-09-12 22:22:43 -05:00
Randy Heit
2a1414ad66 Use labels in autogenerated enum value expressions
- For an enum like this:
    enum { value1 = SOME_NUM*2, value2 };
  Generate an increment expression for value2 of the form
    (add (id value1) 1)
  and not
    (add (* SOME_NUM 2) 1)
2013-09-12 22:06:57 -05:00
Randy Heit
af8e0f2ba6 Represent enumerations as constant definitions
- Instead of representating enumeration values with a special node type,
  use the same ZCC_ConstantDef nodes that const_def produces. These are
  created at the same scope as the ZCC_Enum, rather than being contained
  entirely within it. To mark the end of enums for a single instance of
  ZCC_Enum, a ZCC_EnumTerminator node is now appended to the chain of
  ZCC_ConstantDefs.
2013-09-12 22:00:49 -05:00
Randy Heit
d5fa550118 Make ZCC_TreeNode::AppendSibling() work with lists
- Previously, you could only append lone nodes to ZCC_TreeNode lists.
  Now you can append one list to another.
2013-09-12 22:00:49 -05:00
Randy Heit
33e835b58d Accept name constants in the grammar 2013-09-10 21:56:13 -05:00
Randy Heit
b6e525d935 Add missing closing " for string constants in AST dumps 2013-09-10 21:50:27 -05:00
Randy Heit
52d5e74e7e Mark unsigned constants in AST dumps.
- Add the u suffix to unsigned integer constants printed in AST dumps.
2013-09-10 21:48:15 -05:00
Randy Heit
1b4851224e Let the grammar accept unsigned integer constants 2013-09-10 21:44:32 -05:00
Randy Heit
6545c48e07 Accept constant definitions at global scope 2013-09-10 21:25:50 -05:00
Randy Heit
3044fdd0a9 Use %f instead of %g in AST dumps
- To ensure that floating point constants are identifiable as floating
  point, FLispString::AddFloat() now prints them with %f.
2013-09-10 21:24:32 -05:00
Randy Heit
61666e1515 Consolidate constant expression nodes into a single type
- Instead of having ZCC_ExprString, ZCC_ExprInt, and ZCC_ExprFloat,
  just use a single ZCC_ExprConstant. It should simplify type
  promotion and constant folding in the future.
2013-09-10 21:10:48 -05:00
Randy Heit
f9f8d1e79b Add a type field for ZCC expressions.
- Constants can fill out the type field right away. Other expressions will need
  to wait until a later pass, after names have been resolved, so they get
  initialized to NULL.
2013-09-10 20:50:21 -05:00
Randy Heit
2823ea5de3 Annote AST nodes with source information 2013-08-28 22:59:03 -05:00
Randy Heit
064710422b Accept empty struct and enum definitions (useless as they may be) 2013-08-24 20:32:59 -05:00
Randy Heit
80daf736ec Accept enums and structs defined at global scope 2013-08-24 20:28:26 -05:00
Randy Heit
3ea0d1b444 Add VM opcodes NOP, LANG, and SANG
- To simplify code generation genericizing, add three new opcodes
  * NOP: No-Operation
  * LANG: Load Angle - load a BAM angle into a float reg as degrees
  * SANG: Save Angle - store a float reg into a BEM angle, converting from degrees
2013-08-23 21:46:40 -05:00
Randy Heit
11b588de4a Add names for fallback tokens.
- Fixed: When falling back to the IDENTIFIER token, the identifier it
  would get was undefined, because it never got initialized.
2013-08-02 21:54:50 -05:00
Randy Heit
ff7b1f6e5e Add degree variants of FLOP operations
- Added versions of the trig operations supported by FLOP that can work
  with degrees directly instead of radians.
- Reorder FLOPs into more sensible groupings.
2013-07-28 20:22:47 -05:00
Randy Heit
0603295822 Added EmitParamInt to VMFunctionBuilder 2013-07-27 22:06:14 -05:00
Randy Heit
57bb9c2f7a Better disassembly of FLOP instructions.
- Annotate FLOP instructions with the name of the floating point operation
  indicated by the C field.
2013-07-25 22:29:59 -05:00
Randy Heit
f6bbd5abf7 Simplify AST dumps.
- More forced line breaks.
- Don't use extra parentheses in places where it can still be unambiguous
  without them.
- Don't print the UserType for basic-types that aren't ZCC_UserType.
2013-07-24 21:35:02 -05:00
Randy Heit
7d304a4cb6 Partially revert commit 46c0127
- Being able to omit optional function arguments is not such a nonsensical
  thing after all. However, the previous grammar was still inadequate for
  representing this in a useful way.
2013-07-24 20:59:29 -05:00
Randy Heit
a136ca65ea Allow functions without parameters
- Fixed: Trying to define a function without any parameters would silently
  discard the function, because the declarator tested FuncParams instead
  of FuncName to decide if it was a function.
2013-07-23 20:43:15 -05:00
Randy Heit
67caf3303b Add the array size to ZCC_VarName 2013-07-23 19:59:47 -05:00
Randy Heit
0d25ed8289 state_call needs parenthesis around func_expr_list
- Fixed: state_call needs to enclose func_expr_list in LPAREN/RPAREN
  itself, because func_expr_list doesn't include them. This means it also
  needs a separate production to accept calls without a parameter list.
2013-07-23 19:34:21 -05:00
Randy Heit
46c0127ebb Don't accept function params starting with a comma
- Fixed: func_expr_list would accept nonsense like this:
    Myfunction(, 1, 2);
2013-07-23 19:28:58 -05:00
Randy Heit
aadd4e4de6 ZCCParseNode needs to initialize TopNode
- If the parsing is a complete failure, then TopNode won't ever be set to
  anything during the parsing process.
2013-07-23 18:38:57 -05:00
Randy Heit
733e5fa2e1 Recognize C-style array declarations
- The variable_name production now accepts an optional array size
  argument. (Not yet passed to the AST.)
- The notation for using dotted ID lists as types has been changed from
  [id1.id2] to .id1.id2, beacuse the former conflicts with the notation
  for arrays.
2013-07-19 23:25:01 -05:00
Randy Heit
9cf9226e86 Don't leave open parentheses hanging at line breaks 2013-07-17 23:47:06 -05:00
Randy Heit
c733e4229a Added more linebreaks to AST dumps 2013-07-17 23:47:06 -05:00
Randy Heit
726ecaf01b Added basic pretty printing for AST dumps 2013-07-17 23:47:05 -05:00
Randy Heit
a7bbe299e3 Assignment for expr ::= unary_expr was backwards 2013-07-13 23:25:53 -05:00
Randy Heit
ec32248f31 Set value of assign_op explicitly. 2013-07-13 22:34:33 -05:00
Randy Heit
62fb43d67a Properly pass statements around in the parser. 2013-07-13 22:26:29 -05:00
Randy Heit
6088acd4c0 Add function body to ZCC_FuncDeclarator 2013-07-10 23:26:56 -05:00
Randy Heit
572823046c Add newlines for better readability in AST dump. 2013-07-10 23:26:01 -05:00
Randy Heit
c2e700f116 - Move the RET and RETI final flag into the high bit of the destination selector.
SVN r3922 (scripting)
2012-10-29 01:11:24 +00:00
Randy Heit
6e88529324 - Added a RETI instruction for returning 15-bit signed immediate values.
- Changed Actor's Damage property into an actual function. All access to the damage property
  must now be done through GetMissileDamage. actor->GetMissileDamage(0, 1) is equivalent
  to the former actor->Damage, for the case where actor->Damage was not an expression. (I
  suppose I will probably need to make a thunk for DECORATE expressions that want to read it.)
- Cleaned up some decorate expression evaluation functions that are no longer used.

SVN r3919 (scripting)
2012-10-28 04:36:52 +00:00
Randy Heit
29bc9cbf35 - Change the formatting for floating immediates in the dissasembly to %g.
SVN r3917 (scripting)
2012-10-28 01:16:01 +00:00
Randy Heit
110c253854 - Silence GCC warning stuffs.
SVN r3911 (scripting)
2012-10-26 22:56:50 +00:00