Not working
This commit is contained in:
@ -15,16 +15,17 @@ void S_Free(Stack *s){
|
||||
free(s);
|
||||
}
|
||||
|
||||
void S_Push(Stack * s, void *v) {
|
||||
void S_Push(Stack * s, void *v, int i) {
|
||||
__Node * n = calloc(1, sizeof(*n));
|
||||
n->v = v;
|
||||
n->next = s->n;
|
||||
s->n = n;
|
||||
s->w = i;
|
||||
s->size = s->size + 1;
|
||||
}
|
||||
|
||||
void * S_Pop(Stack *s) {
|
||||
if (s->size == 0) {
|
||||
if (s == NULL || !S_IsEmpty(s)) {
|
||||
return NULL;
|
||||
}
|
||||
__Node * node = s->n;
|
||||
@ -37,20 +38,23 @@ void * S_Pop(Stack *s) {
|
||||
|
||||
|
||||
void * S_Peek(Stack *s){
|
||||
if (!S_IsEmpty(s)) {
|
||||
if (s == NULL || !S_IsEmpty(s)) {
|
||||
return NULL;
|
||||
}
|
||||
return s->n->v;
|
||||
}
|
||||
|
||||
bool S_IsEmpty(Stack *s){
|
||||
if(!s->size) {
|
||||
if(!s) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int S_Size(Stack *s){
|
||||
if (s == NULL || !S_IsEmpty(s)) {
|
||||
return 0;
|
||||
}
|
||||
return s->size;
|
||||
}
|
||||
//_______________________________________________________________________
|
||||
@ -64,6 +68,15 @@ char * temp = NULL;
|
||||
otherwise make it next of current and set cur to your instruction.
|
||||
*/
|
||||
|
||||
void emit_push_all(Stack * s){
|
||||
for (Instruction * i = S_Pop(s); s; i = S_Pop(s)){
|
||||
current->next = i;
|
||||
i->prev = current;
|
||||
current = i;
|
||||
current->next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void emit_detach(){
|
||||
current = current->prev;
|
||||
current->next = NULL;
|
||||
@ -162,6 +175,12 @@ void emit_binary_op(
|
||||
current->operand2 = arg2;
|
||||
}
|
||||
|
||||
void emit_goto(int i){
|
||||
emit_helper();
|
||||
current->opcode = E_GOTO;
|
||||
current->label = i;
|
||||
}
|
||||
|
||||
void emit_unary_op(Op op, TableNode * result, TNodeOrConst * arg){
|
||||
emit_helper();
|
||||
current->opcode = op;
|
||||
@ -257,8 +276,8 @@ void emit_function_call(
|
||||
){
|
||||
emit_helper();
|
||||
current->opcode = E_CALL;
|
||||
current->operand1 = tn_or_const(INTEGER, ¶m_count);
|
||||
current->operand2 = name;
|
||||
current->operand1 = name;
|
||||
current->operand2 = tn_or_const(INTEGER, ¶m_count);
|
||||
current->result = result;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user