aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/interp/c-util.boot1
-rw-r--r--src/interp/g-opt.boot5
-rw-r--r--src/interp/g-util.boot126
-rw-r--r--src/interp/slam.boot8
4 files changed, 54 insertions, 86 deletions
diff --git a/src/interp/c-util.boot b/src/interp/c-util.boot
index 79e040b6..be422d75 100644
--- a/src/interp/c-util.boot
+++ b/src/interp/c-util.boot
@@ -1079,6 +1079,7 @@ middleEndExpand x ==
x = '%true => 'T
isAtomicForm x => x
[op,:args] := x
+ IDENTP op and (op' := op has %Rename) => [op',:middleEndExpand args]
IDENTP op and (fun := getOpcodeExpander op) => apply(fun,x,nil)
op in $middleEndMacroList =>
middleEndExpand MACROEXPAND_-1 x
diff --git a/src/interp/g-opt.boot b/src/interp/g-opt.boot
index 827aecd4..85da2c38 100644
--- a/src/interp/g-opt.boot
+++ b/src/interp/g-opt.boot
@@ -403,8 +403,9 @@ $VMsideEffectFreeOperators ==
QEQCAR QCDR QCAR INTEGERP FLOATP STRINGP IDENTP SYMBOLP
MINUSP GREATERP ZEROP ODDP FLOAT_-RADIX FLOAT FLOAT_-SIGN FLOAT_-DIGITS
CGREATERP GGREATERP CHAR BOOLE GET BVEC_-GREATER FUNCALL
- %and %or %not %eq %ieq %equal %lt %le %gt %ge %head %tail
- %imul %iadd %isub %igcd)
+ %and %or %not %eq %ieq %ilt %ile %igt %ige %head %tail
+ %imul %iadd %isub %igcd %ilcm %iexp %imin %imax
+ %feq %flt %fle %fgt %fge %fmul %fadd %fsub %fexp %fmin %fmax)
++ List of simple VM operators
$simpleVMoperators ==
diff --git a/src/interp/g-util.boot b/src/interp/g-util.boot
index 0a78b182..139eff6e 100644
--- a/src/interp/g-util.boot
+++ b/src/interp/g-util.boot
@@ -212,62 +212,12 @@ expandCollect ["%collect",:iters,body] ==
expandRepeat ["%repeat",:iters,body] ==
expandLoop(iters,body,["voidValue"])
-
-expandGreaterEqual ["%ge",:args] ==
- [">=",:expandToVMForm args]
-
-expandGreater ["%gt",:args] ==
- [">",:expandToVMForm args]
-expandLessEqual ["%le",:args] ==
- ["<=",:expandToVMForm args]
-
-expandLess ["%lt",:args] ==
- ["<",:expandToVMForm args]
-
-- Logical operators
-expandNot ["%not",arg] ==
- ["NOT",expandToVMForm arg]
-
-expandAnd ["%and",:args] ==
- ["AND",:expandToVMForm args]
-
-expandOr ["%or",:args] ==
- ["OR",:expandToVMForm args]
-
--- Arithmetic operations
-
-expandIabs ["%iabs",arg] ==
- ["ABS",expandToVMForm arg]
-
-expandIexp ["%iexp",:args] ==
- ["EXPT",:expandToVMForm args]
-
-expandImul ["%imul",:args] ==
- ["*",:expandToVMForm args]
-
-expandIadd ["%iadd",:args] ==
- ["+",:expandToVMForm args]
-
-expandIsub ["%isub",:args] ==
- ["-",:expandToVMForm args]
-
expandEq ["%eq",:args] ==
["EQ",:expandToVMForm args]
-expandIeq ["%ieq",:args] ==
- ["EQL",:expandToVMForm args]
-
-expandImin ["%imin",:args] ==
- ["MIN",:expandToVMForm args]
-
-expandImax ["%imax",:args] ==
- ["MAX",:expandToVMForm args]
-
-expandIgcd ["%igcd",:args] ==
- ["GCD",:expandToVMForm args]
-
-- Local variable bindings
expandBind ["%bind",inits,body] ==
body := expandToVMForm body
@@ -286,43 +236,58 @@ expandStore ["%store",place,value] ==
cons? place => ["SETF",place,value]
["SETQ",place,value]
--- List operators
-
-expandHead ["%head",x] ==
- ["CAR",expandToVMForm x]
-
-expandTail ["%tail",x] ==
- ["CDR",expandToVMForm x]
-
+++ Opcodes with direct mapping to target operations.
+for x in [
+ -- unary Boolean operations
+ ['%not, :'NOT],
+
+ -- binary Boolean operations
+ ['%and, :'AND],
+ ['%or, :'OR],
+
+ -- unary integer operations.
+ ['%iabs,:'ABS],
+
+ -- binary integer operations.
+ ['%iadd,:"+"],
+ ['%iexp,:'EXPT],
+ ['%igcd,:'GCD],
+ ['%ige, :">="],
+ ['%igt, :">"],
+ ['%ilcm,:'LCM],
+ ['%ile, :"<="],
+ ['%ilt, :"<"],
+ ['%imax,:'MAX],
+ ['%imin,:'MIN],
+ ['%imul,:"*"],
+ ['%isub,:"-"],
+
+ -- unary float operations.
+ ['%fabs,:'ABS],
+
+ -- binary float operations.
+ ['%fadd,:"+"],
+ ['%fexp,:'EXPT],
+ ['%fge, :">="],
+ ['%fgt, :">"],
+ ['%fle, :"<="],
+ ['%flt, :"<"],
+ ['%fmax,:'MAX],
+ ['%fmin,:'MIN],
+ ['%fmul,:"*"],
+ ['%fsub,:"-"],
+
+ -- unary list operations
+ ['%head,:'CAR],
+ ['%tail,:'CDR]
+ ] repeat property(first x,'%Rename) := rest x
++ Table of opcode-expander pairs.
for x in [
- ["%not",:function expandNot],
- ["%and",:function expandAnd],
- ["%or",:function expandOr],
-
["%collect",:function expandCollect],
["%repeat",:function expandRepeat],
- ["%le",:function expandLessEqual],
- ["%lt",:function expandLess],
- ["%ge",:function expandGreaterEqual],
- ["%gt",:function expandGreater],
-
- ["%iabs",:function expandIabs],
- ["%imul",:function expandImul],
- ["%iexp",:function expandIexp],
- ["%iadd",:function expandIadd],
- ["%isub",:function expandIsub],
- ["%imin",:function expandImin],
- ["%imax",:function expandImax],
- ["%igcd",:function expandIgcd],
-
["%eq",:function expandEq],
- ["%ieq",:function expandIeq],
-
- ["%head",:function expandHead],
- ["%tail",:function expandTail],
["%bind",:function expandBind],
["%store",:function expandStore],
@@ -340,6 +305,7 @@ expandToVMForm x ==
x = '%true => 'T
isAtomicForm x => x
[op,:args] := x
+ IDENTP op and (op' := op has %Rename) => [op',:expandToVMForm args]
IDENTP op and (fun:= getOpcodeExpander op) => apply(fun,x,nil)
op' := expandToVMForm op
args' := expandToVMForm args
diff --git a/src/interp/slam.boot b/src/interp/slam.boot
index a2c2c778..a1ea2cb3 100644
--- a/src/interp/slam.boot
+++ b/src/interp/slam.boot
@@ -331,12 +331,12 @@ compileRecurrenceRelation(op,nam,argl,junk,[body,sharpArg,n,:initCode]) ==
mbody :=
preset := [initialSetCode,:initialResetCode,["%LET",max,["ELT",stateVar,0]]]
- phrase1:= [["%and",["%LET",max,["ELT",stateVar,0]],["%ge",sharpArg,max]],
+ phrase1:= [["%and",["%LET",max,["ELT",stateVar,0]],["%ige",sharpArg,max]],
[auxfn,:argl,stateVar]]
- phrase2:= [["%gt",sharpArg,["SETQ",max,["DIFFERENCE",max,k]]],
+ phrase2:= [["%igt",sharpArg,["SETQ",max,["DIFFERENCE",max,k]]],
["ELT",stateVar,["QSADD1",["QSDIFFERENCE",k,["DIFFERENCE",sharpArg,max]]]]]
- phrase3:= [["%gt",sharpArg,n],[auxfn,:argl,["LIST",n,:initCode]]]
- phrase4:= [["%gt",sharpArg,n-k],
+ phrase3:= [["%igt",sharpArg,n],[auxfn,:argl,["LIST",n,:initCode]]]
+ phrase4:= [["%igt",sharpArg,n-k],
["ELT",["LIST",:initCode],["QSDIFFERENCE",n,sharpArg]]]
phrase5:= ['(QUOTE T),['recurrenceError,MKQ op,sharpArg]]
['PROGN,:preset,['COND,phrase1,phrase2,phrase3,phrase4,phrase5]]