]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/internal/codegen/utils/SCLContextPreparationStep.java
(refs #7250) Merging master, minor CHR bugfixes
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / internal / codegen / utils / SCLContextPreparationStep.java
1 package org.simantics.scl.compiler.internal.codegen.utils;
2
3 import org.cojen.classfile.TypeDesc;
4 import org.simantics.scl.runtime.SCLContext;
5
6 public enum SCLContextPreparationStep implements PreparationStep<LocalVariable> {
7     INSTANCE;
8     
9     public final static TypeDesc SCL_CONTEXT = TypeDesc.forClass(SCLContext.class);
10     
11     public static LocalVariable getCurrent(MethodBuilder mb) {
12         LocalVariable var = mb.getPreparation(INSTANCE);
13         if(var == null) {
14             var = mb.createLocalVariable("sclContext", SCL_CONTEXT);
15             mb.invokeStatic(SCL_CONTEXT, "getCurrent", SCL_CONTEXT, Constants.EMPTY_TYPEDESC_ARRAY);
16             mb.storeLocal(var);
17             mb.addPreparation(INSTANCE, var);
18         }
19         return var;
20     }
21 }