diff --git a/examples/list b/examples/list new file mode 100755 index 0000000..3de91ed Binary files /dev/null and b/examples/list differ diff --git a/examples/list.gom b/examples/list.gom new file mode 100644 index 0000000..56aac7d --- /dev/null +++ b/examples/list.gom @@ -0,0 +1,42 @@ +import io; + +type Numbers = [int]; +type Status = { + code: int, + success: bool, +}; +type StatusList = [Status]; +type Pairs = [{ int, int }]; + +fn main() { + let numbers = Numbers { 1, 2, 3, 4, 5 }; + + let i = 0; + for(i; i < numbers.size; i = i + 1) { + io.log("numbers[", i, "] = ", numbers.i); + } + + let statusList = StatusList { + Status { code: 200, success: true }, + Status { code: 404, success: false }, + Status { code: 500, success: false }, + }; + let j = 0; + for(j; j < statusList.size; j = j + 1) { + let status = statusList.j; + io.log("statusList[", j, "] = { code: ", status.code, ", success: ", status.success, " }"); + } + + let pairs = Pairs { + { 1, 2 }, + { 3, 4 }, + { 5, 6 }, + { 7, 8 }, + { 9, 10 }, + }; + let k = 0; + for(k; k < pairs.size; k = k + 1) { + let pair = pairs.k; + io.log("pairs[", k, "] = { ", pair.0, ", ", pair.1, " }"); + } +} \ No newline at end of file diff --git a/examples/list.ll b/examples/list.ll new file mode 100644 index 0000000..02cea52 --- /dev/null +++ b/examples/list.ll @@ -0,0 +1,251 @@ +; ModuleID = 'mod' +source_filename = "mod" + +%Numbers = type { i32*, i32, i32 } +%StatusList = type { %Status*, i32, i32 } +%Status = type { i32, i1 } +%Pairs = type { { i32, i32 }*, i32, i32 } + +@.strliteral = private unnamed_addr constant [9 x i8] c"numbers[\00", align 1 +@.strliteral.1 = private unnamed_addr constant [5 x i8] c"] = \00", align 1 +@fmt.int = private unnamed_addr constant [3 x i8] c"%d\00", align 1 +@newline = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@.strliteral.2 = private unnamed_addr constant [12 x i8] c"statusList[\00", align 1 +@.strliteral.3 = private unnamed_addr constant [13 x i8] c"] = { code: \00", align 1 +@.strliteral.4 = private unnamed_addr constant [12 x i8] c", success: \00", align 1 +@.strliteral.5 = private unnamed_addr constant [3 x i8] c" }\00", align 1 +@fmt.bool = private unnamed_addr constant [3 x i8] c"%d\00", align 1 +@.strliteral.6 = private unnamed_addr constant [7 x i8] c"pairs[\00", align 1 +@.strliteral.7 = private unnamed_addr constant [7 x i8] c"] = { \00", align 1 +@.strliteral.8 = private unnamed_addr constant [3 x i8] c", \00", align 1 +@.strliteral.9 = private unnamed_addr constant [3 x i8] c" }\00", align 1 + +declare i32 @printf(i8*, ...) + +declare i8* @malloc(i32) + +define void @main() { +entry: + %numbers = alloca %Numbers, align 8 + %data_ptr_ptr = getelementptr %Numbers, %Numbers* %numbers, i32 0, i32 0 + %size_ptr = getelementptr %Numbers, %Numbers* %numbers, i32 0, i32 1 + %capacity_ptr = getelementptr %Numbers, %Numbers* %numbers, i32 0, i32 2 + store i32 16, i32* %capacity_ptr, align 4 + store i32 5, i32* %size_ptr, align 4 + %malloc_call = call i8* @malloc(i32 64) + %data_alloca = bitcast i8* %malloc_call to i32* + store i32* %data_alloca, i32** %data_ptr_ptr, align 8 + %element_ptr = getelementptr inbounds i32, i32* %data_alloca, i32 0 + store i32 1, i32* %element_ptr, align 4 + %element_ptr1 = getelementptr inbounds i32, i32* %data_alloca, i32 1 + store i32 2, i32* %element_ptr1, align 4 + %element_ptr2 = getelementptr inbounds i32, i32* %data_alloca, i32 2 + store i32 3, i32* %element_ptr2, align 4 + %element_ptr3 = getelementptr inbounds i32, i32* %data_alloca, i32 3 + store i32 4, i32* %element_ptr3, align 4 + %element_ptr4 = getelementptr inbounds i32, i32* %data_alloca, i32 4 + store i32 5, i32* %element_ptr4, align 4 + %i = alloca i32, align 4 + store i32 0, i32* %i, align 4 + store i32 0, i32* %i, align 4 + %i.load = load i32, i32* %i, align 4 + br label %loop + +loop: ; preds = %loopupdate, %entry + %i.load5 = load i32, i32* %i, align 4 + %size_ptr6 = getelementptr %Numbers, %Numbers* %numbers, i32 0, i32 1 + %size_value = load i32, i32* %size_ptr6, align 4 + %lttmp = icmp slt i32 %i.load5, %size_value + br i1 %lttmp, label %loopbody, label %afterloop + +loopbody: ; preds = %loop + %i.load7 = load i32, i32* %i, align 4 + %i.load8 = load i32, i32* %i, align 4 + %data_ptr_ptr9 = getelementptr inbounds %Numbers, %Numbers* %numbers, i32 0, i32 0 + %data_ptr = load i32*, i32** %data_ptr_ptr9, align 8 + %element_ptr10 = getelementptr inbounds i32, i32* %data_ptr, i32 %i.load8 + %element_load = load i32, i32* %element_ptr10, align 4 + %calltmp0 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.strliteral, i32 0, i32 0)) + %calltmp1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %i.load7) + %calltmp2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.strliteral.1, i32 0, i32 0)) + %calltmp3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %element_load) + %newline = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @newline, i32 0, i32 0)) + br label %loopupdate + +loopupdate: ; preds = %loopbody + %i.load11 = load i32, i32* %i, align 4 + %addtmp = add i32 %i.load11, 1 + store i32 %addtmp, i32* %i, align 4 + br label %loop + +afterloop: ; preds = %loop + %statusList = alloca %StatusList, align 8 + %data_ptr_ptr12 = getelementptr %StatusList, %StatusList* %statusList, i32 0, i32 0 + %size_ptr13 = getelementptr %StatusList, %StatusList* %statusList, i32 0, i32 1 + %capacity_ptr14 = getelementptr %StatusList, %StatusList* %statusList, i32 0, i32 2 + store i32 16, i32* %capacity_ptr14, align 4 + store i32 3, i32* %size_ptr13, align 4 + %malloc_call15 = call i8* @malloc(i32 128) + %data_alloca16 = bitcast i8* %malloc_call15 to %Status* + store %Status* %data_alloca16, %Status** %data_ptr_ptr12, align 8 + %Status_instance = alloca %Status, align 8 + %fieldptr = getelementptr %Status, %Status* %Status_instance, i32 0, i32 0 + store i32 200, i32* %fieldptr, align 4 + %fieldptr17 = getelementptr %Status, %Status* %Status_instance, i32 0, i32 1 + store i1 true, i1* %fieldptr17, align 1 + %element_load18 = load %Status, %Status* %Status_instance, align 4 + %element_ptr19 = getelementptr inbounds %Status, %Status* %data_alloca16, i32 0 + store %Status %element_load18, %Status* %element_ptr19, align 4 + %Status_instance20 = alloca %Status, align 8 + %fieldptr21 = getelementptr %Status, %Status* %Status_instance20, i32 0, i32 0 + store i32 404, i32* %fieldptr21, align 4 + %fieldptr22 = getelementptr %Status, %Status* %Status_instance20, i32 0, i32 1 + store i1 false, i1* %fieldptr22, align 1 + %element_load23 = load %Status, %Status* %Status_instance20, align 4 + %element_ptr24 = getelementptr inbounds %Status, %Status* %data_alloca16, i32 1 + store %Status %element_load23, %Status* %element_ptr24, align 4 + %Status_instance25 = alloca %Status, align 8 + %fieldptr26 = getelementptr %Status, %Status* %Status_instance25, i32 0, i32 0 + store i32 500, i32* %fieldptr26, align 4 + %fieldptr27 = getelementptr %Status, %Status* %Status_instance25, i32 0, i32 1 + store i1 false, i1* %fieldptr27, align 1 + %element_load28 = load %Status, %Status* %Status_instance25, align 4 + %element_ptr29 = getelementptr inbounds %Status, %Status* %data_alloca16, i32 2 + store %Status %element_load28, %Status* %element_ptr29, align 4 + %j = alloca i32, align 4 + store i32 0, i32* %j, align 4 + store i32 0, i32* %j, align 4 + %j.load = load i32, i32* %j, align 4 + br label %loop30 + +loop30: ; preds = %loopupdate32, %afterloop + %j.load34 = load i32, i32* %j, align 4 + %size_ptr35 = getelementptr %StatusList, %StatusList* %statusList, i32 0, i32 1 + %size_value36 = load i32, i32* %size_ptr35, align 4 + %lttmp37 = icmp slt i32 %j.load34, %size_value36 + br i1 %lttmp37, label %loopbody31, label %afterloop33 + +loopbody31: ; preds = %loop30 + %status = alloca %Status, align 8 + %j.load38 = load i32, i32* %j, align 4 + %data_ptr_ptr39 = getelementptr inbounds %StatusList, %StatusList* %statusList, i32 0, i32 0 + %data_ptr40 = load %Status*, %Status** %data_ptr_ptr39, align 8 + %element_ptr41 = getelementptr inbounds %Status, %Status* %data_ptr40, i32 %j.load38 + %element_load42 = load %Status, %Status* %element_ptr41, align 4 + store %Status %element_load42, %Status* %status, align 4 + %j.load43 = load i32, i32* %j, align 4 + %fieldptr44 = getelementptr %Status, %Status* %status, i32 0, i32 0 + %fieldload = load i32, i32* %fieldptr44, align 4 + %fieldptr45 = getelementptr %Status, %Status* %status, i32 0, i32 1 + %fieldload46 = load i1, i1* %fieldptr45, align 1 + %calltmp047 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral.2, i32 0, i32 0)) + %calltmp148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %j.load43) + %calltmp249 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.strliteral.3, i32 0, i32 0)) + %calltmp350 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %fieldload) + %calltmp4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral.4, i32 0, i32 0)) + %calltmp5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i32 0, i32 0), i1 %fieldload46) + %calltmp6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.strliteral.5, i32 0, i32 0)) + %newline51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @newline, i32 0, i32 0)) + br label %loopupdate32 + +loopupdate32: ; preds = %loopbody31 + %j.load52 = load i32, i32* %j, align 4 + %addtmp53 = add i32 %j.load52, 1 + store i32 %addtmp53, i32* %j, align 4 + br label %loop30 + +afterloop33: ; preds = %loop30 + %pairs = alloca %Pairs, align 8 + %data_ptr_ptr54 = getelementptr %Pairs, %Pairs* %pairs, i32 0, i32 0 + %size_ptr55 = getelementptr %Pairs, %Pairs* %pairs, i32 0, i32 1 + %capacity_ptr56 = getelementptr %Pairs, %Pairs* %pairs, i32 0, i32 2 + store i32 16, i32* %capacity_ptr56, align 4 + store i32 5, i32* %size_ptr55, align 4 + %malloc_call57 = call i8* @malloc(i32 128) + %data_alloca58 = bitcast i8* %malloc_call57 to { i32, i32 }* + store { i32, i32 }* %data_alloca58, { i32, i32 }** %data_ptr_ptr54, align 8 + %tuple = alloca { i32, i32 }, align 8 + %fieldptr59 = getelementptr { i32, i32 }, { i32, i32 }* %tuple, i32 0, i32 0 + store i32 1, i32* %fieldptr59, align 4 + %fieldptr60 = getelementptr { i32, i32 }, { i32, i32 }* %tuple, i32 0, i32 1 + store i32 2, i32* %fieldptr60, align 4 + %element_load61 = load { i32, i32 }, { i32, i32 }* %tuple, align 4 + %element_ptr62 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %data_alloca58, i32 0 + store { i32, i32 } %element_load61, { i32, i32 }* %element_ptr62, align 4 + %tuple63 = alloca { i32, i32 }, align 8 + %fieldptr64 = getelementptr { i32, i32 }, { i32, i32 }* %tuple63, i32 0, i32 0 + store i32 3, i32* %fieldptr64, align 4 + %fieldptr65 = getelementptr { i32, i32 }, { i32, i32 }* %tuple63, i32 0, i32 1 + store i32 4, i32* %fieldptr65, align 4 + %element_load66 = load { i32, i32 }, { i32, i32 }* %tuple63, align 4 + %element_ptr67 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %data_alloca58, i32 1 + store { i32, i32 } %element_load66, { i32, i32 }* %element_ptr67, align 4 + %tuple68 = alloca { i32, i32 }, align 8 + %fieldptr69 = getelementptr { i32, i32 }, { i32, i32 }* %tuple68, i32 0, i32 0 + store i32 5, i32* %fieldptr69, align 4 + %fieldptr70 = getelementptr { i32, i32 }, { i32, i32 }* %tuple68, i32 0, i32 1 + store i32 6, i32* %fieldptr70, align 4 + %element_load71 = load { i32, i32 }, { i32, i32 }* %tuple68, align 4 + %element_ptr72 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %data_alloca58, i32 2 + store { i32, i32 } %element_load71, { i32, i32 }* %element_ptr72, align 4 + %tuple73 = alloca { i32, i32 }, align 8 + %fieldptr74 = getelementptr { i32, i32 }, { i32, i32 }* %tuple73, i32 0, i32 0 + store i32 7, i32* %fieldptr74, align 4 + %fieldptr75 = getelementptr { i32, i32 }, { i32, i32 }* %tuple73, i32 0, i32 1 + store i32 8, i32* %fieldptr75, align 4 + %element_load76 = load { i32, i32 }, { i32, i32 }* %tuple73, align 4 + %element_ptr77 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %data_alloca58, i32 3 + store { i32, i32 } %element_load76, { i32, i32 }* %element_ptr77, align 4 + %tuple78 = alloca { i32, i32 }, align 8 + %fieldptr79 = getelementptr { i32, i32 }, { i32, i32 }* %tuple78, i32 0, i32 0 + store i32 9, i32* %fieldptr79, align 4 + %fieldptr80 = getelementptr { i32, i32 }, { i32, i32 }* %tuple78, i32 0, i32 1 + store i32 10, i32* %fieldptr80, align 4 + %element_load81 = load { i32, i32 }, { i32, i32 }* %tuple78, align 4 + %element_ptr82 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %data_alloca58, i32 4 + store { i32, i32 } %element_load81, { i32, i32 }* %element_ptr82, align 4 + %k = alloca i32, align 4 + store i32 0, i32* %k, align 4 + store i32 0, i32* %k, align 4 + %k.load = load i32, i32* %k, align 4 + br label %loop83 + +loop83: ; preds = %loopupdate85, %afterloop33 + %k.load87 = load i32, i32* %k, align 4 + %size_ptr88 = getelementptr %Pairs, %Pairs* %pairs, i32 0, i32 1 + %size_value89 = load i32, i32* %size_ptr88, align 4 + %lttmp90 = icmp slt i32 %k.load87, %size_value89 + br i1 %lttmp90, label %loopbody84, label %afterloop86 + +loopbody84: ; preds = %loop83 + %pair = alloca { i32, i32 }, align 8 + %k.load91 = load i32, i32* %k, align 4 + %data_ptr_ptr92 = getelementptr inbounds %Pairs, %Pairs* %pairs, i32 0, i32 0 + %data_ptr93 = load { i32, i32 }*, { i32, i32 }** %data_ptr_ptr92, align 8 + %element_ptr94 = getelementptr inbounds { i32, i32 }, { i32, i32 }* %data_ptr93, i32 %k.load91 + %element_load95 = load { i32, i32 }, { i32, i32 }* %element_ptr94, align 4 + store { i32, i32 } %element_load95, { i32, i32 }* %pair, align 4 + %k.load96 = load i32, i32* %k, align 4 + %fieldptr97 = getelementptr { i32, i32 }, { i32, i32 }* %pair, i32 0, i32 0 + %fieldload98 = load i32, i32* %fieldptr97, align 4 + %fieldptr99 = getelementptr { i32, i32 }, { i32, i32 }* %pair, i32 0, i32 1 + %fieldload100 = load i32, i32* %fieldptr99, align 4 + %calltmp0101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.strliteral.6, i32 0, i32 0)) + %calltmp1102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %k.load96) + %calltmp2103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.strliteral.7, i32 0, i32 0)) + %calltmp3104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %fieldload98) + %calltmp4105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.strliteral.8, i32 0, i32 0)) + %calltmp5106 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.int, i32 0, i32 0), i32 %fieldload100) + %calltmp6107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.strliteral.9, i32 0, i32 0)) + %newline108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @newline, i32 0, i32 0)) + br label %loopupdate85 + +loopupdate85: ; preds = %loopbody84 + %k.load109 = load i32, i32* %k, align 4 + %addtmp110 = add i32 %k.load109, 1 + store i32 %addtmp110, i32* %k, align 4 + br label %loop83 + +afterloop86: ; preds = %loop83 + ret void +} diff --git a/examples/opt_list.ll b/examples/opt_list.ll new file mode 100644 index 0000000..97981d5 --- /dev/null +++ b/examples/opt_list.ll @@ -0,0 +1,46 @@ +; ModuleID = 'examples/list.ll' +source_filename = "mod" + +@.strliteral = private unnamed_addr constant [12 x i8] c"statusList[\00", align 1 +@.strliteral.1 = private unnamed_addr constant [13 x i8] c"] = { code: \00", align 1 +@.strliteral.2 = private unnamed_addr constant [12 x i8] c", success: \00", align 1 +@.strliteral.3 = private unnamed_addr constant [3 x i8] c" }\00", align 1 +@fmt.bool = private unnamed_addr constant [3 x i8] c"%d\00", align 1 + +; Function Attrs: nofree nounwind +declare noundef i32 @printf(i8* nocapture noundef readonly, ...) local_unnamed_addr #0 + +; Function Attrs: nofree nounwind +define void @main() local_unnamed_addr #0 { +entry: + %calltmp0 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral, i64 0, i64 0)) + %calltmp1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i32 0) + %calltmp2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.strliteral.1, i64 0, i64 0)) + %calltmp3 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i32 undef) + %calltmp4 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral.2, i64 0, i64 0)) + %calltmp5 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i1 undef) + %calltmp6 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.strliteral.3, i64 0, i64 0)) + %putchar = tail call i32 @putchar(i32 10) + %calltmp0.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral, i64 0, i64 0)) + %calltmp1.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i32 1) + %calltmp2.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.strliteral.1, i64 0, i64 0)) + %calltmp3.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i32 undef) + %calltmp4.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral.2, i64 0, i64 0)) + %calltmp5.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i1 undef) + %calltmp6.1 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.strliteral.3, i64 0, i64 0)) + %putchar.1 = tail call i32 @putchar(i32 10) + %calltmp0.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral, i64 0, i64 0)) + %calltmp1.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i32 2) + %calltmp2.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.strliteral.1, i64 0, i64 0)) + %calltmp3.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i32 undef) + %calltmp4.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.strliteral.2, i64 0, i64 0)) + %calltmp5.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @fmt.bool, i64 0, i64 0), i1 undef) + %calltmp6.2 = tail call i32 (i8*, ...) @printf(i8* nonnull dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.strliteral.3, i64 0, i64 0)) + %putchar.2 = tail call i32 @putchar(i32 10) + ret void +} + +; Function Attrs: nofree nounwind +declare noundef i32 @putchar(i32 noundef) local_unnamed_addr #0 + +attributes #0 = { nofree nounwind } diff --git a/package-lock.json b/package-lock.json index 0791c63..c443484 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "chalk": "^5.4.1", "commander": "^13.1.0", "cors": "^2.8.5", - "llvm-bindings": "github:TypeFox/llvm-bindings", + "llvm-bindings": "git+https://github.com/mohitk05/llvm-bindings.git", "ts-pattern": "^5.6.2", "typescript": "^5.4.5" }, @@ -3057,7 +3057,7 @@ }, "node_modules/llvm-bindings": { "version": "0.4.2", - "resolved": "git+ssh://git@github.com/TypeFox/llvm-bindings.git#2993d11f0e7d5cef6707bea687b9f9bc45b5402f", + "resolved": "git+ssh://git@github.com/mohitk05/llvm-bindings.git#2993d11f0e7d5cef6707bea687b9f9bc45b5402f", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -7548,8 +7548,8 @@ "integrity": "sha512-3mk/Zag0+IJxeDrxSgaDPy4zZ3w05PRZeJNnlWhzFz5OkX49J4krc+A8X2d2M69vGMBEX0uyl8M+W+8gH+kBqQ==" }, "llvm-bindings": { - "version": "git+ssh://git@github.com/TypeFox/llvm-bindings.git#2993d11f0e7d5cef6707bea687b9f9bc45b5402f", - "from": "llvm-bindings@github:TypeFox/llvm-bindings", + "version": "git+ssh://git@github.com/mohitk05/llvm-bindings.git#2993d11f0e7d5cef6707bea687b9f9bc45b5402f", + "from": "llvm-bindings@git+https://github.com/mohitk05/llvm-bindings.git", "requires": { "bindings": "^1.5.0", "cmake-js": "^6.3.2", diff --git a/package.json b/package.json index 15fc505..669d783 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "chalk": "^5.4.1", "commander": "^13.1.0", "cors": "^2.8.5", - "llvm-bindings": "github:TypeFox/llvm-bindings", + "llvm-bindings": "git+https://github.com/mohitk05/llvm-bindings.git", "ts-pattern": "^5.6.2", "typescript": "^5.4.5" }, diff --git a/src/codegen/llvm.ts b/src/codegen/llvm.ts index afb55db..63943a6 100644 --- a/src/codegen/llvm.ts +++ b/src/codegen/llvm.ts @@ -5,12 +5,15 @@ import { NodeAssignment, NodeBinaryOp, NodeCall, + NodeCollectionInit, NodeExpr, NodeExprBracketed, NodeExpressionStatement, NodeForStatement, NodeFunctionDefinition, + NodeGomTypeList, NodeGomTypeStruct, + NodeGomTypeTuple, NodeIfStatement, NodeLetStatement, NodeMainFunction, @@ -25,6 +28,7 @@ import { ScopeManager } from "../semantics/scope"; import { GomCompositeType, GomFunctionType, + GomListType, GomPrimitiveTypeOrAlias, GomPrimitiveTypeOrAliasValue, GomStructType, @@ -50,6 +54,8 @@ type ExpressionContext = Partial<{ pointer: llvm.Value; }>; +const LIST_INITIAL_CAPACITY = 16; + /** * Generates LLVM IR - todo to use llvm bindings */ @@ -63,7 +69,9 @@ export class CodeGenerator extends BaseCodeGenerator { private formatStrings: Record = {}; private globalStringPtrs: Record = {}; - private structTypes: Record = {}; + private complexTypes: Record = {}; + + private mallocedPointers: Record = {}; constructor({ ast, @@ -131,7 +139,7 @@ export class CodeGenerator extends BaseCodeGenerator { } private mapGomStructTypeToLLVMType(type: GomStructType) { - const structType = this.structTypes[type.name]; + const structType = this.complexTypes[type.name]; if (!structType) { throw new Error("Unknown type: " + type.name); } @@ -139,6 +147,15 @@ export class CodeGenerator extends BaseCodeGenerator { return structType; } + private mapGomListTypeToLLVMType(type: GomListType) { + const listType = this.complexTypes[type.name]; + if (!listType) { + throw new Error("Unknown type: " + type.name); + } + + return listType; + } + private mapGomTypeToLLVMType(type: GomType): llvm.Type { if (type instanceof GomPrimitiveTypeOrAlias) { return this.mapGomPrimitiveTypeToLLVMType(type); @@ -146,8 +163,9 @@ export class CodeGenerator extends BaseCodeGenerator { return this.mapGomStructTypeToLLVMType(type); } else if (type instanceof GomTupleType) { return this.mapGomTupleTypeToLLVMType(type); + } else if (type instanceof GomListType) { + return this.mapGomListTypeToLLVMType(type); } - throw new Error("Unknown type: " + type.toStr()); } @@ -201,6 +219,13 @@ export class CodeGenerator extends BaseCodeGenerator { ); this.module.getOrInsertFunction("printf", printFnType); + + const mallocFnType = llvm.FunctionType.get( + this.builder.getInt8PtrTy(), + [this.builder.getInt32Ty()], + false + ); + this.module.getOrInsertFunction("malloc", mallocFnType); } override generateAndWriteFile(): void { @@ -239,7 +264,46 @@ export class CodeGenerator extends BaseCodeGenerator { }); structType.setBody(fields); - this.structTypes[type.name] = structType; + this.complexTypes[type.name] = structType; + } else if (node.rhs instanceof NodeGomTypeTuple) { + const type = this.symbolTableReader.getType(node.name.token.value); + if (!type) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "Unknown type: " + node.name.token.value, + }); + } + const tupleType = llvm.StructType.create( + this.context, + node.name.token.value + ); + const gomType = type.gomType as GomTupleType; + const fields = Array.from(gomType.fields).map(([_key, fieldType]) => { + return this.mapGomTypeToLLVMType(fieldType); + }); + tupleType.setBody(fields); + this.complexTypes[type.name] = tupleType; + } else if (node.rhs instanceof NodeGomTypeList) { + const type = this.symbolTableReader.getType(node.name.token.value); + if (!type) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "Unknown type: " + node.name.token.value, + }); + } + const listType = llvm.StructType.create( + this.context, + node.name.token.value + ); + const gomType = type.gomType as GomListType; + const elementType = this.mapGomTypeToLLVMType(gomType.elementType); + listType.setBody([ + llvm.PointerType.get(elementType, 0), // data + llvm.Type.getInt32Ty(this.context), // size + llvm.Type.getInt32Ty(this.context), // capacity + ]); + + this.complexTypes[type.name] = listType; } } @@ -363,6 +427,8 @@ export class CodeGenerator extends BaseCodeGenerator { pointer: alloca, }); + console.log("RHS Value:", rhsValue, "Type:", rhsValue.getType()); + if (!type.isStructTy()) { this.builder.CreateStore(rhsValue, alloca); } @@ -491,8 +557,8 @@ export class CodeGenerator extends BaseCodeGenerator { this.builder.CreateCondBr(condValue, bodyBB, afterBB); this.builder.SetInsertPoint(bodyBB); - this.symbolTableReader.enterScope("for"); - this.irScopeManager.enterScope("for"); + this.symbolTableReader.enterScope("for" + node._id); + this.irScopeManager.enterScope("for" + node._id); node.body.forEach((stmt) => this.visit(stmt)); this.symbolTableReader.exitScope(); this.irScopeManager.exitScope(); @@ -518,8 +584,8 @@ export class CodeGenerator extends BaseCodeGenerator { this.builder.CreateBr(loopBB); this.builder.SetInsertPoint(loopBB); - this.symbolTableReader.enterScope("for"); - this.irScopeManager.enterScope("for"); + this.symbolTableReader.enterScope("for" + node._id); + this.irScopeManager.enterScope("for" + node._id); node.body.forEach((stmt) => this.visit(stmt)); this.symbolTableReader.exitScope(); this.irScopeManager.exitScope(); @@ -532,7 +598,7 @@ export class CodeGenerator extends BaseCodeGenerator { visitExpression(expr: NodeExpr, context?: ExpressionContext): llvm.Value { if (expr instanceof NodeAccess) { - return this.visitAccess(expr); + return this.visitAccess(expr, context); } else if (expr instanceof NodeBinaryOp) { return this.visitBinaryOp(expr, context); } else if (expr instanceof NodeCall) { @@ -543,6 +609,8 @@ export class CodeGenerator extends BaseCodeGenerator { return this.visitAssignment(expr); } else if (expr instanceof NodeStructInit) { return this.visitStructInit(expr, context); + } else if (expr instanceof NodeCollectionInit) { + return this.visitCollectionInit(expr, context); } else if (expr instanceof NodeTupleLiteral) { return this.visitTupleLiteral(expr, context); } else if (expr instanceof NodeExprBracketed) { @@ -560,7 +628,7 @@ export class CodeGenerator extends BaseCodeGenerator { message: "Unknown identifier: " + node.lhs.token.value, }); } - + console.log(id); const rhsValue = this.visitExpression(node.rhs); this.builder.CreateStore(rhsValue, id.allocaInst!); return rhsValue; @@ -570,42 +638,172 @@ export class CodeGenerator extends BaseCodeGenerator { node: NodeStructInit, context?: ExpressionContext ): llvm.Value { - if (!context?.declLhs) { - this.errorManager.throwCodegenError({ - loc: node.loc, - message: "Struct init without declaration", + if (context?.declLhs) { + const structId = this.symbolTableReader.getIdentifier( + context.declLhs.token.value + ); + if (!structId) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "Unknown struct: " + node.structTypeName.token.value, + }); + } + + if (!structId.allocaInst) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "Struct not allocated: " + node.structTypeName.token.value, + }); + } + const structAlloca = structId.allocaInst; + const structType = this.mapGomTypeToLLVMType(node.resultantType); + const index0 = this.builder.getInt32(0); + node.fields.forEach((field, i) => { + const fieldVal = this.visitExpression(field[1]); + const fieldPtr = this.builder.CreateGEP( + structType, + structAlloca, + [index0, this.builder.getInt32(i)], + "fieldptr" + ); + this.builder.CreateStore(fieldVal, fieldPtr); }); - } - const structId = this.symbolTableReader.getIdentifier( - context.declLhs.token.value - ); - if (!structId) { - this.errorManager.throwCodegenError({ - loc: node.loc, - message: "Unknown struct: " + node.structTypeName.token.value, + return structAlloca; + } else { + const structType = this.mapGomTypeToLLVMType(node.resultantType); + const structAlloca = this.builder.CreateAlloca( + structType, + null, + node.structTypeName.token.value + "_instance" + ); + node.fields.forEach((field, i) => { + const fieldVal = this.visitExpression(field[1]); + const fieldPtr = this.builder.CreateGEP( + structType, + structAlloca, + [this.builder.getInt32(0), this.builder.getInt32(i)], + "fieldptr" + ); + this.builder.CreateStore(fieldVal, fieldPtr); }); + return structAlloca; } + } - if (!structId.allocaInst) { - this.errorManager.throwCodegenError({ - loc: node.loc, - message: "Struct not allocated: " + node.structTypeName.token.value, + visitCollectionInit( + node: NodeCollectionInit, + context?: ExpressionContext + ): llvm.Value { + if (node.resultantType instanceof GomTupleType) { + const type = this.mapGomTypeToLLVMType( + node.resultantType as GomTupleType + ); + const tuple = this.builder.CreateAlloca(type, null, "tuple"); + node.elements.forEach((element, i) => { + const fieldVal = this.visitExpression(element); + const fieldPtr = this.builder.CreateGEP( + type, + tuple, + [this.builder.getInt32(0), this.builder.getInt32(i)], + "fieldptr" + ); + this.builder.CreateStore(fieldVal, fieldPtr); }); - } - const structAlloca = structId.allocaInst; - const structType = this.mapGomTypeToLLVMType(node.resultantType); - const index0 = this.builder.getInt32(0); - node.fields.forEach((field, i) => { - const fieldVal = this.visitExpression(field[1]); - const fieldPtr = this.builder.CreateGEP( - structType, - structAlloca, - [index0, this.builder.getInt32(i)], - "fieldptr" + return tuple; + } else if (node.resultantType instanceof GomListType) { + const gomListType = node.resultantType as GomListType; + const listType = this.mapGomTypeToLLVMType(gomListType); + // const listPtr = this.builder.CreateAlloca(listType, null, "list_ptr"); + const listPtr = context?.pointer + ? context.pointer + : this.builder.CreateAlloca(listType, null, "list_ptr"); + + const dataPtrPtr = this.builder.CreateGEP( + listType, + listPtr, + [this.builder.getInt32(0), this.builder.getInt32(0)], + "data_ptr_ptr" ); - this.builder.CreateStore(fieldVal, fieldPtr); + const sizePtr = this.builder.CreateGEP( + listType, + listPtr, + [this.builder.getInt32(0), this.builder.getInt32(1)], + "size_ptr" + ); + const capacityPtr = this.builder.CreateGEP( + listType, + listPtr, + [this.builder.getInt32(0), this.builder.getInt32(2)], + "capacity_ptr" + ); + + const initialCapacity = this.builder.getInt32( + Math.max(LIST_INITIAL_CAPACITY, node.elements.length) + ); + this.builder.CreateStore(initialCapacity, capacityPtr); + this.builder.CreateStore( + this.builder.getInt32(node.elements.length), + sizePtr + ); + + const elementType = this.mapGomTypeToLLVMType(gomListType.elementType); + console.log("Element type:", elementType, gomListType.elementType); + const arrayElementType = elementType; + const sizeOfType = llvm.ConstantInt.get( + llvm.Type.getInt32Ty(this.context), + this.module.getDataLayout().getTypeAllocSize(elementType) + ); + console.log("Size of type:", sizeOfType); + const mallocSize = this.builder.CreateMul( + initialCapacity, + sizeOfType, + "malloc_size" + ); + const mallocFn = this.module.getFunction("malloc"); + if (!mallocFn) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "malloc function not added globally", + }); + } + const mallocCall = this.builder.CreateCall( + mallocFn, + [mallocSize], + "malloc_call" + ); + const dataAlloca = this.builder.CreateBitCast( + mallocCall, + llvm.PointerType.get(arrayElementType, 0), + "data_alloca" + ); + this.builder.CreateStore(dataAlloca, dataPtrPtr); + + // initialize elements + node.elements.forEach((element, i) => { + let elementVal = this.visitExpression(element); + if (elementVal.getType().isPointerTy()) { + elementVal = this.builder.CreateLoad( + this.mapGomTypeToLLVMType(gomListType.elementType), + elementVal, + "element_load" + ); + } + const elementPtr = this.builder.CreateInBoundsGEP( + arrayElementType, + dataAlloca, + [this.builder.getInt32(i)], + "element_ptr" + ); + this.builder.CreateStore(elementVal, elementPtr); + }); + + return listPtr; + } + + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "Collection init without tuple or list type", }); - return structAlloca; } visitTupleLiteral( @@ -628,7 +826,7 @@ export class CodeGenerator extends BaseCodeGenerator { return tuple; } - visitAccess(node: NodeAccess): llvm.Value { + visitAccess(node: NodeAccess, context?: ExpressionContext): llvm.Value { const idName = node.lhs.token.value; if (idName === "io" && node.rhs instanceof NodeCall) { const fn = this.module.getFunction("printf"); @@ -703,11 +901,85 @@ export class CodeGenerator extends BaseCodeGenerator { [this.builder.getInt32(0), index], "fieldptr" ); - return this.builder.CreateLoad( + const load = this.builder.CreateLoad( this.mapGomTypeToLLVMType(node.rhs.resultantType), ptr, "fieldload" ); + if (context?.pointer) { + this.builder.CreateStore(load, context.pointer); + } + return load; + } else if (node.lhs.resultantType instanceof GomListType) { + const type = node.lhs.resultantType; + const listType = this.mapGomTypeToLLVMType(type); + const list = this.symbolTableReader.getIdentifier(idName); + if (!list) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "Unknown list: " + idName, + }); + } + if (!list.allocaInst) { + this.errorManager.throwCodegenError({ + loc: node.loc, + message: "List not allocated: " + idName, + }); + } + + // built-in property access + if ( + node.rhs instanceof NodeTerm && + GomListType.isBuiltInProperty(node.rhs.token.value) + ) { + if (node.rhs.token.value === GomListType.SIZE_PROPERTY) { + const sizePtr = this.builder.CreateGEP( + listType, + list.allocaInst, + [this.builder.getInt32(0), this.builder.getInt32(1)], + "size_ptr" + ); + const sizeValue = this.builder.CreateLoad( + llvm.Type.getInt32Ty(this.context), + sizePtr, + "size_value" + ); + if (context?.pointer) { + this.builder.CreateStore(sizeValue, context.pointer); + } + return sizeValue; + } + } else { + const indexValue = this.visitExpression(node.rhs); + const elementType = this.mapGomTypeToLLVMType(type.elementType); + const dataPtrPtr = this.builder.CreateInBoundsGEP( + listType, + list.allocaInst, + [this.builder.getInt32(0), this.builder.getInt32(0)], + "data_ptr_ptr" + ); + const dataPtr = this.builder.CreateLoad( + llvm.PointerType.get(elementType, 0), + dataPtrPtr, + "data_ptr" + ); + + const elementPtr = this.builder.CreateInBoundsGEP( + elementType, + dataPtr, + [indexValue], + "element_ptr" + ); + const load = this.builder.CreateLoad( + elementType, + elementPtr, + "element_load" + ); + if (context?.pointer) { + this.builder.CreateStore(load, context.pointer); + } + return load; + } } return this.builder.getInt32(0); diff --git a/src/parser/rd/index.ts b/src/parser/rd/index.ts index 192d93b..75cde0e 100644 --- a/src/parser/rd/index.ts +++ b/src/parser/rd/index.ts @@ -8,6 +8,7 @@ import { NodeAssignment, NodeBinaryOp, NodeCall, + NodeCollectionInit, NodeConstStatement, NodeExpr, NodeExprBracketed, @@ -18,13 +19,13 @@ import { NodeGomType, NodeGomTypeComposite, NodeGomTypeId, + NodeGomTypeList, NodeGomTypeStruct, NodeGomTypeStructField, NodeGomTypeTuple, NodeIfStatement, NodeImportDeclaration, NodeLetStatement, - NodeListLiteral, NodeMainFunction, NodeProgram, NodeReturnStatement, @@ -216,6 +217,9 @@ export class RecursiveDescentParser { } else { return this.parseTupleType(); } + } else if (this.peek(GomToken.LBRACKET) && typeName) { + // List type + return this.parseListType(typeName); } else if (this.peek(GomToken.IDENTIFIER)) { this.buffer.push(this.lexer.nextToken()); if (this.buffer[this.buffer.length - 1].type === GomToken.LT) { @@ -231,6 +235,19 @@ export class RecursiveDescentParser { throw new Error(`Unexpected token: ${this.token.value}`); } + parseListType(typeName: NodeTerm): NodeGomType { + const loc = this.token.start; + this.match(GomToken.LBRACKET); + const baseType = this.parseGomType(); + this.match(GomToken.RBRACKET); + + return new NodeGomTypeList({ + name: typeName, + elementType: baseType, + loc, + }); + } + parseCompositeType(): NodeGomTypeComposite { const baseType = this.parseTerm(); this.match(GomToken.LT); @@ -472,14 +489,12 @@ export class RecursiveDescentParser { return new NodeExprBracketed({ expr, loc }); } else if (this.peek(GomToken.LBRACE)) { return this.parseTupleLiteral(); - } else if (this.peek(GomToken.LBRACKET)) { - return this.parseListLiteral(); } else if (this.peek(GomToken.IDENTIFIER)) { this.buffer.push(this.lexer.nextToken()); if (this.buffer[1].type === GomToken.EQ) { return this.parseAssignment(); } else { - return this.parseStructInit(); + return this.parseCollectionInit(); } } else { return this.parseComparison(); @@ -501,21 +516,6 @@ export class RecursiveDescentParser { return new NodeTupleLiteral({ elements, loc }); } - parseListLiteral(): NodeListLiteral { - const loc = this.token.start; - this.match(GomToken.LBRACKET); - const elements = this.parseZeroOrMore(() => { - const expr = this.parseExpression(); - if (!this.peek(GomToken.RBRACKET)) { - this.match(GomToken.COMMA); - } - return expr; - }); - this.match(GomToken.RBRACKET); - - return new NodeListLiteral({ elements, loc }); - } - parseAssignment(): NodeAssignment { const loc = this.token.start; const lhs = this.parseTerm() as NodeTerm; @@ -534,26 +534,64 @@ export class RecursiveDescentParser { return new NodeAccess({ lhs, rhs, loc }); } - parseStructInit(): NodeExpr { + parseCollectionInit(): NodeExpr { if (this.buffer[1].type === GomToken.LBRACE) { const loc = this.token.start; - const structTypeName = this.parseTerm(); + const id = this.parseTerm(); this.match(GomToken.LBRACE); - const fields: [NodeTerm, NodeExpr][] = this.parseOneOrMore(() => { - const name = this.parseTerm(); - this.match(GomToken.COLON); - const value = this.parseExpression(); - if (!this.peek(GomToken.RBRACE)) this.match(GomToken.COMMA); - return [name, value]; - }); - this.match(GomToken.RBRACE); - - return new NodeStructInit({ structTypeName, fields, loc }); + // could be struct, tuple or list + this.buffer.push(this.lexer.nextToken()); + console.log(this.buffer); + // @ts-ignore + if (this.buffer[1].type === GomToken.COLON) { + const fields: [NodeTerm, NodeExpr][] = this.parseOneOrMore(() => { + const name = this.parseTerm(); + this.match(GomToken.COLON); + const value = this.parseExpression(); + if (!this.peek(GomToken.RBRACE)) this.match(GomToken.COMMA); + return [name, value]; + }); + this.match(GomToken.RBRACE); + return new NodeStructInit({ structTypeName: id, fields, loc }); + } else { + // tuple or list + const elements: NodeExpr[] = this.parseZeroOrMore(() => { + const expr = this.parseExpression(); + if (!this.peek(GomToken.RBRACE)) this.match(GomToken.COMMA); + return expr; + }); + this.match(GomToken.RBRACE); + return new NodeCollectionInit({ + collectionTypeName: id, + elements, + loc, + }); + } } return this.parseComparison(); } + // parseStructInit(): NodeExpr { + // if (this.buffer[1].type === GomToken.LBRACE) { + // const loc = this.token.start; + // const structTypeName = this.parseTerm(); + // this.match(GomToken.LBRACE); + // const fields: [NodeTerm, NodeExpr][] = this.parseOneOrMore(() => { + // const name = this.parseTerm(); + // this.match(GomToken.COLON); + // const value = this.parseExpression(); + // if (!this.peek(GomToken.RBRACE)) this.match(GomToken.COMMA); + // return [name, value]; + // }); + // this.match(GomToken.RBRACE); + + // return new NodeStructInit({ structTypeName, fields, loc }); + // } + + // return this.parseComparison(); + // } + parseComparison(): NodeExpr { const loc = this.token.start; let lhs = this.parseSum(); diff --git a/src/parser/rd/nodes/index.ts b/src/parser/rd/nodes/index.ts index 8eef51a..7ced0c0 100644 --- a/src/parser/rd/nodes/index.ts +++ b/src/parser/rd/nodes/index.ts @@ -1,10 +1,10 @@ import { Token } from "../../../lexer"; import { GomToken } from "../../../lexer/tokens"; import { - GomArrayType, GomCompositeType, GomCompositeTypeKind, GomFunctionType, + GomListType, GomPrimitiveTypeOrAlias, GomStructType, GomTupleType, @@ -352,6 +352,7 @@ export class NodeFunctionReturnType extends AbstractNode { export type NodeGomType = | NodeGomTypeId | NodeGomTypeStruct + | NodeGomTypeList | NodeGomTypeComposite | NodeGomTypeTuple; export class NodeGomTypeId extends AbstractNode { @@ -415,6 +416,30 @@ export class NodeGomTypeStruct extends AbstractNode { } } +export class NodeGomTypeList extends AbstractNode { + type: NodeType; + elementType: NodeGomType; + gomType: GomListType; + children: Node[]; + + constructor({ + name, + elementType, + loc, + }: { + name: NodeTerm; + elementType: NodeGomType; + loc: number; + }) { + super(); + this.type = NodeType.GOM_TYPE_LIST; + this.loc = loc; + this.elementType = elementType; + this.gomType = new GomListType(name.token.value, elementType.gomType); + this.children = formChildrenArray(elementType); + } +} + export class NodeGomTypeComposite extends AbstractNode { type: NodeType; id: NodeTerm; @@ -445,8 +470,6 @@ export class NodeGomTypeComposite extends AbstractNode { static getGomCompositeTypeKind(id: NodeTerm): GomCompositeTypeKind { switch (id.token.value) { - case "List": - return GomCompositeTypeKind.List; default: return GomCompositeTypeKind._Custom; } @@ -482,12 +505,12 @@ export type NodeExpr = NodeExprBasic | NodeExprBracketed; export type NodeExprBasic = | NodeAssignment | NodeStructInit + | NodeCollectionInit | NodeAccess | NodeIndexedAccess | NodeCall | NodeBinaryOp | NodeTupleLiteral - | NodeListLiteral | NodeTerm; export class NodeAssignment extends AbstractNode { @@ -546,6 +569,34 @@ export class NodeStructInit extends AbstractNode { } } +export class NodeCollectionInit extends AbstractNode { + type: NodeType; + collectionTypeName: NodeTerm; + elements: NodeExpr[]; + resultantType: GomType; + + constructor({ + collectionTypeName, + elements, + loc, + }: { + collectionTypeName: NodeTerm; + elements: NodeExpr[]; + loc: number; + }) { + super(); + this.type = NodeType.COLLECTION_INIT; + this.loc = loc; + this.collectionTypeName = collectionTypeName; + this.elements = elements; + this.resultantType = new GomListType( + collectionTypeName.token.value, + elements[0].resultantType + ); + this.children = formChildrenArray(elements); + } +} + export class NodeBinaryOp extends AbstractNode { type: NodeType; lhs: NodeExpr; @@ -691,26 +742,6 @@ export class NodeTupleLiteral extends AbstractNode { } } -export class NodeListLiteral extends AbstractNode { - type: NodeType; - elements: NodeExpr[]; - children: Node[]; - gomType: GomType; - resultantType: GomType; - - constructor({ elements, loc }: { elements: NodeExpr[]; loc: number }) { - super(); - this.type = NodeType.LIST_LITERAL; - this.loc = loc; - this.elements = elements; - this.children = elements; - this.gomType = new GomCompositeType(GomCompositeTypeKind.List, [ - elements[0].resultantType, - ]); - this.resultantType = this.gomType; - } -} - export class NodeTerm extends AbstractNode { type: NodeType; token: Token; diff --git a/src/parser/rd/tree.ts b/src/parser/rd/tree.ts index a580947..0122f01 100644 --- a/src/parser/rd/tree.ts +++ b/src/parser/rd/tree.ts @@ -9,7 +9,10 @@ export interface Node { token?: Token; } +let globalNodeIdCounter = 0; + export abstract class AbstractNode implements Node { + readonly _id: number; type: NodeType; loc: number; parent?: Node; @@ -17,6 +20,7 @@ export abstract class AbstractNode implements Node { token?: Token; constructor() { + this._id = globalNodeIdCounter++; this.type = NodeType.PROGRAM; this.loc = 0; this.children = []; @@ -44,6 +48,7 @@ export enum NodeType { GOM_TYPE_TUPLE = "GOM_TYPE_TUPLE", GOM_TYPE_STRUCT = "GOM_TYPE_STRUCT", GOM_TYPE_STRUCT_FIELD = "GOM_TYPE_STRUCT_FIELD", + GOM_TYPE_LIST = "GOM_TYPE_LIST", GOM_TYPE_COMPOSITE = "GOM_TYPE_COMPOSITE", ARGUMENT_ITEM = "ARGUMENT_ITEM", FUNCTION_RETURN_TYPE = "FUNCTION_RETURN_TYPE", @@ -51,6 +56,7 @@ export enum NodeType { EXPR_BRACKETED = "EXPR_BRACKETED", ASSIGNMENT = "ASSIGNMENT", STRUCT_INIT = "STRUCT_INIT", + COLLECTION_INIT = "COLLECTION_INIT", ACCESS = "ACCESS", CALL = "CALL", COMPARISON = "COMPARISON", diff --git a/src/parser/rd/visitor.ts b/src/parser/rd/visitor.ts index 6c194a9..1f407d4 100644 --- a/src/parser/rd/visitor.ts +++ b/src/parser/rd/visitor.ts @@ -4,6 +4,7 @@ import { NodeAssignment, NodeBinaryOp, NodeCall, + NodeCollectionInit, NodeExprBracketed, NodeExpressionStatement, NodeForStatement, @@ -14,7 +15,6 @@ import { NodeImportDeclaration, NodeIndexedAccess, NodeLetStatement, - NodeListLiteral, NodeMainFunction, NodeProgram, NodeReturnStatement, @@ -97,6 +97,9 @@ export class SimpleVisitor implements Visitor { case NodeType.STRUCT_INIT: this.visitStructInit(node as NodeStructInit); return; + case NodeType.COLLECTION_INIT: + this.visitCollectionInit(node as NodeCollectionInit); + return; case NodeType.GOM_TYPE_STRUCT_FIELD: this.visitStructField(node as NodeGomTypeStructField); return; @@ -124,9 +127,6 @@ export class SimpleVisitor implements Visitor { case NodeType.TUPLE_LITERAL: this.visitTupleLiteral(node as NodeTupleLiteral); return; - case NodeType.LIST_LITERAL: - this.visitListLiteral(node as NodeListLiteral); - return; case NodeType.INDEXED_ACCESS: this.visitIndexedAccess(node as NodeIndexedAccess); return; @@ -178,6 +178,9 @@ export class SimpleVisitor implements Visitor { visitStructInit(node: NodeStructInit) { this.visitChildren(node); } + visitCollectionInit(node: NodeCollectionInit) { + this.visitChildren(node); + } visitStructField(node: NodeGomTypeStructField) { this.visitChildren(node); } @@ -202,9 +205,6 @@ export class SimpleVisitor implements Visitor { visitTupleLiteral(node: NodeTupleLiteral) { this.visitChildren(node); } - visitListLiteral(node: NodeListLiteral) { - this.visitChildren(node); - } visitIndexedAccess(node: NodeIndexedAccess) { this.visitChildren(node); } diff --git a/src/semantics/index.ts b/src/semantics/index.ts index 4d2805b..3edc5eb 100644 --- a/src/semantics/index.ts +++ b/src/semantics/index.ts @@ -2,6 +2,7 @@ import { NodeAccess, NodeBinaryOp, NodeCall, + NodeCollectionInit, NodeExpr, NodeForStatement, NodeFunctionDefinition, @@ -24,6 +25,7 @@ import { ScopeManager, SymbolTableReader } from "./scope"; import { SimpleVisitor } from "../parser/rd/visitor"; import { GomFunctionType, + GomListType, GomPrimitiveTypeOrAlias, GomStructType, GomTupleType, @@ -166,7 +168,7 @@ export class SemanticAnalyzer extends SimpleVisitor { if (node.updateExpr) this.visit(node.updateExpr); - this.scopeManager.beginScope("for"); + this.scopeManager.beginScope("for" + node._id); node.body.forEach((stmt) => this.visit(stmt)); this.scopeManager.endScope(); } @@ -214,11 +216,6 @@ export class SemanticAnalyzer extends SimpleVisitor { inferredType, decl.rhs ); - console.log( - "let", - decl.lhs.token.value, - this.scopeManager.getCurrentSymbolTableNode().getName() - ); } }); } @@ -348,6 +345,58 @@ class TypeResolver extends SimpleVisitor { this.currentType = gomType; } + visitCollectionInit(node: NodeCollectionInit): void { + // tuple or list + const collectionType = this.symbolTableReader.getType( + node.collectionTypeName.token.value + ); + if (!collectionType) { + this.errorManager.throwTypeError({ + message: `Type ${node.collectionTypeName.token.value} not found`, + loc: node.loc, + }); + } + const gomType = collectionType.gomType; + if (gomType instanceof GomTupleType) { + if (node.elements.length !== gomType.fields.size) { + this.errorManager.throwTypeError({ + message: `Element count mismatch: expected ${gomType.fields.size}, got ${node.elements.length}`, + loc: node.loc, + }); + } + + node.elements.forEach((element, index) => { + this.visit(element); + const elementType = this.currentType; + if (!elementType?.isEqual(gomType.fields.get(index.toString())!)) { + this.errorManager.throwTypeError({ + message: `Type mismatch: expected ${gomType.fields + .get(index.toString())! + .toStr()}, got ${elementType?.toStr()}`, + loc: element.loc, + }); + } + }); + + node.resultantType = gomType; + this.currentType = gomType; + } else if (gomType instanceof GomListType) { + node.elements.forEach((element) => { + this.visit(element); + const elementType = this.currentType; + if (!elementType?.isEqual(gomType.elementType)) { + this.errorManager.throwTypeError({ + message: `Type mismatch: expected ${gomType.elementType.toStr()}, got ${elementType?.toStr()}`, + loc: element.loc, + }); + } + }); + + node.resultantType = gomType; + this.currentType = gomType; + } + } + visitTypeDefinition(node: NodeTypeDefinition): void { const type = this.symbolTableReader.getType(node.name.token.value); if (!type) { @@ -374,6 +423,24 @@ class TypeResolver extends SimpleVisitor { } } }); + } else if (gomType instanceof GomListType) { + if (gomType.elementType instanceof GomPrimitiveTypeOrAlias) { + if (gomType.elementType.typeString.startsWith("resolve_type@@")) { + const idName = gomType.elementType.typeString.replace( + "resolve_type@@", + "" + ); + const id = this.symbolTableReader.getType(idName); + if (id) { + gomType.elementType = id.gomType; + } else { + this.errorManager.throwTypeError({ + message: `Type ${idName} not found`, + loc: node.loc, + }); + } + } + } } else if (gomType instanceof GomPrimitiveTypeOrAlias) { if (gomType.typeString.startsWith("resolve_type@@")) { const idName = gomType.typeString.replace("resolve_type@@", ""); @@ -412,6 +479,22 @@ class TypeResolver extends SimpleVisitor { }); } } + } else if (id.type instanceof GomListType) { + node.lhs.resultantType = id.type; + if ( + node.rhs instanceof NodeTerm && + GomListType.isBuiltInProperty(node.rhs.token.value) + ) { + const propertyType = GomListType.builtInPropertyType( + node.rhs.token.value + ); + node.rhs.resultantType = propertyType; + node.resultantType = propertyType; + this.currentType = propertyType; + } else { + node.resultantType = id.type.elementType; + this.currentType = id.type.elementType; + } } else { this.visit(node.rhs); } @@ -544,7 +627,6 @@ class TypeResolver extends SimpleVisitor { visitTerm(node: NodeTerm): void { const type = node.gomType; - if (type instanceof GomPrimitiveTypeOrAlias) { if (type.typeString.startsWith("resolve_type@@")) { const idName = type.typeString.replace("resolve_type@@", ""); diff --git a/src/semantics/scope.ts b/src/semantics/scope.ts index cfd0d9d..b4a3cb2 100644 --- a/src/semantics/scope.ts +++ b/src/semantics/scope.ts @@ -391,8 +391,22 @@ export class SymbolTableReader { } } - getAllIdentifiers() { - return this.currentSymbolTable.getValue().getAllIdentifiers(); + getAllIdentifiers(recursive = false) { + if (!recursive) { + return this.currentSymbolTable.getValue().getAllIdentifiers(); + } + const identifiers: IdentifierEntry[] = []; + let currentSymbolTable = this.currentSymbolTable; + while (currentSymbolTable) { + identifiers.push(...currentSymbolTable.getValue().getAllIdentifiers()); + const parent = currentSymbolTable.getParent(); + if (parent) { + currentSymbolTable = parent; + } else { + break; + } + } + return identifiers; } getAllTypes() { diff --git a/src/semantics/type.ts b/src/semantics/type.ts index 790cec2..d4a412f 100644 --- a/src/semantics/type.ts +++ b/src/semantics/type.ts @@ -13,16 +13,14 @@ import assert from "assert"; export enum GomTypeKind { PrimitiveOrAlias = "PrimitiveOrAlias", - // Deprecated, use Composite instead - Array = "Array", Tuple = "Tuple", Struct = "Struct", + List = "List", Composite = "Composite", Function = "Function", } export enum GomCompositeTypeKind { - List = "List", _Custom = "_Custom", // Map = "Map", // Set = "Set", @@ -68,32 +66,41 @@ export class GomPrimitiveTypeOrAlias extends GomType { } } -/** - * Deprecated, use GomCompositeType instead - */ -export class GomArrayType extends GomType { +export class GomListType extends GomType { + name: string; kind: GomTypeKind; elementType: GomType; - size: number; + static readonly SIZE_PROPERTY = "size"; - constructor(elementType: GomType, size: number) { + constructor(name: string, elementType: GomType) { super(); - this.kind = GomTypeKind.Array; + this.name = name; + this.kind = GomTypeKind.List; this.elementType = elementType; - this.size = size; } - isEqual(other: GomArrayType): boolean { - if (other.kind !== GomTypeKind.Array) { + isEqual(other: GomListType): boolean { + if (other.kind !== GomTypeKind.List) { return false; } - return ( - this.size === other.size && this.elementType.isEqual(other.elementType) - ); + return this.elementType.isEqual(other.elementType); } toStr(): string { - return `${this.elementType.toStr()}[${this.size}]`; + return `[${this.elementType.toStr()}]`; + } + + static isBuiltInProperty(name: string): boolean { + return [GomListType.SIZE_PROPERTY].includes(name); + } + + static builtInPropertyType(name: string): GomType { + switch (name) { + case GomListType.SIZE_PROPERTY: + return new GomPrimitiveTypeOrAlias("int"); + default: + throw new Error(`Unknown list property: ${name}`); + } } } diff --git a/tree.json b/tree.json index f4fcc3d..a88b265 100644 --- a/tree.json +++ b/tree.json @@ -1,8 +1,10 @@ { + "_id": 185, "type": "PROGRAM", "loc": 0, "importDeclarations": [ { + "_id": 0, "type": "IMPORT_DECLARATION", "loc": 7, "path": { @@ -15,603 +17,729 @@ ], "typeDefinitions": [ { + "_id": 5, "type": "TYPE_DEFINITION", - "loc": 21, + "loc": 12, "name": { + "_id": 1, "type": "TERM", - "loc": 26, + "loc": 17, "token": { "type": "identifier", - "value": "HttpResponse", - "start": 26, - "end": 37 + "value": "Numbers", + "start": 17, + "end": 23 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" + "typeString": "resolve_type@@Numbers" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" + "typeString": "resolve_type@@Numbers" } }, "rhs": { - "type": "GOM_TYPE_TUPLE", - "loc": 41, + "_id": 4, + "type": "GOM_TYPE_LIST", + "loc": 27, + "elementType": { + "_id": 3, + "type": "GOM_TYPE_ID", + "loc": 28, + "id": { + "_id": 2, + "type": "TERM", + "loc": 28, + "token": { + "type": "built_in_type", + "value": "int", + "start": 28, + "end": 30 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "gomType": { + "kind": "List", + "name": "Numbers", + "elementType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + } + }, + { + "_id": 14, + "type": "TYPE_DEFINITION", + "loc": 34, + "name": { + "_id": 6, + "type": "TERM", + "loc": 39, + "token": { + "type": "identifier", + "value": "Status", + "start": 39, + "end": 44 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Status" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Status" + } + }, + "rhs": { + "_id": 13, + "type": "GOM_TYPE_STRUCT", + "loc": 48, "fields": [ { - "type": "GOM_TYPE_ID", - "loc": 43, - "id": { - "type": "TERM", - "loc": 43, - "token": { - "type": "built_in_type", - "value": "int", - "start": 43, - "end": 45 + "_id": 9, + "type": "GOM_TYPE_STRUCT_FIELD", + "loc": 52, + "name": { + "type": "identifier", + "value": "code", + "start": 52, + "end": 55 + }, + "fieldType": { + "_id": 8, + "type": "GOM_TYPE_ID", + "loc": 58, + "id": { + "_id": 7, + "type": "TERM", + "loc": 58, + "token": { + "type": "built_in_type", + "value": "int", + "start": 58, + "end": 60 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, "gomType": { "kind": "PrimitiveOrAlias", "typeString": "int" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" } - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" } }, { - "type": "GOM_TYPE_ID", - "loc": 48, - "id": { - "type": "TERM", - "loc": 48, - "token": { - "type": "built_in_type", - "value": "bool", - "start": 48, - "end": 51 + "_id": 12, + "type": "GOM_TYPE_STRUCT_FIELD", + "loc": 65, + "name": { + "type": "identifier", + "value": "success", + "start": 65, + "end": 71 + }, + "fieldType": { + "_id": 11, + "type": "GOM_TYPE_ID", + "loc": 74, + "id": { + "_id": 10, + "type": "TERM", + "loc": 74, + "token": { + "type": "built_in_type", + "value": "bool", + "start": 74, + "end": 77 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } }, "gomType": { "kind": "PrimitiveOrAlias", "typeString": "bool" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" } - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" } } ], "gomType": { - "kind": "Tuple", + "kind": "Struct", + "name": "Status", "fields": {} } } - } - ], - "globalVariables": [], - "functionDeclarations": [ + }, { - "type": "FUNCTION_DEFINITION", - "loc": 58, + "_id": 19, + "type": "TYPE_DEFINITION", + "loc": 83, "name": { - "type": "identifier", - "value": "process_http", - "start": 61, - "end": 72 - }, - "args": [ - { - "type": "ARGUMENT_ITEM", - "loc": 74, - "name": { - "type": "TERM", - "loc": 74, - "token": { - "type": "identifier", - "value": "url", - "start": 74, - "end": 76 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@url" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@url" - } - }, - "expectedType": { - "type": "TERM", - "loc": 79, - "token": { - "type": "built_in_type", - "value": "str", - "start": 79, - "end": 81 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - } - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - } + "_id": 15, + "type": "TERM", + "loc": 88, + "token": { + "type": "identifier", + "value": "StatusList", + "start": 88, + "end": 97 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@StatusList" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@StatusList" } - ], - "returnType": { - "type": "FUNCTION_RETURN_TYPE", - "loc": 83, - "returnType": { + }, + "rhs": { + "_id": 18, + "type": "GOM_TYPE_LIST", + "loc": 101, + "elementType": { + "_id": 17, "type": "GOM_TYPE_ID", - "loc": 85, + "loc": 102, "id": { + "_id": 16, "type": "TERM", - "loc": 85, + "loc": 102, "token": { "type": "identifier", - "value": "HttpResponse", - "start": 85, - "end": 96 + "value": "Status", + "start": 102, + "end": 107 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" + "typeString": "resolve_type@@Status" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" + "typeString": "resolve_type@@Status" } }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" + "typeString": "resolve_type@@Status" + } + }, + "gomType": { + "kind": "List", + "name": "StatusList", + "elementType": { + "kind": "Struct", + "name": "Status", + "fields": {} } } + } + }, + { + "_id": 27, + "type": "TYPE_DEFINITION", + "loc": 111, + "name": { + "_id": 20, + "type": "TERM", + "loc": 116, + "token": { + "type": "identifier", + "value": "Pairs", + "start": 116, + "end": 120 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Pairs" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Pairs" + } }, - "body": [ - { - "type": "IF_STATEMENT", - "loc": 102, - "conditionExpr": { - "type": "EXPR_BRACKETED", - "loc": 104, - "expr": { - "type": "COMPARISON", - "loc": 105, - "lhs": { + "rhs": { + "_id": 26, + "type": "GOM_TYPE_LIST", + "loc": 124, + "elementType": { + "_id": 25, + "type": "GOM_TYPE_TUPLE", + "loc": 125, + "fields": [ + { + "_id": 22, + "type": "GOM_TYPE_ID", + "loc": 127, + "id": { + "_id": 21, "type": "TERM", - "loc": 105, + "loc": 127, "token": { - "type": "identifier", - "value": "url", - "start": 105, - "end": 107 + "type": "built_in_type", + "value": "int", + "start": 127, + "end": 129 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@url" + "typeString": "int" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "int" } }, - "op": { - "type": "==", - "value": "==", - "start": 109, - "end": 110 - }, - "rhs": { + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 24, + "type": "GOM_TYPE_ID", + "loc": 132, + "id": { + "_id": 23, "type": "TERM", - "loc": 112, + "loc": 132, "token": { - "type": "strliteral", - "value": "\"http://www.example.com\"", - "start": 112, - "end": 135 + "type": "built_in_type", + "value": "int", + "start": 132, + "end": 134 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "int" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "int" } }, - "resultantType": { + "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "bool" + "typeString": "int" } - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" } - }, - "body": [ - { - "type": "RETURN_STATEMENT", - "loc": 144, - "expr": { - "type": "TUPLE_LITERAL", - "loc": 151, - "elements": [ - { - "type": "TERM", - "loc": 153, - "token": { - "type": "numliteral", - "value": "200", - "start": 153, - "end": 155 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - { - "type": "TERM", - "loc": 158, - "token": { - "type": "true", - "value": "true", - "start": 158, - "end": 161 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" - } - } - ], - "gomType": { - "kind": "Tuple", - "fields": {} - }, - "resultantType": { - "kind": "Tuple", - "fields": {} + ], + "gomType": { + "kind": "Tuple", + "fields": {} + } + }, + "gomType": { + "kind": "List", + "name": "Pairs", + "elementType": { + "kind": "Tuple", + "fields": {} + } + } + } + } + ], + "globalVariables": [], + "functionDeclarations": [], + "exportStatements": [], + "mainFunction": { + "_id": 184, + "type": "MAIN_FUNCTION", + "loc": 144, + "body": [ + { + "_id": 37, + "type": "LET_STATEMENT", + "loc": 155, + "decls": [ + { + "_id": 36, + "type": "ASSIGNMENT", + "loc": 159, + "lhs": { + "_id": 28, + "type": "TERM", + "loc": 159, + "token": { + "type": "identifier", + "value": "numbers", + "start": 159, + "end": 165 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@numbers" + }, + "resultantType": { + "kind": "List", + "name": "Numbers", + "elementType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" } } - } - ] - }, - { - "type": "RETURN_STATEMENT", - "loc": 175, - "expr": { - "type": "TUPLE_LITERAL", - "loc": 182, - "elements": [ - { + }, + "rhs": { + "_id": 35, + "type": "COLLECTION_INIT", + "loc": 169, + "collectionTypeName": { + "_id": 29, "type": "TERM", - "loc": 184, + "loc": 169, "token": { - "type": "numliteral", - "value": "401", - "start": 184, - "end": 186 + "type": "identifier", + "value": "Numbers", + "start": 169, + "end": 175 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "int" + "typeString": "resolve_type@@Numbers" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "int" + "typeString": "resolve_type@@Numbers" } }, - { - "type": "TERM", - "loc": 189, - "token": { - "type": "false", - "value": "false", - "start": 189, - "end": 193 + "elements": [ + { + "_id": 30, + "type": "TERM", + "loc": 179, + "token": { + "type": "numliteral", + "value": "1", + "start": 179, + "end": 179 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" + { + "_id": 31, + "type": "TERM", + "loc": 182, + "token": { + "type": "numliteral", + "value": "2", + "start": 182, + "end": 182 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, - "resultantType": { + { + "_id": 32, + "type": "TERM", + "loc": 185, + "token": { + "type": "numliteral", + "value": "3", + "start": 185, + "end": 185 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 33, + "type": "TERM", + "loc": 188, + "token": { + "type": "numliteral", + "value": "4", + "start": 188, + "end": 188 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 34, + "type": "TERM", + "loc": 191, + "token": { + "type": "numliteral", + "value": "5", + "start": 191, + "end": 191 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + ], + "resultantType": { + "kind": "List", + "name": "Numbers", + "elementType": { "kind": "PrimitiveOrAlias", - "typeString": "bool" + "typeString": "int" } } - ], - "gomType": { - "kind": "Tuple", - "fields": {} }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "void" } } - } - ], - "resultantType": { - "kind": "Function", - "args": [ - { - "kind": "PrimitiveOrAlias", - "typeString": "str" - } - ], - "returnType": { - "kind": "Tuple", - "fields": {} - } - } - }, - { - "type": "FUNCTION_DEFINITION", - "loc": 201, - "name": { - "type": "identifier", - "value": "process_http_retry", - "start": 204, - "end": 221 + ] }, - "args": [ - { - "type": "ARGUMENT_ITEM", - "loc": 223, - "name": { - "type": "TERM", - "loc": 223, - "token": { - "type": "identifier", - "value": "url", - "start": 223, - "end": 225 + { + "_id": 41, + "type": "LET_STATEMENT", + "loc": 199, + "decls": [ + { + "_id": 40, + "type": "ASSIGNMENT", + "loc": 203, + "lhs": { + "_id": 38, + "type": "TERM", + "loc": 203, + "token": { + "type": "identifier", + "value": "i", + "start": 203, + "end": 203 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@i" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@url" + "rhs": { + "_id": 39, + "type": "TERM", + "loc": 207, + "token": { + "type": "numliteral", + "value": "0", + "start": 207, + "end": 207 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@url" + "typeString": "void" } + } + ] + }, + { + "_id": 64, + "type": "FOR_STATEMENT", + "loc": 212, + "initExpr": { + "_id": 42, + "type": "TERM", + "loc": 216, + "token": { + "type": "identifier", + "value": "i", + "start": 216, + "end": 216 }, - "expectedType": { - "type": "TERM", - "loc": 228, - "token": { - "type": "built_in_type", - "value": "str", - "start": 228, - "end": 230 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - } + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@i" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "resolve_type@@i" } }, - { - "type": "ARGUMENT_ITEM", - "loc": 233, - "name": { + "conditionExpr": { + "_id": 47, + "type": "COMPARISON", + "loc": 219, + "lhs": { + "_id": 43, "type": "TERM", - "loc": 233, + "loc": 219, "token": { "type": "identifier", - "value": "retries", - "start": 233, - "end": 239 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@retries" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@retries" - } - }, - "expectedType": { - "type": "TERM", - "loc": 242, - "token": { - "type": "built_in_type", - "value": "int", - "start": 242, - "end": 244 + "value": "i", + "start": 219, + "end": 219 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "int" + "typeString": "resolve_type@@i" }, "resultantType": { "kind": "PrimitiveOrAlias", "typeString": "int" } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - } - ], - "returnType": { - "type": "FUNCTION_RETURN_TYPE", - "loc": 246, - "returnType": { - "type": "GOM_TYPE_ID", - "loc": 248, - "id": { - "type": "TERM", - "loc": 248, - "token": { - "type": "identifier", - "value": "HttpResponse", - "start": 248, - "end": 259 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" - } + "op": { + "type": "<", + "value": "<", + "start": 221, + "end": 221 }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@HttpResponse" - } - } - }, - "body": [ - { - "type": "LET_STATEMENT", - "loc": 265, - "decls": [ - { - "type": "ASSIGNMENT", - "loc": 269, - "lhs": { - "type": "TERM", - "loc": 269, - "token": { - "type": "identifier", - "value": "i", - "start": 269, - "end": 269 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - "rhs": { - "type": "TERM", - "loc": 273, - "token": { - "type": "numliteral", - "value": "0", - "start": 273, - "end": 273 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" - } - } - ] - }, - { - "type": "FOR_STATEMENT", - "loc": 278, - "initExpr": { - "type": "ASSIGNMENT", - "loc": 282, + "rhs": { + "_id": 46, + "type": "ACCESS", + "loc": 223, "lhs": { + "_id": 44, "type": "TERM", - "loc": 282, + "loc": 223, "token": { "type": "identifier", - "value": "i", - "start": 282, - "end": 282 + "value": "numbers", + "start": 223, + "end": 229 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" + "typeString": "resolve_type@@numbers" }, "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" + "kind": "List", + "name": "Numbers", + "elementType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } } }, "rhs": { + "_id": 45, "type": "TERM", - "loc": 286, + "loc": 231, "token": { "type": "identifier", - "value": "retries", - "start": 286, - "end": 292 + "value": "size", + "start": 231, + "end": 234 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@retries" + "typeString": "resolve_type@@size" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@retries" + "typeString": "int" } }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "void" + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } + }, + "updateExpr": { + "_id": 52, + "type": "ASSIGNMENT", + "loc": 237, + "lhs": { + "_id": 48, + "type": "TERM", + "loc": 237, + "token": { + "type": "identifier", + "value": "i", + "start": 237, + "end": 237 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@i" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@i" } }, - "conditionExpr": { - "type": "COMPARISON", - "loc": 295, + "rhs": { + "_id": 51, + "type": "SUM", + "loc": 241, "lhs": { + "_id": 49, "type": "TERM", - "loc": 295, + "loc": 241, "token": { "type": "identifier", "value": "i", - "start": 295, - "end": 295 + "start": 241, + "end": 241 }, "gomType": { "kind": "PrimitiveOrAlias", @@ -623,19 +751,20 @@ } }, "op": { - "type": ">", - "value": ">", - "start": 297, - "end": 297 + "type": "+", + "value": "+", + "start": 243, + "end": 243 }, "rhs": { + "_id": 50, "type": "TERM", - "loc": 299, + "loc": 245, "token": { "type": "numliteral", - "value": "0", - "start": 299, - "end": 299 + "value": "1", + "start": 245, + "end": 245 }, "gomType": { "kind": "PrimitiveOrAlias", @@ -648,217 +777,298 @@ }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "bool" + "typeString": "int" } }, - "updateExpr": { - "type": "ASSIGNMENT", - "loc": 302, - "lhs": { - "type": "TERM", - "loc": 302, - "token": { - "type": "identifier", - "value": "i", - "start": 302, - "end": 302 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" - } - }, - "rhs": { - "type": "SUM", - "loc": 306, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + }, + "body": [ + { + "_id": 63, + "type": "EXPRESSION_STATEMENT", + "loc": 254, + "expr": { + "_id": 62, + "type": "ACCESS", + "loc": 254, "lhs": { + "_id": 53, "type": "TERM", - "loc": 306, + "loc": 254, "token": { "type": "identifier", - "value": "i", - "start": 306, - "end": 306 + "value": "io", + "start": 254, + "end": 255 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" + "typeString": "resolve_type@@io" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "int" + "typeString": "resolve_type@@io" } }, - "op": { - "type": "-", - "value": "-", - "start": 308, - "end": 308 - }, "rhs": { - "type": "TERM", - "loc": 310, - "token": { - "type": "numliteral", - "value": "1", - "start": 310, - "end": 310 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" - } - }, - "body": [ - { - "type": "EXPRESSION_STATEMENT", - "loc": 319, - "expr": { - "type": "ACCESS", - "loc": 319, - "lhs": { + "_id": 61, + "type": "CALL", + "loc": 257, + "id": { + "_id": 54, "type": "TERM", - "loc": 319, + "loc": 257, "token": { "type": "identifier", - "value": "io", - "start": 319, - "end": 320 + "value": "log", + "start": 257, + "end": 259 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@io" + "typeString": "resolve_type@@log" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@io" + "typeString": "resolve_type@@log" } }, - "rhs": { - "type": "CALL", - "loc": 322, - "id": { + "args": [ + { + "_id": 55, + "type": "TERM", + "loc": 261, + "token": { + "type": "strliteral", + "value": "\"numbers[\"", + "start": 261, + "end": 270 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 56, "type": "TERM", - "loc": 322, + "loc": 273, "token": { "type": "identifier", - "value": "log", - "start": 322, - "end": 324 + "value": "i", + "start": 273, + "end": 273 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@log" + "typeString": "resolve_type@@i" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@log" + "typeString": "int" } }, - "args": [ - { + { + "_id": 57, + "type": "TERM", + "loc": 276, + "token": { + "type": "strliteral", + "value": "\"] = \"", + "start": 276, + "end": 281 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 60, + "type": "ACCESS", + "loc": 284, + "lhs": { + "_id": 58, + "type": "TERM", + "loc": 284, + "token": { + "type": "identifier", + "value": "numbers", + "start": 284, + "end": 290 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@numbers" + }, + "resultantType": { + "kind": "List", + "name": "Numbers", + "elementType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + }, + "rhs": { + "_id": 59, "type": "TERM", - "loc": 326, + "loc": 292, "token": { - "type": "strliteral", - "value": "\"Round: \"", - "start": 326, - "end": 334 + "type": "identifier", + "value": "i", + "start": 292, + "end": 292 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "resolve_type@@i" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "resolve_type@@i" } }, - { - "type": "SUM", - "loc": 337, - "lhs": { - "type": "SUM", - "loc": 337, - "lhs": { - "type": "TERM", - "loc": 337, - "token": { - "type": "identifier", - "value": "retries", - "start": 337, - "end": 343 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@retries" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - "op": { - "type": "-", - "value": "-", - "start": 345, - "end": 345 + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + ], + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + } + } + ] + }, + { + "_id": 87, + "type": "LET_STATEMENT", + "loc": 303, + "decls": [ + { + "_id": 86, + "type": "ASSIGNMENT", + "loc": 307, + "lhs": { + "_id": 65, + "type": "TERM", + "loc": 307, + "token": { + "type": "identifier", + "value": "statusList", + "start": 307, + "end": 316 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@statusList" + }, + "resultantType": { + "kind": "List", + "name": "StatusList", + "elementType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + } + }, + "rhs": { + "_id": 85, + "type": "COLLECTION_INIT", + "loc": 320, + "collectionTypeName": { + "_id": 66, + "type": "TERM", + "loc": 320, + "token": { + "type": "identifier", + "value": "StatusList", + "start": 320, + "end": 329 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@StatusList" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@StatusList" + } + }, + "elements": [ + { + "_id": 72, + "type": "STRUCT_INIT", + "loc": 337, + "structTypeName": { + "_id": 67, + "type": "TERM", + "loc": 337, + "token": { + "type": "identifier", + "value": "Status", + "start": 337, + "end": 342 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Status" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Status" + } + }, + "fields": [ + [ + { + "_id": 68, + "type": "TERM", + "loc": 346, + "token": { + "type": "identifier", + "value": "code", + "start": 346, + "end": 349 }, - "rhs": { - "type": "TERM", - "loc": 347, - "token": { - "type": "identifier", - "value": "i", - "start": 347, - "end": 347 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@i" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@code" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "int" + "typeString": "resolve_type@@code" } }, - "op": { - "type": "+", - "value": "+", - "start": 349, - "end": 349 - }, - "rhs": { + { + "_id": 69, "type": "TERM", - "loc": 351, + "loc": 352, "token": { "type": "numliteral", - "value": "1", - "start": 351, - "end": 351 + "value": "200", + "start": 352, + "end": 354 }, "gomType": { "kind": "PrimitiveOrAlias", @@ -868,438 +1078,1489 @@ "kind": "PrimitiveOrAlias", "typeString": "int" } + } + ], + [ + { + "_id": 70, + "type": "TERM", + "loc": 357, + "token": { + "type": "identifier", + "value": "success", + "start": 357, + "end": 363 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" + { + "_id": 71, + "type": "TERM", + "loc": 366, + "token": { + "type": "true", + "value": "true", + "start": 366, + "end": 369 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } } - } + ] ], "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" + "kind": "Struct", + "name": "Status", + "fields": {} } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" - } - } - }, - { - "type": "LET_STATEMENT", - "loc": 359, - "decls": [ { - "type": "ASSIGNMENT", - "loc": 363, - "lhs": { + "_id": 78, + "type": "STRUCT_INIT", + "loc": 378, + "structTypeName": { + "_id": 73, "type": "TERM", - "loc": 363, + "loc": 378, "token": { "type": "identifier", - "value": "resp", - "start": 363, - "end": 366 + "value": "Status", + "start": 378, + "end": 383 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@resp" + "typeString": "resolve_type@@Status" }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Status" } }, - "rhs": { - "type": "CALL", - "loc": 370, - "id": { - "type": "TERM", - "loc": 370, - "token": { - "type": "identifier", - "value": "process_http", - "start": 370, - "end": 381 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@process_http" + "fields": [ + [ + { + "_id": 74, + "type": "TERM", + "loc": 387, + "token": { + "type": "identifier", + "value": "code", + "start": 387, + "end": 390 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@code" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@code" + } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@process_http" + { + "_id": 75, + "type": "TERM", + "loc": 393, + "token": { + "type": "numliteral", + "value": "404", + "start": 393, + "end": 395 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } } - }, - "args": [ + ], + [ { + "_id": 76, "type": "TERM", - "loc": 383, + "loc": 398, "token": { "type": "identifier", - "value": "url", - "start": 383, - "end": 385 + "value": "success", + "start": 398, + "end": 404 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + } + }, + { + "_id": 77, + "type": "TERM", + "loc": 407, + "token": { + "type": "false", + "value": "false", + "start": 407, + "end": 411 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@url" + "typeString": "bool" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "bool" } } - ], - "resultantType": { - "kind": "Tuple", - "fields": {} - } - }, + ] + ], "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" + "kind": "Struct", + "name": "Status", + "fields": {} } - } - ] - }, - { - "type": "IF_STATEMENT", - "loc": 393, - "conditionExpr": { - "type": "EXPR_BRACKETED", - "loc": 395, - "expr": { - "type": "ACCESS", - "loc": 396, - "lhs": { + }, + { + "_id": 84, + "type": "STRUCT_INIT", + "loc": 420, + "structTypeName": { + "_id": 79, "type": "TERM", - "loc": 396, + "loc": 420, "token": { "type": "identifier", - "value": "resp", - "start": 396, - "end": 399 + "value": "Status", + "start": 420, + "end": 425 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@resp" + "typeString": "resolve_type@@Status" }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Status" + } + }, + "fields": [ + [ + { + "_id": 80, + "type": "TERM", + "loc": 429, + "token": { + "type": "identifier", + "value": "code", + "start": 429, + "end": 432 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@code" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@code" + } + }, + { + "_id": 81, + "type": "TERM", + "loc": 435, + "token": { + "type": "numliteral", + "value": "500", + "start": 435, + "end": 437 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + ], + [ + { + "_id": 82, + "type": "TERM", + "loc": 440, + "token": { + "type": "identifier", + "value": "success", + "start": 440, + "end": 446 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + } + }, + { + "_id": 83, + "type": "TERM", + "loc": 449, + "token": { + "type": "false", + "value": "false", + "start": 449, + "end": 453 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } + } + ] + ], + "resultantType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + } + ], + "resultantType": { + "kind": "List", + "name": "StatusList", + "elementType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + } + ] + }, + { + "_id": 91, + "type": "LET_STATEMENT", + "loc": 465, + "decls": [ + { + "_id": 90, + "type": "ASSIGNMENT", + "loc": 469, + "lhs": { + "_id": 88, + "type": "TERM", + "loc": 469, + "token": { + "type": "identifier", + "value": "j", + "start": 469, + "end": 469 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "rhs": { + "_id": 89, + "type": "TERM", + "loc": 473, + "token": { + "type": "numliteral", + "value": "0", + "start": 473, + "end": 473 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + } + ] + }, + { + "_id": 125, + "type": "FOR_STATEMENT", + "loc": 478, + "initExpr": { + "_id": 92, + "type": "TERM", + "loc": 482, + "token": { + "type": "identifier", + "value": "j", + "start": 482, + "end": 482 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + } + }, + "conditionExpr": { + "_id": 97, + "type": "COMPARISON", + "loc": 485, + "lhs": { + "_id": 93, + "type": "TERM", + "loc": 485, + "token": { + "type": "identifier", + "value": "j", + "start": 485, + "end": 485 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "op": { + "type": "<", + "value": "<", + "start": 487, + "end": 487 + }, + "rhs": { + "_id": 96, + "type": "ACCESS", + "loc": 489, + "lhs": { + "_id": 94, + "type": "TERM", + "loc": 489, + "token": { + "type": "identifier", + "value": "statusList", + "start": 489, + "end": 498 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@statusList" + }, + "resultantType": { + "kind": "List", + "name": "StatusList", + "elementType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + } + }, + "rhs": { + "_id": 95, + "type": "TERM", + "loc": 500, + "token": { + "type": "identifier", + "value": "size", + "start": 500, + "end": 503 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@size" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } + }, + "updateExpr": { + "_id": 102, + "type": "ASSIGNMENT", + "loc": 506, + "lhs": { + "_id": 98, + "type": "TERM", + "loc": 506, + "token": { + "type": "identifier", + "value": "j", + "start": 506, + "end": 506 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + } + }, + "rhs": { + "_id": 101, + "type": "SUM", + "loc": 510, + "lhs": { + "_id": 99, + "type": "TERM", + "loc": 510, + "token": { + "type": "identifier", + "value": "j", + "start": 510, + "end": 510 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "op": { + "type": "+", + "value": "+", + "start": 512, + "end": 512 + }, + "rhs": { + "_id": 100, + "type": "TERM", + "loc": 514, + "token": { + "type": "numliteral", + "value": "1", + "start": 514, + "end": 514 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + }, + "body": [ + { + "_id": 108, + "type": "LET_STATEMENT", + "loc": 523, + "decls": [ + { + "_id": 107, + "type": "ASSIGNMENT", + "loc": 527, + "lhs": { + "_id": 103, + "type": "TERM", + "loc": 527, + "token": { + "type": "identifier", + "value": "status", + "start": 527, + "end": 532 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@status" + }, + "resultantType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + }, + "rhs": { + "_id": 106, + "type": "ACCESS", + "loc": 536, + "lhs": { + "_id": 104, + "type": "TERM", + "loc": 536, + "token": { + "type": "identifier", + "value": "statusList", + "start": 536, + "end": 545 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@statusList" + }, + "resultantType": { + "kind": "List", + "name": "StatusList", + "elementType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + } + }, + "rhs": { + "_id": 105, + "type": "TERM", + "loc": 547, + "token": { + "type": "identifier", + "value": "j", + "start": 547, + "end": 547 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + } + }, + "resultantType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + } + ] + }, + { + "_id": 124, + "type": "EXPRESSION_STATEMENT", + "loc": 554, + "expr": { + "_id": 123, + "type": "ACCESS", + "loc": 554, + "lhs": { + "_id": 109, + "type": "TERM", + "loc": 554, + "token": { + "type": "identifier", + "value": "io", + "start": 554, + "end": 555 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@io" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@io" + } + }, + "rhs": { + "_id": 122, + "type": "CALL", + "loc": 557, + "id": { + "_id": 110, + "type": "TERM", + "loc": 557, + "token": { + "type": "identifier", + "value": "log", + "start": 557, + "end": 559 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@log" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@log" + } + }, + "args": [ + { + "_id": 111, + "type": "TERM", + "loc": 561, + "token": { + "type": "strliteral", + "value": "\"statusList[\"", + "start": 561, + "end": 573 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 112, + "type": "TERM", + "loc": 576, + "token": { + "type": "identifier", + "value": "j", + "start": 576, + "end": 576 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@j" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 113, + "type": "TERM", + "loc": 579, + "token": { + "type": "strliteral", + "value": "\"] = { code: \"", + "start": 579, + "end": 592 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 116, + "type": "ACCESS", + "loc": 595, + "lhs": { + "_id": 114, + "type": "TERM", + "loc": 595, + "token": { + "type": "identifier", + "value": "status", + "start": 595, + "end": 600 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@status" + }, + "resultantType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + }, + "rhs": { + "_id": 115, + "type": "TERM", + "loc": 602, + "token": { + "type": "identifier", + "value": "code", + "start": 602, + "end": 605 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@code" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 117, + "type": "TERM", + "loc": 608, + "token": { + "type": "strliteral", + "value": "\", success: \"", + "start": 608, + "end": 620 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 120, + "type": "ACCESS", + "loc": 623, + "lhs": { + "_id": 118, + "type": "TERM", + "loc": 623, + "token": { + "type": "identifier", + "value": "status", + "start": 623, + "end": 628 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@status" + }, + "resultantType": { + "kind": "Struct", + "name": "Status", + "fields": {} + } + }, + "rhs": { + "_id": 119, + "type": "TERM", + "loc": 630, + "token": { + "type": "identifier", + "value": "success", + "start": 630, + "end": 636 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@success" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" + } + }, + { + "_id": 121, + "type": "TERM", + "loc": 639, + "token": { + "type": "strliteral", + "value": "\" }\"", + "start": 639, + "end": 642 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + } + ], + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + } + } + ] + }, + { + "_id": 145, + "type": "LET_STATEMENT", + "loc": 653, + "decls": [ + { + "_id": 144, + "type": "ASSIGNMENT", + "loc": 657, + "lhs": { + "_id": 126, + "type": "TERM", + "loc": 657, + "token": { + "type": "identifier", + "value": "pairs", + "start": 657, + "end": 661 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@pairs" + }, + "resultantType": { + "kind": "List", + "name": "Pairs", + "elementType": { + "kind": "Tuple", + "fields": {} + } + } + }, + "rhs": { + "_id": 143, + "type": "COLLECTION_INIT", + "loc": 665, + "collectionTypeName": { + "_id": 127, + "type": "TERM", + "loc": 665, + "token": { + "type": "identifier", + "value": "Pairs", + "start": 665, + "end": 669 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Pairs" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@Pairs" + } + }, + "elements": [ + { + "_id": 130, + "type": "TUPLE_LITERAL", + "loc": 677, + "elements": [ + { + "_id": 128, + "type": "TERM", + "loc": 679, + "token": { + "type": "numliteral", + "value": "1", + "start": 679, + "end": 679 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 129, + "type": "TERM", + "loc": 682, + "token": { + "type": "numliteral", + "value": "2", + "start": 682, + "end": 682 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + ], + "gomType": { + "kind": "Tuple", + "fields": {} + }, + "resultantType": { + "kind": "Tuple", + "fields": {} + } + }, + { + "_id": 133, + "type": "TUPLE_LITERAL", + "loc": 691, + "elements": [ + { + "_id": 131, + "type": "TERM", + "loc": 693, + "token": { + "type": "numliteral", + "value": "3", + "start": 693, + "end": 693 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 132, + "type": "TERM", + "loc": 696, + "token": { + "type": "numliteral", + "value": "4", + "start": 696, + "end": 696 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + } + ], + "gomType": { + "kind": "Tuple", + "fields": {} + }, + "resultantType": { + "kind": "Tuple", + "fields": {} + } + }, + { + "_id": 136, + "type": "TUPLE_LITERAL", + "loc": 705, + "elements": [ + { + "_id": 134, + "type": "TERM", + "loc": 707, + "token": { + "type": "numliteral", + "value": "5", + "start": 707, + "end": 707 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 135, + "type": "TERM", + "loc": 710, + "token": { + "type": "numliteral", + "value": "6", + "start": 710, + "end": 710 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } } + ], + "gomType": { + "kind": "Tuple", + "fields": {} }, - "rhs": { - "type": "TERM", - "loc": 401, - "token": { - "type": "numliteral", - "value": "1", - "start": 401, - "end": 401 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" + "resultantType": { + "kind": "Tuple", + "fields": {} + } + }, + { + "_id": 139, + "type": "TUPLE_LITERAL", + "loc": 719, + "elements": [ + { + "_id": 137, + "type": "TERM", + "loc": 721, + "token": { + "type": "numliteral", + "value": "7", + "start": 721, + "end": 721 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" + { + "_id": 138, + "type": "TERM", + "loc": 724, + "token": { + "type": "numliteral", + "value": "8", + "start": 724, + "end": 724 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } } + ], + "gomType": { + "kind": "Tuple", + "fields": {} }, "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" + "kind": "Tuple", + "fields": {} } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" - } - }, - "body": [ { - "type": "RETURN_STATEMENT", - "loc": 412, - "expr": { - "type": "TERM", - "loc": 419, - "token": { - "type": "identifier", - "value": "resp", - "start": 419, - "end": 422 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@resp" + "_id": 142, + "type": "TUPLE_LITERAL", + "loc": 733, + "elements": [ + { + "_id": 140, + "type": "TERM", + "loc": 735, + "token": { + "type": "numliteral", + "value": "9", + "start": 735, + "end": 735 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, - "resultantType": { - "kind": "Tuple", - "fields": {} + { + "_id": 141, + "type": "TERM", + "loc": 738, + "token": { + "type": "numliteral", + "value": "10", + "start": 738, + "end": 739 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } } + ], + "gomType": { + "kind": "Tuple", + "fields": {} + }, + "resultantType": { + "kind": "Tuple", + "fields": {} } } - ] - } - ] - }, - { - "type": "RETURN_STATEMENT", - "loc": 438, - "expr": { - "type": "TUPLE_LITERAL", - "loc": 445, - "elements": [ - { - "type": "TERM", - "loc": 447, - "token": { - "type": "numliteral", - "value": "500", - "start": 447, - "end": 449 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - }, - { - "type": "TERM", - "loc": 452, - "token": { - "type": "false", - "value": "false", - "start": 452, - "end": 456 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" + ], + "resultantType": { + "kind": "List", + "name": "Pairs", + "elementType": { + "kind": "Tuple", + "fields": {} } } - ], - "gomType": { - "kind": "Tuple", - "fields": {} }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "void" } } - } - ], - "resultantType": { - "kind": "Function", - "args": [ - { - "kind": "PrimitiveOrAlias", - "typeString": "str" - }, - { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } - ], - "returnType": { - "kind": "Tuple", - "fields": {} - } - } - } - ], - "exportStatements": [], - "mainFunction": { - "type": "MAIN_FUNCTION", - "loc": 467, - "body": [ + ] + }, { + "_id": 149, "type": "LET_STATEMENT", - "loc": 478, + "loc": 751, "decls": [ { + "_id": 148, "type": "ASSIGNMENT", - "loc": 482, + "loc": 755, "lhs": { + "_id": 146, "type": "TERM", - "loc": 482, + "loc": 755, "token": { "type": "identifier", - "value": "resp", - "start": 482, - "end": 485 + "value": "k", + "start": 755, + "end": 755 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@resp" + "typeString": "resolve_type@@k" }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "int" } }, "rhs": { - "type": "CALL", - "loc": 489, - "id": { - "type": "TERM", - "loc": 489, - "token": { - "type": "identifier", - "value": "process_http_retry", - "start": 489, - "end": 506 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@process_http_retry" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@process_http_retry" - } + "_id": 147, + "type": "TERM", + "loc": 759, + "token": { + "type": "numliteral", + "value": "0", + "start": 759, + "end": 759 }, - "args": [ - { - "type": "TERM", - "loc": 508, - "token": { - "type": "strliteral", - "value": "\"http://www.example.com\"", - "start": 508, - "end": 531 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - } - }, - { - "type": "TERM", - "loc": 534, - "token": { - "type": "numliteral", - "value": "10", - "start": 534, - "end": 535 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" - } + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + } + ] + }, + { + "_id": 183, + "type": "FOR_STATEMENT", + "loc": 764, + "initExpr": { + "_id": 150, + "type": "TERM", + "loc": 768, + "token": { + "type": "identifier", + "value": "k", + "start": 768, + "end": 768 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@k" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@k" + } + }, + "conditionExpr": { + "_id": 155, + "type": "COMPARISON", + "loc": 771, + "lhs": { + "_id": 151, + "type": "TERM", + "loc": 771, + "token": { + "type": "identifier", + "value": "k", + "start": 771, + "end": 771 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@k" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "op": { + "type": "<", + "value": "<", + "start": 773, + "end": 773 + }, + "rhs": { + "_id": 154, + "type": "ACCESS", + "loc": 775, + "lhs": { + "_id": 152, + "type": "TERM", + "loc": 775, + "token": { + "type": "identifier", + "value": "pairs", + "start": 775, + "end": 779 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@pairs" + }, + "resultantType": { + "kind": "List", + "name": "Pairs", + "elementType": { + "kind": "Tuple", + "fields": {} } - ], + } + }, + "rhs": { + "_id": 153, + "type": "TERM", + "loc": 781, + "token": { + "type": "identifier", + "value": "size", + "start": 781, + "end": 784 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@size" + }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "int" } }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "void" + "typeString": "int" } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "bool" } - ] - }, - { - "type": "EXPRESSION_STATEMENT", - "loc": 541, - "expr": { - "type": "ACCESS", - "loc": 541, + }, + "updateExpr": { + "_id": 160, + "type": "ASSIGNMENT", + "loc": 787, "lhs": { + "_id": 156, "type": "TERM", - "loc": 541, + "loc": 787, "token": { "type": "identifier", - "value": "io", - "start": 541, - "end": 542 + "value": "k", + "start": 787, + "end": 787 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@io" + "typeString": "resolve_type@@k" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@io" + "typeString": "resolve_type@@k" } }, "rhs": { - "type": "CALL", - "loc": 544, - "id": { + "_id": 159, + "type": "SUM", + "loc": 791, + "lhs": { + "_id": 157, "type": "TERM", - "loc": 544, + "loc": 791, "token": { "type": "identifier", - "value": "log", - "start": 544, - "end": 546 + "value": "k", + "start": 791, + "end": 791 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@log" + "typeString": "resolve_type@@k" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@log" + "typeString": "int" } }, - "args": [ - { - "type": "TERM", - "loc": 548, - "token": { - "type": "strliteral", - "value": "\"Status: \"", - "start": 548, - "end": 557 - }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "str" - } + "op": { + "type": "+", + "value": "+", + "start": 793, + "end": 793 + }, + "rhs": { + "_id": 158, + "type": "TERM", + "loc": 795, + "token": { + "type": "numliteral", + "value": "1", + "start": 795, + "end": 795 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" + } + }, + "body": [ + { + "_id": 166, + "type": "LET_STATEMENT", + "loc": 804, + "decls": [ { - "type": "ACCESS", - "loc": 560, + "_id": 165, + "type": "ASSIGNMENT", + "loc": 808, "lhs": { + "_id": 161, "type": "TERM", - "loc": 560, + "loc": 808, "token": { "type": "identifier", - "value": "resp", - "start": 560, - "end": 563 + "value": "pair", + "start": 808, + "end": 811 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@resp" + "typeString": "resolve_type@@pair" }, "resultantType": { "kind": "Tuple", @@ -1307,101 +2568,316 @@ } }, "rhs": { - "type": "TERM", - "loc": 565, - "token": { - "type": "numliteral", - "value": "0", - "start": 565, - "end": 565 + "_id": 164, + "type": "ACCESS", + "loc": 815, + "lhs": { + "_id": 162, + "type": "TERM", + "loc": 815, + "token": { + "type": "identifier", + "value": "pairs", + "start": 815, + "end": 819 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@pairs" + }, + "resultantType": { + "kind": "List", + "name": "Pairs", + "elementType": { + "kind": "Tuple", + "fields": {} + } + } }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" + "rhs": { + "_id": 163, + "type": "TERM", + "loc": 821, + "token": { + "type": "identifier", + "value": "k", + "start": 821, + "end": 821 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@k" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@k" + } }, "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" + "kind": "Tuple", + "fields": {} } }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "int" + "typeString": "void" } - }, - { + } + ] + }, + { + "_id": 182, + "type": "EXPRESSION_STATEMENT", + "loc": 828, + "expr": { + "_id": 181, + "type": "ACCESS", + "loc": 828, + "lhs": { + "_id": 167, "type": "TERM", - "loc": 568, + "loc": 828, "token": { - "type": "strliteral", - "value": "\" Success: \"", - "start": 568, - "end": 579 + "type": "identifier", + "value": "io", + "start": 828, + "end": 829 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "resolve_type@@io" }, "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "str" + "typeString": "resolve_type@@io" } }, - { - "type": "ACCESS", - "loc": 582, - "lhs": { + "rhs": { + "_id": 180, + "type": "CALL", + "loc": 831, + "id": { + "_id": 168, "type": "TERM", - "loc": 582, + "loc": 831, "token": { "type": "identifier", - "value": "resp", - "start": 582, - "end": 585 + "value": "log", + "start": 831, + "end": 833 }, "gomType": { "kind": "PrimitiveOrAlias", - "typeString": "resolve_type@@resp" + "typeString": "resolve_type@@log" }, "resultantType": { - "kind": "Tuple", - "fields": {} + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@log" } }, - "rhs": { - "type": "TERM", - "loc": 587, - "token": { - "type": "numliteral", - "value": "1", - "start": 587, - "end": 587 + "args": [ + { + "_id": 169, + "type": "TERM", + "loc": 835, + "token": { + "type": "strliteral", + "value": "\"pairs[\"", + "start": 835, + "end": 842 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } }, - "gomType": { - "kind": "PrimitiveOrAlias", - "typeString": "int" + { + "_id": 170, + "type": "TERM", + "loc": 845, + "token": { + "type": "identifier", + "value": "k", + "start": 845, + "end": 845 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@k" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "bool" + { + "_id": 171, + "type": "TERM", + "loc": 848, + "token": { + "type": "strliteral", + "value": "\"] = { \"", + "start": 848, + "end": 855 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 174, + "type": "ACCESS", + "loc": 858, + "lhs": { + "_id": 172, + "type": "TERM", + "loc": 858, + "token": { + "type": "identifier", + "value": "pair", + "start": 858, + "end": 861 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@pair" + }, + "resultantType": { + "kind": "Tuple", + "fields": {} + } + }, + "rhs": { + "_id": 173, + "type": "TERM", + "loc": 863, + "token": { + "type": "numliteral", + "value": "0", + "start": 863, + "end": 863 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 175, + "type": "TERM", + "loc": 866, + "token": { + "type": "strliteral", + "value": "\", \"", + "start": 866, + "end": 869 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } + }, + { + "_id": 178, + "type": "ACCESS", + "loc": 872, + "lhs": { + "_id": 176, + "type": "TERM", + "loc": 872, + "token": { + "type": "identifier", + "value": "pair", + "start": 872, + "end": 875 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "resolve_type@@pair" + }, + "resultantType": { + "kind": "Tuple", + "fields": {} + } + }, + "rhs": { + "_id": 177, + "type": "TERM", + "loc": 877, + "token": { + "type": "numliteral", + "value": "1", + "start": 877, + "end": 877 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "int" + } + }, + { + "_id": 179, + "type": "TERM", + "loc": 880, + "token": { + "type": "strliteral", + "value": "\" }\"", + "start": 880, + "end": 883 + }, + "gomType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "str" + } } - }, + ], "resultantType": { "kind": "PrimitiveOrAlias", - "typeString": "bool" + "typeString": "void" } + }, + "resultantType": { + "kind": "PrimitiveOrAlias", + "typeString": "void" } - ], - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" } - }, - "resultantType": { - "kind": "PrimitiveOrAlias", - "typeString": "void" } - } + ] } ] }