New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix console func refactor #853

Closed
crabmusket opened this Issue Oct 23, 2014 · 0 comments

Comments

Projects
None yet
1 participant
@crabmusket
Contributor

crabmusket commented Oct 23, 2014

I missed some things in the merge which James caught after reviewing #842. Apparently they'll hurt the optmisations introduced. They don't appear to be causing chaos though.

Affected areas are shown below. Note though that all occurrences of codeStream[ip++] = X should become codeStream.emit(X). This is what the code does currently, but doesn't do the other stuff these patches do.

U32 ReturnStmtNode::compileStmt(U32 *codeStream, U32 ip, U32, U32)
@@ -246,8 +275,22 @@ U32 ReturnStmtNode::compileStmt(U32 *codeStream, U32 ip, U32, U32)
       codeStream[ip++] = OP_RETURN_VOID;
    else
    {
-      ip = expr->compile(codeStream, ip, TypeReqString);
-      codeStream[ip++] = OP_RETURN;
+      TypeReq walkType = expr->getPreferredType();
+      if (walkType == TypeReqNone) walkType = TypeReqString;
+      ip = expr->compile(codeStream, ip, walkType);
+
+      // Return the correct type
+      switch (walkType) {
+      case TypeReqUInt:
+         codeStream[ip++] = OP_RETURN_UINT;
+      break;
+      case TypeReqFloat:
+         codeStream[ip++] = OP_RETURN_FLT;
+      break;
+      default:
+         codeStream[ip++] = OP_RETURN;
+      break;
+      }
    }
    return ip;
 }

and

@@ -1775,8 +1860,21 @@ U32 ObjectDeclNode::compileSubObject(U32 *codeStream, U32 ip, bool root)
    codeStream[ip++] = OP_PUSH;
    for(ExprNode *exprWalk = argList; exprWalk; exprWalk = (ExprNode *) exprWalk->getNext())
    {
-      ip = exprWalk->compile(codeStream, ip, TypeReqString);
-      codeStream[ip++] = OP_PUSH;
+      TypeReq walkType = exprWalk->getPreferredType();
+      if (walkType == TypeReqNone) walkType = TypeReqString;
+      ip = exprWalk->compile(codeStream, ip, walkType);
+      switch (exprWalk->getPreferredType())
+      {
+         case TypeReqFloat:
+            codeStream[ip++] = OP_PUSH_FLT;
+            break;
+         case TypeReqUInt:
+            codeStream[ip++] = OP_PUSH_UINT;
+            break;
+         default:
+            codeStream[ip++] = OP_PUSH;
+            break;      
+      }
    }

and

@@ -1357,8 +1426,21 @@ U32 FuncCallExprNode::compile(U32 *codeStream, U32 ip, TypeReq type)
    codeStream[ip++] = OP_PUSH_FRAME;
    for(ExprNode *walk = args; walk; walk = (ExprNode *) walk->getNext())
    {
-      ip = walk->compile(codeStream, ip, TypeReqString);
-      codeStream[ip++] = OP_PUSH;
+      TypeReq walkType = walk->getPreferredType();
+      if (walkType == TypeReqNone) walkType = TypeReqString;
+      ip = walk->compile(codeStream, ip, walkType);
+      switch (walk->getPreferredType())
+      {
+         case TypeReqFloat:
+            codeStream[ip++] = OP_PUSH_FLT;
+            break;
+         case TypeReqUInt:
+            codeStream[ip++] = OP_PUSH_UINT;
+            break;
+         default:
+            codeStream[ip++] = OP_PUSH;
+            break;
+      }
    }
    if(callType == MethodCall || callType == ParentCall)
       codeStream[ip++] = OP_CALLFUNC;

@crabmusket crabmusket added the Bug label Oct 23, 2014

@crabmusket crabmusket added this to the 3.7 milestone Oct 23, 2014

@crabmusket crabmusket self-assigned this Oct 25, 2014

@crabmusket crabmusket closed this Oct 27, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment