Compare commits

..

No commits in common. '3d1b3ac76b113462f23ba0445862f30e0f2a75f3' and '775dfee6a82fe5ee0cdcd97859d0436eb83157d4' have entirely different histories.

  1. 120
      src/rustint/core.clj
  2. 249
      test/rustint/core_test.clj

@ -1927,53 +1927,10 @@
; user=> (palabra-reservada? 13) ; user=> (palabra-reservada? 13)
; false ; false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn palabra-reservada? [arg] ;TODO
(let [keywords (hash-set ;(defn palabra-reservada?
'EOF, ;
'String, ;)
'Write,
'abs,
'as,
'as_str,
'atan,
'bool,
'char,
'chars,
'const,
'else,
'exit,
'expect,
'f64,
'flush,
'fn,
'format!,
'from,
'i64,
'if,
'io,
'let,
'mut,
'new,
'nth,
'parse,
'print!,
'println!,
'process,
'read_line,
'return,
'sin,
'sqrt,
'std,
'stdin,
'stdout,
'to_string,
'trim,
'unwrap,
'use,
'usize,
'while,
)] (contains? keywords arg))
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; IDENTIFICADOR?: Recibe un elemento y devuelve true si es un identificador valido en Rust; si no, false. ; IDENTIFICADOR?: Recibe un elemento y devuelve true si es un identificador valido en Rust; si no, false.
@ -1987,18 +1944,10 @@
; user=> (identificador? '12e0) ; user=> (identificador? '12e0)
; false ; false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn identificador? [arg] ;TODO
(and ;(defn identificador?
(symbol? arg) ;
(not (palabra-reservada? arg)) ;)
(contains?
(set
(map char (range 97 122))
)
(first (name arg))
)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DUMP: Recibe un vector con instrucciones de la RI y las imprime numeradas a partir de 0. Siempre devuelve nil. ; DUMP: Recibe un vector con instrucciones de la RI y las imprime numeradas a partir de 0. Siempre devuelve nil.
@ -2018,17 +1967,10 @@
; 0 nil ; 0 nil
; nil ; nil
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TODO
(defn format_elem [idx itm] ;(defn dump
(format "%d %s" idx itm) ;
) ;)
(defn dump [args]
(
cond (nil? args) (println "0 nil")
:else (dorun (map println (map-indexed format_elem args)))
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; YA-DECLARADO-LOCALMENTE?: Recibe un identificador y un contexto (un vector formado por dos subvectores: el primero ; YA-DECLARADO-LOCALMENTE?: Recibe un identificador y un contexto (un vector formado por dos subvectores: el primero
@ -2168,29 +2110,10 @@
; user=> (convertir-formato-impresion '("Las raices cuadradas de {} son +{:.8} y -{:.8}" 4.0 1.999999999985448 1.999999999985448)) ; user=> (convertir-formato-impresion '("Las raices cuadradas de {} son +{:.8} y -{:.8}" 4.0 1.999999999985448 1.999999999985448))
; ("Las raices cuadradas de %.0f son +%.8f y -%.8f" 4.0 1.999999999985448 1.999999999985448) ; ("Las raices cuadradas de %.0f son +%.8f y -%.8f" 4.0 1.999999999985448 1.999999999985448)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; TODO
(defn especificador-formato [arg, rustf] ;(defn convertir-formato-impresion
(cond ;
(string? arg) "%s" ;)
(int? arg) "%d"
(and (float? arg) (nil? rustf)) "%.0f"
(and (float? arg) (not (nil? rustf))) (format "%%%sf" rustf)
)
)
(defn get-rust-formatters [s]
(map last (re-seq #"\{:?(.\d)?\}" s))
)
(defn convertir-formato-impresion [args]
(let [clojure-fspecifiers (
map
especificador-formato
(rest args)
(get-rust-formatters (first args))
)
] args)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; DIVIDIR: Recibe dos numeros y devuelve su cociente, manteniendo su tipo. ; DIVIDIR: Recibe dos numeros y devuelve su cociente, manteniendo su tipo.
@ -2208,13 +2131,10 @@
; user=> (dividir 1 2.0) ; user=> (dividir 1 2.0)
; 0.5 ; 0.5
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn dividir [arg1 arg2] ; TODO
( ;(defn dividir
cond ;
(and (float? arg2) (int? arg1)) (/ arg1 arg2) ;)
:else (quot arg1 arg2)
)
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; COMPATIBLES?: Recibe dos elementos. Si el primero es un tipo de dato de Rust y el segundo es un valor de Clojure ; COMPATIBLES?: Recibe dos elementos. Si el primero es un tipo de dato de Rust y el segundo es un valor de Clojure

@ -127,252 +127,3 @@
(is (= (compatibles? 'char ['a]) true)) (is (= (compatibles? 'char ['a]) true))
) )
) )
(deftest dividir-test01
(testing "Test 01 dividir"
(is (= (dividir 12 3) 4))
)
)
(deftest dividir-test02
(testing "Test 02 dividir"
(is (= (dividir 12.0 3) 4.0))
)
)
(deftest dividir-test03
(testing "Test 03 dividir"
(is (= (dividir 12 3.0) 4.0))
)
)
(deftest dividir-test04
(testing "Test 04h dividir"
(is (= (dividir 12.0 3.0) 4.0))
)
)
(deftest dividir-test05
(testing "Test 05 dividir"
(is (= (dividir 1 2) 0))
)
)
(deftest dividir-test06
(testing "Test 06 dividir"
(is (= (dividir 1 2.0) 0.5))
)
)
(deftest identificador-test01
(testing "Test 01 identificador"
(is (= (identificador? 'boolean) true))
)
)
(deftest identificador-test02
(testing "Test 02 identificador"
(is (= (identificador? 'bool) false))
)
)
(deftest identificador-test03
(testing "Test 03 identificador"
(is (= (identificador? 'e120) true))
)
)
(deftest identificador-test04
(testing "Test 04 identificador"
(is (= (identificador? '12e0) false))
)
)
(deftest palabra-reservada-test01
(testing "Test 01 palabra reservada"
(is (= (palabra-reservada? 'while) true))
)
)
(deftest palabra-reservada-test02
(testing "Test 02 palabra reservada"
(is (= (palabra-reservada? 'until) false))
)
)
(deftest palabra-reservada-test03
(testing "Test 03 palabra reservada"
(is (= (palabra-reservada? 13) false))
)
)
(deftest dump-01
(testing "Test 01 dump"
(let [
printed (with-out-str (dump '[[POPREF 2] [PUSHFI 2] MUL [PUSHFI 1] ADD NEG]))
]
(is (= printed "0 [POPREF 2]\n1 [PUSHFI 2]\n2 MUL\n3 [PUSHFI 1]\n4 ADD\n5 NEG\n"
))
)
)
)
(deftest dump-01-nil
(testing "Test 01 dump nil"
(is (nil? (dump '[[POPREF 2] [PUSHFI 2] MUL [PUSHFI 1] ADD NEG])))
)
)
(deftest dump-02
(testing "Test 02 dump"
(let [
printed (with-out-str (dump '[HLT]))
]
(is (= printed "0 HLT\n"
))
)
)
)
(deftest dump-02-nil
(testing "Test 02 dump nil"
(is (nil? (dump '[HLT])))
)
)
(deftest dump-03
(testing "Test 03 dump"
(let [
printed (with-out-str (dump nil))
]
(is (= printed "0 nil\n"
))
)
)
)
(deftest dump-03-nil
(testing "Test 03 dump nil"
(is (nil? (dump nil)))
)
)
(deftest convertir-formato-impresion-01
(testing "Test 01 convertir-formato-impresion"
(is (=
(convertir-formato-impresion '("Hola, mundo!"))
'("Hola, mundo!")
)
)
)
)
(deftest convertir-formato-impresion-02
(testing "Test 02 convertir-formato-impresion"
(is (=
(convertir-formato-impresion '("Hola, mundo 2!"))
'("Hola, mundo 2!")
)
)
)
)
(deftest convertir-formato-impresion-03
(testing "Test 03 convertir-formato-impresion"
(is (=
(convertir-formato-impresion '("Hola, mundo {}!" 2))
'("Hola, mundo %d!" 2)
)
)
)
)
(deftest get-rust-formatters-01
(testing "Test 01 get-rust-formatters"
(is (=
(get-rust-formatters "Hola, Mundo!")
'()
)
)
)
)
(deftest get-rust-formatters-02
(testing "Test 02 get-rust-formatters"
(is (=
(get-rust-formatters "- My name is {}, James {}.\n- Hello, {}{}{}!")
'(nil nil nil nil nil)
)
)
)
)
(deftest get-rust-formatters-03
(testing "Test 03 get-rust-formatters"
(is (=
(get-rust-formatters "{} elevado a la {} es\t{}")
'(nil nil nil)
)
)
)
)
(deftest get-rust-formatters-04
(testing "Test 04 get-rust-formatters"
(is (=
(get-rust-formatters "Las raices cuadradas de {} son +{:.8} y -{:.8}")
'(nil ".8" ".8")
)
)
)
)
(deftest test-especificador-formato-01
(testing "Test 01 especificador formato"
(is (=
(especificador-formato "Bond" nil)
"%s"
)
)
)
)
(deftest test-especificador-formato-02
(testing "Test 02 especificador formato"
(is (=
(especificador-formato 0 nil)
"%d"
)
)
)
)
(deftest test-especificador-formato-03
(testing "Test 03 especificador formato"
(is (=
(especificador-formato 2.0 nil)
"%.0f"
)
)
)
)
(deftest test-especificador-formato-04
(testing "Test 04 especificador formato"
(is (=
(especificador-formato 2.0 ".4")
"%.4f"
)
)
)
)
(deftest test-especificador-formato-05
(testing "Test 05 especificador formato"
(is (=
(especificador-formato 2.0 ".8")
"%.8f"
)
)
)
)

Loading…
Cancel
Save