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
1 change: 1 addition & 0 deletions doc/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
| `(build X)`; `(build STR STR STR)` | NimonyPragma, NifIndexKind | `build` pragma |
| `(string)` | NimonyPragma | `string` pragma |
| `(view)` | NimonyPragma | `view` pragma |
| `(incompleteStruct)` | NimonyPragma | `incompleteStruct` pragma |
| `(quoted X+)` | NimonyExpr, NiflerKind | name in backticks |
| `(hderef X)` | NimonyExpr | hidden pointer deref operation |
| `(ddot X)` | NimonyExpr | deref dot |
Expand Down
2 changes: 1 addition & 1 deletion lib/std/posix/posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ when defined(posix):

# Directory operations
type
DIR* {.importc: "DIR", header: "<dirent.h>".} = object
DIR* {.importc: "DIR", header: "<dirent.h>", incompleteStruct.} = object
Dirent* {.importc: "struct dirent", header: "<dirent.h>".} = object
d_type* {.importc: "d_type".}: uint8
d_name* {.importc: "d_name".}: array[256, char]
Expand Down
2 changes: 1 addition & 1 deletion src/hexer/nifcgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ proc parsePragmas(c: var EContext; n: var Cursor): CollectedPragmas =
of NodeclP, SelectanyP, ThreadvarP, GlobalP, DiscardableP, NoReturnP,
VarargsP, NoSideEffectP, NoDestroyP, ByCopyP, ByRefP,
InlineP, NoinlineP, NoInitP, InjectP, GensymP, UntypedP, ViewP,
InheritableP, PureP, ClosureP, PackedP, UnionP:
InheritableP, PureP, ClosureP, PackedP, UnionP, IncompleteStructP:
result.flags.incl pk
inc n
of BorrowP:
Expand Down
3 changes: 2 additions & 1 deletion src/models/nimony_tags.nim
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ type
BuildP = (ord(BuildTagId), "build") ## `build` pragma
StringP = (ord(StringTagId), "string") ## `string` pragma
ViewP = (ord(ViewTagId), "view") ## `view` pragma
IncompleteStructP = (ord(IncompleteStructTagId), "incompleteStruct") ## `incompleteStruct` pragma
InjectP = (ord(InjectTagId), "inject") ## `inject` pragma
GensymP = (ord(GensymTagId), "gensym") ## `gensym` pragma
ErrorP = (ord(ErrorTagId), "error") ## `error` pragma
Expand All @@ -336,7 +337,7 @@ type
PassCP = (ord(PassCTagId), "passC") ## `passC` pragma adds options to the backend compiler

proc rawTagIsNimonyPragma*(raw: TagEnum): bool {.inline.} =
raw in {CursorTagId, EmitTagId, UnionTagId, InlineTagId, NoinlineTagId, ClosureTagId, VarargsTagId, SelectanyTagId, AlignTagId, BitsTagId, NodeclTagId, RaisesTagId, UntypedTagId, MagicTagId, ImportcTagId, ImportcppTagId, DynlibTagId, ExportcTagId, HeaderTagId, ThreadvarTagId, GlobalTagId, DiscardableTagId, NoreturnTagId, BorrowTagId, NoSideEffectTagId, NodestroyTagId, PluginTagId, BycopyTagId, ByrefTagId, NoinitTagId, RequiresTagId, EnsuresTagId, AssumeTagId, AssertTagId, BuildTagId, StringTagId, ViewTagId, InjectTagId, GensymTagId, ErrorTagId, ReportTagId, TagsTagId, DeprecatedTagId, SideEffectTagId, KeepOverflowFlagTagId, SemanticsTagId, InheritableTagId, BaseTagId, PureTagId, FinalTagId, PragmaTagId, PackedTagId, PassiveTagId, PushTagId, PopTagId, PassLTagId, PassCTagId}
raw in {CursorTagId, EmitTagId, UnionTagId, InlineTagId, NoinlineTagId, ClosureTagId, VarargsTagId, SelectanyTagId, AlignTagId, BitsTagId, NodeclTagId, RaisesTagId, UntypedTagId, MagicTagId, ImportcTagId, ImportcppTagId, DynlibTagId, ExportcTagId, HeaderTagId, ThreadvarTagId, GlobalTagId, DiscardableTagId, NoreturnTagId, BorrowTagId, NoSideEffectTagId, NodestroyTagId, PluginTagId, BycopyTagId, ByrefTagId, NoinitTagId, RequiresTagId, EnsuresTagId, AssumeTagId, AssertTagId, BuildTagId, StringTagId, ViewTagId, IncompleteStructTagId, InjectTagId, GensymTagId, ErrorTagId, ReportTagId, TagsTagId, DeprecatedTagId, SideEffectTagId, KeepOverflowFlagTagId, SemanticsTagId, InheritableTagId, BaseTagId, PureTagId, FinalTagId, PragmaTagId, PackedTagId, PassiveTagId, PushTagId, PopTagId, PassLTagId, PassCTagId}

