Граф коммитов

1530 коммитов

Автор SHA1 Сообщение Дата
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
58c87329d4
Implement closures and bound methods 2018-09-02 03:39:37 +02:00
Ayke van Laethem
58b853bbef
Defer for trivial cases 2018-09-01 17:14:38 +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
906e061e37
Replace own dummy syscall with standard library syscall
This makes it easier to support other standard library packages.
2018-08-30 05:58:54 +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
abaae5b90d
Remove unnecessary compiler workaround
This workaround isn't needed anymore: the feature has been implemented
now.
2018-08-29 20:45:50 +02:00
Ayke van Laethem
7991243554
Remove CGo from machine module
It isn't necessary anymore but apparently the Go importer didn't
complain about an unused import.
2018-08-29 20:44: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
f9f92de1c3
Add a test for the unicode package
This massively increases .data size, possibly because loads of unused
globals are included. I'll need to investigate what's going on here. For
now, increase the RAM size for nrf chips (the nrf52 has 64kB of RAM).
2018-08-24 03:35:03 +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