bug fix
This commit is contained in:
+9
-7
@@ -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, ...)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <string.h>
|
||||
#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)
|
||||
|
||||
+24
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user