summaryrefslogtreecommitdiff
path: root/ppc.fun
diff options
context:
space:
mode:
Diffstat (limited to 'ppc.fun')
-rw-r--r--ppc.fun42
1 files changed, 34 insertions, 8 deletions
diff --git a/ppc.fun b/ppc.fun
index 656a4b1..5c0cb2b 100644
--- a/ppc.fun
+++ b/ppc.fun
@@ -64,7 +64,7 @@ struct
fun tkClassErrorPrint (TkPos (pos, layers), cls) =
let
val printCtk = fn
- Ctk tk => printf T.Ptoken tk %
+ Ctk tk => printf T.Ptk tk %
| Cid => printf `"identifier" %
| Cconst => printf `"constant" %
| Cunop => printf `"unary operator" %
@@ -166,7 +166,7 @@ struct
Printf out `"\n" R offset2 `fname' `":" I line' `"|\t" %
else
();
- Printf out I col' `":" T.Ptoken tk `" ";
+ Printf out I col' `":" T.Ptk tk `" ";
(offset2, layers', (fname', line'))
end
@@ -480,7 +480,7 @@ struct
val macroName =
case macroName of T.Id id => id | _ => raise Unreachable
- val () = dprintf ppc `"\ndefine " `macroName %
+ val () = dprintf ppc `"\n#define " `macroName %
val parser =
if isFuncMacroDefine (size macroName) pos ppc then
@@ -552,9 +552,6 @@ struct
insertRevBody revBody ppc
end
- fun getClass ppc clList =
- getClassGeneric clList getToken raiseTkClassError ppc
-
and parseFuncMacroArgs mPos params ppc =
let
@@ -691,7 +688,7 @@ struct
fun unexpected tk prevTk =
raiseTkErrorP pos
- `"unexpected " T.Ptoken tk `" inside " T.Ptoken prevTk %
+ `"unexpected " T.Ptk tk `" inside " T.Ptk prevTk %
fun handleIfdef ifTk =
if tk = T.PpcElif then
@@ -866,6 +863,21 @@ struct
| _ => def ()
end
+ and handleUndef _ ppc =
+ let
+ val (tk, pos, ppc) = getTokenNoexpand ppc
+ val id = case tk of T.Id id => id | _ => raise Unreachable
+ val (_, _, ppc) = getClassNoexpand ppc [Ctk T.NewLine]
+ val (prevVal, macros) = Tree.delete macroCompare (#macros ppc) id
+ in
+ dprintf ppc `"\n#undef " `id %;
+ case prevVal of
+ NONE => warning pos
+ `"#undef: no macro with provided name was defined" %
+ | SOME _ => ();
+ updatePpc ppc s#macros macros %
+ end
+
and ppcFallback (_, pos) _ =
raiseTkError pos "directive is not implemented"
@@ -877,7 +889,7 @@ struct
(%T.PpcDefine, handleDefine),
(%T.PpcIfdef, handleIf),
(%T.PpcIfndef, handleIf),
- (%T.PpcUndef, ppcFallback),
+ (%T.PpcUndef, handleUndef),
(%T.PpcIf, handleIf),
(%T.PpcElse, ppcFallback),
(%T.PpcElif, ppcFallback),
@@ -935,4 +947,18 @@ struct
debugPrint' startCache ppc;
printf `"\n" %
end
+
+ fun getClass ppc clList =
+ let
+ fun getTokenSkipNL ppc =
+ let
+ val (tk, pos, ppc) = getToken ppc
+ in
+ case tk of
+ T.NewLine => getTokenSkipNL ppc
+ | _ => (tk, pos, ppc)
+ end
+ in
+ getClassGeneric clList getTokenSkipNL raiseTkClassError ppc
+ end
end