[Nice-commit] Nice/stdlib/nice/lang/inline OptionOr.java,1.2,1.3
Brought to you by:
bonniot
|
From: <ar...@us...> - 2003-03-30 21:49:56
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline
In directory sc8-pr-cvs1:/tmp/cvs-serv26306/F:/nice/stdlib/nice/lang/inline
Modified Files:
OptionOr.java
Log Message:
Workaround for a bug that only happens when using primitive types as arguments for OptionOr.
This is really a strange bug, I couldn't find any other case where is bug also happens and I didn't find the exact cause of this bug so this patch is only a workaroud.
Index: OptionOr.java
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/OptionOr.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** OptionOr.java 19 Feb 2003 14:19:40 -0000 1.2
--- OptionOr.java 30 Mar 2003 21:49:53 -0000 1.3
***************
*** 16,19 ****
--- 16,20 ----
import gnu.expr.*;
import gnu.bytecode.*;
+ import nice.tools.code.EnsureTypeProc;
/**
***************
*** 37,49 ****
Expression[] args = exp.getArgs();
CodeAttr code = comp.getCode();
! args[0].compile(comp, target);
code.emitDup();
! code.emitIfNull();
code.emitPop(1);
! args[1].compile(comp, target);
! code.emitElse();
! code.emitFi();
}
public Type getReturnType (Expression[] args)
--- 38,72 ----
Expression[] args = exp.getArgs();
CodeAttr code = comp.getCode();
+ Label _end = new Label(code);
! fixAndLoadArgument(args[0], comp, target);
code.emitDup();
! code.emitGotoIfNotNull(_end);
code.emitPop(1);
! fixAndLoadArgument(args[1], comp, target);
! _end.define(code);
}
+
+ private void fixAndLoadArgument(Expression arg, Compilation comp, Target target)
+ {
+ if (arg instanceof ReferenceExp && ((ReferenceExp)arg).getBinding() != null)
+ {
+ Declaration.followAliases(((ReferenceExp)arg).getBinding()).load(comp);
+ return;
+ }
+ if ((arg instanceof ApplyExp) && (((ApplyExp)arg).getFunction() instanceof QuoteExp))
+ {
+ Object ensTP = ((QuoteExp)((ApplyExp)arg).getFunction()).getValue();
+ if (ensTP != null && (ensTP instanceof EnsureTypeProc))
+ {
+ Target t = new CheckedTarget(((EnsureTypeProc)ensTP).getReturnType(((ApplyExp)arg).getArgs()),
+ "nice.tools.code.EnsureTypeProc", gnu.mapping.WrongType.ARG_DESCRIPTION);
+ ((ApplyExp)arg).getArgs()[0].compile(comp, t);
+ return;
+ }
+ }
+ arg.compile(comp, target);
+ }
+
public Type getReturnType (Expression[] args)
|