Skip to content

Commit

Permalink
nifler: now has a spec in the form of tags.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Feb 13, 2025
1 parent 229266d commit 3c7ab46
Show file tree
Hide file tree
Showing 15 changed files with 1,204 additions and 993 deletions.
180 changes: 97 additions & 83 deletions doc/tags.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
| Name | Enums | Description |
|----------------------|-----------------------------|---------------|
| err | X, TN | indicates an error |
| suf | C, X | literal with suffix annotation |
| at | C, X, TN | array indexing operation |
| deref | C, X | pointer deref operation |
| dot | C, X | object field selection |
| err | X, TN, L | indicates an error |
| suf | C, X, L | literal with suffix annotation |
| at | C, X, TN, L | array indexing operation |
| deref | C, X, L | pointer deref operation |
| dot | C, X, L | object field selection |
| pat | C, X | pointer indexing operation |
| par | C, X | syntactic parenthesis |
| addr | C, X | address of operation |
| nil | C, X | nil pointer value |
| par | C, X, L | syntactic parenthesis |
| addr | C, X, L | address of operation |
| nil | C, X, L | nil pointer value |
| inf | C, X | positive infinity floating point value |
| neginf | C, X | negative infinity floating point value |
| nan | C, X | NaN floating point value |
Expand All @@ -22,12 +22,14 @@
| alignof | C, X | `alignof` operation |
| offsetof | C, X | `offsetof` operation |
| oconstr | C | object constructor |
| obj | X | object constructor |
| obj | X, L | object constructor |
| aconstr | C | array constructor |
| arr | X | array constructor |
| bracket | X | untyped array constructor |
| curly | X | untyped set constructor |
| kv | SU | key-value pair |
| bracket | X, L | untyped array constructor |
| curly | X, L | untyped set constructor |
| curlyat | X, L | curly expression `a{i}` |
| kv | SU, L | key-value pair |
| vv | SUN, L | value-value pair (used for explicitly named arguments in function calls) | 
| add | C, X | |
| sub | C, X | |
| mul | C, X | |
Expand All @@ -43,59 +45,59 @@
| neq | C, X | |
| le | C, X | |
| lt | C, X | |
| cast | C, X | |
| cast | C, X, L | `cast` operation |
| conv | C, X | type conversion |
| call | C, X, SC, SN | call operation |
| cmd | SN, X | command operation |
| call | C, X, SC, SN, L | call operation |
| cmd | SN, X, L | command operation |
| range | SU | `(range a b)` construct |
| ranges | SU | |
| ranges | SU, L | |
| gvar | SC, Z | global variable declaration |
| tvar | SC, Z | thread local variable declaration |
| var | SC, SN, Y, Z | variable declaration |
| param | SU, Y, Z | parameter declaration |
| const | SC, SN, Y, Z | const variable declaration |
| var | SC, SN, Y, Z, L | variable declaration |
| param | SU, Y, Z, L | parameter declaration |
| const | SC, SN, Y, Z, L | const variable declaration |
| result | Y, SN | result variable declaration |
| let | Y, SN | let variable declaration |
| let | Y, SN, L | let variable declaration |
| cursor | Y, SN | cursor variable declaration |
| typevar | Y, SU | type variable declaration |
| efld | Y, Z, SU | enum field declaration |
| fld | SU, Y, Z | field declaration |
| proc | SC, SN, Y, Z | proc declaration |
| func | SN, Y | function declaration |
| iterator | SN, Y, TN | iterator declaration |
| converter | SN, Y | converter declaration |
| method | SN, Y | method declaration |
| macro | SN, Y | macro declaration |
| template | SN, Y | template declaration |
| type | SC, SN, Y | type declaration |
| block | SN, Y | block declaration |
| typevar | Y, SU, L | type variable declaration |
| efld | Y, Z, SU, L | enum field declaration |
| fld | SU, Y, Z, L | field declaration |
| proc | SC, SN, Y, Z, L | proc declaration |
| func | SN, Y, L | function declaration |
| iterator | SN, Y, TN, L | iterator declaration |
| converter | SN, Y, L | converter declaration |
| method | SN, Y, L | method declaration |
| macro | SN, Y, L | macro declaration |
| template | SN, Y, L | template declaration |
| type | SC, SN, Y, L | type declaration |
| block | SN, Y, L | block declaration |
| module | Y | module declaration |
| cchoice | X, Y | closed choice |
| ochoice | X | open choice |
| emit | SC, SN, PN | emit statement |
| asgn | SC, SN | assignment statement |
| asgn | SC, SN, L | assignment statement |
| scope | SC, SN | explicit scope annotation, like `stmts` |
| if | SC, SN | if statement header |
| when | SN | when statement header |
| elif | SU | pair of (condition, action) |
| else | SU | `else` action |
| typevars | SUN | type variable/generic parameters |
| break | SC, SN | `break` statement |
| continue | SN | `continue` statement |
| for | SN | for statement |
| while | SC, SN | `while` statement |
| case | SC, SN | `case` statement |
| of | SU | `of` branch within a `case` statement |
| if | SC, SN, L | if statement header |
| when | SN, L | when statement header |
| elif | SU, L | pair of (condition, action) |
| else | SU, L | `else` action |
| typevars | SUN, L | type variable/generic parameters |
| break | SC, SN, L | `break` statement |
| continue | SN, L | `continue` statement |
| for | SN, L | for statement |
| while | SC, SN, L| `while` statement |
| case | SC, SN, L | `case` statement |
| of | SU, L | `of` branch within a `case` statement |
| lab | SC, Z | label, target of a `jmp` instruction |
| jmp | SC | jump/goto instruction |
| ret | SC, SN | `return` instruction |
| yld | SN | yield statement |
| stmts | SC, SN | list of statements |
| params | TC, TN | list of proc parameters, also used as a "proc type" |
| ret | SC, SN, L | `return` instruction |
| yld | SN, L | yield statement |
| stmts | SC, SN, L | list of statements |
| params | TC, TN, L | list of proc parameters, also used as a "proc type" |
| union | TC | union declaration |
| object | TC, TN | object type declaration |
| enum | TC, TN | enum type declaration |
| proctype | TC, TN | proc type declaration (soon obsolete, use params instead) |
| object | TC, TN, L | object type declaration |
| enum | TC, TN, L | enum type declaration |
| proctype | TC, TN, L | proc type declaration (soon obsolete, use params instead) |
| atomic | TQC | `atomic` type qualifier for NIFC |
| ro | TQC | `readonly` (= `const`) type qualifier for NIFC |
| restrict | TQC | type qualifier for NIFC |
Expand All @@ -106,7 +108,7 @@
| c | TC, TN | `char` builtin type |
| bool | TC, TN | `bool` builtin type |
| void | TC, TN | `void` return type |
| ptr | TC, TN | `ptr` type contructor |
| ptr | TC, TN, L | `ptr` type contructor |
| array | TC, TN | `array` type constructor |
| flexarray | TC | `flexarray` type constructor |
| aptr | TC | "pointer to array of" type constructor |
Expand All @@ -125,48 +127,52 @@
| varargs | PP, TN | `varargs` proc annotation |
| was | PC | |
| selectany | PP | |
| pragmas | SU, SN | begin of pragma section |
| pragmas | SU, SN, L | begin of pragma section |
| pragmax | X, L | pragma expressions |
| align | PP | |
| bits | PP | |
| vector | PC | |
| imp | SC | import declaration |
| nodecl | P | `nodecl` annotation |
| incl | SC, SN | `#include` statement or `incl` set operation |
| excl | SN | `excl` set operation |
| include | SN | `include` statement |
| import | SN | `import` statement |
| from | SN | `from` statement |
| importexcept | SN | `importexcept` statement |
| export | SN | `export` statement |
| comment | SN | `comment` statement |
| discard | SC, SN | `discard` statement |
| try | SC, SN | `try` statement |
| raise | SC, SN | `raise` statement |
| include | SN, L | `include` statement |
| import | SN, L | `import` statement |
| importas | SN, L | `import as` statement |
| from | SN, L | `from` statement |
| importexcept | SN, L | `importexcept` statement |
| export | SN, L | `export` statement |
| exportexcept | SN, L | `exportexcept` statement |
| comment | SN, L | `comment` statement |
| discard | SC, SN, L | `discard` statement |
| try | SC, SN, L | `try` statement |
| raise | SC, SN, L | `raise` statement |
| onerr | SC | error handling statement |
| raises | PP | proc annotation |
| errs | PPC | proc annotation |
| static | PC, TN | `static` type or annotation |
| static | PC, TN, L | `static` type or annotation |
| ite | G | if-then-else |
| graph | G | disjoint subgraph annotation |
| forbind | G | bindings for a `for` loop but the loop itself is mapped to gotos |
| kill | G | some.var is about to disappear (scope exit) |
| unpackflat | SUN | unpack into flat variable list |
| unpacktup | SUN | unpack tuple |
| except | SUN | except subsection |
| fin | SUN | finally subsection |
| refobj | TN | `ref object` type |
| ptrobj | TN | `ptr object` type |
| tuple | TN | `tuple` type |
| unpackflat | SUN, L | unpack into flat variable list |
| unpacktup | SUN, L | unpack tuple |
| unpackdecl | SN, L | unpack var/let/const declaration |
| except | SUN, L | except subsection |
| fin | SUN, L | finally subsection |
| refobj | TN, L | `ref object` type |
| ptrobj | TN, L | `ptr object` type |
| tuple | TN, L | `tuple` type |
| onum | TN | enum with holes type |
| ref | TN | `ref` type |
| mut | TN | `mut` type |
| out | TN | `out` type |
| ref | TN, L | `ref` type |
| mut | TN, L | `mut` type |
| out | TN, L | `out` type |
| lent | TN | `lent` type |
| sink | TN | `sink` type |
| nilt | TN | `nilt` type |
| concept | TN | `concept` type |
| distinct | TN | `distinct` type |
| itertype | TN | `itertype` type |
| concept | TN, L | `concept` type |
| distinct | TN, L | `distinct` type |
| itertype | TN, L | `itertype` type |
| rangetype | TN | `rangetype` type |
| uarray | TN | `uarray` type |
| openarray | TN | `openarray` type |
Expand Down Expand Up @@ -200,33 +206,35 @@
| ensures | PN | `ensures` pragma |
| build | PN | `build` pragma |
| string | PN | `string` pragma |
| quoted | X | name in backticks |
| quoted | X, L | name in backticks |
| hderef | X | hidden pointer deref operation |
| ddot | X | deref dot |
| haddr | X | hidden address of operation |
| newobj | X | new object constructor |
| tup | X | tuple constructor |
| tup | X, L | tuple constructor |
| setconstr | X | set constructor |
| tabconstr | X, L | table constructor |
| ashr | X | |
| oconv | X | object conversion |
| hconv | X | hidden basic type conversion |
| dconv | X | conversion between `distinct` types |
| callstrlit | X | |
| infix | X | |
| prefix | X | |
| callstrlit | X, L | |
| infix | X, L | |
| prefix | X, L | |
| hcall | X | hidden converter call |
| compiles | X | |
| declared | X | |
| defined | X | |
| high | X | |
| low | X | |
| typeof | X | |
| typeof | X, L | |
| unpack | X | |
| enumtostr | X | |
| ismainmodule | X | |
| defaultobj | X | |
| defaulttup | X | |
| expr | X | |
| expr | X, L | |
| do | X, L | `do` expression |
| arrat | X | |
| tupat | X | |
| plusset | X | |
Expand All @@ -246,3 +254,9 @@
| sinkh | X | |
| trace | X | |
| errv | C | error flag for `NIFC` |
| staticstmt | SN, L | `static` statement |
| bind | SN, L | `bind` statement |
| mixin | SN, L | `mixin` statement |
| using | SN, L | `using` statement |
| asm | SN, L | `asm` statement |
| defer | SN, L | `defer` statement |
2 changes: 2 additions & 0 deletions src/hexer/duplifier.nim
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ proc tr(c: var Context; n: var Cursor; e: Expects) =
trSons c, n, WantNonOwner
of DefaultobjX, DefaulttupX, BracketX, CurlyX:
raiseAssert "nodekind should have been eliminated in sem.nim"
of PragmaxX, CurlyatX, TabconstrX, DoX:
trSons c, n, e
of NoExpr:
case n.stmtKind
of RetS:
Expand Down
4 changes: 3 additions & 1 deletion src/hexer/mover.nim
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ proc singlePath(pc, x: Cursor; pcs: var seq[Cursor]; otherUsage: var Cursor): bo
otherUsage = pc
return false
of IfS, WhenS, WhileS, ForS, CaseS, TryS, YldS, RaiseS, ExportS,
IncludeS, ImportS, FromS, ImportExceptS, CommentS, PragmasS:
IncludeS, ImportS, FromS, ImportExceptS, CommentS, PragmasS,
ImportasS, ExportexceptS, BindS, MixinS, UsingS,
UnpackDeclS, StaticstmtS, AsmS, DeferS:
raiseAssert "BUG: statement not eliminated: " & $pc.stmtKind
of ProcS, FuncS, IteratorS, ConverterS, MethodS, MacroS, TemplateS, TypeS:
# declarative junk we don't care about:
Expand Down
7 changes: 4 additions & 3 deletions src/hexer/nifcgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ proc traverseStmt(e: var EContext; c: var Cursor; mode = TraverseAll) =
inc c
e.loop c:
traverseExpr e, c
of EmitS:
of EmitS, AsmS:
e.dest.add c
inc c
e.loop c:
Expand Down Expand Up @@ -1249,13 +1249,14 @@ proc traverseStmt(e: var EContext; c: var Cursor; mode = TraverseAll) =
of BlockS: traverseBlock e, c
of IfS: traverseIf e, c
of CaseS: traverseCase e, c
of YldS, ForS, InclS, ExclS:
of YldS, ForS, InclS, ExclS, DeferS, UnpackDeclS:
error e, "BUG: not eliminated: ", c
of TryS, RaiseS:
error e, "BUG: not implemented: ", c
of FuncS, ProcS, ConverterS, MethodS:
traverseProc e, c, mode
of MacroS, TemplateS, IncludeS, ImportS, FromS, ImportExceptS, ExportS, CommentS, IteratorS:
of MacroS, TemplateS, IncludeS, ImportS, FromS, ImportExceptS, ExportS, CommentS, IteratorS,
ImportasS, ExportexceptS, BindS, MixinS, UsingS, StaticstmtS:
# pure compile-time construct, ignore:
skip c
of TypeS:
Expand Down
8 changes: 4 additions & 4 deletions src/hexer/xelim.nim
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ proc trStmt(c: var Context; dest: var TokenBuf; n: var Cursor) =

of WhileS:
trWhile c, dest, n
of AsgnS, CallS, InclS, ExclS:
of AsgnS, CallS, InclS, ExclS, AsmS, DeferS:
# IMPORTANT: Stores into `tar` helper!
var tar = Target(m: IsAppend)
tar.t.copyInto n:
Expand All @@ -383,15 +383,15 @@ proc trStmt(c: var Context; dest: var TokenBuf; n: var Cursor) =
of IteratorS, TemplateS, TypeS, EmitS, BreakS, ContinueS,
ForS, CmdS, IncludeS, ImportS, FromS, ImportExceptS,
ExportS, CommentS,
PragmasS:
PragmasS, ImportasS, ExportexceptS, BindS, MixinS, UsingS:
takeTree dest, n
of ScopeS:
of ScopeS, StaticstmtS:
c.typeCache.openScope()
copyInto(dest, n):
while n.kind != ParRi:
trStmt c, dest, n
c.typeCache.closeScope()
of StmtsS:
of StmtsS, UnpackDeclS:
copyInto(dest, n):
while n.kind != ParRi:
trStmt 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

Loading

0 comments on commit 3c7ab46

Please sign in to comment.