Skip to content

Commit

Permalink
Make tvar and gvar part of Nimony's model (#554)
Browse files Browse the repository at this point in the history
* Integrate the move analyser into duplifier.nim

* Make tvar and gvar part of Nimony's model
  • Loading branch information
ringabout authored Feb 14, 2025
1 parent 4f9fd2e commit c97fc6e
Show file tree
Hide file tree
Showing 11 changed files with 787 additions and 773 deletions.
6 changes: 4 additions & 2 deletions doc/tags.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
| `(cmd X X*)` | NimonyStmt, NimonyExpr, NiflerKind | command operation |
| `(range X X)` | NifcOther, NimonyOther | `(range a b)` construct |
| `(ranges (range ...)*)` | NifcOther, NimonyOther, NiflerKind | |
| `(gvar D P T X)` | NifcStmt, NifcSym | global variable declaration |
| `(tvar D P T X)` | NifcStmt, NifcSym | thread local variable declaration |
| `(gvar D E P T X)`; `(gvar D P T X)` | NifcStmt, NimonyStmt, NimonySym, NifcSym | global variable declaration |
| `(tvar D E P T X)`; `(tvar D P T X)` | NifcStmt, NimonyStmt, NimonySym, NifcSym | thread local variable declaration |
| `(var D E P T X)`; `(var D P T X)` | NifcStmt, NimonyStmt, NimonySym, NifcSym, NiflerKind | variable declaration |
| `(param D E P T X)`; `(param D P T)` | NifcOther, NimonyOther, NimonySym, NifcSym, NiflerKind | parameter declaration |
| `(const D E P T X)`; `(const D P T)` | NifcStmt, NimonyStmt, NimonySym, NifcSym, NiflerKind | const variable declaration |
| `(result D E P T X)` | NimonySym, NimonyStmt | result variable declaration |
| `(glet D E P T X)` | NimonyStmt, NimonySym | global let variable declaration |
| `(tlet D E P T X)` | NimonyStmt, NimonySym | thread local let variable declaration |
| `(let D E P T X)` | NimonySym, NimonyStmt, NiflerKind | let variable declaration |
| `(cursor D E P T X)` | NimonySym, NimonyStmt | cursor variable declaration |
| `(typevar D E P T X)` | NimonySym, NifcOther, NimonyOther, NiflerKind | type variable declaration |
Expand Down
2 changes: 1 addition & 1 deletion src/hexer/mover.nim
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ proc singlePath(pc, x: Cursor; pcs: var seq[Cursor]; otherUsage: var Cursor): bo
of StmtsS, ScopeS, BlockS, ContinueS, BreakS:
inc pc
inc nested
of VarS, LetS, CursorS, ResultS, ConstS:
of VarS, LetS, CursorS, ResultS, ConstS, GvarS, TvarS, GletS, TletS:
inc pc
if root != NoSymId and pc.kind == SymbolDef and pc.symId == root:
# found the definition, so it gets a new value:
Expand Down
2 changes: 1 addition & 1 deletion src/hexer/nifcgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1210,7 +1210,7 @@ proc traverseStmt(e: var EContext; c: var Cursor; mode = TraverseAll) =
e.loop c:
traverseStmt e, c, mode
e.closeMangleScope()
of VarS, LetS, CursorS, ResultS:
of VarS, LetS, CursorS, ResultS, GvarS, TvarS, GletS, TletS:
traverseLocal e, c, (if e.nestedIn[^1][0] == StmtsS and mode in {TraverseTopLevel, TraverseSig}: "gvar" else: "var"), mode
of ConstS:
traverseLocal e, c, "const", mode
Expand Down
2 changes: 1 addition & 1 deletion src/hexer/xelim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ proc trStmt(c: var Context; dest: var TokenBuf; n: var Cursor) =
while n.kind != ParRi:
trExpr c, dest, n, tar
dest.add tar
of ResultS, LetS, VarS, CursorS, ConstS:
of ResultS, LetS, VarS, CursorS, ConstS, GvarS, TvarS, GletS, TletS:
trLocal c, dest, n
of ProcS, FuncS, MacroS, MethodS, ConverterS:
trProc c, dest, n
Expand Down
20 changes: 10 additions & 10 deletions src/models/callconv_tags.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
type
CallConv* = enum
NoCallConv
Cdecl = (111, "cdecl") ## `cdecl` calling convention
Stdcall = (112, "stdcall") ## `stdcall` calling convention
Safecall = (113, "safecall") ## `safecall` calling convention
Syscall = (114, "syscall") ## `syscall` calling convention
Fastcall = (115, "fastcall") ## `fastcall` calling convention
Thiscall = (116, "thiscall") ## `thiscall` calling convention
Noconv = (117, "noconv") ## no explicit calling convention
Member = (118, "member") ## `member` calling convention
Nimcall = (119, "nimcall") ## `nimcall` calling convention
Cdecl = (113, "cdecl") ## `cdecl` calling convention
Stdcall = (114, "stdcall") ## `stdcall` calling convention
Safecall = (115, "safecall") ## `safecall` calling convention
Syscall = (116, "syscall") ## `syscall` calling convention
Fastcall = (117, "fastcall") ## `fastcall` calling convention
Thiscall = (118, "thiscall") ## `thiscall` calling convention
Noconv = (119, "noconv") ## no explicit calling convention
Member = (120, "member") ## `member` calling convention
Nimcall = (121, "nimcall") ## `nimcall` calling convention

