Skip to content

Commit

Permalink
make buildNifc compile, couple tasks left
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Nov 26, 2024
1 parent eb7bfc3 commit ec14cfe
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
36 changes: 19 additions & 17 deletions compiler/cbuilderdecls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ proc addVarHeader(builder: var Builder, kind: VarKind) =
when buildNifc:
builder.add("tvar ")
else:
doAssert false, "unimplemented"
raiseAssert "unimplemented"

proc addVar(builder: var Builder, kind: VarKind = Local, name: string, typ: Snippet, initializer: Snippet = "") =
## adds a variable declaration to the builder
Expand Down Expand Up @@ -91,6 +91,7 @@ when buildNifc:
if key in m.arrayTypes:
result = m.arrayTypes[key]
else:
# XXX elementType can be a non-name
result = elementType & "_Arr_" & $len
m.s[cfsTypes].add("(type :")
m.s[cfsTypes].add(result)
Expand Down Expand Up @@ -319,7 +320,7 @@ proc addArrayField(obj: var Builder; m: BModule, name, elementType: Snippet; len
obj.add("\n\t(fld :")
obj.add(name)
obj.add(" . ") # pragmas
obj.add(getArrayType(elementType, len))
obj.add(getArrayType(m, elementType, len))
obj.add(")")
else:
obj.add('\t')
Expand All @@ -338,12 +339,12 @@ proc addField(obj: var Builder; field: PSym; name, typ: Snippet; isFlexArray: bo
var pragmasInner = ""
if field.alignment > 0:
pragmasInner.add("(align ")
pragmasInner.addIntValue(field.alignment)
pragmasInner.add(cIntValue(field.alignment))
pragmasInner.add(")")
if field.bitsize != 0:
if pragmasInner.len != 0: pragmasInner.add(" ")
pragmasInner.add("(bits ")
pragmasInner.addIntValue(field.bitsize)
pragmasInner.add(cIntValue(field.bitsize))
pragmasInner.add(")")
if sfNoalias in field.flags:
when false: # XXX not implemented in NIFC
Expand Down Expand Up @@ -431,16 +432,17 @@ proc startSimpleStruct(obj: var Builder; m: BModule; name: string; baseType: Sni
if result.named:
obj.add("(type :")
obj.add(name)
obj.add(" (object ")
if baseType.len != 0:
if m.compileToCpp:
result.baseKind = bcCppInherit
else:
result.baseKind = bcSupField
obj.add(baseType)
obj.add(" ")
obj.add(" ")
obj.add("(object ")
if baseType.len != 0:
if m.compileToCpp:
result.baseKind = bcCppInherit
else:
obj.add(". ")
result.baseKind = bcSupField
obj.add(baseType)
obj.add(" ")
else:
obj.add(". ")
else:
obj.add("struct")
if result.named:
Expand Down Expand Up @@ -656,7 +658,7 @@ proc addVisibilityPrefix(builder: var Builder, visibility: DeclVisibility) =
of Extern:
builder.add("(imp ")
of ExternC, ImportLib, ExportLib, ExportLibVar:
doAssert false, "visibility " & $visibility & " not supported in NIFC"
raiseAssert "visibility " & $visibility & " not supported in NIFC"
of Private, StaticProc:
# also not supported but can just be ignored
discard
Expand Down Expand Up @@ -685,7 +687,7 @@ proc addVisibilitySuffix(builder: var Builder, visibility: DeclVisibility) =
of Extern:
builder.addLineEnd(")")
of ExternC, ImportLib, ExportLib, ExportLibVar:
doAssert false, "visibility " & $visibility & " not supported in NIFC"
raiseAssert "visibility " & $visibility & " not supported in NIFC"
of Private, StaticProc:
# also not supported but can just be ignored
discard
Expand Down Expand Up @@ -754,7 +756,7 @@ proc addParam(builder: var Builder, params: var ProcParamBuilder, param: PSym, t
builder.add(typ)
builder.add(")")
else:
doAssert false, "codegendecl not supported on NIFC"
raiseAssert "codegendecl not supported on NIFC"
else:
var modifiedTyp = typ
if sfNoalias in param.flags:
Expand Down Expand Up @@ -1082,7 +1084,7 @@ type VarInitializerKind = enum
proc addVar(builder: var Builder, m: BModule, s: PSym, name: string, typ: Snippet, kind = Local, visibility: DeclVisibility = None, initializer: Snippet = "", initializerKind: VarInitializerKind = Assignment) =
if sfCodegenDecl in s.flags:
when buildNifc:
doAssert false, "codegendecl not supported in nifc"
raiseAssert "codegendecl not supported in nifc"
else:
builder.add(runtimeFormat(s.cgDeclFrmt, [typ, name]))
if initializer.len != 0:
Expand Down
10 changes: 5 additions & 5 deletions compiler/cbuilderexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type CppCaptureKind = enum None, ByReference, ByCopy

template addCppLambda(builder: var Builder, captures: CppCaptureKind, params: Snippet, body: typed) =
when buildNifc:
doAssert false, "not implemented"
raiseAssert "not implemented"
else:
builder.add("[")
case captures
Expand Down Expand Up @@ -123,7 +123,7 @@ proc cAddr(value: Snippet): Snippet =

proc cLabelAddr(value: TLabel): Snippet =
when buildNifc:
doAssert false, "unimplemented"
raiseAssert "unimplemented"
else:
"&&" & value

Expand All @@ -141,13 +141,13 @@ proc subscript(a, b: Snippet): Snippet =

proc dotField(a, b: Snippet): Snippet =
when buildNifc:
"(dot " & a & " " & b & " 0)"
"(dot " & a & " " & b & " +0)" # XXX inheritance field
else:
a & "." & b

proc derefField(a, b: Snippet): Snippet =
when buildNifc:
"(dot " & cDeref(a) & " " & b & " 0)"
"(dot " & cDeref(a) & " " & b & " +0)" # XXX inheritance field
else:
a & "->" & b

Expand Down Expand Up @@ -370,7 +370,7 @@ proc addOp(builder: var Builder, binOp: TypedBinaryOp, t: Snippet, a, b: Snippet
proc addOp(builder: var Builder, unOp: TypedUnaryOp, t: Snippet, a: Snippet) =
when buildNifc:
builder.add('(')
builder.add(typedUnaryOperators[binOp])
builder.add(typedUnaryOperators[unOp])
builder.add(' ')
builder.add(t)
builder.add(' ')
Expand Down
4 changes: 2 additions & 2 deletions compiler/cbuilderstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -515,15 +515,15 @@ proc addGoto(builder: var Builder, label: TLabel) =

proc addComputedGoto(builder: var Builder, value: Snippet) =
when buildNifc:
doAssert false, "not implemented in nifc"
raiseAssert "not implemented in nifc"
else:
builder.add("goto *")
builder.add(value)
builder.addLineEnd(";")

template addCPragma(builder: var Builder, val: Snippet) =
when buildNifc:
doAssert false, "not implememented in nifc"
raiseAssert "not implememented in nifc"
else:
builder.addNewline()
builder.add("#pragma ")
Expand Down

0 comments on commit ec14cfe

Please sign in to comment.