-
Notifications
You must be signed in to change notification settings - Fork 0
add builtin function and more primitive type #22
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #include "../include/share.h" | ||
| #include "../compiler/summoner.h" | ||
|
|
||
| typedef struct | ||
| { | ||
| const char *name; | ||
| BasicType *parameters; | ||
| int parameter_count; | ||
| BasicType return_type; | ||
| const char *op_codes; | ||
| } BuiltinFun; | ||
|
|
||
| static BasicType sha3_params[] = {HEX_TYPE}; | ||
| static BasicType sha256_params[] = {HEX_TYPE}; | ||
| static BasicType abs_params[] = {INT_TYPE}; | ||
| static BasicType min_params[] = {INT_TYPE, INT_TYPE}; | ||
| static BasicType max_params[] = {INT_TYPE, INT_TYPE}; | ||
| static BasicType check_tx_sig_params[] = {PUBKEY_TYPE, SIG_TYPE}; | ||
| static BasicType check_msg_sig_params[] = {PUBKEY_TYPE, HASH_TYPE, SIG_TYPE}; | ||
| static BasicType below_params[] = {INT_TYPE, BOOLEAN_TYPE}; | ||
| static BasicType above_params[] = {INT_TYPE, BOOLEAN_TYPE}; | ||
| static BasicType lock_params[] = {AMOUNT_TYPE, ASSET_TYPE, HEX_TYPE, HEX_TYPE}; | ||
| static BasicType verify_params[] = {BOOLEAN_TYPE}; | ||
|
|
||
| BuiltinFun builtin_funs[] = { | ||
| {"sha3", sha3_params, ARRAY_SIZE(sha3_params), HASH_TYPE, "SHA3"}, | ||
| {"sha256", sha256_params, ARRAY_SIZE(sha256_params), HASH_TYPE, "SHA256"}, | ||
| {"abs", abs_params, ARRAY_SIZE(abs_params), INT_TYPE, "ABS"}, | ||
| {"min", min_params, ARRAY_SIZE(min_params), INT_TYPE, "MIN"}, | ||
| {"max", max_params, ARRAY_SIZE(max_params), INT_TYPE, "MAX"}, | ||
| {"check_tx_sig", check_tx_sig_params, ARRAY_SIZE(check_tx_sig_params), BOOLEAN_TYPE, "TXSIGHASH SWAP CHECKSIG"}, | ||
| {"check_msg_sig", check_msg_sig_params, ARRAY_SIZE(check_msg_sig_params), BOOLEAN_TYPE, "CHECKSIG"}, | ||
| {"below", below_params, ARRAY_SIZE(below_params), BOOLEAN_TYPE, "BLOCKHEIGHT GREATERTHAN"}, | ||
| {"above", above_params, ARRAY_SIZE(above_params), BOOLEAN_TYPE, "BLOCKHEIGHT LESSTHAN"}, | ||
| {"lock", lock_params, ARRAY_SIZE(lock_params), VOID_TYPE, ""}, | ||
| {"verify", verify_params, ARRAY_SIZE(verify_params), VOID_TYPE, ""}, | ||
|
||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,10 @@ void lex_err(char *str) { | |
| } | ||
|
|
||
| ":=" return DECL_ASSIGN; | ||
| "+=" return ADD_ASSIGN; | ||
| "-=" return SUB_ASSIGN; | ||
| "*=" return MUL_ASSIGN; | ||
| "/=" return DIV_ASSIGN; | ||
| ">=" return GE; | ||
| "<=" return LE; | ||
| "==" return EQ; | ||
|
|
@@ -78,6 +82,11 @@ void lex_err(char *str) { | |
| "int" return INT_T; | ||
| "double" return DOUBLE_T; | ||
| "string" return STRING_T; | ||
| "asset" return ASSET_T; | ||
| "hash" return HASH_T; | ||
| "amount" return AMOUNT_T; | ||
| "pubkey" return PUBKEY_T; | ||
| "hex" return HEX_T; | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "sig" return SIG_T; |
||
| "true"|"false" { | ||
| yylval.int_value = strcmp(yytext, "false"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #ifndef PRIVATE_SHARE_H_INCLUDED | ||
| #define PRIVATE_SHARE_H_INCLUDED | ||
|
|
||
| #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0])) | ||
|
|
||
| #endif |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lock的op组合逻辑: