Commit Graph

6690 Commits

Author SHA1 Message Date
Kartik Agaram 90b374622c 6690 2020-07-30 21:39:19 -07:00
Kartik Agaram de8ec47d60 6689 - some little white lies to GitHub 2020-07-30 21:38:00 -07:00
Kartik Agaram ca9455ba82 6688 2020-07-30 21:11:56 -07:00
Kartik Agaram 3001235028 6687 - stream-empty? and stream-full? 2020-07-30 19:34:29 -07:00
Kartik Agaram ca237761bf 6686 2020-07-30 19:22:40 -07:00
Kartik Agaram 9cbd4199f3 6685 2020-07-29 22:04:13 -07:00
Kartik Agaram bae22d720f 6684 - experimental primitives for streams
This is a hacky special case. The alternative would be more general support
for generics.

One observation: we might be able to type-check some primitives using `sig`s.
Only if they don't return anything, since primitives usually need to support
arbitrary registers. I'm not doing that yet, though. It eliminates the
possibility of writing tests for them in mu.subx, which can't see 400.mu.
But it's an alternative:

  sig allocate out: (addr handle _)
  sig populate out: (addr handle array _), n: int
  sig populate-stream out: (addr handle stream _), n: int
  sig read-from-stream s: (addr stream _T), out: (addr _T)
  sig write-to-stream s: (addr stream _T), in: (addr _T)

We could write the tests in Mu. But then we're testing behavior rather
than the code generated. There are trade-offs. By performing type-checking
in mu.subx I retain the option to write both kinds of tests.
2020-07-29 21:41:29 -07:00
Kartik Agaram 129bb8117b 6683 2020-07-28 21:41:00 -07:00
Kartik Agaram b8df5340fa 6682 - experimental support for streams and slices
Slices contain `addr`s so the same rules apply to them. They can't be stored
in structs and so on. But they may be an efficient temporary while parsing.

Streams are currently a second generic type after arrays, and gradually
strengthening the case to just bite the bullet and support first-class
generics in Mu.
2020-07-28 21:37:32 -07:00
Kartik Agaram e2c22ad4d9 6681 2020-07-26 22:51:21 -07:00
Kartik Agaram f7a90521d1 6680 2020-07-26 22:08:22 -07:00
Kartik Agaram 44b1636e2d 6679 2020-07-25 20:53:47 -07:00
Kartik Agaram 437838b40d 6678 2020-07-25 19:14:05 -07:00
Kartik Agaram d8c2a0e704 6677 - prototype: spreadsheet for trees 2020-07-25 19:12:09 -07:00
Kartik Agaram 2b1737363f 6676 - type checks for 'lookup' 2020-07-25 19:11:51 -07:00
Kartik Agaram ab8d4b593b 6675 2020-07-25 17:11:45 -07:00
Kartik Agaram de0e57d3ce 6674 2020-07-25 15:35:43 -07:00
Kartik Agaram cd07e9b22c 6673 2020-07-25 15:11:08 -07:00
Kartik Agaram 4dc20af1bf 6672 - error on addr or array inside type 2020-07-25 15:08:52 -07:00
Kartik Agaram bf0a6b69dc 6671 - bugfix in generic functions
We need to remember to clear local variables. And there's a good question
here of how Mu supports variables of type stream or table. Or other user-defined
types that inline arrays.
2020-07-25 11:04:34 -07:00
Kartik Agaram 32055c369b 6670 - generic functions
Function signatures can now take type parameters starting with '_'.

Type parameters in a signature match any concrete type in the call. But
they have to be consistent within a single call.

Things I considered but punted on for now:
- having '_' match anything without needing to be consistent. Wildcards
  actually seem harder to understand.
- disallowing top-level '_' types. I'll wait until a concrete use case
  for disallowing.