type
NimonySym* = enum
Expand Down
184 changes: 93 additions & 91 deletions src/models/tags.nim
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ type
BuildTagId
StringTagId
ViewTagId
IncompleteStructTagId
QuotedTagId
HderefTagId
DdotTagId
Expand Down Expand Up @@ -541,95 +542,96 @@ const
("build", 220),
("string", 221),
("view", 222),
("quoted", 223),
("hderef", 224),
("ddot", 225),
("haddr", 226),
("newref", 227),
("newobj", 228),
("tup", 229),
("tupconstr", 230),
("setconstr", 231),
("tabconstr", 232),
("ashr", 233),
("baseobj", 234),
("hconv", 235),
("dconv", 236),
("callstrlit", 237),
("infix", 238),
("prefix", 239),
("hcall", 240),
("compiles", 241),
("declared", 242),
("defined", 243),
("astToStr", 244),
("instanceof", 245),
("proccall", 246),
("high", 247),
("low", 248),
("typeof", 249),
("unpack", 250),
("fields", 251),
("fieldpairs", 252),
("enumtostr", 253),
("ismainmodule", 254),
("defaultobj", 255),
("defaulttup", 256),
("defaultdistinct", 257),
("delay", 258),
("expr", 259),
("do", 260),
("arrat", 261),
("tupat", 262),
("plusset", 263),
("minusset", 264),
("mulset", 265),
("xorset", 266),
("eqset", 267),
("leset", 268),
("ltset", 269),
("inset", 270),
("card", 271),
("emove", 272),
("destroy", 273),
("dup", 274),
("copy", 275),
("wasmoved", 276),
("sinkh", 277),
("trace", 278),
("errv", 279),
("staticstmt", 280),
("bind", 281),
("mixin", 282),
("using", 283),
("asm", 284),
("defer", 285),
("index", 286),
("public", 287),
("private", 288),
("inject", 289),
("gensym", 290),
("error", 291),
("report", 292),
("tags", 293),
("deprecated", 294),
("sideEffect", 295),
("keepOverflowFlag", 296),
("semantics", 297),
("inheritable", 298),
("base", 299),
("pure", 300),
("final", 301),
("pragma", 302),
("internalTypeName", 303),
("internalFieldPairs", 304),
("failed", 305),
("is", 306),
("envp", 307),
("packed", 308),
("passive", 309),
("push", 310),
("pop", 311),
("passL", 312),
("passC", 313)
("incompleteStruct", 223),
("quoted", 224),
("hderef", 225),
("ddot", 226),
("haddr", 227),
("newref", 228),
("newobj", 229),
("tup", 230),
("tupconstr", 231),
("setconstr", 232),
("tabconstr", 233),
("ashr", 234),
("baseobj", 235),
("hconv", 236),
("dconv", 237),
("callstrlit", 238),
("infix", 239),
("prefix", 240),
("hcall", 241),
("compiles", 242),
("declared", 243),
("defined", 244),
("astToStr", 245),
("instanceof", 246),
("proccall", 247),
("high", 248),
("low", 249),
("typeof", 250),
("unpack", 251),
("fields", 252),
("fieldpairs", 253),
("enumtostr", 254),
("ismainmodule", 255),
("defaultobj", 256),
("defaulttup", 257),
("defaultdistinct", 258),
("delay", 259),
("expr", 260),
("do", 261),
("arrat", 262),
("tupat", 263),
("plusset", 264),
("minusset", 265),
("mulset", 266),
("xorset", 267),
("eqset", 268),
("leset", 269),
("ltset", 270),
("inset", 271),
("card", 272),
("emove", 273),
("destroy", 274),
("dup", 275),
("copy", 276),
("wasmoved", 277),
("sinkh", 278),
("trace", 279),
("errv", 280),
("staticstmt", 281),
("bind", 282),
("mixin", 283),
("using", 284),
("asm", 285),
("defer", 286),
("index", 287),
("public", 288),
("private", 289),
("inject", 290),
("gensym", 291),
("error", 292),
("report", 293),
("tags", 294),
("deprecated", 295),
("sideEffect", 296),
("keepOverflowFlag", 297),
("semantics", 298),
("inheritable", 299),
("base", 300),
("pure", 301),
("final", 302),
("pragma", 303),
("internalTypeName", 304),
("internalFieldPairs", 305),
("failed", 306),
("is", 307),
("envp", 308),
("packed", 309),
("passive", 310),
("push", 311),
("pop", 312),
("passL", 313),
("passC", 314)
]
13 changes: 13 additions & 0 deletions src/nimony/expreval.nim
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,19 @@ proc eval*(c: var EvalContext; n: var Cursor): Cursor =
of CallKinds:
result = evalCall(c, n)
skip n
of SizeofX:
if c.c.g.config.compat:
var orig = n
inc n
let s = c.c.semGetSize(c.c[], n)
var err = false
let value = asSigned(s, err)
if err:
cannotEval orig
else:
result = intValue(c, value, orig.info)
else:
cannotEval n
of PlusSetX, MinusSetX, XorSetX, MulSetX:
result = evalSetOp(c, n, n.exprKind)
else:
Expand Down
9 changes: 7 additions & 2 deletions src/nimony/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,10 @@ proc semStmtCallback(c: var SemContext; dest: var TokenBuf; n: Cursor) =
swap c.dest, dest
c.phase = oldPhase


