Skip to content

Commit 0dce941

Browse files
committed
py: Implement BigInt to extend Int and tests for it
1 parent b6756c7 commit 0dce941

File tree

12 files changed

+1349
-75
lines changed

12 files changed

+1349
-75
lines changed

notes.txt

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,26 @@ Limitations
99
* string keys only in dictionaries
1010
* ints only 64 bit
1111

12+
FIXME parsing 00007 works fine whereas it should be throwing an error
13+
14+
FIXME "\tstring\n" isn't lexing properly :-(
15+
16+
FIXME interesting crash with compiling `int("42"), sausage=11)`
17+
Compile error: SystemError: [interface conversion: *ast.Call is not ast.SetCtxer: missing method SetCtx]
18+
19+
1220
Todo
1321
====
1422

23+
FIXME move the whole of Vm into Frame! perpahs decode the extended args inline.
24+
1525
Speedup
1626
* Make Object a fat interface so it defines all the M__method__ or at least all the common ones
17-
* Make the methods be pointers in *Type more like python
27+
* Embed a zero sized struct with default implementations of all the methods to avoid interface bloat
28+
* except for String/Int/Bool/Tuple/Float/Bytes and possibly some others...
29+
* Or Make the methods be pointers in *Type more like python
30+
* Function pointers would have to be func(a Object) (Object, error) which would mean a type assertion :-(
31+
* An interface is the go way of doing this
1832

1933

2034
* Getting rid of panic/defer error handling

parser/lexer.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -641,17 +641,17 @@ isNumber:
641641
var s string
642642
var err error
643643
if s = octalInteger.FindString(x.line); s != "" {
644-
value, err = py.IntNew(py.IntType, py.Tuple{py.String(s[2:]), py.Int(8)}, nil)
644+
value, err = py.IntFromString(s[2:], 8)
645645
if err != nil {
646646
panic(err)
647647
}
648648
} else if s = hexInteger.FindString(x.line); s != "" {
649-
value, err = py.IntNew(py.IntType, py.Tuple{py.String(s[2:]), py.Int(16)}, nil)
649+
value, err = py.IntFromString(s[2:], 16)
650650
if err != nil {
651651
panic(err)
652652
}
653653
} else if s = binaryInteger.FindString(x.line); s != "" {
654-
value, err = py.IntNew(py.IntType, py.Tuple{py.String(s[2:]), py.Int(2)}, nil)
654+
value, err = py.IntFromString(s[2:], 2)
655655
if err != nil {
656656
panic(err)
657657
}
@@ -687,7 +687,7 @@ isNumber:
687687
x.Error("illegal decimal with leading zero")
688688
return eofError, nil
689689
}
690-
value, err = py.IntNew(py.IntType, py.Tuple{py.String(s), py.Int(10)}, nil)
690+
value, err = py.IntFromString(s, 10)
691691
if err != nil {
692692
panic(err)
693693
}

0 commit comments

Comments
 (0)