Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Reflection/Get_source
note: Reflection

View file

@ -0,0 +1,3 @@
;Task:
The goal is to get the source code or file path and line number where a programming object (e.g. module, class, function, method) is defined.
<br><br>

View file

@ -0,0 +1,33 @@
LDA #<foo
sta $00
LDA #>foo
sta $01
jsr PrintBytecode
foo:
;do stuff
rts
PrintBytecode:
ldy #0
lda $01 ;high byte of starting address of the source
jsr PrintHex
;unimplemented routine that separates the "nibbles" of the accumulator,
; adds $30 or $37 to each depending on if it's 0-9 or A-F respectively, which converts hex to ASCII,
; then prints the high nibble then the low.
lda $00 ;low byte of the starting address of the source
jsr PrintHex
jsr NewLine ;unimplemented new line routine
loop:
lda ($00),y
cmp #$60
beq Terminated
jsr PrintHex
jmp loop
Terminated:
jsr PrintHex ;print the last instruction of the routine.
rts

View file

@ -0,0 +1,5 @@
; Use source function for source code.
(source println)
; Use meta function for filenames and line numbers (and other metadata)
(meta #'println)

View file

@ -0,0 +1,4 @@
USE: see
\ integer see ! class
nl
\ dip see ! word

View file

@ -0,0 +1,2 @@
USE: accessors
\ partition def>> .

View file

@ -0,0 +1,2 @@
USE: accessors
\ dip vocabulary>> print

View file

@ -0,0 +1,2 @@
USE: vocabs.files
"sequences" vocab-files .

View file

@ -0,0 +1 @@
"loc" \ dip props>> at

View file

@ -0,0 +1,8 @@
' FB 1.05.0 Win64 (getsource.bas)
Sub Proc()
Print __Function__ & " is defined in " & __Path__ & "\" & __File__ & " at line " & ( __line__ - 1)
End Sub
Proc()
Sleep

View file

@ -0,0 +1,22 @@
package main
import (
"fmt"
"path"
"reflect"
"runtime"
)
func someFunc() {
fmt.Println("someFunc called")
}
func main() {
pc := reflect.ValueOf(someFunc).Pointer()
f := runtime.FuncForPC(pc)
name := f.Name()
file, line := f.FileLine(pc)
fmt.Println("Name of function :", name)
fmt.Println("Name of file :", path.Base(file))
fmt.Println("Line number :", line)
}

View file

@ -0,0 +1,13 @@
mean=:+/ %#
5!:5 <'mean'
+/ % #
5!:6 <'mean'
(+/) % #
4!:4 <'mean'
_1
4!:4 <'names'
2
2 { 4!:3 ''
┌────────────────────────────────────────────┐
│/Applications/j64-804/system/main/stdlib.ijs│
└────────────────────────────────────────────┘

View file

@ -0,0 +1,2 @@
linrep=: 5!:5@<
srcfile=: (4!:4@<) { a:,~ 4!:3 bind ''

View file

@ -0,0 +1,10 @@
linrep 'names'
list_z_@nl
srcfile 'names'
┌────────────────────────────────────────────┐
│/Applications/j64-804/system/main/stdlib.ijs│
└────────────────────────────────────────────┘
srcfile 'mean'
┌┐
││
└┘

View file

@ -0,0 +1,28 @@
public class ReflectionGetSource {
public static void main(String[] args) {
new ReflectionGetSource().method1();
}
public ReflectionGetSource() {}
public void method1() {
method2();
}
public void method2() {
method3();
}
public void method3() {
Throwable t = new Throwable();
for ( StackTraceElement ste : t.getStackTrace() ) {
System.out.printf("File Name = %s%n", ste.getFileName());
System.out.printf("Class Name = %s%n", ste.getClassName());
System.out.printf("Method Name = %s%n", ste.getMethodName());
System.out.printf("Line number = %s%n%n", ste.getLineNumber());
}
}
}

View file

@ -0,0 +1,3 @@
function foo() {...}
foo.toString();
// "function foo() {...}"

View file

@ -0,0 +1,2 @@
Math.sqrt.toString();
// "function sqrt() { [native code] }"

View file

@ -0,0 +1,5 @@
# Definition
function foo() end
@which foo() # where foo is defined
@less foo() # first file where foo is defined

View file

@ -0,0 +1,10 @@
// Kotlin JS Version 1.2.31
fun hello() {
println("Hello")
}
fun main(args: Array<String>) {
val code = js("_.hello.toString()")
println(code)
}

View file

@ -0,0 +1,25 @@
----------------------------------------
-- Returns source code either for a class (parent script) or a class instance (object)
-- @param {script|instance} class
-- @return {string}
----------------------------------------
on getClassCode (class)
if ilk(class)=#instance then class=class.script
return class.text
end
----------------------------------------
-- Returns the source code of the movie script that defines the specified global function
-- @param {symbol} func - function specified as symbol
-- @return {string|VOID}
----------------------------------------
on getGlobalFunctionCode (func)
-- iterate over all members in all castlibs
repeat with i = 1 to _movie.castlib.count
repeat with j = 1 to _movie.castlib[i].member.count
m = _movie.castlib[i].member[j]
if m.type<>#script then next repeat
if m.scriptType=#movie and m.script.handler(func) then return m.script.text
end repeat
end repeat
end

View file

@ -0,0 +1,7 @@
obj = script("MyClass").new()
put getClassCode(obj)
-- script text is printed...
func = #startMovie
put getGlobalFunctionCode(func)
-- script text is printed...

View file

@ -0,0 +1,6 @@
debug = require("debug")
function foo(bar)
info = debug.getinfo(1)
for k,v in pairs(info) do print(k,v) end
end
foo()

View file

@ -0,0 +1,2 @@
import Nanoquery.IO
println new(File, __file__).readAll()

View file

@ -0,0 +1,13 @@
import macros, strformat
proc f(arg: int): int = arg+1
macro getSource(source: static[string]) =
let module = parseStmt(source)
for node in module.children:
if node.kind == nnkProcDef:
echo(&"source of procedure {node.name} is:\n{toStrLit(node).strVal}")
proc g(arg: float): float = arg*arg
getSource(staticRead(currentSourcePath()))

View file

@ -0,0 +1,8 @@
# 20211213 Perl programming solution
use strict;
use warnings;
use Class::Inspector;
print Class::Inspector->resolved_filename( 'IO::Socket::INET' ), "\n";

View file

@ -0,0 +1,3 @@
import os
os.__file__
# "/usr/local/lib/python3.5/os.pyc"

View file

@ -0,0 +1,12 @@
/*REXX program gets the source function (source code) and */
/*───────────────────────── displays the number of lines. */
#=sourceline()
do j=1 for sourceline()
say 'line' right(j, length(#) ) '' ,
strip( sourceline(j), 'T')
end /*j*/
say
parse source x y sID
say 'The name of the source file (program) is: ' sID
say 'The number of lines in the source program: ' #
/*stick a fork in it, we're all done.*/

View file

@ -0,0 +1,2 @@
say &sum.file;
say Date.^find_method("day-of-week").file;

View file

@ -0,0 +1,27 @@
# Project : Reflection/Get source
fp = fopen("C:\Ring\applications\fifteenpuzzle\CalmoSoftFifteenPuzzleGame.ring","r")
r = ""
str = ""
flag = 0
numline = 0
see "give the function: "
give funct
funct = "func " + funct
while isstring(r)
r = fgetc(fp)
if r = char(10)
flag = 1
numline = numline + 1
else
flag = 0
str = str + r
ok
if flag = 1
if left(str,len(funct)) = funct
see '"' + funct + '"' +" is in the line: " + numline + nl
ok
str = ""
ok
end
fclose(fp)

View file

@ -0,0 +1,6 @@
require 'mathn'
Math.method(:sqrt).source_location
# ["/usr/local/lib/ruby2.3/2.3.0/mathn.rb", 119]
Class.method(:nesting).source_location
# nil, since Class#nesting is native

View file

@ -0,0 +1 @@
mthd := someClass compiledMethodAt:#nameOfMethod

View file

@ -0,0 +1 @@
mthd source

View file

@ -0,0 +1,2 @@
thisContext method source
thisContext lineNumber

View file

@ -0,0 +1,15 @@
proc getproc {name} {
set name [uplevel 1 [list namespace which -command $name]]
set args [info args $name]
set args [lmap arg $args { ;# handle default arguments, if it has them!
if {[info default $name $arg default]} {
list $name $default
} else {
return -level 0 $arg
}
}]
set body [info body $name]
list proc $name $args $body
}
puts [getproc getproc]

View file

@ -0,0 +1,13 @@
proc ::getproc name {
set name [uplevel 1 [list namespace which -command $name]]
set args [info args $name]
set args [lmap arg $args { ;# handle default arguments, if it has them!
if {[info default $name $arg default]} {
list $name $default
} else {
return -level 0 $arg
}
}]
set body [info body $name]
list proc $name $args $body
}

View file

@ -0,0 +1,31 @@
import "os" for Platform, Process
import "io" for File
import "/pattern" for Pattern
var getSourceLines = Fn.new {
var fileName = Process.allArguments[1]
var text = File.read(fileName)
var sep = Platform.isWindows ? "\r\n" : "\n"
return [fileName, text.split(sep)]
}
var res = getSourceLines.call()
var fileName = res[0]
var lines = res[1]
// look for getSourceLines function
var funcName = "getSourceLines"
var p = Pattern.new("+1/s")
var i = 1
var found = 0
for (line in lines) {
var t = p.splitAll(line.trim())
if (t[0] == "var" && t[1] == funcName && t[2] == "=" && t[3] == "Fn.new") {
found = i
break
}
i = i + 1
}
System.print("File name : %(fileName)")
System.print("Function name : %(funcName)")
System.print("Line number : %(found > 0 ? found : "Function not found")")

View file

@ -0,0 +1,2 @@
src:=File(__FILE__).read();
println("Src file is \"%s\" and has %d lines".fmt(__FILE__,src.len(1)));