aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/runtime/runtime.go
AgeCommit message (Collapse)Author
2023-02-18runtime: implement KeepAlive using inline assemblyAyke van Laethem
2023-02-17runtime: allow custom-gc SetFinalizer and clarify KeepAliveAnuraag Agrawal
2023-02-03runtime: implement internal/godebug.setUpdateAyke van Laethem
This function was a stub, but it really needs to be implemented for full Go 1.20 support. Without it, the archive/zip tests will fail.
2023-01-17runtime: implement internal/godebug.setUpdate as a stubAyke van Laethem
This function provides a mechanism to watch for changes to the GODEBUG environment variable. For now, we'll not implement it. It might be useful in the future, when it can always be added.
2022-12-15runtime: move KeepAlive/SetFinalizer to common codeAyke van Laethem
We don't support these yet so let's just put them in a central location. Once these functions are supported we can think about how to structure the code again.
2022-10-19ci: add support for LLVM 15Ayke van Laethem
This commit switches to LLVM 15 everywhere by default, while still keeping LLVM 14 support.
2022-08-04all: format code according to Go 1.19 rulesAyke van Laethem
Go 1.19 started reformatting code in a way that makes it more obvious how it will be rendered on pkg.go.dev. It gets it almost right, but not entirely. Therefore, I had to modify some of the comments so that they are formatted correctly.
2022-06-24compiler: really define runtime.mem* as LLVM intrinsic wrappersAyke van Laethem
This makes it possible to //go:linkname them from other places, like in the reflect package. And is in my opinion a much cleaner solution.
2022-04-07runtime: stub {Lock,Unlock}OSThread. Makes 1.18 happier on windows.Dan Kegel
2021-12-28rumtime: implement __sync libcalls as critical sectionsNia Waldvogel
This change implements __sync atomic polyfill libcalls by disabling interrupts. This was previously done in a limited capacity on some targets, but this change uses a go:generate to emit all of the calls on all microcontroller targets.
2021-11-30runtime: use LLVM intrinsic to read the stack pointerAyke van Laethem
This should result in smaller code.
2021-11-24cgo: add support for C.CString and related functionsAyke van Laethem
2021-11-05runtime: only initialize os.runtime_args when neededAyke van Laethem
This generally means that code size is reduced, especially when the os package is not imported. Specifically: - On Linux (which currently statically links musl), it avoids calling malloc, which avoids including the musl C heap for small programs saving around 1.6kB. - On WASI, it avoids initializing the args slice when the os package is not used. This reduces binary size by around 1kB.
2021-07-20runtime: fix time base for time.Now()Ayke van Laethem
This function previously returned the atomic time, that isn't affected by system time changes but also has a time base at some arbitrary time in the past. This makes sense for baremetal platforms (which typically don't know the wall time) but it gives surprising results on Linux and macOS: time.Now() usually returns a time somewhere near the start of 1970. This commit fixes this by obtaining both time values: the monotonic time and the wall clock time. This is also how the Go runtime implements the time.now function.
2021-04-21runtime: implement command line arguments in hosted environmentsAyke van Laethem
Implement command line arguments for Linux, MacOS and WASI.
2021-04-21runtime: implement environment variables for LinuxAyke van Laethem
2021-01-24compiler: remove unnecessary main.main call workaroundAyke van Laethem
Since https://github.com/tinygo-org/tinygo/pull/1571 (in particular, the first commit that sets the main package path), the main package is always named "main". This makes the callMain() workaround in the runtime unnecessary and allows directly calling the main.main function with a //go:linkname pragma.
2020-05-25runtime: refactor time handlingAyke van Laethem
This commit refactors both determining the current time and sleeping for a given time. It also improves precision for many chips. * The nrf chips had a long-standing TODO comment about a slightly inaccurate clock. This should now be fixed. * The SAM D2x/D5x chips may have a slightly more accurate clock, although probably within the error margin of the RTC. Also, by working with RTC ticks and converting in the least number of places, code size is often slightly reduced (usually just a few bytes, up to around 1kB in some cases). * I believe the HiFive1 rev B timer was slightly wrong (32768Hz vs 30517.6Hz). Because the datasheet says the clock runs at 32768Hz, I've used the same conversion code here as in the nrf and sam cases. * I couldn't test both stm32 timers, so I kept them as they currently are. It may be possible to make them more efficient by using the native tick frequency instead of using microseconds everywhere.
2020-05-12os: add Args and stub it with mock datacornelk
2020-03-27compiler,runtime: translate memzero calls to LLVM memset intrinsicsAyke van Laethem
This gives the optimizer a bit more information about what the calls do. This should result in slightly better generated code. Code size sometimes goes up and sometimes goes down. I blame the code size going up on the inliner which inlines more functions, because compiling the smoke tests in the drivers repository with -opt=1 results in a slight code size reduction in all cases.
2020-03-27compiler,runtime: use LLVM intrinsics for memcpy/memmoveAyke van Laethem
This replaces the custom runtime.memcpy and runtime.memmove functions with calls to LLVM builtins that should hopefully allow LLVM to better optimize such calls. They will be lowered to regular libc memcpy/memmove when they can't be optimized away. When testing this change with some smoke tests, I found that many smoke tests resulted in slightly larger binary sizes with this commit applied. I looked into it and it appears that machine.sendUSBPacket was not inlined before while it is with this commit applied. Additionally, when I compared all driver smoke tests with -opt=1 I saw that many were reduced slightly in binary size and none increased in size.
2020-03-17refactor coroutine lowering and tasksJaden Weiss
2019-11-10runtime: add AdjustTimeOffset to update current timeAyke van Laethem
This function adjusts the time returned by time.Now() and similar functions. This is necessary on bare metal systems, where there would not be a way to adjust the time otherwise.
2019-08-15compiler,runtime: implement stack-based schedulerAyke van Laethem
This scheduler is intended to live along the (stackless) coroutine based scheduler which is needed for WebAssembly and unsupported platforms. The stack based scheduler is somewhat simpler in implementation as it does not require full program transform passes and supports things like function pointers and interface methods out of the box with no changes. Code size is reduced in most cases, even in the case where no scheduler scheduler is used at all. I'm not exactly sure why but these changes likely allowed some further optimizations somewhere. Even RAM is slightly reduced, perhaps some global was elminated in the process as well.
2019-05-28Trivial typo fixJustin Clift
2019-03-23runtime: add runtime.nanotimeAyke van Laethem
This function returns the current timestamp, or 0 at compile time. runtime.nanotime is used at package initialization by the time package starting with Go 1.12.
2019-02-01Makefile: rename tgo to tinygoAyke van Laethem
2019-01-21all: rewrite goroutine loweringAyke van Laethem
Before this commit, goroutine support was spread through the compiler. This commit changes this support, so that the compiler itself only generates simple intrinsics and leaves the real support to a compiler pass that runs as one of the TinyGo-specific optimization passes. The biggest change, that was done together with the rewrite, was support for goroutines in WebAssembly for JavaScript. The challenge in JavaScript is that in general no blocking operations are allowed, which means that programs that call time.Sleep() but do not start goroutines also have to be scheduled by the scheduler.
2018-10-29runtime: correctly copy a zero-length buffer backwardsAyke van Laethem
Fixes: https://github.com/aykevl/tinygo/issues/64
2018-10-28runtime: implement syscall.runtime_envsAyke van Laethem
It is stubbed out currently, but may be useful in the future. Note that this function is implemented for a future change to the init system, it is not yet useful.
2018-10-20runtime: fix linker error: os.sigpipeAyke van Laethem
2018-10-19compiler: add support for the append builtinAyke van Laethem
2018-10-15runtime: add support for time.Now()Ayke van Laethem
TODO: On unix systems, this does not return an accurate value.
2018-10-08runtime: refactor initialization codeAyke van Laethem
Let each target handle its own initialization/finalization sequence instead of providing one in the runtime with hooks for memory initialization etc. This is much more flexible although it causes a little bit of code duplication.
2018-09-24all: allow -O0 optimization levelAyke van Laethem
2018-09-22runtime: merge common sleep() functionsAyke van Laethem
2018-09-16avr: convert initialization from asm to GoAyke van Laethem
This increases code size by 1 instruction (2 bytes) because LLVM isn't yet smart enough to recognize that it doesn't need to clear a register to use 0: it can just use r1 which is always 0 according to the convention. It makes initialization a lot easier to read, however.
2018-09-16all: basic support for the os packageAyke van Laethem
The resulting binary is pretty big due to lacking optimizations (probably because of interfaces), so that should be fixed.
2018-09-15all: rewrite sleep functionAyke van Laethem
time.Sleep now compiles on all systems, so lets use that. Additionally, do a few improvements in time unit handling for the scheduler. This should lead to somewhat longer sleep durations without wrapping (on some platforms). Some examples got smaller, some got bigger. In particular, code using the scheduler got bigger and the blinky1 example got smaller (especially on Arduino: 380 -> 314 bytes).
2018-09-06compiler: implement builtin copy(dst, src []T)Ayke van Laethem
Not implemented: copying a string into a []byte slice.
2018-09-06runtime: move panic functions to a separate fileAyke van Laethem
2018-09-06compiler: implement make([]T, ...)Ayke van Laethem
2018-09-04all: move bootstrapping IR to Go runtimeAyke van Laethem
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-02Optimize/eliminate bounds checkingAyke van Laethem
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-02Move runtime.TargetBits out of the compilerAyke van Laethem
2018-08-30Add (hardcoded) runtime.GOROOT()Ayke van Laethem
Necessary for the time package.
2018-08-29Add integer key support to hashmapAyke van Laethem
2018-08-29Move string type to runtime in separate fileAyke van Laethem
2018-08-23Fix bug in runtime.memzeroAyke van Laethem
Not the memory itself, but the byte after the memory was zeroed.
2018-08-22Preliminary implementation of a hashmap, unfinishedAyke van Laethem
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?