aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCamil Staps2016-10-18 23:52:49 +0200
committerCamil Staps2016-10-18 23:53:46 +0200
commitca6d92ece51042024ae99e3e52cfb89801db97b0 (patch)
treee20f3ccfebf068e19962122f545169297334d353
parentCleanup (diff)
Template file
-rw-r--r--README.md18
-rw-r--r--compile.c19
-rw-r--r--iclean.icl20
3 files changed, 45 insertions, 12 deletions
diff --git a/README.md b/README.md
index 3654c21..ca99089 100644
--- a/README.md
+++ b/README.md
@@ -13,9 +13,9 @@ license. For more details, see the LICENSE file.
```
$ ./iclean
λ. [1,2,3,4]
-[1,2,3,4]
+[Int] :: [1,2,3,4]
λ. map toString [1..10]
-["1","2","3","4","5","6","7","8","9","10"]
+[{#Char}] :: ["1","2","3","4","5","6","7","8","9","10"]
λ. [Ctrl-D]
$
```
@@ -23,12 +23,18 @@ $
## Usage
Use `docker pull camilstaps/iclean` to pull the latest iClean version.
-Run iClean with `docker run --rm -it camilstaps/iclean`. If you want history,
-add `-v ~/.iclean_history:/home/.iclean_history` and `touch ~/.iclean_history`
-on the host. Make it an alias:
+Run iClean with `docker run --rm -it camilstaps/iclean`.
+
+If you want history, add `-v ~/.iclean_history:/home/.iclean_history` and
+`touch ~/.iclean_history` on the host.
+
+You can add imports by creating a template in `~/.iclean_template`, then adding
+it to the container with `-v ~/.iclean_template:/home/.iclean_template`.
+
+Make all this an alias:
```
-alias iclean="docker run --rm -it -v ~/.iclean_history:/home/.iclean_history camilstaps/iclean"
+alias iclean="docker run --rm -it -v ~/.iclean_history:/home/.iclean_history -v ~/.iclean_template:/home/.iclean_template camilstaps/iclean"
```
## Without Docker
diff --git a/compile.c b/compile.c
index 6366a3d..d32c7ac 100644
--- a/compile.c
+++ b/compile.c
@@ -67,11 +67,20 @@ int64_t compile(CleanString path, CleanString module) {
}
// Build command:
- // cd "<path>" && clm -ms -nw -b -nt <module> -o <module>
- char cmd[182];
- snprintf(cmd, 181, "cd \"%s\" && clm -ms -nw -I $CLEAN_HOME/lib/StdLib -I "
- "$CLEAN_HOME/lib/Generics -I $CLEAN_HOME/lib/Dynamics -dynamics "
- "-I $CLEAN_HOME/lib/Gast -b -nt %s -o %s",
+ char cmd[512];
+ snprintf(cmd, 511, "cd \"%s\" && clm -ms -nw "
+ "-I $CLEAN_HOME/lib/Generics "
+ "-I $CLEAN_HOME/lib/Dynamics -dynamics "
+ "-I $CLEAN_HOME/lib/Gast "
+ "-I $CLEAN_HOME/lib/clean-platform/OS-Independent "
+ "-I $CLEAN_HOME/lib/clean-platform/OS-Independent/Deprecated/StdLib "
+ "-I $CLEAN_HOME/lib/clean-platform/OS-Posix "
+ "-I $CLEAN_HOME/lib/clean-platform/OS-Linux "
+ "-I $CLEAN_HOME/lib/clean-platform/OS-Linux-64 "
+ "-I $CLEAN_HOME/lib/ArgEnv "
+ "-I $CLEAN_HOME/lib/Directory "
+ "-I $CLEAN_HOME/lib/MersenneTwister "
+ "-b -nt %s -o %s",
pathchars, modulechars, modulechars);
free(pathchars);
diff --git a/iclean.icl b/iclean.icl
index 6b64d98..7683619 100644
--- a/iclean.icl
+++ b/iclean.icl
@@ -36,6 +36,7 @@ temp_path :== "/tmp/"
temp_module :== "iclean"
readline_history :== "/home/.iclean_history"
template :== map ((+++) "import ") ["StdEnv", "StdDynamic", "genLibTest"]
+template_file :== "/home/.iclean_template"
// END SETTINGS
temp_file :== temp_path +++ temp_module +++ ".icl"
@@ -54,7 +55,8 @@ Start w
# w = setReadLineName "iClean" w
# w = usingHistory w
# w = checkedWorldFunc readHistory "Couldn't read history" readline_history w
-# w = loop template True w
+# (more_template,w) = readTemplate template_file w
+# w = loop (template ++ more_template) True w
# w = checkedWorldFunc writeHistory "Couldn't write history" readline_history w
= w
where
@@ -83,6 +85,22 @@ where
undef :: !String !String -> Bool
undef n h = not (matches (n +++ " ") h)
+ readTemplate :: !String !*World -> *([String], *World)
+ readTemplate f w
+ # (ok,f,w) = fopen f FReadText w
+ | not ok = ([], w)
+ # (lines,f) = readLines f
+ # (ok,w) = fclose f w
+ = (lines, w)
+ where
+ readLines :: !*File -> *([String], *File)
+ readLines f
+ # (end,f) = fend f
+ | end = ([], f)
+ # (line,f) = freadline f
+ # (lines,f) = readLines f
+ = ([line % (0,size line - 2):lines], f)
+
// iClean functions
checkedWorldFunc :: (a *World -> (Bool, *World)) !String !a !*World -> *World
checkedWorldFunc f err s w