Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Introspection/00-META.yaml
Normal file
3
Task/Introspection/00-META.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
from: http://rosettacode.org/wiki/Introspection
|
||||
note: Programming environment operations
|
||||
9
Task/Introspection/00-TASK.txt
Normal file
9
Task/Introspection/00-TASK.txt
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
;Task:
|
||||
* verify the version/revision of your currently running (compiler/interpreter/byte-compiler/runtime environment/whatever your language uses) and exit if it is too old.
|
||||
* check whether the variable "bloop" exists and whether the math-function "abs()" is available and if yes compute <i>abs(bloop)</i>.
|
||||
|
||||
|
||||
;Extra credit:
|
||||
* Report the number of integer variables in global scope, and their sum.
|
||||
<br><br>
|
||||
|
||||
6
Task/Introspection/ALGOL-68/introspection-1.alg
Normal file
6
Task/Introspection/ALGOL-68/introspection-1.alg
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN
|
||||
print (("Integer range: ", -max int, " .. ", max int, new line));
|
||||
print (("Integer digits: ", int width, new line));
|
||||
print (("Float range: ", -max real, " .. ", max real, new line));
|
||||
print (("Float digits: ", real width, new line))
|
||||
END
|
||||
50
Task/Introspection/ALGOL-68/introspection-2.alg
Normal file
50
Task/Introspection/ALGOL-68/introspection-2.alg
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
BEGIN
|
||||
MODE SSMODES = UNION(SHORT SHORT BITS, SHORT SHORT BYTES, #SHORT SHORT CHAR,#
|
||||
SHORT SHORT INT, SHORT SHORT REAL, SHORT SHORT COMPL);
|
||||
MODE SMODES = UNION(SHORT BITS, SHORT BYTES, #SHORT CHAR,#
|
||||
SHORT INT, SHORT REAL, SHORT COMPL);
|
||||
MODE NMODES = UNION(BITS, BYTES, CHAR, INT, REAL, COMPL);
|
||||
MODE LMODES = UNION(LONG BITS, LONG BYTES, #LONG CHAR,#
|
||||
LONG INT, LONG REAL, LONG COMPL);
|
||||
MODE LLMODES = UNION(LONG LONG BITS, LONG LONG BYTES, #LONG LONG CHAR,#
|
||||
LONG LONG INT, LONG LONG REAL, LONG LONG COMPL);
|
||||
MODE XMODES = UNION(BOOL, SEMA, STRING, VOID, CHANNEL, FILE, FORMAT);
|
||||
|
||||
MODE MODES = UNION(SSMODES, SMODES, NMODES, LLMODES, LMODES, XMODES);
|
||||
|
||||
OP REPRTYPEOF = (MODES val)STRING:
|
||||
CASE val IN
|
||||
(VOID):"VOID",
|
||||
(INT):"INT",(SHORT INT):"SHORT INT",(SHORT SHORT INT):"SHORT SHORT INT",
|
||||
(LONG INT):"LONG INT",(LONG LONG INT):"LONG LONG INT",
|
||||
(REAL):"REAL",(SHORT REAL):"SHORT REAL",(SHORT SHORT REAL):"SHORT SHORT REAL",
|
||||
(LONG REAL):"LONG REAL",(LONG LONG REAL):"LONG LONG REAL",
|
||||
(COMPL):"COMPL",(SHORT COMPL):"SHORT COMPL",(SHORT SHORT COMPL):"SHORT SHORT COMPL",
|
||||
(LONG COMPL):"LONG COMPL",(LONG LONG COMPL):"LONG LONG COMPL",
|
||||
(BITS):"BITS",(SHORT BITS):"SHORT BITS",(SHORT SHORT BITS):"SHORT SHORT BITS",
|
||||
(LONG BITS):"LONG BITS",(LONG LONG BITS):"LONG LONG BITS",
|
||||
(BYTES):"BYTES",(SHORT BYTES):"SHORT BYTES",(SHORT SHORT BYTES):"SHORT SHORT BYTES",
|
||||
(LONG BYTES):"LONG BYTES",(LONG LONG BYTES):"LONG LONG BYTES",
|
||||
(CHAR):"CHAR",#(SHORT CHAR):"SHORT CHAR",(SHORT SHORT CHAR):"SHORT SHORT CHAR",
|
||||
(LONG CHAR):"LONG CHAR",(LONG LONG CHAR):"LONG LONG CHAR",#
|
||||
(BOOL):"BOOL",
|
||||
(STRING):"STRING",
|
||||
(SEMA):"SEMA",
|
||||
(CHANNEL):"CHANNEL",
|
||||
(FILE):"FILE",
|
||||
(FORMAT):"FORMAT"
|
||||
OUT
|
||||
"ARRAY, PROC or STRUCT"
|
||||
ESAC;
|
||||
|
||||
[]MODES x = (EMPTY, 1, 2.0, 3I4, SHORT SHORT 5, SHORT 6, LONG 7, LONG LONG 8,
|
||||
8r666, bytes pack("abc"), TRUE, "xyz", LEVEL 1,
|
||||
stand in channel, stand in, $ddd$);
|
||||
|
||||
STRING sep := "";
|
||||
print(("Array member types: "));
|
||||
FOR i TO UPB x DO
|
||||
print((sep,REPRTYPEOF x[i]));
|
||||
sep := ", "
|
||||
OD
|
||||
END
|
||||
8
Task/Introspection/ALGOL-68/introspection-3.alg
Normal file
8
Task/Introspection/ALGOL-68/introspection-3.alg
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/usr/local/bin/a68g --script #
|
||||
|
||||
OP TYPEOF = (INT skip)STRING: "INT";
|
||||
OP TYPEOF = (CHAR skip)STRING: "CHAR";
|
||||
OP TYPEOF = (REAL skip)STRING: "REAL";
|
||||
OP TYPEOF = (COMPL skip)STRING: "COMPL";
|
||||
|
||||
printf(($g" "$,TYPEOF 1, TYPEOF "x", TYPEOF pi, TYPEOF (0 I 1 ), $l$))
|
||||
6
Task/Introspection/ALGOL-68/introspection-4.alg
Normal file
6
Task/Introspection/ALGOL-68/introspection-4.alg
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/local/bin/a68g --script #
|
||||
|
||||
[]INT x = (5,4,3,2,1);
|
||||
|
||||
print(("x =", x, new line));
|
||||
print(("LWB x =", LWB x, ", UPB x = ",UPB x, new line))
|
||||
14
Task/Introspection/AWK/introspection.awk
Normal file
14
Task/Introspection/AWK/introspection.awk
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
# syntax: GAWK -f INTROSPECTION.AWK
|
||||
BEGIN {
|
||||
if (PROCINFO["version"] < "4.1.0") {
|
||||
print("version is too old")
|
||||
exit(1)
|
||||
}
|
||||
bloop = -1
|
||||
if (PROCINFO["identifiers"]["abs"] == "user" && bloop != "") {
|
||||
printf("bloop = %s\n",bloop)
|
||||
printf("abs(bloop) = %s\n",abs(bloop))
|
||||
}
|
||||
exit(0)
|
||||
}
|
||||
function abs(x) { if (x >= 0) { return x } else { return -x } }
|
||||
14
Task/Introspection/Ada/introspection.ada
Normal file
14
Task/Introspection/Ada/introspection.ada
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
with Ada.Integer_Text_IO, Ada.Text_IO;
|
||||
procedure Introspection is
|
||||
use Ada.Integer_Text_IO, Ada.Text_IO;
|
||||
begin
|
||||
Put ("Integer range: ");
|
||||
Put (Integer'First);
|
||||
Put (" .. ");
|
||||
Put (Integer'Last);
|
||||
New_Line;
|
||||
|
||||
Put ("Float digits: ");
|
||||
Put (Float'Digits);
|
||||
New_Line;
|
||||
end Introspection;
|
||||
50
Task/Introspection/Aikido/introspection.aikido
Normal file
50
Task/Introspection/Aikido/introspection.aikido
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import math
|
||||
|
||||
if (version < 144) {
|
||||
throw "Version of aikido is too old"
|
||||
}
|
||||
|
||||
var bloop = -1.4
|
||||
|
||||
// Math package doesn't have 'abs'. We'll use 'fabs' instead.
|
||||
if ("fabs" in Math) {
|
||||
if ("bloop" in main) {
|
||||
println ("fabs(bloop) is " + eval ("Math.fabs(bloop)"))
|
||||
}
|
||||
}
|
||||
|
||||
var x = 104
|
||||
var y = 598
|
||||
var z = "hello"
|
||||
var a = 1234
|
||||
|
||||
function count_ints {
|
||||
// there are builtin integer variables that we don't want to count. There are
|
||||
// 3 of them
|
||||
var intcount = 0
|
||||
// map of builtin variables we want to ignore
|
||||
var ignore = {"version":true, "int":true, "integer":true}
|
||||
var sum = 0
|
||||
|
||||
// the 'split' function can be used to split a block into a vector of the names
|
||||
// of the variables within it
|
||||
foreach v split (main, 0) {
|
||||
var varname = v
|
||||
try {
|
||||
var value = eval (varname)
|
||||
if (typeof(value) == "integer") {
|
||||
if (varname in ignore) {
|
||||
continue
|
||||
}
|
||||
intcount++
|
||||
sum += value
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore exception
|
||||
}
|
||||
}
|
||||
println ("There are " + intcount + " integer variables in the global scope")
|
||||
println ("Their sum is " + sum)
|
||||
}
|
||||
|
||||
count_ints()
|
||||
14
Task/Introspection/Arturo/introspection.arturo
Normal file
14
Task/Introspection/Arturo/introspection.arturo
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
if not? sys\version > 0.9.0 -> panic "version too old!"
|
||||
|
||||
bloop: 3 - 5
|
||||
|
||||
if? set? 'bloop -> "variable 'bloop' is set"
|
||||
else -> "variable 'bloop' is not set"
|
||||
|
||||
if set? 'abs -> print ["the absolute value of bloop is:" abs bloop]
|
||||
|
||||
print [
|
||||
"The sum of all globally defined integers is:"
|
||||
sum map select keys symbols 'sym -> integer? var sym
|
||||
'sym -> var sym
|
||||
]
|
||||
10
Task/Introspection/AutoHotkey/introspection.ahk
Normal file
10
Task/Introspection/AutoHotkey/introspection.ahk
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
if (A_AhkVersion < "1.0.48.03")
|
||||
{
|
||||
MsgBox % "you are using" . A_AhkVersion . "`nplease upgrade to" . "1.0.48.03"
|
||||
ExitApp
|
||||
}
|
||||
bloop = -3
|
||||
if bloop
|
||||
if IsFunc("abs")
|
||||
MsgBox % abs(bloop)
|
||||
return
|
||||
23
Task/Introspection/BBC-BASIC/introspection.basic
Normal file
23
Task/Introspection/BBC-BASIC/introspection.basic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
IF VAL(FNversion) < 5.94 THEN PRINT "Version is too old" : END
|
||||
|
||||
ON ERROR LOCAL PRINT "Variable 'bloop' doesn't exist" : END
|
||||
test = bloop
|
||||
RESTORE ERROR
|
||||
|
||||
ON ERROR LOCAL PRINT "Function 'FNabs()' is not defined" : END
|
||||
test = ^FNabs()
|
||||
RESTORE ERROR
|
||||
|
||||
PRINT FNabs(bloop)
|
||||
END
|
||||
|
||||
DEF FNversion
|
||||
LOCAL F%, V$
|
||||
F% = OPENOUT(@tmp$+"version.txt")
|
||||
OSCLI "OUTPUT "+STR$F%
|
||||
*HELP
|
||||
*OUTPUT 0
|
||||
PTR #F% = 0
|
||||
INPUT #F%,V$
|
||||
CLOSE #F%
|
||||
= RIGHT$(V$,5)
|
||||
5
Task/Introspection/C++/introspection.cpp
Normal file
5
Task/Introspection/C++/introspection.cpp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#if !defined(__cplusplus) || __cplusplus < 201103L
|
||||
#pragma error("The following code requires at least C++11.")
|
||||
#else
|
||||
// ...
|
||||
#endif
|
||||
81
Task/Introspection/C-sharp/introspection.cs
Normal file
81
Task/Introspection/C-sharp/introspection.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Rosetta_Introspection
|
||||
{
|
||||
static public class Program
|
||||
{
|
||||
static public int bloop = -10;
|
||||
static public int bloop2 = -20;
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
var asm = Assembly.GetExecutingAssembly();
|
||||
var version = int.Parse(asm.ImageRuntimeVersion.Split('.')[0].Substring(1));
|
||||
if (version < 4)
|
||||
{
|
||||
Console.WriteLine("Get with the program! I'm outta here!");
|
||||
return;
|
||||
}
|
||||
|
||||
FieldInfo bloopField = null;
|
||||
|
||||
foreach (var type in asm.GetExportedTypes())
|
||||
{
|
||||
foreach (var field in type.GetFields())
|
||||
{
|
||||
if (field.Name != "bloop")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
bloopField = field;
|
||||
if (bloopField.FieldType != typeof(int))
|
||||
{
|
||||
throw new InvalidProgramException("bloop should be an integer");
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (bloopField != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bloopField == null)
|
||||
{
|
||||
throw new InvalidProgramException("No bloop exported value");
|
||||
}
|
||||
foreach (var refAsm in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
foreach (var type in refAsm.GetExportedTypes())
|
||||
{
|
||||
if (type.Name == "Math")
|
||||
{
|
||||
var absMethod = type.GetMethod("Abs", new Type[] { typeof(int) });
|
||||
if (absMethod != null)
|
||||
{
|
||||
Console.WriteLine("bloop's abs value = {0}", absMethod.Invoke(null, new object[] { bloopField.GetValue(null) }));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int intCount = 0;
|
||||
int total = 0;
|
||||
|
||||
foreach (var type in asm.GetExportedTypes())
|
||||
{
|
||||
foreach (var field in type.GetFields())
|
||||
{
|
||||
if (field.FieldType == typeof(int))
|
||||
{
|
||||
intCount++;
|
||||
total += (int)field.GetValue(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Console.WriteLine("{0} exported ints which total to {1}", intCount, total);
|
||||
Console.ReadKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
5
Task/Introspection/C/introspection.c
Normal file
5
Task/Introspection/C/introspection.c
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#if !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
|
||||
#pragma error("C compiler must adhere to at least C99 for the following code.")
|
||||
#else
|
||||
/* rest of file */
|
||||
#endif
|
||||
11
Task/Introspection/Clojure/introspection.clj
Normal file
11
Task/Introspection/Clojure/introspection.clj
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
; check Java version
|
||||
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (System/getProperty "java.version")))]
|
||||
(if (>= version 1.5)
|
||||
(println "Version ok")
|
||||
(throw (Error. "Bad version"))))
|
||||
|
||||
; check Clojure version
|
||||
(let [version (Double/parseDouble (re-find #"\d*\.\d*" (clojure-version)))]
|
||||
(if (>= version 1.0)
|
||||
(println "Version ok")
|
||||
(throw (Error. "Bad version"))))
|
||||
5
Task/Introspection/Common-Lisp/introspection-1.lisp
Normal file
5
Task/Introspection/Common-Lisp/introspection-1.lisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(let* ((ver (lisp-implementation-version))
|
||||
(major (parse-integer ver :start 0 :end (position #\. ver))))
|
||||
#+lispworks (assert (>= 5 major) () "Requires Lispworks version 5 or above")
|
||||
#+clisp (assert (>= 2 major) () "Requires CLISP 2.n")
|
||||
)
|
||||
4
Task/Introspection/Common-Lisp/introspection-2.lisp
Normal file
4
Task/Introspection/Common-Lisp/introspection-2.lisp
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
(defvar bloop -4)
|
||||
(if (and (fboundp 'abs)
|
||||
(boundp 'bloop))
|
||||
(format t "~d~%" (abs bloop)))
|
||||
10
Task/Introspection/Common-Lisp/introspection-3.lisp
Normal file
10
Task/Introspection/Common-Lisp/introspection-3.lisp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(let ((sum 0)
|
||||
(ints '()))
|
||||
(loop for pkg in (list-all-packages)
|
||||
do (do-symbols (s pkg)
|
||||
(when (and (boundp s)
|
||||
(integerp (symbol-value s)))
|
||||
(push s ints)
|
||||
(incf sum (symbol-value s)))))
|
||||
(format t "there are ~d integer variables adding up to ~d~%"
|
||||
(length ints) sum))
|
||||
32
Task/Introspection/D/introspection.d
Normal file
32
Task/Introspection/D/introspection.d
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
// Some module-level variables (D doesn't have a global scope).
|
||||
immutable x = 3, y = 100, z = 3_000;
|
||||
short w = 1; // Not an int, must be ignored.
|
||||
immutable s = "some string"; // Not an int, must be ignored.
|
||||
|
||||
void main() {
|
||||
import std.compiler, std.math, std.traits;
|
||||
|
||||
// Compile-time constants of the compiler version:
|
||||
static assert(version_major > 1 && version_minor > 50,
|
||||
"I can't cope with this compiler version.");
|
||||
|
||||
immutable bloop = 10;
|
||||
|
||||
// To check if something compiles:
|
||||
static if (__traits(compiles, bloop.abs)) {
|
||||
pragma(msg, "The expression is compilable.");
|
||||
auto x = bloop.abs;
|
||||
} else {
|
||||
pragma(msg, "The expression can't be compiled.");
|
||||
}
|
||||
|
||||
import std.stdio;
|
||||
immutable s = 10_000; // Not at module scope, must be ignored.
|
||||
|
||||
int tot = 0;
|
||||
/*static*/ foreach (name; __traits(allMembers, mixin(__MODULE__)))
|
||||
static if (name != "object" &&
|
||||
is(int == Unqual!(typeof(mixin("." ~ name)))))
|
||||
tot += mixin("." ~ name);
|
||||
writeln("Total of the module-level ints (could overflow): ", tot);
|
||||
}
|
||||
1
Task/Introspection/E/introspection-1.e
Normal file
1
Task/Introspection/E/introspection-1.e
Normal file
|
|
@ -0,0 +1 @@
|
|||
def version := interp.getProps()["e.version"]
|
||||
5
Task/Introspection/E/introspection-2.e
Normal file
5
Task/Introspection/E/introspection-2.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
escape fail {
|
||||
def &x := meta.getState().fetch("&bloop", fn { fail("no bloop") })
|
||||
if (!x.__respondsTo("abs", 0)) { fail("no abs") }
|
||||
x.abs()
|
||||
}
|
||||
5
Task/Introspection/E/introspection-3.e
Normal file
5
Task/Introspection/E/introspection-3.e
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
var sum := 0
|
||||
for &x in interp.getTopScope() { sum += try { x :int } catch _ { 0 } }
|
||||
sum
|
||||
}
|
||||
26
Task/Introspection/EchoLisp/introspection.l
Normal file
26
Task/Introspection/EchoLisp/introspection.l
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
(version)
|
||||
→ EchoLisp - 2.50.3
|
||||
📗 local-db: db.version: 3
|
||||
|
||||
(when (< (version) 2.6)
|
||||
(writeln "Please reload EchoLisp : CTRL-F5, CMD-R or other...")
|
||||
(exit))
|
||||
|
||||
(if (and (bound? 'bloop) (bound? 'abs) (procedure? abs))
|
||||
(abs bloop) 'NOT-HERE)
|
||||
→ NOT-HERE
|
||||
|
||||
(define bloop -777)
|
||||
→ bloop
|
||||
(if (and (bound? 'bloop) (bound? 'abs) (procedure? abs)) (abs bloop) 'NOT-HERE)
|
||||
→ 777
|
||||
|
||||
(for/sum ((kv (environment-bindings user-initial-environment )))
|
||||
#:when (integer? (second kv))
|
||||
(writeln kv)
|
||||
(second kv))
|
||||
|
||||
("bloop" -777)
|
||||
("gee" 555)
|
||||
("buzz" 333)
|
||||
→ 111 ;; sum
|
||||
20
Task/Introspection/Erlang/introspection.erl
Normal file
20
Task/Introspection/Erlang/introspection.erl
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
-module( introspection ).
|
||||
|
||||
-export( [task/0] ).
|
||||
|
||||
task() ->
|
||||
exit_if_too_old( erlang:system_info(otp_release) ),
|
||||
Bloop = lists:keyfind( bloop, 1, ?MODULE:module_info(functions) ),
|
||||
Abs = lists:keyfind( abs, 1, erlang:module_info(exports) ),
|
||||
io:fwrite( "abs( bloop ) => ~p~n", [call_abs_with_bloop(Abs, Bloop)] ),
|
||||
io:fwrite( "Number of modules: ~p~n", [erlang:length(code:all_loaded())] ).
|
||||
|
||||
|
||||
|
||||
bloop() -> -1.
|
||||
|
||||
call_abs_with_bloop( {abs, 1}, {bloop, 0} ) -> erlang:abs( bloop() );
|
||||
call_abs_with_bloop( _Missing, _Not_here ) -> abs_and_bloop_missing.
|
||||
|
||||
exit_if_too_old( Release ) when Release < "R13A" -> erlang:exit( too_old_release );
|
||||
exit_if_too_old( _Release ) -> ok.
|
||||
9
Task/Introspection/Factor/introspection-1.factor
Normal file
9
Task/Introspection/Factor/introspection-1.factor
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
: if-older ( n true false -- )
|
||||
[ build > ] 2dip if ; inline
|
||||
|
||||
: when-older ( n true -- )
|
||||
[ ] if-older ; inline
|
||||
: unless-older ( n false -- )
|
||||
[ [ ] ] dip if-older ; inline
|
||||
|
||||
900 [ "Your version of Factor is too old." print 1 exit ] when-older
|
||||
5
Task/Introspection/Factor/introspection-2.factor
Normal file
5
Task/Introspection/Factor/introspection-2.factor
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
"bloop" search [
|
||||
get [
|
||||
"abs" search [ execute( n -- n' ) ] when*
|
||||
] [ 0 ] if*
|
||||
] [ 0 ] if*
|
||||
7
Task/Introspection/Factor/introspection-3.factor
Normal file
7
Task/Introspection/Factor/introspection-3.factor
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
USING: assocs formatting kernel math namespaces ;
|
||||
|
||||
0 0
|
||||
global [
|
||||
nip dup integer? [ + [ 1 + ] dip ] [ drop ] if
|
||||
] assoc-each
|
||||
"There are %d integer variables, the sum is %d\n" printf
|
||||
8
Task/Introspection/Forth/introspection-1.fth
Normal file
8
Task/Introspection/Forth/introspection-1.fth
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
s" MAX-U" environment? [IF]
|
||||
0xffffffff <> [IF] .( Requires 32 bits! ) bye [THEN]
|
||||
[THEN]
|
||||
|
||||
[defined] bloop [if]
|
||||
[defined] abs [if]
|
||||
bloop @ abs
|
||||
[then] [then]
|
||||
11
Task/Introspection/Forth/introspection-2.fth
Normal file
11
Task/Introspection/Forth/introspection-2.fth
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[hex] 362 [decimal] 4TH# - [if] [abort] [then]
|
||||
|
||||
-32 value bloop
|
||||
[defined] bloop [if]
|
||||
[defined] abs [if]
|
||||
bloop abs . cr
|
||||
[then]
|
||||
[then]
|
||||
|
||||
0 last cell+ first over over - .( User variables: ) .
|
||||
?do i @ + loop .( Sum: ) . cr
|
||||
17
Task/Introspection/FreeBASIC/introspection-1.basic
Normal file
17
Task/Introspection/FreeBASIC/introspection-1.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#If __FB_VERSION__ < "1.06.0"
|
||||
#Error "Compiler version is too old - needs to be 1.06.0 or later"
|
||||
#EndIf
|
||||
|
||||
Dim bloop As Integer = -15
|
||||
#IfDef bloop
|
||||
#IfDef Abs
|
||||
Print "Abs(bloop) = "; Abs(bloop)
|
||||
#Else
|
||||
Print "Abs is not available"
|
||||
#EndIf
|
||||
#Else
|
||||
Print "bloop does not exist"
|
||||
#EndIf
|
||||
Sleep
|
||||
17
Task/Introspection/FreeBASIC/introspection-2.basic
Normal file
17
Task/Introspection/FreeBASIC/introspection-2.basic
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
#If __FB_VERSION__ < "1.05.0" '' version 1.05.0 is now OK
|
||||
#Error "Compiler version is too old - needs to be 1.05.0 or later"
|
||||
#EndIf
|
||||
|
||||
Dim bloop As Integer = -15
|
||||
#IfDef bloop
|
||||
#IfDef Abs
|
||||
Print "Abs(bloop) = "; Abs(bloop)
|
||||
#Else
|
||||
Print "Abs is not available"
|
||||
#EndIf
|
||||
#Else
|
||||
Print "bloop does not exist"
|
||||
#EndIf
|
||||
Sleep
|
||||
12
Task/Introspection/FreeBASIC/introspection-3.basic
Normal file
12
Task/Introspection/FreeBASIC/introspection-3.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#Undef Abs '' undefine Abs keyword
|
||||
Dim bloop As Integer = -15
|
||||
#IfDef bloop
|
||||
#IfDef Abs
|
||||
Print "Abs(bloop) = "; Abs(bloop)
|
||||
#Else
|
||||
Print "Abs is not available"
|
||||
#EndIf
|
||||
#Else
|
||||
Print "bloop does not exist"
|
||||
#EndIf
|
||||
Sleep
|
||||
12
Task/Introspection/FreeBASIC/introspection-4.basic
Normal file
12
Task/Introspection/FreeBASIC/introspection-4.basic
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#Undef Abs '' undefine Abs keyword
|
||||
'Dim bloop As Integer = -15 '' bloop declaration commented out
|
||||
#IfDef bloop
|
||||
#IfDef Abs
|
||||
Print "Abs(bloop) = "; Abs(bloop)
|
||||
#Else
|
||||
Print "Abs is not available"
|
||||
#EndIf
|
||||
#Else
|
||||
Print "bloop does not exist"
|
||||
#EndIf
|
||||
Sleep
|
||||
30
Task/Introspection/GAP/introspection.gap
Normal file
30
Task/Introspection/GAP/introspection.gap
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
# Apply a function to a value, given variable names for both function and value
|
||||
CheckEval := function(fun, val)
|
||||
local f, x;
|
||||
if IsBoundGlobal(fun) and IsBoundGlobal(val) then
|
||||
f := ValueGlobal(fun);
|
||||
x := ValueGlobal(val);
|
||||
return f(x);
|
||||
fi;
|
||||
end;
|
||||
|
||||
bloop := -1;
|
||||
CheckEval("AbsInt", "bloop");
|
||||
# 1
|
||||
|
||||
|
||||
# Sum of integer variables
|
||||
GlobalIntegers := function()
|
||||
local s, x, name;
|
||||
s := 0;
|
||||
for name in SortedList(NamesGVars()) do
|
||||
if IsBoundGlobal(name) then
|
||||
x := ValueGlobal(name);
|
||||
if IsInt(x) then
|
||||
Print(name, " ", x, "\n");
|
||||
s := s + x;
|
||||
fi;
|
||||
fi;
|
||||
od;
|
||||
return s;
|
||||
end;
|
||||
59
Task/Introspection/Go/introspection.go
Normal file
59
Task/Introspection/Go/introspection.go
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"debug/elf"
|
||||
"debug/gosym"
|
||||
"fmt"
|
||||
"log"
|
||||
"math"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var bloop = -3.4
|
||||
|
||||
func main() {
|
||||
fmt.Println("task 1: verify version")
|
||||
fmt.Println(" program compiled with", runtime.Version())
|
||||
|
||||
fmt.Println("task 2: check for presence of variable and function")
|
||||
// inspect ELF symbol table
|
||||
f, err := elf.Open(os.Args[0])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
symSection := f.Section(".gosymtab")
|
||||
lineSection := f.Section(".gopclntab")
|
||||
textSection := f.Section(".text")
|
||||
if symSection == nil || lineSection == nil || textSection == nil {
|
||||
log.Fatal("symbolic information not found")
|
||||
}
|
||||
symData, err := symSection.Data()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
lineData, err := lineSection.Data()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
table, err := gosym.NewTable(symData,
|
||||
gosym.NewLineTable(lineData, textSection.Addr))
|
||||
if err != nil {
|
||||
log.Fatal(" ", err)
|
||||
}
|
||||
var foundBloop, foundFabs bool
|
||||
for _, s := range table.Syms {
|
||||
if s.Name == "main.bloop" {
|
||||
foundBloop = true
|
||||
fmt.Println(" bloop symbol table entry:", s)
|
||||
} else if s.Name == "math.Abs" {
|
||||
foundFabs = true
|
||||
fmt.Println(" abs symbol table entry:", s)
|
||||
}
|
||||
}
|
||||
if foundBloop && foundFabs {
|
||||
fmt.Println(" bloop: ", bloop)
|
||||
fmt.Println(" abs(bloop): ", math.Abs(bloop))
|
||||
}
|
||||
}
|
||||
8
Task/Introspection/Haskell/introspection.hs
Normal file
8
Task/Introspection/Haskell/introspection.hs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import Data.Version
|
||||
import Control.Monad
|
||||
import System.Info
|
||||
|
||||
minGHCVersion = Version [6, 8] []
|
||||
|
||||
main = when (compilerName == "ghc" && compilerVersion < minGHCVersion) $
|
||||
fail "Compiler too old."
|
||||
8
Task/Introspection/IS-BASIC/introspection.basic
Normal file
8
Task/Introspection/IS-BASIC/introspection.basic
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
100 IF VERNUM<2.1 THEN PRINT "Version is too old.":STOP
|
||||
110 WHEN EXCEPTION USE ERROR
|
||||
120 PRINT ABS(BLOOP)
|
||||
130 END WHEN
|
||||
140 HANDLER ERROR
|
||||
150 PRINT EXSTRING$(EXTYPE)
|
||||
160 CONTINUE
|
||||
170 END HANDLER
|
||||
18
Task/Introspection/Icon/introspection.icon
Normal file
18
Task/Introspection/Icon/introspection.icon
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
global bloop
|
||||
|
||||
procedure main(A)
|
||||
if older(11,7) then stop("Must have version >= 11.7!")
|
||||
bloop := -5 # global variable
|
||||
floop := -11.3 # local variable
|
||||
write(proc("abs")(variable("bloop")))
|
||||
write(proc("abs")(variable("floop")))
|
||||
end
|
||||
|
||||
procedure older(maj,min)
|
||||
&version ? {
|
||||
(tab(find("Version ")),move(*"Version "))
|
||||
major := 1(tab(upto('.')),move(1))
|
||||
minor := tab(upto('.'))
|
||||
return (major < maj) | ((major = maj) & (minor < min))
|
||||
}
|
||||
end
|
||||
25
Task/Introspection/Inform-7/introspection.inf
Normal file
25
Task/Introspection/Inform-7/introspection.inf
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Home is a room.
|
||||
|
||||
When play begins:
|
||||
let V be the current runtime version;
|
||||
if V is less than the required runtime version:
|
||||
say "Version [required runtime version] required, but [V] found.";
|
||||
otherwise:
|
||||
say "Your interpreter claims version [V].";
|
||||
end the story.
|
||||
|
||||
A version is a kind of value.
|
||||
|
||||
Section - Checking the version (for Glulx only)
|
||||
|
||||
1.255.255 specifies a version with parts major, minor (without leading zeros), and subminor (without leading zeros).
|
||||
|
||||
To decide which version is current runtime version: (- (0-->1) -).
|
||||
To decide which version is required runtime version: decide on 3.1.2.
|
||||
|
||||
Section - Checking the version (for Z-machine only)
|
||||
|
||||
1.255 specifies a version with parts major and minor (without leading zeros).
|
||||
|
||||
To decide which version is current runtime version: (- ($32-->0) -).
|
||||
To decide which version is required runtime version: decide on 1.1.
|
||||
3
Task/Introspection/Io/introspection-1.io
Normal file
3
Task/Introspection/Io/introspection-1.io
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if(System version < 20080000, exit)
|
||||
|
||||
if(hasSlot("bloop") and bloop hasSlot("abs"), bloop abs)
|
||||
1
Task/Introspection/Io/introspection-2.io
Normal file
1
Task/Introspection/Io/introspection-2.io
Normal file
|
|
@ -0,0 +1 @@
|
|||
getSlot("arbitraryMethod") code
|
||||
1
Task/Introspection/J/introspection-1.j
Normal file
1
Task/Introspection/J/introspection-1.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
6 (2!:55@:]^:>) 0 ". 1 { 9!:14''
|
||||
1
Task/Introspection/J/introspection-2.j
Normal file
1
Task/Introspection/J/introspection-2.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
".(#~3 0*./ .=4!:0@;:)'abs bloop'
|
||||
1
Task/Introspection/J/introspection-3.j
Normal file
1
Task/Introspection/J/introspection-3.j
Normal file
|
|
@ -0,0 +1 @@
|
|||
((],&(+/);@#~)((=<.)@[^:](''-:$)*.0=0{.@#,)&>)".&.>4!:1]0
|
||||
12
Task/Introspection/Java/introspection.java
Normal file
12
Task/Introspection/Java/introspection.java
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
public class VersCheck {
|
||||
public static void main(String[] args) {
|
||||
String vers = System.getProperty("java.version");
|
||||
vers = vers.substring(0,vers.indexOf('.')) + "." + //some String fiddling to get the version number into a usable form
|
||||
vers.substring(vers.indexOf('.')+1,vers.lastIndexOf('.'));
|
||||
if(Double.parseDouble(vers) >= 1.5){
|
||||
System.out.println("YAY!");
|
||||
}else{
|
||||
System.err.println("Must use Java >=1.5");
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/Introspection/JavaScript/introspection-1.js
Normal file
1
Task/Introspection/JavaScript/introspection-1.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
if (typeof bloop !== "undefined") { ... }
|
||||
1
Task/Introspection/JavaScript/introspection-2.js
Normal file
1
Task/Introspection/JavaScript/introspection-2.js
Normal file
|
|
@ -0,0 +1 @@
|
|||
if ("abs" in Math) { ... }
|
||||
20
Task/Introspection/Jsish/introspection.jsish
Normal file
20
Task/Introspection/Jsish/introspection.jsish
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/* Introspection, in jsish */
|
||||
if (Info.version() < Util.verConvert('2.8.6')) {
|
||||
puts("need at least version 2.8.6 of jsish for this application");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Check for "abs()" as function and "bloop" as defined value, call if both check true */
|
||||
if ((bloop != undefined) && (typeof Math.abs == 'function')) {
|
||||
puts(Math.abs(bloop));
|
||||
}
|
||||
|
||||
/* ECMAScript, this will sum all numeric values, not just strict integers */
|
||||
var nums = 0, sums = 0, v;
|
||||
for (v of Info.vars(this)) {
|
||||
if (isFinite(this[v])) {
|
||||
nums++;
|
||||
sums += this[v];
|
||||
}
|
||||
}
|
||||
printf("%d numerics with sum of: %d\n", nums, sums);
|
||||
11
Task/Introspection/Julia/introspection.julia
Normal file
11
Task/Introspection/Julia/introspection.julia
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
@show VERSION
|
||||
VERSION < v"0.4" && exit(1)
|
||||
|
||||
if isdefined(Base, :bloop) && !isempty(methods(abs))
|
||||
@show abs(bloop)
|
||||
end
|
||||
|
||||
a, b, c = 1, 2, 3
|
||||
vars = filter(x -> eval(x) isa Integer, names(Main))
|
||||
println("Integer variables: ", join(vars, ", "), ".")
|
||||
println("Sum of integers in the global scope: ", sum(eval.(vars)), ".")
|
||||
40
Task/Introspection/Kotlin/introspection.kotlin
Normal file
40
Task/Introspection/Kotlin/introspection.kotlin
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
// version 1.0.6 (intro.kt)
|
||||
|
||||
import java.lang.reflect.Method
|
||||
|
||||
val bloop = -3
|
||||
val i = 4
|
||||
val j = 5
|
||||
val k = 6
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// get version of JVM
|
||||
val version = System.getProperty("java.version")
|
||||
if (version >= "1.6") println("The current JVM version is $version")
|
||||
else println("Must use version 1.6 or later")
|
||||
|
||||
// check that 'bloop' and 'Math.abs' are available
|
||||
// note that the class created by the Kotlin compiler for top level declarations will be called 'IntroKt'
|
||||
val topLevel = Class.forName("IntroKt")
|
||||
val math = Class.forName("java.lang.Math")
|
||||
val abs = math.getDeclaredMethod("abs", Int::class.java)
|
||||
val methods = topLevel.getDeclaredMethods()
|
||||
for (method in methods) {
|
||||
// note that the read-only Kotlin property 'bloop' is converted to the static method 'getBloop' in Java
|
||||
if (method.name == "getBloop" && method.returnType == Int::class.java) {
|
||||
println("\nabs(bloop) = ${abs.invoke(null, method.invoke(null))}")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// now get the number of global integer variables and their sum
|
||||
var count = 0
|
||||
var sum = 0
|
||||
for (method in methods) {
|
||||
if (method.returnType == Int::class.java) {
|
||||
count++
|
||||
sum += method.invoke(null) as Int
|
||||
}
|
||||
}
|
||||
println("\nThere are $count global integer variables and their sum is $sum")
|
||||
}
|
||||
5
Task/Introspection/Lasso/introspection-1.lasso
Normal file
5
Task/Introspection/Lasso/introspection-1.lasso
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var(bloob = -26)
|
||||
|
||||
decimal(lasso_version(-lassoversion)) < 9.2 ? abort
|
||||
|
||||
var_defined('bloob') and $bloob -> isa(::integer) and lasso_tagexists('math_abs') ? math_abs($bloob)
|
||||
15
Task/Introspection/Lasso/introspection-2.lasso
Normal file
15
Task/Introspection/Lasso/introspection-2.lasso
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
var(
|
||||
bloob = -26,
|
||||
positive = 450
|
||||
)
|
||||
|
||||
local(total = integer)
|
||||
|
||||
with v in var_keys
|
||||
// Lasso creates a number of thread variables that all start with an underscore. We don't want those
|
||||
where not(string(#v) -> beginswith('_')) and var(#v) -> isa(::integer)
|
||||
do {
|
||||
#total += var(#v)
|
||||
}
|
||||
|
||||
#total
|
||||
5
Task/Introspection/Lingo/introspection-1.lingo
Normal file
5
Task/Introspection/Lingo/introspection-1.lingo
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
put _player.productVersion
|
||||
-- "11.5.9"
|
||||
|
||||
_player.itemDelimiter="."
|
||||
if integer(_player.productVersion.item[1])<11 then _player.quit()
|
||||
6
Task/Introspection/Lingo/introspection-2.lingo
Normal file
6
Task/Introspection/Lingo/introspection-2.lingo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-- check existence of bloop in local scope
|
||||
bloopExists = not voidP(value("bloop"))
|
||||
-- or for global scope:
|
||||
-- bloopExists = not voidP(_global.bloop)
|
||||
absExists = value("abs(1)")=1
|
||||
if bloopExists and absExists then put abs(bloop) -- or abs(_global.bloop)
|
||||
10
Task/Introspection/Lingo/introspection-3.lingo
Normal file
10
Task/Introspection/Lingo/introspection-3.lingo
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
cnt = 0
|
||||
sum = 0
|
||||
repeat with v in the globals
|
||||
if integerP(v) then
|
||||
cnt = cnt + 1
|
||||
sum = sum + v
|
||||
end if
|
||||
end repeat
|
||||
put cnt
|
||||
put sum
|
||||
24
Task/Introspection/Locomotive-Basic/introspection-1.basic
Normal file
24
Task/Introspection/Locomotive-Basic/introspection-1.basic
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
org &4000 ; program start address
|
||||
|
||||
push bc
|
||||
push de
|
||||
push hl
|
||||
push af
|
||||
ld bc,&df00 ; select BASIC ROM
|
||||
out (c),c ; (ROM 0)
|
||||
|
||||
ld bc,&7f86 ; make ROM accessible at &c000
|
||||
out (c),c ; (RAM block 3)
|
||||
|
||||
ld hl,&c001 ; copy ROM version number to RAM
|
||||
ld de,&4040
|
||||
ld bc,3
|
||||
ldir
|
||||
|
||||
ld bc,&7f8e ; turn off ROM
|
||||
out (c),c
|
||||
pop af
|
||||
pop hl
|
||||
pop de
|
||||
pop bc
|
||||
ret
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
10 s=&4000:SYMBOL AFTER 256:MEMORY s-1
|
||||
20 FOR i=0 to 34:READ a:POKE s+i,a:NEXT
|
||||
30 DATA &c5,&d5,&e5,&f5,&01,&00,&df,&ed,&49,&01,&86,&7f,&ed,&49
|
||||
40 DATA &21,&01,&c0,&11,&40,&40,&01,&03,&00,&ed,&b0
|
||||
50 DATA &01,&8e,&7f,&ed,&49,&f1,&e1,&d1,&c1,&c9
|
||||
60 CALL s
|
||||
70 PRINT "BASIC ROM version is ";PEEK(&4040);".";PEEK(&4041);".";PEEK(&4042)
|
||||
80 IF PEEK(&4041)=0 THEN PRINT "Uh oh, you are still using BASIC 1.0":END
|
||||
90 PRINT "You are using BASIC 1.1 or later, program can continue"
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
1 ' decide randomly whether to define the variable:
|
||||
10 IF RND>.5 THEN bloop=-100*RND
|
||||
20 ON ERROR GOTO 100
|
||||
30 a=@bloop ' try to get a pointer
|
||||
40 PRINT "Variable bloop exists and its value is",bloop
|
||||
50 PRINT "ABS of bloop is",ABS(bloop)
|
||||
90 END
|
||||
100 IF ERL=30 THEN PRINT "Variable bloop not defined":RESUME 90
|
||||
18
Task/Introspection/Locomotive-Basic/introspection-4.basic
Normal file
18
Task/Introspection/Locomotive-Basic/introspection-4.basic
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
10 ' The program should find and add those three integers (%), ignoring reals:
|
||||
20 foo%=-4:bar%=7:baz%=9:somereal=3.141
|
||||
30 varstart=&ae68 ' for CPC 664 and 6128
|
||||
40 ' varstart=&ae85 ' (use this line instead on the CPC 464)
|
||||
50 start=PEEK(varstart)+256*PEEK(varstart+1)
|
||||
60 WHILE start<HIMEM
|
||||
70 j=2:WHILE j<43 ' skip variable name
|
||||
80 IF PEEK(start+j)=0 GOTO 170
|
||||
90 IF PEEK(start+j)>127 THEN ptr=start+j+1:j=100
|
||||
100 j=j+1:WEND
|
||||
110 vartype=PEEK(ptr) ' integer=1, string=2, real=4
|
||||
120 IF vartype=1 THEN sum=sum+UNT(PEEK(ptr+1)+256*PEEK(ptr+2)):num=num+1:nvar=ptr+3
|
||||
130 IF vartype=2 THEN nvar=ptr+4
|
||||
140 IF vartype=4 THEN nvar=ptr+6
|
||||
150 start=nvar
|
||||
160 WEND
|
||||
170 PRINT "There are"num"integer variables."
|
||||
180 PRINT "Their sum is"sum
|
||||
6
Task/Introspection/Logo/introspection.logo
Normal file
6
Task/Introspection/Logo/introspection.logo
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
show logoversion ; 5.6
|
||||
if logoversion < 6.0 [print [too old!]]
|
||||
|
||||
if and [name? "a] [number? :a] [
|
||||
print ifelse procedure? "abs [abs :a] [ifelse :a < 0 [minus :a] [:a]]
|
||||
]
|
||||
33
Task/Introspection/Logtalk/introspection.logtalk
Normal file
33
Task/Introspection/Logtalk/introspection.logtalk
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
:- object(my_application).
|
||||
|
||||
:- initialization((
|
||||
check_logtalk_version,
|
||||
compute_predicate_if_available
|
||||
)).
|
||||
|
||||
check_logtalk_version :-
|
||||
% version data is available by consulting the "version_data" flag
|
||||
current_logtalk_flag(version_data, logtalk(Major,Minor,Patch,_)),
|
||||
( (Major,Minor,Patch) @< (3,0,0) ->
|
||||
write('Logtalk version is too old! Please upgrade to version 3.0.0 or later'), nl,
|
||||
halt
|
||||
; true
|
||||
).
|
||||
|
||||
% Logtalk is not a functional language and thus doesn't support user-defined functions; we
|
||||
% use instead a predicate, abs/2, with a return argument to implement the abs/1 function
|
||||
compute_predicate_if_available :-
|
||||
( % check that the variable "bloop" is defined within this object
|
||||
current_predicate(bloop/1),
|
||||
% assume that the abs/2 predicate, if available, comes from a "utilities" object
|
||||
utilities::current_predicate(abs/2) ->
|
||||
bloop(Value),
|
||||
utilities::abs(Value, Result),
|
||||
write('Function value: '), write(Result), nl
|
||||
; write('Could not compute function!'), nl
|
||||
).
|
||||
|
||||
% our "bloop" variable value as per task description
|
||||
bloop(-1).
|
||||
|
||||
:- end_object.
|
||||
3
Task/Introspection/Lua/introspection.lua
Normal file
3
Task/Introspection/Lua/introspection.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if _VERSION:sub(5) + 0 < 5.1 then print"too old" end --_VERSION is "Lua <version>".
|
||||
|
||||
if bloop and math.abs then print(math.abs(bloop)) end
|
||||
21
Task/Introspection/MATLAB/introspection-1.m
Normal file
21
Task/Introspection/MATLAB/introspection-1.m
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
% convert version into numerical value
|
||||
v = version;
|
||||
v(v=='.')=' ';
|
||||
v = str2num(v);
|
||||
if v(2)>10; v(2) = v(2)/10; end;
|
||||
ver = v(1)+v(2)/10;
|
||||
if exist('OCTAVE_VERSION','builtin')
|
||||
if ver < 3.0,
|
||||
exit
|
||||
end;
|
||||
else
|
||||
if ver < 7.0,
|
||||
exit
|
||||
end;
|
||||
end
|
||||
|
||||
% test variable bloob, and test whether function abs is defined as m-function, mex-function or builtin-function
|
||||
if exist('bloob','var') && any(exist('abs')==[2,3,5])
|
||||
printf('abs(bloob) is %f\n',abs(bloob));
|
||||
return;
|
||||
end;
|
||||
15
Task/Introspection/MATLAB/introspection-2.m
Normal file
15
Task/Introspection/MATLAB/introspection-2.m
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
% find all integers
|
||||
varlist = whos;
|
||||
ix = [strmatch('int', {varlist.class}),strmatch('uint', {varlist.class})];
|
||||
intsumall = 0;
|
||||
intsum = 0;
|
||||
for k=1:length(ix)
|
||||
if prod(varlist(ix).size)==1,
|
||||
intsum = intsum + eval(varlist.name); % sum only integer scalars
|
||||
elseif prod(varlist(ix).size)>=1,
|
||||
tmp = eval(varlist.name);
|
||||
intsumall = intsumall + sum(tmp(:)); % sum all elements of integer array.
|
||||
end;
|
||||
end;
|
||||
printf('sum of integer scalars: %i\n',intsum);
|
||||
printf('sum of all integer elements: %i\n',intsumall);
|
||||
28
Task/Introspection/MAXScript/introspection.max
Normal file
28
Task/Introspection/MAXScript/introspection.max
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
fn computeAbsBloop bloop =
|
||||
(
|
||||
versionNumber = maxVersion()
|
||||
|
||||
if versionNumber[1] < 9000 then
|
||||
(
|
||||
print "Max version 9 required"
|
||||
return false
|
||||
)
|
||||
|
||||
if bloop == undefined then
|
||||
(
|
||||
print "Bloop is undefined"
|
||||
return false
|
||||
)
|
||||
|
||||
try
|
||||
(
|
||||
abs bloop
|
||||
)
|
||||
catch
|
||||
(
|
||||
print "No function abs"
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
computeAbsBloop -17
|
||||
2
Task/Introspection/Maple/introspection-1.maple
Normal file
2
Task/Introspection/Maple/introspection-1.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> kernelopts( 'version' );
|
||||
Maple 16.00, SUN SPARC SOLARIS, Mar 3 2012, Build ID 732982
|
||||
1
Task/Introspection/Maple/introspection-2.maple
Normal file
1
Task/Introspection/Maple/introspection-2.maple
Normal file
|
|
@ -0,0 +1 @@
|
|||
> if sscanf( (StringTools:-Split(kernelopts(version))[2]), "%d.%d" )[1] < 300 then `quit`(1) end;
|
||||
3
Task/Introspection/Maple/introspection-3.maple
Normal file
3
Task/Introspection/Maple/introspection-3.maple
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
> if type( bloop, complex( extended_numeric ) ) and type( abs, mathfunc ) then print( abs( bloop ) ) end:
|
||||
1/2
|
||||
13
|
||||
2
Task/Introspection/Maple/introspection-4.maple
Normal file
2
Task/Introspection/Maple/introspection-4.maple
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
> abs( bloop );
|
||||
| bloop |
|
||||
5
Task/Introspection/Maple/introspection-5.maple
Normal file
5
Task/Introspection/Maple/introspection-5.maple
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
> nops([anames](integer));
|
||||
3
|
||||
|
||||
> eval(`+`(anames(integer)));
|
||||
17
|
||||
6
Task/Introspection/Maple/introspection-6.maple
Normal file
6
Task/Introspection/Maple/introspection-6.maple
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
> foo := 25:
|
||||
> nops([anames](integer));
|
||||
4
|
||||
|
||||
> eval(`+`(anames(integer)));
|
||||
42
|
||||
3
Task/Introspection/Mathematica/introspection-1.math
Normal file
3
Task/Introspection/Mathematica/introspection-1.math
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
If[$VersionNumber < 8, Quit[]]
|
||||
If[NameQ["bloop"] && NameQ["Abs"],
|
||||
Print[Abs[bloop]]]
|
||||
2
Task/Introspection/Mathematica/introspection-2.math
Normal file
2
Task/Introspection/Mathematica/introspection-2.math
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
globalintegers = Symbol /@ Select[Names["Global`*"], IntegerQ[Symbol[#]] &];
|
||||
Print [ globalintegers //Length, " global integer(s) and their sum is: ", globalintegers // Total]
|
||||
18
Task/Introspection/Maxima/introspection.maxima
Normal file
18
Task/Introspection/Maxima/introspection.maxima
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* Get version information */
|
||||
build_info();
|
||||
/* build_info("5.27.0", "2012-05-08 11:27:57", "i686-pc-mingw32", "GNU Common Lisp (GCL)", "GCL 2.6.8") */
|
||||
|
||||
%@lisp_version;
|
||||
/* "GCL 2.6.8" */
|
||||
|
||||
/* One can only check for user-defined objects: functions, variables, macros, ...
|
||||
Hence we won't check for 'abs, which is built-in, but for 'weekday, defined elsewhere on RosettaCode.
|
||||
Here year, month and day are 2012, 05, 29. */
|
||||
|
||||
if subsetp({'year, 'month, 'day}, setify(values))
|
||||
and member('weekday, map(op, functions))
|
||||
then weekday(year, month, day)
|
||||
else 'bad\ luck;
|
||||
|
||||
/* Sum of integer variables */
|
||||
lreduce("+", sublist(map(ev, values), integerp));
|
||||
25
Task/Introspection/NetRexx/introspection.netrexx
Normal file
25
Task/Introspection/NetRexx/introspection.netrexx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* NetRexx */
|
||||
options replace format comments java crossref symbols binary
|
||||
|
||||
runSample(arg)
|
||||
return
|
||||
|
||||
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
method runSample(arg) private static
|
||||
parse arg minVersion .
|
||||
if minVersion = '' then minVersion = 2.0
|
||||
parse version lang ver bdate
|
||||
if ver < minVersion then do
|
||||
say -
|
||||
lang 'version' ver -
|
||||
'[Build date:' bdate']' -
|
||||
'is less than' minVersion.format(null, 2)'; exiting...'
|
||||
exit
|
||||
end
|
||||
else do
|
||||
say -
|
||||
lang 'version' ver -
|
||||
'[Build date:' bdate']' -
|
||||
'meets minimum requirements of' minVersion.format(null, 2)
|
||||
end
|
||||
return
|
||||
9
Task/Introspection/Nim/introspection.nim
Normal file
9
Task/Introspection/Nim/introspection.nim
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
when NimVersion < "1.2":
|
||||
error "This compiler is too old" # Error at compile time.
|
||||
|
||||
assert NimVersion >= "1.4", "This compiler is too old." # Assertion defect at runtime.
|
||||
|
||||
var bloop = -12
|
||||
|
||||
when compiles abs(bloop):
|
||||
echo abs(bloop)
|
||||
2
Task/Introspection/OCaml/introspection-1.ocaml
Normal file
2
Task/Introspection/OCaml/introspection-1.ocaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Sys.ocaml_version;;
|
||||
- : string = "3.10.2"
|
||||
3
Task/Introspection/OCaml/introspection-2.ocaml
Normal file
3
Task/Introspection/OCaml/introspection-2.ocaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# Scanf.sscanf (Sys.ocaml_version) "%d.%d.%d"
|
||||
(fun major minor micro -> major, minor, micro) ;;
|
||||
- : int * int * int = (3, 10, 2)
|
||||
12
Task/Introspection/Oforth/introspection.fth
Normal file
12
Task/Introspection/Oforth/introspection.fth
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
: bloopAbs
|
||||
| bl m |
|
||||
System.VERSION println
|
||||
|
||||
Word find("bloop") ->bl
|
||||
bl isA(Constant) ifFalse: [ "bloop constant does not exist" println return ]
|
||||
|
||||
"abs" asMethod ->m
|
||||
m ifNull: [ "abs method does not exist" println return ]
|
||||
|
||||
System.Out "bloop value is : " << bl value << cr
|
||||
System.Out "bloop abs is : " << bl value m perform << cr ;
|
||||
15
Task/Introspection/OxygenBasic/introspection.basic
Normal file
15
Task/Introspection/OxygenBasic/introspection.basic
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
$ rtlversion "0.4.0"
|
||||
'
|
||||
#if not match(rtlversion,o2version)
|
||||
#error "This RTL version mismatches o2 version "+o2version
|
||||
#else
|
||||
print o2version
|
||||
#endif
|
||||
|
||||
float bloop=-1618
|
||||
|
||||
#ifdef bloop
|
||||
#ifdef abs
|
||||
print abs(bloop)
|
||||
#endif
|
||||
#endif
|
||||
14
Task/Introspection/Oz/introspection.oz
Normal file
14
Task/Introspection/Oz/introspection.oz
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
declare
|
||||
Version = {Property.get 'oz.version'}
|
||||
%% Version is an atom like '1.4.0'. So we can not compare it directly.
|
||||
%% Extract the version components:
|
||||
[Major Minor Release] = {Map {String.tokens {Atom.toString Version} &.} String.toInt}
|
||||
in
|
||||
if Major >= 1 andthen Minor >= 4 then
|
||||
%% check whether module Number exports a value 'abs':
|
||||
if {HasFeature Number abs} then
|
||||
{Show {Number.abs ~42}}
|
||||
end
|
||||
else
|
||||
{System.showInfo "Your Mozart version is too old."}
|
||||
end
|
||||
3
Task/Introspection/PARI-GP/introspection.parigp
Normal file
3
Task/Introspection/PARI-GP/introspection.parigp
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
if(lex(version(), [2,4,3]) < 0, quit()); \\ Compare the version to 2.4.3 lexicographically
|
||||
|
||||
if(bloop!='bloop && type(abs) == "t_CLOSURE", abs(bloop))
|
||||
16
Task/Introspection/PHP/introspection.php
Normal file
16
Task/Introspection/PHP/introspection.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
if (version_compare(PHP_VERSION, '5.3.0', '<' ))
|
||||
{
|
||||
echo("You are using PHP Version " . PHP_VERSION . ". Please upgrade to Version 5.3.0\n");
|
||||
exit();
|
||||
}
|
||||
$bloop = -3;
|
||||
if (isset($bloop) && function_exists('abs'))
|
||||
{
|
||||
echo(abs($bloop));
|
||||
}
|
||||
echo(count($GLOBALS) . " variables in global scope.\n");
|
||||
echo(array_sum($GLOBALS) . " is the total of variables in global scope.\n");
|
||||
|
||||
?>
|
||||
3
Task/Introspection/PL-I/introspection-1.pli
Normal file
3
Task/Introspection/PL-I/introspection-1.pli
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
S = SYSVERSION();
|
||||
if substr(S, 6, 6) < '050000' then
|
||||
do; put skip list ('Version of compiler is too old'); stop; end;
|
||||
22
Task/Introspection/PL-I/introspection-2.pli
Normal file
22
Task/Introspection/PL-I/introspection-2.pli
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
*process source attributes options m or(!);
|
||||
/*********************************************************************
|
||||
* 02-11.2013 Walter Pachl
|
||||
* I modified this to run on my Windows PL/I
|
||||
*********************************************************************/
|
||||
v: Proc Options(main);
|
||||
%version: Proc Returns(char);
|
||||
Dcl res char;
|
||||
res=sysversion;
|
||||
Return(''''!!res!!'''');
|
||||
%End;
|
||||
%Act version;
|
||||
Dcl s char(31) Init('');
|
||||
s=version;
|
||||
if substr(S,15,3) < '7.5' then Do;
|
||||
put Skip list('Version of compiler ('!!substr(S,15,3)!!
|
||||
') is too old');
|
||||
stop;
|
||||
End;
|
||||
Else
|
||||
Put Skip List('Version is '!!s);
|
||||
End
|
||||
3
Task/Introspection/Perl/introspection-1.pl
Normal file
3
Task/Introspection/Perl/introspection-1.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
require v5.6.1; # run time version check
|
||||
require 5.6.1; # ditto
|
||||
require 5.006_001; # ditto; preferred for backwards compatibility
|
||||
3
Task/Introspection/Perl/introspection-2.pl
Normal file
3
Task/Introspection/Perl/introspection-2.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#$bloop = -123; # uncomment this line to see the difference
|
||||
no strict 'refs'; # referring to variable by name goes against 'strict' pragma
|
||||
if (defined($::{'bloop'})) {print abs(${'bloop'})} else {print "bloop isn't defined"};
|
||||
2
Task/Introspection/Perl/introspection-3.pl
Normal file
2
Task/Introspection/Perl/introspection-3.pl
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
eval('abs(0)'); # eval("") instead of eval{}; the latter is not for run-time check
|
||||
print "abs() doesn't seem to be available\n" if $@;
|
||||
8
Task/Introspection/Perl/introspection-4.pl
Normal file
8
Task/Introspection/Perl/introspection-4.pl
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
use Math::Complex;
|
||||
my $cpl = Math::Complex->new(1,1);
|
||||
|
||||
print "package Math::Complex has 'make' method\n"
|
||||
if Math::Complex->can('make');
|
||||
|
||||
print "object \$cpl does not have 'explode' method\n"
|
||||
unless $cpl->can('explode');
|
||||
13
Task/Introspection/Perl/introspection-5.pl
Normal file
13
Task/Introspection/Perl/introspection-5.pl
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use 5.010;
|
||||
our $bloop = -12;
|
||||
if (defined $::bloop) {
|
||||
if (eval { abs(1) }) {
|
||||
say 'abs($bloop) is ' . abs($::bloop);
|
||||
}
|
||||
else {
|
||||
say 'abs() is not available';
|
||||
}
|
||||
}
|
||||
else {
|
||||
say '$bloop is not defined';
|
||||
}
|
||||
16
Task/Introspection/Perl/introspection-6.pl
Normal file
16
Task/Introspection/Perl/introspection-6.pl
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
use 5.010;
|
||||
package test;
|
||||
use Regexp::Common;
|
||||
use List::Util qw(sum);
|
||||
|
||||
our $a = 7;
|
||||
our $b = 1;
|
||||
our $c = 2;
|
||||
our $d = -5;
|
||||
our $e = 'text';
|
||||
our $f = 0.25;
|
||||
|
||||
my @ints = grep { /^$RE{num}{int}$/ } map { $$_ // '' } values %::test::;
|
||||
my $num = @ints;
|
||||
my $sum = sum @ints;
|
||||
say "$num integers, sum = $sum";
|
||||
7
Task/Introspection/Perl/introspection-7.pl
Normal file
7
Task/Introspection/Perl/introspection-7.pl
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
use 5.010;
|
||||
use Regexp::Common;
|
||||
use List::Util qw(sum);
|
||||
my @ints = grep { /^$RE{num}{int}$/ } map { $$_ // '' } values %::;
|
||||
my $num = @ints;
|
||||
my $sum = sum @ints;
|
||||
say "$num integers, sum = $sum";
|
||||
5
Task/Introspection/Phix/introspection-1.phix
Normal file
5
Task/Introspection/Phix/introspection-1.phix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
-->
|
||||
<span style="color: #7060A8;">requires<span style="color: #0000FF;">(<span style="color: #008000;">"0.8.2"<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- crashes on 0.8.1 and earlier </span>
|
||||
<span style="color: #7060A8;">requires<span style="color: #0000FF;">(<span style="color: #000000;">WINDOWS<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- crashes on Linux </span>
|
||||
<span style="color: #7060A8;">requires<span style="color: #0000FF;">(<span style="color: #000000;">64<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- crashes on 32-bit
|
||||
<!--
|
||||
3
Task/Introspection/Phix/introspection-2.phix
Normal file
3
Task/Introspection/Phix/introspection-2.phix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
-->
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">version<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- eg "0.8.0"
|
||||
<!--
|
||||
9
Task/Introspection/Phix/introspection-3.phix
Normal file
9
Task/Introspection/Phix/introspection-3.phix
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
-->
|
||||
<span style="color: #000080;font-style:italic;">--include pmaths.e -- (an auto-include, ok but not needed)
|
||||
--include complex.e -- (not an auto-include, needed if used)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">r_abs</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">routine_id<span style="color: #0000FF;">(<span style="color: #008000;">"abs"<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000080;font-style:italic;">--integer r_abs = routine_id("complex_abs")</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">r_abs<span style="color: #0000FF;">!=<span style="color: #0000FF;">-<span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">call_func<span style="color: #0000FF;">(<span style="color: #000000;">r_abs<span style="color: #0000FF;">,<span style="color: #0000FF;">{<span style="color: #0000FF;">-<span style="color: #000000;">42<span style="color: #0000FF;">}<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if
|
||||
<!--
|
||||
115
Task/Introspection/Phix/introspection-4.phix
Normal file
115
Task/Introspection/Phix/introspection-4.phix
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
-->
|
||||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins<span style="color: #0000FF;">/<span style="color: #000000;">VM<span style="color: #0000FF;">/<span style="color: #000000;">pStack<span style="color: #0000FF;">.<span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- :%opGetST
|
||||
-- copies from pglobals.e:</span>
|
||||
<span style="color: #008080;">constant</span> <span style="color: #000000;">S_Name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- const/var/rtn name</span>
|
||||
<span style="color: #000000;">S_NTyp</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- Const/GVar/TVar/Nspc/Type/Func/Proc</span>
|
||||
<span style="color: #000000;">S_FPno</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- File and Path number</span>
|
||||
<span style="color: #000000;">S_Slink</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">6<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- scope/secondary chain (see below)</span>
|
||||
<span style="color: #000000;">S_vtype</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">7<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- variable type or namespace fileno</span>
|
||||
<span style="color: #000000;">S_GVar2</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">2<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- global or static variable</span>
|
||||
<span style="color: #000000;">T_int</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1<span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">T_EBP</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">22<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- compiled/listing=0, interpreted={ebp4,esp4,sym4} (set at last possible moment)</span>
|
||||
<span style="color: #000000;">T_ds4</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">23</span> <span style="color: #000080;font-style:italic;">-- compiled = start of data section, same but /4 when interpreted ([T_EBP]!=0)</span>
|
||||
|
||||
<span style="color: #008080;">function</span> <span style="color: #000000;">var_id<span style="color: #0000FF;">(<span style="color: #004080;">object</span> <span style="color: #000000;">s<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000080;font-style:italic;">-- hacked copy of routine_id(), for local file-level integers only</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">res<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- symidx for string s, else sum(local gvar integers)</span>
|
||||
<span style="color: #000000;">rtn<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- routine number of callee, from callstack</span>
|
||||
<span style="color: #000000;">cFno<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- calling fileno.</span>
|
||||
<span style="color: #000000;">tidx<span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">ds4</span>
|
||||
<span style="color: #004080;">object</span> <span style="color: #000000;">symtab<span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000000;">si<span style="color: #0000FF;">,</span> <span style="color: #000080;font-style:italic;">-- copy of symtab[i], speedwise</span>
|
||||
<span style="color: #000000;">si_name</span> <span style="color: #000080;font-style:italic;">-- copy of symtab[i][S_name], speedwise/thread-sfaety
|
||||
|
||||
-- get copy of symtab. NB read only! may contain nuts! (unassigned vars)</span>
|
||||
<span style="color: #000000;">enter_cs<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #000000;"> #ilASM{
|
||||
[32]
|
||||
lea edi,[symtab]
|
||||
call :%opGetST -- [edi]=symtab (ie our local:=the real symtab)
|
||||
mov edi,[ebp+20] -- prev_ebp
|
||||
mov edi,[edi+8] -- calling routine no
|
||||
mov [rtn],edi
|
||||
[64]
|
||||
lea rdi,[symtab]
|
||||
call :%opGetST -- [rdi]=symtab (ie our local:=the real symtab)
|
||||
mov rdi,[rbp+40] -- prev_ebp
|
||||
mov rdi,[rdi+16] -- calling routine no
|
||||
mov [rtn],rdi
|
||||
[]
|
||||
}</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">symtab<span style="color: #0000FF;">[<span style="color: #000000;">T_EBP<span style="color: #0000FF;">]<span style="color: #0000FF;">=<span style="color: #000000;">0</span> <span style="color: #008080;">then</span> <span style="color: #000080;font-style:italic;">-- compiled</span>
|
||||
<span style="color: #000000;">ds4</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">floor<span style="color: #0000FF;">(<span style="color: #000000;">symtab<span style="color: #0000FF;">[<span style="color: #000000;">T_ds4<span style="color: #0000FF;">]<span style="color: #0000FF;">/<span style="color: #000000;">4<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">else</span> <span style="color: #000080;font-style:italic;">-- interpreted</span>
|
||||
<span style="color: #000000;">ds4</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">symtab<span style="color: #0000FF;">[<span style="color: #000000;">T_ds4<span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #000000;">cFno</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">symtab<span style="color: #0000FF;">[<span style="color: #000000;">rtn<span style="color: #0000FF;">]<span style="color: #0000FF;">[<span style="color: #000000;">S_FPno<span style="color: #0000FF;">]</span> <span style="color: #000080;font-style:italic;">-- fileno of callee (whether routine or toplevel)</span>
|
||||
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #008080;">iff<span style="color: #0000FF;">(<span style="color: #000000;">s<span style="color: #0000FF;">=<span style="color: #000000;">0<span style="color: #0000FF;">?<span style="color: #000000;">0<span style="color: #0000FF;">:<span style="color: #0000FF;">-<span style="color: #000000;">1<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">for</span> <span style="color: #000000;">i<span style="color: #0000FF;">=<span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length<span style="color: #0000FF;">(<span style="color: #000000;">symtab<span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
|
||||
<span style="color: #000000;">si</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">symtab<span style="color: #0000FF;">[<span style="color: #000000;">i<span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #004080;">sequence<span style="color: #0000FF;">(<span style="color: #000000;">si<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">and</span> <span style="color: #000000;">si<span style="color: #0000FF;">[<span style="color: #000000;">S_NTyp<span style="color: #0000FF;">]<span style="color: #0000FF;">=<span style="color: #000000;">S_GVar2</span>
|
||||
<span style="color: #008080;">and</span> <span style="color: #000000;">si<span style="color: #0000FF;">[<span style="color: #000000;">S_FPno<span style="color: #0000FF;">]<span style="color: #0000FF;">=<span style="color: #000000;">cFno</span>
|
||||
<span style="color: #008080;">and</span> <span style="color: #000000;">si<span style="color: #0000FF;">[<span style="color: #000000;">S_vtype<span style="color: #0000FF;">]<span style="color: #0000FF;">=<span style="color: #000000;">T_int</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">si_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">si<span style="color: #0000FF;">[<span style="color: #000000;">S_Name<span style="color: #0000FF;">]</span>
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">s<span style="color: #0000FF;">=<span style="color: #000000;">0</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000080;font-style:italic;">-- cut-down version of pDiagN.e/getGvarValue():</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">gidx</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">si<span style="color: #0000FF;">[<span style="color: #000000;">S_Slink<span style="color: #0000FF;">]<span style="color: #0000FF;">,</span> <span style="color: #000000;">novalue<span style="color: #0000FF;">,</span> <span style="color: #000000;">o</span>
|
||||
#ilASM{
|
||||
mov [novalue],0
|
||||
[32]
|
||||
mov esi,[ds4]
|
||||
mov edx,[gidx]
|
||||
shl esi,2
|
||||
mov esi,[esi+edx*4+16] -- ([ds+(gidx+4)*4] == gvar[gidx])
|
||||
cmp esi,h4
|
||||
jl @f
|
||||
mov [novalue],1
|
||||
xor esi,esi
|
||||
@@:
|
||||
mov [o],esi
|
||||
[64]
|
||||
mov rsi,[ds4]
|
||||
mov rdx,[gidx]
|
||||
shl rsi,2
|
||||
mov rsi,[rsi+rdx*8+24] -- ([ds+(gidx+3)*8] == gvar[gidx])
|
||||
mov r15,h4
|
||||
cmp rsi,r15
|
||||
jl @f
|
||||
mov [novalue],1
|
||||
xor rsi,rsi
|
||||
@@:
|
||||
mov [o],rsi
|
||||
[]
|
||||
}
|
||||
<span style="color: #008080;">if</span> <span style="color: #000000;">novalue</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #0000FF;">{<span style="color: #000000;">si_name<span style="color: #0000FF;">,<span style="color: #008000;">"no_value"<span style="color: #0000FF;">}</span>
|
||||
<span style="color: #008080;">else</span>
|
||||
<span style="color: #000000;">res</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">o</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">elsif</span> <span style="color: #000000;">s<span style="color: #0000FF;">=<span style="color: #000000;">si_name</span> <span style="color: #008080;">then</span>
|
||||
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">i</span>
|
||||
<span style="color: #008080;">exit</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
|
||||
<span style="color: #000000;">si_name</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
<span style="color: #000000;">si</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
<span style="color: #000000;">symtab</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">0</span>
|
||||
<span style="color: #000000;">leave_cs<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span>
|
||||
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
|
||||
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
|
||||
|
||||
<span style="color: #0000FF;">{<span style="color: #0000FF;">}</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">routine_id<span style="color: #0000FF;">(<span style="color: #008000;">"blurgzmp"<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- force symtab name population..
|
||||
-- (alt: see rbldrqd in pDiagN.e)</span>
|
||||
<span style="color: #004080;">integer</span> <span style="color: #000000;">bloop</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">5<span style="color: #0000FF;">,</span>
|
||||
<span style="color: #000080;font-style:italic;">-- barf, -- triggers {"barf","no_value"}</span>
|
||||
<span style="color: #000000;">burp</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">35</span>
|
||||
<span style="color: #000000;">bloop</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">6</span>
|
||||
<span style="color: #000000;">burp</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #000000;">var_id<span style="color: #0000FF;">(<span style="color: #008000;">"bloop"<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- >0 === exists</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #000000;">var_id<span style="color: #0000FF;">(<span style="color: #008000;">"blooop"<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- -1 === does not exist</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #000000;">var_id<span style="color: #0000FF;">(<span style="color: #000000;">0<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- bloop+burp = 42</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #000000;">bloop<span style="color: #0000FF;">+<span style="color: #000000;">burp</span> <span style="color: #000080;font-style:italic;">-- "", doh
|
||||
<!--
|
||||
11
Task/Introspection/Phix/introspection-5.phix
Normal file
11
Task/Introspection/Phix/introspection-5.phix
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
-->
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">platform<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- WINDOWS=2, LINUX=3</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">machine_bits<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- 32 or 64</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">machine_word<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- 4 or 8</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">include_paths<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- eg {"C:\\Program Files (x86)\\Phix\\builtins\\",
|
||||
-- "C:\\Program Files (x86)\\Phix\\builtins\\VM\\",
|
||||
-- "C:\\Program Files (x86)\\Phix\\"}
|
||||
-- (plus other application-specific directories)</span>
|
||||
<span style="color: #0000FF;">?<span style="color: #7060A8;">get_interpreter<span style="color: #0000FF;">(<span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- eg "C:\Program Files (x86)\Phix\p.exe"
|
||||
-- or perhaps "/home/pete/phix/p" on Linux
|
||||
<!--
|
||||
1
Task/Introspection/Phixmonti/introspection.phixmonti
Normal file
1
Task/Introspection/Phixmonti/introspection.phixmonti
Normal file
|
|
@ -0,0 +1 @@
|
|||
_version 1.0 < if "Interpreter version is old" else "Last version" endif print
|
||||
9
Task/Introspection/PicoLisp/introspection.l
Normal file
9
Task/Introspection/PicoLisp/introspection.l
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(unless (>= (version T) (3 0 1)) # Check version (only in the 64-bit version)
|
||||
(bye) )
|
||||
|
||||
# (setq bloop -7) # Uncomment this to get the output '7'
|
||||
|
||||
(and
|
||||
(num? bloop) # When 'bloop' is bound to a number
|
||||
(getd 'abs) # and 'abs' defined as a function
|
||||
(println (abs bloop)) ) # then print the absolute value
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue