mirror of
https://gitee.com/Lyon1998/pikapython.git
synced 2025-02-05 17:28:23 +08:00
test stack for str is ok
This commit is contained in:
parent
46bf755673
commit
a119401b65
26
port/linux/test/stack-test.cpp
Normal file
26
port/linux/test/stack-test.cpp
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#include "gtest/gtest.h"
|
||||||
|
extern "C" {
|
||||||
|
#include "BaseObj.h"
|
||||||
|
#include "dataMemory.h"
|
||||||
|
#include "dataStack.h"
|
||||||
|
}
|
||||||
|
static int mem;
|
||||||
|
|
||||||
|
TEST(stack, NEW) {
|
||||||
|
Stack* s = New_Stack();
|
||||||
|
stack_deinit(s);
|
||||||
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(stack, str) {
|
||||||
|
Stack* s = New_Stack();
|
||||||
|
stack_pushStr(s, (char*)"abc");
|
||||||
|
stack_pushStr(s, (char*)"123");
|
||||||
|
stack_pushStr(s, (char*)"xyz");
|
||||||
|
char buff[32] = {0};
|
||||||
|
EXPECT_STREQ(stack_popStr(s, buff), (char*)"xyz");
|
||||||
|
EXPECT_STREQ(stack_popStr(s, buff), (char*)"123");
|
||||||
|
EXPECT_STREQ(stack_popStr(s, buff), (char*)"abc");
|
||||||
|
stack_deinit(s);
|
||||||
|
EXPECT_EQ(pikaMemNow(), 0);
|
||||||
|
}
|
@ -2,6 +2,7 @@
|
|||||||
#include "PikaObj.h"
|
#include "PikaObj.h"
|
||||||
#include "dataQueue.h"
|
#include "dataQueue.h"
|
||||||
#include "dataQueueObj.h"
|
#include "dataQueueObj.h"
|
||||||
|
#include "dataStack.h"
|
||||||
#include "dataStrs.h"
|
#include "dataStrs.h"
|
||||||
|
|
||||||
char* strsPopStmts(Args* buffs, char* stmts) {
|
char* strsPopStmts(Args* buffs, char* stmts) {
|
||||||
@ -138,7 +139,7 @@ static int32_t getPyLineBlockDeepth(char* line) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AST* pikaParseLine(char* line, Args* blockStack) {
|
AST* pikaParseLine(char* line, Stack* blockStack) {
|
||||||
AST* ast = New_queueObj();
|
AST* ast = New_queueObj();
|
||||||
Args* buffs = New_strBuff();
|
Args* buffs = New_strBuff();
|
||||||
uint8_t blockDeepth = getPyLineBlockDeepth(line);
|
uint8_t blockDeepth = getPyLineBlockDeepth(line);
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#ifndef __PIKA__PARSER__H
|
#ifndef __PIKA__PARSER__H
|
||||||
#define __PIKA__PARSER__H
|
#define __PIKA__PARSER__H
|
||||||
#include "dataQueueObj.h"
|
#include "dataQueueObj.h"
|
||||||
|
#include "dataStack.h"
|
||||||
|
|
||||||
typedef QueueObj AST;
|
typedef QueueObj AST;
|
||||||
AST* pikaParseLine(char* line, Args* blockStack);
|
AST* pikaParseLine(char* line, Stack* blockStack);
|
||||||
char* pikaParseToAsm(Args* buffs, char* line);
|
char* pikaParseToAsm(Args* buffs, char* line);
|
||||||
int32_t AST_deinit(AST* ast);
|
int32_t AST_deinit(AST* ast);
|
||||||
char* AST_toPikaAsm(AST* ast, Args* buffs);
|
char* AST_toPikaAsm(AST* ast, Args* buffs);
|
||||||
|
@ -1,15 +1,34 @@
|
|||||||
#include "dataQueue.h"
|
|
||||||
#include "dataStack.h"
|
#include "dataStack.h"
|
||||||
|
#include "dataQueue.h"
|
||||||
|
|
||||||
Stack* New_Stack(){
|
Stack* New_Stack() {
|
||||||
|
Args* args = New_args(NULL);
|
||||||
|
args_setInt(args, "top", 0);
|
||||||
|
Stack* stack = args;
|
||||||
|
return stack;
|
||||||
}
|
}
|
||||||
int32_t stack_deinit(Stack* stack){
|
int32_t stack_deinit(Stack* stack) {
|
||||||
|
Args* args = stack;
|
||||||
|
args_deinit(args);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
int32_t stack_pushStr(Stack* stack, char* str){
|
int32_t stack_pushStr(Stack* stack, char* str) {
|
||||||
|
Args* args = stack;
|
||||||
|
uint64_t top = args_getInt(args, "top");
|
||||||
|
char buff[11];
|
||||||
|
/* add top */
|
||||||
|
char* topStr = fast_itoa(buff, top);
|
||||||
|
args_setInt(args, "top", top + 1);
|
||||||
|
return args_setStr(args, topStr, str);
|
||||||
}
|
}
|
||||||
char* stack_popStr(Stack* queue, char* buff){
|
char* stack_popStr(Stack* queue, char* outBuff) {
|
||||||
|
Args* args = queue;
|
||||||
|
uint64_t top = args_getInt(args, "top") - 1;
|
||||||
|
char buff[11];
|
||||||
|
/* sub top */
|
||||||
|
args_setInt(args, "top", top);
|
||||||
|
char* topStr = fast_itoa(buff, top);
|
||||||
|
strcpy(outBuff, args_getStr(args, topStr));
|
||||||
|
args_removeArg(args, topStr);
|
||||||
|
return outBuff;
|
||||||
}
|
}
|
@ -12,5 +12,5 @@ Stack* New_Stack();
|
|||||||
int32_t stack_deinit(Stack* stack);
|
int32_t stack_deinit(Stack* stack);
|
||||||
|
|
||||||
int32_t stack_pushStr(Stack* stack, char* str);
|
int32_t stack_pushStr(Stack* stack, char* str);
|
||||||
char* stack_popStr(Stack* queue, char* buff);
|
char* stack_popStr(Stack* queue, char* outBuff);
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user