List of usage examples for org.objectweb.asm Opcodes INVOKEVIRTUAL
int INVOKEVIRTUAL
To view the source code for org.objectweb.asm Opcodes INVOKEVIRTUAL.
Click Source Link
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.addingExpressionRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//from www . j ava 2s .com /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * if there are 3 values, we add them */ if (generationContext.getParseTree().getChildCount() == 3) { /* * operation */ final AddingExpressionContext addingExpressionContext = (AddingExpressionContext) generationContext .getParseTree(); final CommonToken commonToken = (CommonToken) addingExpressionContext.getChild(1).getPayload(); if (commonToken.getType() == jvmBasicParser.PLUS) { /* * add */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"); generationContext.getMethodVisitor().visitInsn(Opcodes.DADD); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); } else { /* * swap the stack arguments so we have the prompt on top and the variable name next */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "swap", "()V"); /* * subtract */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getDouble", "()Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Double", "doubleValue", "()D"); generationContext.getMethodVisitor().visitInsn(Opcodes.DSUB); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); } return true; } else { /** * do nothing */ return true; } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.atnfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {// www .j a va 2s .c o m /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply abs */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "ATAN", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.cosfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//ww w.ja v a 2 s.co m /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply abs */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "COS", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.exponentExpressionRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/*from ww w . j a v a2s .c o m*/ /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * exponentiate if there were 3 args */ if (generationContext.getParseTree().getChildCount() == 3) { /* * pop the argument and apply exp */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "EXP", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); } return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.ifstmtRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//w ww . jav a 2 s . c o m if (generationContext.getParseTree().getChildCount() == 4) { /* * dispatch into the test */ final GenerationContext testGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(1)); Dispatcher.dispatchChildren(testGenerationContext); /* * check the result */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getBoolean", "()Ljava/lang/Boolean;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z"); /* * check result */ final Label l1 = new Label(); generationContext.getMethodVisitor().visitJumpInsn(Opcodes.IFEQ, l1); /* * process the contained tree */ final GenerationContext statementGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(3)); Dispatcher.dispatch(statementGenerationContext); /* * label to skip to */ generationContext.getMethodVisitor().visitLabel(l1); generationContext.getMethodVisitor().visitFrame(Opcodes.F_SAME, 0, null, 0, null); return true; } else if (generationContext.getParseTree().getChildCount() == 3) { /* * dispatch into the test */ final GenerationContext testGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(1)); Dispatcher.dispatchChildren(testGenerationContext); /* * check the result */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getBoolean", "()Ljava/lang/Boolean;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Boolean", "booleanValue", "()Z"); /* * check result */ final Label l1 = new Label(); generationContext.getMethodVisitor().visitJumpInsn(Opcodes.IFEQ, l1); /* * process the contained tree */ final GenerationContext statementGenerationContext = new GenerationContext(generationContext, generationContext.getParseTree().getChild(2)); Dispatcher.dispatch(statementGenerationContext); /* * label to skip to */ generationContext.getMethodVisitor().visitLabel(l1); generationContext.getMethodVisitor().visitFrame(Opcodes.F_SAME, 0, null, 0, null); return true; } else { throw new Exception( "Invalid number of tokens in subtree '" + generationContext.getParseTree().getChildCount() + "' expected 3 on line number: " + generationContext.getLineNumber()); } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.inputstmtRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {//w w w. jav a 2s . com /* * process the contained nodes. This will push the String prompt onto the stack, and a variable name */ Dispatcher.dispatchChildren(generationContext); /* * input with a prompt? INPUT <prompt> , <variable> */ if (generationContext.getParseTree().getChildCount() == 4) { /* * swap the stack arguments so we have the prompt on top and the variable name next */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "swap", "()V"); /* * print the prompt */ generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getAsString", "()Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V"); } /* * read a line and push onto value stack */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitTypeInsn(Opcodes.NEW, "java/lang/StringBuilder"); generationContext.getMethodVisitor().visitInsn(Opcodes.DUP); generationContext.getMethodVisitor().visitLdcInsn("\""); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "(Ljava/lang/String;)V"); generationContext.getMethodVisitor().visitTypeInsn(Opcodes.NEW, "java/io/BufferedReader"); generationContext.getMethodVisitor().visitInsn(Opcodes.DUP); generationContext.getMethodVisitor().visitTypeInsn(Opcodes.NEW, "java/io/InputStreamReader"); generationContext.getMethodVisitor().visitInsn(Opcodes.DUP); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), "inputStream", "Ljava/io/InputStream;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESPECIAL, "java/io/InputStreamReader", "<init>", "(Ljava/io/InputStream;)V"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESPECIAL, "java/io/BufferedReader", "<init>", "(Ljava/io/Reader;)V"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/io/BufferedReader", "readLine", "()Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); generationContext.getMethodVisitor().visitLdcInsn("\""); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/String;)V"); /* * swap the stack arguments so we have the variable name on top and the value below it */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "swap", "()V"); /* * set the variable */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, "com/khubla/jvmbasic/jvmbasicrt/Value", "getString", "()Ljava/lang/String;"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "setVariable", "(Ljava/lang/String;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.intfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/* ww w .j a va 2s. c o m*/ /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply abs */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "INT", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.leftfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/*from w ww . j a va 2 s. c om*/ /* * get the operands */ Dispatcher.dispatchChildren(generationContext); /* * there should be 6 values. grammar is "LEFT LPAREN expression COMMA expression RPAREN" */ if (generationContext.getParseTree().getChildCount() == 6) { generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "com/khubla/jvmbasic/jvmbasicrt/StringFunctions", "LEFT", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/String;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/String;)V"); return true; } else { throw new Exception("Invalid number of values passed to leftfuncRule"); } } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.lenfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {// w w w. j a v a2 s . c om /* * get the operands */ Dispatcher.dispatchChildren(generationContext); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "resolveValue", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, "com/khubla/jvmbasic/jvmbasicrt/StringFunctions", "LEN", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Integer;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Integer;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }
From source file:com.khubla.jvmbasic.jvmbasicc.function.impl.rule.logfuncRule.java
License:Open Source License
@Override public boolean execute(GenerationContext generationContext) throws Exception { try {/*from w w w .ja v a 2s .c o m*/ /* * get the argument */ Dispatcher.dispatchChildren(generationContext); /* * pop the argument and apply abs */ generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitVarInsn(Opcodes.ALOAD, 0); generationContext.getMethodVisitor().visitFieldInsn(Opcodes.GETFIELD, generationContext.getClassName(), RTLHelper.EXECUTIONCONTEXT_NAME, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT_TYPE); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "pop", "()Lcom/khubla/jvmbasic/jvmbasicrt/Value;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKESTATIC, RTLHelper.JASIC_RUNTIME_MATH, "LOG", "(Lcom/khubla/jvmbasic/jvmbasicrt/Value;)Ljava/lang/Double;"); generationContext.getMethodVisitor().visitMethodInsn(Opcodes.INVOKEVIRTUAL, RTLHelper.JASIC_RUNTIME_EXECUTIONCONTEXT, "push", "(Ljava/lang/Double;)V"); return true; } catch (final Exception e) { throw new Exception("Exception in execute", e); } }