48 Commits

Author SHA1 Message Date
Olaf Seibert
be7bbc5539 Improve comment about the division by multiplying. 2022-06-21 20:02:04 +02:00
Olaf Seibert
13f0fb4d2b Replace the loop that divides by 10 by a divide. 2022-06-19 16:27:20 +02:00
Olaf Seibert
3eb7274625 Add some FP test cases, including some parse errors.
Adjust the parsing a bit, and generate 0 values for bad syntax
like the reference version does.
2022-06-19 16:16:31 +02:00
Olaf Seibert
3109f40bd5 Parse floats using integers (64 bits) only.
The algorithm is close to what the reference version is doing.
2022-06-19 14:56:14 +02:00
Olaf Seibert
ff183c0e36 Improve parsing of symbols.
In particular, don't confuse `4..` with a symbol.
2022-06-04 21:31:06 +02:00
Olaf Seibert
21e9410571 Add evaluation of %+unary expressions.
This is a first step towards expressions like <%1>+1 and even later R1+1.
2021-11-15 18:31:15 +01:00
Olaf Seibert
2df94bfc43 Fix memory leaks in error paths of get_mode(). 2021-11-14 18:58:58 +01:00
Olaf Seibert
1722fae3d4 Rename 'rel' field to 'pcrel'. 2021-07-04 20:02:21 +02:00
Olaf Seibert
34b4815798 Rename undef to flags 2021-06-12 21:44:23 +02:00
Olaf Seibert
7ba6ed13e6 Move some work into expression parse tree constructors 2021-06-12 20:32:49 +02:00
Olaf Seibert
0058db9044 Name the addressing modes. 2021-06-12 18:37:45 +02:00
Olaf Seibert
7bbcbba5f5 Include undefined symbols in the symbol table for listing purposes.
MACRO11 V05.05 does this:

```
.MAIN.  MACRO V05.05  Sunday 18-APR-2021 16:29  Page 1

      1
      2 000000  012700  000000G                 mov #lab1,r0
      3
      4                                         .dsabl gbl
      5
U     6 000004  012700  000000                  mov #lab2,r0
      7
      8         000001                          .end

.MAIN.  MACRO V05.05  Sunday 18-APR-2021 16:29  Page 1-1
Symbol table

LAB1  = ****** GX       LAB2  = ******

. ABS.  000000    000   (RW,I,GBL,ABS,OVR)
        000010    001   (RW,I,LCL,REL,CON)
Errors detected:  1

*** Assembler statistics

Work  file  reads: 0
Work  file writes: 0
Size of work file: 34 Words  ( 1 Pages)
Size of core pool: 9260 Words  ( 35 Pages)
Operating  system: RSX-11M/M-PLUS

Elapsed time: 00:00:00.01
GBL,GBL/-SP=GBL
```
2021-05-30 13:19:39 +02:00
Olaf Seibert
877248f94e More detailed error messages about bad addressing modes
because of gitlab issue #10.
2021-05-28 19:02:31 +02:00
Olaf Seibert
0e373a8570 Make operand parsing error messages more helpful
and add a test that is supposed to exercise them all.
2021-03-14 20:19:15 +01:00
Olaf Seibert
54b73f7f9c Attempt bracketing checking.
Too bad we can't issue a diagnostic here now; we just return failure
and the caller will probably next try a whitespace delimited string
next.
2021-02-18 22:49:52 +01:00
Olaf Seibert
289860e539 Rearrange flow control in brackrange()
which was a bit weird.
This also fixes a potential bug when a bracketed or nested string is not
properly terminated on this line.
2021-02-18 20:56:54 +01:00
Stephen Casner
dcdbc02b2e Add binary operator '_' for left shift
If the command line option yus to allow the underscore character in
symbols is NOT selected, then interpret underscore as a new binary
operator meaning to do a left shift of the left side value by the
number of bit positions indicated by the right side value.  As for the
arithmetic operators, both values must be literal (numeric constants
or symbols equated to a numeric constant).
2021-02-14 14:33:42 +01:00
Olaf Seibert
706e4e9758 Clang found an uninitialized pointer. 2021-01-23 22:06:12 +01:00
Olaf Seibert
e3042c9175 Remove dubious workaround in parse_unary().
The comment "eat first char of illegal label, else endless loop on
implied .WORD" was no longer true. It did reveal some other small
gotchas, which are corrected now as well.
2021-01-23 21:30:52 +01:00
Olaf Seibert
c587587f49 Fix/work around a bug in parse_expr().
There was an obscure bug in parse_expr(), used to evaluate 'if df',
where it could skip past the end of the line marker.

If this happened inside an expanded macro, then after that was the
next line...
In other cases it might be worse.

Now that this is fixed, another check for line end junk can be enabled.
2021-01-23 20:09:32 +01:00
Olaf Seibert
6f1af83101 Check junk at end of line with the repeat directives. 2021-01-23 18:37:47 +01:00
Olaf Seibert
0e3d596daf Allow implicit floating point immediate for FPP instructions
which have an general (source) argument and an AC destination.
There are no FPP instrs which have 1 general source arg;
only with 1 general destination (even TSTF).
2021-01-23 16:11:51 +01:00
Olaf Seibert
96942ca6d6 Simplify rounding: unify cases for different sizes.
Mostly taken from Bjoren Davis in issue #5.
2021-01-21 20:56:22 +01:00
Olaf Seibert
8193f2c2cd Fix (rare) problem of exponent overflow when rounding. 2021-01-21 20:06:53 +01:00
Bjoren Davis
c559f1b65f Bump exponent when needed. 2021-01-21 18:04:49 +01:00
Olaf Seibert
90943eaf49 Add some more tests; rounding of 56-bit mantissa now works. 2021-01-20 19:48:56 +01:00
Olaf Seibert
4f2f813dee Adjust some comments about precision 2021-01-19 10:52:22 +01:00
Olaf Seibert
7705c33076 Use standard type instead of ulong64 2021-01-19 10:52:22 +01:00
Olaf Seibert
0d2b0950be Fix short float rounding
The exponent was adjusted incorrectly.
2021-01-19 10:52:18 +01:00
Olaf Seibert
8aea1498c5 For now, solve the precision problem with brute force,
by using long double where available.
Unfortunately, it won't be available everywhere, so a better solution
would still be nice.
Also, sometimes rounding of smaller sizes doesn't work right yet.
2021-01-19 09:39:02 +01:00
Olaf Seibert
37abe35427 Add some test cases; some are failing so far. 2021-01-18 21:42:18 +01:00
Bjoren Davis
6f7e7963bc small (1 and 2 word) floating point literals not parsed correctly
Fix gitlab issue #5.

