projects
/
fur
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c7f381f
)
Added booleans
author
David Kerkeslager
<kerkeslager@gmail.com>
Tue, 1 Oct 2019 05:34:04 +0000
(
01:34
-0400)
committer
David Kerkeslager
<kerkeslager@gmail.com>
Tue, 1 Oct 2019 05:34:04 +0000
(
01:34
-0400)
templates/program2.c
patch
|
blob
|
history
diff --git
a/templates/program2.c
b/templates/program2.c
index
8602054
..
1610a54
100644
(file)
--- a/
templates/program2.c
+++ b/
templates/program2.c
@@
-8,6
+8,7
@@
enum Type;
typedef enum Type Type;
enum Type {
enum Type;
typedef enum Type Type;
enum Type {
+ BOOLEAN,
BUILTIN,
INTEGER,
STRING
BUILTIN,
INTEGER,
STRING
@@
-25,6
+26,7
@@
union Value;
typedef union Value Value;
union Value {
Builtin builtin;
typedef union Value Value;
union Value {
Builtin builtin;
+ bool boolean;
char* string;
int32_t integer;
};
char* string;
int32_t integer;
};
@@
-111,6
+113,10
@@
void call(struct Thread* thread, Argument argument) {
Object arg = Stack_pop(&(thread->stack));
switch(arg.type) {
Object arg = Stack_pop(&(thread->stack));
switch(arg.type) {
+ case BOOLEAN:
+ if(arg.value.boolean) printf("true");
+ else printf("false");
+ break;
case INTEGER:
printf("%i", arg.value.integer);
break;
case INTEGER:
printf("%i", arg.value.integer);
break;
@@
-192,16
+198,20
@@
void pop(struct Thread* thread, Argument argument) {
void push(struct Thread* thread, Argument argument) {
char* argumentString = argument.string;
void push(struct Thread* thread, Argument argument) {
char* argumentString = argument.string;
- if(strcmp(argumentString, "print") == 0) {
+ if(strcmp(argumentString, "false") == 0) {
+ Stack_push(&(thread->stack), (Object){ BOOLEAN, false });
+ }else if(strcmp(argumentString, "pow") == 0) {
Object result;
result.type = BUILTIN;
Object result;
result.type = BUILTIN;
- result.value.builtin = P
RINT
;
+ result.value.builtin = P
OW
;
Stack_push(&(thread->stack), result);
Stack_push(&(thread->stack), result);
- } else if(strcmp(argumentString, "p
ow
") == 0) {
+ } else if(strcmp(argumentString, "p
rint
") == 0) {
Object result;
result.type = BUILTIN;
Object result;
result.type = BUILTIN;
- result.value.builtin = P
OW
;
+ result.value.builtin = P
RINT
;
Stack_push(&(thread->stack), result);
Stack_push(&(thread->stack), result);
+ } else if(strcmp(argumentString, "true") == 0) {
+ Stack_push(&(thread->stack), (Object){ BOOLEAN, true });
} else {
Environment_get_Result result = Environment_get(thread->environment, argumentString);
if(!result.found) {
} else {
Environment_get_Result result = Environment_get(thread->environment, argumentString);
if(!result.found) {