Skip to content

Commit 23aeff8

Browse files
Fixed bugs in interpreter and validator. Made emit-ast now also emit ids of identifiers
1 parent f9df936 commit 23aeff8

9 files changed

Lines changed: 246 additions & 231 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# -----------------------------
44
CC := gcc
55
CFLAGS := -Wall -Wextra -Wno-unused-parameter -O2
6-
DBGFLAGS := -Wall -Wextra -g -O0
6+
DBGFLAGS := -Wall -Wextra -Wno-unused-parameter -g -O0
77
LDFLAGS :=
88

99
SRC_DIR := src

project/lib.galo

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,8 @@ fun increment(v int) int
66
return (v + 1)
77
end
88

9-
#int convert(string val) int
10-
#float convert(string val) float
11-
#bool convert(string val) bool
12-
#byte convert(string val) byte
13-
#
14-
#fun string length(self string) int
15-
#fun string index(self string, int index) byte
16-
#fun string contains(value string, sub string) bool
17-
#fun string starts_with(value string, check string) bool
18-
#fun string ends_with(value string, check string) bool
19-
#fun string replace(value string, bef string, aft string) string
20-
#fun string sub(value string, start int, end int) string
21-
#fun string concat(left string, right string) string
22-
#
23-
#struct list
24-
# type Type
25-
#end
26-
#
27-
#fun init(type Type) list
28-
#fun add(self list, value list type) void
29-
#fun get(self list, index int) list type
30-
#fun length(self list) int
31-
#fun remove(self list, index int) void
32-
#fun clear(self list) void
33-
#fun contains(self list, value list type) bool
34-
#fun set(self list, index int, value list type) void
35-
369
# for build.galo
37-
#struct __BuildArguments
10+
#struct BuildArguments
3811
# input_file string
3912
# output_file string
4013
# input_files list
@@ -60,7 +33,7 @@ end
6033
# interpret_debug bool
6134
#end
6235
#
63-
#fun compile(args __BuildArguments)
64-
#fun transpile(args __BuildArguments)
65-
#fun interpret(args __BuildArguments)
36+
#fun compile(args BuildArguments)
37+
#fun transpile(args BuildArguments)
38+
#fun interpret(args BuildArguments)
6639
#fun run(program string, args list)

project/main.galo

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,17 @@
1-
let l1 list = list init(int, 10)
2-
println(l1)
3-
l1 = list append(l1, 99)
4-
println(l1)
5-
l1 = list append(l1, 98)
6-
println(l1)
7-
l1 = list append(l1, 97)
8-
println(l1)
9-
l1 = list remove(l1, 1)
10-
println(l1)
11-
l1 = list set(l1, 0, 55)
12-
println(l1)
13-
l1 = list insert(l1, 1, 125)
14-
println(l1)
15-
l1 = list clear(l1)
16-
println(l1)
17-
l1 = list(10, "abc", 789.0, true)
18-
println(l1)
1+
#!galo interpret project/main.galo --emit-validator --emit-ast -- 1 5 9 3 -5 4 -99 123
2+
#!include project/lib.galo
193

20-
##!galo interpret project/main.galo -- 1 5 9 3 -5 4 -99 123
21-
##!include project/lib.galo
22-
#
23-
#fun main(args list) int
24-
# let x int = 0
25-
# let i int = 0
26-
# while (list length(args) > i)
27-
# let arg string = list get(args, i)
28-
# let val int = cast(int, arg)
29-
# if (val == -6)
30-
# print("INVALID ARGUMENT:", arg, "\n")
31-
# return 1
32-
# end
33-
# x = add(x, val)
34-
# i = increment(i)
35-
# end
36-
# print("args total up to: ", x, "\n")
37-
#end
4+
fun main(args list) void
5+
let i int = 0
6+
let x int = 0
7+
while (list length(args) > i)
8+
let s string = list get(args, i)
9+
let v int = cast(int, s)
10+
x = add(x, v)
11+
i = increment(i)
12+
end
13+
println(x)
14+
end
3815

3916

4017
#TODO

src/galo_headers.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -343,18 +343,12 @@ typedef struct GaloObject_t {
343343
void* data;
344344
} GaloObject;
345345

346-
typedef struct {
346+
typedef struct ScopeFrame_t {
347347
int* variable_ids;
348348
int count;
349349
int capacity;
350350
} ScopeFrame;
351351

352-
typedef struct CallFrame_t {
353-
int function_id;
354-
Node* return_node;
355-
int scope_depth_at_entry;
356-
} CallFrame;
357-
358352
typedef struct Interpreter_Object_t {
359353
// Program data
360354
Validator_Object* validator_object;
@@ -374,11 +368,6 @@ typedef struct Interpreter_Object_t {
374368
int scope_depth;
375369
int scope_capacity;
376370

377-
// Call stack
378-
CallFrame* call_stack;
379-
int call_depth;
380-
int call_capacity;
381-
382371
// Execution state
383372
Node* current_node;
384373
GaloObject return_value;
@@ -404,6 +393,8 @@ GaloObject list_object_value(ObjectList* list);
404393
GaloObject void_object_value();
405394
void print_out_variable_values(Interpreter_Object* interp);
406395
void print_galo_object(Interpreter_Object* interp, GaloObject* object);
396+
GaloObject function_call(Interpreter_Object* interp, FunctionDeclaration* function, int argument_count, GaloObject* arguments);
397+
GaloObject predefined_function_call(Interpreter_Object* interp, PredefinedFunction* predefined_function, int argument_count, GaloObject* arguments);
407398

408399
/////////////////////////////////////////////////////////////////////
409400
// FUNCTIONS AND THEIR DEBUGGER FUNCTIONS
@@ -434,7 +425,7 @@ void build_option_new(char* project_name);
434425
void build_option_version();
435426
void build_option_help();
436427

437-
void interpret(Interpreter_Object* interpreter_object, int input_argc, char** input_argv);
428+
int interpret(Interpreter_Object* interpreter_object, int input_argc, char** input_argv);
438429
GaloObject interpret_node(Interpreter_Object* interpreter_object, Node* node);
439430

440431
void transpile();

0 commit comments

Comments
 (0)