proc rawTagIsCallConv*(raw: uint32): bool {.inline.} =
raw >= 111'u32 and raw <= 119'u32
raw >= 113'u32 and raw <= 121'u32

140 changes: 70 additions & 70 deletions src/models/nifc_tags.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ type
CastC = (44, "cast") ## `cast` operation
ConvC = (45, "conv") ## type conversion
CallC = (46, "call") ## call operation
ErrvC = (252, "errv") ## error flag for `NIFC`
ErrvC = (254, "errv") ## error flag for `NIFC`

proc rawTagIsNifcExpr*(raw: uint32): bool {.inline.} =
let r = raw - 2'u32
r <= 255'u32 and r.uint8 in {0'u8, 1'u8, 2'u8, 3'u8, 4'u8, 5'u8, 6'u8, 7'u8, 8'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8, 19'u8, 20'u8, 21'u8, 27'u8, 28'u8, 29'u8, 30'u8, 31'u8, 32'u8, 33'u8, 34'u8, 35'u8, 36'u8, 37'u8, 38'u8, 39'u8, 40'u8, 41'u8, 42'u8, 43'u8, 44'u8, 250'u8}
r <= 255'u32 and r.uint8 in {0'u8, 1'u8, 2'u8, 3'u8, 4'u8, 5'u8, 6'u8, 7'u8, 8'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8, 19'u8, 20'u8, 21'u8, 27'u8, 28'u8, 29'u8, 30'u8, 31'u8, 32'u8, 33'u8, 34'u8, 35'u8, 36'u8, 37'u8, 38'u8, 39'u8, 40'u8, 41'u8, 42'u8, 43'u8, 44'u8, 252'u8}

type
NifcStmt* = enum
Expand All @@ -58,51 +58,51 @@ type
TvarS = (51, "tvar") ## thread local variable declaration
VarS = (52, "var") ## variable declaration
ConstS = (54, "const") ## const variable declaration
ProcS = (61, "proc") ## proc declaration
TypeS = (68, "type") ## type declaration
EmitS = (73, "emit") ## emit statement
AsgnS = (74, "asgn") ## assignment statement
ScopeS = (75, "scope") ## explicit scope annotation, like `stmts`
IfS = (76, "if") ## if statement header
BreakS = (81, "break") ## `break` statement
WhileS = (84, "while") ## `while` statement
CaseS = (85, "case") ## `case` statement
LabS = (87, "lab") ## label, target of a `jmp` instruction
JmpS = (88, "jmp") ## jump/goto instruction
RetS = (89, "ret") ## `return` instruction
StmtsS = (91, "stmts") ## list of statements
ImpS = (131, "imp") ## import declaration
InclS = (133, "incl") ## `#include` statement or `incl` set operation
DiscardS = (143, "discard") ## `discard` statement
TryS = (144, "try") ## `try` statement
RaiseS = (145, "raise") ## `raise` statement
OnerrS = (146, "onerr") ## error handling statement
ProcS = (63, "proc") ## proc declaration
TypeS = (70, "type") ## type declaration
EmitS = (75, "emit") ## emit statement
AsgnS = (76, "asgn") ## assignment statement
ScopeS = (77, "scope") ## explicit scope annotation, like `stmts`
IfS = (78, "if") ## if statement header
BreakS = (83, "break") ## `break` statement
WhileS = (86, "while") ## `while` statement
CaseS = (87, "case") ## `case` statement
LabS = (89, "lab") ## label, target of a `jmp` instruction
JmpS = (90, "jmp") ## jump/goto instruction
RetS = (91, "ret") ## `return` instruction
StmtsS = (93, "stmts") ## list of statements
ImpS = (133, "imp") ## import declaration
InclS = (135, "incl") ## `#include` statement or `incl` set operation
DiscardS = (145, "discard") ## `discard` statement
TryS = (146, "try") ## `try` statement
RaiseS = (147, "raise") ## `raise` statement
OnerrS = (148, "onerr") ## error handling statement

