Skip to content

Commit

Permalink
Merge pull request #127 from asahi3g/develop_opcodes
Browse files Browse the repository at this point in the history
Use function instead of function literal for opcode handlers.
  • Loading branch information
amherag authored Dec 30, 2019
2 parents fc9ea87 + 3ec997f commit 73e1799
Show file tree
Hide file tree
Showing 3 changed files with 1,315 additions and 1,310 deletions.
149 changes: 74 additions & 75 deletions cx/opcodes_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,81 +151,80 @@ func init() {
[]*CXArgument{newOpPar(TYPE_STR, false)},
[]*CXArgument{})

// exec
handleOpcode := func(opCode int) opcodeHandler {
switch opCode {
// time
case OP_TIME_SLEEP:
return op_time_Sleep
case OP_TIME_UNIX:
case OP_TIME_UNIX_MILLI:
return op_time_UnixMilli
case OP_TIME_UNIX_NANO:
return op_time_UnixNano

// http
// case OP_HTTP_GET:
// return op_http_get

// os
case OP_OS_GET_WORKING_DIRECTORY:
return op_os_GetWorkingDirectory
case OP_OS_OPEN:
return op_os_Open
case OP_OS_CLOSE:
return op_os_Close
case OP_OS_SEEK:
return op_os_Seek
case OP_OS_READ_F32:
return op_os_ReadF32
case OP_OS_READ_UI32:
return op_os_ReadUI32
case OP_OS_READ_UI16:
return op_os_ReadUI16
case OP_OS_READ_F32_SLICE:
return op_os_ReadF32Slice
case OP_OS_READ_UI32_SLICE:
return op_os_ReadUI32Slice
case OP_OS_READ_UI16_SLICE:
return op_os_ReadUI16Slice
case OP_OS_READ_ALL_TEXT:
return op_os_ReadAllText
case OP_OS_RUN:
return op_os_Run
case OP_OS_EXIT:
return op_os_Exit

// json
case OP_JSON_OPEN:
return opJSONOpen
case OP_JSON_CLOSE:
return opJSONClose
case OP_JSON_TOKEN_MORE:
return opJSONTokenMore
case OP_JSON_TOKEN_NEXT:
return opJSONTokenNext
case OP_JSON_TOKEN_TYPE:
return opJSONTokenType
case OP_JSON_TOKEN_DELIM:
return opJSONTokenDelim
case OP_JSON_TOKEN_BOOL:
return opJSONTokenBool
case OP_JSON_TOKEN_F64:
return opJSONTokenF64
case OP_JSON_TOKEN_I64:
return opJSONTokenI64
case OP_JSON_TOKEN_STR:
return opJSONTokenStr

// profile
case OP_START_CPU_PROFILE:
return opStartProfile
case OP_STOP_CPU_PROFILE:
return opStopProfile
}

return nil
opcodeHandlerFinders = append(opcodeHandlerFinders, handleBaseOpcode)
}

func handleBaseOpcode(opCode int) opcodeHandler {
switch opCode {
// time
case OP_TIME_SLEEP:
return op_time_Sleep
case OP_TIME_UNIX:
case OP_TIME_UNIX_MILLI:
return op_time_UnixMilli
case OP_TIME_UNIX_NANO:
return op_time_UnixNano

// http
// case OP_HTTP_GET:
// return op_http_get

// os
case OP_OS_GET_WORKING_DIRECTORY:
return op_os_GetWorkingDirectory
case OP_OS_OPEN:
return op_os_Open
case OP_OS_CLOSE:
return op_os_Close
case OP_OS_SEEK:
return op_os_Seek
case OP_OS_READ_F32:
return op_os_ReadF32
case OP_OS_READ_UI32:
return op_os_ReadUI32
case OP_OS_READ_UI16:
return op_os_ReadUI16
case OP_OS_READ_F32_SLICE:
return op_os_ReadF32Slice
case OP_OS_READ_UI32_SLICE:
return op_os_ReadUI32Slice
case OP_OS_READ_UI16_SLICE:
return op_os_ReadUI16Slice
case OP_OS_READ_ALL_TEXT:
return op_os_ReadAllText
case OP_OS_RUN:
return op_os_Run
case OP_OS_EXIT:
return op_os_Exit

// json
case OP_JSON_OPEN:
return opJSONOpen
case OP_JSON_CLOSE:
return opJSONClose
case OP_JSON_TOKEN_MORE:
return opJSONTokenMore
case OP_JSON_TOKEN_NEXT:
return opJSONTokenNext
case OP_JSON_TOKEN_TYPE:
return opJSONTokenType
case OP_JSON_TOKEN_DELIM:
return opJSONTokenDelim
case OP_JSON_TOKEN_BOOL:
return opJSONTokenBool
case OP_JSON_TOKEN_F64:
return opJSONTokenF64
case OP_JSON_TOKEN_I64:
return opJSONTokenI64
case OP_JSON_TOKEN_STR:
return opJSONTokenStr

// profile
case OP_START_CPU_PROFILE:
return opStartProfile
case OP_STOP_CPU_PROFILE:
return opStopProfile
}

opcodeHandlerFinders = append(opcodeHandlerFinders, handleOpcode)
return nil
}
Loading

0 comments on commit 73e1799

Please sign in to comment.