Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nifc: Unary negation operator #21

Merged
merged 1 commit into from
Jul 21, 2024
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/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