Commit Graph

67 Commits

Author SHA1 Message Date
Ayke van Laethem 83ad0b6137 all: move bootstrapping IR to Go runtime
This has the benefit of not requiring a 'runtime' IR file, so that
complete relocatable files can be built without requiring input IR.
This makes the compiler a lot easier to use without the Makefile.

Code size is not affected.
2018-09-04 21:18:26 +02:00
Ayke van Laethem a7fcef62e0 compiler: implement comparing interfaces to nil
Comparing an interface to nil is easy, as the dynamic type is also nil.
Comparing the dynamic values (when the dynamic types match) is much
harder and depends on reflection capabilities, so is not yet implemented.
2018-09-03 01:13:07 +02:00
Ayke van Laethem ebd87ce4cd compiler: implement []byte(str) 2018-09-03 00:21:33 +02:00
Ayke van Laethem 9519f989bc runtime/scheduler: make debugging easier + rename some functions
This shouldn't affect functionality but makes debugging a whole lot
easier. A scheduler is difficult so make it easy to debug.
2018-09-02 19:30:13 +02:00
Ayke van Laethem 8ba3fef7d7 runtime/scheduler: always update task state
Not updating it only saves 4 bytes and makes debugging harder.
2018-09-02 19:28:41 +02:00
Ayke van Laethem d183f12395 nrf: fix sleep
For some reason, the old behavior stopped working at some point (maybe
at the nrfx update?). Change sleep behavior to be more correct.
2018-09-02 19:20:05 +02:00
Ayke van Laethem 88b6b2e7f5 Optimize/eliminate bounds checking
TODO: do better at it by tracking min/max values of integers. The
following straightforward code doesn't have its bounds checks removed:

    for _, n := range slice {
        println(n)
    }
2018-09-02 16:28:46 +02:00
Ayke van Laethem 42cddd3260 Move runtime.TargetBits out of the compiler 2018-09-02 16:00:31 +02:00
Ayke van Laethem cd2a9d99a1 Add dummy runtime.SetFinalizer()
Requirement for the os package. The os package can't be compiled yet,
though.
2018-08-31 21:56:46 +02:00
Ayke van Laethem 94ce893ab4 Copy printfloat() from original runtime
I've tried writing my own, but I couldn't make it correct in all cases.
So just copy the one from upstream for now, hopefully to be replaced at
some point.

