Fixed repl bug

This commit is contained in:
2023-02-06 04:47:30 +00:00
parent d5c833b344
commit 0d7e4db661
5 changed files with 14 additions and 11 deletions

View File

@@ -152,6 +152,9 @@ int main(int argc, const char* argv[]) {
if (Toy_commandLine.compilefile && Toy_commandLine.outfile) { if (Toy_commandLine.compilefile && Toy_commandLine.outfile) {
size_t size = 0; size_t size = 0;
char* source = Toy_readFile(Toy_commandLine.compilefile, &size); char* source = Toy_readFile(Toy_commandLine.compilefile, &size);
if (!source) {
return 1;
}
unsigned char* tb = Toy_compileString(source, &size); unsigned char* tb = Toy_compileString(source, &size);
if (!tb) { if (!tb) {
return 1; return 1;

View File

@@ -145,6 +145,9 @@ void Toy_runSource(char* source) {
void Toy_runSourceFile(char* fname) { void Toy_runSourceFile(char* fname) {
size_t size = 0; //not used size_t size = 0; //not used
char* source = Toy_readFile(fname, &size); char* source = Toy_readFile(fname, &size);
if (!source) {
return;
}
Toy_runSource(source); Toy_runSource(source);
free((void*)source); free((void*)source);
} }

View File

@@ -2,9 +2,9 @@
var memo: [int : int] = [:]; var memo: [int : int] = [:];
fn fib(n : int) { fn fib(n : int) {
if (n < 2) { if (n < 2) {
return n; return n;
} }
var result = memo[n]; var result = memo[n];
if (result == null) { if (result == null) {
@@ -12,7 +12,7 @@ fn fib(n : int) {
memo[n] = result; memo[n] = result;
} }
return result; return result;
} }
for (var i = 0; i < 40; i++) { for (var i = 0; i < 40; i++) {

View File

@@ -1,9 +1,6 @@
fn fib(n : int) { fn fib(n : int) {
if (n < 2) { if (n < 2) return n;
return n; return fib(n-1) + fib(n-2);
}
return fib(n-1) + fib(n-2);
} }
for (var i = 0; i < 20; i++) { for (var i = 0; i < 20; i++) {

View File

@@ -1,5 +1,5 @@
//number of iterations //number of iterations
var SIZE: int const = 100; var SIZE: int const = 260;
//lookup table //lookup table
var lookup = [ var lookup = [
@@ -32,7 +32,7 @@ prev += "*"; //initial
print prev; print prev;
//run //run
for (var iteration = 0; iteration < 100; iteration++) { for (var iteration = 0; iteration < SIZE -1; iteration++) {
//left //left
var output = (lookup[" "][prev[0]][prev[1]]); var output = (lookup[" "][prev[0]][prev[1]]);