Commit Graph

299 Commits

Author SHA1 Message Date
Kartik Agaram 9483fdc1fb 6591 2020-06-28 23:17:34 -07:00
Kartik Agaram 4ddc2620f7 6590 2020-06-28 23:10:45 -07:00
Kartik Agaram 896e3bcfb2 6589 2020-06-28 23:09:10 -07:00
Kartik Agaram d31bd529f7 6588 2020-06-28 18:49:50 -07:00
Kartik Agaram 52d3ee0326 6587 2020-06-28 14:35:45 -07:00
Kartik Agaram f7a174c2a1 6586 - error-checking for 'get' stmts feels done 2020-06-28 14:23:31 -07:00
Kartik Agaram 1a89b13b9c 6585 2020-06-28 11:50:50 -07:00
Kartik Agaram bf4fbab76d 6584 2020-06-28 10:19:02 -07:00
Kartik Agaram 60bffdaa49 6583 2020-06-28 09:53:32 -07:00
Kartik Agaram 76a669f689 6582 2020-06-28 09:10:16 -07:00
Kartik Agaram fbc4544ff8 6581 2020-06-28 08:49:08 -07:00
Kartik Agaram f58a6acc3f 6579 2020-06-28 00:55:31 -07:00
Kartik Agaram 1da16dd6cb 6578 - redo error if 'get' on unknown field
This commit reimplements commit 6515 to happen during type-checking rather
than as early as possible. That way we naturally get a more informative
error message.
2020-06-27 21:03:43 -07:00
Kartik Agaram ab42709e14 6577 2020-06-27 14:30:07 -07:00
Kartik Agaram 14d9b56668 6576 2020-06-27 14:23:50 -07:00
Kartik Agaram ca9dec80b6 6575 2020-06-27 12:13:43 -07:00
Kartik Agaram 3b02c3dfa2 6572
Small change to mu.subx to keep the treeshaker working with it. That's
currently the only place where we prevent jumps across 'functions'.
2020-06-21 17:31:38 -07:00
Kartik Agaram 6bfb565819 6570 - error on use of a clobbered var
All tests now passing, and factorial.mu and all other apps now working.
The new checks caught one problem in a few prototypes.
2020-06-21 17:08:03 -07:00
Kartik Agaram c70beadc7a 6562
The new failing test is now passing, and so is this manual test that had
been throwing a spurious error:
  fn foo {
    var a/eax: int <- copy 0
    var b/ebx: int <- copy 0
    {
      var a1/eax: int <- copy 0
      var b1/ebx: int <- copy a1
    }
    b <- copy a
  }

However, factorial.mu is still throwing a spurious error.

Some history on this commit's fix: When I moved stack-location tracking
out of the parsing phase (commit 6116, Mar 10) I thoughtlessly moved block-depth
tracking as well. And the reason that happened: I'd somehow gotten by without
ever cleaning up vars from a block during parsing. For all my tests, this
is a troubling sign that I'm not testing enough.

The good news: clean-up-blocks works perfectly during parsing.
2020-06-21 11:06:25 -07:00
Kartik Agaram d1ad96e038 6556 - check for uses of clobbered vars
Now all tests passing again. In the process I found a bug where one of
my tests actually generated incorrect code.
2020-06-19 23:25:43 -07:00
Kartik Agaram 4d2f171ce1 6553 - Mu: disallow registers esp and ebp 2020-06-19 20:52:37 -07:00
Kartik Agaram 88908608b0 6550 - type-checking for function calls
There were a couple of benign type errors in arith.mu but nowhere else.
2020-06-18 08:57:48 -07:00
Kartik Agaram 9ab613b233 6549 - starting on type checking 2020-06-17 13:59:22 -07:00
Kartik Agaram 5a6d2d0db7 6528 2020-06-15 16:57:39 -07:00
Kartik Agaram 43957d3ce5 6525 2020-06-15 14:16:38 -07:00
Kartik Agaram 39bcd3a8bc 6524 2020-06-15 14:11:11 -07:00
Kartik Agaram 532068bfc6 6523
Still some issues; add some tests. I have more that were passing a couple
of days ago but aren't currently.
2020-06-15 14:06:30 -07:00
Kartik Agaram 89c2b59a5f 6522 - redo support for 'byte'
Before: bytes can't live on the stack, so size(byte) == 1 just for array
elements.

After: bytes mostly can't live on the stack except for function args (which
seem too useful to disallow), so size(byte) == 4 except there's now a new
primitive called element-size for array elements where size(byte) == 1.

