Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pkg/codegen/codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,14 @@ func (ctx *Context) genStructTypeDeclare(node *mTypes.Node) {
for n := node.Child; n != nil; n = n.Next {
// Note: is NOT TRUE
rootTy, _, _ := mTypes.GetLLVMTypeRec(ctx.mod, n.Type, ctx.prog.Prelude)
typsArr = append(typsArr, rootTy)
f := structField[n.Val]
f.Pos = pos
f.Type = rootTy
if _, ok := rootTy.(*types.StructType); ok {
f.Type = &types.PointerType{ElemType: rootTy}
} else {
f.Type = rootTy
}
typsArr = append(typsArr, f.Type)
structField[n.Val] = f
pos++
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/types/ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,21 @@ func GetBitWidth(t types.Type) uint64 {
}

func GetVectorTypeFromPtr(v value.Value) (*types.StructType, types.Type) {
structPtr := v.Type().(*types.PointerType)
structedVecType := structPtr.ElemType.(*types.StructType)
structPtr, ok := v.Type().(*types.PointerType)
if !ok {
return nil, nil
}

structedVecType, ok := structPtr.ElemType.(*types.StructType)
if !ok {
return nil, nil
}

vecTypeField := structedVecType.Fields
if len(vecTypeField) == 0 {
return nil, nil
}

elemType := structedVecType.Fields[0].(*types.PointerType).ElemType

return structedVecType, elemType
Expand Down
1 change: 1 addition & 0 deletions script/test-full.sh
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ testexec(){
assertexec '(defschema Person {:name :: string :age :: int :isMale :: bool})(def main :: int (fn [] (let [node :: Person {:age 20 :name "richard" :isMale true}] (prn (get node :name)) (prn (get node :age)) (prn (get node :isMale))))))' "richard\\\n20\\\ntrue\\\n"
assertexec '(defschema Person {:name :: string :age :: int :isMale :: bool :height :: double})(def main :: int (fn [] (let [node :: Person {:age 20 :name "richard" :isMale true :height 5.8}] (prn (get node :name)) (prn (get node :age)) (prn (get node :isMale)) (prn (get node :height))))))' "richard\\\n20\\\ntrue\\\n5.8\\\n"
assertexec '(defschema Person {:name :: string :age :: int :isMale :: bool}) (def f :: Person (fn [] (let [node :: Person {:age 20 :name "richard" :isMale true}] node))) (def main :: int (fn [] (prn (get f :age))))' "20\\\n"
assertexec '(defschema Person {:name :: string :age :: int :isMale :: bool :height :: double :v :: [int]}) (def main :: int (fn [] (let [node :: Person {:age 20 :name "richard" :isMale true :height 5.8 :v [4, 3, 2]}] (prn (get node :name)) (prn (get node :age)) (prn (get node :isMale)) (prn (get node :height)) (prn (get node :v)) )))' "richard\\\n20\\\ntrue\\\n5.8\\\n[4, 3, 2]\\\n"

#############
# Prelude functions
Expand Down