Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored Statements and Expressions
This should hopefully make these beasts more managable.
- Loading branch information
Showing
11 changed files
with
292 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,4 +1,4 @@ | |||
a = "Hello World\n" | a = "Hello World\n" | ||
puts a | puts a | ||
b = a | b = a | ||
puts b | puts b |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,126 @@ | |||
#include <assert.h> | |||
|
|||
#include "hkl_value.h" | |||
|
|||
HklValue* hklr_op_plus(HklValue* left_value, HklValue* right_value) | |||
{ | |||
HklValue* result = NULL; | |||
bool left_updated = false, right_updated = false; | |||
|
|||
// Dereference left and right sides | |||
if (left_value->type == HKL_TYPE_REF) | |||
{ | |||
left_updated = true; | |||
left_value = hklr_object_dereference(left_value->as.object); | |||
} | |||
|
|||
if (right_value->type == HKL_TYPE_REF) | |||
{ | |||
right_updated = true; | |||
right_value = hklr_object_dereference(right_value->as.object); | |||
} | |||
|
|||
switch (left_value->type) | |||
{ | |||
case HKL_TYPE_INT: | |||
switch(right_value->type) | |||
{ | |||
case HKL_TYPE_INT: | |||
result = hkl_value_new(HKL_TYPE_INT, | |||
left_value->as.integer + right_value->as.integer); | |||
break; | |||
|
|||
case HKL_TYPE_REAL: | |||
result = hkl_value_new(HKL_TYPE_REAL, | |||
left_value->as.integer + right_value->as.real); | |||
break; | |||
|
|||
case HKL_TYPE_STRING: | |||
assert(false); | |||
break; | |||
|
|||
default: | |||
assert(false); | |||
break; | |||
} | |||
break; // HKL_TYPE_INT | |||
|
|||
case HKL_TYPE_REAL: | |||
switch(right_value->type) | |||
{ | |||
case HKL_TYPE_INT: | |||
result = hkl_value_new(HKL_TYPE_REAL, | |||
left_value->as.real + right_value->as.integer); | |||
break; | |||
|
|||
case HKL_TYPE_REAL: | |||
result = hkl_value_new(HKL_TYPE_REAL, | |||
left_value->as.real + right_value->as.real); | |||
break; | |||
|
|||
case HKL_TYPE_STRING: | |||
assert(false); | |||
break; | |||
|
|||
default: | |||
assert(false); | |||
break; | |||
} | |||
break; // HKL_TYPE_REAL | |||
|
|||
case HKL_TYPE_STRING: | |||
switch(right_value->type) | |||
{ | |||
|
|||
case HKL_TYPE_INT: | |||
{ | |||
result = hkl_value_new(HKL_TYPE_STRING, | |||
hkl_string_new_from_string(left_value->as.string)); | |||
HklString* right_string = | |||
hkl_string_new_from_integer(right_value->as.integer); | |||
hkl_string_cat(result->as.string, right_string); | |||
hkl_string_free(right_string); | |||
} | |||
break; | |||
|
|||
case HKL_TYPE_REAL: | |||
{ | |||
result = hkl_value_new(HKL_TYPE_STRING, | |||
hkl_string_new_from_string(left_value->as.string)); | |||
HklString* right_string = | |||
hkl_string_new_from_real(right_value->as.real); | |||
hkl_string_cat(result->as.string, right_string); | |||
hkl_string_free(right_string); | |||
} | |||
break; | |||
|
|||
case HKL_TYPE_STRING: | |||
result = hkl_value_new(HKL_TYPE_STRING, | |||
hkl_string_new_from_string(left_value->as.string)); | |||
|
|||
hkl_string_cat(result->as.string, right_value->as.string); | |||
break; | |||
|
|||
default: | |||
assert(false); | |||
break; | |||
} | |||
break; // HKL_TYPE_STRING | |||
|
|||
default: | |||
assert(false); | |||
break; | |||
} | |||
|
|||
if (left_updated) | |||
{ | |||
hkl_value_free(left_value); | |||
} | |||
|
|||
if (right_updated) | |||
{ | |||
hkl_value_free(right_value); | |||
} | |||
|
|||
return result; | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.