Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
DQNEO committed Aug 19, 2023
1 parent 4f72923 commit 4eb280f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions internal/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,7 @@ func emitMapGet(m *ir.MetaIndexExpr, okContext bool) {
// 1 or 2 values
func emitTypeAssertExpr(meta *ir.MetaTypeAssertExpr) {
emitExpr(meta.X)
emitDtypeLabelAddr(meta.Type, sema.GetTypeOfExpr(meta.X))
emitDtypeLabelAddr(meta.Type.GoType, sema.GetGoTypeOfExpr(meta.X))
emitCompareDtypes()

emitPopBool("type assertion ok value")
Expand Down Expand Up @@ -1141,7 +1141,7 @@ func emitConvertToInterface(fromType *types.Type, toType *types.Type) {
emitCallMalloc(memSize)
emitStore(fromType.GoType, false, true) // heap addr pushed
// push dtype label's address
emitDtypeLabelAddr(fromType, toType)
emitDtypeLabelAddr(fromType.GoType, toType.GoType)
}

// Check type identity by comparing its serialization, not id or address of dtype label.
Expand Down Expand Up @@ -1194,8 +1194,8 @@ func emitCompareDtypes() {
printf(" %s:\n", labelEnd)
}

func emitDtypeLabelAddr(t *types.Type, it *types.Type) {
de := sema.GetITabEntry(t, it)
func emitDtypeLabelAddr(d types.GoType, i types.GoType) {
de := sema.GetITabEntry(d, i)
dtypeLabel := de.Label
sr := de.DSerialized
printf(" leaq %s(%%rip), %%rax # dtype label address \"%s\"\n", dtypeLabel, sr)
Expand Down Expand Up @@ -1812,7 +1812,7 @@ func emitTypeSwitchStmt(meta *ir.MetaTypeSwitchStmt) {
if t == nil { // case nil:
printf(" pushq $0 # nil\n")
} else { // case T:s
emitDtypeLabelAddr(t, sema.GetTypeOfExpr(meta.Subject))
emitDtypeLabelAddr(t.GoType, sema.GetGoTypeOfExpr(meta.Subject))
}
emitCompareDtypes()
emitPopBool(" of switch-case comparison")
Expand Down
6 changes: 3 additions & 3 deletions internal/sema/sema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2821,9 +2821,9 @@ func RegisterDtype(dtype *types.Type, itype *types.Type) {
ITabID++
}

func GetITabEntry(t *types.Type, it *types.Type) *ITabEntry {
ds := SerializeType(t.GoType, true, false, "")
is := SerializeType(it.GoType, true, false, "")
func GetITabEntry(d types.GoType, i types.GoType) *ITabEntry {
ds := SerializeType(d, true, false, "")
is := SerializeType(i, true, false, "")
key := ds + "-" + is
ent, ok := ITab[key]
if !ok {
Expand Down

0 comments on commit 4eb280f

Please sign in to comment.