Skip to content

Commit

Permalink
add oct base to integer literals
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich committed Nov 30, 2023
1 parent 7f03a00 commit e7ae5db
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/grammar/grammar.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,16 @@ Tact {
// Integer Literal
// hexDigit defined in Ohm's built-in rules (otherwise: hexDigit = "0".."9" | "a".."f" | "A".."F")
// digit defined in Ohm's built-in rules (otherwise: digit = "0".."9")
integerLiteral = integerLiteralHex | integerLiteralBin | integerLiteralDec // Order is important
integerLiteral = integerLiteralHex | integerLiteralBin | integerLiteralOct | integerLiteralDec // Order is important
integerLiteralDec = digit+ ("_" | digit)*
integerLiteralHex = "0x" hexDigit+ ("_" | hexDigit)*
| "0X" hexDigit+ ("_" | hexDigit)*
integerLiteralBin = "0b" binDigit+ ("_" | binDigit)*
| "0B" binDigit+ ("_" | binDigit)*
integerLiteralOct = "0o" octDigit+ ("_" | octDigit)*
| "0O" octDigit+ ("_" | octDigit)*
binDigit = "0" | "1"
octDigit = "0".."7"

// Letters
letterAsciiLC = "a".."z"
Expand Down
2 changes: 2 additions & 0 deletions src/grammar/grammar.ohm-bundle.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ export interface TactActionDict<T> extends ActionDict<T> {
integerLiteralDec?: (this: NonterminalNode, arg0: IterationNode, arg1: IterationNode) => T;
integerLiteralHex?: (this: NonterminalNode, arg0: TerminalNode, arg1: IterationNode, arg2: IterationNode) => T;
integerLiteralBin?: (this: NonterminalNode, arg0: TerminalNode, arg1: IterationNode, arg2: IterationNode) => T;
integerLiteralOct?: (this: NonterminalNode, arg0: TerminalNode, arg1: IterationNode, arg2: IterationNode) => T;
binDigit?: (this: NonterminalNode, arg0: TerminalNode) => T;
octDigit?: (this: NonterminalNode, arg0: TerminalNode) => T;
letterAsciiLC?: (this: NonterminalNode, arg0: TerminalNode) => T;
letterAsciiUC?: (this: NonterminalNode, arg0: TerminalNode) => T;
letterAscii?: (this: NonterminalNode, arg0: NonterminalNode) => T;
Expand Down
2 changes: 1 addition & 1 deletion src/grammar/grammar.ohm-bundle.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/test/feature-integer-literals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,9 @@ describe('feature-integer-literals', () => {
expect(await contract.getBinLiteral1()).toEqual(0b101010n);
expect(await contract.getBinLiteral2()).toEqual(-0b101010n);
expect(await contract.getBinLiteral3()).toEqual(0b1010100000n);

expect(await contract.getOctLiteral1()).toEqual(0o123n);
expect(await contract.getOctLiteral2()).toEqual(-0o123n);
expect(await contract.getOctLiteral3()).toEqual(0o1012300000n);
});
});
12 changes: 12 additions & 0 deletions src/test/features/integer-literals.tact
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,16 @@ contract IntegerLiteralsTester {
get fun binLiteral3(): Int {
return 0b1_0101_00__000;
}

get fun octLiteral1(): Int {
return 0o123;
}

get fun octLiteral2(): Int {
return -0o123;
}

get fun octLiteral3(): Int {
return 0o1_0123_00__000;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"IntegerLiteralsTester","types":[{"name":"StateInit","header":null,"fields":[{"name":"code","type":{"kind":"simple","type":"cell","optional":false}},{"name":"data","type":{"kind":"simple","type":"cell","optional":false}}]},{"name":"Context","header":null,"fields":[{"name":"bounced","type":{"kind":"simple","type":"bool","optional":false}},{"name":"sender","type":{"kind":"simple","type":"address","optional":false}},{"name":"value","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"raw","type":{"kind":"simple","type":"slice","optional":false}}]},{"name":"SendParameters","header":null,"fields":[{"name":"bounce","type":{"kind":"simple","type":"bool","optional":false}},{"name":"to","type":{"kind":"simple","type":"address","optional":false}},{"name":"value","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"mode","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"body","type":{"kind":"simple","type":"cell","optional":true}},{"name":"code","type":{"kind":"simple","type":"cell","optional":true}},{"name":"data","type":{"kind":"simple","type":"cell","optional":true}}]}],"receivers":[{"receiver":"internal","message":{"kind":"empty"}}],"getters":[{"name":"decLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"decLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"decLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"hexLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"hexLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"hexLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"binLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"binLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"binLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}}],"errors":{"2":{"message":"Stack undeflow"},"3":{"message":"Stack overflow"},"4":{"message":"Integer overflow"},"5":{"message":"Integer out of expected range"},"6":{"message":"Invalid opcode"},"7":{"message":"Type check error"},"8":{"message":"Cell overflow"},"9":{"message":"Cell underflow"},"10":{"message":"Dictionary error"},"13":{"message":"Out of gas error"},"32":{"message":"Method ID not found"},"34":{"message":"Action is invalid or not supported"},"37":{"message":"Not enough TON"},"38":{"message":"Not enough extra-currencies"},"128":{"message":"Null reference exception"},"129":{"message":"Invalid serialization prefix"},"130":{"message":"Invalid incoming message"},"131":{"message":"Constraints error"},"132":{"message":"Access denied"},"133":{"message":"Contract stopped"},"134":{"message":"Invalid argument"},"135":{"message":"Code of a contract was not found"},"136":{"message":"Invalid address"},"137":{"message":"Masterchain support is not enabled for this contract"}},"interfaces":["org.ton.introspection.v0","org.ton.abi.ipfs.v0","org.ton.deploy.lazy.v0","org.ton.debug.v0","org.ton.chain.workchain.v0"]}
{"name":"IntegerLiteralsTester","types":[{"name":"StateInit","header":null,"fields":[{"name":"code","type":{"kind":"simple","type":"cell","optional":false}},{"name":"data","type":{"kind":"simple","type":"cell","optional":false}}]},{"name":"Context","header":null,"fields":[{"name":"bounced","type":{"kind":"simple","type":"bool","optional":false}},{"name":"sender","type":{"kind":"simple","type":"address","optional":false}},{"name":"value","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"raw","type":{"kind":"simple","type":"slice","optional":false}}]},{"name":"SendParameters","header":null,"fields":[{"name":"bounce","type":{"kind":"simple","type":"bool","optional":false}},{"name":"to","type":{"kind":"simple","type":"address","optional":false}},{"name":"value","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"mode","type":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"body","type":{"kind":"simple","type":"cell","optional":true}},{"name":"code","type":{"kind":"simple","type":"cell","optional":true}},{"name":"data","type":{"kind":"simple","type":"cell","optional":true}}]}],"receivers":[{"receiver":"internal","message":{"kind":"empty"}}],"getters":[{"name":"decLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"decLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"decLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"hexLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"hexLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"hexLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"binLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"binLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"binLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"octLiteral1","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"octLiteral2","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}},{"name":"octLiteral3","arguments":[],"returnType":{"kind":"simple","type":"int","optional":false,"format":257}}],"errors":{"2":{"message":"Stack undeflow"},"3":{"message":"Stack overflow"},"4":{"message":"Integer overflow"},"5":{"message":"Integer out of expected range"},"6":{"message":"Invalid opcode"},"7":{"message":"Type check error"},"8":{"message":"Cell overflow"},"9":{"message":"Cell underflow"},"10":{"message":"Dictionary error"},"13":{"message":"Out of gas error"},"32":{"message":"Method ID not found"},"34":{"message":"Action is invalid or not supported"},"37":{"message":"Not enough TON"},"38":{"message":"Not enough extra-currencies"},"128":{"message":"Null reference exception"},"129":{"message":"Invalid serialization prefix"},"130":{"message":"Invalid incoming message"},"131":{"message":"Constraints error"},"132":{"message":"Access denied"},"133":{"message":"Contract stopped"},"134":{"message":"Invalid argument"},"135":{"message":"Code of a contract was not found"},"136":{"message":"Invalid address"},"137":{"message":"Masterchain support is not enabled for this contract"}},"interfaces":["org.ton.introspection.v0","org.ton.abi.ipfs.v0","org.ton.deploy.lazy.v0","org.ton.debug.v0","org.ton.chain.workchain.v0"]}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,21 @@ tuple $IntegerLiteralsTester$_contract_init() impure inline_ref {
return ($self, 672);
}

(tuple, int) $IntegerLiteralsTester$_fun_octLiteral1(tuple $self) impure inline_ref {
var ($self) = $self;
return ($self, 83);
}

(tuple, int) $IntegerLiteralsTester$_fun_octLiteral2(tuple $self) impure inline_ref {
var ($self) = $self;
return ($self, (- 83));
}

(tuple, int) $IntegerLiteralsTester$_fun_octLiteral3(tuple $self) impure inline_ref {
var ($self) = $self;
return ($self, 136937472);
}

;;
;; Receivers of a Contract IntegerLiteralsTester
;;
Expand Down Expand Up @@ -127,6 +142,24 @@ _ %binLiteral3() method_id(124513) {
return res;
}

_ %octLiteral1() method_id(115972) {
var self = $IntegerLiteralsTester$_contract_load();
var res = self~$IntegerLiteralsTester$_fun_octLiteral1();
return res;
}

_ %octLiteral2() method_id(128359) {
var self = $IntegerLiteralsTester$_contract_load();
var res = self~$IntegerLiteralsTester$_fun_octLiteral2();
return res;
}

_ %octLiteral3() method_id(124230) {
var self = $IntegerLiteralsTester$_contract_load();
var res = self~$IntegerLiteralsTester$_fun_octLiteral3();
return res;
}

_ supported_interfaces() method_id {
return (
"org.ton.introspection.v0"H >> 128,
Expand All @@ -138,7 +171,7 @@ _ supported_interfaces() method_id {
}

_ get_abi_ipfs() method_id {
return "ipfs://QmTVJohQATrpjwL6CWMTknc5g3GMfbPLjwd28io5hPjK1m";
return "ipfs://QmNsM6dTeFnXrmZ43LGqqPUSo2GCxyd2uh6Au2Yx4hvrwT";
}

_ lazy_deployment_completed() method_id {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ PROGRAM{
DECLPROC $IntegerLiteralsTester$_fun_binLiteral1
DECLPROC $IntegerLiteralsTester$_fun_binLiteral2
DECLPROC $IntegerLiteralsTester$_fun_binLiteral3
DECLPROC $IntegerLiteralsTester$_fun_octLiteral1
DECLPROC $IntegerLiteralsTester$_fun_octLiteral2
DECLPROC $IntegerLiteralsTester$_fun_octLiteral3
DECLPROC %$IntegerLiteralsTester$_internal_empty
102042 DECLMETHOD %decLiteral1
114425 DECLMETHOD %decLiteral2
Expand All @@ -22,6 +25,9 @@ PROGRAM{
116259 DECLMETHOD %binLiteral1
128576 DECLMETHOD %binLiteral2
124513 DECLMETHOD %binLiteral3
115972 DECLMETHOD %octLiteral1
128359 DECLMETHOD %octLiteral2
124230 DECLMETHOD %octLiteral3
113617 DECLMETHOD supported_interfaces
121275 DECLMETHOD get_abi_ipfs
115390 DECLMETHOD lazy_deployment_completed
Expand Down Expand Up @@ -107,6 +113,15 @@ PROGRAM{
$IntegerLiteralsTester$_fun_binLiteral3 PROCREF:<{
672 PUSHINT
}>
$IntegerLiteralsTester$_fun_octLiteral1 PROCREF:<{
83 PUSHINT
}>
$IntegerLiteralsTester$_fun_octLiteral2 PROCREF:<{
-83 PUSHINT
}>
$IntegerLiteralsTester$_fun_octLiteral3 PROCREF:<{
136937472 PUSHINT
}>
%$IntegerLiteralsTester$_internal_empty PROCINLINE:<{
}>
%decLiteral1 PROC:<{
Expand Down Expand Up @@ -154,6 +169,21 @@ PROGRAM{
$IntegerLiteralsTester$_fun_binLiteral3 INLINECALLDICT
NIP
}>
%octLiteral1 PROC:<{
$IntegerLiteralsTester$_contract_load INLINECALLDICT
$IntegerLiteralsTester$_fun_octLiteral1 INLINECALLDICT
NIP
}>
%octLiteral2 PROC:<{
$IntegerLiteralsTester$_contract_load INLINECALLDICT
$IntegerLiteralsTester$_fun_octLiteral2 INLINECALLDICT
NIP
}>
%octLiteral3 PROC:<{
$IntegerLiteralsTester$_contract_load INLINECALLDICT
$IntegerLiteralsTester$_fun_octLiteral3 INLINECALLDICT
NIP
}>
supported_interfaces PROC:<{
123515602279859691144772641439386770278 PUSHINT
209801025412363888721030803524359905849 PUSHINT
Expand All @@ -162,7 +192,7 @@ PROGRAM{
209474421377847335869795010607481022628 PUSHINT
}>
get_abi_ipfs PROC:<{
x{697066733a2f2f516d54564a6f6851415472706a774c3643574d546b6e63356733474d6662504c6a77643238696f3568506a4b316d} PUSHSLICE
x{697066733a2f2f516d4e734d36645465466e58726d5a34334c4771715055536f324743787964327568364175325978346876727754} PUSHSLICE
}>
lazy_deployment_completed PROC:<{
c4 PUSH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ PROGRAM{
DECLPROC supported_interfaces;
DECLPROC ?fun_114425;
DECLPROC lazy_deployment_completed;
DECLPROC ?fun_115972;
DECLPROC ?fun_116259;
DECLPROC get_abi_ipfs;
DECLPROC ?fun_124230;
DECLPROC ?fun_124513;
DECLPROC ?fun_128359;
DECLPROC ?fun_128576;
DECLPROC ?fun_ref_026cdd3ff17e82bb;
DECLPROC ?fun_ref_26dd4850c2973b9d;
Expand All @@ -21,9 +24,12 @@ PROGRAM{
DECLPROC ?fun_ref_553f7869b01170d9;
DECLPROC ?fun_ref_5bdfe841fa412a76;
DECLPROC ?fun_ref_684a8c99db9474e5;
DECLPROC ?fun_ref_7366f20a31928e43;
DECLPROC ?fun_ref_7a4cfefa28b39727;
DECLPROC ?fun_ref_a05e0042bce184fb;
DECLPROC ?fun_ref_b5b9e67d57f2dcce;
DECLPROC ?fun_ref_c0ca23818e24f3c9;
DECLPROC ?fun_ref_f0101fa3fb0bc1f5;
recv_internal PROC:<{
s0 s1 XCHG
CTOS
Expand Down Expand Up @@ -113,19 +119,34 @@ PROGRAM{
1 LDI
s0 s1 XCHG
}>
?fun_115972 PROC:<{
?fun_ref_a05e0042bce184fb INLINECALLDICT
?fun_ref_7366f20a31928e43 INLINECALLDICT
s1 POP
}>
?fun_116259 PROC:<{
?fun_ref_a05e0042bce184fb INLINECALLDICT
?fun_ref_026cdd3ff17e82bb INLINECALLDICT
s1 POP
}>
get_abi_ipfs PROC:<{
x{697066733A2F2F516D54564A6F6851415472706A774C3643574D546B6E63356733474D6662504C6A77643238696F3568506A4B316D82_} PUSHSLICE
x{697066733A2F2F516D4E734D36645465466E58726D5A34334C4771715055536F32474378796432756836417532597834687672775482_} PUSHSLICE
}>
?fun_124230 PROC:<{
?fun_ref_a05e0042bce184fb INLINECALLDICT
?fun_ref_b5b9e67d57f2dcce INLINECALLDICT
s1 POP
}>
?fun_124513 PROC:<{
?fun_ref_a05e0042bce184fb INLINECALLDICT
?fun_ref_5bdfe841fa412a76 INLINECALLDICT
s1 POP
}>
?fun_128359 PROC:<{
?fun_ref_a05e0042bce184fb INLINECALLDICT
?fun_ref_f0101fa3fb0bc1f5 INLINECALLDICT
s1 POP
}>
?fun_128576 PROC:<{
?fun_ref_a05e0042bce184fb INLINECALLDICT
?fun_ref_4065f3bb1951fe13 INLINECALLDICT
Expand Down Expand Up @@ -183,6 +204,9 @@ PROGRAM{
?fun_ref_684a8c99db9474e5 PROCREF:<{
69024612352 PUSHINT
}>
?fun_ref_7366f20a31928e43 PROCREF:<{
83 PUSHINT
}>
?fun_ref_7a4cfefa28b39727 PROCREF:<{
291 PUSHINT
}>
Expand All @@ -205,7 +229,13 @@ PROGRAM{
137 THROWIFNOT
?fun_ref_c0ca23818e24f3c9 INLINECALLDICT
}>
?fun_ref_b5b9e67d57f2dcce PROCREF:<{
136937472 PUSHINT
}>
?fun_ref_c0ca23818e24f3c9 PROCREF:<{
NULL
}>
?fun_ref_f0101fa3fb0bc1f5 PROCREF:<{
-83 PUSHINT
}>
}END>c
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,12 @@ tuple $IntegerLiteralsTester$_contract_load() impure inline_ref;

;; $IntegerLiteralsTester$_fun_binLiteral3
(tuple, int) $IntegerLiteralsTester$_fun_binLiteral3(tuple $self) impure inline_ref;

;; $IntegerLiteralsTester$_fun_octLiteral1
(tuple, int) $IntegerLiteralsTester$_fun_octLiteral1(tuple $self) impure inline_ref;

;; $IntegerLiteralsTester$_fun_octLiteral2
(tuple, int) $IntegerLiteralsTester$_fun_octLiteral2(tuple $self) impure inline_ref;

;; $IntegerLiteralsTester$_fun_octLiteral3
(tuple, int) $IntegerLiteralsTester$_fun_octLiteral3(tuple $self) impure inline_ref;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TACT Compilation Report
Contract: IntegerLiteralsTester
BOC Size: 545 bytes
BOC Size: 607 bytes

# Types
Total Types: 3
Expand All @@ -18,7 +18,7 @@ TLB: `_ bounce:bool to:address value:int257 mode:int257 body:Maybe ^cell code:Ma
Signature: `SendParameters{bounce:bool,to:address,value:int257,mode:int257,body:Maybe ^cell,code:Maybe ^cell,data:Maybe ^cell}`

# Get Methods
Total Get Methods: 9
Total Get Methods: 12

## decLiteral1

Expand All @@ -38,6 +38,12 @@ Total Get Methods: 9

## binLiteral3

## octLiteral1

## octLiteral2

## octLiteral3

# Error Codes
2: Stack undeflow
3: Stack overflow
Expand Down
Loading

0 comments on commit e7ae5db

Please sign in to comment.