diff --git a/lang/boolean.c b/lang/boolean.c index abde3be..0d1a027 100644 --- a/lang/boolean.c +++ b/lang/boolean.c @@ -42,8 +42,22 @@ vm_stack_set(state, 0, boolean_create(state, invert)); } +static void boolean_and(VmState state, Object obj, int priv) { + (void)priv; + int arg_count = vm_stack_depth(state); + vm_abort_if(state, arg_count != 2, "boolean_and requires one argument"); + Object arg = vm_stack_pop(state); + bool value1 = boolean_value(state, obj); + bool value2 = boolean_value(state, arg); + bool anded = value1 && value2; + Object new = boolean_create(state, anded); + vm_stack_set(state, 0, new); + object_drop(state, &arg); +} + static struct object_call calls[] = { {.name = "Invert", .handler = boolean_invert, .priv = 0}, + {.name = "And", .handler = boolean_and, .priv = 0}, {.name = NULL, /* end */}}; static struct object_class boolean_class = { diff --git a/lang/modules/main.txt b/lang/modules/main.txt index aef6c5c..c2ed0d7 100644 --- a/lang/modules/main.txt +++ b/lang/modules/main.txt @@ -3,7 +3,9 @@ Public Class Main Function BoolTest Set A To True - Set B To A Invert + Set B To False + Set C To B Invert + Set D To A And C Return B EndFunction