summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglenda <glenda@cirno>2022-09-10 17:14:51 +0000
committerglenda <glenda@cirno>2022-09-10 17:14:51 +0000
commita1a9641baeab04b954420122b6fd1c9428a757b5 (patch)
tree1d41db19a169d3d6d130841750968ccb3e974a85
parente2ebfbb7d19ff3b990eb51dc9843200053cbbf98 (diff)
Try some more
-rw-r--r--apl9.h2
-rw-r--r--main.c4
-rw-r--r--quadnames.c15
-rw-r--r--runtime/start.apl22
4 files changed, 34 insertions, 9 deletions
diff --git a/apl9.h b/apl9.h
index 1f9c8a7..3349cb7 100644
--- a/apl9.h
+++ b/apl9.h
@@ -329,7 +329,7 @@ Array *runtrain(Function *, int, Array *, Array *, Array *);
/* quadnames.c */
void initquadnames(void);
Datum *quadnamedatum(QuadnameDef);
-void setquad(Datum *);
+void outputmain(Datum *);
Array *runfile(Array *);
/* error.c */
diff --git a/main.c b/main.c
index e1734f9..f74468c 100644
--- a/main.c
+++ b/main.c
@@ -51,11 +51,11 @@ restart:
checkmem("main loop");
Datum *result = evalline(nil, stdin, 1);
if(result && !result->shy)
- setquad(result);
+ outputmain(result);
else{
Datum *dummy = allocdatum(ArrayTag, 0);
dummy->array = mkrunearray(L"");
- setquad(dummy);
+ outputmain(dummy);
freedatum(dummy);
}
freedatum(result);
diff --git a/quadnames.c b/quadnames.c
index 7c915eb..f00de5e 100644
--- a/quadnames.c
+++ b/quadnames.c
@@ -8,7 +8,7 @@
Datum *getquotequad(void);
void setquotequad(Datum *);
Datum *getquad(void);
-/* void setquad(Datum *); in apl9.h */
+void setquad(Datum *);
Datum *getquadrawio(void);
void setquadrawio(Datum *);
Datum *getio(void);
@@ -164,6 +164,19 @@ setquad(Datum *d)
free(str);
}
+/* for output from main loop */
+void
+outputmain(Datum *d)
+{
+ Rune *str = ppdatum(d);
+ Array *strarray = mkrunearray(str);
+ if(session)
+ rundfn(L"0::⎕RAWIO←⍶ ⋄ ('→' ⍺) ⍈ ⍵", d, nil, strarray, session);
+ else
+ setquadrawio(d);
+ free(str);
+}
+
/* ⎕RAWIO */
Datum *
getquadrawio(void)
diff --git a/runtime/start.apl b/runtime/start.apl
index c98462e..70df0fb 100644
--- a/runtime/start.apl
+++ b/runtime/start.apl
@@ -1,8 +1,19 @@
⎕session←{
(indented main prompt)←⍵
+ ⎕rawio←'Welcome to APL9',(⎕ucs 10),prompt
+ indented←≢prompt
+
unindent←{
⎕rawio←⎕ucs ⍺⍴8
}
+ handleMain←{
+ 0::⍺
+ data←⍵
+ ⎕rawio←data
+ ⎕rawio←⎕ucs 10
+ ⎕rawio←prompt
+ ≢prompt
+ }
handleError←{
0::⍺
(task (error msg taskname))←⍵
@@ -31,11 +42,12 @@
(task (type data))←⍵
indented←⍺
_←indented∘unindent IF (indented>0)∧task≢main
- type≡'!': 0 handleError task data
- type≡'⎕': 0 handleQuad data
- type≡'⍞': 0 handleQuoteQuad data
+ indented←indented×task≡main
+ type≡'→': indented handleMain data
+ type≡'!': indented handleError task data
+ type≡'⎕': indented handleQuad data
+ type≡'⍞': indented handleQuoteQuad data
}
{∇ ⍵ handle {1 ⍵}⍇⍬} indented
-}&'session'⊢0 ⎕self (6⍴' ')
-⎕←'Welcome to APL9'
+}&'session'⊢0 ⎕self ('APL9> ')