View Single Post
nergal
Veteran Member
Join Date: Apr 2012
Old 11-05-2020 , 17:25   Re: SourceGo: Experimental Golang to SourcePawn Transpiler
Reply With Quote #6

another update, v0.22A, added two types of switch statements: normal and "true" switch statements.

Normal is of course what you'd expect:
Code:
/// Original:
switch x {
	case 1, 2:
	case 3:
	default:
}

/// Generated:
switch (x) {
	case 1, 2: {
	}
	case 3: {
	}
	default: {
	}
}
Golang has a feature where you can omit the controller expression, which basically makes it "true" in terms of value. Thus you have "true" switch statements which can act as a more compact form of an if-else-if series. This is also supported and appropriately generated!
Code:
/// Original:
switch {
	case x < 10, x+y < 10.0:
	case x * y <= 1024.0:
	default:
}

/// Generated:
if ((x < 10) || (x + y < 10.0)) {
}
else if ((x * y <= 1024.0)) {
}
else {
}
__________________

Last edited by nergal; 11-05-2020 at 17:26.
nergal is offline