From 59ee694e2266b29dff595286647998eb448537ac Mon Sep 17 00:00:00 2001 From: dos-reis Date: Mon, 28 Feb 2011 09:47:25 +0000 Subject: * interp/i-code.boot: Move content to i-coerce.boot. Delete. --- src/interp/i-coerce.boot | 111 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) (limited to 'src/interp/i-coerce.boot') diff --git a/src/interp/i-coerce.boot b/src/interp/i-coerce.boot index 89e1699b..a56ae5d1 100644 --- a/src/interp/i-coerce.boot +++ b/src/interp/i-coerce.boot @@ -1361,3 +1361,114 @@ hasCorrectTarget(m,sig is [dc,tar,:.]) == tar is ['Union,t,'failed] => t=m tar is ['Union,'failed,t] and t=m + +--% Interpreter Code Generation Routines + +--Modified by JHD 9/9/93 to fix a problem with coerces inside +--interpreter functions being used as mappings. They were being +--handled with $useCoerceOrCroak being NIL, and therefore internal +--coercions were not correctly handled. Fix: remove dependence +--on $useCoerceOrCroak, and test explicitly for Mapping types. + +--% COERCE + +intCodeGenCOERCE(triple,t2) == + -- NOTE: returns a triple + t1 := objMode triple + t1 = $EmptyMode => NIL + t1 = t2 => triple + val := objVal triple + + -- if request is for a coerce to t2 from a coerce from + -- to to t1, and t1 = Void or canCoerce(t0,t2), then optimize + + (val is ['coerceOrCroak,trip,t1', .]) and + (t0 := objCodeMode trip) and ([.,val0] := objCodeVal trip) and + ( (t1 = $Void) or canCoerceFrom(removeQuote t0,t2) ) => + -- just generate code for coercion, don't coerce constants + -- might be too big + intCodeGenCOERCE(objNew(val0, removeQuote t0), t2) + + val is ['THROW,label,code] => + if label is ['QUOTE, l] then label := l + null($compilingMap) or (label ~= mapCatchName($mapName)) => + objNew(['THROW,label,getValueNormalForm + intCodeGenCOERCE(objNew(code,t1),t2)],t2) + -- we have a return statement. just send it back as is + objNew(val,t2) + + val is ['PROGN,:code,lastCode] => + objNew(['PROGN,:code,getValueNormalForm + intCodeGenCOERCE(objNew(lastCode,t1),t2)],t2) + + val is ['%when,:conds] => + objNew(['%when, + :[[p,getValueNormalForm intCodeGenCOERCE(objNew(v,t1),t2)] + for [p,v] in conds]],t2) + + -- specially handle subdomain + absolutelyCanCoerceByCheating(t1,t2) => objNew(val,t2) + + -- specially handle coerce to Any + t2 = $Any => objNew(['CONS,MKQ t1,val],t2) + + -- optimize coerces from Any + (t1 = $Any) and (val is ['CONS,t1',val']) => + intCodeGenCOERCE(objNew(val',removeQuote t1'),t2) + + -- specially handle coerce from Equation to Boolean + (t1 is ['Equation,:.]) and (t2 = $Boolean) => + coerceByFunction(triple,t2) + + -- next is hack for if-then-elses + (t1 = '$NoValueMode) and (val is ['%when,pred]) => + code := + ['%when,pred, + ['%otherwise,['throwKeyedMsg,MKQ "S2IM0016",MKQ $mapName]]] + objNew(code,t2) + + -- optimize coerces to Expression + t2 = $OutputForm => + coerceByFunction(triple,t2) + + isSubDomain(t1, $Integer) => + intCodeGenCOERCE(objNew(val, $Integer), t2) + + -- generate code + -- 1. See if the coercion will go through (absolutely) + -- Must be careful about variables or else things like + -- P I --> P[x] P I might not have the x in the original polynomial + -- put in the correct place + + (not containsVariables(t2)) and canCoerceByFunction(t1,t2) => + -- try coerceByFunction + (not canCoerceByMap(t1,t2)) and + (code := coerceByFunction(triple,t2)) => code + intCodeGenCoerce1(val,t1,t2) + + -- 2. Set up a failure point otherwise + + intCodeGenCoerce1(val,t1,t2) + +intCodeGenCoerce1(val,t1,t2) == + -- Internal function to previous one + -- designed to ensure that we don't use coerceOrCroak on mappings +--(t2 is ['Mapping,:.]) => THROW('coerceOrCroaker, 'croaked) + objNew(['coerceOrCroak,objNewCode(['wrap,val],t1), + MKQ t2, MKQ $mapName],t2) + +--% Map components + +wrapMapBodyWithCatch body == + -- places a CATCH around the map body + -- note that we will someday have to fix up the catch identifier + -- to use the generated internal map name + $mapThrowCount = 0 => body + if body is ['failCheck,['coerceOrFail,trip,targ,mapn]] + then + trip is ['LIST,v,m,e] => + ['failCheck,['coerceOrFail, + ['LIST,['CATCH,MKQ mapCatchName $mapName, v],m,e],targ,mapn]] + keyedSystemError("S2GE0016",['"wrapMapBodyWithCatch", + '"bad CATCH for in function form"]) + else ['CATCH,MKQ mapCatchName $mapName,body] -- cgit v1.2.3