[Nice-commit] Nice/stdlib/nice/lang/inline OptionOr.java,1.3,1.4
Brought to you by:
bonniot
|
From: <bo...@us...> - 2003-04-02 16:44:54
|
Update of /cvsroot/nice/Nice/stdlib/nice/lang/inline
In directory sc8-pr-cvs1:/tmp/cvs-serv18474/stdlib/nice/lang/inline
Modified Files:
OptionOr.java
Log Message:
A simpler fix for OptionOr, when the first argument has an optional primitive
type.
Index: OptionOr.java
===================================================================
RCS file: /cvsroot/nice/Nice/stdlib/nice/lang/inline/OptionOr.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** OptionOr.java 30 Mar 2003 21:49:53 -0000 1.3
--- OptionOr.java 2 Apr 2003 16:44:50 -0000 1.4
***************
*** 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)
--- 38,53 ----
Expression[] args = exp.getArgs();
CodeAttr code = comp.getCode();
! // We cannot use target for the first argument, since its value maybe
! // be null, while the target may not.
! args[0].compile(comp, Target.pushObject);
code.emitDup();
! code.emitIfNotNull();
! target.compileFromStack(comp, code.topType());
! code.emitElse();
code.emitPop(1);
! args[1].compile(comp, target);
! code.emitFi();
}
public Type getReturnType (Expression[] args)
|