The parse_float() function has several bugs:

    1. For 1- and 2-word floats it will always write all 4 bytes if the value is
       exactly 0.
    2. It incorrectly rounds and normalizes 1- and 2-word floats.

To see the issue easily try the following inputs:

     .flt2  1.0
     .flt4  1.0

These will assemble as '040100 000000' and '040200 000000 000000 000000'.
They should both begin '040200'.

In fact the test file test/test-prec.mac is incorrect in its only floating point value:
	.word	^f 1.5		; 040140
should actually assemble as 040300, not 040140 (040140 is actually ^F0.875).
I confirmed this on RT-11 running MACRO V05.06.

I fixed the problem with the following deltas:

[the patch]

The most crucial change is the very last one. 0x200000000000 is actually (1 << 45)
and because ufrac is normalized it means that it will always downshift ufrac by 1.
2021-01-18 20:22:34 +01:00
Olaf Seibert
4916b699fa Add ^pl and ^ph expressions from 2.11BSD's m11.
I hope I understood what this is doing!
2017-04-28 23:02:06 +02:00
Olaf Seibert
fda852a3f1 ^X is not an extension; ^R ^/.../ is.
Adjust comments about that.
2015-11-09 21:13:49 +01:00
Olaf Seibert
0fba6eea33 Use function for creating a literal expression node. 2015-11-08 20:51:45 +01:00
Olaf Seibert
d6ff111149 Introduce a function to create a binary expression node. 2015-11-08 20:51:07 +01:00
Olaf Seibert
9d756361b4 Fix pasto, present since all recorded history.
I don't think it made any practical difference: 2, like 1, is >= 1 and
that is what all the tests of xxx_PREC test.
2015-11-08 17:41:46 +01:00
Olaf Seibert
137a9db671 More tests. Refine string delimiter test for .ASCII a bit.
Make the delimiters for .INCLUDE and .LIBRARY accept the same
delimiters (= is not disallowed, it just makes the line look like
an assignment).
2015-06-04 12:11:14 +02:00
Olaf Seibert
d38f4009c4 Crank up the warning levels, and adjust the code to silence ...
several compilers:
- gcc version 4.5.3 (NetBSD nb2 20110806)
- gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13)
- Ubuntu clang version 3.6.0-2ubuntu1 (tags/RELEASE_360/final) (based on LLVM 3.6.0)

The warnings were mostly about local variables shadowing others,
unused function parameters, and C++ style comments. Some variables were
indeed used before set.

Note that on Linux, using -std=c99 does stupid things like *remove* the
declaration of strdup() from <string.h>. Therefore I've reluctantly used
-std=gnu99.
2015-05-27 21:51:26 +02:00
Olaf Seibert
435cdb0b7f Separate out the string parsing for .include/.library file names and macro arguments.
They behave observably different from generic string parsing and trying
to account for them generically just gets in the way.
.rept is treated the same as a macro.
2015-05-22 16:36:16 +02:00
Olaf Seibert
6c992f6406 Fix some warnings from clang. 2015-05-20 22:54:26 +02:00
Olaf Seibert
b45cf742f7 A trailing comma in a macro call is an empty argument
which should also be counted for the purposes of .NARG.
2015-05-19 22:10:44 +02:00
Olaf Seibert
a8b5272bb8 Nested delimited strings had an infinite loop.
The code for nested and unnested strings was mixed, thereby being too
simple for the nested case. I separated them, which is simpler than
the fixed combined version.
Detected by the macro call
        ..EMIT <$FAC=^D<fb$rea>>
2015-05-12 21:40:13 +02:00
Olaf Seibert
f75f5e1242 Change delimiters of local symbol blocks to be more like page 3-10 of the manual.
Also, to make Kermit sources work, only increase the local symbol block
counter if there actually was a local symbol used in the block.
This way, conditional inclusions (which include source text only in the
first pass) will have less potential for de-synchronisation between the
passes. After all, if the generated internal local symbol names do
not match, phase errors will result (showing themselves as strange label
redefinition problems).
2015-05-10 17:51:32 +02:00
Olaf Seibert
fcc85aa5f5 Fix .asciz <expr>... where an overzealous parsing wants to parse too much of the remaining text
In particular, the example was
	.asciz <cr><lf>/<SOH>/
where it tried to make a division betweem <lf> and the delimited
string /<SOH>/.
2015-05-10 17:32:44 +02:00
Olaf Seibert
184fae4b67 Generalise argument string parsing,
not just for .include. Manual shows various delimiters.
2015-05-08 12:35:57 +02:00
Toby Thain
7ab53debb8 Fix some warnings under clang. 2015-02-01 22:11:54 -05:00
Sergey Svishchev
6a2afc3fa7 Import J Hoppe's 20090427 release from http://retrocmp.com/tools/macro-11-on-windows 2013-02-15 23:50:38 +04:00