Commit Graph

368 Commits

Author SHA1 Message Date
Bill Currie ef4ad52239 Make binary_expr fold constants
This is where constant folding should have happened all along. While
unary_expr should fold constants too, it seems to already try to do so
and it's a bit much of a mess to clean up right now.
2019-06-10 00:36:13 +09:00
Bill Currie e849c2d1ce Mark block expr result as rvalue when used as one
At least for return. There may be other cases that need it, but this
fixes comma-expr.r (minus int->float promotion issues).
2019-06-09 19:29:21 +09:00
Bill Currie 7fce68649a Implement comma expressions
Doesn't quite work (attempt to suppress warning for return a = 3, 5;
failed).
2019-06-09 16:56:20 +09:00
Bill Currie 689d1ad3ec Remove some debug prints 2019-06-09 16:45:01 +09:00
Bill Currie ec89149b29 Build for loop decl inits correctly
The multiple expressions are chained together and evaluate in left to
right order.
2019-06-09 13:54:03 +09:00
Bill Currie 5bd3c8c985 Allow variable declarations in for loops
Matches C, C++ and C#
2019-06-08 21:52:17 +09:00
Bill Currie be4c3a82a2 Detect redefinitions of structs and unions
While the redefinition was being detected, it was misreported as the tag
being wrong, and on the wrong line, too.
2019-06-08 19:25:25 +09:00
Bill Currie 4ef4a7e955 Start work on simple names in symbol tables
I don't remember what the goal was (stopped working on it eight months
ago), but some possibilities include:
 - better handling of nil (have trouble with assigning into struts)
 - automatic forward declarations ala C# and jai (I was watching vids
   about jai at the time)
 - something for pascal
 - simply that the default symbol type should not be var (in which case,
   goal accomplished)
2019-06-06 07:01:44 +09:00
Bill Currie ff5c1cd4c2 Clean up redundant type parameter to initialize_def. 2018-10-15 22:11:20 +09:00
Bill Currie 3295370328 Expose and use field_expr().
This may cause problems later on, but it is needed for the binary_expr()
cleanup.
2013-09-27 23:15:57 +09:00
Bill Currie 7a7a685105 Add support for actual vector expressions.
Currently, they can represent either vectors or quaternions, and the
quaternions can be in either [s, v] form or [w, x, y, z] form.

Many things will not actual work yet as the vector expression needs to be
converted into the appropriate form for assigning the elements to the
components of the "vector" type.
2013-09-27 23:15:57 +09:00
Bill Currie a6cdc8735a Start implementing vec = [x,y,z].
This is a nice feature found in fteqcc (also a bit of a challenge from
Spike). Getting bison to accept the new expression required rewriting the
state expression grammar, so this is mostly for the state expression. A
test to ensure the state expression doesn't break is included.
2013-09-27 23:15:56 +09:00
Bill Currie cef2136050 Implement "not" logic for while and do-while.
This goes towards complementing the "if not" logic extension. I need to
check if fteqcc supports "not" with "while" (the version I have access to
at the moment does not), and also whether it would be good  to support
"not" with "for", and if so, what form the syntax should take.
2013-06-26 23:04:35 +09:00
Bill Currie 8d34d33055 Implement "if not (foo)" syntax.
It is syntactic sugar for if (!(foo)), but is useful for avoiding
inconsistencies between such things as if (string) and if (!string), even
though qcc can't parse if not (string). It also makes for easier to read
code when the logic in the condition is complex.
2013-06-26 23:02:55 +09:00
Bill Currie 46d2959908 Delay calling find_type for enums.
As find_type encodes the type too, calling find_type before the enumerators
have been created causes the type encoding to lose the enumerators.
2013-01-17 20:55:25 +09:00
Bill Currie 76a69d9a53 Implement fteqcc's "nosave" specifier.
Of course, it's "@nosave" for traditional progs, but that's only a define
away.
2013-01-07 14:35:34 +09:00
Bill Currie 1e3154ecd5 Do not always reset current_storage.
resetting current_storage in external_def_list's empty rule breaks the
block storage scopes (extern { ... } etc);
2012-12-25 13:43:52 +09:00
Bill Currie a778d45ebf Drop non-function symbols returned from function_symbol.
In such situations, everything is a mess from earlier errors.
2012-12-23 14:25:09 +09:00
Bill Currie 996b2734a4 Reset current_class in the top-level error rules.
This fixes a weird internal error after a parse error in an ivar
declaration.
2012-12-23 05:57:13 +09:00
Bill Currie ff4b232d92 Reset current_storage when resetting current_symtab.
This helps prevent an internal error caused by ealier errors.
2012-12-22 20:04:11 +09:00
Bill Currie 7d928047ae Remove support for break as an identifier.
I never really liked it, but I have a better solution in the pipe-line.
2012-12-22 16:29:43 +09:00
Bill Currie 6d6f231bd2 Fix mangling of types when attaching protocols.
The protocol attachment test was in the wrong place, and there were some
typos in compare_protocols and procollist_find_protocol.
2012-12-20 13:12:05 +09:00
Bill Currie 3af031c33d Move the rest of the obj specific stuff into class.c.
This gives better hiding of implementation details.
2012-12-20 10:10:41 +09:00
Bill Currie f181772a76 Attach protocolrefs to class types.
The protocolrefs (as protocollist_t) are attached to the type as a
qualifier.
2012-12-20 10:10:41 +09:00
Bill Currie 4868a245b3 Fix the "for new syntax" FIXME.
Empty structs are now (correctly) invalid. The hack of using an empty
struct to represent a handle returned from a builtin has been unnecessary
since opaque structs were implemented: now a pointer to an opaque struct
can be used. This is mostly safe as handles are aways negative and thus
attempting to dereference such a pointer should result in a VM error. It
will be even safer once const is implemented and the pointers can be made
constant (eg, typedef struct handle * const handle;)
2012-12-20 10:10:41 +09:00
Bill Currie 3e94869f1e Remove the function overloading FIXMEs.
It seems they were fixed a long time ago.
2012-12-20 10:10:41 +09:00
Bill Currie c68578d15d Rename CONST to VALUE.
VALUE is a much more accurate name, and this allows for "const" to be
implemented at some stage.
2012-12-20 10:10:41 +09:00
Bill Currie cd7c53d223 Parse id <protocol> and classname <protocol>.
This is needed to allow compile-time protocol conformance checks, though
nothing along those lines has been implemented yet.