proc rawTagIsNifcStmt*(raw: uint32): bool {.inline.} =
let r = raw - 46'u32
r <= 255'u32 and r.uint8 in {0'u8, 4'u8, 5'u8, 6'u8, 8'u8, 15'u8, 22'u8, 27'u8, 28'u8, 29'u8, 30'u8, 35'u8, 38'u8, 39'u8, 41'u8, 42'u8, 43'u8, 45'u8, 85'u8, 87'u8, 97'u8, 98'u8, 99'u8, 100'u8}
r <= 255'u32 and r.uint8 in {0'u8, 4'u8, 5'u8, 6'u8, 8'u8, 17'u8, 24'u8, 29'u8, 30'u8, 31'u8, 32'u8, 37'u8, 40'u8, 41'u8, 43'u8, 44'u8, 45'u8, 47'u8, 87'u8, 89'u8, 99'u8, 100'u8, 101'u8, 102'u8}

type
NifcType* = enum
NoType
ParamsT = (92, "params") ## list of proc parameters, also used as a "proc type"
UnionT = (93, "union") ## union declaration
ObjectT = (94, "object") ## object type declaration
EnumT = (95, "enum") ## enum type declaration
ProctypeT = (96, "proctype") ## proc type declaration (soon obsolete, use params instead)
IT = (101, "i") ## `int` builtin type
UT = (102, "u") ## `uint` builtin type
FT = (103, "f") ## `float` builtin type
CT = (104, "c") ## `char` builtin type
BoolT = (105, "bool") ## `bool` builtin type
VoidT = (106, "void") ## `void` return type
PtrT = (107, "ptr") ## `ptr` type contructor
ArrayT = (108, "array") ## `array` type constructor
FlexarrayT = (109, "flexarray") ## `flexarray` type constructor
AptrT = (110, "aptr") ## "pointer to array of" type constructor
ParamsT = (94, "params") ## list of proc parameters, also used as a "proc type"
UnionT = (95, "union") ## union declaration
ObjectT = (96, "object") ## object type declaration
EnumT = (97, "enum") ## enum type declaration
ProctypeT = (98, "proctype") ## proc type declaration (soon obsolete, use params instead)
IT = (103, "i") ## `int` builtin type
UT = (104, "u") ## `uint` builtin type
FT = (105, "f") ## `float` builtin type
CT = (106, "c") ## `char` builtin type
BoolT = (107, "bool") ## `bool` builtin type
VoidT = (108, "void") ## `void` return type
PtrT = (109, "ptr") ## `ptr` type contructor
ArrayT = (110, "array") ## `array` type constructor
FlexarrayT = (111, "flexarray") ## `flexarray` type constructor
AptrT = (112, "aptr") ## "pointer to array of" type constructor

proc rawTagIsNifcType*(raw: uint32): bool {.inline.} =
let r = raw - 92'u32
let r = raw - 94'u32
r <= 255'u32 and r.uint8 in {0'u8, 1'u8, 2'u8, 3'u8, 4'u8, 9'u8, 10'u8, 11'u8, 12'u8, 13'u8, 14'u8, 15'u8, 16'u8, 17'u8, 18'u8}

type
Expand All @@ -112,49 +112,49 @@ type
RangeU = (48, "range") ## `(range a b)` construct
RangesU = (49, "ranges")
ParamU = (53, "param") ## parameter declaration
TypevarU = (58, "typevar") ## type variable declaration
EfldU = (59, "efld") ## enum field declaration
FldU = (60, "fld") ## field declaration
ElifU = (78, "elif") ## pair of (condition, action)
ElseU = (79, "else") ## `else` action
OfU = (86, "of") ## `of` branch within a `case` statement
PragmasU = (126, "pragmas") ## begin of pragma section
TypevarU = (60, "typevar") ## type variable declaration
EfldU = (61, "efld") ## enum field declaration
FldU = (62, "fld") ## field declaration
ElifU = (80, "elif") ## pair of (condition, action)
ElseU = (81, "else") ## `else` action
OfU = (88, "of") ## `of` branch within a `case` statement
PragmasU = (128, "pragmas") ## begin of pragma section