TODO: add a printfloat32() implementation, now it just casts to float64.
This will be useful for embedded systems that sometimes have float32 but
not float64.
2018-08-31 21:29:34 +02:00
Ayke van Laethem 3cdf606183 Improve runtime.printuint32: avoid recursion
This reduces size slightly at least on the PCA10040, and is probably
faster and probably uses less stack as well.
2018-08-31 21:29:06 +02:00
Ayke van Laethem 734b0cb6bc Implement runtime functions for reflect
The reflect package isn't supported yet. But at least the Go
parser/typechecker can now deal with it.
2018-08-30 22:53:34 +02:00
Ayke van Laethem 674b506bb2 Replace compiler hack for sync package with //go:linkname 2018-08-30 22:38:45 +02:00
Ayke van Laethem 74bd378c29 Replace _llvm_* workaround in the scheduler with //go:linkname
This also removes the need for the _llvm_ special case in the compiler.
And it makes the scheduler code a whole lot nicer!
2018-08-30 22:30:16 +02:00
Ayke van Laethem 15f62b29cf Add runtime.GOOS 2018-08-30 05:48:16 +02:00
Ayke van Laethem 82d0d70ba2 Add (hardcoded) runtime.GOROOT()
Necessary for the time package.
2018-08-30 05:41:48 +02:00
Ayke van Laethem a4fd096393 Add dummy channel support 2018-08-30 05:32:18 +02:00
Ayke van Laethem 42711c11e9 Be able to print maps to some degree
Print the number of elements, or nil if it is a nil map.
2018-08-30 02:26:48 +02:00
Ayke van Laethem d930a9ba16 Implement print() for interface values 2018-08-30 02:20:36 +02:00
Ayke van Laethem d13c124df9 Implement casting from (Unicode) integer to string 2018-08-30 00:36:54 +02:00
Ayke van Laethem fdc56d5940 Implement convert string <- []byte 2018-08-29 23:54:46 +02:00
Ayke van Laethem 8b95b869ab Implement string concatenation 2018-08-29 22:10:46 +02:00
Ayke van Laethem c912091f8b Add integer key support to hashmap 2018-08-29 21:50:43 +02:00
Ayke van Laethem 8f7db8661b Move string type to runtime in separate file 2018-08-29 20:55:09 +02:00
Ayke van Laethem bf160d096b Move lenType definition to runtime (partially) 2018-08-29 20:48:56 +02:00
Ayke van Laethem d4f5700625 Remove use of CGo in the runtime
CGo depends on syscall, which (in the standard library) depends on sync,
which depends on the runtime. There are also other import cycles. To be
able to use the syscall package from upstream, stop using CGo.
2018-08-29 20:01:33 +02:00
Ayke van Laethem 0c71ed81a4 Rename runtime.itfmethod -> runtime.interfaceMethod 2018-08-27 00:49:33 +02:00
Ayke van Laethem 64e478ef36 Switch to 16-bit typecodes and method IDs
It took Android some time to even hit the 64K limit for regular method
calls, so switching to 16-bit IDs should be fine for method IDs of
interfaces. At least for the time being. When this limit is ever hit,
I'll think of another way, probably involving some platform-dependent
interface code (e.g. microcontrollers won't need 64K of methods) or
detecting the limit at build time.

https://android-developers.googleblog.com/2014/12/google-play-services-and-dex-method.html

Code size isn't changed, probably because the compiler optimizes away
all method calls.
2018-08-27 00:32:30 +02:00
Ayke van Laethem 539de9db9e Move interface method calls in Go from LLVM IR + documentation
This commit moves the itfmethod call implemented directly in LLVM IR to
a Go implementation in the runtime. Additionally, it fixes variable
names to be more obvious and adds a lot of documentation to explain how
interfaces actually work in TinyGo.

Code size changes for src/examples/hello:
nrf:  -144
unix: -93

I'm guessing this code size reduction is a result of removing the
'noinline' function attribute.
2018-08-26 23:40:11 +02:00
Ayke van Laethem 179cf74b01 Implement package-global maps (of max 8 entries) 2018-08-24 00:56:20 +02:00
Ayke van Laethem 2b78b6d7e8 Fix bug in runtime.memzero
Not the memory itself, but the byte after the memory was zeroed.
2018-08-23 23:45:39 +02:00
Ayke van Laethem e884221fad Implement len() for map types 2018-08-23 23:14:54 +02:00
Ayke van Laethem 005665aee6 Move hashmap creation to runtime 2018-08-23 23:13:38 +02:00
Ayke van Laethem 3a6ef38041 Preliminary implementation of a hashmap, unfinished
Missing features:
  * keys other than strings
  * more than 8 values in the hashmap
  * growing a map when needed
  * initial size hint
  * delete(m, key)
  * iterators (for range)
  * initializing global maps
  * ...more?
2018-08-22 04:50:24 +02:00
Ayke van Laethem c3cb22030f Implement == and != for strings 2018-08-22 00:56:11 +02:00
Ayke van Laethem 2777f8464e Implement printing of booleans 2018-08-22 00:54:39 +02:00
Ayke van Laethem 29d601883b Implement dummy GOMAXPROCS
This compiler targets single-core machines, GOMAXPROCS is thus fixed to
1.
2018-08-18 20:06:59 +02:00
Ayke van Laethem 8b6cb204cd Basic support for slices 2018-08-18 20:06:35 +02:00
Ayke van Laethem 70871c98f8 Improve print functions 2018-08-17 23:23:38 +02:00
Ayke van Laethem 62c4c5e90b go fmt 2018-08-17 23:23:20 +02:00
Ayke van Laethem a97ca91c1f compiler: Implement interface calls
This is a big combined change. Other changes in this commit:

  * Analyze makeinterface and make sure type switches don't include
    unnecessary cases.
  * Do not include CGo wrapper functions in the analyzer callgraph.
    This also avoids some unnecessary type IDs.
  * Give all Go named structs a name in LLVM.
  * Use such a named struct for compiler-generated task data.
  * Use the type and function names defined by the ssa and types
    package instead of generating our own.
  * Some improvements to function pointers.
  * A few other minor improvements.

The one thing lacking here is interface-to-interface assertions.
2018-06-17 15:50:19 +02:00
Ayke van Laethem 90fb0ee4eb Add AVR support
This requires support in LLVM, as AVR support is still experimental. For
example, in bindings/go/build.sh, add
-DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=AVR to cmake_flags.
2018-06-07 18:35:54 +02:00
Ayke van Laethem 802302a1aa Add support for inline assembly
This depends on support in LLVM, which hasn't been merged yet.
See: https://reviews.llvm.org/D46437
2018-06-07 18:29:49 +02:00
Ayke van Laethem 0168bf7797 Add goroutines and function pointers 2018-06-07 14:48:24 +02:00
Ayke van Laethem b4e60deacd runtime/nrf: Fix allocator by adding align() function 2018-06-03 17:56:56 +02:00
Ayke van Laethem 588910792d Translate bootstrapping main from C to LLVM IR
This avoids needing a C compiler for every platform.
2018-06-03 17:38:16 +02:00
Ayke van Laethem 320c583221 Implement printing of int8/uint8/pointers 2018-06-03 16:39:24 +02:00
Ayke van Laethem e171f32493 Implement minimal bump pointer allocator
Useful for MCUs, until a real garbage collector has been implemented.
2018-06-03 16:30:48 +02:00
Ayke van Laethem a39951c3d7 runtime: Convert device initialization to Go 2018-05-05 20:10:39 +02:00
Ayke van Laethem c4f0dc90dd machine: Rewrite most of the GPIO functionality
Split across device types (nrf, dummy) and use registers directly
instead of the HAL.
2018-05-05 20:05:53 +02:00