Skip to content

Commit

Permalink
Unary negation operator (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
SirOlaf authored Jul 21, 2024
1 parent 29e5f10 commit 311a001
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
1 change: 1 addition & 0 deletions doc/nifc-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ Expr ::= Number | CharLiteral | StringLiteral |
(and Expr Expr) | # "&&"
(or Expr Expr) | # "||"
(not Expr) | # "!"
(neg Expr) |
(sizeof Expr) |
(oconstr Type (kv Symbol Expr)*) | # (object constructor){...}
(aconstr Type Expr*) | # array constructor
Expand Down
15 changes: 3 additions & 12 deletions src/nifc/genexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ proc genLvalue(c: var GeneratedCode; t: Tree; n: NodePos) =
let name = mangle(c.m.lits.strings[lit])
c.add name
c.requestedSyms.incl name
of DerefC:
let arg = n.firstSon
c.add ParLe
c.add "*"
genx c, t, arg
c.add ParRi
of DerefC: unop "*"
of AtC:
let (a, i) = sons2(t, n)
genx c, t, a
Expand Down Expand Up @@ -148,12 +143,7 @@ proc genx(c: var GeneratedCode; t: Tree; n: NodePos) =
c.add ParLe
genx c, t, arg
c.add ParRi
of AddrC:
let arg = n.firstSon
c.add ParLe
c.add "&"
genx c, t, arg
c.add ParRi
of AddrC: unop "&"
of SizeofC:
let arg = n.firstSon
c.add "sizeof"
Expand All @@ -175,6 +165,7 @@ proc genx(c: var GeneratedCode; t: Tree; n: NodePos) =
of AndC: cmpop " && "
of OrC: cmpop " || "
of NotC: unOp " !"
of NegC: unOp " -"
of EqC: cmpop " == "
of LeC: cmpop " <= "
of LtC: cmpop " < "
Expand Down
1 change: 1 addition & 0 deletions src/nifc/nifc_model.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type
AndC = "and"
OrC = "or"
NotC = "not"
NegC = "neg"
SizeofC = "sizeof"
OconstrC = "oconstr"
AconstrC = "aconstr"
Expand Down

0 comments on commit 311a001

Please sign in to comment.