Even more fixes

This commit is contained in:
Erik Svedäng 2019-03-05 16:37:27 +01:00
parent 6a685f4bf4
commit 87de6fbb76
5 changed files with 67 additions and 11 deletions

View File

@ -5,6 +5,7 @@ import qualified System.Environment as SystemEnvironment
import System.IO (stdout)
import System.Console.Haskeline (runInputT)
import System.Directory (doesPathExist, getHomeDirectory)
import GHC.IO.Encoding
import ColorText
import Obj
@ -49,7 +50,8 @@ defaultProject =
-- | Starting point of the application.
main :: IO ()
main = do args <- SystemEnvironment.getArgs
main = do setLocaleEncoding utf8
args <- SystemEnvironment.getArgs
sysEnv <- SystemEnvironment.getEnvironment
let (argFilesToLoad, execMode, otherOptions) = parseArgs args
logMemory = LogMemory `elem` otherOptions

View File

@ -11,14 +11,64 @@ void IO_error(String *s) { fprintf(stderr, "%s", *s); }
char IO_EOF = (char) EOF;
#ifndef _WIN32
#ifdef _WIN32
// getline isn't a C standard library function so it's missing on windows
// This implementation is stolen from StackOverflow, not sure if it's optimal...
size_t getline(char **lineptr, size_t *n, FILE *stream) {
size_t pos;
int c;
if (lineptr == NULL || stream == NULL || n == NULL) {
errno = EINVAL;
return -1;
}
c = fgetc(stream);
if (c == EOF) {
return -1;
}
if (*lineptr == NULL) {
*lineptr = malloc(128);
if (*lineptr == NULL) {
return -1;
}
*n = 128;
}
pos = 0;
while(c != EOF) {
if (pos + 1 >= *n) {
size_t new_size = *n + (*n >> 2);
if (new_size < 128) {
new_size = 128;
}
char *new_ptr = realloc(*lineptr, new_size);
if (new_ptr == NULL) {
return -1;
}
*n = new_size;
*lineptr = new_ptr;
}
((unsigned char *)(*lineptr))[pos ++] = c;
if (c == '\n') {
break;
}
c = fgetc(stream);
}
(*lineptr)[pos] = '\0';
return pos;
}
#endif
String IO_get_MINUS_line() {
size_t size = 1024;
String buffer = CARP_MALLOC(size);
getline(&buffer, &size, stdin);
return buffer;
}
#endif
String IO_read_MINUS_file(String *filename) {
String buffer = 0;

View File

@ -1,10 +1,10 @@
# Installation
Carp is mainly developed on macOS, but it also works fine on Linux. Windows is currently not supported - but please get in touch in case you want to help out with that!
Carp is mainly developed on macOS, but it also works fine on Linux. There is ongoing work on Windows support but it's not completely done yet.
## Building the Carp executable from source
1. Make sure you have [Stack](https://docs.haskellstack.org/en/stable/README/) installed.
1. Make sure you have a recent version of [Stack](https://docs.haskellstack.org/en/stable/README/) installed.
2. Clone this repo to your machine.
3. Run ```stack build``` in the root of the project directory.
4. ```stack install``` will install the Carp command line tool for easy access on your system.
@ -12,7 +12,7 @@ Carp is mainly developed on macOS, but it also works fine on Linux. Windows is c
## Setting the CARP_DIR
The `carp` executable must know where to find its core libraries and other files.
To be able to run `carp` from anywhere on you system, the executable must know where to find its core libraries and other files.
Set the environment variable CARP_DIR so that it points to the root of the Carp repo.
For example, add this to your `.bashrc` or similar:
@ -30,9 +30,11 @@ $ carp
## C compiler
The `carp` executable will emit a single file with C code, `main.c` and try to compile it using an external C compiler.
On macOS and Linux it defaults to `clang`, on Windows it's `cl.exe`.
On macOS and Linux it defaults to `clang`, so make sure you have that installed (On macOS this is preferably done by installing XCode, including its developer tools).
You can configure the exact compiler command like so:
On Windows the default C compiler used by Carp is `clang-cl.exe` which compiles the code using Clang but links it with the Visual Studio linker. Tip: use the package manager [Scoop](https://scoop.sh/) to install LLVM for an easy way to set this up on Windows.
If you want to use another compiler, you can configure the exact build command like so:
```clojure
(Project.config "compiler" "gcc --important-flag")

View File

@ -12,7 +12,7 @@
(def stuff [(A.init 10) (A.init 20) (A.init 30)])
(defn main []
(Debug.assert-balanced
;;(Debug.assert-balanced
(do
;;(IO.println s)
(IO.println &(A.str &a))
@ -20,7 +20,9 @@
;;(IO.println &(A.str &a))
(IO.println &(str &q))
(IO.println &(str &stuff))
)))
)
;;)
)
;; (defn f [x]
;; (do

View File

@ -15,7 +15,7 @@
# resolver:
# name: custom-snapshot
# location: "./custom-snapshot.yaml"
resolver: lts-11.12
resolver: lts-11.19
# User packages to be built.
# Various formats can be used as shown in the example below.