about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-20 10:13:58 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-20 10:13:58 -0800
commit8a3e81b4b0d8365baa40ff1326ed4d13b34506dc (patch)
treea9ad614d6769c8e26c5ddabd9ed8175866992b41 /src
parente693448b65721843e3d8dbfc978a9e4a95de5809 (diff)
downloadteliva-8a3e81b4b0d8365baa40ff1326ed4d13b34506dc.tar.gz
report errors when calling non-existent functions
Diffstat (limited to 'src')
-rw-r--r--src/lua.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/lua.c b/src/lua.c
index 8d3a1a4..61836e6 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -295,11 +295,13 @@ static int handle_image (lua_State *L, char **argv, int n) {
   for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) {
     const char* key = lua_tostring(L, -2);
     const char* value = lua_tostring(L, -1);
-    dostring(L, value, key);
+    status = dostring(L, value, key);
+    if (status != 0) return report(L, status);
   }
   /* call main() */
   lua_getglobal(L, "main");
-  docall(L, 0, 1);
+  status = docall(L, 0, 1);
+  if (status != 0) return report(L, status);
   return 0;
 }
 
lor: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Some OS-specific preliminaries for Linux.

# Memory layout
#
#          0 - 0x08047ffff - reserved for the kernel
# 0x08048000 - 0xbffffffff - available for user programs
# 0xc0000000 - 0xfffffffff - reserved for the kernel
== code 0x09000000
== data 0x0a000000

# Syscalls
#
# We don't have libc, so we need to know Linux's precise syscall layout.
# These are not real functions. Pass arguments in specific registers.
== code

# http://man7.org/linux/man-pages/man2/exit.2.html
syscall_exit:  # status/ebx: int
    b8/copy-to-eax 1/imm32
    cd/syscall 0x80/imm8

# http://man7.org/linux/man-pages/man2/read.2.html
syscall_read:  # fd/ebx: int, buf/ecx: addr, size/edx: int -> nbytes-or-error/eax: int
    b8/copy-to-eax 3/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/write.2.html
syscall_write:  # fd/ebx: int, buf/ecx: addr, size/edx: int -> nbytes-or-error/eax: int
    b8/copy-to-eax 4/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/open.2.html
syscall_open:  # filename/ebx: (addr kernel-string), flags/ecx: int, dummy=0x180/edx -> fd-or-error/eax: int
    b8/copy-to-eax 5/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/close.2.html
syscall_close:  # fd/ebx: int -> status/eax
    b8/copy-to-eax 6/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/lseek.2.html
syscall_lseek:  # fd/ebx: int, offset/ecx: int, whence/edx: int
    b8/copy-to-eax 0x13/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/creat.2.html
syscall_creat:  # filename/ebx: (addr kernel-string) -> fd-or-error/eax: int
    b8/copy-to-eax 8/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/unlink.2.html
syscall_unlink:  # filename/ebx: (addr kernel-string) -> status/eax: int
    b8/copy-to-eax 0xa/imm32
    cd/syscall 0x80/imm8
    c3/return

# http://man7.org/linux/man-pages/man2/rename.2.html
syscall_rename:  # source/ebx: (addr kernel-string), dest/ecx: (addr kernel-string) -> status/eax: int
    b8/copy-to-eax 0x26/imm32
    cd/syscall 0x80/imm8
    c3/return

# https://github.com/torvalds/linux/blob/fa121bb3fed6313b1f0af23952301e06cf6d32ed/mm/nommu.c#L1352
syscall_mmap:  # arg/ebx: (addr mmap_arg_struct) -> status/eax: int
    # the important thing: ebx+4 contains the 32-bit size to be allocated
    b8/copy-to-eax 0x5a/imm32
    cd/syscall 0x80/imm8
    c3/return

syscall_ioctl:  # fd/ebx: int, cmd/ecx: int, arg/edx: (addr _)
    b8/copy-to-eax 0x36/imm32
    cd/syscall 0x80/imm8
    c3/return

syscall_nanosleep:  # req/ebx: (addr timespec)
    b8/copy-to-eax 0xa2/imm32  # 162
    cd/syscall 0x80/imm8
    c3/return

syscall_clock_gettime:  # clock/ebx: int, out/ecx: (addr timespec)
    b8/copy-to-eax 0x109/imm32  # 265
    cd/syscall 0x80/imm8
    c3/return