@@ -653,13 +653,14 @@ class GenCxx {
653
653
}
654
654
655
655
if let expr = expr {
656
- out.push(printFunctionReturnType(funcType))
656
+ let returns = printFunctionReturnType(funcType)
657
+ out.push(returns)
657
658
out.push(' ' + name)
658
659
out.push(printFunctionArguments(args, funcType, variadic))
659
660
660
661
let _currentReturnType = currentReturnType
661
662
currentReturnType = getFunctionReturnType(funcType)
662
- out.push(' ' + printBlock (expr) + ';\n\n')
663
+ out.push(' ' + printFunctionBody (expr, returns ) + ';\n\n')
663
664
currentReturnType = _currentReturnType
664
665
}
665
666
}}
@@ -733,8 +734,8 @@ class GenCxx {
733
734
734
735
switch type {
735
736
// TODO same for const
736
- case ClassInstance(type , generics): {
737
- if type .name == 'ArrayByValue' {
737
+ case ClassInstance(classType , generics): {
738
+ if classType .name == 'ArrayByValue' {
738
739
var arraySize = ''
739
740
if let count = generics[1] {
740
741
arraySize = '[' + Type.stringify(count) + ']'
@@ -768,6 +769,11 @@ class GenCxx {
768
769
}
769
770
globalVariables.push(';\n')
770
771
772
+ defaults = false
773
+ } else if classType.name == 'ByValue' {
774
+ globalVariables.push(stringifyType(type))
775
+ globalVariables.push(' ' + name + '_')
776
+ globalVariables.push(';\n')
771
777
defaults = false
772
778
}
773
779
}
@@ -776,7 +782,20 @@ class GenCxx {
776
782
if defaults {
777
783
//types.push('void* ' + name + '_;\n')
778
784
globalVariables.push(stringifyType(type))
779
- globalVariables.push(' ' + name + '_;\n')
785
+ globalVariables.push(' ' + name + '_') // TODO respect `@rename`
786
+
787
+ if let link = link, let linkName = link.linkName {
788
+ if exports and extraUnderscore and linkName.startsWith('_') {
789
+ globalVariables.push(' HEXA_LINK("_')
790
+ } else {
791
+ globalVariables.push(' HEXA_LINK("')
792
+ }
793
+
794
+ globalVariables.push(linkName)
795
+ globalVariables.push('")')
796
+ }
797
+
798
+ globalVariables.push(';\n')
780
799
if expr != null {
781
800
let value String = printExpression(expr)
782
801
@@ -1047,6 +1066,24 @@ class GenCxx {
1047
1066
}
1048
1067
}
1049
1068
1069
+ // Add extra `return 0` to avoid stack corruption
1070
+ fun printFunctionBody(s: Statement, returns: String): String {
1071
+ if returns != 'void', returns.endsWith('*') or [
1072
+ 'float','int',
1073
+ 'uint8_t','uint16_t','uint32_t','uint64_t',
1074
+ 'int8_t','int16_t','int32_t','int64_t'
1075
+ ].includes(returns) {
1076
+ switch s {
1077
+ case Block(el):
1078
+ let block = el.clone()
1079
+ block.push(Statement.Return(Expression.Int(0)))
1080
+ return printBlock(Statement.Block(block))
1081
+ }
1082
+ }
1083
+
1084
+ return printBlock(s)
1085
+ }
1086
+
1050
1087
var metaBlock: [String] = []
1051
1088
var tempId = 0
1052
1089
@@ -1634,12 +1671,18 @@ class GenCxx {
1634
1671
return 'String_$fromBool_(' + string + ')'
1635
1672
}
1636
1673
1637
- if fromValue == project.typer.typeString { switch to {
1638
- case ClassInstance(type): if (type.name == 'ConstCharPointer') {
1639
- console.log(type)
1640
- return '(' + string + ')->bytes_'
1674
+ if fromValue == project.typer.typeString {
1675
+ switch to {
1676
+ case ClassInstance(type):
1677
+ if type.name == 'ConstCharPointer' {
1678
+ return '(' + string + ')->bytes_'
1679
+ }
1680
+
1681
+ if type.name == 'ConstArrayPointer' {
1682
+ return '(' + string + ')->bytes_'
1683
+ }
1641
1684
}
1642
- }}
1685
+ }
1643
1686
1644
1687
switch fromValue {
1645
1688
case Nullable(_):
0 commit comments