summaryrefslogtreecommitdiff
path: root/gcc/testsuite/melt/tletmacro-3.melt
blob: bdcd283a0940ca4f10034c6db37069fa3a1e1bf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
;; file tletmacro-3.melt -*- lisp -*-
;; this sample code is in the public domain
#| run in buildir/gcc
 ln -sv $GCCMELT_SOURCE/gcc/testsuite/melt/tletmacro-3.melt
 ln -sv $GCCMELT_SOURCE/gcc/testsuite/melt/tletmacro-3-loaded.melt

 ./cc1 -fmelt-mode=runfile @meltbuild-common.args -Iinclude/ \
    -fmelt-init=@warmelt.quicklybuilt -fmelt-arg=tletmacro-3.melt \
     /dev/null -o /dev/null
## perhaps also: -fmelt-debugging=all -fmelt-out-descr-comment

or in a MELT module

gcc -fplugin=melt -fplugin-arg-melt-mode=runfile @meltbuild-common.args \
    -fplugin-arg-melt-init=@melt-default-modules.quicklybuilt -fplugin-arg-melt-arg=tletmacro-3.melt \
     -c -x c /dev/null -o /dev/null
|#
(module_is_gpl_compatible "public domain")

(let (
      (the_stdout (unsafe_get_field :sysdata_stdout initial_system_data))
      (:macro loadedmac (sexp env mexpander modctx)
	      (debug "macro loadedmac" " sexp=" sexp)
	      (let ( (arg1 (list_nth (usafe_get_field :sexp_contents sexp) 1))
		     (sloc (unsafe_get_field :loca_location sexp))
		     (sline (get_int sloc))
		     (res (instance class_source_apply
				    :loca_location sloc
				    :sapp_fun 'add2out
				    :sargop_args (tuple 'the_stdout "loadedmac@" sline ":" arg1)))
		     )
		(debug "macro loadedmac" " arg1=" arg1 " sline=" sline
		       "\n.. res=" res)
		res))
      )
  (debug "before loading tletmacro-3-loaded")
  (load "tletmacro-3-loaded.melt")
  (debug "after loading tletmacro-3-loaded")  
  )