aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordos-reis <gdr@axiomatics.org>2010-05-26 18:40:13 +0000
committerdos-reis <gdr@axiomatics.org>2010-05-26 18:40:13 +0000
commita7e98a2ab2fcc87c3505ab11708d5bf24607ae85 (patch)
treea4bbe3b50760d18318402714211e02b545562f76 /src
parent8e0498b66e19be7e22039866d695c1cb81707bd6 (diff)
downloadopen-axiom-a7e98a2ab2fcc87c3505ab11708d5bf24607ae85.tar.gz
* interp/slam.boot (compileRecurrenceRelation): Generate code to
access and set the global value of the variable holding the cache state. * interp/g-util.boot: Add more middle end form expanders.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog7
-rw-r--r--src/interp/g-util.boot61
-rw-r--r--src/interp/slam.boot10
3 files changed, 58 insertions, 20 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 639cb4bd..c24c65b3 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,12 @@
2010-05-26 Gabriel Dos Reis <gdr@cs.tamu.edu>
+ * interp/slam.boot (compileRecurrenceRelation): Generate code to
+ access and set the global value of the variable holding the cache
+ state.
+ * interp/g-util.boot: Add more middle end form expanders.
+
+2010-05-26 Gabriel Dos Reis <gdr@cs.tamu.edu>
+
* boot/tokens.boot: Automatically translate alphabetic?, digit?,
lowerCase?, upperCase?, readByte, readInteger, readLine,
writeByte, writeLine.
diff --git a/src/interp/g-util.boot b/src/interp/g-util.boot
index e3c4ec2b..8815cf5b 100644
--- a/src/interp/g-util.boot
+++ b/src/interp/g-util.boot
@@ -191,34 +191,65 @@ expandAnd ["%and",:args] ==
expandOr ["%or",:args] ==
["OR",:expandToVMForm args]
+-- Arithmetic operations
+expandImul ["%imul",:args] ==
+ ["*",:expandToVMForm args]
+
+expandIadd ["%iadd",:args] ==
+ ["+",:expandToVMForm args]
+
+expandIsub ["%isub",:args] ==
+ ["-",:expandToVMForm args]
+
+expandIeq ["%ieq",:args] ==
+ ["EQL",:expandToVMForm args]
+
-- Local variable bindings
expandBind ["%bind",inits,body] ==
body := expandToVMForm body
inits := [[first x,expandToVMForm second x] for x in inits]
-- FIXME: we should consider turning LET* into LET or direct inlining.
["LET*",inits,body]
-
+
+-- Memory load/store
+
+expandDynval ["%dynval",:args] ==
+ ["SYMBOL-VALUE",:expandToVMForm args]
+
+expandStore ["%store",place,value] ==
+ place := expandToVMForm place
+ value := expandToVMForm value
+ cons? place => ["SETF",place,value]
+ ["SETQ",place,value]
+
++ Table of opcode-expander pairs.
-$OpcodeExpanders == [
- ["%not",:"expandNot"],
- ["%and",:"expandAnd"],
- ["%or",:"expandOr"],
+for x in [
+ ["%not",:function expandNot],
+ ["%and",:function expandAnd],
+ ["%or",:function expandOr],
- ["%collect",:"expandCollect"],
- ["%repeat",:"expandRepeat"],
+ ["%collect",:function expandCollect],
+ ["%repeat",:function expandRepeat],
- ["%le",:"expandLessEqual"],
- ["%lt",:"expandLess"],
- ["%ge",:"expandGreaterEqual"],
- ["%gt",:"expandGreater"],
+ ["%le",:function expandLessEqual],
+ ["%lt",:function expandLess],
+ ["%ge",:function expandGreaterEqual],
+ ["%gt",:function expandGreater],
- ["%bind",:"expandBind"]
- ]
+ ["%imul",:function expandImul],
+ ["%iadd",:function expandIadd],
+ ["%isub",:function expandIsub],
+
+ ["%ieq",:function expandIeq],
+
+ ["%bind",:function expandBind],
+ ["%store",:function expandStore],
+ ["%dynval",:function expandDynval]
+ ] repeat MAKEPROP(first x,"%Expander", rest x)
++ Return the expander of a middle-end opcode, or nil if there is none.
getOpcodeExpander op ==
- x := ASSOC(op,$OpcodeExpanders) => rest x
- nil
+ op has %Expander
++ Expand all opcodes contained in the form `x' into a form
++ suitable for evaluation by the VM.
diff --git a/src/interp/slam.boot b/src/interp/slam.boot
index 450e70a2..3da6c906 100644
--- a/src/interp/slam.boot
+++ b/src/interp/slam.boot
@@ -282,8 +282,8 @@ compileRecurrenceRelation(op,nam,argl,junk,[body,sharpArg,n,:initCode]) ==
newTripleCode := ["LIST",sharpArg,:gsList]
newStateCode :=
- null extraArguments => ["SETQ",stateNam,newTripleCode]
- ["HPUT",stateNam,extraArgumentCode,newTripleCode]
+ null extraArguments => ["%store",["%dynval", MKQ stateNam],newTripleCode]
+ ["HPUT",["%dynval", MKQ stateNam],extraArgumentCode,newTripleCode]
computeFunction:= [auxfn,["LAM",cargl,cbody]] where
cargl:= [:argl,lastArg]
@@ -312,11 +312,11 @@ compileRecurrenceRelation(op,nam,argl,junk,[body,sharpArg,n,:initCode]) ==
initialValueCode :=
extraArguments => ["hashTable",''EQUAL]
tripleCode
- cacheResetCode := ["SETQ",stateNam,initialValueCode]
+ cacheResetCode := ["%store",["%dynval", MKQ stateNam],initialValueCode]
["COND",[["%not",["%and",["BOUNDP",MKQ stateNam], _
- ["CONSP",stateNam]]], _
+ ["CONSP",["%dynval",MKQ stateNam]]]], _
["%LET",stateVar,cacheResetCode]], _
- [''T, ["%LET",stateVar,stateNam]]]
+ [''T, ["%LET",stateVar,["%dynval",MKQ stateNam]]]]
-- when there are extra arguments, initialResetCode resets "stateVar"
-- to the hashtable entry for the extra arguments