From 7958bfe952186caa08f46c1ec99cc1ea40a8edb2 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Tue, 18 Oct 2016 23:40:21 +0200 Subject: Cleanup --- ExtraString.dcl | 1 - ExtraString.icl | 1 - README.md | 20 ++++++----- compile.c | 110 ++++++++++++++++++++++++++++---------------------------- iclean.icl | 42 +++++++++++----------- 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/ExtraString.dcl b/ExtraString.dcl index 568bdb7..d3ccb28 100644 --- a/ExtraString.dcl +++ b/ExtraString.dcl @@ -8,4 +8,3 @@ matches :: !String !String -> Bool // b starts with a skip :: !Int !String -> String // drop join :: !String ![a] -> String | toString a // join with delimiter color :: TextColor !String -> String // bash color - diff --git a/ExtraString.icl b/ExtraString.icl index 740e8d2..d128326 100644 --- a/ExtraString.icl +++ b/ExtraString.icl @@ -18,4 +18,3 @@ color :: TextColor !String -> String color Red s = "\x1B[31m" +++ s +++ "\x1B[0m" color Green s = "\x1B[32m" +++ s +++ "\x1B[0m" color None s = "\x1B[0m" +++ s +++ "\x1B[0m" - diff --git a/README.md b/README.md index 9fcde4c..3654c21 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,15 @@ license. For more details, see the LICENSE file. ## Example session - $ ./iclean - λ. [1,2,3,4] - [1,2,3,4] - λ. map toString [1..10] - ["1","2","3","4","5","6","7","8","9","10"] - λ. [Ctrl-D] - $ +``` +$ ./iclean +λ. [1,2,3,4] +[1,2,3,4] +λ. map toString [1..10] +["1","2","3","4","5","6","7","8","9","10"] +λ. [Ctrl-D] +$ +``` ## Usage Use `docker pull camilstaps/iclean` to pull the latest iClean version. @@ -37,7 +39,7 @@ Use either `./iclean` or `make run`. You can of course add the executable ## Todo - * Implement memory (e.g. to first declare a function / constant and then use it) - * Allow extra imports +* Implement memory (e.g. to first declare a function / constant and then use it) +* Allow extra imports [Clean]:http://clean.cs.ru.nl/Clean diff --git a/compile.c b/compile.c index 03fe833..6366a3d 100644 --- a/compile.c +++ b/compile.c @@ -32,16 +32,16 @@ SOFTWARE. #include "Clean.h" char* cleanstoc(CleanString s) { - char* cs = calloc(sizeof(char), CleanStringLength(s) + 1); - if (cs == NULL) - return NULL; - - int i; - for (i = 0; i < CleanStringLength(s); i++) - cs[i] = CleanStringCharacters(s)[i]; - cs[i] = '\0'; - - return cs; + char* cs = calloc(sizeof(char), CleanStringLength(s) + 1); + if (cs == NULL) + return NULL; + + int i; + for (i = 0; i < CleanStringLength(s); i++) + cs[i] = CleanStringCharacters(s)[i]; + cs[i] = '\0'; + + return cs; } /** @@ -56,29 +56,29 @@ char* cleanstoc(CleanString s) { * @return int the result of clm */ int64_t compile(CleanString path, CleanString module) { - char* pathchars, * modulechars; - - pathchars = cleanstoc(path); - modulechars = cleanstoc(module); - - if (modulechars == NULL || pathchars == NULL) { - printf("Couldn't allocate memory\n"); - exit(-1); - } - - // Build command: - // cd "" && clm -ms -nw -b -nt -o - 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", - pathchars, modulechars, modulechars); - - free(pathchars); - free(modulechars); - - // Call clm - return system(cmd); + char* pathchars, * modulechars; + + pathchars = cleanstoc(path); + modulechars = cleanstoc(module); + + if (modulechars == NULL || pathchars == NULL) { + printf("Couldn't allocate memory\n"); + exit(-1); + } + + // Build command: + // cd "" && clm -ms -nw -b -nt -o + 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", + pathchars, modulechars, modulechars); + + free(pathchars); + free(modulechars); + + // Call clm + return system(cmd); } /** @@ -92,26 +92,26 @@ int64_t compile(CleanString path, CleanString module) { * @return void */ int64_t run(CleanString executable) { - char* execchars; - int execlength; - - // Copy CleanString to char[] - execlength = CleanStringLength(executable); - - execchars = calloc(1, execlength + 1); - if (execchars == NULL) { - printf("Couldn't allocate memory\n"); - exit(-1); - } - - int i; - for (i=0;i *World - loop mem success w - # prompt = color (if success None Red) "λ. " - # (s,w) = readLine prompt False w - | isNothing s = print "\n" w - # s = fromJust s - | s == "" = loop mem False (print "Use Ctrl-D to exit\n" w) - # w = addHistory s w - | s == ":quit" || s == ":q" = w - | s == ":mem" = loop mem True (print (join "\n" mem) w) - | matches ":import " s = loop (mem ++ [skip 1 s]) True w - | matches ":def " s = loop (mem ++ [skip 5 s]) True w + loop :: ![String] Bool !*World -> *World + loop mem success w + # prompt = color (if success None Red) "λ. " + # (s,w) = readLine prompt False w + | isNothing s = print "\n" w + # s = fromJust s + | s == "" = loop mem False (print "Use Ctrl-D to exit\n" w) + # w = addHistory s w + | s == ":quit" || s == ":q" = w + | s == ":mem" = loop mem True (print (join "\n" mem) w) + | matches ":import " s = loop (mem ++ [skip 1 s]) True w + | matches ":def " s = loop (mem ++ [skip 5 s]) True w | matches ":undef " s = loop (filter (undef (skip 7 s)) mem) True w | s == ":help" = loop mem True (print help w) - | matches ":" s = loop mem False (print ("Unknown command\n") w) - # w = writemodule mem s w - # (r,w) = compile temp_path temp_module w - | r <> 0 = loop mem False w - # (r,w) = run (temp_path +++ temp_module) w - | r <> 0 = loop mem False w - = loop mem True w + | matches ":" s = loop mem False (print ("Unknown command\n") w) + # w = writemodule mem s w + # (r,w) = compile temp_path temp_module w + | r <> 0 = loop mem False w + # (r,w) = run (temp_path +++ temp_module) w + | r <> 0 = loop mem False w + = loop mem True w undef :: !String !String -> Bool undef n h = not (matches (n +++ " ") h) @@ -115,10 +115,10 @@ writemodule mem s w // C functions compile :: !String !String !*World -> *(!Int,!*World) compile _ _ _ = code { - ccall compile "SS:p:A" + ccall compile "SS:p:A" } run :: !String !*World -> (!Int, !*World) run _ _ = code { - ccall run "S:I:A" + ccall run "S:I:A" } -- cgit v1.2.3