Now apps/browse.subx starts working again.
2020-06-15 14:02:41 -07:00
Kartik Agaram 5945986cc5 6521 - new primitive: array size in bytes 2020-06-14 00:40:16 -07:00
Kartik Agaram ad61776f49 6520 - new app: parse-int
Several bugs fixed in the process, and expectation of further bugs is growing.
I'd somehow started assuming I don't need to have separate cases for rm32
as a register vs mem. That's not right. We might need more reg-reg Primitives.
2020-06-14 00:28:23 -07:00
Kartik Agaram 57f92a9334 6518 - extra args through a whole swathe of places
Most unbelievably, I'd forgotten to pass the output 'out' arg to 'lookup-var'
long before the recent additions of 'err' and 'ed' args. But things continued
to work because an earlier call just happened to leave the arg at just
the right place on the stack. So we only caught all these places when we
had to provide error messages.
2020-06-13 23:05:51 -07:00
Kartik Agaram ef845524e9 6516 - operations on bytes
Byte-oriented addressing is only supported in a couple of instructions
in SubX. As a result, variables of type 'byte' can't live on the stack,
or in registers 'esi' and 'edi'.
2020-06-13 20:23:51 -07:00
Kartik Agaram 7e55a20ff4 6515 - error if 'get' on unknown field
We can't yet say in the error message precisely where the 'get' occurs.
2020-06-12 23:04:22 -07:00
Kartik Agaram 0e20925078 6511 - start of error-checking
We now raise an error if a variable is declared on the stack with an initializer.
And there are unit tests for this functionality.
2020-06-12 00:43:50 -07:00
Kartik Agaram 73cec3939f 6509 - mu.subx: exit-descriptors everywhere 2020-06-11 08:01:37 -07:00
Kartik Agaram 80f53f4a18 6508 - support null exit-descriptor 2020-06-10 23:34:42 -07:00
Kartik Agaram 7dac9ade15 6507 - use syscall names everywhere 2020-06-10 23:09:30 -07:00
Kartik Agaram 8a065c536e 6479
Fix a stray copy-paste when deciding whether to emit spills for registers
(commit 6464).
2020-06-05 22:06:13 -07:00
Kartik Agaram 8122f5d391 6477
I had a little "optimization" to avoid creating nested blocks if "they weren't
needed". Except, of course, they were. Lose the optimization. Sometimes
we create multiple jumps when a single one would suffice. Ignore that for
now.
2020-06-05 21:54:33 -07:00
Kartik Agaram cde591e03e 6466 2020-06-04 21:25:38 -07:00
Kartik Agaram 20411cc442 6464 - support temporaries in fn output registers
The rule: emit spills for a register unless the output is written somewhere
in the current block after the current instruction. Including in nested
blocks.

Let's see if this is right.
2020-06-04 20:28:27 -07:00
Kartik Agaram 04b3afd67e 6463 - clean up some duplication
Rather than have two ways to decide whether to emit push/pop instructions,
just record for each var on the 'vars' stack whether we emitted a push
for it, and reuse the decision to emit a pop.
2020-06-03 23:40:52 -07:00
Kartik Agaram da1a29f121 6462
Stack bug.
2020-06-03 23:09:00 -07:00
Kartik Agaram 91c80ca32c 6461 2020-06-03 22:36:35 -07:00
Kartik Agaram 5aed53d809 6460 2020-06-03 22:32:24 -07:00
Kartik Agaram 69a29fc62c 6459 2020-06-03 00:27:01 -07:00
Kartik Agaram e38a95ecd9 6458 2020-06-03 00:20:05 -07:00
Kartik Agaram 242a50f229 6441
Just always flush Stdout when printing numbers.
2020-05-29 16:44:40 -07:00
Kartik Agaram eb40c70e26 6440
Minor reordering; the hacky flush-stdout is now only needed if we ever
call print-int32-to-screen.
2020-05-29 16:41:51 -07:00
Kartik Agaram 967d11f102 6424 2020-05-28 22:48:40 -07:00
Kartik Agaram b22fa8afd8 6423 - done with sample app 'print-file'
Observations:
  - the orchestration from 'in' to 'addr-in' to '_in-addr' to 'in-addr'
    is quite painful. Once to turn a handle into its address, once to turn
    a handle into the address of its payload, and a third time to switch
    a variable out of the overloaded 'eax' variable to make room for read-byte-buffered.
  - I'm starting to use SubX as an escape hatch for features missing in Mu:
    - access to syscalls (which pass args in registers)
    - access to global variables