id has been changed from TYPE to OBJECT, required to allow id <proto> to be
parsed. OBJECT uses symbol, allowing id to be redefined once suitable work
has been done on the parser.
2012-12-20 10:10:41 +09:00
Bill Currie d6ec944e5f Set a builtin methods func pointer.
Forgetting to set the func pointer is what caused the bogus "does not
respond to" message for -error:.
2012-12-16 12:01:12 +09:00
Bill Currie 7ccfd7b9e0 Fix the wrong space for static vars.
Turns out there was only one place to fix (for qc, anyway: I don't have
tests for qp yet). func-static now passes :)

Hmm, how to test for static var naming... (not implemented yet)
2012-12-04 14:25:06 +09:00
Bill Currie 5725c5124c Rename the storage_class_t enum values.
With the intoduction of the statement type enum came a prefix clash. As
"st" makes sense for "statement type", I decided that "storage class"
should be "sc". Although there haven't been any problems as of yet, I
decided it would be a good idea to clean up the clash now. It also helps
avoid confusion (I was a bit surprised after working with st_assign etc to
be reminded of st_extern etc).
2012-12-02 10:11:30 +09:00
Bill Currie 54289da416 Fix the line number info for else.
It has bugged me for a while that the goto for else would display the if's
source line.
2012-12-01 16:37:38 +09:00
Bill Currie 5cfeb7809f Fix a missing ; 2012-11-20 17:11:39 +09:00
Bill Currie f307c7bebc Rework the unary_expr grammar to allow ++*foo.
This required throwing out the primary rules that snax did up to help me
with conflicts many years ago, but they were now getting in the way. Now
the productions from primary are merged in with unary_expr.
2012-11-09 12:32:38 +09:00
Bill Currie f14d8060e0 Merge qfpc into qfcc.
Since gnu bison and flex are required anyway, no harm in using their api
prefix options. Now, qfcc can compile both QC/Ruamoko and Pascal files
(Pascal is (currently?) NOT supported in progs.src mode), selecting the
language based on the extension: .r, .qc and .c select QC/Ruamoko, .pas and
.p select Pascal, while anything else is treated as an object file (as
before).
2012-10-26 16:01:41 +09:00
Bill Currie dbc203b625 And a few more bits of whitespace. 2012-05-23 08:21:27 +09:00
Bill Currie bc1b483525 Nuke the rcsid stuff.
It's pretty useless in git.
2012-04-22 10:56:32 +09:00
Bill Currie 617e70c8e3 Clean up a bunch of bison unused warnings. 2011-06-21 19:52:47 +09:00
Bill Currie 1617f0765e Support the default type without segfaulting. 2011-03-25 09:59:48 +09:00
Bill Currie a7cfe3b215 Preserve the current class across protocol defs.
It seems that protocol defs are allowed in class implementations, so don't
let the protocol def kill the current class for the class implementation.
2011-03-24 11:55:17 +09:00
Bill Currie 71af121665 Detect missing @end tags.
Give a warning when @end is forgotten in class implementations.
2011-03-24 11:44:22 +09:00
Bill Currie f1d9570dc8 Fix constant value type handling.
Rename immediate.[ch] to value.[ch] and clean up the mess.

Add convert_value() to convert the type of a value (only scalar types).
2011-03-22 12:24:39 +09:00
Bill Currie 6312ccba81 Fix storage class blocks.
@extern { defs }; etc
2011-03-07 20:51:51 +09:00
Bill Currie 4db8ebb6af Support qcc style local function variables. 2011-03-07 20:04:05 +09:00
Bill Currie 853cc53d0f FIx the handling of storage class. 2011-03-07 17:49:01 +09:00
Bill Currie 16103f9018 Fix param mangling for qc style functions. 2011-03-07 10:43:38 +09:00
Bill Currie 28f4de94d2 Fix switch statements so the work in the new scheme.
Convert case labels to be the same type as the switch expression.
Use alias expressions for the various test expressions.
2011-03-06 00:29:29 +09:00
Bill Currie 8cfa80b5d4 Implement think expressions. 2011-03-05 18:01:37 +09:00
Bill Currie c5ecc170b6 Give labels a usage count to detect unused labels. 2011-03-03 15:28:49 +09:00
Bill Currie 76f912c7a1 Fix function typedefs. 2011-03-02 22:23:24 +09:00