This repository has been archived on 2026-05-18. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
piquant/tests/basic_solver.c

52 lines
1.6 KiB
C
Raw Permalink Normal View History

#include "types.h"
#include "basic.h"
#include "string.h"
#include <stdio.h>
int main(void)
{
basic_expr expr;
basic_variable result;
result.flags = 0;
expr.type = BASIC_OPTP_ADD;
expr.lval_type = BASIC_LVAL_CONST_INT;
expr.lval.i = 1;
expr.rval_type = BASIC_RVAL_CONST_INT;
expr.rval.i = 1;
basic_solve_expr(&expr, &result);
if ( basic_errno != 0 ) return 2;
if ( result.flags != (BASIC_VARFLAG_INIT | BASIC_VARFLAG_TINT) ) return 3;
if ( result.value.i != 2 ) return 4;
expr.type = BASIC_OPTP_NONE;
expr.lval_type = BASIC_LVAL_CONST_INT;
expr.lval.i = 1;
expr.rval_type = BASIC_RVAL_NONE;
memset(&result, 0x00, sizeof(basic_variable));
basic_solve_expr(&expr, &result);
if ( basic_errno != 0 ) return 5;
if ( result.flags != (BASIC_VARFLAG_INIT | BASIC_VARFLAG_TINT) ) return 6;
if ( result.value.i != 1 ) return 7;
expr.type = BASIC_OPTP_STOR;
expr.lval_type = BASIC_LVAL_CONST_INT;
expr.rval_type = BASIC_RVAL_PTR;
expr.lval.i = 10;
expr.rval.ptr = " REM ignore me";
memset(&result, 0x00, sizeof(basic_variable));
basic_solve_expr(&expr, &result);
if ( basic_errno != 0 ) return 8;
if ( result.flags != (BASIC_VARFLAG_INIT | BASIC_VARFLAG_TSTR) ) return 9;
if ( result.value.ptr == NULL ) return 10;
if ( basic_last_stored_lineno != 9 ) return 11;
printf("last stored line number: %d\n", basic_last_stored_lineno);
printf("stored memory line 10 equals: %s\n", basic_memory_line_address(basic_last_stored_lineno));
if ( strcmp(basic_memory_line_address(basic_last_stored_lineno), expr.rval.ptr) != 0 ) return 12;
return 0;
}