2020-05-28 22:41:26 -07:00
Kartik Agaram 583a966d3e 6422 - size-of for handles 2020-05-28 22:31:52 -07:00
Kartik Agaram 3962ac5959 6419 - new primitive for opening files 2020-05-28 21:33:04 -07:00
Kartik Agaram dd6e4bc789 6415 2020-05-27 23:48:27 -07:00
Kartik Agaram d3bca9dbfe 6413
Fix CI.
2020-05-27 01:53:16 -07:00
Kartik Agaram 9511ff5cd7 6409 - primitives for text-mode UIs 2020-05-27 00:09:22 -07:00
Kartik Agaram 3b5b19df66 6406 - primitive 'copy-handle' 2020-05-25 19:26:18 -07:00
Kartik Agaram d1179723a9 6394 - a catastrophic bug
How did new-literal ever work?! Somehow we had eax silently being clobbered
without affecting behavior over like 5 apps. Unsafe languages suck.

Anyways, factorial.mu is now part of CI.
2020-05-24 20:54:12 -07:00
Kartik Agaram 4d14c3fefd 6393 - start running .mu apps in CI 2020-05-24 20:36:31 -07:00
Kartik Agaram 27b1e19ebe 6392 - 'length' instruction done in all complexity 2020-05-24 19:46:47 -07:00
Kartik Agaram 1eecd0934f 6391 2020-05-24 16:42:26 -07:00
Kartik Agaram 156763463d 6390 - return `length` in elements 2020-05-24 14:48:41 -07:00
Kartik Agaram 4335309233 6388 - fix regression #1 2020-05-24 00:51:52 -07:00
Kartik Agaram e992b940e4 6387 2020-05-23 13:01:39 -07:00
Kartik Agaram 5bc9a5b72e update binaries
CI should start passing again now.
2020-05-22 16:59:53 -07:00
Kartik Agaram 1f38b75e31 6219 2020-05-18 00:43:34 -07:00
Kartik Agaram 6a1cc7d65a 6216 2020-05-05 14:55:52 -07:00
Kartik Agaram 84a0297229 6208 2020-04-22 16:34:08 -07:00
Kartik Agaram d6f9813650 6205
Rip out scaffolding for function overloading.
2020-04-15 16:25:04 -07:00
Kartik Agaram d70fca1c3f 6204 2020-04-15 16:09:04 -07:00
Kartik Agaram 0671315c1a 6203 2020-04-12 02:33:01 -07:00
Kartik Agaram 677f98c6f2 6184
Why the heck are we bumping this pointer? Seems like a bug.
2020-04-05 00:05:36 -07:00
Kartik Agaram bfcc0f858a 6182 - start of support for safe handles
So far it's unclear how to do this in a series of small commits. Still
nibbling around the edges. In this commit we standardize some terminology:

The length of an array or stream is denominated in the high-level elements.
The _size_ is denominated in bytes.

The thing we encode into the type is always the size, not the length.

There's still an open question of what to do about the Mu `length` operator.
I'd like to modify it to provide the length. Currently it provides the
size. If I can't fix that I'll rename it.
2020-04-03 12:35:53 -07:00
Kartik Agaram f730f2f2c7 6181 2020-04-03 01:05:01 -07:00
Kartik Agaram df609237c1 6158 - standardize opcode names
At the lowest level, SubX without syntax sugar uses names without prepositions.
For example, 01 and 03 are both called 'add', irrespective of source and
destination operand. Horizontal space is at a premium, and we rely on the
comments at the end of each line to fully describe what is happening.

Above that, however, we standardize on a slightly different naming convention
across:
  a) SubX with syntax sugar,
  b) Mu, and
  c) the SubX code that the Mu compiler emits.

Conventions, in brief:
  - by default, the source is on the left and destination on the right.
    e.g. add %eax, 1/r32/ecx ("add eax to ecx")
  - prepositions reverse the direction.
    e.g. add-to %eax, 1/r32/ecx ("add ecx to eax")
         subtract-from %eax, 1/r32/ecx ("subtract ecx from eax")
  - by default, comparisons are left to right while 'compare<-' reverses.

Before, I was sometimes swapping args to make the operation more obvious,
but that would complicate the code-generation of the Mu compiler, and it's
nice to be able to read the output of the compiler just like hand-written
code.

