aboutsummaryrefslogtreecommitdiffhomepage
path: root/compiler/interface.go
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2021-03-24 16:07:44 +0100
committerRon Evans <[email protected]>2021-03-28 14:00:37 +0200
commitbcce296ca315d81633802183a8ba8658450f7ee3 (patch)
tree4beb06c01dfea1d97cfb68a098c0dc0cc9acb4ea /compiler/interface.go
parentc5ec95508127678ebbd11df8bdcf30d83766a141 (diff)
downloadtinygo-bcce296ca315d81633802183a8ba8658450f7ee3.tar.gz
tinygo-bcce296ca315d81633802183a8ba8658450f7ee3.zip
transform: optimize reflect.Type Implements() method
This commit adds a new transform that converts reflect Implements() calls to runtime.interfaceImplements. At the moment, the Implements() method is not yet implemented (how ironic) but if the value passed to Implements is known at compile time the method call can be optimized to runtime.interfaceImplements to make it a regular interface assert. This commit is the last change necessary to add basic support for the encoding/json package. The json package is certainly not yet fully supported, but some trivial objects can be converted to JSON.
Diffstat (limited to 'compiler/interface.go')
-rw-r--r--compiler/interface.go3
1 files changed, 3 insertions, 0 deletions
diff --git a/compiler/interface.go b/compiler/interface.go
index ed75b3577..dae098577 100644
--- a/compiler/interface.go
+++ b/compiler/interface.go
@@ -62,6 +62,9 @@ func (c *compilerContext) getTypeCode(typ types.Type) llvm.Value {
// Take a pointer to the typecodeID of the first field (if it exists).
structGlobal := c.makeStructTypeFields(typ)
references = llvm.ConstBitCast(structGlobal, global.Type())
+ case *types.Interface:
+ methodSetGlobal := c.getInterfaceMethodSet(typ)
+ references = llvm.ConstBitCast(methodSetGlobal, global.Type())
}
if _, ok := typ.Underlying().(*types.Interface); !ok {
methodSet = c.getTypeMethodSet(typ)