)savesystem is fixed in Axiom and ported to FriCAS

36 views
Skip to first unread message

Zhaocong Jia

unread,
Jan 6, 2015, 3:07:47 AM1/6/15
to fricas-devel
)savesystem is fixed in Axiom by this commit
Now )savesystem can preserve variables and functions,
I think it's useful and should be added to FriCAS.
I ported this change to FriCAS as following patch:


diff --git a/src/interp/i-syscmd.boot b/src/interp/i-syscmd.boot
index d3d4fe3..32c7343 100644
--- a/src/interp/i-syscmd.boot
+++ b/src/interp/i-syscmd.boot
@@ -2138,6 +2138,12 @@ read_or_compile(quiet, lib) ==
     type = '"input" => ncINTERPFILE(input_file, not(quiet))
     spadCompile(input_file)
 
+--% )savesystem
+savesystem l ==
+  #l ~= 1 or not(SYMBOLP first l) => helpSpad2Cmd '(savesystem)
+  $ThisIsARunningSystem := true
+  SPAD_-SAVE (SYMBOL_-NAME first l, true)
+
 --% )show
 
 show l ==
diff --git a/src/interp/i-toplev.boot b/src/interp/i-toplev.boot
index 18f79ca..e7d1b7a 100644
--- a/src/interp/i-toplev.boot
+++ b/src/interp/i-toplev.boot
@@ -87,11 +87,13 @@ interpsysInitialization() ==
 
 interpsys_restart() ==
   $IOindex := 1
-  $InteractiveFrame := makeInitialModemapFrame()
   loadExposureGroupData()
   statisticsInitialization()
-  initHist()
-  initializeInterpreterFrameRing()
+  if not $ThisIsARunningSystem then
+    $InteractiveFrame := makeInitialModemapFrame()
+    initHist()
+    initializeInterpreterFrameRing()
+  $ThisIsARunningSystem := true
 
   if $displayStartMsgs then spadStartUpMsgs()
   $currentLine := nil
diff --git a/src/interp/setq.lisp b/src/interp/setq.lisp
index ec75759..b9b2426 100644
--- a/src/interp/setq.lisp
+++ b/src/interp/setq.lisp
@@ -165,6 +165,7 @@
    (|pquit|                          . |interpreter|)
    (|quit|                           . |interpreter|)
    (|read|                           . |interpreter|)
+   (|savesystem|                     . |interpreter|)
    (|set|                            . |interpreter|)
    (|show|                           . |interpreter|)
    (|spool|                          . |interpreter|)
@@ -209,6 +210,7 @@
     |ltrace|
     |nopiles|
     |read|
+    |savesystem|
     |set|
     |spool|
     |undo|
@@ -462,6 +464,7 @@
   '(|$EmptyMode| |$NoValueMode|))
 
 (SETQ |$InitialModemapFrame| '((NIL)))
+(defvar |$ThisIsARunningSystem| nil "Are we restarting a running system?")
 
 (SETQ |$NRTaddForm| NIL)
 (SETQ |$NRTdeltaList| NIL)

Waldek Hebisch

unread,
Jan 6, 2015, 10:03:31 PM1/6/15
to fricas...@googlegroups.com
>
> )savesystem is fixed in Axiom by this commit
> https://github.com/daly/axiom/commit/abbb38c1a4395448f8d769dff02a4e17c4308bf8
>
> Now )savesystem can preserve variables and functions,
> I think it's useful and should be added to FriCAS.
> I ported this change to FriCAS as following patch:
>

Thank for the patch. ATM I see two problems:

- saving images is not supported by ECL, so we need to
disable this for ECL,
- the code from the patch will skip part of initialization
if initialization is re-run. This looks wrong: one
may explicitely call initialization function to restart
the system and also during build we dump running system
and expect it to come in "fresh" state.

The second problem looks easy to fix:

> show l ==
> diff --git a/src/interp/i-toplev.boot b/src/interp/i-toplev.boot
> index 18f79ca..e7d1b7a 100644
> --- a/src/interp/i-toplev.boot
> +++ b/src/interp/i-toplev.boot
> @@ -87,11 +87,13 @@ interpsysInitialization() ==
>
> interpsys_restart() ==
> $IOindex := 1
> - $InteractiveFrame := makeInitialModemapFrame()
> loadExposureGroupData()
> statisticsInitialization()
> - initHist()
> - initializeInterpreterFrameRing()
> + if not $ThisIsARunningSystem then
> + $InteractiveFrame := makeInitialModemapFrame()
> + initHist()
> + initializeInterpreterFrameRing()
> + $ThisIsARunningSystem := true
^^^^

I think this should be 'false' so that initialization is redone
when needed. Of course, given that we should have better
name for the variable...

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Zhaocong Jia

unread,
Jan 6, 2015, 11:00:55 PM1/6/15
to fricas-devel
> I think this should be 'false' so that initialization is redone
> when needed. Of course, given that we should have better
> name for the variable...

Yes, that should be 'false'. How about name the variable ''SaveSystemFlag"?

Waldek Hebisch

unread,
Jan 10, 2015, 9:45:49 PM1/10/15
to fricas...@googlegroups.com
That is OK. Now we need to disable ')savesystem' for ecl. AFAICS
changing line is 'setq.lisp' to

#-:ecl(|savesystem| . |interpreter|)

should do.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Waldek Hebisch

unread,
Jan 28, 2015, 2:09:48 AM1/28/15
to fricas...@googlegroups.com
I tested the patch with indicated changes and there still is
problem. Namely, interpreter has concept of frames. During
early startup FriCAS is in 'initial' frame. But normal use
is via 'sman', and in such case different frame is in use.
Variables in different frames are considered different.
The problem is that patch keeps existing frames (and variables),
but user ends up in a new frame, so variables from old
session are not visible. There is possibility to change
frame, but the user must know that this is possible
and how to do this. ATM I do not see how to cleanly
restore active frame (there are hacky ways, but they
still may lead to confusion under some circumstances).
I admit that I have reservation commiting code that from
point of view of naive user is not working.

--
Waldek Hebisch
heb...@math.uni.wroc.pl

Ralf Hemmecke

unread,
Jan 28, 2015, 2:16:47 AM1/28/15
to fricas...@googlegroups.com
Is )savesystem really important?

Another way of keeping a session is to start FriCAS inside a virtual
machine and don't log out of that VM, but rather put it into sleep.

If we now promote )savesystem as a feature in FriCAS, we later might
have problems keeping that feature when the underlying Lisp is replaced
by LLVM or whatever. (OK, still a long way to go, but something to
consider.)

Ralf
Reply all
Reply to author
Forward
0 new messages