From 0e7430c86fbfe3cd3cd37ec97dace2d31ff99ea2 Mon Sep 17 00:00:00 2001
From: Daniel Olsson <danol716@student.liu.se>
Date: Fri, 11 Oct 2019 13:53:37 +0200
Subject: [PATCH] Finished the lab with the line number changes

---
 debugging/fileutil.cpp |  6 +++---
 debugging/workitems.c  |  4 +---
 julia/dowhile.jl       | 31 +++++++++++++------------------
 3 files changed, 17 insertions(+), 24 deletions(-)

diff --git a/debugging/fileutil.cpp b/debugging/fileutil.cpp
index b64a441..1997f8a 100644
--- a/debugging/fileutil.cpp
+++ b/debugging/fileutil.cpp
@@ -20,8 +20,8 @@ using namespace std;
 int main(int argc, char **argv)
 {
   int cur = 0;
-  char *lines[35000];
-  char line[700];
+  char *lines[16536];
+  char line[80];
   // Fix num lines, num columns, strdup-1
   FILE *fin = fopen("bible.txt", "r");
   if (fin==NULL){
@@ -30,7 +30,7 @@ int main(int argc, char **argv)
   }
   while (!feof(fin)) {
     getline(line, fin);
-    lines[cur] = (char*) malloc(strlen(line) + 1);
+    lines[cur] = (char*) malloc(strlen(line)+1);
     strcpy(lines[cur], line);
     cur++;
   }
diff --git a/debugging/workitems.c b/debugging/workitems.c
index d6237fc..6f8d1cb 100644
--- a/debugging/workitems.c
+++ b/debugging/workitems.c
@@ -24,7 +24,6 @@ static void* launchThread(void *in)
   while (1) {
     pthread_mutex_lock(&lock);
     n = data->current++;
-    //printf("%d\n",data->current);
     if (n >= data->len){
       pthread_mutex_unlock(&lock);
       break;
@@ -32,7 +31,6 @@ static void* launchThread(void *in)
     data->fn(&data->data[n]);
     pthread_mutex_unlock(&lock);
   }
-  //rintf("Jag är ute\n" );
   return NULL;
 }
 
@@ -79,7 +77,7 @@ int main(int argc, char **argv)
   for (int i=0; i<100; i++) {
     vals[i] = i*1.5;
   }
-  launchParallel(8 /* Increase this if no error occurs */, vals, 100, mul2);
+  launchParallel(4 /* Increase this if no error occurs */, vals, 100, mul2);
 
   for (int i=0; i<100; i++) {
     if (vals[i] != 1.5*2*i) {
diff --git a/julia/dowhile.jl b/julia/dowhile.jl
index e4df3f5..53867f6 100644
--- a/julia/dowhile.jl
+++ b/julia/dowhile.jl
@@ -1,21 +1,19 @@
 function adjustLines(res, macrofile, invokedFile, invokedLine )
-    sz =size(res.args)
-    dump(res)
-    temp = copy(res)
-    for i=1:sz[1]
-        if isa(temp.args[i], LineNumberNode)
-            if (String(temp.args[i].file) == macrofile)
-                file = temp.args[i].line = invokedLine
+    if(typeof(res) == Expr)
+        #Loop thorugh all args
+        for i = 1:size(res.args)[1]
+            #Check if is a LineNumberNode
+            if(typeof(res.args[i]) == LineNumberNode)
+                #Check if it is the macrofile and then change the file and line
+                #otherwise do nothing
+                if(String(res.args[i].file) == String(macrofile))
+                    res.args[i] = LineNumberNode(invokedLine, invokedFile)
+                end
+                #Recusive expression if res.args[i] is a Expr 
+            elseif(typeof(res) == Expr)
+                res.args[i] = adjustLines(res.args[i], macrofile, invokedFile, invokedLine)
             end
-
-            #println(i)
-            #println(res.args[i].file)
-        else
-            #println(i)
-            #println("Nej")
         end
-        #println(i)
-        #println(res.args[i].args)
     end
     return res
 end
@@ -24,8 +22,6 @@ macro doWhile(block, cond)
  # println("__source__ ", __source__)
   #println("cond ", cond)
   #println("block ", block)
-
-
   res = quote
     #error("TODO: Your code here")
     $(esc(block))
@@ -34,7 +30,6 @@ macro doWhile(block, cond)
     end
   end
   res = adjustLines(res,@__FILE__(), __source__.file, __source__.line)
-  println("Here is the whole")
   println(res) # Should not print any lines referencing dowhile.jl
   res
 end
-- 
GitLab