-SUBDIRS = src include examples
+SUBDIRS = src include
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess \
config.h.in config.sub configure install-sh \
debian/control \
debian/copyright \
debian/embryo0-bin.install \
- debian/embryo0-debug.install \
debian/libembryo0-dev.install \
debian/libembryo0.install \
debian/rules
Makefile
embryo.pc
include/Makefile
-examples/Makefile
src/Makefile
src/lib/Makefile
src/bin/Makefile
Description: SMALL compiler creating Embryo bytecode
This package contains the compiler embryo_cc.
-Package: embryo0-debug
-Section: devel
-Architecture: any
-Provides: embryo-debug
-Depends: ${shlibs:Depends}
-Description: Debugging execution utility for embryo compiled bytecode.
- This package contains the debugging utility.
-
Package: libembryo0-dev
Section: libdevel
Architecture: any
+++ /dev/null
-debian/tmp/usr/bin/embryo
-debian/tmp/usr/share/embryo/examples/*.inc
-debian/tmp/usr/share/embryo/examples/*.sma
%description bin
The embryo bytecode compiler and its files
-%package debug
-Summary: Embryo debug utilities
-Group: System Environment/Libraries
-Requires: %{name} = %{version}
-
-%description debug
-Debug utilities for embryo
-
%prep
%setup -q
%attr(755,root,root) %{_bindir}/embryo_cc
%{_datadir}/embryo/include
-%files debug
-%defattr(-, root, root)
-%attr(755,root,root) %{_bindir}/embryo
-%{_datadir}/embryo/examples
-
%files devel
%defattr(-, root, root)
%{_libdir}/*.so
+++ /dev/null
-Makefile
-Makefile.in
-*.amx
+++ /dev/null
-MAINTAINERCLEANFILES = Makefile.in
-
-filesdir = $(datadir)/embryo/examples
-files_DATA = \
-test.inc \
-test.sma \
-example.inc \
-example.sma \
-recurse.inc \
-recurse.sma
-
-EXTRA_DIST = $(files_DATA)
-
+++ /dev/null
-#if defined EXAMPLE_INC
-#endinput
-#endif
-#define EXAMPLE_INC
-
-native printf(format[], ...);
+++ /dev/null
-#include "example.inc"
-
-/* To compile:
- * embryo_cc ./example.sma -o example.amx
- *
- * To test run:
- * embryo ./example.amx
- */
-
-public global1 = 99;
-public global2 = 77;
-
-main()
-{
- new Float:t;
-
- testfn(12345, "Panties!!!!", 7);
- t = seconds();
- printf("SECONDS = %f\n", t);
- testdate();
- return 77;
-}
-
-testdate()
-{
- new year, month, day, yearday, weekday, hour, minute;
- new Float:second;
-
- date(year, month, day, yearday, weekday, hour, minute, second);
- printf("%i/%i/%i\n", day, month, year);
- printf("%i:%i:%f\n", hour, minute, second);
- printf("yearday: %i, weekday: %i\n", yearday, weekday);
- printf("frand: %f\n", randf());
- printf("rand: %X\n", rand());
-}
-
-tester(arg1=0, str[]="", arg2=0)
-{
- if (arg1 == 7) printf("arg1 == 7!!!\n");
- printf(" TESTER: arg1=%i str='%s' arg2=%i\n", arg1, str, arg2);
-}
-
-public testfn(arg1, str[], arg2)
-{
- new a = 10;
- new Float:b = 20.0;
-
- printf("arg1=%i str='%s' arg2=%i\n", arg1, str, arg2);
-
- printf("float test %i %f\n", a, b);
-
- tester(77, "blahdieblah", 1024);
- if (arg1 == 7) printf("arg1 == 7!!!\n");
-
- return 5;
-}
-
+++ /dev/null
-#if defined EXAMPLE_INC
-#endinput
-#endif
-#define EXAMPLE_INC
-
-native printf(format[], ...);
-native native_rec(arg1, str[], arg2);
+++ /dev/null
-#include "recurse.inc"
-
-/* To compile:
- * embryo_cc ./recurse.sma -o recurse.amx
- *
- * To test run:
- * embryo ./recurse.amx
- */
-
-main()
-{
- new ret = 0;
-
- ret = rec1(1, "Recurse Test", 123);
- return ret;
-}
-
-public rec1(arg1, str[], arg2)
-{
- new ret = 0;
-
- printf("rec1(arg1=%i, str='%s', arg2=%i);\n", arg1, str, arg2);
- ret = native_rec(arg1, str, arg2 * 2);
- return ret;
-}
+++ /dev/null
-#if defined TEST_INC
-#endinput
-#endif
-#define TEST_INC
-
-native printf(format[], ...);
-native native_rec(arg1, str[], arg2);
+++ /dev/null
-#include "test.inc"
-
-/* This is ugly - please ignore this code! */
-
-/* To compile:
- * embryo_cc ./test.sma -o test.amx
- *
- * To test run:
- * embryo ./test.amx
- */
-
-public global1 = 99;
-public global2 = 77;
-
-main()
-{
- printf("Testing switch and case statements...\n");
-
- new var;
-
- for (var = 1; var < 5; var++)
- {
- switch (var)
- {
- case 0:
- printf("It's 0\n");
- case 1:
- printf("It's 1\n");
- case 2:
- printf("It's 2\n");
- case 3:
- printf("It's 3\n");
- case 4:
- printf("It's 4\n");
- case 5:
- printf("It's 5\n");
- case 6:
- printf("It's 6\n");
- case 7:
- printf("It's 7\n");
- default:
- printf("It's something else\n");
- }
- }
- printf("\n\n");
- printf("Testing for loops...\n");
- for (var = 0; var < 10; var++)
- {
- printf("Var = %i\n", var);
- }
-
- printf("\n\n");
- printf("Testing recursion...\n");
- var = recurse(3);
- printf("var = %i\n", var);
-
- printf("\n\n");
- printf("Testing while loops...\n");
- var = 7;
- while (var > 1)
- {
- printf("var = %i\n", var);
- var--;
- }
-
- printf("\n\n");
- printf("Testing Float Math...\n");
- new Float:a;
- new Float:b;
- new Float:c;
-
- c = 10.5;
- printf("c = %f (should be 10.5)\n", c);
- a = 5.0;
- b = 2.345;
- c = a + b;
- printf("a = %f (should be 5.0)\n", a);
- printf("b = %f (should be 2.345)\n", b);
- printf("a + b = %f (should be 7.345)\n", c);
- a = 2.5;
- b = 3.5;
- c = a * b;
- printf("a = %f (should be 2.5)\n", a);
- printf("b = %f (should be 3.5)\n", b);
- printf("a 8 b = %f (should be 8.75)\n", c);
- a = 5.5;
- b = 1.5;
- c = a / b;
- printf("a = %f (should be 5.5)\n", a);
- printf("b = %f (should be 1.5)\n", b);
- printf("a / b = %f (should be 3.666666667)\n", c);
-
- printf("The printf() call is a native exported function. This should work\n");
- printf("Calling testfn()...\n");
-
- new ret;
- ret = testfn(12345, "A Test String", 7);
- printf("Done. Return value of testfn() was %i\n", ret);
-
- printf("Test varargs...\n");
- vargs(1, 2, "hello", "there", 8, 77, 5.0, 7.77);
-
- printf("\n\n");
-
- printf("native_rec(1, 77)\n");
- native_rec(1, "Smelly", 77);
- printf("native_rec() done\n");
-
- printf("atoi(\"7\") = %i\n", atoi("7"));
-
- return 7;
-}
-
-public rec1(arg1, str[], arg2)
-{
- printf("arg1=%i str=%s arg2=%i\n", arg1, str, arg2);
- return native_rec(arg1 + 1, str, arg2);
-}
-
-vargs(a, b, ...)
-{
- printf("ARGS...\n");
- printf(" a = %i\n", a);
- printf(" b = %i\n", b);
- for (new i = 2; i < numargs(); i++)
- {
- new val;
- new Float:fval;
- new str[100];
-
- printf(" GET ARG... %i\n", i);
- if (i < 4)
- {
- getsarg(i, str, sizeof(str));
- printf(" ARG: %s [max %i]\n", str, sizeof(str));
- }
- else if (i < 6)
- {
- val = getarg(i);
- printf(" ARG: %i\n", val);
- }
- else if (i < 8)
- {
- fval = getfarg(i);
- printf(" FARG: %f\n", fval);
- }
- }
- printf("ARGS DONE.\n");
-}
-
-recurse(val)
-{
- printf("Recurse: val = %i\n", val);
- if (val >= 10) return val;
- return recurse(val + 1);
-}
-
-tester(arg1=0, str[]="", arg2=0)
-{
- if (arg1 == 7) printf("arg1 == 7!!!\n");
- printf(" TESTER: arg1=%i str='%s' arg2=%i\n", arg1, str, arg2);
-}
-
-public testfn(arg1, str[], arg2)
-{
- new a = 10;
- new Float:b = 20.0;
-
- printf("arg1=%i str='%s' arg2=%i\n", arg1, str, arg2);
-
- printf("float test %i %f\n", a, b);
-
- tester(77, "blahdieblah", 1024);
- if (arg1 == 7) printf("arg1 == 7!!!\n");
-
- return 5;
-}
-DPACKAGE_LIB_DIR=\"@PACKAGE_LIB_DIR@\" \
-DPACKAGE_DATA_DIR=\"@PACKAGE_DATA_DIR@\"
-bin_PROGRAMS = embryo embryo_cc
-
-embryo_SOURCES = \
-embryo_main.c
-
-embryo_LDADD = $(top_builddir)/src/lib/libembryo.la
-embryo_DEPENDENCIES = $(top_builddir)/src/lib/libembryo.la
+bin_PROGRAMS = embryo_cc
embryo_cc_SOURCES = \
embryo_cc_amx.h \
+++ /dev/null
-#include "Embryo.h"
-#include "config.h"
-
-/* This is ugly code! don't look at it please! i am embarrassed! i need to */
-/* cleanit up! */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <limits.h>
-#include <stdarg.h>
-#include <string.h>
-
-#if HAVE_ALLOCA_H
-# include <alloca.h>
-#endif
-
-/* debugging native calls */
-static int process_format_char(Embryo_Program *ep, char ch, Embryo_Cell param);
-static int process_escape_char(Embryo_Program *ep, char ch);
-static int custom_printf(Embryo_Program *ep, Embryo_Cell *cstr, Embryo_Cell *params, int num);
-
-static Embryo_Cell exported_printf(Embryo_Program *ep, Embryo_Cell *params);
-
-static int
-process_format_char(Embryo_Program * ep, char ch, Embryo_Cell param)
-{
- Embryo_Cell *cptr;
-
- switch (ch)
- {
- case '%':
- putchar(ch);
- return 0;
- case 'c':
- cptr = embryo_data_address_get(ep, param);
- if (cptr) putchar((int) *cptr);
- return 1;
- case 'i':
- case 'd':
- cptr = embryo_data_address_get(ep, param);
- if (cptr) printf("%i", (int) *cptr);
- return 1;
- case 'x':
- cptr = embryo_data_address_get(ep, param);
- if (cptr) printf("%x", (unsigned int) *cptr);
- return 1;
- case 'f':
- cptr = embryo_data_address_get(ep, param);
- if (cptr) printf("%f", (float)(*(float *)cptr));
- return 1;
- case 'X':
- cptr = embryo_data_address_get(ep, param);
- if (cptr) printf("%08x", (unsigned int) *cptr);
- return 1;
- case 's':
- cptr = embryo_data_address_get(ep, param);
- if (cptr) custom_printf(ep, cptr, NULL, 0);
- return 1;
- }
- putchar(ch);
- return 0;
-}
-
-static int
-process_escape_char(Embryo_Program * ep, char ch)
-{
- switch (ch)
- {
- case 'n':
- putchar('\n');
- return 1;
- case 't':
- putchar('\t');
- return 1;
- }
- putchar(ch);
- return 0;
-}
-
-static int
-custom_printf(Embryo_Program * ep, Embryo_Cell *cstr, Embryo_Cell *params, int num)
-{
- int i;
- int informat = 0, paramidx = 0, inesc = 0, len = 0;
- char c;
- char *str;
-
- i = 0;
- len = embryo_data_string_length_get(ep, cstr);
- str = alloca(len + 1);
- embryo_data_string_get(ep, cstr, str);
- for (i = 0;; i++)
- {
- c = (char) (str[i]);
- if (c == 0)
- break;
- if (informat)
- {
- paramidx += process_format_char(ep, c, params[paramidx]);
- informat = 0;
- }
- else if (inesc)
- {
- process_escape_char(ep, c);
- inesc = 0;
- }
- else if ((params != NULL) && (c == '%'))
- {
- informat = 1;
- }
- else if ((params != NULL) && (c == '\\'))
- {
- inesc = 1;
- }
- else
- {
- putchar(c);
- }
- }
- return EMBRYO_ERROR_NONE;
-}
-
-static Embryo_Cell
-exported_printf(Embryo_Program *ep, Embryo_Cell *params)
-{
- Embryo_Cell *cptr;
-
- cptr = embryo_data_address_get(ep, params[1]);
- custom_printf(ep, cptr, params + 2, (int) (params[0] / sizeof(Embryo_Cell)) - 1);
- return EMBRYO_ERROR_NONE;
-}
-
-static Embryo_Cell
-exported_rec(Embryo_Program *ep, Embryo_Cell *params)
-{
- Embryo_Function fn;
- Embryo_Cell ret = 0, arg1, arg2;
-
- // params[0] = number of bytes of params passed
- if (params[0] != 3 * sizeof(Embryo_Cell)) return -1;
- arg1 = params[1];
- arg2 = params[3];
- arg1++;
-
- if (arg1 > 7)
- {
- printf("arg1 == %i\n", arg1);
- return arg1;
- }
-
- // call the rec1 again
- fn = embryo_program_function_find(ep, "rec1");
- if (fn != EMBRYO_FUNCTION_NONE)
- {
- char buf[128];
-
- printf("... recurse!\n");
- snprintf(buf, sizeof(buf), "SMELLY %i", arg1);
- embryo_parameter_cell_push(ep, arg1);
- embryo_parameter_string_push(ep, buf);
- embryo_parameter_cell_push(ep, arg2);
- while (embryo_program_run(ep, fn) == EMBRYO_PROGRAM_SLEEP);
- ret = embryo_program_return_value_get(ep);
- }
- return ret + 1;
-}
-
-/* another example native call */
-/*
-static Embryo_Cell
-exported_call(Embryo_Program *ep, Embryo_Cell *params)
-{
- Embryo_Cell *cptr;
-
- // params[0] = number of bytes of params passed
- cptr = embryo_data_address_get(ep, params[1]);
- if (cptr)
- {
- char buf[4096];
-
- buf[0] = 0;
- printf("..");
- embryo_data_string_get(ep, cptr, buf);
- printf("OUT: \"%s\"", buf);
- }
- cptr = embryo_data_address_get(ep, params[3]);
- if (cptr)
- {
- char buf[4096];
-
- buf[0] = 0;
- embryo_data_string_get(ep, cptr, buf);
- printf(" \"%s\"", buf);
- }
- {
- int v;
-
- v = params[3];
- printf(" %i", v);
- }
- printf("\n");
- return 10;
-}
-*/
-
-int
-main(int argc,char *argv[])
-{
- Embryo_Program *ep;
- Embryo_Function fn;
- int i;
- int r = EMBRYO_PROGRAM_OK;
- int err;
- int args = 0;
- int instruct = 0;
- char *file = NULL;
- char *func = NULL;
-
- embryo_init();
- for (i = 1; i < argc; i++)
- {
- if (argv[i][0] != '-')
- {
- file = argv[i];
- if (i < (argc - 1)) args = i + 1;
- break;
- }
- else if (!strcmp(argv[i], "-func"))
- {
- if (i < (argc - 1))
- {
- i++;
- func = argv[i];
- }
- }
- }
- if ((argc < 2) || (!file))
- {
- printf("Usage: %s [options] <filename> [parameters]\n"
- "Where options can be any of:\n"
- "\t-func name execute function \"name\" to start\n"
- , argv[0]);
- exit(-1);
- }
- ep = embryo_program_load(file);
- if (!ep)
- {
- printf("Cannot load %s\n", file);
- exit(-1);
- }
- embryo_program_native_call_add(ep, "printf", exported_printf);
- embryo_program_native_call_add(ep, "native_rec", exported_rec);
- embryo_program_vm_push(ep);
-
- if (args > 0)
- {
- for (i = args; i < argc; i++)
- {
- if (argv[i][0] == 's')
- embryo_parameter_string_push(ep, argv[i] + 1);
- else if (argv[i][0] == 'i')
- {
- Embryo_Cell n;
-
- n = atoi(argv[i] + 1);
- embryo_parameter_cell_push(ep, n);
- }
- else if (argv[i][0] == 'f')
- {
- float n;
- Embryo_Cell c;
-
- n = atof(argv[i] + 1);
- c = EMBRYO_FLOAT_TO_CELL(n);
- embryo_parameter_cell_push(ep, c);
- }
- }
- }
- r = EMBRYO_PROGRAM_OK;
- fn = EMBRYO_FUNCTION_MAIN;
- if (func)
- {
- fn = embryo_program_function_find(ep, func);
- if (fn == EMBRYO_FUNCTION_NONE)
- {
- printf("Unable to find public function %s()\n"
- "Executing main() instead\n", func);
- fn = EMBRYO_FUNCTION_MAIN;
- }
- }
- if (!getenv("NOMAX"))
- embryo_program_max_cycle_run_set(ep, 100000000);
- for (;;)
- {
- r = embryo_program_run(ep, fn);
- if (r == EMBRYO_PROGRAM_SLEEP)
- {
- fn = EMBRYO_FUNCTION_CONT;
- printf("SLEEP INSTRUCTION!\n");
- continue;
- }
- else if (r == EMBRYO_PROGRAM_TOOLONG)
- {
- fn = EMBRYO_FUNCTION_CONT;
- instruct++;
- printf("Executed %i00 million instructions!\n", instruct);
- continue;
- }
- else
- break;
- }
- embryo_program_vm_pop(ep);
- if (r == EMBRYO_PROGRAM_FAIL)
- {
- printf("Run failed!\n");
- err = embryo_program_error_get(ep);
- if (err != EMBRYO_ERROR_NONE)
- {
- printf("Run time error %d: \"%s\"\n", err, embryo_error_string_get(err));
- exit(-1);
- }
- }
- printf("Program returned %i\n", (int)embryo_program_return_value_get(ep));
- embryo_program_free(ep);
- embryo_shutdown();
- return 0;
-}