summary refs log tree commit diff stats
path: root/compiler/plugins.nim
diff options
context:
space:
mode:
authorSimon Hafner <hafnersimon@gmail.com>2015-05-13 12:06:05 -0500
committerSimon Hafner <hafnersimon@gmail.com>2015-05-13 12:06:05 -0500
commit9c4a74637db266c3cfcffcfb1e65bae982c6e4bf (patch)
tree495f50a989d7ab696ddb0b7b0e815c572ab27f3c /compiler/plugins.nim
parentc55f884b5c0ebc0b637138a8de446ba1fd05acdf (diff)
parent0b184f2584221543a7dec9c8ae4a700533919e0c (diff)
downloadNim-9c4a74637db266c3cfcffcfb1e65bae982c6e4bf.tar.gz
Merge branch 'devel' into jpoirier-realtimeGCTest
Diffstat (limited to 'compiler/plugins.nim')
-rw-r--r--compiler/plugins.nim43
1 files changed, 43 insertions, 0 deletions
diff --git a/compiler/plugins.nim b/compiler/plugins.nim
new file mode 100644
index 000000000..1c9b7b77b
--- /dev/null
+++ b/compiler/plugins.nim
@@ -0,0 +1,43 @@
+#
+#
+#           The Nim Compiler
+#        (c) Copyright 2015 Andreas Rumpf
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+
+## Plugin support for the Nim compiler. Right now there are no plugins and they
+## need to be build with the compiler, no DLL support.
+
+import ast, semdata, idents
+
+type
+  Transformation* = proc (c: PContext; n: PNode): PNode {.nimcall.}
+  Plugin = ref object
+    fn, module, package: PIdent
+    t: Transformation
+    next: Plugin
+
+proc pluginMatches(p: Plugin; s: PSym): bool =
+  if s.name.id != p.fn.id: return false
+  let module = s.owner
+  if module == nil or module.kind != skModule or
+      module.name.id != p.module.id: return false
+  let package = module.owner
+  if package == nil or package.kind != skPackage or
+      package.name.id != p.package.id: return false
+  return true
+
+var head: Plugin
+
+proc getPlugin*(fn: PSym): Transformation =
+  var it = head
+  while it != nil:
+    if pluginMatches(it, fn): return it.t
+    it = it.next
+
+proc registerPlugin*(package, module, fn: string; t: Transformation) =
+  let oldHead = head
+  head = Plugin(fn: getIdent(fn), module: getIdent(module),
+                 package: getIdent(package), t: t, next: oldHead)