1
0
forked from Mirror/wren

Remove Linux-specific libc stuff.

This commit is contained in:
Bob Nystrom
2015-01-16 23:32:20 -08:00
parent f79f1d2b63
commit ae97e9c3a4
2 changed files with 12 additions and 26 deletions

View File

@ -1,5 +1,3 @@
#define _GNU_SOURCE // Makes getline() available in GCC.
#include <stdarg.h> #include <stdarg.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@ -8,6 +6,8 @@
#include "wren.h" #include "wren.h"
#define MAX_LINE_LENGTH 1024 // TODO: Something less arbitrary.
// This is the source file for the standalone command line interpreter. It is // This is the source file for the standalone command line interpreter. It is
// not needed if you are embedding Wren in an application. // not needed if you are embedding Wren in an application.
@ -75,38 +75,24 @@ static int runRepl(WrenVM* vm)
printf("\\\\/\"-\n"); printf("\\\\/\"-\n");
printf(" \\_/ wren v0.0.0\n"); printf(" \\_/ wren v0.0.0\n");
char line[MAX_LINE_LENGTH];
for (;;) for (;;)
{ {
printf("> "); printf("> ");
char* line = NULL; if (fgets(line, MAX_LINE_LENGTH, stdin))
size_t size = 0; {
ssize_t numRead = getline(&line, &size, stdin); // TODO: Handle failure.
wrenInterpret(vm, "Prompt", line);
// If stdin was closed (usually meaning the user entered Ctrl-D), exit. // TODO: Automatically print the result of expressions.
if (numRead == -1 || feof(stdin)) }
else
{ {
printf("\n"); printf("\n");
return 0; return 0;
} }
// TODO: Handle failure.
wrenInterpret(vm, "Prompt", line);
free(line);
// TODO: Figure out how this should work with wren API.
/*
ObjFn* fn = compile(vm, line);
if (fn != NULL)
{
Value result = interpret(vm, fn);
printf("= ");
printValue(result);
printf("\n");
}
*/
} }
wrenFreeVM(vm); wrenFreeVM(vm);

View File

@ -1007,7 +1007,7 @@ static bool runInterpreter(WrenVM* vm)
if (superclass->numFields + numFields > MAX_FIELDS) if (superclass->numFields + numFields > MAX_FIELDS)
{ {
char message[70 + MAX_VARIABLE_NAME]; char message[70 + MAX_VARIABLE_NAME];
snprintf(message, 70 + MAX_VARIABLE_NAME, sprintf(message,
"Class '%s' may not have more than %d fields, including inherited " "Class '%s' may not have more than %d fields, including inherited "
"ones.", name->value, MAX_FIELDS); "ones.", name->value, MAX_FIELDS);