Commit Graph

13 Commits

Author SHA1 Message Date
Kartik Agaram b3998440f3 6468 2020-06-05 13:56:19 -07:00
Kartik Agaram 0ef7f1d2d6 6160 - plan for safe heap access
Based on apps/handle.subx (commit 4894), but we're able to simplify it
further now that we know more about the situation we find ourselves in.
6 instructions, zero pushes or pops.

Before I can start building this, I need to reorganize my use of handles.
They're going to be fat pointers so we can't store them in registers anymore.
2020-03-21 22:43:43 -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 92ca78429c 6131 - operating on arrays on the stack 2020-03-12 00:17:35 -07:00
Kartik Agaram afc0be47a5 6129 2020-03-11 20:56:27 -07:00
Kartik Agaram 44798a2e2c 6097
I thought I needed to support compute-offset with literal index, but in
that case might as well just use an index literal directly. The 'index'
instruction with literals already supports non-power-of-2 sizes.
2020-03-07 19:55:03 -08:00
Kartik Agaram 3cf0315859 6094 - new 'compute-offset' instruction
If indexing into a type with power-of-2-sized elements we can access them
in one instruction:

  x/reg1: (addr int) <- index A/reg2: (addr array int), idx/reg3: int

This translates to a single instruction because x86 instructions support
an addressing mode with left-shifts.

For non-powers-of-2, however, we need a multiply. To keep things type-safe,
it is performed like this:

  x/reg1: (offset T) <- compute-offset A: (addr array T), idx: int
  y/reg2: (addr T) <- index A, x

An offset is just an int that is guaranteed to be a multiple of size-of(T).
Offsets can only be used in index instructions, and the types will eventually
be required to line up.

In the process, I have to expand Input-size because mu.subx is growing
big.
2020-03-07 17:40:45 -08:00
Kartik Agaram 8b85a07f97 6059 2020-02-27 17:03:00 -08:00
Kartik Agaram fee1bbd8b4 6041 - array indexing starting to work
And we're using it now in factorial.mu!

In the process I had to fix a couple of bugs in pointer dereferencing.

There are still some limitations:
a) Indexing by a literal doesn't work yet.
b) Only arrays of ints supported so far.

Looking ahead, I'm not sure how I can support indexing arrays by non-literals
(variables in registers) unless the element size is a power of 2.
2020-02-21 10:09:59 -08:00
Kartik Agaram 7f453fe085 6039 2020-02-21 00:18:41 -08:00
Kartik Agaram 01a28c56c7 6019 - finish supporting all branch primitives
I'd been thinking I didn't need unconditional `break` instructions, but
I just realized that non-local unconditional breaks have a use. Stop over-thinking
this, just support everything.

The code is quite duplicated.
2020-02-18 00:07:11 -08:00
Kartik Agaram 819513fb53 5969 2020-02-01 12:21:48 -08:00
Kartik Agaram 924ed08aca 5968 2020-02-01 12:14:20 -08:00