1313import java .util .concurrent .ExecutorService ;
1414import java .util .concurrent .Executors ;
1515import java .util .concurrent .Future ;
16+ import java .util .function .BiFunction ;
17+ import java .util .function .Function ;
1618import org .antlr .v4 .runtime .misc .Pair ;
1719import org .piccode .ast .Ast ;
1820import org .piccode .backend .Compiler ;
@@ -35,6 +37,7 @@ public class Context {
3537 private static final ExecutorService threadPool = Executors .newVirtualThreadPerTaskExecutor ();
3638 public static final ConcurrentMap <String , Future <PiccodeValue >> futureMap = new ConcurrentHashMap <>();
3739 public static final ConcurrentMap <Integer , Object > objectPool = new ConcurrentHashMap <>();
40+ private static final ConcurrentMap <String , BiFunction <Integer , Ast , PiccodeValue >> annotations = new ConcurrentHashMap <>();
3841
3942 public Context () {
4043 call_frames = new Stack <>();
@@ -64,6 +67,18 @@ public int getFramesCount() {
6467 return call_frames .size ();
6568 }
6669
70+ public static void addAnnotation (String name , BiFunction <Integer , Ast , PiccodeValue > fx ) {
71+ annotations .put (name , fx );
72+ }
73+
74+ public static BiFunction <Integer , Ast , PiccodeValue > getAnnotation (String name ) {
75+ return annotations .get (name );
76+ }
77+
78+ public static boolean hasAnnotation (String name ) {
79+ return annotations .containsKey (name );
80+ }
81+
6782 public static String makeThread (PiccodeClosure node ) {
6883 synchronized (Context .class ) {
6984 var ctx = node .frame == null ? top : threadContexts .get (node .frame );
0 commit comments