aseboboutique.blogg.se

Visual prolog ejemplos
Visual prolog ejemplos














Jnz short if not zeroed, continue popping args. Pop edx recover next argument from the stackĭec ecx decrement the remaining number_of_args loop to POP function-args after the call Mov ecx, get the function's number of args from if the called function had NO args, exit 'fcnt'Ĭall ecx call the (external) function (given in ARG-1) = ,ebx store the number_of_args in local var. Jz short if so, not yet the list's end, so repeat! Lodsd load element-flag of next list-element Mov esi,eax now ESI = (pointer-to-) next list-element Lodsd load the pointer to next list-element in EAX Push eax push it into the stack (for a function-call) Inc ebx increment ebx (counter for number_of_args) loop to read the (Visual-Prolog-) arg-list Lodsd load the 1st list-element's "element-flag"ĭec al decrement it, to check if it was a 1 Mov ,ebx initialize local variable 'fcnt' to 0 C:\TASM\BIN\TASM32.EXE /p /z /w2 /m2 /ml _apply_func.asm IDEALĪLIGN 4 public _apply_func (i,i) PROC _apply_func near

#Visual prolog ejemplos code

Code for TASM 5 Assembler, command-line call for compilation: OK, so here is the Assembly language code: = _apply_func.asm = %This program should produce " result = 60" (sum of ). % converts a predicate to a doubleword/addressįunc2dword(FUNC,DW):- DW = cast(dword,FUNC). % where arg-1 is a predicate-domain, such as "dom_iii"Īfter you compile the Assembly language code, you could create a simple “EasyWin” Visual Prolog project, with the following ines: PREDICATES (i,i,i) language c % <- example domain GLOBAL PREDICATESĪpply_func(DWORD,ListDomain) -(i,i) language c However, before you (even begin to) look at the Assembly Language Code, the following simple definitions in Visual Prolog (5.*) are a prerequisite for easier understanding: GLOBAL DOMAINSĭom_iii = determ INTEGER (INTEGER,INTEGER,INTEGER) If you understand Assembly Language and intend to use this code for other (meta-programming) tasks, all you have to do is modify just a couple of lines in the code that follows. The only difference between the way it works for Visual Prolog and the way it might work for another Prolog (or -indeed- ANY programming language, using a ‘C’-calling convention) is the Visual-Prolog-specific structure of a LIST, which in Visual Prolog has a different form than in all other languages. However, this does not exist in Visual Prolog, which sacrifices such “luxuries” for speed (which is the reason I also often use ISO-Prolog compilers, such as LPA-WinProlog and SWI-Prolog).Īnyway… The code you are about to see can be useful more generally, as an example of Prolog meta-programming, implemented in Assembly Language. Now, in ISO-Prolog there is a standard predicate known as “univ”, written as “ =.“, which turns a list like into a predicate call such as PRED(ARG1,ARG2,…). here is an Assembly language predicate, that takes as inputs another (external) predicate’s memory-address and a ( Visual Prolog-) argument-list, and calls this (external) predicate, using the (arbitrary-length-) list of N arguments, as arguments of “arity N”:Īpply_func(PRED, ) PRED(Arg1,Arg2,…) They also have an intrinsic fascination in themselves, as general tools for Prolog meta-programming.Į.g. Prolog even further, potentially valuable for a multitude of other purposes. Recently, I discovered some Assembly language techniques to enhance G.I.S. Code modifications could therefore be done very quickly and most mistakes were (semi-)automatically corrected by the interpreter’s own enhanced error-checking capabilities. Prolog produced immediate results, without any need for (often tedious) EXE-file compilation. Prolog for easy immediate experimentation: Coding in G.I.S. A multitude of extra predicates, implemented in pure Assembly language, became available through G.I.S. So, the only way to implement ISO-Prolog functionality in Visual Prologis to extend the “ PIE Interpreter” (and G.I.S. Of course, such attempts are inherently limited by the internal design of Visual Prolog compilers. Ever since I started using the Visual Prolog compilers (and the PDC Prolog compilers preceding them) I was fascinated by the possibilities of implementing additional ISO-Prolog functionality in Visual Prologthrough Assembly Language and ‘C’.














Visual prolog ejemplos