summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-12-06 20:41:22 +0100
committerStefan Israelsson Tampe <stefan.itampe@gmail.com>2018-12-06 20:41:22 +0100
commit25605a21140af33eacc455631083e70f3f28c2b7 (patch)
tree760c061a34acff86146e783195b10a520ae5f1c2
parent31a53d9844f3431099010cc6ebef8fbbf1a38855 (diff)
better guilemod
-rw-r--r--modules/language/python/compile.scm11
-rw-r--r--modules/language/python/def.scm18
-rw-r--r--modules/language/python/guilemod.scm32
-rw-r--r--modules/language/python/module.scm3
-rw-r--r--modules/language/python/module/f.py45
-rw-r--r--modules/language/python/string.scm3
6 files changed, 30 insertions, 82 deletions
diff --git a/modules/language/python/compile.scm b/modules/language/python/compile.scm
index e291e34..06e529b 100644
--- a/modules/language/python/compile.scm
+++ b/modules/language/python/compile.scm
@@ -281,7 +281,7 @@
(fold f (f (car l) init) (cdr l))
init))
-(define do-pr #f)
+(define do-pr #t)
(define (pr . x)
(if do-pr
@@ -1259,7 +1259,7 @@
`(,(G 'begin) ,(exp vs a) ,(exp vs (cons #:comma l)))))
(#:import
- ((_ (#:from (() . nm) . #f))
+ ((_ (#:from (() () . nm) . #f))
(let* ((xl (map (lambda (nm) (exp vs nm)) nm))
(l `(language python module ,@xl)))
@@ -1297,7 +1297,7 @@
(if (eq? ? #t) (for-each dont-warn (get-exported-symbols l)))
`(,(C 'use) ,? ,l ,l))))
- ((_ (#:from (() . nm) l))
+ ((_ (#:from (() () . nm) l))
;; Make sure to load the module in
(let* ((xl (map (lambda (nm) (exp vs nm)) nm))
(ll `(language python module ,@xl)))
@@ -2842,10 +2842,7 @@
((_ v (#:apply x ...) . l)
#'(ref-x (py-apply v x ...) . l))
-
- ((_ v (#:apply x ...) . l)
- #'(ref-x (py-apply v x ...) . l))
-
+
((_ v (#:vecref x) . l)
#'(ref-x (pylist-ref v x) . l))
diff --git a/modules/language/python/def.scm b/modules/language/python/def.scm
index 25edc7e..7e97d22 100644
--- a/modules/language/python/def.scm
+++ b/modules/language/python/def.scm
@@ -1,4 +1,5 @@
(define-module (language python def)
+ #:use-module (ice-9 pretty-print)
#:use-module (oop pf-objects)
#:use-module (language python for)
#:use-module (language python exceptions)
@@ -98,15 +99,16 @@
((k ...) (map car kv))
((s ...) (map ->kw (map car kv)))
((v ...) (map cdr kv)))
- #`(object-method
- (lambda* (#,@as . l)
- (call-with-values (lambda () (get-akw l))
- (lambda (ww* kw)
- (let*-values (((ww* k) (take-1 #,(null? ww-) ww* kw s v))
+ #`(object-method
+ (lambda* (#,@as . l)
+ (call-with-values (lambda () (get-akw l))
+ (lambda (ww* kw)
+ (let*-values (((ww* k) (take-1 #,(null? ww-) ww*
+ kw s v))
...)
- (let ((ww ww*)
- (kw (pytonize kw)))
- (let () code ...))))))))))))))
+ (let ((ww ww*)
+ (kw (pytonize kw)))
+ (let () code ...))))))))))))))
(define-syntax-rule (def (f . args) code ...) (define f (lam args code ...)))
diff --git a/modules/language/python/guilemod.scm b/modules/language/python/guilemod.scm
index 1e3351e..c8dc413 100644
--- a/modules/language/python/guilemod.scm
+++ b/modules/language/python/guilemod.scm
@@ -1,6 +1,8 @@
(define-module (language python guilemod)
#:export ())
+(define-syntax-rule (aif it p . l) (let ((it p)) (if it . l)))
+
(define-syntax-rule (mk-commands path mod-C define-C define-exp-C define-set-C)
(begin
(define mod-C (resolve-module 'path))
@@ -241,27 +243,15 @@
(define pload
(let ((guile-load (@ (guile) primitive-load-path)))
(lambda (p . q)
- (let ((tag (make-prompt-tag)))
- (call-with-prompt
- tag
- (lambda ()
- (guile-load p (lambda () (abort-to-prompt tag))))
- (lambda (k)
- (let lp ((l *extension-dispatches*))
- (if (pair? l)
- (let lp2 ((u (caar l)))
- (if (pair? u)
- (let ((tag (make-prompt-tag)))
- (call-with-prompt
- tag
- (lambda ()
- (guile-load (string-append p "." (car u))
- (lambda () (abort-to-prompt tag))))
- (lambda (k) (lp2 (cdr u)))))
- (lp (cdr l))))))
- (if (pair? q)
- ((car q))
- (error (string-append "no code for path " p)))))))))
+ (let lp ((l *extension-dispatches*))
+ (if (pair? l)
+ (let lp2 ((u (caar l)))
+ (if (pair? u)
+ (aif it (%search-load-path (string-append p "." (car u)))
+ (apply guile-load it q)
+ (lp2 (cdr u)))
+ (lp (cdr l))))
+ (apply guile-load p q))))))
(define-set-G primitive-load-path pload)
diff --git a/modules/language/python/module.scm b/modules/language/python/module.scm
index d239baf..5e04fda 100644
--- a/modules/language/python/module.scm
+++ b/modules/language/python/module.scm
@@ -82,7 +82,6 @@
(define __init__
(case-lambda
((self pre l nm)
- (pk 1)
(match l
((name)
(rawset self '_path (reverse (cons name pre)))
@@ -94,11 +93,9 @@
((self l nm)
- (pk 2)
(_cont self #f l #f nm #f))
((self l)
- (pk 3)
(if (pair? l)
(if (and (> (length l) 3)
(equal? (list (list-ref l 0)
diff --git a/modules/language/python/module/f.py b/modules/language/python/module/f.py
index 6de30e7..ea0d50f 100644
--- a/modules/language/python/module/f.py
+++ b/modules/language/python/module/f.py
@@ -1,45 +1,6 @@
module(f)
-from enum import Enum, unique, auto, IntEnum
+def g(x):
+ return x
-class Color (Enum):
- RED = 1
- GREEN = 2
- BLUE = 3
-
-class Shape(Enum):
- SQUARE = 2
- DIAMOND = 1
- CIRCLE = 3
- ALIAS_FOR_SQUARE = 2
-
-class Color2 (Enum):
- RED = auto()
- GREEN = auto()
- BLUE = auto()
-
-@unique
-class Misstake(Enum):
- ONE = 1
- TWO = 2
- THREE = 3
- FOUR = 4
-
-class AutoName(Enum):
- def _generate_next_value_(name, start, count, last_values):
- return name
-
-
-class Ordinal(AutoName):
- NORTH = auto()
- SOUTH = auto()
- EAST = auto()
- WEST = auto()
-
-class Num(IntEnum):
- One = 1
- Two = 2
- Three = 3
-
-
-__all__ = ['Color','Shape','Color2','Misstake','Ordinal','Num']
+__all__ = ['g']
diff --git a/modules/language/python/string.scm b/modules/language/python/string.scm
index 864a7a1..b3708b5 100644
--- a/modules/language/python/string.scm
+++ b/modules/language/python/string.scm
@@ -624,7 +624,8 @@
(case-lambda
((self)
"")
- ((self s . l)
+ ((self s . l)
+ (pk s)
(cond
((is-a? s <py-string>)
(slot-ref s 'str))