diff --git a/src/buildvalue.c b/src/buildvalue.c index dff09b7..6df12d4 100644 --- a/src/buildvalue.c +++ b/src/buildvalue.c @@ -171,10 +171,6 @@ static Object *walkListValue(const char *fmt, int *i, va_list va, Heap *heap, Er static Object *walkValue(const char *fmt, int *i, va_list va, Heap *heap, Error *error) { - int i_; - if(i == NULL) - i = &i_; - while(isspace(fmt[*i])) *i += 1; @@ -222,16 +218,21 @@ static Object *walkValue(const char *fmt, int *i, va_list va, Heap *heap, Error if(fmt[*i] == '\0') { // ERROR: Format ended inside of ${..}. + Error_Report(error, 0, "Format ended inside ${..}"); return NULL; } - int end = fmt[*i]; + assert(fmt[*i] == '}'); + + int end = *i; // NOTE: The last '}' is skipped after the switch. const char *src = fmt + start; int len = end - start; - + + printf("src: [%.*s]\n", len, src); + o = eval(src, len, NULL, heap, error); if(o == NULL) @@ -281,7 +282,8 @@ static Object *walkValue(const char *fmt, int *i, va_list va, Heap *heap, Error Object *buildValue2(Heap *heap, Error *error, const char *fmt, va_list va) { - return walkValue(fmt, NULL, va, heap, error); + int i = 0; + return walkValue(fmt, &i, va, heap, error); } Object *buildValue(Heap *heap, Error *error, const char *fmt, ...) diff --git a/src/eval.c b/src/eval.c index 213c11c..d83d2d5 100644 --- a/src/eval.c +++ b/src/eval.c @@ -1,3 +1,4 @@ +#include #include "compiler/parse.h" #include "compiler/compile.h" #include "runtime/runtime.h" @@ -6,6 +7,9 @@ Object *eval(const char *str, int len, Object *closure, Heap *heap, Error *error) { + if(len < 0) + len = strlen(str); + Source *s = Source_FromString(NULL, str, len, error); if(s == NULL) diff --git a/src/main.c b/src/main.c index 5179436..fa17a04 100644 --- a/src/main.c +++ b/src/main.c @@ -103,11 +103,35 @@ static int parse_args(Options *opts, int argc, char **argv, Error *error) return i; } +#include "buildvalue.h" + int main(int argc, char **argv) { Error error; Error_Init(&error); + { + Heap *heap = Heap_New(-1); + + if(heap == NULL) + { + fprintf(stderr, "ERROR: Failed to create heap.\n"); + return -1; + } + + Object *o = buildValue(heap, &error, "${ return 3+1; }"); + + if(o == NULL) + { + fprintf(stderr, "ERROR: %s.\n", error.message); + return -1; + } + + Object_Print(o, stdout); + + Heap_Free(heap); + } + // Parse command line options.