We still don't support *defining* types with type parameters, so for now
this is only useful for calling functions on arrays or streams or handles.
2020-07-25 10:21:22 -07:00
Kartik Agaram ba4e33f711 tmp - snapshot of type-parameter support
I think I've got all the stack management down. Time now for the business
logic. There's one failing test.
2020-07-25 09:36:43 -07:00
Kartik Agaram 2a1b9d32d7 6668
type-match? is no longer symmetric; we have to be careful about arg ordering.
2020-07-24 22:10:09 -07:00
Kartik Agaram 750f490b4d 6667 2020-07-24 21:40:18 -07:00
Kartik Agaram 39a4cbdf61 6666 - types starting with '_' now match anything
We still need to perform pattern matching.
2020-07-24 21:34:36 -07:00
Kartik Agaram a4c31549f9 6665 2020-07-24 21:29:20 -07:00
Kartik Agaram 511844ffb9 6664 2020-07-24 21:25:46 -07:00
Kartik Agaram c9ea1bd55a 6663 2020-07-24 21:25:46 -07:00
Kartik Agaram ac6af96c5a 6662 - start support for generics
Mu will be a language with generics -- but no static dispatch.
2020-07-20 22:30:02 -07:00
Kartik Agaram 3a5512389e 6661 2020-07-20 22:17:57 -07:00
Kartik Agaram 97dbe33fd4 6660 2020-07-20 21:03:55 -07:00
Kartik Agaram 01b72aa064 6659
Tighten up some function signatures.
2020-07-18 19:33:39 -07:00
Kartik Agaram 02b7f9bd89 6658 2020-07-18 15:56:32 -07:00
Kartik Agaram 28b25a4893 6657 2020-07-16 22:34:57 -07:00
Kartik Agaram 571dd3e23c 6656 2020-07-16 22:20:46 -07:00
Kartik Agaram 0085782f1b 6655 2020-07-16 22:03:40 -07:00
Kartik Agaram a3d6672bca 6654 2020-07-16 21:46:41 -07:00
Kartik Agaram e5f9d8123a 6653 - render deeper trees with a single child
Every time you press a key the depth increases by 1, and then the tree
re-renders.
2020-07-16 21:38:40 -07:00
Kartik Agaram 93c94c6fee 6652 - function to divide whole numbers 2020-07-16 21:30:19 -07:00
Kartik Agaram 0e38e7e868 6651
baby steps: rendering a tree node with just one child
2020-07-16 21:01:56 -07:00
Kartik Agaram 8cc1ed72c3 6650 - bit-shift operations really working
test input:

  fn foo {
    var y/edx: int <- copy 0
    y <- shift-left 2
    y <- shift-right 2
    y <- shift-right-signed 2
    var x: int
    shift-left x, 2
    shift-right x, 2
    shift-right-signed x, 2
  }

output:

  foo:
    # . prologue
    55/push-ebp
    89/<- %ebp 4/r32/esp
    {
  $foo:0x00000001:loop:
      ff 6/subop/push %edx
      ba/copy-to-edx 0/imm32
      c1/shift 4/subop/left %edx 2/imm8
      c1/shift 5/subop/right-padding-zeroes %edx 2/imm8
      c1/shift 7/subop/right-preserving-sign %edx 2/imm8
      68/push 0/imm32
      c1/shift 4/subop/left *(ebp+0xfffffff8) 2/imm8
      c1/shift 5/subop/right-padding-zeroes *(ebp+0xfffffff8) 2/imm8
      c1/shift 7/subop/right-preserving-sign *(ebp+0xfffffff8) 2/imm8
      81 0/subop/add %esp 0x00000004/imm32
      8f 0/subop/pop %edx
    }
  $foo:0x00000001:break:
    # . epilogue
    89/<- %esp 5/r32/ebp
    5d/pop-to-ebp
    c3/return

test input 2:

  $ cat x.mu
  fn main -> o/ebx: int {
    o <- copy 3
    o <- shift-left 2
  }

output 2:

  $ ./translate_mu x.mu
  $ ./a.elf
  $ echo $?
  12
2020-07-14 22:53:56 -07:00
Kartik Agaram fd100782cb 6649
Bit-shifts aren't quite right yet. We need to emit /imm8 rather than /imm32.

This commit introduces the field, though we don't use it yet.
2020-07-14 22:33:00 -07:00
Kartik Agaram ab26c894c8 6648 - bit-shift instructions in Mu
I'm not happy with the names.
2020-07-14 21:42:20 -07:00
Kartik Agaram 42b0c1139c 6647 2020-07-14 21:24:31 -07:00
Kartik Agaram 32b904728a 6646 - in-progress prototype: tree editor 2020-07-14 04:34:21 -07:00
Kartik Agaram 5e0ae917d0 6645 - heap allocations in Mu
- allocate var
- populate var, n

Both rely on the type of `var` to compute the size of the allocation. No
need to repeat the name of the type like in C, C++ or Java.
2020-07-13 22:21:26 -07:00
Kartik Agaram 4cb4d4d2d8 6644 2020-07-13 22:08:55 -07:00
Kartik Agaram e2b55208b2 6643 2020-07-13 21:52:26 -07:00
Kartik Agaram 6b8a3a94b1 6642 2020-07-12 21:34:04 -07:00
Kartik Agaram 8c78c3eb48 6641 2020-07-12 21:01:34 -07:00