Skip to content
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

Use int64 instead of int32 in the AST #252

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ast.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let stringToJumpKeyword = function
| s -> failwith ("not a keyword: " + s)

type Expr =
| Int of int * string
| Int of int64 * string
| Float of decimal * string
| Var of Ident
| Op of string
Expand Down
6 changes: 3 additions & 3 deletions src/parse.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ type ParseImpl() =
// Primitives
let octal =
let r = @"0[0-7]+"
let conv s = System.Convert.ToInt32(s, 8) |> (fun x -> Ast.Int(x, ""))
let conv s = System.Convert.ToInt64(s, 8) |> (fun x -> Ast.Int(x, ""))
let body = regex r |>> conv
body .>> ws

let hexa =
let prefix = pstring "0x" <|> pstring "0X"
let r = @"([0-9a-fA-F])+"
let conv s = System.Convert.ToInt32(s, 16) |> (fun x -> Ast.Int(x, ""))
let conv s = System.Convert.ToInt64(s, 16) |> (fun x -> Ast.Int(x, ""))
let body = regex r |>> conv
prefix >>. body .>> ws

let number =
let r = @"(\d+\.?\d*|\.\d+)([eE][-+]?[0-9]+)?"
let conv s =
let ok, res = System.Int32.TryParse(s : string)
let ok, res = System.Int64.TryParse(s : string)
if ok then Ast.Int (res, "")
else Ast.Float (try decimal s, "" with _ -> failwith ("invalid number: " + s))
regex r .>> ws |>> conv
Expand Down
2 changes: 1 addition & 1 deletion src/printer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ type PrinterImpl(outputFormat) =
let size =
match decl.size with
| None -> ""
| Some (Int (0, _)) -> "[]"
| Some (Int (0L, _)) -> "[]"
| Some n -> out "[%s]" (exprToS indent n)

let init =
Expand Down
1 change: 1 addition & 0 deletions tests/commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
--no-renaming --no-inlining --format indented -o tests/unit/augmented.frag.expected tests/unit/augmented.frag
--no-remove-unused --no-renaming -o tests/unit/loop.frag.expected tests/unit/loop.frag
--no-remove-unused --no-renaming -o tests/unit/array.frag.expected tests/unit/array.frag
--no-remove-unused --no-renaming --format indented -o tests/unit/numbers.frag.expected tests/unit/numbers.frag

# Inlining unit tests

Expand Down
4 changes: 2 additions & 2 deletions tests/compression_results.log
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ controllable-machinery.frag 7773 => 1227.926
ed-209.frag 7938 => 1360.765
elevated.hlsl 3416 => 603.918
endeavour.frag 2661 => 541.942
from-the-seas-to-the-stars.frag 14370 => 2345.702
from-the-seas-to-the-stars.frag 14367 => 2342.623
frozen-wasteland.frag 4609 => 812.410
kinder_painter.frag 2905 => 450.888
leizex.frag 2327 => 515.566
Expand All @@ -20,4 +20,4 @@ terrarium.frag 3634 => 747.342
the_real_party_is_in_your_pocket.frag 12248 => 1815.043
valley_ball.glsl 4386 => 888.496
yx_long_way_from_home.frag 3030 => 615.535
Total: 119326 => 21361.418
Total: 119323 => 21358.339
8 changes: 4 additions & 4 deletions tests/real/from-the-seas-to-the-stars.frag.expected
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ vec2 disc(vec2 uv)
float zoom=.4,cameraroll=1.,cameraroll2=0;
uvec2 encrypt(uvec2 v)
{
uint k[4],sum=0,delta=-1640531527;
k[0]=-1556008596;
k[1]=-939442524;
k[2]=-1383041155;
uint k[4],sum=0,delta=2654435769;
k[0]=2738958700;
k[1]=3355524772;
k[2]=2911926141;
k[3]=2123724318;
for(uint i=0;i<4;++i)
sum+=delta,v.x+=(v.y<<4)+k[0]^v.y+sum^(v.y>>5)+k[1],v.y+=(v.x<<4)+k[2]^v.x+sum^(v.x>>5)+k[3];
Expand Down
8 changes: 6 additions & 2 deletions tests/unit/numbers.frag
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
void main()
#version 130

uint large() { return 3812015801U; }

vec4 f()
{
float oct = float(042) / 1000.;
float oct2 = float(-071) / 1000.;
int dec = 65535;
int dec2 = -65536;
float n = oct - oct2 + float(4 * 0x0) + float(dec + dec2) / 20.;
gl_FragColor=vec4(n,n,n,0.);
return vec4(n,n,n,0.);
}
11 changes: 11 additions & 0 deletions tests/unit/numbers.frag.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#version 130

uint large()
{
return 3812015801U;
}
vec4 f()
{
float oct=float(34)/1e3,oct2=float(-57)/1e3,n=oct-oct2+float(0)+float(-1)/20.;
return vec4(n,n,n,0);
}