proc semGetSize(c: var SemContext; n: Cursor; strict=false): xint =
getSize(n, c.g.config.bits div 8, strict)

proc sameIdent(sym: SymId; str: StrId): bool =
# XXX speed this up by using the `fieldCache` idea
var name = pool.syms[sym]
Expand Down Expand Up @@ -1391,7 +1395,7 @@ proc semPragma(c: var SemContext; n: var Cursor; crucial: var CrucialPragma; kin
c.dest.addParRi()
of NodeclP, SelectanyP, ThreadvarP, GlobalP, DiscardableP, NoreturnP, BorrowP,
NoSideEffectP, NodestroyP, BycopyP, ByrefP, InlineP, NoinlineP, NoinitP,
InjectP, GensymP, UntypedP, SideEffectP, BaseP, ClosureP, PassiveP:
InjectP, GensymP, UntypedP, SideEffectP, BaseP, ClosureP, PassiveP, IncompleteStructP:
crucial.flags.incl pk
c.dest.add parLeToken(pk, n.info)
c.dest.addParRi()
Expand Down Expand Up @@ -5367,7 +5371,8 @@ proc semcheck*(infile, outfile: string; config: sink NifConfig; moduleFlags: set
canSelfExec: canSelfExec,
pending: createTokenBuf(),
executeCall: exprexec.executeCall,
semStmtCallback: semStmtCallback)
semStmtCallback: semStmtCallback,
semGetSize: semGetSize)

for magic in ["typeof", "compiles", "defined", "declared"]:
c.unoverloadableMagics.incl(pool.strings.getOrIncl(magic))
Expand Down
5 changes: 4 additions & 1 deletion src/nimony/semdata.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import std / [tables, sets, os, syncio, formatfloat, assertions]
include ".." / lib / nifprelude
import ".." / lib / [symparser, nifindexes]
import nimony_model, symtabs, builtintypes, decls, programs, magics, reporters, nifconfig
import nimony_model, symtabs, builtintypes, decls, programs, magics, reporters, nifconfig, xints

Check warning on line 12 in src/nimony/semdata.nim

View workflow job for this annotation

GitHub Actions / windows-amd64-nim-devel (master)

imported and not used: 'reporters' [UnusedImport]

Check warning on line 12 in src/nimony/semdata.nim

View workflow job for this annotation

GitHub Actions / macos-arm64-nim-devel (master)

imported and not used: 'reporters' [UnusedImport]

Check warning on line 12 in src/nimony/semdata.nim

View workflow job for this annotation

GitHub Actions / linux-amd64-nim-devel (master)

imported and not used: 'reporters' [UnusedImport]

import ".." / gear2 / modnames

Expand Down Expand Up @@ -74,6 +74,8 @@

SemExecutor* = proc (c: var SemContext; routine: Routine; result: var TokenBuf; call: Cursor; info: PackedLineInfo): string {.nimcall.}
SemStmtCallback* = proc (c: var SemContext; dest: var TokenBuf; n: Cursor) {.nimcall.}
SemGetSize* = proc(c: var SemContext; n: Cursor; strict=false): xint {.nimcall.}


SemContext* = object
dest*: TokenBuf
Expand Down Expand Up @@ -126,6 +128,7 @@
pragmaStack*: seq[Cursor] # used to implement {.push.} and {.pop.}
executeCall*: SemExecutor
semStmtCallback*: SemStmtCallback
semGetSize*: SemGetSize
passL*: seq[string]
passC*: seq[string]
genericInnerProcs*: HashSet[SymId] # these are special in that they must be instantiated in specific places
Expand Down
5 changes: 2 additions & 3 deletions src/nimony/sizeof.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ proc parseTypePragmas(n: Cursor): TypePragmas =
inc n
while n.kind != ParRi:
case n.pragmaKind:
of {PackedP, UnionP, InheritableP}:
of {PackedP, UnionP, InheritableP, IncompleteStructP}:
result.pragmas.incl n.pragmaKind
skip n
else:
Expand All @@ -91,7 +91,6 @@ proc getSizeObject(c: var SizeofValue; cache: var Table[SymId, SizeofValue]; ite
# selector
let field = takeLocal(n, SkipFinalParRi)
getSize c, cache, field.typ, ptrSize

var cCase = createSizeofValue(c.strict)
while n.kind != ParRi:
case n.substructureKind
Expand Down Expand Up @@ -180,7 +179,7 @@ proc getSize(c: var SizeofValue; cache: var Table[SymId, SizeofValue]; n: Cursor
else:
update c, 8, 8
of ObjectT:
if c.strict:
if c.strict or (IncompleteStructP in pragmas.pragmas):
# mark as invalid as we pretend to not to know the alignment the backend ends up using etc.
c.overflow = true
var n = n
Expand Down
Loading