proc rawTagIsNifcOther*(raw: uint32): bool {.inline.} =
let r = raw - 27'u32
r <= 255'u32 and r.uint8 in {0'u8, 21'u8, 22'u8, 26'u8, 31'u8, 32'u8, 33'u8, 51'u8, 52'u8, 59'u8, 99'u8}
r <= 255'u32 and r.uint8 in {0'u8, 21'u8, 22'u8, 26'u8, 33'u8, 34'u8, 35'u8, 53'u8, 54'u8, 61'u8, 101'u8}

type
NifcPragma* = enum
NoPragma
InlineP = (120, "inline") ## `inline` proc annotation
NoinlineP = (121, "noinline") ## `noinline` proc annotation
AttrP = (122, "attr") ## general attribute annoation
VarargsP = (123, "varargs") ## `varargs` proc annotation
WasP = (124, "was")
SelectanyP = (125, "selectany")
AlignP = (128, "align")
BitsP = (129, "bits")
VectorP = (130, "vector")
NodeclP = (132, "nodecl") ## `nodecl` annotation
RaisesP = (147, "raises") ## proc annotation
ErrsP = (148, "errs") ## proc annotation
StaticP = (149, "static") ## `static` type or annotation
InlineP = (122, "inline") ## `inline` proc annotation
NoinlineP = (123, "noinline") ## `noinline` proc annotation
AttrP = (124, "attr") ## general attribute annoation
VarargsP = (125, "varargs") ## `varargs` proc annotation
WasP = (126, "was")
SelectanyP = (127, "selectany")
AlignP = (130, "align")
BitsP = (131, "bits")
VectorP = (132, "vector")
NodeclP = (134, "nodecl") ## `nodecl` annotation
RaisesP = (149, "raises") ## proc annotation
ErrsP = (150, "errs") ## proc annotation
StaticP = (151, "static") ## `static` type or annotation

proc rawTagIsNifcPragma*(raw: uint32): bool {.inline.} =
let r = raw - 120'u32
let r = raw - 122'u32
r <= 255'u32 and r.uint8 in {0'u8, 1'u8, 2'u8, 3'u8, 4'u8, 5'u8, 8'u8, 9'u8, 10'u8, 12'u8, 27'u8, 28'u8, 29'u8}

type
NifcTypeQualifier* = enum
NoQualifier
AtomicQ = (97, "atomic") ## `atomic` type qualifier for NIFC
RoQ = (98, "ro") ## `readonly` (= `const`) type qualifier for NIFC
RestrictQ = (99, "restrict") ## type qualifier for NIFC
CpprefQ = (100, "cppref") ## type qualifier for NIFC that provides a C++ reference
AtomicQ = (99, "atomic") ## `atomic` type qualifier for NIFC
RoQ = (100, "ro") ## `readonly` (= `const`) type qualifier for NIFC
RestrictQ = (101, "restrict") ## type qualifier for NIFC
CpprefQ = (102, "cppref") ## type qualifier for NIFC that provides a C++ reference

proc rawTagIsNifcTypeQualifier*(raw: uint32): bool {.inline.} =
raw >= 97'u32 and raw <= 100'u32
raw >= 99'u32 and raw <= 102'u32

type
NifcSym* = enum
Expand All @@ -164,12 +164,12 @@ type
VarY = (52, "var") ## variable declaration
ParamY = (53, "param") ## parameter declaration
ConstY = (54, "const") ## const variable declaration
EfldY = (59, "efld") ## enum field declaration
FldY = (60, "fld") ## field declaration
ProcY = (61, "proc") ## proc declaration
LabY = (87, "lab") ## label, target of a `jmp` instruction
EfldY = (61, "efld") ## enum field declaration
FldY = (62, "fld") ## field declaration
ProcY = (63, "proc") ## proc declaration
LabY = (89, "lab") ## label, target of a `jmp` instruction

proc rawTagIsNifcSym*(raw: uint32): bool {.inline.} =
let r = raw - 50'u32
r <= 255'u32 and r.uint8 in {0'u8, 1'u8, 2'u8, 3'u8, 4'u8, 9'u8, 10'u8, 11'u8, 37'u8}
r <= 255'u32 and r.uint8 in {0'u8, 1'u8, 2'u8, 3'u8, 4'u8, 11'u8, 12'u8, 13'u8, 39'u8}

Loading

0 comments on commit c97fc6e

Please sign in to comment.