]> gitweb.factorcode.org Git - factor.git/commitdiff
python.modules: vocab hierarchy for standard library modules
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 27 Oct 2014 12:24:33 +0000 (13:24 +0100)
committerDoug Coleman <doug.coleman@gmail.com>
Mon, 27 Oct 2014 16:52:04 +0000 (09:52 -0700)
pre-existing bindings for various python modules can be placed here so
that they dont have to be redeclared for everyone using them

extra/python/modules/__builtin__/__builtin__.factor [new file with mode: 0644]
extra/python/modules/argparse/argparse.factor [new file with mode: 0644]
extra/python/modules/datetime/datetime.factor [new file with mode: 0644]
extra/python/modules/os/os.factor [new file with mode: 0644]
extra/python/modules/os/path/path.factor [new file with mode: 0644]
extra/python/modules/sys/sys.factor [new file with mode: 0644]
extra/python/modules/time/time.factor [new file with mode: 0644]
extra/python/throwing/throwing.factor

diff --git a/extra/python/modules/__builtin__/__builtin__.factor b/extra/python/modules/__builtin__/__builtin__.factor
new file mode 100644 (file)
index 0000000..fb8c884
--- /dev/null
@@ -0,0 +1,31 @@
+USING: python.syntax ;
+IN: python.modules.__builtin__
+
+PY-FROM: __builtin__ =>
+    callable ( obj -- ? )
+    dir ( obj -- seq )
+    int ( val -- s )
+    len ( seq -- n )
+    open ( name mode -- file )
+    range ( n -- seq )
+    repr ( obj -- str ) ;
+
+PY-METHODS: obj =>
+    __name__ ( self -- n )
+    __str__ ( o -- str ) ;
+
+PY-METHODS: file =>
+    close ( self -- )
+    fileno ( self -- n )
+    tell ( self -- n ) ;
+
+PY-METHODS: str =>
+    lower ( self -- self' )
+    partition ( self sep -- bef sep aft )
+    startswith ( self str -- ? )
+    title ( self -- self' )
+    zfill ( self n -- str' ) ;
+
+PY-METHODS: list =>
+    append ( list obj -- )
+    remove ( list obj -- ) ;
diff --git a/extra/python/modules/argparse/argparse.factor b/extra/python/modules/argparse/argparse.factor
new file mode 100644 (file)
index 0000000..fdfdd93
--- /dev/null
@@ -0,0 +1,7 @@
+USING: python.syntax ;
+IN: python.modules.argparse
+
+PY-FROM: argparse => ArgumentParser ( -- self ) ;
+PY-METHODS: ArgumentParser =>
+    add_argument ( self name ** -- )
+    format_help ( self -- str ) ;
diff --git a/extra/python/modules/datetime/datetime.factor b/extra/python/modules/datetime/datetime.factor
new file mode 100644 (file)
index 0000000..0fe0621
--- /dev/null
@@ -0,0 +1,4 @@
+USING: python.syntax ;
+IN: python.modules.datetime
+
+PY-FROM: datetime => timedelta ( ** -- timedelta ) ;
diff --git a/extra/python/modules/os/os.factor b/extra/python/modules/os/os.factor
new file mode 100644 (file)
index 0000000..6ab8eba
--- /dev/null
@@ -0,0 +1,6 @@
+USING: python.syntax ;
+IN: python.modules.os
+
+PY-FROM: os =>
+    getpid ( -- y )
+    system ( x -- y ) ;
diff --git a/extra/python/modules/os/path/path.factor b/extra/python/modules/os/path/path.factor
new file mode 100644 (file)
index 0000000..30a8a2c
--- /dev/null
@@ -0,0 +1,6 @@
+USING: python.syntax ;
+IN: python.modules.os.path
+
+PY-FROM: os.path =>
+    basename ( x -- x' )
+    splitext ( x -- base ext ) ;
diff --git a/extra/python/modules/sys/sys.factor b/extra/python/modules/sys/sys.factor
new file mode 100644 (file)
index 0000000..f84238f
--- /dev/null
@@ -0,0 +1,8 @@
+USING: python.syntax ;
+IN: python.modules.sys
+
+PY-FROM: sys =>
+    path ( -- seq )
+    argv ( -- seq )
+    getrefcount ( obj -- n )
+    platform ( -- x ) ;
diff --git a/extra/python/modules/time/time.factor b/extra/python/modules/time/time.factor
new file mode 100644 (file)
index 0000000..9c4212a
--- /dev/null
@@ -0,0 +1,4 @@
+USING: python.syntax ;
+IN: python.modules.time
+
+PY-FROM: time => sleep ( n -- ) ;
index 4cdf539d48d4b04fa144824335db758789db78a1..7e783aba98d28b8b088ac4b950136b7550950c9e 100644 (file)
@@ -1,12 +1,9 @@
-USING: arrays kernel python python.ffi python.syntax sequences ;
+USING: arrays kernel python python.ffi python.modules.__builtin__ python.syntax
+sequences ;
 IN: python.throwing
 
 PY-FROM: traceback => format_tb ( tb -- seq ) ;
 
-PY-METHODS: obj =>
-    __name__ ( o -- str )
-    __str__ ( o -- str ) ;
-
 : throw-error ( ptype pvalue ptraceback -- )
     [
         [ $__name__ py> ]