One place where SubX differs from Mu: copy opcodes are called '<-' and
'->'. Hopefully that fits with the spirit of Mu rather than the letter
of the 'copy' and 'copy-to' instructions.
2020-03-21 16:51:52 -07:00
Kartik Agaram c6886c1c97 6157 2020-03-21 15:07:59 -07:00
Kartik Agaram c48ce3c8bf 6153 - switch 'main' to use Mu strings
At the SubX level we have to put up with null-terminated kernel strings
for commandline args. But so far we haven't done much with them. Rather
than try to support them we'll just convert them transparently to standard
length-prefixed strings.

In the process I realized that it's not quite right to treat the combination
of argc and argv as an array of kernel strings. Argc counts the number
of elements, whereas the length of an array is usually denominated in bytes.
2020-03-15 21:03:12 -07:00
Kartik Agaram f559236bdf 6152 - fix regression in factorial.mu
I had to amend commit 6148 three times yesterday as I kept finding bugs
by inspection. And yet I stubbornly thought I didn't need a test.
2020-03-15 16:44:55 -07:00
Kartik Agaram abb66df2c7 6150 - call-by-reference is working 2020-03-14 16:04:57 -07:00
Kartik Agaram afa4d6bb4c 6149 - pass multi-word objects to functions
This is quite inefficient; don't use it for very large objects.
2020-03-14 15:46:38 -07:00
Kartik Agaram 9655878e1b 6148 2020-03-14 15:31:35 -07:00
Kartik Agaram 999292dfdd 6147 2020-03-14 15:15:46 -07:00
Kartik Agaram 114641e2c8 6145 - 'address' operator
This could be a can of worms, but I think I have a set of checks that will
keep use of addresses type-safe.
2020-03-14 14:46:45 -07:00
Kartik Agaram ff0f216b41 6133 2020-03-12 00:45:17 -07:00
Kartik Agaram b50c0e3279 6132 2020-03-12 00:36:36 -07:00
Kartik Agaram 92ca78429c 6131 - operating on arrays on the stack 2020-03-12 00:17:35 -07:00
Kartik Agaram 0aa7420745 6128 - arrays on the stack 2020-03-11 19:55:45 -07:00
Kartik Agaram 15655a1246 6126 - support 8-byte register names
Using these is quite unsafe. But what isn't, here?
2020-03-11 18:16:56 -07:00
Kartik Agaram 39eb1e4963 6125 2020-03-11 17:34:48 -07:00
Kartik Agaram f2d6bb1cb8 6124 2020-03-11 17:30:06 -07:00
Kartik Agaram 28746b3666 6123 - runtime helper for initializing arrays
I built this in 3 phases:
a) create a helper in the bootstrap VM to render the state of the stack.
b) interactively arrive at the right function (tools/stack_array.subx)
c) pull the final solution into the standard library (093stack_allocate.subx)

As the final layer says, this may not be the fastest approach for most
(or indeed any) Mu programs. Perhaps it's better on balance for the compiler
to just emit n/4 `push` instructions.

(I'm sure this solution can be optimized further.)
2020-03-11 17:21:59 -07:00
Kartik Agaram bfb7c60135 6122 2020-03-10 19:30:03 -07:00
Kartik Agaram 3ca9742e6e 6118 - support records on the stack 2020-03-10 16:39:06 -07:00
Kartik Agaram fed9e7135c 6116 - stack locations now computed during codegen
We can't do it during parsing time because we may not have all type definitions
available yet. Mu supports using types before defining them.

At first I thought I should do it in populate-mu-type-sizes (appropriately
renamed). But there's enough complexity to tracking when stuff lands on
the stack that it's easiest to do while emitting code.

I don't think we need this information earlier in the compiler. If I'm
right, it seems simpler to colocate the computation of state close to where
it's used.
2020-03-10 16:20:33 -07:00
Kartik Agaram 9f8524a95c 6115 2020-03-10 15:19:18 -07:00
Kartik Agaram fdce202105 6113 2020-03-10 14:08:59 -07:00
Kartik Agaram dd0cdc6b80 6112
Move computation of offsets to record fields into the new phase as well.
Now we should be robust to type definitions in any order.
2020-03-08 22:44:56 -07:00
Kartik Agaram c8784d1c0f 6111
Move out total-size computation from parsing to a separate phase.

I don't have any new tests yet, but it's encouraging that existing tests
continue to pass.

This may be the first time I've ever written this much machine code (with
mutual recursion!) and gotten it to work the first time.
2020-03-08 18:20:16 -07:00
Kartik Agaram ab74038c0d 6109 2020-03-08 17:12:06 -07:00
Kartik Agaram c67b26bbcb 6108 2020-03-08 17:09:27 -07:00